xref: /dpdk/lib/vhost/rte_vhost_crypto.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017-2018 Intel Corporation
3  */
4 
5 #ifndef _VHOST_CRYPTO_H_
6 #define _VHOST_CRYPTO_H_
7 
8 #include <stdint.h>
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 /* pre-declare structs to avoid including full headers */
15 struct rte_mempool;
16 struct rte_crypto_op;
17 
18 #define VHOST_CRYPTO_MBUF_POOL_SIZE		(8192)
19 #define VHOST_CRYPTO_MAX_BURST_SIZE		(64)
20 #define VHOST_CRYPTO_MAX_DATA_SIZE		(4096)
21 #define VHOST_CRYPTO_SESSION_MAP_ENTRIES	(1024) /**< Max nb sessions */
22 /** max nb virtual queues in a burst for finalizing*/
23 #define VIRTIO_CRYPTO_MAX_NUM_BURST_VQS		(64)
24 #define VHOST_CRYPTO_MAX_IV_LEN			(32)
25 #define VHOST_CRYPTO_MAX_N_DESC			(32)
26 
27 enum rte_vhost_crypto_zero_copy {
28 	RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE = 0,
29 	RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE = 1,
30 	RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS
31 };
32 
33 /**
34  * Start vhost crypto driver
35  *
36  * @param path
37  *  The vhost-user socket file path
38  * @return
39  *  0 on success, -1 on failure
40  */
41 int
42 rte_vhost_crypto_driver_start(const char *path);
43 
44 /**
45  *  Create Vhost-crypto instance
46  *
47  * @param vid
48  *  The identifier of the vhost device.
49  * @param cryptodev_id
50  *  The identifier of DPDK Cryptodev, the same cryptodev_id can be assigned to
51  *  multiple Vhost-crypto devices.
52  * @param sess_pool
53  *  The pointer to the created cryptodev session pool.
54  * @param socket_id
55  *  NUMA Socket ID to allocate resources on. *
56  * @return
57  *  0 if the Vhost Crypto Instance is created successfully.
58  *  Negative integer if otherwise
59  */
60 int
61 rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
62 		struct rte_mempool *sess_pool,
63 		int socket_id);
64 
65 /**
66  *  Free the Vhost-crypto instance
67  *
68  * @param vid
69  *  The identifier of the vhost device.
70  * @return
71  *  0 if the Vhost Crypto Instance is created successfully.
72  *  Negative integer if otherwise.
73  */
74 int
75 rte_vhost_crypto_free(int vid);
76 
77 /**
78  *  Enable or disable zero copy feature
79  *
80  * @param vid
81  *  The identifier of the vhost device.
82  * @param option
83  *  Flag of zero copy feature.
84  * @return
85  *  0 if completed successfully.
86  *  Negative integer if otherwise.
87  */
88 int
89 rte_vhost_crypto_set_zero_copy(int vid, enum rte_vhost_crypto_zero_copy option);
90 
91 /**
92  * Fetch a number of vring descriptors from virt-queue and translate to DPDK
93  * crypto operations. After this function is executed, the user can enqueue
94  * the processed ops to the target cryptodev.
95  *
96  * @param vid
97  *  The identifier of the vhost device.
98  * @param qid
99  *  Virtio queue index.
100  * @param ops
101  *  The address of an array of pointers to *rte_crypto_op* structures that must
102  *  be large enough to store *nb_ops* pointers in it.
103  * @param nb_ops
104  *  The maximum number of operations to be fetched and translated.
105  * @return
106  *  The number of fetched and processed vhost crypto request operations.
107  */
108 uint16_t
109 rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
110 		struct rte_crypto_op **ops, uint16_t nb_ops);
111 /**
112  * Finalize the dequeued crypto ops. After the translated crypto ops are
113  * dequeued from the cryptodev, this function shall be called to write the
114  * processed data back to the vring descriptor (if no-copy is turned off).
115  *
116  * @param ops
117  *  The address of an array of *rte_crypto_op* structure that was dequeued
118  *  from cryptodev.
119  * @param nb_ops
120  *  The number of operations contained in the array.
121  * @callfds
122  *  The callfd number(s) contained in this burst, this shall be an array with
123  *  no less than VIRTIO_CRYPTO_MAX_NUM_BURST_VQS elements.
124  * @nb_callfds
125  *  The number of call_fd numbers exist in the callfds.
126  * @return
127  *  The number of ops processed.
128  */
129 uint16_t
130 rte_vhost_crypto_finalize_requests(struct rte_crypto_op **ops,
131 		uint16_t nb_ops, int *callfds, uint16_t *nb_callfds);
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /**< _VHOST_CRYPTO_H_ */
138