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