199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2017-2018 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef _VHOST_CRYPTO_H_ 699a2dd95SBruce Richardson #define _VHOST_CRYPTO_H_ 799a2dd95SBruce Richardson 8*719834a6SMattias Rönnblom #include <stdint.h> 9*719834a6SMattias Rönnblom 10cedca408SBrian Dooley #ifdef __cplusplus 11cedca408SBrian Dooley extern "C" { 12cedca408SBrian Dooley #endif 13cedca408SBrian Dooley 1499a2dd95SBruce Richardson /* pre-declare structs to avoid including full headers */ 1599a2dd95SBruce Richardson struct rte_mempool; 1699a2dd95SBruce Richardson struct rte_crypto_op; 1799a2dd95SBruce Richardson 1899a2dd95SBruce Richardson #define VHOST_CRYPTO_MBUF_POOL_SIZE (8192) 1999a2dd95SBruce Richardson #define VHOST_CRYPTO_MAX_BURST_SIZE (64) 2099a2dd95SBruce Richardson #define VHOST_CRYPTO_MAX_DATA_SIZE (4096) 2199a2dd95SBruce Richardson #define VHOST_CRYPTO_SESSION_MAP_ENTRIES (1024) /**< Max nb sessions */ 2299a2dd95SBruce Richardson /** max nb virtual queues in a burst for finalizing*/ 2399a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAX_NUM_BURST_VQS (64) 2499a2dd95SBruce Richardson #define VHOST_CRYPTO_MAX_IV_LEN (32) 2599a2dd95SBruce Richardson #define VHOST_CRYPTO_MAX_N_DESC (32) 2699a2dd95SBruce Richardson 2799a2dd95SBruce Richardson enum rte_vhost_crypto_zero_copy { 2899a2dd95SBruce Richardson RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE = 0, 2999a2dd95SBruce Richardson RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE = 1, 3099a2dd95SBruce Richardson RTE_VHOST_CRYPTO_MAX_ZERO_COPY_OPTIONS 3199a2dd95SBruce Richardson }; 3299a2dd95SBruce Richardson 3399a2dd95SBruce Richardson /** 3499a2dd95SBruce Richardson * Start vhost crypto driver 3599a2dd95SBruce Richardson * 3699a2dd95SBruce Richardson * @param path 3799a2dd95SBruce Richardson * The vhost-user socket file path 3899a2dd95SBruce Richardson * @return 3999a2dd95SBruce Richardson * 0 on success, -1 on failure 4099a2dd95SBruce Richardson */ 4199a2dd95SBruce Richardson int 4299a2dd95SBruce Richardson rte_vhost_crypto_driver_start(const char *path); 4399a2dd95SBruce Richardson 4499a2dd95SBruce Richardson /** 4599a2dd95SBruce Richardson * Create Vhost-crypto instance 4699a2dd95SBruce Richardson * 4799a2dd95SBruce Richardson * @param vid 4899a2dd95SBruce Richardson * The identifier of the vhost device. 4999a2dd95SBruce Richardson * @param cryptodev_id 5099a2dd95SBruce Richardson * The identifier of DPDK Cryptodev, the same cryptodev_id can be assigned to 5199a2dd95SBruce Richardson * multiple Vhost-crypto devices. 5299a2dd95SBruce Richardson * @param sess_pool 5399a2dd95SBruce Richardson * The pointer to the created cryptodev session pool. 5499a2dd95SBruce Richardson * @param socket_id 5599a2dd95SBruce Richardson * NUMA Socket ID to allocate resources on. * 5699a2dd95SBruce Richardson * @return 5799a2dd95SBruce Richardson * 0 if the Vhost Crypto Instance is created successfully. 5899a2dd95SBruce Richardson * Negative integer if otherwise 5999a2dd95SBruce Richardson */ 6099a2dd95SBruce Richardson int 6199a2dd95SBruce Richardson rte_vhost_crypto_create(int vid, uint8_t cryptodev_id, 6299a2dd95SBruce Richardson struct rte_mempool *sess_pool, 6399a2dd95SBruce Richardson int socket_id); 6499a2dd95SBruce Richardson 6599a2dd95SBruce Richardson /** 6699a2dd95SBruce Richardson * Free the Vhost-crypto instance 6799a2dd95SBruce Richardson * 6899a2dd95SBruce Richardson * @param vid 6999a2dd95SBruce Richardson * The identifier of the vhost device. 7099a2dd95SBruce Richardson * @return 7199a2dd95SBruce Richardson * 0 if the Vhost Crypto Instance is created successfully. 7299a2dd95SBruce Richardson * Negative integer if otherwise. 7399a2dd95SBruce Richardson */ 7499a2dd95SBruce Richardson int 7599a2dd95SBruce Richardson rte_vhost_crypto_free(int vid); 7699a2dd95SBruce Richardson 7799a2dd95SBruce Richardson /** 7899a2dd95SBruce Richardson * Enable or disable zero copy feature 7999a2dd95SBruce Richardson * 8099a2dd95SBruce Richardson * @param vid 8199a2dd95SBruce Richardson * The identifier of the vhost device. 8299a2dd95SBruce Richardson * @param option 8399a2dd95SBruce Richardson * Flag of zero copy feature. 8499a2dd95SBruce Richardson * @return 8599a2dd95SBruce Richardson * 0 if completed successfully. 8699a2dd95SBruce Richardson * Negative integer if otherwise. 8799a2dd95SBruce Richardson */ 8899a2dd95SBruce Richardson int 8999a2dd95SBruce Richardson rte_vhost_crypto_set_zero_copy(int vid, enum rte_vhost_crypto_zero_copy option); 9099a2dd95SBruce Richardson 9199a2dd95SBruce Richardson /** 9299a2dd95SBruce Richardson * Fetch a number of vring descriptors from virt-queue and translate to DPDK 9399a2dd95SBruce Richardson * crypto operations. After this function is executed, the user can enqueue 9499a2dd95SBruce Richardson * the processed ops to the target cryptodev. 9599a2dd95SBruce Richardson * 9699a2dd95SBruce Richardson * @param vid 9799a2dd95SBruce Richardson * The identifier of the vhost device. 9899a2dd95SBruce Richardson * @param qid 9999a2dd95SBruce Richardson * Virtio queue index. 10099a2dd95SBruce Richardson * @param ops 10199a2dd95SBruce Richardson * The address of an array of pointers to *rte_crypto_op* structures that must 10299a2dd95SBruce Richardson * be large enough to store *nb_ops* pointers in it. 10399a2dd95SBruce Richardson * @param nb_ops 10499a2dd95SBruce Richardson * The maximum number of operations to be fetched and translated. 10599a2dd95SBruce Richardson * @return 10699a2dd95SBruce Richardson * The number of fetched and processed vhost crypto request operations. 10799a2dd95SBruce Richardson */ 10899a2dd95SBruce Richardson uint16_t 10999a2dd95SBruce Richardson rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, 11099a2dd95SBruce Richardson struct rte_crypto_op **ops, uint16_t nb_ops); 11199a2dd95SBruce Richardson /** 11299a2dd95SBruce Richardson * Finalize the dequeued crypto ops. After the translated crypto ops are 11399a2dd95SBruce Richardson * dequeued from the cryptodev, this function shall be called to write the 11499a2dd95SBruce Richardson * processed data back to the vring descriptor (if no-copy is turned off). 11599a2dd95SBruce Richardson * 11699a2dd95SBruce Richardson * @param ops 11799a2dd95SBruce Richardson * The address of an array of *rte_crypto_op* structure that was dequeued 11899a2dd95SBruce Richardson * from cryptodev. 11999a2dd95SBruce Richardson * @param nb_ops 12099a2dd95SBruce Richardson * The number of operations contained in the array. 12199a2dd95SBruce Richardson * @callfds 12299a2dd95SBruce Richardson * The callfd number(s) contained in this burst, this shall be an array with 12399a2dd95SBruce Richardson * no less than VIRTIO_CRYPTO_MAX_NUM_BURST_VQS elements. 12499a2dd95SBruce Richardson * @nb_callfds 12599a2dd95SBruce Richardson * The number of call_fd numbers exist in the callfds. 12699a2dd95SBruce Richardson * @return 12799a2dd95SBruce Richardson * The number of ops processed. 12899a2dd95SBruce Richardson */ 12999a2dd95SBruce Richardson uint16_t 13099a2dd95SBruce Richardson rte_vhost_crypto_finalize_requests(struct rte_crypto_op **ops, 13199a2dd95SBruce Richardson uint16_t nb_ops, int *callfds, uint16_t *nb_callfds); 13299a2dd95SBruce Richardson 133cedca408SBrian Dooley #ifdef __cplusplus 134cedca408SBrian Dooley } 135cedca408SBrian Dooley #endif 136cedca408SBrian Dooley 13799a2dd95SBruce Richardson #endif /**< _VHOST_CRYPTO_H_ */ 138