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