1d30ea906Sjfb8856606 /* SPDX-License-Identifier: BSD-3-Clause
2*2d9fd380Sjfb8856606 * Copyright(c) 2015-2020 Intel Corporation.
3a9643ea8Slogwang */
4a9643ea8Slogwang
5a9643ea8Slogwang #ifndef _RTE_CRYPTODEV_H_
6a9643ea8Slogwang #define _RTE_CRYPTODEV_H_
7a9643ea8Slogwang
8a9643ea8Slogwang /**
9a9643ea8Slogwang * @file rte_cryptodev.h
10a9643ea8Slogwang *
11a9643ea8Slogwang * RTE Cryptographic Device APIs
12a9643ea8Slogwang *
13a9643ea8Slogwang * Defines RTE Crypto Device APIs for the provisioning of cipher and
14a9643ea8Slogwang * authentication operations.
15a9643ea8Slogwang */
16a9643ea8Slogwang
17a9643ea8Slogwang #ifdef __cplusplus
18a9643ea8Slogwang extern "C" {
19a9643ea8Slogwang #endif
20a9643ea8Slogwang
21a9643ea8Slogwang #include "rte_kvargs.h"
22a9643ea8Slogwang #include "rte_crypto.h"
23a9643ea8Slogwang #include "rte_dev.h"
242bfe3f2eSlogwang #include <rte_common.h>
252bfe3f2eSlogwang #include <rte_config.h>
26a9643ea8Slogwang
27*2d9fd380Sjfb8856606 #include "rte_cryptodev_trace_fp.h"
28*2d9fd380Sjfb8856606
29a9643ea8Slogwang extern const char **rte_cyptodev_names;
30a9643ea8Slogwang
31a9643ea8Slogwang /* Logging Macros */
32a9643ea8Slogwang
332bfe3f2eSlogwang #define CDEV_LOG_ERR(...) \
342bfe3f2eSlogwang RTE_LOG(ERR, CRYPTODEV, \
352bfe3f2eSlogwang RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
362bfe3f2eSlogwang __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
37a9643ea8Slogwang
382bfe3f2eSlogwang #define CDEV_LOG_INFO(...) \
392bfe3f2eSlogwang RTE_LOG(INFO, CRYPTODEV, \
402bfe3f2eSlogwang RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
412bfe3f2eSlogwang RTE_FMT_TAIL(__VA_ARGS__,)))
42a9643ea8Slogwang
432bfe3f2eSlogwang #define CDEV_LOG_DEBUG(...) \
442bfe3f2eSlogwang RTE_LOG(DEBUG, CRYPTODEV, \
452bfe3f2eSlogwang RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
462bfe3f2eSlogwang __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
47a9643ea8Slogwang
482bfe3f2eSlogwang #define CDEV_PMD_TRACE(...) \
492bfe3f2eSlogwang RTE_LOG(DEBUG, CRYPTODEV, \
502bfe3f2eSlogwang RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
512bfe3f2eSlogwang dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
52a9643ea8Slogwang
532bfe3f2eSlogwang /**
542bfe3f2eSlogwang * A macro that points to an offset from the start
552bfe3f2eSlogwang * of the crypto operation structure (rte_crypto_op)
562bfe3f2eSlogwang *
572bfe3f2eSlogwang * The returned pointer is cast to type t.
582bfe3f2eSlogwang *
592bfe3f2eSlogwang * @param c
602bfe3f2eSlogwang * The crypto operation.
612bfe3f2eSlogwang * @param o
622bfe3f2eSlogwang * The offset from the start of the crypto operation.
632bfe3f2eSlogwang * @param t
642bfe3f2eSlogwang * The type to cast the result into.
652bfe3f2eSlogwang */
662bfe3f2eSlogwang #define rte_crypto_op_ctod_offset(c, t, o) \
672bfe3f2eSlogwang ((t)((char *)(c) + (o)))
682bfe3f2eSlogwang
692bfe3f2eSlogwang /**
702bfe3f2eSlogwang * A macro that returns the physical address that points
712bfe3f2eSlogwang * to an offset from the start of the crypto operation
722bfe3f2eSlogwang * (rte_crypto_op)
732bfe3f2eSlogwang *
742bfe3f2eSlogwang * @param c
752bfe3f2eSlogwang * The crypto operation.
762bfe3f2eSlogwang * @param o
772bfe3f2eSlogwang * The offset from the start of the crypto operation
782bfe3f2eSlogwang * to calculate address from.
792bfe3f2eSlogwang */
802bfe3f2eSlogwang #define rte_crypto_op_ctophys_offset(c, o) \
812bfe3f2eSlogwang (rte_iova_t)((c)->phys_addr + (o))
822bfe3f2eSlogwang
832bfe3f2eSlogwang /**
842bfe3f2eSlogwang * Crypto parameters range description
852bfe3f2eSlogwang */
862bfe3f2eSlogwang struct rte_crypto_param_range {
872bfe3f2eSlogwang uint16_t min; /**< minimum size */
882bfe3f2eSlogwang uint16_t max; /**< maximum size */
892bfe3f2eSlogwang uint16_t increment;
902bfe3f2eSlogwang /**< if a range of sizes are supported,
912bfe3f2eSlogwang * this parameter is used to indicate
922bfe3f2eSlogwang * increments in byte size that are supported
932bfe3f2eSlogwang * between the minimum and maximum
942bfe3f2eSlogwang */
952bfe3f2eSlogwang };
962bfe3f2eSlogwang
97a9643ea8Slogwang /**
98a9643ea8Slogwang * Symmetric Crypto Capability
99a9643ea8Slogwang */
100a9643ea8Slogwang struct rte_cryptodev_symmetric_capability {
101a9643ea8Slogwang enum rte_crypto_sym_xform_type xform_type;
1022bfe3f2eSlogwang /**< Transform type : Authentication / Cipher / AEAD */
1032bfe3f2eSlogwang RTE_STD_C11
104a9643ea8Slogwang union {
105a9643ea8Slogwang struct {
106a9643ea8Slogwang enum rte_crypto_auth_algorithm algo;
107a9643ea8Slogwang /**< authentication algorithm */
108a9643ea8Slogwang uint16_t block_size;
109a9643ea8Slogwang /**< algorithm block size */
1102bfe3f2eSlogwang struct rte_crypto_param_range key_size;
111a9643ea8Slogwang /**< auth key size range */
1122bfe3f2eSlogwang struct rte_crypto_param_range digest_size;
113a9643ea8Slogwang /**< digest size range */
1142bfe3f2eSlogwang struct rte_crypto_param_range aad_size;
115a9643ea8Slogwang /**< Additional authentication data size range */
1162bfe3f2eSlogwang struct rte_crypto_param_range iv_size;
1172bfe3f2eSlogwang /**< Initialisation vector data size range */
118a9643ea8Slogwang } auth;
119a9643ea8Slogwang /**< Symmetric Authentication transform capabilities */
120a9643ea8Slogwang struct {
121a9643ea8Slogwang enum rte_crypto_cipher_algorithm algo;
122a9643ea8Slogwang /**< cipher algorithm */
123a9643ea8Slogwang uint16_t block_size;
124a9643ea8Slogwang /**< algorithm block size */
1252bfe3f2eSlogwang struct rte_crypto_param_range key_size;
126a9643ea8Slogwang /**< cipher key size range */
1272bfe3f2eSlogwang struct rte_crypto_param_range iv_size;
128a9643ea8Slogwang /**< Initialisation vector data size range */
129a9643ea8Slogwang } cipher;
130a9643ea8Slogwang /**< Symmetric Cipher transform capabilities */
1312bfe3f2eSlogwang struct {
1322bfe3f2eSlogwang enum rte_crypto_aead_algorithm algo;
1332bfe3f2eSlogwang /**< AEAD algorithm */
1342bfe3f2eSlogwang uint16_t block_size;
1352bfe3f2eSlogwang /**< algorithm block size */
1362bfe3f2eSlogwang struct rte_crypto_param_range key_size;
1372bfe3f2eSlogwang /**< AEAD key size range */
1382bfe3f2eSlogwang struct rte_crypto_param_range digest_size;
1392bfe3f2eSlogwang /**< digest size range */
1402bfe3f2eSlogwang struct rte_crypto_param_range aad_size;
1412bfe3f2eSlogwang /**< Additional authentication data size range */
1422bfe3f2eSlogwang struct rte_crypto_param_range iv_size;
1432bfe3f2eSlogwang /**< Initialisation vector data size range */
1442bfe3f2eSlogwang } aead;
145a9643ea8Slogwang };
146a9643ea8Slogwang };
147a9643ea8Slogwang
148d30ea906Sjfb8856606 /**
149d30ea906Sjfb8856606 * Asymmetric Xform Crypto Capability
150d30ea906Sjfb8856606 *
151d30ea906Sjfb8856606 */
152d30ea906Sjfb8856606 struct rte_cryptodev_asymmetric_xform_capability {
153d30ea906Sjfb8856606 enum rte_crypto_asym_xform_type xform_type;
154d30ea906Sjfb8856606 /**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
155d30ea906Sjfb8856606
156d30ea906Sjfb8856606 uint32_t op_types;
157d30ea906Sjfb8856606 /**< bitmask for supported rte_crypto_asym_op_type */
158d30ea906Sjfb8856606
159d30ea906Sjfb8856606 __extension__
160d30ea906Sjfb8856606 union {
161d30ea906Sjfb8856606 struct rte_crypto_param_range modlen;
162d30ea906Sjfb8856606 /**< Range of modulus length supported by modulus based xform.
163d30ea906Sjfb8856606 * Value 0 mean implementation default
164d30ea906Sjfb8856606 */
165d30ea906Sjfb8856606 };
166d30ea906Sjfb8856606 };
167d30ea906Sjfb8856606
168d30ea906Sjfb8856606 /**
169d30ea906Sjfb8856606 * Asymmetric Crypto Capability
170d30ea906Sjfb8856606 *
171d30ea906Sjfb8856606 */
172d30ea906Sjfb8856606 struct rte_cryptodev_asymmetric_capability {
173d30ea906Sjfb8856606 struct rte_cryptodev_asymmetric_xform_capability xform_capa;
174d30ea906Sjfb8856606 };
175d30ea906Sjfb8856606
176d30ea906Sjfb8856606
177a9643ea8Slogwang /** Structure used to capture a capability of a crypto device */
178a9643ea8Slogwang struct rte_cryptodev_capabilities {
179a9643ea8Slogwang enum rte_crypto_op_type op;
180a9643ea8Slogwang /**< Operation type */
181a9643ea8Slogwang
1822bfe3f2eSlogwang RTE_STD_C11
183a9643ea8Slogwang union {
184a9643ea8Slogwang struct rte_cryptodev_symmetric_capability sym;
185a9643ea8Slogwang /**< Symmetric operation capability parameters */
186d30ea906Sjfb8856606 struct rte_cryptodev_asymmetric_capability asym;
187d30ea906Sjfb8856606 /**< Asymmetric operation capability parameters */
188a9643ea8Slogwang };
189a9643ea8Slogwang };
190a9643ea8Slogwang
1912bfe3f2eSlogwang /** Structure used to describe crypto algorithms */
1922bfe3f2eSlogwang struct rte_cryptodev_sym_capability_idx {
1932bfe3f2eSlogwang enum rte_crypto_sym_xform_type type;
1942bfe3f2eSlogwang union {
1952bfe3f2eSlogwang enum rte_crypto_cipher_algorithm cipher;
1962bfe3f2eSlogwang enum rte_crypto_auth_algorithm auth;
1972bfe3f2eSlogwang enum rte_crypto_aead_algorithm aead;
1982bfe3f2eSlogwang } algo;
1992bfe3f2eSlogwang };
2002bfe3f2eSlogwang
2012bfe3f2eSlogwang /**
202d30ea906Sjfb8856606 * Structure used to describe asymmetric crypto xforms
203d30ea906Sjfb8856606 * Each xform maps to one asym algorithm.
204d30ea906Sjfb8856606 *
205d30ea906Sjfb8856606 */
206d30ea906Sjfb8856606 struct rte_cryptodev_asym_capability_idx {
207d30ea906Sjfb8856606 enum rte_crypto_asym_xform_type type;
208d30ea906Sjfb8856606 /**< Asymmetric xform (algo) type */
209d30ea906Sjfb8856606 };
210d30ea906Sjfb8856606
211d30ea906Sjfb8856606 /**
2122bfe3f2eSlogwang * Provide capabilities available for defined device and algorithm
2132bfe3f2eSlogwang *
2142bfe3f2eSlogwang * @param dev_id The identifier of the device.
2152bfe3f2eSlogwang * @param idx Description of crypto algorithms.
2162bfe3f2eSlogwang *
2172bfe3f2eSlogwang * @return
2182bfe3f2eSlogwang * - Return description of the symmetric crypto capability if exist.
2192bfe3f2eSlogwang * - Return NULL if the capability not exist.
2202bfe3f2eSlogwang */
2212bfe3f2eSlogwang const struct rte_cryptodev_symmetric_capability *
2222bfe3f2eSlogwang rte_cryptodev_sym_capability_get(uint8_t dev_id,
2232bfe3f2eSlogwang const struct rte_cryptodev_sym_capability_idx *idx);
2242bfe3f2eSlogwang
2252bfe3f2eSlogwang /**
226d30ea906Sjfb8856606 * Provide capabilities available for defined device and xform
227d30ea906Sjfb8856606 *
228d30ea906Sjfb8856606 * @param dev_id The identifier of the device.
229d30ea906Sjfb8856606 * @param idx Description of asym crypto xform.
230d30ea906Sjfb8856606 *
231d30ea906Sjfb8856606 * @return
232d30ea906Sjfb8856606 * - Return description of the asymmetric crypto capability if exist.
233d30ea906Sjfb8856606 * - Return NULL if the capability not exist.
234d30ea906Sjfb8856606 */
2354418919fSjohnjiang __rte_experimental
2364418919fSjohnjiang const struct rte_cryptodev_asymmetric_xform_capability *
237d30ea906Sjfb8856606 rte_cryptodev_asym_capability_get(uint8_t dev_id,
238d30ea906Sjfb8856606 const struct rte_cryptodev_asym_capability_idx *idx);
239d30ea906Sjfb8856606
240d30ea906Sjfb8856606 /**
2412bfe3f2eSlogwang * Check if key size and initial vector are supported
2422bfe3f2eSlogwang * in crypto cipher capability
2432bfe3f2eSlogwang *
2442bfe3f2eSlogwang * @param capability Description of the symmetric crypto capability.
2452bfe3f2eSlogwang * @param key_size Cipher key size.
2462bfe3f2eSlogwang * @param iv_size Cipher initial vector size.
2472bfe3f2eSlogwang *
2482bfe3f2eSlogwang * @return
2492bfe3f2eSlogwang * - Return 0 if the parameters are in range of the capability.
2502bfe3f2eSlogwang * - Return -1 if the parameters are out of range of the capability.
2512bfe3f2eSlogwang */
2522bfe3f2eSlogwang int
2532bfe3f2eSlogwang rte_cryptodev_sym_capability_check_cipher(
2542bfe3f2eSlogwang const struct rte_cryptodev_symmetric_capability *capability,
2552bfe3f2eSlogwang uint16_t key_size, uint16_t iv_size);
2562bfe3f2eSlogwang
2572bfe3f2eSlogwang /**
2582bfe3f2eSlogwang * Check if key size and initial vector are supported
2592bfe3f2eSlogwang * in crypto auth capability
2602bfe3f2eSlogwang *
2612bfe3f2eSlogwang * @param capability Description of the symmetric crypto capability.
2622bfe3f2eSlogwang * @param key_size Auth key size.
2632bfe3f2eSlogwang * @param digest_size Auth digest size.
2642bfe3f2eSlogwang * @param iv_size Auth initial vector size.
2652bfe3f2eSlogwang *
2662bfe3f2eSlogwang * @return
2672bfe3f2eSlogwang * - Return 0 if the parameters are in range of the capability.
2682bfe3f2eSlogwang * - Return -1 if the parameters are out of range of the capability.
2692bfe3f2eSlogwang */
2702bfe3f2eSlogwang int
2712bfe3f2eSlogwang rte_cryptodev_sym_capability_check_auth(
2722bfe3f2eSlogwang const struct rte_cryptodev_symmetric_capability *capability,
2732bfe3f2eSlogwang uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
2742bfe3f2eSlogwang
2752bfe3f2eSlogwang /**
2762bfe3f2eSlogwang * Check if key, digest, AAD and initial vector sizes are supported
2772bfe3f2eSlogwang * in crypto AEAD capability
2782bfe3f2eSlogwang *
2792bfe3f2eSlogwang * @param capability Description of the symmetric crypto capability.
2802bfe3f2eSlogwang * @param key_size AEAD key size.
2812bfe3f2eSlogwang * @param digest_size AEAD digest size.
2822bfe3f2eSlogwang * @param aad_size AEAD AAD size.
2832bfe3f2eSlogwang * @param iv_size AEAD IV size.
2842bfe3f2eSlogwang *
2852bfe3f2eSlogwang * @return
2862bfe3f2eSlogwang * - Return 0 if the parameters are in range of the capability.
2872bfe3f2eSlogwang * - Return -1 if the parameters are out of range of the capability.
2882bfe3f2eSlogwang */
2892bfe3f2eSlogwang int
2902bfe3f2eSlogwang rte_cryptodev_sym_capability_check_aead(
2912bfe3f2eSlogwang const struct rte_cryptodev_symmetric_capability *capability,
2922bfe3f2eSlogwang uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
2932bfe3f2eSlogwang uint16_t iv_size);
2942bfe3f2eSlogwang
2952bfe3f2eSlogwang /**
296d30ea906Sjfb8856606 * Check if op type is supported
297d30ea906Sjfb8856606 *
298d30ea906Sjfb8856606 * @param capability Description of the asymmetric crypto capability.
299d30ea906Sjfb8856606 * @param op_type op type
300d30ea906Sjfb8856606 *
301d30ea906Sjfb8856606 * @return
302d30ea906Sjfb8856606 * - Return 1 if the op type is supported
303d30ea906Sjfb8856606 * - Return 0 if unsupported
304d30ea906Sjfb8856606 */
3054418919fSjohnjiang __rte_experimental
3064418919fSjohnjiang int
307d30ea906Sjfb8856606 rte_cryptodev_asym_xform_capability_check_optype(
308d30ea906Sjfb8856606 const struct rte_cryptodev_asymmetric_xform_capability *capability,
309d30ea906Sjfb8856606 enum rte_crypto_asym_op_type op_type);
310d30ea906Sjfb8856606
311d30ea906Sjfb8856606 /**
312d30ea906Sjfb8856606 * Check if modulus length is in supported range
313d30ea906Sjfb8856606 *
314d30ea906Sjfb8856606 * @param capability Description of the asymmetric crypto capability.
315d30ea906Sjfb8856606 * @param modlen modulus length.
316d30ea906Sjfb8856606 *
317d30ea906Sjfb8856606 * @return
318d30ea906Sjfb8856606 * - Return 0 if the parameters are in range of the capability.
319d30ea906Sjfb8856606 * - Return -1 if the parameters are out of range of the capability.
320d30ea906Sjfb8856606 */
3214418919fSjohnjiang __rte_experimental
3224418919fSjohnjiang int
323d30ea906Sjfb8856606 rte_cryptodev_asym_xform_capability_check_modlen(
324d30ea906Sjfb8856606 const struct rte_cryptodev_asymmetric_xform_capability *capability,
325d30ea906Sjfb8856606 uint16_t modlen);
326d30ea906Sjfb8856606
327d30ea906Sjfb8856606 /**
3282bfe3f2eSlogwang * Provide the cipher algorithm enum, given an algorithm string
3292bfe3f2eSlogwang *
3302bfe3f2eSlogwang * @param algo_enum A pointer to the cipher algorithm
3312bfe3f2eSlogwang * enum to be filled
3322bfe3f2eSlogwang * @param algo_string Authentication algo string
3332bfe3f2eSlogwang *
3342bfe3f2eSlogwang * @return
3352bfe3f2eSlogwang * - Return -1 if string is not valid
3362bfe3f2eSlogwang * - Return 0 is the string is valid
3372bfe3f2eSlogwang */
3382bfe3f2eSlogwang int
3392bfe3f2eSlogwang rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
3402bfe3f2eSlogwang const char *algo_string);
3412bfe3f2eSlogwang
3422bfe3f2eSlogwang /**
3432bfe3f2eSlogwang * Provide the authentication algorithm enum, given an algorithm string
3442bfe3f2eSlogwang *
3452bfe3f2eSlogwang * @param algo_enum A pointer to the authentication algorithm
3462bfe3f2eSlogwang * enum to be filled
3472bfe3f2eSlogwang * @param algo_string Authentication algo string
3482bfe3f2eSlogwang *
3492bfe3f2eSlogwang * @return
3502bfe3f2eSlogwang * - Return -1 if string is not valid
3512bfe3f2eSlogwang * - Return 0 is the string is valid
3522bfe3f2eSlogwang */
3532bfe3f2eSlogwang int
3542bfe3f2eSlogwang rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
3552bfe3f2eSlogwang const char *algo_string);
3562bfe3f2eSlogwang
3572bfe3f2eSlogwang /**
3582bfe3f2eSlogwang * Provide the AEAD algorithm enum, given an algorithm string
3592bfe3f2eSlogwang *
3602bfe3f2eSlogwang * @param algo_enum A pointer to the AEAD algorithm
3612bfe3f2eSlogwang * enum to be filled
3622bfe3f2eSlogwang * @param algo_string AEAD algorithm string
3632bfe3f2eSlogwang *
3642bfe3f2eSlogwang * @return
3652bfe3f2eSlogwang * - Return -1 if string is not valid
3662bfe3f2eSlogwang * - Return 0 is the string is valid
3672bfe3f2eSlogwang */
3682bfe3f2eSlogwang int
3692bfe3f2eSlogwang rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
3702bfe3f2eSlogwang const char *algo_string);
3712bfe3f2eSlogwang
372d30ea906Sjfb8856606 /**
373d30ea906Sjfb8856606 * Provide the Asymmetric xform enum, given an xform string
374d30ea906Sjfb8856606 *
375d30ea906Sjfb8856606 * @param xform_enum A pointer to the xform type
376d30ea906Sjfb8856606 * enum to be filled
377d30ea906Sjfb8856606 * @param xform_string xform string
378d30ea906Sjfb8856606 *
379d30ea906Sjfb8856606 * @return
380d30ea906Sjfb8856606 * - Return -1 if string is not valid
381d30ea906Sjfb8856606 * - Return 0 if the string is valid
382d30ea906Sjfb8856606 */
3834418919fSjohnjiang __rte_experimental
3844418919fSjohnjiang int
385d30ea906Sjfb8856606 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
386d30ea906Sjfb8856606 const char *xform_string);
387d30ea906Sjfb8856606
388d30ea906Sjfb8856606
389a9643ea8Slogwang /** Macro used at end of crypto PMD list */
390a9643ea8Slogwang #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
391a9643ea8Slogwang { RTE_CRYPTO_OP_TYPE_UNDEFINED }
392a9643ea8Slogwang
393a9643ea8Slogwang
394a9643ea8Slogwang /**
395a9643ea8Slogwang * Crypto device supported feature flags
396a9643ea8Slogwang *
397a9643ea8Slogwang * Note:
398a9643ea8Slogwang * New features flags should be added to the end of the list
399a9643ea8Slogwang *
400a9643ea8Slogwang * Keep these flags synchronised with rte_cryptodev_get_feature_name()
401a9643ea8Slogwang */
402a9643ea8Slogwang #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
403a9643ea8Slogwang /**< Symmetric crypto operations are supported */
404a9643ea8Slogwang #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
405a9643ea8Slogwang /**< Asymmetric crypto operations are supported */
406a9643ea8Slogwang #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
407a9643ea8Slogwang /**< Chaining symmetric crypto operations are supported */
408a9643ea8Slogwang #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
409a9643ea8Slogwang /**< Utilises CPU SIMD SSE instructions */
410a9643ea8Slogwang #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
411a9643ea8Slogwang /**< Utilises CPU SIMD AVX instructions */
412a9643ea8Slogwang #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
413a9643ea8Slogwang /**< Utilises CPU SIMD AVX2 instructions */
414a9643ea8Slogwang #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
415a9643ea8Slogwang /**< Utilises CPU AES-NI instructions */
416a9643ea8Slogwang #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
417d30ea906Sjfb8856606 /**< Operations are off-loaded to an
418d30ea906Sjfb8856606 * external hardware accelerator
419d30ea906Sjfb8856606 */
4202bfe3f2eSlogwang #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
4212bfe3f2eSlogwang /**< Utilises CPU SIMD AVX512 instructions */
422d30ea906Sjfb8856606 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL (1ULL << 9)
423d30ea906Sjfb8856606 /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
424d30ea906Sjfb8856606 * are supported
425d30ea906Sjfb8856606 */
426d30ea906Sjfb8856606 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT (1ULL << 10)
427d30ea906Sjfb8856606 /**< Out-of-place Scatter-gather (SGL) buffers are
428d30ea906Sjfb8856606 * supported in input and output
429d30ea906Sjfb8856606 */
430d30ea906Sjfb8856606 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT (1ULL << 11)
431d30ea906Sjfb8856606 /**< Out-of-place Scatter-gather (SGL) buffers are supported
432d30ea906Sjfb8856606 * in input, combined with linear buffers (LB), with a
433d30ea906Sjfb8856606 * single segment in output
434d30ea906Sjfb8856606 */
435d30ea906Sjfb8856606 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT (1ULL << 12)
436d30ea906Sjfb8856606 /**< Out-of-place Scatter-gather (SGL) buffers are supported
437d30ea906Sjfb8856606 * in output, combined with linear buffers (LB) in input
438d30ea906Sjfb8856606 */
439d30ea906Sjfb8856606 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT (1ULL << 13)
440d30ea906Sjfb8856606 /**< Out-of-place linear buffers (LB) are supported in input and output */
441d30ea906Sjfb8856606 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 14)
4422bfe3f2eSlogwang /**< Utilises CPU NEON instructions */
443d30ea906Sjfb8856606 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 15)
4442bfe3f2eSlogwang /**< Utilises ARM CPU Cryptographic Extensions */
445d30ea906Sjfb8856606 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 16)
4462bfe3f2eSlogwang /**< Support Security Protocol Processing */
4474418919fSjohnjiang #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP (1ULL << 17)
4484418919fSjohnjiang /**< Support RSA Private Key OP with exponent */
4494418919fSjohnjiang #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT (1ULL << 18)
4504418919fSjohnjiang /**< Support RSA Private Key OP with CRT (quintuple) Keys */
4514418919fSjohnjiang #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED (1ULL << 19)
4524418919fSjohnjiang /**< Support encrypted-digest operations where digest is appended to data */
4534418919fSjohnjiang #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS (1ULL << 20)
4544418919fSjohnjiang /**< Support asymmetric session-less operations */
455*2d9fd380Sjfb8856606 #define RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO (1ULL << 21)
456*2d9fd380Sjfb8856606 /**< Support symmetric cpu-crypto processing */
457*2d9fd380Sjfb8856606 #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS (1ULL << 22)
458*2d9fd380Sjfb8856606 /**< Support symmetric session-less operations */
459*2d9fd380Sjfb8856606 #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA (1ULL << 23)
460*2d9fd380Sjfb8856606 /**< Support operations on data which is not byte aligned */
461*2d9fd380Sjfb8856606 #define RTE_CRYPTODEV_FF_SYM_RAW_DP (1ULL << 24)
462*2d9fd380Sjfb8856606 /**< Support accelerator specific symmetric raw data-path APIs */
463a9643ea8Slogwang
464a9643ea8Slogwang /**
465a9643ea8Slogwang * Get the name of a crypto device feature flag
466a9643ea8Slogwang *
467a9643ea8Slogwang * @param flag The mask describing the flag.
468a9643ea8Slogwang *
469a9643ea8Slogwang * @return
470a9643ea8Slogwang * The name of this flag, or NULL if it's not a valid feature flag.
471a9643ea8Slogwang */
472a9643ea8Slogwang
473a9643ea8Slogwang extern const char *
474a9643ea8Slogwang rte_cryptodev_get_feature_name(uint64_t flag);
475a9643ea8Slogwang
476a9643ea8Slogwang /** Crypto device information */
477a9643ea8Slogwang struct rte_cryptodev_info {
478a9643ea8Slogwang const char *driver_name; /**< Driver name. */
4792bfe3f2eSlogwang uint8_t driver_id; /**< Driver identifier */
480d30ea906Sjfb8856606 struct rte_device *device; /**< Generic device information. */
481a9643ea8Slogwang
482d30ea906Sjfb8856606 uint64_t feature_flags;
483d30ea906Sjfb8856606 /**< Feature flags exposes HW/SW features for the given device */
484a9643ea8Slogwang
485a9643ea8Slogwang const struct rte_cryptodev_capabilities *capabilities;
486a9643ea8Slogwang /**< Array of devices supported capabilities */
487a9643ea8Slogwang
488a9643ea8Slogwang unsigned max_nb_queue_pairs;
489a9643ea8Slogwang /**< Maximum number of queues pairs supported by device. */
490a9643ea8Slogwang
491d30ea906Sjfb8856606 uint16_t min_mbuf_headroom_req;
492d30ea906Sjfb8856606 /**< Minimum mbuf headroom required by device */
493d30ea906Sjfb8856606
494d30ea906Sjfb8856606 uint16_t min_mbuf_tailroom_req;
495d30ea906Sjfb8856606 /**< Minimum mbuf tailroom required by device */
496d30ea906Sjfb8856606
497a9643ea8Slogwang struct {
498a9643ea8Slogwang unsigned max_nb_sessions;
499d30ea906Sjfb8856606 /**< Maximum number of sessions supported by device.
500d30ea906Sjfb8856606 * If 0, the device does not have any limitation in
501d30ea906Sjfb8856606 * number of sessions that can be used.
5022bfe3f2eSlogwang */
503a9643ea8Slogwang } sym;
504a9643ea8Slogwang };
505a9643ea8Slogwang
506a9643ea8Slogwang #define RTE_CRYPTODEV_DETACHED (0)
507a9643ea8Slogwang #define RTE_CRYPTODEV_ATTACHED (1)
508a9643ea8Slogwang
509a9643ea8Slogwang /** Definitions of Crypto device event types */
510a9643ea8Slogwang enum rte_cryptodev_event_type {
511a9643ea8Slogwang RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
512a9643ea8Slogwang RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
513a9643ea8Slogwang RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
514a9643ea8Slogwang };
515a9643ea8Slogwang
516a9643ea8Slogwang /** Crypto device queue pair configuration structure. */
517a9643ea8Slogwang struct rte_cryptodev_qp_conf {
518a9643ea8Slogwang uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
5194418919fSjohnjiang struct rte_mempool *mp_session;
5204418919fSjohnjiang /**< The mempool for creating session in sessionless mode */
5214418919fSjohnjiang struct rte_mempool *mp_session_private;
5224418919fSjohnjiang /**< The mempool for creating sess private data in sessionless mode */
523a9643ea8Slogwang };
524a9643ea8Slogwang
525a9643ea8Slogwang /**
526a9643ea8Slogwang * Typedef for application callback function to be registered by application
527a9643ea8Slogwang * software for notification of device events
528a9643ea8Slogwang *
529a9643ea8Slogwang * @param dev_id Crypto device identifier
530a9643ea8Slogwang * @param event Crypto device event to register for notification of.
531a9643ea8Slogwang * @param cb_arg User specified parameter to be passed as to passed to
532a9643ea8Slogwang * users callback function.
533a9643ea8Slogwang */
534a9643ea8Slogwang typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
535a9643ea8Slogwang enum rte_cryptodev_event_type event, void *cb_arg);
536a9643ea8Slogwang
537a9643ea8Slogwang
538a9643ea8Slogwang /** Crypto Device statistics */
539a9643ea8Slogwang struct rte_cryptodev_stats {
540a9643ea8Slogwang uint64_t enqueued_count;
541a9643ea8Slogwang /**< Count of all operations enqueued */
542a9643ea8Slogwang uint64_t dequeued_count;
543a9643ea8Slogwang /**< Count of all operations dequeued */
544a9643ea8Slogwang
545a9643ea8Slogwang uint64_t enqueue_err_count;
546a9643ea8Slogwang /**< Total error count on operations enqueued */
547a9643ea8Slogwang uint64_t dequeue_err_count;
548a9643ea8Slogwang /**< Total error count on operations dequeued */
549a9643ea8Slogwang };
550a9643ea8Slogwang
5512bfe3f2eSlogwang #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
5522bfe3f2eSlogwang /**< Max length of name of crypto PMD */
553a9643ea8Slogwang
554a9643ea8Slogwang /**
555a9643ea8Slogwang * Get the device identifier for the named crypto device.
556a9643ea8Slogwang *
557a9643ea8Slogwang * @param name device name to select the device structure.
558a9643ea8Slogwang *
559a9643ea8Slogwang * @return
560a9643ea8Slogwang * - Returns crypto device identifier on success.
561a9643ea8Slogwang * - Return -1 on failure to find named crypto device.
562a9643ea8Slogwang */
563a9643ea8Slogwang extern int
564a9643ea8Slogwang rte_cryptodev_get_dev_id(const char *name);
565a9643ea8Slogwang
566a9643ea8Slogwang /**
5672bfe3f2eSlogwang * Get the crypto device name given a device identifier.
5682bfe3f2eSlogwang *
5692bfe3f2eSlogwang * @param dev_id
5702bfe3f2eSlogwang * The identifier of the device
5712bfe3f2eSlogwang *
5722bfe3f2eSlogwang * @return
5732bfe3f2eSlogwang * - Returns crypto device name.
5742bfe3f2eSlogwang * - Returns NULL if crypto device is not present.
5752bfe3f2eSlogwang */
5762bfe3f2eSlogwang extern const char *
5772bfe3f2eSlogwang rte_cryptodev_name_get(uint8_t dev_id);
5782bfe3f2eSlogwang
5792bfe3f2eSlogwang /**
580a9643ea8Slogwang * Get the total number of crypto devices that have been successfully
581a9643ea8Slogwang * initialised.
582a9643ea8Slogwang *
583a9643ea8Slogwang * @return
584a9643ea8Slogwang * - The total number of usable crypto devices.
585a9643ea8Slogwang */
586a9643ea8Slogwang extern uint8_t
587a9643ea8Slogwang rte_cryptodev_count(void);
588a9643ea8Slogwang
5892bfe3f2eSlogwang /**
5902bfe3f2eSlogwang * Get number of crypto device defined type.
5912bfe3f2eSlogwang *
5922bfe3f2eSlogwang * @param driver_id driver identifier.
5932bfe3f2eSlogwang *
5942bfe3f2eSlogwang * @return
5952bfe3f2eSlogwang * Returns number of crypto device.
5962bfe3f2eSlogwang */
597a9643ea8Slogwang extern uint8_t
5982bfe3f2eSlogwang rte_cryptodev_device_count_by_driver(uint8_t driver_id);
5992bfe3f2eSlogwang
6002bfe3f2eSlogwang /**
6012bfe3f2eSlogwang * Get number and identifiers of attached crypto devices that
6022bfe3f2eSlogwang * use the same crypto driver.
6032bfe3f2eSlogwang *
6042bfe3f2eSlogwang * @param driver_name driver name.
6052bfe3f2eSlogwang * @param devices output devices identifiers.
6062bfe3f2eSlogwang * @param nb_devices maximal number of devices.
6072bfe3f2eSlogwang *
6082bfe3f2eSlogwang * @return
6092bfe3f2eSlogwang * Returns number of attached crypto device.
6102bfe3f2eSlogwang */
6112bfe3f2eSlogwang uint8_t
6122bfe3f2eSlogwang rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
6132bfe3f2eSlogwang uint8_t nb_devices);
614a9643ea8Slogwang /*
615a9643ea8Slogwang * Return the NUMA socket to which a device is connected
616a9643ea8Slogwang *
617a9643ea8Slogwang * @param dev_id
618a9643ea8Slogwang * The identifier of the device
619a9643ea8Slogwang * @return
620a9643ea8Slogwang * The NUMA socket id to which the device is connected or
621a9643ea8Slogwang * a default of zero if the socket could not be determined.
622a9643ea8Slogwang * -1 if returned is the dev_id value is out of range.
623a9643ea8Slogwang */
624a9643ea8Slogwang extern int
625a9643ea8Slogwang rte_cryptodev_socket_id(uint8_t dev_id);
626a9643ea8Slogwang
627a9643ea8Slogwang /** Crypto device configuration structure */
628a9643ea8Slogwang struct rte_cryptodev_config {
629a9643ea8Slogwang int socket_id; /**< Socket to allocate resources on */
630a9643ea8Slogwang uint16_t nb_queue_pairs;
631a9643ea8Slogwang /**< Number of queue pairs to configure on device */
6324418919fSjohnjiang uint64_t ff_disable;
6334418919fSjohnjiang /**< Feature flags to be disabled. Only the following features are
6344418919fSjohnjiang * allowed to be disabled,
6354418919fSjohnjiang * - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
6364418919fSjohnjiang * - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
6374418919fSjohnjiang * - RTE_CRYTPODEV_FF_SECURITY
6384418919fSjohnjiang */
639a9643ea8Slogwang };
640a9643ea8Slogwang
641a9643ea8Slogwang /**
642a9643ea8Slogwang * Configure a device.
643a9643ea8Slogwang *
644a9643ea8Slogwang * This function must be invoked first before any other function in the
645a9643ea8Slogwang * API. This function can also be re-invoked when a device is in the
646a9643ea8Slogwang * stopped state.
647a9643ea8Slogwang *
648a9643ea8Slogwang * @param dev_id The identifier of the device to configure.
649a9643ea8Slogwang * @param config The crypto device configuration structure.
650a9643ea8Slogwang *
651a9643ea8Slogwang * @return
652a9643ea8Slogwang * - 0: Success, device configured.
653a9643ea8Slogwang * - <0: Error code returned by the driver configuration function.
654a9643ea8Slogwang */
655a9643ea8Slogwang extern int
656a9643ea8Slogwang rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
657a9643ea8Slogwang
658a9643ea8Slogwang /**
659a9643ea8Slogwang * Start an device.
660a9643ea8Slogwang *
661a9643ea8Slogwang * The device start step is the last one and consists of setting the configured
662a9643ea8Slogwang * offload features and in starting the transmit and the receive units of the
663a9643ea8Slogwang * device.
664a9643ea8Slogwang * On success, all basic functions exported by the API (link status,
665a9643ea8Slogwang * receive/transmit, and so on) can be invoked.
666a9643ea8Slogwang *
667a9643ea8Slogwang * @param dev_id
668a9643ea8Slogwang * The identifier of the device.
669a9643ea8Slogwang * @return
670a9643ea8Slogwang * - 0: Success, device started.
671a9643ea8Slogwang * - <0: Error code of the driver device start function.
672a9643ea8Slogwang */
673a9643ea8Slogwang extern int
674a9643ea8Slogwang rte_cryptodev_start(uint8_t dev_id);
675a9643ea8Slogwang
676a9643ea8Slogwang /**
677a9643ea8Slogwang * Stop an device. The device can be restarted with a call to
678a9643ea8Slogwang * rte_cryptodev_start()
679a9643ea8Slogwang *
680a9643ea8Slogwang * @param dev_id The identifier of the device.
681a9643ea8Slogwang */
682a9643ea8Slogwang extern void
683a9643ea8Slogwang rte_cryptodev_stop(uint8_t dev_id);
684a9643ea8Slogwang
685a9643ea8Slogwang /**
686a9643ea8Slogwang * Close an device. The device cannot be restarted!
687a9643ea8Slogwang *
688a9643ea8Slogwang * @param dev_id The identifier of the device.
689a9643ea8Slogwang *
690a9643ea8Slogwang * @return
691a9643ea8Slogwang * - 0 on successfully closing device
692a9643ea8Slogwang * - <0 on failure to close device
693a9643ea8Slogwang */
694a9643ea8Slogwang extern int
695a9643ea8Slogwang rte_cryptodev_close(uint8_t dev_id);
696a9643ea8Slogwang
697a9643ea8Slogwang /**
698a9643ea8Slogwang * Allocate and set up a receive queue pair for a device.
699a9643ea8Slogwang *
700a9643ea8Slogwang *
701a9643ea8Slogwang * @param dev_id The identifier of the device.
702a9643ea8Slogwang * @param queue_pair_id The index of the queue pairs to set up. The
703a9643ea8Slogwang * value must be in the range [0, nb_queue_pair
704a9643ea8Slogwang * - 1] previously supplied to
705a9643ea8Slogwang * rte_cryptodev_configure().
706a9643ea8Slogwang * @param qp_conf The pointer to the configuration data to be
7074418919fSjohnjiang * used for the queue pair.
708a9643ea8Slogwang * @param socket_id The *socket_id* argument is the socket
709a9643ea8Slogwang * identifier in case of NUMA. The value can be
710a9643ea8Slogwang * *SOCKET_ID_ANY* if there is no NUMA constraint
711a9643ea8Slogwang * for the DMA memory allocated for the receive
712a9643ea8Slogwang * queue pair.
713a9643ea8Slogwang *
714a9643ea8Slogwang * @return
715a9643ea8Slogwang * - 0: Success, queue pair correctly set up.
716a9643ea8Slogwang * - <0: Queue pair configuration failed
717a9643ea8Slogwang */
718a9643ea8Slogwang extern int
719a9643ea8Slogwang rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
7204418919fSjohnjiang const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
721a9643ea8Slogwang
722a9643ea8Slogwang /**
723*2d9fd380Sjfb8856606 * Get the status of queue pairs setup on a specific crypto device
724*2d9fd380Sjfb8856606 *
725*2d9fd380Sjfb8856606 * @param dev_id Crypto device identifier.
726*2d9fd380Sjfb8856606 * @param queue_pair_id The index of the queue pairs to set up. The
727*2d9fd380Sjfb8856606 * value must be in the range [0, nb_queue_pair
728*2d9fd380Sjfb8856606 * - 1] previously supplied to
729*2d9fd380Sjfb8856606 * rte_cryptodev_configure().
730*2d9fd380Sjfb8856606 * @return
731*2d9fd380Sjfb8856606 * - 0: qp was not configured
732*2d9fd380Sjfb8856606 * - 1: qp was configured
733*2d9fd380Sjfb8856606 * - -EINVAL: device was not configured
734*2d9fd380Sjfb8856606 */
735*2d9fd380Sjfb8856606 __rte_experimental
736*2d9fd380Sjfb8856606 int
737*2d9fd380Sjfb8856606 rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id);
738*2d9fd380Sjfb8856606
739*2d9fd380Sjfb8856606 /**
740a9643ea8Slogwang * Get the number of queue pairs on a specific crypto device
741a9643ea8Slogwang *
742a9643ea8Slogwang * @param dev_id Crypto device identifier.
743a9643ea8Slogwang * @return
744a9643ea8Slogwang * - The number of configured queue pairs.
745a9643ea8Slogwang */
746a9643ea8Slogwang extern uint16_t
747a9643ea8Slogwang rte_cryptodev_queue_pair_count(uint8_t dev_id);
748a9643ea8Slogwang
749a9643ea8Slogwang
750a9643ea8Slogwang /**
751a9643ea8Slogwang * Retrieve the general I/O statistics of a device.
752a9643ea8Slogwang *
753a9643ea8Slogwang * @param dev_id The identifier of the device.
754a9643ea8Slogwang * @param stats A pointer to a structure of type
755a9643ea8Slogwang * *rte_cryptodev_stats* to be filled with the
756a9643ea8Slogwang * values of device counters.
757a9643ea8Slogwang * @return
758a9643ea8Slogwang * - Zero if successful.
759a9643ea8Slogwang * - Non-zero otherwise.
760a9643ea8Slogwang */
761a9643ea8Slogwang extern int
762a9643ea8Slogwang rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
763a9643ea8Slogwang
764a9643ea8Slogwang /**
765a9643ea8Slogwang * Reset the general I/O statistics of a device.
766a9643ea8Slogwang *
767a9643ea8Slogwang * @param dev_id The identifier of the device.
768a9643ea8Slogwang */
769a9643ea8Slogwang extern void
770a9643ea8Slogwang rte_cryptodev_stats_reset(uint8_t dev_id);
771a9643ea8Slogwang
772a9643ea8Slogwang /**
773a9643ea8Slogwang * Retrieve the contextual information of a device.
774a9643ea8Slogwang *
775a9643ea8Slogwang * @param dev_id The identifier of the device.
776a9643ea8Slogwang * @param dev_info A pointer to a structure of type
777a9643ea8Slogwang * *rte_cryptodev_info* to be filled with the
778a9643ea8Slogwang * contextual information of the device.
7792bfe3f2eSlogwang *
7802bfe3f2eSlogwang * @note The capabilities field of dev_info is set to point to the first
7812bfe3f2eSlogwang * element of an array of struct rte_cryptodev_capabilities. The element after
7822bfe3f2eSlogwang * the last valid element has it's op field set to
7832bfe3f2eSlogwang * RTE_CRYPTO_OP_TYPE_UNDEFINED.
784a9643ea8Slogwang */
785a9643ea8Slogwang extern void
786a9643ea8Slogwang rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
787a9643ea8Slogwang
788a9643ea8Slogwang
789a9643ea8Slogwang /**
790a9643ea8Slogwang * Register a callback function for specific device id.
791a9643ea8Slogwang *
792a9643ea8Slogwang * @param dev_id Device id.
793a9643ea8Slogwang * @param event Event interested.
794a9643ea8Slogwang * @param cb_fn User supplied callback function to be called.
795a9643ea8Slogwang * @param cb_arg Pointer to the parameters for the registered
796a9643ea8Slogwang * callback.
797a9643ea8Slogwang *
798a9643ea8Slogwang * @return
799a9643ea8Slogwang * - On success, zero.
800a9643ea8Slogwang * - On failure, a negative value.
801a9643ea8Slogwang */
802a9643ea8Slogwang extern int
803a9643ea8Slogwang rte_cryptodev_callback_register(uint8_t dev_id,
804a9643ea8Slogwang enum rte_cryptodev_event_type event,
805a9643ea8Slogwang rte_cryptodev_cb_fn cb_fn, void *cb_arg);
806a9643ea8Slogwang
807a9643ea8Slogwang /**
808a9643ea8Slogwang * Unregister a callback function for specific device id.
809a9643ea8Slogwang *
810a9643ea8Slogwang * @param dev_id The device identifier.
811a9643ea8Slogwang * @param event Event interested.
812a9643ea8Slogwang * @param cb_fn User supplied callback function to be called.
813a9643ea8Slogwang * @param cb_arg Pointer to the parameters for the registered
814a9643ea8Slogwang * callback.
815a9643ea8Slogwang *
816a9643ea8Slogwang * @return
817a9643ea8Slogwang * - On success, zero.
818a9643ea8Slogwang * - On failure, a negative value.
819a9643ea8Slogwang */
820a9643ea8Slogwang extern int
821a9643ea8Slogwang rte_cryptodev_callback_unregister(uint8_t dev_id,
822a9643ea8Slogwang enum rte_cryptodev_event_type event,
823a9643ea8Slogwang rte_cryptodev_cb_fn cb_fn, void *cb_arg);
824a9643ea8Slogwang
825a9643ea8Slogwang
826a9643ea8Slogwang typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
827a9643ea8Slogwang struct rte_crypto_op **ops, uint16_t nb_ops);
828a9643ea8Slogwang /**< Dequeue processed packets from queue pair of a device. */
829a9643ea8Slogwang
830a9643ea8Slogwang typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
831a9643ea8Slogwang struct rte_crypto_op **ops, uint16_t nb_ops);
832a9643ea8Slogwang /**< Enqueue packets for processing on queue pair of a device. */
833a9643ea8Slogwang
834a9643ea8Slogwang
835a9643ea8Slogwang
836a9643ea8Slogwang
837a9643ea8Slogwang struct rte_cryptodev_callback;
838a9643ea8Slogwang
839a9643ea8Slogwang /** Structure to keep track of registered callbacks */
840a9643ea8Slogwang TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
841a9643ea8Slogwang
842a9643ea8Slogwang /** The data structure associated with each crypto device. */
843a9643ea8Slogwang struct rte_cryptodev {
844a9643ea8Slogwang dequeue_pkt_burst_t dequeue_burst;
845a9643ea8Slogwang /**< Pointer to PMD receive function. */
846a9643ea8Slogwang enqueue_pkt_burst_t enqueue_burst;
847a9643ea8Slogwang /**< Pointer to PMD transmit function. */
848a9643ea8Slogwang
849a9643ea8Slogwang struct rte_cryptodev_data *data;
850a9643ea8Slogwang /**< Pointer to device data */
851a9643ea8Slogwang struct rte_cryptodev_ops *dev_ops;
852a9643ea8Slogwang /**< Functions exported by PMD */
853a9643ea8Slogwang uint64_t feature_flags;
854d30ea906Sjfb8856606 /**< Feature flags exposes HW/SW features for the given device */
8552bfe3f2eSlogwang struct rte_device *device;
8562bfe3f2eSlogwang /**< Backing device */
857a9643ea8Slogwang
8582bfe3f2eSlogwang uint8_t driver_id;
8592bfe3f2eSlogwang /**< Crypto driver identifier*/
860a9643ea8Slogwang
861a9643ea8Slogwang struct rte_cryptodev_cb_list link_intr_cbs;
862a9643ea8Slogwang /**< User application callback for interrupts if present */
863a9643ea8Slogwang
8642bfe3f2eSlogwang void *security_ctx;
8652bfe3f2eSlogwang /**< Context for security ops */
8662bfe3f2eSlogwang
8672bfe3f2eSlogwang __extension__
868a9643ea8Slogwang uint8_t attached : 1;
869a9643ea8Slogwang /**< Flag indicating the device is attached */
870a9643ea8Slogwang } __rte_cache_aligned;
871a9643ea8Slogwang
8722bfe3f2eSlogwang void *
8732bfe3f2eSlogwang rte_cryptodev_get_sec_ctx(uint8_t dev_id);
874a9643ea8Slogwang
875a9643ea8Slogwang /**
876a9643ea8Slogwang *
877a9643ea8Slogwang * The data part, with no function pointers, associated with each device.
878a9643ea8Slogwang *
879a9643ea8Slogwang * This structure is safe to place in shared memory to be common among
880a9643ea8Slogwang * different processes in a multi-process configuration.
881a9643ea8Slogwang */
882a9643ea8Slogwang struct rte_cryptodev_data {
883a9643ea8Slogwang uint8_t dev_id;
884a9643ea8Slogwang /**< Device ID for this instance */
885a9643ea8Slogwang uint8_t socket_id;
886a9643ea8Slogwang /**< Socket ID where memory is allocated */
887a9643ea8Slogwang char name[RTE_CRYPTODEV_NAME_MAX_LEN];
888a9643ea8Slogwang /**< Unique identifier name */
889a9643ea8Slogwang
8902bfe3f2eSlogwang __extension__
891a9643ea8Slogwang uint8_t dev_started : 1;
892a9643ea8Slogwang /**< Device state: STARTED(1)/STOPPED(0) */
893a9643ea8Slogwang
894a9643ea8Slogwang struct rte_mempool *session_pool;
895a9643ea8Slogwang /**< Session memory pool */
896a9643ea8Slogwang void **queue_pairs;
897a9643ea8Slogwang /**< Array of pointers to queue pairs. */
898a9643ea8Slogwang uint16_t nb_queue_pairs;
899a9643ea8Slogwang /**< Number of device queue pairs. */
900a9643ea8Slogwang
901a9643ea8Slogwang void *dev_private;
902a9643ea8Slogwang /**< PMD-specific private data */
903a9643ea8Slogwang } __rte_cache_aligned;
904a9643ea8Slogwang
905a9643ea8Slogwang extern struct rte_cryptodev *rte_cryptodevs;
906a9643ea8Slogwang /**
907a9643ea8Slogwang *
908a9643ea8Slogwang * Dequeue a burst of processed crypto operations from a queue on the crypto
909a9643ea8Slogwang * device. The dequeued operation are stored in *rte_crypto_op* structures
910a9643ea8Slogwang * whose pointers are supplied in the *ops* array.
911a9643ea8Slogwang *
912a9643ea8Slogwang * The rte_cryptodev_dequeue_burst() function returns the number of ops
913a9643ea8Slogwang * actually dequeued, which is the number of *rte_crypto_op* data structures
914a9643ea8Slogwang * effectively supplied into the *ops* array.
915a9643ea8Slogwang *
916a9643ea8Slogwang * A return value equal to *nb_ops* indicates that the queue contained
917a9643ea8Slogwang * at least *nb_ops* operations, and this is likely to signify that other
918a9643ea8Slogwang * processed operations remain in the devices output queue. Applications
919a9643ea8Slogwang * implementing a "retrieve as many processed operations as possible" policy
920a9643ea8Slogwang * can check this specific case and keep invoking the
921a9643ea8Slogwang * rte_cryptodev_dequeue_burst() function until a value less than
922a9643ea8Slogwang * *nb_ops* is returned.
923a9643ea8Slogwang *
924a9643ea8Slogwang * The rte_cryptodev_dequeue_burst() function does not provide any error
925a9643ea8Slogwang * notification to avoid the corresponding overhead.
926a9643ea8Slogwang *
927a9643ea8Slogwang * @param dev_id The symmetric crypto device identifier
928a9643ea8Slogwang * @param qp_id The index of the queue pair from which to
929a9643ea8Slogwang * retrieve processed packets. The value must be
930a9643ea8Slogwang * in the range [0, nb_queue_pair - 1] previously
931a9643ea8Slogwang * supplied to rte_cryptodev_configure().
932a9643ea8Slogwang * @param ops The address of an array of pointers to
933a9643ea8Slogwang * *rte_crypto_op* structures that must be
934a9643ea8Slogwang * large enough to store *nb_ops* pointers in it.
935a9643ea8Slogwang * @param nb_ops The maximum number of operations to dequeue.
936a9643ea8Slogwang *
937a9643ea8Slogwang * @return
938a9643ea8Slogwang * - The number of operations actually dequeued, which is the number
939a9643ea8Slogwang * of pointers to *rte_crypto_op* structures effectively supplied to the
940a9643ea8Slogwang * *ops* array.
941a9643ea8Slogwang */
942a9643ea8Slogwang static inline uint16_t
rte_cryptodev_dequeue_burst(uint8_t dev_id,uint16_t qp_id,struct rte_crypto_op ** ops,uint16_t nb_ops)943a9643ea8Slogwang rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
944a9643ea8Slogwang struct rte_crypto_op **ops, uint16_t nb_ops)
945a9643ea8Slogwang {
946a9643ea8Slogwang struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
947a9643ea8Slogwang
948a9643ea8Slogwang nb_ops = (*dev->dequeue_burst)
949a9643ea8Slogwang (dev->data->queue_pairs[qp_id], ops, nb_ops);
950a9643ea8Slogwang
951*2d9fd380Sjfb8856606 rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
952a9643ea8Slogwang return nb_ops;
953a9643ea8Slogwang }
954a9643ea8Slogwang
955a9643ea8Slogwang /**
956a9643ea8Slogwang * Enqueue a burst of operations for processing on a crypto device.
957a9643ea8Slogwang *
958a9643ea8Slogwang * The rte_cryptodev_enqueue_burst() function is invoked to place
959a9643ea8Slogwang * crypto operations on the queue *qp_id* of the device designated by
960a9643ea8Slogwang * its *dev_id*.
961a9643ea8Slogwang *
962a9643ea8Slogwang * The *nb_ops* parameter is the number of operations to process which are
963a9643ea8Slogwang * supplied in the *ops* array of *rte_crypto_op* structures.
964a9643ea8Slogwang *
965a9643ea8Slogwang * The rte_cryptodev_enqueue_burst() function returns the number of
966a9643ea8Slogwang * operations it actually enqueued for processing. A return value equal to
967a9643ea8Slogwang * *nb_ops* means that all packets have been enqueued.
968a9643ea8Slogwang *
969a9643ea8Slogwang * @param dev_id The identifier of the device.
970a9643ea8Slogwang * @param qp_id The index of the queue pair which packets are
971a9643ea8Slogwang * to be enqueued for processing. The value
972a9643ea8Slogwang * must be in the range [0, nb_queue_pairs - 1]
973a9643ea8Slogwang * previously supplied to
974a9643ea8Slogwang * *rte_cryptodev_configure*.
975a9643ea8Slogwang * @param ops The address of an array of *nb_ops* pointers
976a9643ea8Slogwang * to *rte_crypto_op* structures which contain
977a9643ea8Slogwang * the crypto operations to be processed.
978a9643ea8Slogwang * @param nb_ops The number of operations to process.
979a9643ea8Slogwang *
980a9643ea8Slogwang * @return
981a9643ea8Slogwang * The number of operations actually enqueued on the crypto device. The return
982a9643ea8Slogwang * value can be less than the value of the *nb_ops* parameter when the
983a9643ea8Slogwang * crypto devices queue is full or if invalid parameters are specified in
984a9643ea8Slogwang * a *rte_crypto_op*.
985a9643ea8Slogwang */
986a9643ea8Slogwang static inline uint16_t
rte_cryptodev_enqueue_burst(uint8_t dev_id,uint16_t qp_id,struct rte_crypto_op ** ops,uint16_t nb_ops)987a9643ea8Slogwang rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
988a9643ea8Slogwang struct rte_crypto_op **ops, uint16_t nb_ops)
989a9643ea8Slogwang {
990a9643ea8Slogwang struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
991a9643ea8Slogwang
992*2d9fd380Sjfb8856606 rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
993a9643ea8Slogwang return (*dev->enqueue_burst)(
994a9643ea8Slogwang dev->data->queue_pairs[qp_id], ops, nb_ops);
995a9643ea8Slogwang }
996a9643ea8Slogwang
997a9643ea8Slogwang
998d30ea906Sjfb8856606 /** Cryptodev symmetric crypto session
999d30ea906Sjfb8856606 * Each session is derived from a fixed xform chain. Therefore each session
1000d30ea906Sjfb8856606 * has a fixed algo, key, op-type, digest_len etc.
1001d30ea906Sjfb8856606 */
1002a9643ea8Slogwang struct rte_cryptodev_sym_session {
10034418919fSjohnjiang uint64_t opaque_data;
10044418919fSjohnjiang /**< Can be used for external metadata */
10054418919fSjohnjiang uint16_t nb_drivers;
10064418919fSjohnjiang /**< number of elements in sess_data array */
10074418919fSjohnjiang uint16_t user_data_sz;
10084418919fSjohnjiang /**< session user data will be placed after sess_data */
10094418919fSjohnjiang __extension__ struct {
10104418919fSjohnjiang void *data;
10114418919fSjohnjiang uint16_t refcnt;
10124418919fSjohnjiang } sess_data[0];
10134418919fSjohnjiang /**< Driver specific session material, variable size */
1014a9643ea8Slogwang };
1015a9643ea8Slogwang
1016d30ea906Sjfb8856606 /** Cryptodev asymmetric crypto session */
1017d30ea906Sjfb8856606 struct rte_cryptodev_asym_session {
1018d30ea906Sjfb8856606 __extension__ void *sess_private_data[0];
1019d30ea906Sjfb8856606 /**< Private asymmetric session material */
1020d30ea906Sjfb8856606 };
1021a9643ea8Slogwang
1022a9643ea8Slogwang /**
10234418919fSjohnjiang * Create a symmetric session mempool.
10244418919fSjohnjiang *
10254418919fSjohnjiang * @param name
10264418919fSjohnjiang * The unique mempool name.
10274418919fSjohnjiang * @param nb_elts
10284418919fSjohnjiang * The number of elements in the mempool.
10294418919fSjohnjiang * @param elt_size
10304418919fSjohnjiang * The size of the element. This value will be ignored if it is smaller than
10314418919fSjohnjiang * the minimum session header size required for the system. For the user who
10324418919fSjohnjiang * want to use the same mempool for sym session and session private data it
10334418919fSjohnjiang * can be the maximum value of all existing devices' private data and session
10344418919fSjohnjiang * header sizes.
10354418919fSjohnjiang * @param cache_size
10364418919fSjohnjiang * The number of per-lcore cache elements
10374418919fSjohnjiang * @param priv_size
10384418919fSjohnjiang * The private data size of each session.
10394418919fSjohnjiang * @param socket_id
10404418919fSjohnjiang * The *socket_id* argument is the socket identifier in the case of
10414418919fSjohnjiang * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
10424418919fSjohnjiang * constraint for the reserved zone.
10434418919fSjohnjiang *
10444418919fSjohnjiang * @return
10454418919fSjohnjiang * - On success return size of the session
10464418919fSjohnjiang * - On failure returns 0
10474418919fSjohnjiang */
10484418919fSjohnjiang __rte_experimental
10494418919fSjohnjiang struct rte_mempool *
10504418919fSjohnjiang rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
10514418919fSjohnjiang uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
10524418919fSjohnjiang int socket_id);
10534418919fSjohnjiang
10544418919fSjohnjiang /**
10552bfe3f2eSlogwang * Create symmetric crypto session header (generic with no private data)
1056a9643ea8Slogwang *
10572bfe3f2eSlogwang * @param mempool Symmetric session mempool to allocate session
10582bfe3f2eSlogwang * objects from
1059a9643ea8Slogwang * @return
10602bfe3f2eSlogwang * - On success return pointer to sym-session
10612bfe3f2eSlogwang * - On failure returns NULL
1062a9643ea8Slogwang */
10632bfe3f2eSlogwang struct rte_cryptodev_sym_session *
10642bfe3f2eSlogwang rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
1065a9643ea8Slogwang
1066a9643ea8Slogwang /**
1067d30ea906Sjfb8856606 * Create asymmetric crypto session header (generic with no private data)
1068d30ea906Sjfb8856606 *
1069d30ea906Sjfb8856606 * @param mempool mempool to allocate asymmetric session
1070d30ea906Sjfb8856606 * objects from
1071d30ea906Sjfb8856606 * @return
1072d30ea906Sjfb8856606 * - On success return pointer to asym-session
1073d30ea906Sjfb8856606 * - On failure returns NULL
1074d30ea906Sjfb8856606 */
10754418919fSjohnjiang __rte_experimental
10764418919fSjohnjiang struct rte_cryptodev_asym_session *
1077d30ea906Sjfb8856606 rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
1078d30ea906Sjfb8856606
1079d30ea906Sjfb8856606 /**
10802bfe3f2eSlogwang * Frees symmetric crypto session header, after checking that all
10812bfe3f2eSlogwang * the device private data has been freed, returning it
10822bfe3f2eSlogwang * to its original mempool.
10832bfe3f2eSlogwang *
10842bfe3f2eSlogwang * @param sess Session header to be freed.
10852bfe3f2eSlogwang *
10862bfe3f2eSlogwang * @return
10872bfe3f2eSlogwang * - 0 if successful.
10882bfe3f2eSlogwang * - -EINVAL if session is NULL.
10892bfe3f2eSlogwang * - -EBUSY if not all device private data has been freed.
10902bfe3f2eSlogwang */
10912bfe3f2eSlogwang int
10922bfe3f2eSlogwang rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
10932bfe3f2eSlogwang
10942bfe3f2eSlogwang /**
1095d30ea906Sjfb8856606 * Frees asymmetric crypto session header, after checking that all
1096d30ea906Sjfb8856606 * the device private data has been freed, returning it
1097d30ea906Sjfb8856606 * to its original mempool.
1098d30ea906Sjfb8856606 *
1099d30ea906Sjfb8856606 * @param sess Session header to be freed.
1100d30ea906Sjfb8856606 *
1101d30ea906Sjfb8856606 * @return
1102d30ea906Sjfb8856606 * - 0 if successful.
1103d30ea906Sjfb8856606 * - -EINVAL if session is NULL.
1104d30ea906Sjfb8856606 * - -EBUSY if not all device private data has been freed.
1105d30ea906Sjfb8856606 */
11064418919fSjohnjiang __rte_experimental
11074418919fSjohnjiang int
1108d30ea906Sjfb8856606 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
1109d30ea906Sjfb8856606
1110d30ea906Sjfb8856606 /**
11112bfe3f2eSlogwang * Fill out private data for the device id, based on its device type.
11122bfe3f2eSlogwang *
11132bfe3f2eSlogwang * @param dev_id ID of device that we want the session to be used on
11142bfe3f2eSlogwang * @param sess Session where the private data will be attached to
11152bfe3f2eSlogwang * @param xforms Symmetric crypto transform operations to apply on flow
11162bfe3f2eSlogwang * processed with this session
11172bfe3f2eSlogwang * @param mempool Mempool where the private data is allocated.
11182bfe3f2eSlogwang *
11192bfe3f2eSlogwang * @return
11202bfe3f2eSlogwang * - On success, zero.
11212bfe3f2eSlogwang * - -EINVAL if input parameters are invalid.
1122d30ea906Sjfb8856606 * - -ENOTSUP if crypto device does not support the crypto transform or
1123d30ea906Sjfb8856606 * does not support symmetric operations.
11242bfe3f2eSlogwang * - -ENOMEM if the private session could not be allocated.
11252bfe3f2eSlogwang */
11262bfe3f2eSlogwang int
11272bfe3f2eSlogwang rte_cryptodev_sym_session_init(uint8_t dev_id,
11282bfe3f2eSlogwang struct rte_cryptodev_sym_session *sess,
11292bfe3f2eSlogwang struct rte_crypto_sym_xform *xforms,
11302bfe3f2eSlogwang struct rte_mempool *mempool);
11312bfe3f2eSlogwang
11322bfe3f2eSlogwang /**
1133d30ea906Sjfb8856606 * Initialize asymmetric session on a device with specific asymmetric xform
1134d30ea906Sjfb8856606 *
1135d30ea906Sjfb8856606 * @param dev_id ID of device that we want the session to be used on
1136d30ea906Sjfb8856606 * @param sess Session to be set up on a device
1137d30ea906Sjfb8856606 * @param xforms Asymmetric crypto transform operations to apply on flow
1138d30ea906Sjfb8856606 * processed with this session
1139d30ea906Sjfb8856606 * @param mempool Mempool to be used for internal allocation.
1140d30ea906Sjfb8856606 *
1141d30ea906Sjfb8856606 * @return
1142d30ea906Sjfb8856606 * - On success, zero.
1143d30ea906Sjfb8856606 * - -EINVAL if input parameters are invalid.
1144d30ea906Sjfb8856606 * - -ENOTSUP if crypto device does not support the crypto transform.
1145d30ea906Sjfb8856606 * - -ENOMEM if the private session could not be allocated.
1146d30ea906Sjfb8856606 */
11474418919fSjohnjiang __rte_experimental
11484418919fSjohnjiang int
1149d30ea906Sjfb8856606 rte_cryptodev_asym_session_init(uint8_t dev_id,
1150d30ea906Sjfb8856606 struct rte_cryptodev_asym_session *sess,
1151d30ea906Sjfb8856606 struct rte_crypto_asym_xform *xforms,
1152d30ea906Sjfb8856606 struct rte_mempool *mempool);
1153d30ea906Sjfb8856606
1154d30ea906Sjfb8856606 /**
11552bfe3f2eSlogwang * Frees private data for the device id, based on its device type,
1156d30ea906Sjfb8856606 * returning it to its mempool. It is the application's responsibility
1157d30ea906Sjfb8856606 * to ensure that private session data is not cleared while there are
1158d30ea906Sjfb8856606 * still in-flight operations using it.
11592bfe3f2eSlogwang *
11602bfe3f2eSlogwang * @param dev_id ID of device that uses the session.
11612bfe3f2eSlogwang * @param sess Session containing the reference to the private data
11622bfe3f2eSlogwang *
11632bfe3f2eSlogwang * @return
11642bfe3f2eSlogwang * - 0 if successful.
11652bfe3f2eSlogwang * - -EINVAL if device is invalid or session is NULL.
1166d30ea906Sjfb8856606 * - -ENOTSUP if crypto device does not support symmetric operations.
11672bfe3f2eSlogwang */
11682bfe3f2eSlogwang int
11692bfe3f2eSlogwang rte_cryptodev_sym_session_clear(uint8_t dev_id,
11702bfe3f2eSlogwang struct rte_cryptodev_sym_session *sess);
11712bfe3f2eSlogwang
11722bfe3f2eSlogwang /**
1173d30ea906Sjfb8856606 * Frees resources held by asymmetric session during rte_cryptodev_session_init
1174d30ea906Sjfb8856606 *
1175d30ea906Sjfb8856606 * @param dev_id ID of device that uses the asymmetric session.
1176d30ea906Sjfb8856606 * @param sess Asymmetric session setup on device using
1177d30ea906Sjfb8856606 * rte_cryptodev_session_init
1178d30ea906Sjfb8856606 * @return
1179d30ea906Sjfb8856606 * - 0 if successful.
1180d30ea906Sjfb8856606 * - -EINVAL if device is invalid or session is NULL.
1181d30ea906Sjfb8856606 */
11824418919fSjohnjiang __rte_experimental
11834418919fSjohnjiang int
1184d30ea906Sjfb8856606 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1185d30ea906Sjfb8856606 struct rte_cryptodev_asym_session *sess);
1186d30ea906Sjfb8856606
1187d30ea906Sjfb8856606 /**
11884418919fSjohnjiang * Get the size of the header session, for all registered drivers excluding
11894418919fSjohnjiang * the user data size.
11902bfe3f2eSlogwang *
11912bfe3f2eSlogwang * @return
11921646932aSjfb8856606 * Size of the symmetric header session.
11932bfe3f2eSlogwang */
11942bfe3f2eSlogwang unsigned int
1195d30ea906Sjfb8856606 rte_cryptodev_sym_get_header_session_size(void);
11962bfe3f2eSlogwang
11972bfe3f2eSlogwang /**
11984418919fSjohnjiang * Get the size of the header session from created session.
11994418919fSjohnjiang *
12004418919fSjohnjiang * @param sess
12014418919fSjohnjiang * The sym cryptodev session pointer
12024418919fSjohnjiang *
12034418919fSjohnjiang * @return
12044418919fSjohnjiang * - If sess is not NULL, return the size of the header session including
12054418919fSjohnjiang * the private data size defined within sess.
12064418919fSjohnjiang * - If sess is NULL, return 0.
12074418919fSjohnjiang */
12084418919fSjohnjiang __rte_experimental
12094418919fSjohnjiang unsigned int
12104418919fSjohnjiang rte_cryptodev_sym_get_existing_header_session_size(
12114418919fSjohnjiang struct rte_cryptodev_sym_session *sess);
12124418919fSjohnjiang
12134418919fSjohnjiang /**
1214d30ea906Sjfb8856606 * Get the size of the asymmetric session header, for all registered drivers.
1215d30ea906Sjfb8856606 *
1216d30ea906Sjfb8856606 * @return
1217d30ea906Sjfb8856606 * Size of the asymmetric header session.
1218d30ea906Sjfb8856606 */
12194418919fSjohnjiang __rte_experimental
12204418919fSjohnjiang unsigned int
1221d30ea906Sjfb8856606 rte_cryptodev_asym_get_header_session_size(void);
1222d30ea906Sjfb8856606
1223d30ea906Sjfb8856606 /**
1224d30ea906Sjfb8856606 * Get the size of the private symmetric session data
1225d30ea906Sjfb8856606 * for a device.
1226a9643ea8Slogwang *
1227a9643ea8Slogwang * @param dev_id The device identifier.
12282bfe3f2eSlogwang *
12292bfe3f2eSlogwang * @return
12302bfe3f2eSlogwang * - Size of the private data, if successful
1231d30ea906Sjfb8856606 * - 0 if device is invalid or does not have private
1232d30ea906Sjfb8856606 * symmetric session
1233a9643ea8Slogwang */
12345af785ecSfengbojiang(姜凤波) unsigned int
1235d30ea906Sjfb8856606 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
12365af785ecSfengbojiang(姜凤波)
12375af785ecSfengbojiang(姜凤波) /**
1238d30ea906Sjfb8856606 * Get the size of the private data for asymmetric session
1239d30ea906Sjfb8856606 * on device
12405af785ecSfengbojiang(姜凤波) *
1241d30ea906Sjfb8856606 * @param dev_id The device identifier.
12425af785ecSfengbojiang(姜凤波) *
12435af785ecSfengbojiang(姜凤波) * @return
1244d30ea906Sjfb8856606 * - Size of the asymmetric private data, if successful
1245d30ea906Sjfb8856606 * - 0 if device is invalid or does not have private session
12465af785ecSfengbojiang(姜凤波) */
12474418919fSjohnjiang __rte_experimental
12484418919fSjohnjiang unsigned int
1249d30ea906Sjfb8856606 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
12502bfe3f2eSlogwang
12512bfe3f2eSlogwang /**
12522bfe3f2eSlogwang * Provide driver identifier.
12532bfe3f2eSlogwang *
12542bfe3f2eSlogwang * @param name
12552bfe3f2eSlogwang * The pointer to a driver name.
12562bfe3f2eSlogwang * @return
12572bfe3f2eSlogwang * The driver type identifier or -1 if no driver found
12582bfe3f2eSlogwang */
12592bfe3f2eSlogwang int rte_cryptodev_driver_id_get(const char *name);
12602bfe3f2eSlogwang
12612bfe3f2eSlogwang /**
12622bfe3f2eSlogwang * Provide driver name.
12632bfe3f2eSlogwang *
12642bfe3f2eSlogwang * @param driver_id
12652bfe3f2eSlogwang * The driver identifier.
12662bfe3f2eSlogwang * @return
12672bfe3f2eSlogwang * The driver name or null if no driver found
12682bfe3f2eSlogwang */
12692bfe3f2eSlogwang const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1270a9643ea8Slogwang
1271d30ea906Sjfb8856606 /**
1272d30ea906Sjfb8856606 * Store user data in a session.
1273d30ea906Sjfb8856606 *
1274d30ea906Sjfb8856606 * @param sess Session pointer allocated by
1275d30ea906Sjfb8856606 * *rte_cryptodev_sym_session_create*.
1276d30ea906Sjfb8856606 * @param data Pointer to the user data.
1277d30ea906Sjfb8856606 * @param size Size of the user data.
1278d30ea906Sjfb8856606 *
1279d30ea906Sjfb8856606 * @return
1280d30ea906Sjfb8856606 * - On success, zero.
1281d30ea906Sjfb8856606 * - On failure, a negative value.
1282d30ea906Sjfb8856606 */
12834418919fSjohnjiang __rte_experimental
12844418919fSjohnjiang int
1285d30ea906Sjfb8856606 rte_cryptodev_sym_session_set_user_data(
1286d30ea906Sjfb8856606 struct rte_cryptodev_sym_session *sess,
1287d30ea906Sjfb8856606 void *data,
1288d30ea906Sjfb8856606 uint16_t size);
1289d30ea906Sjfb8856606
1290d30ea906Sjfb8856606 /**
1291d30ea906Sjfb8856606 * Get user data stored in a session.
1292d30ea906Sjfb8856606 *
1293d30ea906Sjfb8856606 * @param sess Session pointer allocated by
1294d30ea906Sjfb8856606 * *rte_cryptodev_sym_session_create*.
1295d30ea906Sjfb8856606 *
1296d30ea906Sjfb8856606 * @return
1297d30ea906Sjfb8856606 * - On success return pointer to user data.
1298d30ea906Sjfb8856606 * - On failure returns NULL.
1299d30ea906Sjfb8856606 */
13004418919fSjohnjiang __rte_experimental
13014418919fSjohnjiang void *
1302d30ea906Sjfb8856606 rte_cryptodev_sym_session_get_user_data(
1303d30ea906Sjfb8856606 struct rte_cryptodev_sym_session *sess);
1304d30ea906Sjfb8856606
1305*2d9fd380Sjfb8856606 /**
1306*2d9fd380Sjfb8856606 * Perform actual crypto processing (encrypt/digest or auth/decrypt)
1307*2d9fd380Sjfb8856606 * on user provided data.
1308*2d9fd380Sjfb8856606 *
1309*2d9fd380Sjfb8856606 * @param dev_id The device identifier.
1310*2d9fd380Sjfb8856606 * @param sess Cryptodev session structure
1311*2d9fd380Sjfb8856606 * @param ofs Start and stop offsets for auth and cipher operations
1312*2d9fd380Sjfb8856606 * @param vec Vectorized operation descriptor
1313*2d9fd380Sjfb8856606 *
1314*2d9fd380Sjfb8856606 * @return
1315*2d9fd380Sjfb8856606 * - Returns number of successfully processed packets.
1316*2d9fd380Sjfb8856606 */
1317*2d9fd380Sjfb8856606 __rte_experimental
1318*2d9fd380Sjfb8856606 uint32_t
1319*2d9fd380Sjfb8856606 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
1320*2d9fd380Sjfb8856606 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
1321*2d9fd380Sjfb8856606 struct rte_crypto_sym_vec *vec);
1322*2d9fd380Sjfb8856606
1323*2d9fd380Sjfb8856606 /**
1324*2d9fd380Sjfb8856606 * Get the size of the raw data-path context buffer.
1325*2d9fd380Sjfb8856606 *
1326*2d9fd380Sjfb8856606 * @param dev_id The device identifier.
1327*2d9fd380Sjfb8856606 *
1328*2d9fd380Sjfb8856606 * @return
1329*2d9fd380Sjfb8856606 * - If the device supports raw data-path APIs, return the context size.
1330*2d9fd380Sjfb8856606 * - If the device does not support the APIs, return -1.
1331*2d9fd380Sjfb8856606 */
1332*2d9fd380Sjfb8856606 __rte_experimental
1333*2d9fd380Sjfb8856606 int
1334*2d9fd380Sjfb8856606 rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id);
1335*2d9fd380Sjfb8856606
1336*2d9fd380Sjfb8856606 /**
1337*2d9fd380Sjfb8856606 * Union of different crypto session types, including session-less xform
1338*2d9fd380Sjfb8856606 * pointer.
1339*2d9fd380Sjfb8856606 */
1340*2d9fd380Sjfb8856606 union rte_cryptodev_session_ctx {
1341*2d9fd380Sjfb8856606 struct rte_cryptodev_sym_session *crypto_sess;
1342*2d9fd380Sjfb8856606 struct rte_crypto_sym_xform *xform;
1343*2d9fd380Sjfb8856606 struct rte_security_session *sec_sess;
1344*2d9fd380Sjfb8856606 };
1345*2d9fd380Sjfb8856606
1346*2d9fd380Sjfb8856606 /**
1347*2d9fd380Sjfb8856606 * Enqueue a vectorized operation descriptor into the device queue but the
1348*2d9fd380Sjfb8856606 * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1349*2d9fd380Sjfb8856606 * is called.
1350*2d9fd380Sjfb8856606 *
1351*2d9fd380Sjfb8856606 * @param qp Driver specific queue pair data.
1352*2d9fd380Sjfb8856606 * @param drv_ctx Driver specific context data.
1353*2d9fd380Sjfb8856606 * @param vec Vectorized operation descriptor.
1354*2d9fd380Sjfb8856606 * @param ofs Start and stop offsets for auth and cipher
1355*2d9fd380Sjfb8856606 * operations.
1356*2d9fd380Sjfb8856606 * @param user_data The array of user data for dequeue later.
1357*2d9fd380Sjfb8856606 * @param enqueue_status Driver written value to specify the
1358*2d9fd380Sjfb8856606 * enqueue status. Possible values:
1359*2d9fd380Sjfb8856606 * - 1: The number of operations returned are
1360*2d9fd380Sjfb8856606 * enqueued successfully.
1361*2d9fd380Sjfb8856606 * - 0: The number of operations returned are
1362*2d9fd380Sjfb8856606 * cached into the queue but are not processed
1363*2d9fd380Sjfb8856606 * until rte_cryptodev_raw_enqueue_done() is
1364*2d9fd380Sjfb8856606 * called.
1365*2d9fd380Sjfb8856606 * - negative integer: Error occurred.
1366*2d9fd380Sjfb8856606 * @return
1367*2d9fd380Sjfb8856606 * - The number of operations in the descriptor successfully enqueued or
1368*2d9fd380Sjfb8856606 * cached into the queue but not enqueued yet, depends on the
1369*2d9fd380Sjfb8856606 * "enqueue_status" value.
1370*2d9fd380Sjfb8856606 */
1371*2d9fd380Sjfb8856606 typedef uint32_t (*cryptodev_sym_raw_enqueue_burst_t)(
1372*2d9fd380Sjfb8856606 void *qp, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1373*2d9fd380Sjfb8856606 union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status);
1374*2d9fd380Sjfb8856606
1375*2d9fd380Sjfb8856606 /**
1376*2d9fd380Sjfb8856606 * Enqueue single raw data vector into the device queue but the driver may or
1377*2d9fd380Sjfb8856606 * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1378*2d9fd380Sjfb8856606 *
1379*2d9fd380Sjfb8856606 * @param qp Driver specific queue pair data.
1380*2d9fd380Sjfb8856606 * @param drv_ctx Driver specific context data.
1381*2d9fd380Sjfb8856606 * @param data_vec The buffer data vector.
1382*2d9fd380Sjfb8856606 * @param n_data_vecs Number of buffer data vectors.
1383*2d9fd380Sjfb8856606 * @param ofs Start and stop offsets for auth and cipher
1384*2d9fd380Sjfb8856606 * operations.
1385*2d9fd380Sjfb8856606 * @param iv IV virtual and IOVA addresses
1386*2d9fd380Sjfb8856606 * @param digest digest virtual and IOVA addresses
1387*2d9fd380Sjfb8856606 * @param aad_or_auth_iv AAD or auth IV virtual and IOVA addresses,
1388*2d9fd380Sjfb8856606 * depends on the algorithm used.
1389*2d9fd380Sjfb8856606 * @param user_data The user data.
1390*2d9fd380Sjfb8856606 * @return
1391*2d9fd380Sjfb8856606 * - 1: The data vector is enqueued successfully.
1392*2d9fd380Sjfb8856606 * - 0: The data vector is cached into the queue but is not processed
1393*2d9fd380Sjfb8856606 * until rte_cryptodev_raw_enqueue_done() is called.
1394*2d9fd380Sjfb8856606 * - negative integer: failure.
1395*2d9fd380Sjfb8856606 */
1396*2d9fd380Sjfb8856606 typedef int (*cryptodev_sym_raw_enqueue_t)(
1397*2d9fd380Sjfb8856606 void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1398*2d9fd380Sjfb8856606 uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1399*2d9fd380Sjfb8856606 struct rte_crypto_va_iova_ptr *iv,
1400*2d9fd380Sjfb8856606 struct rte_crypto_va_iova_ptr *digest,
1401*2d9fd380Sjfb8856606 struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1402*2d9fd380Sjfb8856606 void *user_data);
1403*2d9fd380Sjfb8856606
1404*2d9fd380Sjfb8856606 /**
1405*2d9fd380Sjfb8856606 * Inform the cryptodev queue pair to start processing or finish dequeuing all
1406*2d9fd380Sjfb8856606 * enqueued/dequeued operations.
1407*2d9fd380Sjfb8856606 *
1408*2d9fd380Sjfb8856606 * @param qp Driver specific queue pair data.
1409*2d9fd380Sjfb8856606 * @param drv_ctx Driver specific context data.
1410*2d9fd380Sjfb8856606 * @param n The total number of processed operations.
1411*2d9fd380Sjfb8856606 * @return
1412*2d9fd380Sjfb8856606 * - On success return 0.
1413*2d9fd380Sjfb8856606 * - On failure return negative integer.
1414*2d9fd380Sjfb8856606 */
1415*2d9fd380Sjfb8856606 typedef int (*cryptodev_sym_raw_operation_done_t)(void *qp, uint8_t *drv_ctx,
1416*2d9fd380Sjfb8856606 uint32_t n);
1417*2d9fd380Sjfb8856606
1418*2d9fd380Sjfb8856606 /**
1419*2d9fd380Sjfb8856606 * Typedef that the user provided for the driver to get the dequeue count.
1420*2d9fd380Sjfb8856606 * The function may return a fixed number or the number parsed from the user
1421*2d9fd380Sjfb8856606 * data stored in the first processed operation.
1422*2d9fd380Sjfb8856606 *
1423*2d9fd380Sjfb8856606 * @param user_data Dequeued user data.
1424*2d9fd380Sjfb8856606 * @return
1425*2d9fd380Sjfb8856606 * - The number of operations to be dequeued.
1426*2d9fd380Sjfb8856606 **/
1427*2d9fd380Sjfb8856606 typedef uint32_t (*rte_cryptodev_raw_get_dequeue_count_t)(void *user_data);
1428*2d9fd380Sjfb8856606
1429*2d9fd380Sjfb8856606 /**
1430*2d9fd380Sjfb8856606 * Typedef that the user provided to deal with post dequeue operation, such
1431*2d9fd380Sjfb8856606 * as filling status.
1432*2d9fd380Sjfb8856606 *
1433*2d9fd380Sjfb8856606 * @param user_data Dequeued user data.
1434*2d9fd380Sjfb8856606 * @param index Index number of the processed descriptor.
1435*2d9fd380Sjfb8856606 * @param is_op_success Operation status provided by the driver.
1436*2d9fd380Sjfb8856606 **/
1437*2d9fd380Sjfb8856606 typedef void (*rte_cryptodev_raw_post_dequeue_t)(void *user_data,
1438*2d9fd380Sjfb8856606 uint32_t index, uint8_t is_op_success);
1439*2d9fd380Sjfb8856606
1440*2d9fd380Sjfb8856606 /**
1441*2d9fd380Sjfb8856606 * Dequeue a burst of symmetric crypto processing.
1442*2d9fd380Sjfb8856606 *
1443*2d9fd380Sjfb8856606 * @param qp Driver specific queue pair data.
1444*2d9fd380Sjfb8856606 * @param drv_ctx Driver specific context data.
1445*2d9fd380Sjfb8856606 * @param get_dequeue_count User provided callback function to
1446*2d9fd380Sjfb8856606 * obtain dequeue operation count.
1447*2d9fd380Sjfb8856606 * @param post_dequeue User provided callback function to
1448*2d9fd380Sjfb8856606 * post-process a dequeued operation.
1449*2d9fd380Sjfb8856606 * @param out_user_data User data pointer array to be retrieve
1450*2d9fd380Sjfb8856606 * from device queue. In case of
1451*2d9fd380Sjfb8856606 * *is_user_data_array* is set there
1452*2d9fd380Sjfb8856606 * should be enough room to store all
1453*2d9fd380Sjfb8856606 * user data.
1454*2d9fd380Sjfb8856606 * @param is_user_data_array Set 1 if every dequeued user data will
1455*2d9fd380Sjfb8856606 * be written into out_user_data array.
1456*2d9fd380Sjfb8856606 * Set 0 if only the first user data will
1457*2d9fd380Sjfb8856606 * be written into out_user_data array.
1458*2d9fd380Sjfb8856606 * @param n_success Driver written value to specific the
1459*2d9fd380Sjfb8856606 * total successful operations count.
1460*2d9fd380Sjfb8856606 * @param dequeue_status Driver written value to specify the
1461*2d9fd380Sjfb8856606 * dequeue status. Possible values:
1462*2d9fd380Sjfb8856606 * - 1: Successfully dequeued the number
1463*2d9fd380Sjfb8856606 * of operations returned. The user
1464*2d9fd380Sjfb8856606 * data previously set during enqueue
1465*2d9fd380Sjfb8856606 * is stored in the "out_user_data".
1466*2d9fd380Sjfb8856606 * - 0: The number of operations returned
1467*2d9fd380Sjfb8856606 * are completed and the user data is
1468*2d9fd380Sjfb8856606 * stored in the "out_user_data", but
1469*2d9fd380Sjfb8856606 * they are not freed from the queue
1470*2d9fd380Sjfb8856606 * until
1471*2d9fd380Sjfb8856606 * rte_cryptodev_raw_dequeue_done()
1472*2d9fd380Sjfb8856606 * is called.
1473*2d9fd380Sjfb8856606 * - negative integer: Error occurred.
1474*2d9fd380Sjfb8856606 * @return
1475*2d9fd380Sjfb8856606 * - The number of operations dequeued or completed but not freed from the
1476*2d9fd380Sjfb8856606 * queue, depends on "dequeue_status" value.
1477*2d9fd380Sjfb8856606 */
1478*2d9fd380Sjfb8856606 typedef uint32_t (*cryptodev_sym_raw_dequeue_burst_t)(void *qp,
1479*2d9fd380Sjfb8856606 uint8_t *drv_ctx,
1480*2d9fd380Sjfb8856606 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1481*2d9fd380Sjfb8856606 rte_cryptodev_raw_post_dequeue_t post_dequeue,
1482*2d9fd380Sjfb8856606 void **out_user_data, uint8_t is_user_data_array,
1483*2d9fd380Sjfb8856606 uint32_t *n_success, int *dequeue_status);
1484*2d9fd380Sjfb8856606
1485*2d9fd380Sjfb8856606 /**
1486*2d9fd380Sjfb8856606 * Dequeue a symmetric crypto processing.
1487*2d9fd380Sjfb8856606 *
1488*2d9fd380Sjfb8856606 * @param qp Driver specific queue pair data.
1489*2d9fd380Sjfb8856606 * @param drv_ctx Driver specific context data.
1490*2d9fd380Sjfb8856606 * @param dequeue_status Driver written value to specify the
1491*2d9fd380Sjfb8856606 * dequeue status. Possible values:
1492*2d9fd380Sjfb8856606 * - 1: Successfully dequeued a operation.
1493*2d9fd380Sjfb8856606 * The user data is returned.
1494*2d9fd380Sjfb8856606 * - 0: The first operation in the queue
1495*2d9fd380Sjfb8856606 * is completed and the user data
1496*2d9fd380Sjfb8856606 * previously set during enqueue is
1497*2d9fd380Sjfb8856606 * returned, but it is not freed from
1498*2d9fd380Sjfb8856606 * the queue until
1499*2d9fd380Sjfb8856606 * rte_cryptodev_raw_dequeue_done() is
1500*2d9fd380Sjfb8856606 * called.
1501*2d9fd380Sjfb8856606 * - negative integer: Error occurred.
1502*2d9fd380Sjfb8856606 * @param op_status Driver written value to specify
1503*2d9fd380Sjfb8856606 * operation status.
1504*2d9fd380Sjfb8856606 * @return
1505*2d9fd380Sjfb8856606 * - The user data pointer retrieved from device queue or NULL if no
1506*2d9fd380Sjfb8856606 * operation is ready for dequeue.
1507*2d9fd380Sjfb8856606 */
1508*2d9fd380Sjfb8856606 typedef void * (*cryptodev_sym_raw_dequeue_t)(
1509*2d9fd380Sjfb8856606 void *qp, uint8_t *drv_ctx, int *dequeue_status,
1510*2d9fd380Sjfb8856606 enum rte_crypto_op_status *op_status);
1511*2d9fd380Sjfb8856606
1512*2d9fd380Sjfb8856606 /**
1513*2d9fd380Sjfb8856606 * Context data for raw data-path API crypto process. The buffer of this
1514*2d9fd380Sjfb8856606 * structure is to be allocated by the user application with the size equal
1515*2d9fd380Sjfb8856606 * or bigger than rte_cryptodev_get_raw_dp_ctx_size() returned value.
1516*2d9fd380Sjfb8856606 */
1517*2d9fd380Sjfb8856606 struct rte_crypto_raw_dp_ctx {
1518*2d9fd380Sjfb8856606 void *qp_data;
1519*2d9fd380Sjfb8856606
1520*2d9fd380Sjfb8856606 cryptodev_sym_raw_enqueue_t enqueue;
1521*2d9fd380Sjfb8856606 cryptodev_sym_raw_enqueue_burst_t enqueue_burst;
1522*2d9fd380Sjfb8856606 cryptodev_sym_raw_operation_done_t enqueue_done;
1523*2d9fd380Sjfb8856606 cryptodev_sym_raw_dequeue_t dequeue;
1524*2d9fd380Sjfb8856606 cryptodev_sym_raw_dequeue_burst_t dequeue_burst;
1525*2d9fd380Sjfb8856606 cryptodev_sym_raw_operation_done_t dequeue_done;
1526*2d9fd380Sjfb8856606
1527*2d9fd380Sjfb8856606 /* Driver specific context data */
1528*2d9fd380Sjfb8856606 __extension__ uint8_t drv_ctx_data[];
1529*2d9fd380Sjfb8856606 };
1530*2d9fd380Sjfb8856606
1531*2d9fd380Sjfb8856606 /**
1532*2d9fd380Sjfb8856606 * Configure raw data-path context data.
1533*2d9fd380Sjfb8856606 *
1534*2d9fd380Sjfb8856606 * NOTE:
1535*2d9fd380Sjfb8856606 * After the context data is configured, the user should call
1536*2d9fd380Sjfb8856606 * rte_cryptodev_raw_attach_session() before using it in
1537*2d9fd380Sjfb8856606 * rte_cryptodev_raw_enqueue/dequeue function call.
1538*2d9fd380Sjfb8856606 *
1539*2d9fd380Sjfb8856606 * @param dev_id The device identifier.
1540*2d9fd380Sjfb8856606 * @param qp_id The index of the queue pair from which to
1541*2d9fd380Sjfb8856606 * retrieve processed packets. The value must be
1542*2d9fd380Sjfb8856606 * in the range [0, nb_queue_pair - 1] previously
1543*2d9fd380Sjfb8856606 * supplied to rte_cryptodev_configure().
1544*2d9fd380Sjfb8856606 * @param ctx The raw data-path context data.
1545*2d9fd380Sjfb8856606 * @param sess_type session type.
1546*2d9fd380Sjfb8856606 * @param session_ctx Session context data.
1547*2d9fd380Sjfb8856606 * @param is_update Set 0 if it is to initialize the ctx.
1548*2d9fd380Sjfb8856606 * Set 1 if ctx is initialized and only to update
1549*2d9fd380Sjfb8856606 * session context data.
1550*2d9fd380Sjfb8856606 * @return
1551*2d9fd380Sjfb8856606 * - On success return 0.
1552*2d9fd380Sjfb8856606 * - On failure return negative integer.
1553*2d9fd380Sjfb8856606 */
1554*2d9fd380Sjfb8856606 __rte_experimental
1555*2d9fd380Sjfb8856606 int
1556*2d9fd380Sjfb8856606 rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
1557*2d9fd380Sjfb8856606 struct rte_crypto_raw_dp_ctx *ctx,
1558*2d9fd380Sjfb8856606 enum rte_crypto_op_sess_type sess_type,
1559*2d9fd380Sjfb8856606 union rte_cryptodev_session_ctx session_ctx,
1560*2d9fd380Sjfb8856606 uint8_t is_update);
1561*2d9fd380Sjfb8856606
1562*2d9fd380Sjfb8856606 /**
1563*2d9fd380Sjfb8856606 * Enqueue a vectorized operation descriptor into the device queue but the
1564*2d9fd380Sjfb8856606 * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1565*2d9fd380Sjfb8856606 * is called.
1566*2d9fd380Sjfb8856606 *
1567*2d9fd380Sjfb8856606 * @param ctx The initialized raw data-path context data.
1568*2d9fd380Sjfb8856606 * @param vec Vectorized operation descriptor.
1569*2d9fd380Sjfb8856606 * @param ofs Start and stop offsets for auth and cipher
1570*2d9fd380Sjfb8856606 * operations.
1571*2d9fd380Sjfb8856606 * @param user_data The array of user data for dequeue later.
1572*2d9fd380Sjfb8856606 * @param enqueue_status Driver written value to specify the
1573*2d9fd380Sjfb8856606 * enqueue status. Possible values:
1574*2d9fd380Sjfb8856606 * - 1: The number of operations returned are
1575*2d9fd380Sjfb8856606 * enqueued successfully.
1576*2d9fd380Sjfb8856606 * - 0: The number of operations returned are
1577*2d9fd380Sjfb8856606 * cached into the queue but are not processed
1578*2d9fd380Sjfb8856606 * until rte_cryptodev_raw_enqueue_done() is
1579*2d9fd380Sjfb8856606 * called.
1580*2d9fd380Sjfb8856606 * - negative integer: Error occurred.
1581*2d9fd380Sjfb8856606 * @return
1582*2d9fd380Sjfb8856606 * - The number of operations in the descriptor successfully enqueued or
1583*2d9fd380Sjfb8856606 * cached into the queue but not enqueued yet, depends on the
1584*2d9fd380Sjfb8856606 * "enqueue_status" value.
1585*2d9fd380Sjfb8856606 */
1586*2d9fd380Sjfb8856606 __rte_experimental
1587*2d9fd380Sjfb8856606 uint32_t
1588*2d9fd380Sjfb8856606 rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1589*2d9fd380Sjfb8856606 struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
1590*2d9fd380Sjfb8856606 void **user_data, int *enqueue_status);
1591*2d9fd380Sjfb8856606
1592*2d9fd380Sjfb8856606 /**
1593*2d9fd380Sjfb8856606 * Enqueue single raw data vector into the device queue but the driver may or
1594*2d9fd380Sjfb8856606 * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1595*2d9fd380Sjfb8856606 *
1596*2d9fd380Sjfb8856606 * @param ctx The initialized raw data-path context data.
1597*2d9fd380Sjfb8856606 * @param data_vec The buffer data vector.
1598*2d9fd380Sjfb8856606 * @param n_data_vecs Number of buffer data vectors.
1599*2d9fd380Sjfb8856606 * @param ofs Start and stop offsets for auth and cipher
1600*2d9fd380Sjfb8856606 * operations.
1601*2d9fd380Sjfb8856606 * @param iv IV virtual and IOVA addresses
1602*2d9fd380Sjfb8856606 * @param digest digest virtual and IOVA addresses
1603*2d9fd380Sjfb8856606 * @param aad_or_auth_iv AAD or auth IV virtual and IOVA addresses,
1604*2d9fd380Sjfb8856606 * depends on the algorithm used.
1605*2d9fd380Sjfb8856606 * @param user_data The user data.
1606*2d9fd380Sjfb8856606 * @return
1607*2d9fd380Sjfb8856606 * - 1: The data vector is enqueued successfully.
1608*2d9fd380Sjfb8856606 * - 0: The data vector is cached into the queue but is not processed
1609*2d9fd380Sjfb8856606 * until rte_cryptodev_raw_enqueue_done() is called.
1610*2d9fd380Sjfb8856606 * - negative integer: failure.
1611*2d9fd380Sjfb8856606 */
1612*2d9fd380Sjfb8856606 __rte_experimental
1613*2d9fd380Sjfb8856606 static __rte_always_inline int
rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx * ctx,struct rte_crypto_vec * data_vec,uint16_t n_data_vecs,union rte_crypto_sym_ofs ofs,struct rte_crypto_va_iova_ptr * iv,struct rte_crypto_va_iova_ptr * digest,struct rte_crypto_va_iova_ptr * aad_or_auth_iv,void * user_data)1614*2d9fd380Sjfb8856606 rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx *ctx,
1615*2d9fd380Sjfb8856606 struct rte_crypto_vec *data_vec, uint16_t n_data_vecs,
1616*2d9fd380Sjfb8856606 union rte_crypto_sym_ofs ofs,
1617*2d9fd380Sjfb8856606 struct rte_crypto_va_iova_ptr *iv,
1618*2d9fd380Sjfb8856606 struct rte_crypto_va_iova_ptr *digest,
1619*2d9fd380Sjfb8856606 struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1620*2d9fd380Sjfb8856606 void *user_data)
1621*2d9fd380Sjfb8856606 {
1622*2d9fd380Sjfb8856606 return (*ctx->enqueue)(ctx->qp_data, ctx->drv_ctx_data, data_vec,
1623*2d9fd380Sjfb8856606 n_data_vecs, ofs, iv, digest, aad_or_auth_iv, user_data);
1624*2d9fd380Sjfb8856606 }
1625*2d9fd380Sjfb8856606
1626*2d9fd380Sjfb8856606 /**
1627*2d9fd380Sjfb8856606 * Start processing all enqueued operations from last
1628*2d9fd380Sjfb8856606 * rte_cryptodev_configure_raw_dp_ctx() call.
1629*2d9fd380Sjfb8856606 *
1630*2d9fd380Sjfb8856606 * @param ctx The initialized raw data-path context data.
1631*2d9fd380Sjfb8856606 * @param n The number of operations cached.
1632*2d9fd380Sjfb8856606 * @return
1633*2d9fd380Sjfb8856606 * - On success return 0.
1634*2d9fd380Sjfb8856606 * - On failure return negative integer.
1635*2d9fd380Sjfb8856606 */
1636*2d9fd380Sjfb8856606 __rte_experimental
1637*2d9fd380Sjfb8856606 int
1638*2d9fd380Sjfb8856606 rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
1639*2d9fd380Sjfb8856606 uint32_t n);
1640*2d9fd380Sjfb8856606
1641*2d9fd380Sjfb8856606 /**
1642*2d9fd380Sjfb8856606 * Dequeue a burst of symmetric crypto processing.
1643*2d9fd380Sjfb8856606 *
1644*2d9fd380Sjfb8856606 * @param ctx The initialized raw data-path context
1645*2d9fd380Sjfb8856606 * data.
1646*2d9fd380Sjfb8856606 * @param get_dequeue_count User provided callback function to
1647*2d9fd380Sjfb8856606 * obtain dequeue operation count.
1648*2d9fd380Sjfb8856606 * @param post_dequeue User provided callback function to
1649*2d9fd380Sjfb8856606 * post-process a dequeued operation.
1650*2d9fd380Sjfb8856606 * @param out_user_data User data pointer array to be retrieve
1651*2d9fd380Sjfb8856606 * from device queue. In case of
1652*2d9fd380Sjfb8856606 * *is_user_data_array* is set there
1653*2d9fd380Sjfb8856606 * should be enough room to store all
1654*2d9fd380Sjfb8856606 * user data.
1655*2d9fd380Sjfb8856606 * @param is_user_data_array Set 1 if every dequeued user data will
1656*2d9fd380Sjfb8856606 * be written into out_user_data array.
1657*2d9fd380Sjfb8856606 * Set 0 if only the first user data will
1658*2d9fd380Sjfb8856606 * be written into out_user_data array.
1659*2d9fd380Sjfb8856606 * @param n_success Driver written value to specific the
1660*2d9fd380Sjfb8856606 * total successful operations count.
1661*2d9fd380Sjfb8856606 * @param dequeue_status Driver written value to specify the
1662*2d9fd380Sjfb8856606 * dequeue status. Possible values:
1663*2d9fd380Sjfb8856606 * - 1: Successfully dequeued the number
1664*2d9fd380Sjfb8856606 * of operations returned. The user
1665*2d9fd380Sjfb8856606 * data previously set during enqueue
1666*2d9fd380Sjfb8856606 * is stored in the "out_user_data".
1667*2d9fd380Sjfb8856606 * - 0: The number of operations returned
1668*2d9fd380Sjfb8856606 * are completed and the user data is
1669*2d9fd380Sjfb8856606 * stored in the "out_user_data", but
1670*2d9fd380Sjfb8856606 * they are not freed from the queue
1671*2d9fd380Sjfb8856606 * until
1672*2d9fd380Sjfb8856606 * rte_cryptodev_raw_dequeue_done()
1673*2d9fd380Sjfb8856606 * is called.
1674*2d9fd380Sjfb8856606 * - negative integer: Error occurred.
1675*2d9fd380Sjfb8856606 * @return
1676*2d9fd380Sjfb8856606 * - The number of operations dequeued or completed but not freed from the
1677*2d9fd380Sjfb8856606 * queue, depends on "dequeue_status" value.
1678*2d9fd380Sjfb8856606 */
1679*2d9fd380Sjfb8856606 __rte_experimental
1680*2d9fd380Sjfb8856606 uint32_t
1681*2d9fd380Sjfb8856606 rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1682*2d9fd380Sjfb8856606 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1683*2d9fd380Sjfb8856606 rte_cryptodev_raw_post_dequeue_t post_dequeue,
1684*2d9fd380Sjfb8856606 void **out_user_data, uint8_t is_user_data_array,
1685*2d9fd380Sjfb8856606 uint32_t *n_success, int *dequeue_status);
1686*2d9fd380Sjfb8856606
1687*2d9fd380Sjfb8856606 /**
1688*2d9fd380Sjfb8856606 * Dequeue a symmetric crypto processing.
1689*2d9fd380Sjfb8856606 *
1690*2d9fd380Sjfb8856606 * @param ctx The initialized raw data-path context
1691*2d9fd380Sjfb8856606 * data.
1692*2d9fd380Sjfb8856606 * @param dequeue_status Driver written value to specify the
1693*2d9fd380Sjfb8856606 * dequeue status. Possible values:
1694*2d9fd380Sjfb8856606 * - 1: Successfully dequeued a operation.
1695*2d9fd380Sjfb8856606 * The user data is returned.
1696*2d9fd380Sjfb8856606 * - 0: The first operation in the queue
1697*2d9fd380Sjfb8856606 * is completed and the user data
1698*2d9fd380Sjfb8856606 * previously set during enqueue is
1699*2d9fd380Sjfb8856606 * returned, but it is not freed from
1700*2d9fd380Sjfb8856606 * the queue until
1701*2d9fd380Sjfb8856606 * rte_cryptodev_raw_dequeue_done() is
1702*2d9fd380Sjfb8856606 * called.
1703*2d9fd380Sjfb8856606 * - negative integer: Error occurred.
1704*2d9fd380Sjfb8856606 * @param op_status Driver written value to specify
1705*2d9fd380Sjfb8856606 * operation status.
1706*2d9fd380Sjfb8856606 * @return
1707*2d9fd380Sjfb8856606 * - The user data pointer retrieved from device queue or NULL if no
1708*2d9fd380Sjfb8856606 * operation is ready for dequeue.
1709*2d9fd380Sjfb8856606 */
1710*2d9fd380Sjfb8856606 __rte_experimental
1711*2d9fd380Sjfb8856606 static __rte_always_inline void *
rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx * ctx,int * dequeue_status,enum rte_crypto_op_status * op_status)1712*2d9fd380Sjfb8856606 rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx *ctx,
1713*2d9fd380Sjfb8856606 int *dequeue_status, enum rte_crypto_op_status *op_status)
1714*2d9fd380Sjfb8856606 {
1715*2d9fd380Sjfb8856606 return (*ctx->dequeue)(ctx->qp_data, ctx->drv_ctx_data, dequeue_status,
1716*2d9fd380Sjfb8856606 op_status);
1717*2d9fd380Sjfb8856606 }
1718*2d9fd380Sjfb8856606
1719*2d9fd380Sjfb8856606 /**
1720*2d9fd380Sjfb8856606 * Inform the queue pair dequeue operations is finished.
1721*2d9fd380Sjfb8856606 *
1722*2d9fd380Sjfb8856606 * @param ctx The initialized raw data-path context data.
1723*2d9fd380Sjfb8856606 * @param n The number of operations.
1724*2d9fd380Sjfb8856606 * @return
1725*2d9fd380Sjfb8856606 * - On success return 0.
1726*2d9fd380Sjfb8856606 * - On failure return negative integer.
1727*2d9fd380Sjfb8856606 */
1728*2d9fd380Sjfb8856606 __rte_experimental
1729*2d9fd380Sjfb8856606 int
1730*2d9fd380Sjfb8856606 rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
1731*2d9fd380Sjfb8856606 uint32_t n);
1732*2d9fd380Sjfb8856606
1733a9643ea8Slogwang #ifdef __cplusplus
1734a9643ea8Slogwang }
1735a9643ea8Slogwang #endif
1736a9643ea8Slogwang
1737a9643ea8Slogwang #endif /* _RTE_CRYPTODEV_H_ */
1738