xref: /dpdk/lib/cryptodev/rte_cryptodev.h (revision 53c65a3ce2c6b56cf3fa71621a74b97c41432fc0)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2015-2020 Intel Corporation.
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_CRYPTODEV_H_
699a2dd95SBruce Richardson #define _RTE_CRYPTODEV_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file rte_cryptodev.h
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * RTE Cryptographic Device APIs
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * Defines RTE Crypto Device APIs for the provisioning of cipher and
1499a2dd95SBruce Richardson  * authentication operations.
1599a2dd95SBruce Richardson  */
1699a2dd95SBruce Richardson 
171094dd94SDavid Marchand #include <rte_compat.h>
1899a2dd95SBruce Richardson #include "rte_kvargs.h"
1999a2dd95SBruce Richardson #include "rte_crypto.h"
2099a2dd95SBruce Richardson #include <rte_common.h>
2199a2dd95SBruce Richardson #include <rte_rcu_qsbr.h>
2299a2dd95SBruce Richardson 
2399a2dd95SBruce Richardson #include "rte_cryptodev_trace_fp.h"
2499a2dd95SBruce Richardson 
25e5dc404dSStephen Hemminger /**
26e5dc404dSStephen Hemminger  * @internal Logtype used for cryptodev related messages.
27e5dc404dSStephen Hemminger  */
28e5dc404dSStephen Hemminger extern int rte_cryptodev_logtype;
29e5dc404dSStephen Hemminger #define RTE_LOGTYPE_CRYPTODEV rte_cryptodev_logtype
3099a2dd95SBruce Richardson 
31e5dc404dSStephen Hemminger /* Logging Macros */
3299a2dd95SBruce Richardson #define CDEV_LOG_ERR(...) \
330f1dc8cbSTyler Retzlaff 	RTE_LOG_LINE_PREFIX(ERR, CRYPTODEV, \
340f1dc8cbSTyler Retzlaff 		"%s() line %u: ", __func__ RTE_LOG_COMMA __LINE__, __VA_ARGS__)
3599a2dd95SBruce Richardson 
3699a2dd95SBruce Richardson #define CDEV_LOG_INFO(...) \
3797433132SDavid Marchand 	RTE_LOG_LINE(INFO, CRYPTODEV, "" __VA_ARGS__)
3899a2dd95SBruce Richardson 
3999a2dd95SBruce Richardson #define CDEV_LOG_DEBUG(...) \
400f1dc8cbSTyler Retzlaff 	RTE_LOG_LINE_PREFIX(DEBUG, CRYPTODEV, \
410f1dc8cbSTyler Retzlaff 		"%s() line %u: ", __func__ RTE_LOG_COMMA __LINE__, __VA_ARGS__)
4299a2dd95SBruce Richardson 
4399a2dd95SBruce Richardson #define CDEV_PMD_TRACE(...) \
440f1dc8cbSTyler Retzlaff 	RTE_LOG_LINE_PREFIX(DEBUG, CRYPTODEV, \
450f1dc8cbSTyler Retzlaff 		"[%s] %s: ", dev RTE_LOG_COMMA __func__, __VA_ARGS__)
4699a2dd95SBruce Richardson 
4799a2dd95SBruce Richardson /**
4899a2dd95SBruce Richardson  * A macro that points to an offset from the start
4999a2dd95SBruce Richardson  * of the crypto operation structure (rte_crypto_op)
5099a2dd95SBruce Richardson  *
5199a2dd95SBruce Richardson  * The returned pointer is cast to type t.
5299a2dd95SBruce Richardson  *
5399a2dd95SBruce Richardson  * @param c
5499a2dd95SBruce Richardson  *   The crypto operation.
5599a2dd95SBruce Richardson  * @param o
5699a2dd95SBruce Richardson  *   The offset from the start of the crypto operation.
5799a2dd95SBruce Richardson  * @param t
5899a2dd95SBruce Richardson  *   The type to cast the result into.
5999a2dd95SBruce Richardson  */
6099a2dd95SBruce Richardson #define rte_crypto_op_ctod_offset(c, t, o)	\
6199a2dd95SBruce Richardson 	((t)((char *)(c) + (o)))
6299a2dd95SBruce Richardson 
6399a2dd95SBruce Richardson /**
6499a2dd95SBruce Richardson  * A macro that returns the physical address that points
6599a2dd95SBruce Richardson  * to an offset from the start of the crypto operation
6699a2dd95SBruce Richardson  * (rte_crypto_op)
6799a2dd95SBruce Richardson  *
6899a2dd95SBruce Richardson  * @param c
6999a2dd95SBruce Richardson  *   The crypto operation.
7099a2dd95SBruce Richardson  * @param o
7199a2dd95SBruce Richardson  *   The offset from the start of the crypto operation
7299a2dd95SBruce Richardson  *   to calculate address from.
7399a2dd95SBruce Richardson  */
7499a2dd95SBruce Richardson #define rte_crypto_op_ctophys_offset(c, o)	\
7599a2dd95SBruce Richardson 	(rte_iova_t)((c)->phys_addr + (o))
7699a2dd95SBruce Richardson 
7799a2dd95SBruce Richardson /**
7899a2dd95SBruce Richardson  * Crypto parameters range description
7999a2dd95SBruce Richardson  */
8099a2dd95SBruce Richardson struct rte_crypto_param_range {
8199a2dd95SBruce Richardson 	uint16_t min;	/**< minimum size */
8299a2dd95SBruce Richardson 	uint16_t max;	/**< maximum size */
8399a2dd95SBruce Richardson 	uint16_t increment;
8499a2dd95SBruce Richardson 	/**< if a range of sizes are supported,
8599a2dd95SBruce Richardson 	 * this parameter is used to indicate
8699a2dd95SBruce Richardson 	 * increments in byte size that are supported
8799a2dd95SBruce Richardson 	 * between the minimum and maximum
8899a2dd95SBruce Richardson 	 */
8999a2dd95SBruce Richardson };
9099a2dd95SBruce Richardson 
9199a2dd95SBruce Richardson /**
9299a2dd95SBruce Richardson  * Data-unit supported lengths of cipher algorithms.
9399a2dd95SBruce Richardson  * A bit can represent any set of data-unit sizes
9499a2dd95SBruce Richardson  * (single size, multiple size, range, etc).
9599a2dd95SBruce Richardson  */
9699a2dd95SBruce Richardson #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_512_BYTES             RTE_BIT32(0)
9799a2dd95SBruce Richardson #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_4096_BYTES            RTE_BIT32(1)
989ad77644SRaja Zidane #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_1_MEGABYTES           RTE_BIT32(2)
9999a2dd95SBruce Richardson 
10099a2dd95SBruce Richardson /**
10199a2dd95SBruce Richardson  * Symmetric Crypto Capability
10299a2dd95SBruce Richardson  */
10399a2dd95SBruce Richardson struct rte_cryptodev_symmetric_capability {
10499a2dd95SBruce Richardson 	enum rte_crypto_sym_xform_type xform_type;
10599a2dd95SBruce Richardson 	/**< Transform type : Authentication / Cipher / AEAD */
10699a2dd95SBruce Richardson 	union {
10799a2dd95SBruce Richardson 		struct {
10899a2dd95SBruce Richardson 			enum rte_crypto_auth_algorithm algo;
10999a2dd95SBruce Richardson 			/**< authentication algorithm */
11099a2dd95SBruce Richardson 			uint16_t block_size;
11199a2dd95SBruce Richardson 			/**< algorithm block size */
11299a2dd95SBruce Richardson 			struct rte_crypto_param_range key_size;
11399a2dd95SBruce Richardson 			/**< auth key size range */
11499a2dd95SBruce Richardson 			struct rte_crypto_param_range digest_size;
11599a2dd95SBruce Richardson 			/**< digest size range */
11699a2dd95SBruce Richardson 			struct rte_crypto_param_range aad_size;
11799a2dd95SBruce Richardson 			/**< Additional authentication data size range */
11899a2dd95SBruce Richardson 			struct rte_crypto_param_range iv_size;
11999a2dd95SBruce Richardson 			/**< Initialisation vector data size range */
12099a2dd95SBruce Richardson 		} auth;
12199a2dd95SBruce Richardson 		/**< Symmetric Authentication transform capabilities */
12299a2dd95SBruce Richardson 		struct {
12399a2dd95SBruce Richardson 			enum rte_crypto_cipher_algorithm algo;
12499a2dd95SBruce Richardson 			/**< cipher algorithm */
12599a2dd95SBruce Richardson 			uint16_t block_size;
12699a2dd95SBruce Richardson 			/**< algorithm block size */
12799a2dd95SBruce Richardson 			struct rte_crypto_param_range key_size;
12899a2dd95SBruce Richardson 			/**< cipher key size range */
12999a2dd95SBruce Richardson 			struct rte_crypto_param_range iv_size;
13099a2dd95SBruce Richardson 			/**< Initialisation vector data size range */
13199a2dd95SBruce Richardson 			uint32_t dataunit_set;
13299a2dd95SBruce Richardson 			/**<
13399a2dd95SBruce Richardson 			 * Supported data-unit lengths:
13499a2dd95SBruce Richardson 			 * RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_* bits
13599a2dd95SBruce Richardson 			 * or 0 for lengths defined in the algorithm standard.
13699a2dd95SBruce Richardson 			 */
13799a2dd95SBruce Richardson 		} cipher;
13899a2dd95SBruce Richardson 		/**< Symmetric Cipher transform capabilities */
13999a2dd95SBruce Richardson 		struct {
14099a2dd95SBruce Richardson 			enum rte_crypto_aead_algorithm algo;
14199a2dd95SBruce Richardson 			/**< AEAD algorithm */
14299a2dd95SBruce Richardson 			uint16_t block_size;
14399a2dd95SBruce Richardson 			/**< algorithm block size */
14499a2dd95SBruce Richardson 			struct rte_crypto_param_range key_size;
14599a2dd95SBruce Richardson 			/**< AEAD key size range */
14699a2dd95SBruce Richardson 			struct rte_crypto_param_range digest_size;
14799a2dd95SBruce Richardson 			/**< digest size range */
14899a2dd95SBruce Richardson 			struct rte_crypto_param_range aad_size;
14999a2dd95SBruce Richardson 			/**< Additional authentication data size range */
15099a2dd95SBruce Richardson 			struct rte_crypto_param_range iv_size;
15199a2dd95SBruce Richardson 			/**< Initialisation vector data size range */
15299a2dd95SBruce Richardson 		} aead;
15399a2dd95SBruce Richardson 	};
15499a2dd95SBruce Richardson };
15599a2dd95SBruce Richardson 
15699a2dd95SBruce Richardson /**
15799a2dd95SBruce Richardson  * Asymmetric Xform Crypto Capability
15899a2dd95SBruce Richardson  */
15999a2dd95SBruce Richardson struct rte_cryptodev_asymmetric_xform_capability {
16099a2dd95SBruce Richardson 	enum rte_crypto_asym_xform_type xform_type;
16199a2dd95SBruce Richardson 	/**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
16299a2dd95SBruce Richardson 
16399a2dd95SBruce Richardson 	uint32_t op_types;
1645fa1fb29SArek Kusztal 	/**<
1655fa1fb29SArek Kusztal 	 * Bitmask for supported rte_crypto_asym_op_type or
1665fa1fb29SArek Kusztal 	 * rte_crypto_asym_ke_type. Which enum is used is determined
1675fa1fb29SArek Kusztal 	 * by the rte_crypto_asym_xform_type. For key exchange algorithms
1685fa1fb29SArek Kusztal 	 * like Diffie-Hellman it is rte_crypto_asym_ke_type, for others
1695fa1fb29SArek Kusztal 	 * it is rte_crypto_asym_op_type.
1705fa1fb29SArek Kusztal 	 */
17199a2dd95SBruce Richardson 
17299a2dd95SBruce Richardson 	__extension__
17399a2dd95SBruce Richardson 	union {
17499a2dd95SBruce Richardson 		struct rte_crypto_param_range modlen;
17599a2dd95SBruce Richardson 		/**< Range of modulus length supported by modulus based xform.
17699a2dd95SBruce Richardson 		 * Value 0 mean implementation default
17799a2dd95SBruce Richardson 		 */
1781a0ef807SGowrishankar Muthukrishnan 
1791a0ef807SGowrishankar Muthukrishnan 		uint8_t internal_rng;
1801a0ef807SGowrishankar Muthukrishnan 		/**< Availability of random number generator for Elliptic curve based xform.
1811a0ef807SGowrishankar Muthukrishnan 		 * Value 0 means unavailable, and application should pass the required
1821a0ef807SGowrishankar Muthukrishnan 		 * random value. Otherwise, PMD would internally compute the random number.
1831a0ef807SGowrishankar Muthukrishnan 		 */
184*53c65a3cSGowrishankar Muthukrishnan 
185*53c65a3cSGowrishankar Muthukrishnan 		uint32_t op_capa[RTE_CRYPTO_ASYM_OP_LIST_END];
186*53c65a3cSGowrishankar Muthukrishnan 		/**< Operation specific capabilities. */
18799a2dd95SBruce Richardson 	};
1886f8ef8b6SGowrishankar Muthukrishnan 
1896f8ef8b6SGowrishankar Muthukrishnan 	uint64_t hash_algos;
1906f8ef8b6SGowrishankar Muthukrishnan 	/**< Bitmask of hash algorithms supported for op_type. */
19199a2dd95SBruce Richardson };
19299a2dd95SBruce Richardson 
19399a2dd95SBruce Richardson /**
19499a2dd95SBruce Richardson  * Asymmetric Crypto Capability
19599a2dd95SBruce Richardson  */
19699a2dd95SBruce Richardson struct rte_cryptodev_asymmetric_capability {
19799a2dd95SBruce Richardson 	struct rte_cryptodev_asymmetric_xform_capability xform_capa;
19899a2dd95SBruce Richardson };
19999a2dd95SBruce Richardson 
20099a2dd95SBruce Richardson 
20199a2dd95SBruce Richardson /** Structure used to capture a capability of a crypto device */
20299a2dd95SBruce Richardson struct rte_cryptodev_capabilities {
20399a2dd95SBruce Richardson 	enum rte_crypto_op_type op;
20499a2dd95SBruce Richardson 	/**< Operation type */
20599a2dd95SBruce Richardson 
20699a2dd95SBruce Richardson 	union {
20799a2dd95SBruce Richardson 		struct rte_cryptodev_symmetric_capability sym;
20899a2dd95SBruce Richardson 		/**< Symmetric operation capability parameters */
20999a2dd95SBruce Richardson 		struct rte_cryptodev_asymmetric_capability asym;
21099a2dd95SBruce Richardson 		/**< Asymmetric operation capability parameters */
21199a2dd95SBruce Richardson 	};
21299a2dd95SBruce Richardson };
21399a2dd95SBruce Richardson 
21499a2dd95SBruce Richardson /** Structure used to describe crypto algorithms */
21599a2dd95SBruce Richardson struct rte_cryptodev_sym_capability_idx {
21699a2dd95SBruce Richardson 	enum rte_crypto_sym_xform_type type;
21799a2dd95SBruce Richardson 	union {
21899a2dd95SBruce Richardson 		enum rte_crypto_cipher_algorithm cipher;
21999a2dd95SBruce Richardson 		enum rte_crypto_auth_algorithm auth;
22099a2dd95SBruce Richardson 		enum rte_crypto_aead_algorithm aead;
22199a2dd95SBruce Richardson 	} algo;
22299a2dd95SBruce Richardson };
22399a2dd95SBruce Richardson 
22499a2dd95SBruce Richardson /**
22599a2dd95SBruce Richardson  * Structure used to describe asymmetric crypto xforms
22699a2dd95SBruce Richardson  * Each xform maps to one asym algorithm.
22799a2dd95SBruce Richardson  */
22899a2dd95SBruce Richardson struct rte_cryptodev_asym_capability_idx {
22999a2dd95SBruce Richardson 	enum rte_crypto_asym_xform_type type;
23099a2dd95SBruce Richardson 	/**< Asymmetric xform (algo) type */
23199a2dd95SBruce Richardson };
23299a2dd95SBruce Richardson 
23399a2dd95SBruce Richardson /**
23499a2dd95SBruce Richardson  * Provide capabilities available for defined device and algorithm
23599a2dd95SBruce Richardson  *
23699a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
23799a2dd95SBruce Richardson  * @param	idx		Description of crypto algorithms.
23899a2dd95SBruce Richardson  *
23999a2dd95SBruce Richardson  * @return
24099a2dd95SBruce Richardson  *   - Return description of the symmetric crypto capability if exist.
24199a2dd95SBruce Richardson  *   - Return NULL if the capability not exist.
24299a2dd95SBruce Richardson  */
24399a2dd95SBruce Richardson const struct rte_cryptodev_symmetric_capability *
24499a2dd95SBruce Richardson rte_cryptodev_sym_capability_get(uint8_t dev_id,
24599a2dd95SBruce Richardson 		const struct rte_cryptodev_sym_capability_idx *idx);
24699a2dd95SBruce Richardson 
24799a2dd95SBruce Richardson /**
24899a2dd95SBruce Richardson  *  Provide capabilities available for defined device and xform
24999a2dd95SBruce Richardson  *
25099a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
25199a2dd95SBruce Richardson  * @param	idx		Description of asym crypto xform.
25299a2dd95SBruce Richardson  *
25399a2dd95SBruce Richardson  * @return
25499a2dd95SBruce Richardson  *   - Return description of the asymmetric crypto capability if exist.
25599a2dd95SBruce Richardson  *   - Return NULL if the capability not exist.
25699a2dd95SBruce Richardson  */
25799a2dd95SBruce Richardson const struct rte_cryptodev_asymmetric_xform_capability *
25899a2dd95SBruce Richardson rte_cryptodev_asym_capability_get(uint8_t dev_id,
25999a2dd95SBruce Richardson 		const struct rte_cryptodev_asym_capability_idx *idx);
26099a2dd95SBruce Richardson 
26199a2dd95SBruce Richardson /**
26299a2dd95SBruce Richardson  * Check if key size and initial vector are supported
26399a2dd95SBruce Richardson  * in crypto cipher capability
26499a2dd95SBruce Richardson  *
26599a2dd95SBruce Richardson  * @param	capability	Description of the symmetric crypto capability.
26699a2dd95SBruce Richardson  * @param	key_size	Cipher key size.
26799a2dd95SBruce Richardson  * @param	iv_size		Cipher initial vector size.
26899a2dd95SBruce Richardson  *
26999a2dd95SBruce Richardson  * @return
27099a2dd95SBruce Richardson  *   - Return 0 if the parameters are in range of the capability.
27199a2dd95SBruce Richardson  *   - Return -1 if the parameters are out of range of the capability.
27299a2dd95SBruce Richardson  */
27399a2dd95SBruce Richardson int
27499a2dd95SBruce Richardson rte_cryptodev_sym_capability_check_cipher(
27599a2dd95SBruce Richardson 		const struct rte_cryptodev_symmetric_capability *capability,
27699a2dd95SBruce Richardson 		uint16_t key_size, uint16_t iv_size);
27799a2dd95SBruce Richardson 
27899a2dd95SBruce Richardson /**
27999a2dd95SBruce Richardson  * Check if key size and initial vector are supported
28099a2dd95SBruce Richardson  * in crypto auth capability
28199a2dd95SBruce Richardson  *
28299a2dd95SBruce Richardson  * @param	capability	Description of the symmetric crypto capability.
28399a2dd95SBruce Richardson  * @param	key_size	Auth key size.
28499a2dd95SBruce Richardson  * @param	digest_size	Auth digest size.
28599a2dd95SBruce Richardson  * @param	iv_size		Auth initial vector size.
28699a2dd95SBruce Richardson  *
28799a2dd95SBruce Richardson  * @return
28899a2dd95SBruce Richardson  *   - Return 0 if the parameters are in range of the capability.
28999a2dd95SBruce Richardson  *   - Return -1 if the parameters are out of range of the capability.
29099a2dd95SBruce Richardson  */
29199a2dd95SBruce Richardson int
29299a2dd95SBruce Richardson rte_cryptodev_sym_capability_check_auth(
29399a2dd95SBruce Richardson 		const struct rte_cryptodev_symmetric_capability *capability,
29499a2dd95SBruce Richardson 		uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
29599a2dd95SBruce Richardson 
29699a2dd95SBruce Richardson /**
29799a2dd95SBruce Richardson  * Check if key, digest, AAD and initial vector sizes are supported
29899a2dd95SBruce Richardson  * in crypto AEAD capability
29999a2dd95SBruce Richardson  *
30099a2dd95SBruce Richardson  * @param	capability	Description of the symmetric crypto capability.
30199a2dd95SBruce Richardson  * @param	key_size	AEAD key size.
30299a2dd95SBruce Richardson  * @param	digest_size	AEAD digest size.
30399a2dd95SBruce Richardson  * @param	aad_size	AEAD AAD size.
30499a2dd95SBruce Richardson  * @param	iv_size		AEAD IV size.
30599a2dd95SBruce Richardson  *
30699a2dd95SBruce Richardson  * @return
30799a2dd95SBruce Richardson  *   - Return 0 if the parameters are in range of the capability.
30899a2dd95SBruce Richardson  *   - Return -1 if the parameters are out of range of the capability.
30999a2dd95SBruce Richardson  */
31099a2dd95SBruce Richardson int
31199a2dd95SBruce Richardson rte_cryptodev_sym_capability_check_aead(
31299a2dd95SBruce Richardson 		const struct rte_cryptodev_symmetric_capability *capability,
31399a2dd95SBruce Richardson 		uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
31499a2dd95SBruce Richardson 		uint16_t iv_size);
31599a2dd95SBruce Richardson 
31699a2dd95SBruce Richardson /**
31799a2dd95SBruce Richardson  * Check if op type is supported
31899a2dd95SBruce Richardson  *
31999a2dd95SBruce Richardson  * @param	capability	Description of the asymmetric crypto capability.
32099a2dd95SBruce Richardson  * @param	op_type		op type
32199a2dd95SBruce Richardson  *
32299a2dd95SBruce Richardson  * @return
32399a2dd95SBruce Richardson  *   - Return 1 if the op type is supported
32499a2dd95SBruce Richardson  *   - Return 0 if unsupported
32599a2dd95SBruce Richardson  */
32699a2dd95SBruce Richardson int
32799a2dd95SBruce Richardson rte_cryptodev_asym_xform_capability_check_optype(
32899a2dd95SBruce Richardson 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
32999a2dd95SBruce Richardson 		enum rte_crypto_asym_op_type op_type);
33099a2dd95SBruce Richardson 
33199a2dd95SBruce Richardson /**
33299a2dd95SBruce Richardson  * Check if modulus length is in supported range
33399a2dd95SBruce Richardson  *
33499a2dd95SBruce Richardson  * @param	capability	Description of the asymmetric crypto capability.
33599a2dd95SBruce Richardson  * @param	modlen		modulus length.
33699a2dd95SBruce Richardson  *
33799a2dd95SBruce Richardson  * @return
33899a2dd95SBruce Richardson  *   - Return 0 if the parameters are in range of the capability.
33999a2dd95SBruce Richardson  *   - Return -1 if the parameters are out of range of the capability.
34099a2dd95SBruce Richardson  */
34199a2dd95SBruce Richardson int
34299a2dd95SBruce Richardson rte_cryptodev_asym_xform_capability_check_modlen(
34399a2dd95SBruce Richardson 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
34499a2dd95SBruce Richardson 		uint16_t modlen);
34599a2dd95SBruce Richardson 
34699a2dd95SBruce Richardson /**
3476f8ef8b6SGowrishankar Muthukrishnan  * Check if hash algorithm is supported.
3486f8ef8b6SGowrishankar Muthukrishnan  *
3496f8ef8b6SGowrishankar Muthukrishnan  * @param	capability	Asymmetric crypto capability.
3506f8ef8b6SGowrishankar Muthukrishnan  * @param	hash		Hash algorithm.
3516f8ef8b6SGowrishankar Muthukrishnan  *
3526f8ef8b6SGowrishankar Muthukrishnan  * @return
3536f8ef8b6SGowrishankar Muthukrishnan  *   - Return true if the hash algorithm is supported.
3546f8ef8b6SGowrishankar Muthukrishnan  *   - Return false if the hash algorithm is not supported.
3556f8ef8b6SGowrishankar Muthukrishnan  */
3566f8ef8b6SGowrishankar Muthukrishnan bool
3576f8ef8b6SGowrishankar Muthukrishnan rte_cryptodev_asym_xform_capability_check_hash(
3586f8ef8b6SGowrishankar Muthukrishnan 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
3596f8ef8b6SGowrishankar Muthukrishnan 	enum rte_crypto_auth_algorithm hash);
3606f8ef8b6SGowrishankar Muthukrishnan 
3616f8ef8b6SGowrishankar Muthukrishnan /**
362*53c65a3cSGowrishankar Muthukrishnan  * @warning
363*53c65a3cSGowrishankar Muthukrishnan  * @b EXPERIMENTAL: this API may change without prior notice.
364*53c65a3cSGowrishankar Muthukrishnan  *
365*53c65a3cSGowrishankar Muthukrishnan  * Check if op capability is supported
366*53c65a3cSGowrishankar Muthukrishnan  *
367*53c65a3cSGowrishankar Muthukrishnan  * @param	capability	Description of the asymmetric crypto capability.
368*53c65a3cSGowrishankar Muthukrishnan  * @param	op_type		op type
369*53c65a3cSGowrishankar Muthukrishnan  * @param	cap		op capability
370*53c65a3cSGowrishankar Muthukrishnan  *
371*53c65a3cSGowrishankar Muthukrishnan  * @return
372*53c65a3cSGowrishankar Muthukrishnan  *   - Return 1 if the op capability is supported
373*53c65a3cSGowrishankar Muthukrishnan  *   - Return 0 if unsupported
374*53c65a3cSGowrishankar Muthukrishnan  */
375*53c65a3cSGowrishankar Muthukrishnan __rte_experimental
376*53c65a3cSGowrishankar Muthukrishnan int
377*53c65a3cSGowrishankar Muthukrishnan rte_cryptodev_asym_xform_capability_check_opcap(
378*53c65a3cSGowrishankar Muthukrishnan 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
379*53c65a3cSGowrishankar Muthukrishnan 	enum rte_crypto_asym_op_type op_type, uint8_t cap);
380*53c65a3cSGowrishankar Muthukrishnan 
381*53c65a3cSGowrishankar Muthukrishnan /**
38299a2dd95SBruce Richardson  * Provide the cipher algorithm enum, given an algorithm string
38399a2dd95SBruce Richardson  *
38499a2dd95SBruce Richardson  * @param	algo_enum	A pointer to the cipher algorithm
38599a2dd95SBruce Richardson  *				enum to be filled
38699a2dd95SBruce Richardson  * @param	algo_string	Authentication algo string
38799a2dd95SBruce Richardson  *
38899a2dd95SBruce Richardson  * @return
38999a2dd95SBruce Richardson  * - Return -1 if string is not valid
39099a2dd95SBruce Richardson  * - Return 0 is the string is valid
39199a2dd95SBruce Richardson  */
39299a2dd95SBruce Richardson int
39399a2dd95SBruce Richardson rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
39499a2dd95SBruce Richardson 		const char *algo_string);
39599a2dd95SBruce Richardson 
39699a2dd95SBruce Richardson /**
39799a2dd95SBruce Richardson  * Provide the authentication algorithm enum, given an algorithm string
39899a2dd95SBruce Richardson  *
39999a2dd95SBruce Richardson  * @param	algo_enum	A pointer to the authentication algorithm
40099a2dd95SBruce Richardson  *				enum to be filled
40199a2dd95SBruce Richardson  * @param	algo_string	Authentication algo string
40299a2dd95SBruce Richardson  *
40399a2dd95SBruce Richardson  * @return
40499a2dd95SBruce Richardson  * - Return -1 if string is not valid
40599a2dd95SBruce Richardson  * - Return 0 is the string is valid
40699a2dd95SBruce Richardson  */
40799a2dd95SBruce Richardson int
40899a2dd95SBruce Richardson rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
40999a2dd95SBruce Richardson 		const char *algo_string);
41099a2dd95SBruce Richardson 
41199a2dd95SBruce Richardson /**
41299a2dd95SBruce Richardson  * Provide the AEAD algorithm enum, given an algorithm string
41399a2dd95SBruce Richardson  *
41499a2dd95SBruce Richardson  * @param	algo_enum	A pointer to the AEAD algorithm
41599a2dd95SBruce Richardson  *				enum to be filled
41699a2dd95SBruce Richardson  * @param	algo_string	AEAD algorithm string
41799a2dd95SBruce Richardson  *
41899a2dd95SBruce Richardson  * @return
41999a2dd95SBruce Richardson  * - Return -1 if string is not valid
42099a2dd95SBruce Richardson  * - Return 0 is the string is valid
42199a2dd95SBruce Richardson  */
42299a2dd95SBruce Richardson int
42399a2dd95SBruce Richardson rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
42499a2dd95SBruce Richardson 		const char *algo_string);
42599a2dd95SBruce Richardson 
42699a2dd95SBruce Richardson /**
42799a2dd95SBruce Richardson  * Provide the Asymmetric xform enum, given an xform string
42899a2dd95SBruce Richardson  *
42999a2dd95SBruce Richardson  * @param	xform_enum	A pointer to the xform type
43099a2dd95SBruce Richardson  *				enum to be filled
43199a2dd95SBruce Richardson  * @param	xform_string	xform string
43299a2dd95SBruce Richardson  *
43399a2dd95SBruce Richardson  * @return
43499a2dd95SBruce Richardson  * - Return -1 if string is not valid
43599a2dd95SBruce Richardson  * - Return 0 if the string is valid
43699a2dd95SBruce Richardson  */
43799a2dd95SBruce Richardson int
43899a2dd95SBruce Richardson rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
43999a2dd95SBruce Richardson 		const char *xform_string);
44099a2dd95SBruce Richardson 
4417e1e1277SAkhil Goyal /**
4427e1e1277SAkhil Goyal  * Provide the cipher algorithm string, given an algorithm enum.
4437e1e1277SAkhil Goyal  *
4447e1e1277SAkhil Goyal  * @param	algo_enum	cipher algorithm enum
4457e1e1277SAkhil Goyal  *
4467e1e1277SAkhil Goyal  * @return
4477e1e1277SAkhil Goyal  * - Return NULL if enum is not valid
4487e1e1277SAkhil Goyal  * - Return algo_string corresponding to enum
4497e1e1277SAkhil Goyal  */
4507e1e1277SAkhil Goyal __rte_experimental
4517e1e1277SAkhil Goyal const char *
4527e1e1277SAkhil Goyal rte_cryptodev_get_cipher_algo_string(enum rte_crypto_cipher_algorithm algo_enum);
4537e1e1277SAkhil Goyal 
4547e1e1277SAkhil Goyal /**
4557e1e1277SAkhil Goyal  * Provide the authentication algorithm string, given an algorithm enum.
4567e1e1277SAkhil Goyal  *
4577e1e1277SAkhil Goyal  * @param	algo_enum	auth algorithm enum
4587e1e1277SAkhil Goyal  *
4597e1e1277SAkhil Goyal  * @return
4607e1e1277SAkhil Goyal  * - Return NULL if enum is not valid
4617e1e1277SAkhil Goyal  * - Return algo_string corresponding to enum
4627e1e1277SAkhil Goyal  */
4637e1e1277SAkhil Goyal __rte_experimental
4647e1e1277SAkhil Goyal const char *
4657e1e1277SAkhil Goyal rte_cryptodev_get_auth_algo_string(enum rte_crypto_auth_algorithm algo_enum);
4667e1e1277SAkhil Goyal 
4677e1e1277SAkhil Goyal /**
4687e1e1277SAkhil Goyal  * Provide the AEAD algorithm string, given an algorithm enum.
4697e1e1277SAkhil Goyal  *
4707e1e1277SAkhil Goyal  * @param	algo_enum	AEAD algorithm enum
4717e1e1277SAkhil Goyal  *
4727e1e1277SAkhil Goyal  * @return
4737e1e1277SAkhil Goyal  * - Return NULL if enum is not valid
4747e1e1277SAkhil Goyal  * - Return algo_string corresponding to enum
4757e1e1277SAkhil Goyal  */
4767e1e1277SAkhil Goyal __rte_experimental
4777e1e1277SAkhil Goyal const char *
4787e1e1277SAkhil Goyal rte_cryptodev_get_aead_algo_string(enum rte_crypto_aead_algorithm algo_enum);
4797e1e1277SAkhil Goyal 
4807e1e1277SAkhil Goyal /**
4817e1e1277SAkhil Goyal  * Provide the Asymmetric xform string, given an xform enum.
4827e1e1277SAkhil Goyal  *
4837e1e1277SAkhil Goyal  * @param	xform_enum	xform type enum
4847e1e1277SAkhil Goyal  *
4857e1e1277SAkhil Goyal  * @return
4867e1e1277SAkhil Goyal  * - Return NULL, if enum is not valid.
4877e1e1277SAkhil Goyal  * - Return xform string, for valid enum.
4887e1e1277SAkhil Goyal  */
4897e1e1277SAkhil Goyal __rte_experimental
4907e1e1277SAkhil Goyal const char *
4917e1e1277SAkhil Goyal rte_cryptodev_asym_get_xform_string(enum rte_crypto_asym_xform_type xform_enum);
4927e1e1277SAkhil Goyal 
49399a2dd95SBruce Richardson 
49499a2dd95SBruce Richardson /** Macro used at end of crypto PMD list */
49599a2dd95SBruce Richardson #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
49699a2dd95SBruce Richardson 	{ RTE_CRYPTO_OP_TYPE_UNDEFINED }
49799a2dd95SBruce Richardson 
49899a2dd95SBruce Richardson 
49999a2dd95SBruce Richardson /**
50099a2dd95SBruce Richardson  * Crypto device supported feature flags
50199a2dd95SBruce Richardson  *
50299a2dd95SBruce Richardson  * Note:
50399a2dd95SBruce Richardson  * New features flags should be added to the end of the list
50499a2dd95SBruce Richardson  *
50599a2dd95SBruce Richardson  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
50699a2dd95SBruce Richardson  */
50799a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO		(1ULL << 0)
50899a2dd95SBruce Richardson /**< Symmetric crypto operations are supported */
50999a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO		(1ULL << 1)
51099a2dd95SBruce Richardson /**< Asymmetric crypto operations are supported */
51199a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING		(1ULL << 2)
51299a2dd95SBruce Richardson /**< Chaining symmetric crypto operations are supported */
51399a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_SSE			(1ULL << 3)
51499a2dd95SBruce Richardson /**< Utilises CPU SIMD SSE instructions */
51599a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_AVX			(1ULL << 4)
51699a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX instructions */
51799a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_AVX2			(1ULL << 5)
51899a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX2 instructions */
51999a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_AESNI			(1ULL << 6)
52099a2dd95SBruce Richardson /**< Utilises CPU AES-NI instructions */
52199a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_HW_ACCELERATED			(1ULL << 7)
52299a2dd95SBruce Richardson /**< Operations are off-loaded to an
52399a2dd95SBruce Richardson  * external hardware accelerator
52499a2dd95SBruce Richardson  */
52599a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_AVX512			(1ULL << 8)
52699a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX512 instructions */
52799a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_IN_PLACE_SGL			(1ULL << 9)
52899a2dd95SBruce Richardson /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
52999a2dd95SBruce Richardson  * are supported
53099a2dd95SBruce Richardson  */
53199a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT		(1ULL << 10)
53299a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are
53399a2dd95SBruce Richardson  * supported in input and output
53499a2dd95SBruce Richardson  */
53599a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT		(1ULL << 11)
53699a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are supported
53799a2dd95SBruce Richardson  * in input, combined with linear buffers (LB), with a
53899a2dd95SBruce Richardson  * single segment in output
53999a2dd95SBruce Richardson  */
54099a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT		(1ULL << 12)
54199a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are supported
54299a2dd95SBruce Richardson  * in output, combined with linear buffers (LB) in input
54399a2dd95SBruce Richardson  */
54499a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT		(1ULL << 13)
54599a2dd95SBruce Richardson /**< Out-of-place linear buffers (LB) are supported in input and output */
54699a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_NEON			(1ULL << 14)
54799a2dd95SBruce Richardson /**< Utilises CPU NEON instructions */
54899a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_ARM_CE			(1ULL << 15)
54999a2dd95SBruce Richardson /**< Utilises ARM CPU Cryptographic Extensions */
55099a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_SECURITY			(1ULL << 16)
55199a2dd95SBruce Richardson /**< Support Security Protocol Processing */
55299a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP		(1ULL << 17)
55399a2dd95SBruce Richardson /**< Support RSA Private Key OP with exponent */
55499a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT		(1ULL << 18)
55599a2dd95SBruce Richardson /**< Support RSA Private Key OP with CRT (quintuple) Keys */
55699a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED		(1ULL << 19)
55799a2dd95SBruce Richardson /**< Support encrypted-digest operations where digest is appended to data */
55899a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS		(1ULL << 20)
55999a2dd95SBruce Richardson /**< Support asymmetric session-less operations */
56099a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO			(1ULL << 21)
56199a2dd95SBruce Richardson /**< Support symmetric cpu-crypto processing */
56299a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS		(1ULL << 22)
56399a2dd95SBruce Richardson /**< Support symmetric session-less operations */
56499a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA		(1ULL << 23)
56599a2dd95SBruce Richardson /**< Support operations on data which is not byte aligned */
56699a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_SYM_RAW_DP			(1ULL << 24)
56799a2dd95SBruce Richardson /**< Support accelerator specific symmetric raw data-path APIs */
56899a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS	(1ULL << 25)
56999a2dd95SBruce Richardson /**< Support operations on multiple data-units message */
57099a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY		(1ULL << 26)
57199a2dd95SBruce Richardson /**< Support wrapped key in cipher xform  */
57203ab51eaSArchana Muniganti #define RTE_CRYPTODEV_FF_SECURITY_INNER_CSUM		(1ULL << 27)
57303ab51eaSArchana Muniganti /**< Support inner checksum computation/verification */
574165bb658SAnoob Joseph #define RTE_CRYPTODEV_FF_SECURITY_RX_INJECT		(1ULL << 28)
575165bb658SAnoob Joseph /**< Support Rx injection after security processing */
57699a2dd95SBruce Richardson 
57799a2dd95SBruce Richardson /**
57899a2dd95SBruce Richardson  * Get the name of a crypto device feature flag
57999a2dd95SBruce Richardson  *
58099a2dd95SBruce Richardson  * @param	flag	The mask describing the flag.
58199a2dd95SBruce Richardson  *
58299a2dd95SBruce Richardson  * @return
58399a2dd95SBruce Richardson  *   The name of this flag, or NULL if it's not a valid feature flag.
58499a2dd95SBruce Richardson  */
58516bd1c62SThomas Monjalon const char *
58699a2dd95SBruce Richardson rte_cryptodev_get_feature_name(uint64_t flag);
58799a2dd95SBruce Richardson 
58899a2dd95SBruce Richardson /**  Crypto device information */
589d2d7f019SAkhil Goyal /* Structure rte_cryptodev_info 8< */
59099a2dd95SBruce Richardson struct rte_cryptodev_info {
59199a2dd95SBruce Richardson 	const char *driver_name;	/**< Driver name. */
59299a2dd95SBruce Richardson 	uint8_t driver_id;		/**< Driver identifier */
59399a2dd95SBruce Richardson 	struct rte_device *device;	/**< Generic device information. */
59499a2dd95SBruce Richardson 
59599a2dd95SBruce Richardson 	uint64_t feature_flags;
59699a2dd95SBruce Richardson 	/**< Feature flags exposes HW/SW features for the given device */
59799a2dd95SBruce Richardson 
59899a2dd95SBruce Richardson 	const struct rte_cryptodev_capabilities *capabilities;
59999a2dd95SBruce Richardson 	/**< Array of devices supported capabilities */
60099a2dd95SBruce Richardson 
60199a2dd95SBruce Richardson 	unsigned max_nb_queue_pairs;
60299a2dd95SBruce Richardson 	/**< Maximum number of queues pairs supported by device. */
60399a2dd95SBruce Richardson 
60499a2dd95SBruce Richardson 	uint16_t min_mbuf_headroom_req;
60599a2dd95SBruce Richardson 	/**< Minimum mbuf headroom required by device */
60699a2dd95SBruce Richardson 
60799a2dd95SBruce Richardson 	uint16_t min_mbuf_tailroom_req;
60899a2dd95SBruce Richardson 	/**< Minimum mbuf tailroom required by device */
60999a2dd95SBruce Richardson 
61099a2dd95SBruce Richardson 	struct {
61199a2dd95SBruce Richardson 		unsigned max_nb_sessions;
61299a2dd95SBruce Richardson 		/**< Maximum number of sessions supported by device.
61399a2dd95SBruce Richardson 		 * If 0, the device does not have any limitation in
61499a2dd95SBruce Richardson 		 * number of sessions that can be used.
61599a2dd95SBruce Richardson 		 */
61699a2dd95SBruce Richardson 	} sym;
61799a2dd95SBruce Richardson };
618d2d7f019SAkhil Goyal /* >8 End of structure rte_cryptodev_info. */
61999a2dd95SBruce Richardson 
62099a2dd95SBruce Richardson #define RTE_CRYPTODEV_DETACHED  (0)
62199a2dd95SBruce Richardson #define RTE_CRYPTODEV_ATTACHED  (1)
62299a2dd95SBruce Richardson 
62399a2dd95SBruce Richardson /** Definitions of Crypto device event types */
62499a2dd95SBruce Richardson enum rte_cryptodev_event_type {
62599a2dd95SBruce Richardson 	RTE_CRYPTODEV_EVENT_UNKNOWN,	/**< unknown event type */
62699a2dd95SBruce Richardson 	RTE_CRYPTODEV_EVENT_ERROR,	/**< error interrupt event */
62799a2dd95SBruce Richardson 	RTE_CRYPTODEV_EVENT_MAX		/**< max value of this enum */
62899a2dd95SBruce Richardson };
62999a2dd95SBruce Richardson 
6306ef8e70eSAkhil Goyal /* Crypto queue pair priority levels */
6316ef8e70eSAkhil Goyal #define RTE_CRYPTODEV_QP_PRIORITY_HIGHEST   0
6326ef8e70eSAkhil Goyal /**< Highest priority of a cryptodev queue pair
6336ef8e70eSAkhil Goyal  * @see rte_cryptodev_queue_pair_setup(), rte_cryptodev_enqueue_burst()
6346ef8e70eSAkhil Goyal  */
6356ef8e70eSAkhil Goyal #define RTE_CRYPTODEV_QP_PRIORITY_NORMAL    128
6366ef8e70eSAkhil Goyal /**< Normal priority of a cryptodev queue pair
6376ef8e70eSAkhil Goyal  * @see rte_cryptodev_queue_pair_setup(), rte_cryptodev_enqueue_burst()
6386ef8e70eSAkhil Goyal  */
6396ef8e70eSAkhil Goyal #define RTE_CRYPTODEV_QP_PRIORITY_LOWEST    255
6406ef8e70eSAkhil Goyal /**< Lowest priority of a cryptodev queue pair
6416ef8e70eSAkhil Goyal  * @see rte_cryptodev_queue_pair_setup(), rte_cryptodev_enqueue_burst()
6426ef8e70eSAkhil Goyal  */
6436ef8e70eSAkhil Goyal 
64499a2dd95SBruce Richardson /** Crypto device queue pair configuration structure. */
645d2d7f019SAkhil Goyal /* Structure rte_cryptodev_qp_conf 8<*/
64699a2dd95SBruce Richardson struct rte_cryptodev_qp_conf {
64799a2dd95SBruce Richardson 	uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
64899a2dd95SBruce Richardson 	struct rte_mempool *mp_session;
64999a2dd95SBruce Richardson 	/**< The mempool for creating session in sessionless mode */
6506ef8e70eSAkhil Goyal 	uint8_t priority;
6516ef8e70eSAkhil Goyal 	/**< Priority for this queue pair relative to other queue pairs.
6526ef8e70eSAkhil Goyal 	 *
6536ef8e70eSAkhil Goyal 	 * The requested priority should in the range of
6546ef8e70eSAkhil Goyal 	 * [@ref RTE_CRYPTODEV_QP_PRIORITY_HIGHEST, @ref RTE_CRYPTODEV_QP_PRIORITY_LOWEST].
6556ef8e70eSAkhil Goyal 	 * The implementation may normalize the requested priority to
6566ef8e70eSAkhil Goyal 	 * device supported priority value.
6576ef8e70eSAkhil Goyal 	 */
65899a2dd95SBruce Richardson };
659d2d7f019SAkhil Goyal /* >8 End of structure rte_cryptodev_qp_conf. */
66099a2dd95SBruce Richardson 
66199a2dd95SBruce Richardson /**
66299a2dd95SBruce Richardson  * Function type used for processing crypto ops when enqueue/dequeue burst is
66399a2dd95SBruce Richardson  * called.
66499a2dd95SBruce Richardson  *
66599a2dd95SBruce Richardson  * The callback function is called on enqueue/dequeue burst immediately.
66699a2dd95SBruce Richardson  *
66799a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
66899a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
66999a2dd95SBruce Richardson  *				enqueued/dequeued. The value must be in the
67099a2dd95SBruce Richardson  *				range [0, nb_queue_pairs - 1] previously
67199a2dd95SBruce Richardson  *				supplied to *rte_cryptodev_configure*.
67299a2dd95SBruce Richardson  * @param	ops		The address of an array of *nb_ops* pointers
67399a2dd95SBruce Richardson  *				to *rte_crypto_op* structures which contain
67499a2dd95SBruce Richardson  *				the crypto operations to be processed.
67599a2dd95SBruce Richardson  * @param	nb_ops		The number of operations to process.
67699a2dd95SBruce Richardson  * @param	user_param	The arbitrary user parameter passed in by the
67799a2dd95SBruce Richardson  *				application when the callback was originally
67899a2dd95SBruce Richardson  *				registered.
67999a2dd95SBruce Richardson  * @return			The number of ops to be enqueued to the
68099a2dd95SBruce Richardson  *				crypto device.
68199a2dd95SBruce Richardson  */
68299a2dd95SBruce Richardson typedef uint16_t (*rte_cryptodev_callback_fn)(uint16_t dev_id, uint16_t qp_id,
68399a2dd95SBruce Richardson 		struct rte_crypto_op **ops, uint16_t nb_ops, void *user_param);
68499a2dd95SBruce Richardson 
68599a2dd95SBruce Richardson /**
68699a2dd95SBruce Richardson  * Typedef for application callback function to be registered by application
68799a2dd95SBruce Richardson  * software for notification of device events
68899a2dd95SBruce Richardson  *
68999a2dd95SBruce Richardson  * @param	dev_id	Crypto device identifier
69099a2dd95SBruce Richardson  * @param	event	Crypto device event to register for notification of.
69199a2dd95SBruce Richardson  * @param	cb_arg	User specified parameter to be passed as to passed to
69299a2dd95SBruce Richardson  *			users callback function.
69399a2dd95SBruce Richardson  */
69499a2dd95SBruce Richardson typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
69599a2dd95SBruce Richardson 		enum rte_cryptodev_event_type event, void *cb_arg);
69699a2dd95SBruce Richardson 
69799a2dd95SBruce Richardson 
69899a2dd95SBruce Richardson /** Crypto Device statistics */
69999a2dd95SBruce Richardson struct rte_cryptodev_stats {
70099a2dd95SBruce Richardson 	uint64_t enqueued_count;
70199a2dd95SBruce Richardson 	/**< Count of all operations enqueued */
70299a2dd95SBruce Richardson 	uint64_t dequeued_count;
70399a2dd95SBruce Richardson 	/**< Count of all operations dequeued */
70499a2dd95SBruce Richardson 
70599a2dd95SBruce Richardson 	uint64_t enqueue_err_count;
70699a2dd95SBruce Richardson 	/**< Total error count on operations enqueued */
70799a2dd95SBruce Richardson 	uint64_t dequeue_err_count;
70899a2dd95SBruce Richardson 	/**< Total error count on operations dequeued */
70999a2dd95SBruce Richardson };
71099a2dd95SBruce Richardson 
71199a2dd95SBruce Richardson #define RTE_CRYPTODEV_NAME_MAX_LEN	(64)
71299a2dd95SBruce Richardson /**< Max length of name of crypto PMD */
71399a2dd95SBruce Richardson 
71499a2dd95SBruce Richardson /**
71599a2dd95SBruce Richardson  * Get the device identifier for the named crypto device.
71699a2dd95SBruce Richardson  *
71799a2dd95SBruce Richardson  * @param	name	device name to select the device structure.
71899a2dd95SBruce Richardson  *
71999a2dd95SBruce Richardson  * @return
72099a2dd95SBruce Richardson  *   - Returns crypto device identifier on success.
72199a2dd95SBruce Richardson  *   - Return -1 on failure to find named crypto device.
72299a2dd95SBruce Richardson  */
72316bd1c62SThomas Monjalon int
72499a2dd95SBruce Richardson rte_cryptodev_get_dev_id(const char *name);
72599a2dd95SBruce Richardson 
72699a2dd95SBruce Richardson /**
72799a2dd95SBruce Richardson  * Get the crypto device name given a device identifier.
72899a2dd95SBruce Richardson  *
72999a2dd95SBruce Richardson  * @param dev_id
73099a2dd95SBruce Richardson  *   The identifier of the device
73199a2dd95SBruce Richardson  *
73299a2dd95SBruce Richardson  * @return
73399a2dd95SBruce Richardson  *   - Returns crypto device name.
73499a2dd95SBruce Richardson  *   - Returns NULL if crypto device is not present.
73599a2dd95SBruce Richardson  */
73616bd1c62SThomas Monjalon const char *
73799a2dd95SBruce Richardson rte_cryptodev_name_get(uint8_t dev_id);
73899a2dd95SBruce Richardson 
73999a2dd95SBruce Richardson /**
74099a2dd95SBruce Richardson  * Get the total number of crypto devices that have been successfully
74199a2dd95SBruce Richardson  * initialised.
74299a2dd95SBruce Richardson  *
74399a2dd95SBruce Richardson  * @return
74499a2dd95SBruce Richardson  *   - The total number of usable crypto devices.
74599a2dd95SBruce Richardson  */
74616bd1c62SThomas Monjalon uint8_t
74799a2dd95SBruce Richardson rte_cryptodev_count(void);
74899a2dd95SBruce Richardson 
74999a2dd95SBruce Richardson /**
75099a2dd95SBruce Richardson  * Get number of crypto device defined type.
75199a2dd95SBruce Richardson  *
75299a2dd95SBruce Richardson  * @param	driver_id	driver identifier.
75399a2dd95SBruce Richardson  *
75499a2dd95SBruce Richardson  * @return
75599a2dd95SBruce Richardson  *   Returns number of crypto device.
75699a2dd95SBruce Richardson  */
75716bd1c62SThomas Monjalon uint8_t
75899a2dd95SBruce Richardson rte_cryptodev_device_count_by_driver(uint8_t driver_id);
75999a2dd95SBruce Richardson 
76099a2dd95SBruce Richardson /**
76199a2dd95SBruce Richardson  * Get number and identifiers of attached crypto devices that
76299a2dd95SBruce Richardson  * use the same crypto driver.
76399a2dd95SBruce Richardson  *
76499a2dd95SBruce Richardson  * @param	driver_name	driver name.
76599a2dd95SBruce Richardson  * @param	devices		output devices identifiers.
76699a2dd95SBruce Richardson  * @param	nb_devices	maximal number of devices.
76799a2dd95SBruce Richardson  *
76899a2dd95SBruce Richardson  * @return
76999a2dd95SBruce Richardson  *   Returns number of attached crypto device.
77099a2dd95SBruce Richardson  */
77199a2dd95SBruce Richardson uint8_t
77299a2dd95SBruce Richardson rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
77399a2dd95SBruce Richardson 		uint8_t nb_devices);
77499a2dd95SBruce Richardson /*
77599a2dd95SBruce Richardson  * Return the NUMA socket to which a device is connected
77699a2dd95SBruce Richardson  *
77799a2dd95SBruce Richardson  * @param dev_id
77899a2dd95SBruce Richardson  *   The identifier of the device
77999a2dd95SBruce Richardson  * @return
78099a2dd95SBruce Richardson  *   The NUMA socket id to which the device is connected or
78199a2dd95SBruce Richardson  *   a default of zero if the socket could not be determined.
78299a2dd95SBruce Richardson  *   -1 if returned is the dev_id value is out of range.
78399a2dd95SBruce Richardson  */
78416bd1c62SThomas Monjalon int
78599a2dd95SBruce Richardson rte_cryptodev_socket_id(uint8_t dev_id);
78699a2dd95SBruce Richardson 
78799a2dd95SBruce Richardson /** Crypto device configuration structure */
788d2d7f019SAkhil Goyal /* Structure rte_cryptodev_config 8< */
78999a2dd95SBruce Richardson struct rte_cryptodev_config {
79099a2dd95SBruce Richardson 	int socket_id;			/**< Socket to allocate resources on */
79199a2dd95SBruce Richardson 	uint16_t nb_queue_pairs;
79299a2dd95SBruce Richardson 	/**< Number of queue pairs to configure on device */
79399a2dd95SBruce Richardson 	uint64_t ff_disable;
79499a2dd95SBruce Richardson 	/**< Feature flags to be disabled. Only the following features are
79599a2dd95SBruce Richardson 	 * allowed to be disabled,
79699a2dd95SBruce Richardson 	 *  - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
79799a2dd95SBruce Richardson 	 *  - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
79899a2dd95SBruce Richardson 	 *  - RTE_CRYTPODEV_FF_SECURITY
79999a2dd95SBruce Richardson 	 */
80099a2dd95SBruce Richardson };
801d2d7f019SAkhil Goyal /* >8 End of structure rte_cryptodev_config. */
80299a2dd95SBruce Richardson 
80399a2dd95SBruce Richardson /**
80499a2dd95SBruce Richardson  * Configure a device.
80599a2dd95SBruce Richardson  *
80699a2dd95SBruce Richardson  * This function must be invoked first before any other function in the
80799a2dd95SBruce Richardson  * API. This function can also be re-invoked when a device is in the
80899a2dd95SBruce Richardson  * stopped state.
80999a2dd95SBruce Richardson  *
81099a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device to configure.
81199a2dd95SBruce Richardson  * @param	config		The crypto device configuration structure.
81299a2dd95SBruce Richardson  *
81399a2dd95SBruce Richardson  * @return
81499a2dd95SBruce Richardson  *   - 0: Success, device configured.
81599a2dd95SBruce Richardson  *   - <0: Error code returned by the driver configuration function.
81699a2dd95SBruce Richardson  */
81716bd1c62SThomas Monjalon int
81899a2dd95SBruce Richardson rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
81999a2dd95SBruce Richardson 
82099a2dd95SBruce Richardson /**
82199a2dd95SBruce Richardson  * Start an device.
82299a2dd95SBruce Richardson  *
82399a2dd95SBruce Richardson  * The device start step is the last one and consists of setting the configured
82499a2dd95SBruce Richardson  * offload features and in starting the transmit and the receive units of the
82599a2dd95SBruce Richardson  * device.
82699a2dd95SBruce Richardson  * On success, all basic functions exported by the API (link status,
82799a2dd95SBruce Richardson  * receive/transmit, and so on) can be invoked.
82899a2dd95SBruce Richardson  *
82999a2dd95SBruce Richardson  * @param dev_id
83099a2dd95SBruce Richardson  *   The identifier of the device.
83199a2dd95SBruce Richardson  * @return
83299a2dd95SBruce Richardson  *   - 0: Success, device started.
83399a2dd95SBruce Richardson  *   - <0: Error code of the driver device start function.
83499a2dd95SBruce Richardson  */
83516bd1c62SThomas Monjalon int
83699a2dd95SBruce Richardson rte_cryptodev_start(uint8_t dev_id);
83799a2dd95SBruce Richardson 
83899a2dd95SBruce Richardson /**
83999a2dd95SBruce Richardson  * Stop an device. The device can be restarted with a call to
84099a2dd95SBruce Richardson  * rte_cryptodev_start()
84199a2dd95SBruce Richardson  *
84299a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
84399a2dd95SBruce Richardson  */
84416bd1c62SThomas Monjalon void
84599a2dd95SBruce Richardson rte_cryptodev_stop(uint8_t dev_id);
84699a2dd95SBruce Richardson 
84799a2dd95SBruce Richardson /**
84899a2dd95SBruce Richardson  * Close an device. The device cannot be restarted!
84999a2dd95SBruce Richardson  *
85099a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
85199a2dd95SBruce Richardson  *
85299a2dd95SBruce Richardson  * @return
85399a2dd95SBruce Richardson  *  - 0 on successfully closing device
85499a2dd95SBruce Richardson  *  - <0 on failure to close device
85599a2dd95SBruce Richardson  */
85616bd1c62SThomas Monjalon int
85799a2dd95SBruce Richardson rte_cryptodev_close(uint8_t dev_id);
85899a2dd95SBruce Richardson 
85999a2dd95SBruce Richardson /**
86099a2dd95SBruce Richardson  * Allocate and set up a receive queue pair for a device.
86199a2dd95SBruce Richardson  *
86299a2dd95SBruce Richardson  *
86399a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
86499a2dd95SBruce Richardson  * @param	queue_pair_id	The index of the queue pairs to set up. The
86599a2dd95SBruce Richardson  *				value must be in the range [0, nb_queue_pair
86699a2dd95SBruce Richardson  *				- 1] previously supplied to
86799a2dd95SBruce Richardson  *				rte_cryptodev_configure().
86899a2dd95SBruce Richardson  * @param	qp_conf		The pointer to the configuration data to be
86999a2dd95SBruce Richardson  *				used for the queue pair.
87099a2dd95SBruce Richardson  * @param	socket_id	The *socket_id* argument is the socket
87199a2dd95SBruce Richardson  *				identifier in case of NUMA. The value can be
87299a2dd95SBruce Richardson  *				*SOCKET_ID_ANY* if there is no NUMA constraint
87399a2dd95SBruce Richardson  *				for the DMA memory allocated for the receive
87499a2dd95SBruce Richardson  *				queue pair.
87599a2dd95SBruce Richardson  *
87699a2dd95SBruce Richardson  * @return
87799a2dd95SBruce Richardson  *   - 0: Success, queue pair correctly set up.
87899a2dd95SBruce Richardson  *   - <0: Queue pair configuration failed
87999a2dd95SBruce Richardson  */
88016bd1c62SThomas Monjalon int
88199a2dd95SBruce Richardson rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
88299a2dd95SBruce Richardson 		const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
88399a2dd95SBruce Richardson 
88499a2dd95SBruce Richardson /**
8850a054e8dSVidya Sagar Velumuri  * @warning
8860a054e8dSVidya Sagar Velumuri  * @b EXPERIMENTAL: this API may change without prior notice.
8870a054e8dSVidya Sagar Velumuri  *
8880a054e8dSVidya Sagar Velumuri  * Reset a queue pair for a device.
8890a054e8dSVidya Sagar Velumuri  * The caller of this API must ensure that, there are no enqueues to the queue and there are no
8900a054e8dSVidya Sagar Velumuri  * pending/inflight packets in the queue when the API is called.
8910a054e8dSVidya Sagar Velumuri  * The API can reconfigure the queue pair when the queue pair configuration data is provided.
8920a054e8dSVidya Sagar Velumuri  *
8930a054e8dSVidya Sagar Velumuri  * @param	dev_id		The identifier of the device.
8940a054e8dSVidya Sagar Velumuri  * @param	queue_pair_id	The index of the queue pairs to set up. The value must be in the
8950a054e8dSVidya Sagar Velumuri  *				range [0, nb_queue_pair - 1] previously supplied to
8960a054e8dSVidya Sagar Velumuri  *				rte_cryptodev_configure().
8970a054e8dSVidya Sagar Velumuri  * @param	qp_conf		The pointer to configuration data to be used for the queue pair.
8980a054e8dSVidya Sagar Velumuri  *				It should be NULL, if the API is called from an interrupt context.
8990a054e8dSVidya Sagar Velumuri  * @param	socket_id	The *socket_id* argument is the socket identifier in case of NUMA.
9000a054e8dSVidya Sagar Velumuri  *				The value can be *SOCKET_ID_ANY* if there is no NUMA constraint
9010a054e8dSVidya Sagar Velumuri  *				for the DMA memory allocated for the queue pair.
9020a054e8dSVidya Sagar Velumuri  *
9030a054e8dSVidya Sagar Velumuri  * @return
9040a054e8dSVidya Sagar Velumuri  *   - 0:  Queue pair is reset successfully.
9050a054e8dSVidya Sagar Velumuri  *   - ENOTSUP: If the operation is not supported by the PMD.
9060a054e8dSVidya Sagar Velumuri  *   - <0: Queue pair reset failed
9070a054e8dSVidya Sagar Velumuri  */
9080a054e8dSVidya Sagar Velumuri __rte_experimental
9090a054e8dSVidya Sagar Velumuri int
9100a054e8dSVidya Sagar Velumuri rte_cryptodev_queue_pair_reset(uint8_t dev_id, uint16_t queue_pair_id,
9110a054e8dSVidya Sagar Velumuri 		const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
9120a054e8dSVidya Sagar Velumuri 
9130a054e8dSVidya Sagar Velumuri /**
91499a2dd95SBruce Richardson  * Get the status of queue pairs setup on a specific crypto device
91599a2dd95SBruce Richardson  *
91699a2dd95SBruce Richardson  * @param	dev_id		Crypto device identifier.
91799a2dd95SBruce Richardson  * @param	queue_pair_id	The index of the queue pairs to set up. The
91899a2dd95SBruce Richardson  *				value must be in the range [0, nb_queue_pair
91999a2dd95SBruce Richardson  *				- 1] previously supplied to
92099a2dd95SBruce Richardson  *				rte_cryptodev_configure().
92199a2dd95SBruce Richardson  * @return
92299a2dd95SBruce Richardson  *   - 0: qp was not configured
92399a2dd95SBruce Richardson  *	 - 1: qp was configured
92499a2dd95SBruce Richardson  *	 - -EINVAL: device was not configured
92599a2dd95SBruce Richardson  */
92699a2dd95SBruce Richardson int
92799a2dd95SBruce Richardson rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id);
92899a2dd95SBruce Richardson 
92999a2dd95SBruce Richardson /**
93099a2dd95SBruce Richardson  * Get the number of queue pairs on a specific crypto device
93199a2dd95SBruce Richardson  *
93299a2dd95SBruce Richardson  * @param	dev_id		Crypto device identifier.
93399a2dd95SBruce Richardson  * @return
93499a2dd95SBruce Richardson  *   - The number of configured queue pairs.
93599a2dd95SBruce Richardson  */
93616bd1c62SThomas Monjalon uint16_t
93799a2dd95SBruce Richardson rte_cryptodev_queue_pair_count(uint8_t dev_id);
93899a2dd95SBruce Richardson 
93999a2dd95SBruce Richardson 
94099a2dd95SBruce Richardson /**
94199a2dd95SBruce Richardson  * Retrieve the general I/O statistics of a device.
94299a2dd95SBruce Richardson  *
94399a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
94499a2dd95SBruce Richardson  * @param	stats		A pointer to a structure of type
94599a2dd95SBruce Richardson  *				*rte_cryptodev_stats* to be filled with the
94699a2dd95SBruce Richardson  *				values of device counters.
94799a2dd95SBruce Richardson  * @return
94899a2dd95SBruce Richardson  *   - Zero if successful.
94999a2dd95SBruce Richardson  *   - Non-zero otherwise.
95099a2dd95SBruce Richardson  */
95116bd1c62SThomas Monjalon int
95299a2dd95SBruce Richardson rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
95399a2dd95SBruce Richardson 
95499a2dd95SBruce Richardson /**
95599a2dd95SBruce Richardson  * Reset the general I/O statistics of a device.
95699a2dd95SBruce Richardson  *
95799a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
95899a2dd95SBruce Richardson  */
95916bd1c62SThomas Monjalon void
96099a2dd95SBruce Richardson rte_cryptodev_stats_reset(uint8_t dev_id);
96199a2dd95SBruce Richardson 
96299a2dd95SBruce Richardson /**
96399a2dd95SBruce Richardson  * Retrieve the contextual information of a device.
96499a2dd95SBruce Richardson  *
96599a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
96699a2dd95SBruce Richardson  * @param	dev_info	A pointer to a structure of type
96799a2dd95SBruce Richardson  *				*rte_cryptodev_info* to be filled with the
96899a2dd95SBruce Richardson  *				contextual information of the device.
96999a2dd95SBruce Richardson  *
97099a2dd95SBruce Richardson  * @note The capabilities field of dev_info is set to point to the first
97199a2dd95SBruce Richardson  * element of an array of struct rte_cryptodev_capabilities. The element after
97299a2dd95SBruce Richardson  * the last valid element has it's op field set to
97399a2dd95SBruce Richardson  * RTE_CRYPTO_OP_TYPE_UNDEFINED.
97499a2dd95SBruce Richardson  */
97516bd1c62SThomas Monjalon void
97699a2dd95SBruce Richardson rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
97799a2dd95SBruce Richardson 
97899a2dd95SBruce Richardson 
97999a2dd95SBruce Richardson /**
98099a2dd95SBruce Richardson  * Register a callback function for specific device id.
98199a2dd95SBruce Richardson  *
98299a2dd95SBruce Richardson  * @param	dev_id		Device id.
98399a2dd95SBruce Richardson  * @param	event		Event interested.
98499a2dd95SBruce Richardson  * @param	cb_fn		User supplied callback function to be called.
98599a2dd95SBruce Richardson  * @param	cb_arg		Pointer to the parameters for the registered
98699a2dd95SBruce Richardson  *				callback.
98799a2dd95SBruce Richardson  *
98899a2dd95SBruce Richardson  * @return
98999a2dd95SBruce Richardson  *  - On success, zero.
99099a2dd95SBruce Richardson  *  - On failure, a negative value.
99199a2dd95SBruce Richardson  */
99216bd1c62SThomas Monjalon int
99399a2dd95SBruce Richardson rte_cryptodev_callback_register(uint8_t dev_id,
99499a2dd95SBruce Richardson 		enum rte_cryptodev_event_type event,
99599a2dd95SBruce Richardson 		rte_cryptodev_cb_fn cb_fn, void *cb_arg);
99699a2dd95SBruce Richardson 
99799a2dd95SBruce Richardson /**
99899a2dd95SBruce Richardson  * Unregister a callback function for specific device id.
99999a2dd95SBruce Richardson  *
100099a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
100199a2dd95SBruce Richardson  * @param	event		Event interested.
100299a2dd95SBruce Richardson  * @param	cb_fn		User supplied callback function to be called.
100399a2dd95SBruce Richardson  * @param	cb_arg		Pointer to the parameters for the registered
100499a2dd95SBruce Richardson  *				callback.
100599a2dd95SBruce Richardson  *
100699a2dd95SBruce Richardson  * @return
100799a2dd95SBruce Richardson  *  - On success, zero.
100899a2dd95SBruce Richardson  *  - On failure, a negative value.
100999a2dd95SBruce Richardson  */
101016bd1c62SThomas Monjalon int
101199a2dd95SBruce Richardson rte_cryptodev_callback_unregister(uint8_t dev_id,
101299a2dd95SBruce Richardson 		enum rte_cryptodev_event_type event,
101399a2dd95SBruce Richardson 		rte_cryptodev_cb_fn cb_fn, void *cb_arg);
101499a2dd95SBruce Richardson 
1015d43e6a01SSrujana Challa /**
1016d43e6a01SSrujana Challa  * @warning
1017d43e6a01SSrujana Challa  * @b EXPERIMENTAL: this API may change without prior notice.
1018d43e6a01SSrujana Challa  *
1019d43e6a01SSrujana Challa  * Query a cryptodev queue pair if there are pending RTE_CRYPTODEV_EVENT_ERROR
1020d43e6a01SSrujana Challa  * events.
1021d43e6a01SSrujana Challa  *
1022d43e6a01SSrujana Challa  * @param          dev_id	The device identifier.
1023d43e6a01SSrujana Challa  * @param          qp_id	Queue pair index to be queried.
1024d43e6a01SSrujana Challa  *
1025d43e6a01SSrujana Challa  * @return
1026d43e6a01SSrujana Challa  *   - 1 if requested queue has a pending event.
1027d43e6a01SSrujana Challa  *   - 0 if no pending event is found.
1028d43e6a01SSrujana Challa  *   - a negative value on failure
1029d43e6a01SSrujana Challa  */
1030d43e6a01SSrujana Challa __rte_experimental
1031d43e6a01SSrujana Challa int
1032d43e6a01SSrujana Challa rte_cryptodev_queue_pair_event_error_query(uint8_t dev_id, uint16_t qp_id);
1033d43e6a01SSrujana Challa 
103499a2dd95SBruce Richardson struct rte_cryptodev_callback;
103599a2dd95SBruce Richardson 
103699a2dd95SBruce Richardson /** Structure to keep track of registered callbacks */
1037f1f6ebc0SWilliam Tu RTE_TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
103899a2dd95SBruce Richardson 
103999a2dd95SBruce Richardson /**
104099a2dd95SBruce Richardson  * Structure used to hold information about the callbacks to be called for a
104199a2dd95SBruce Richardson  * queue pair on enqueue/dequeue.
104299a2dd95SBruce Richardson  */
104399a2dd95SBruce Richardson struct rte_cryptodev_cb {
1044ab1932afSTyler Retzlaff 	RTE_ATOMIC(struct rte_cryptodev_cb *) next;
104599a2dd95SBruce Richardson 	/**< Pointer to next callback */
104699a2dd95SBruce Richardson 	rte_cryptodev_callback_fn fn;
104799a2dd95SBruce Richardson 	/**< Pointer to callback function */
104899a2dd95SBruce Richardson 	void *arg;
104999a2dd95SBruce Richardson 	/**< Pointer to argument */
105099a2dd95SBruce Richardson };
105199a2dd95SBruce Richardson 
105299a2dd95SBruce Richardson /**
105399a2dd95SBruce Richardson  * @internal
105499a2dd95SBruce Richardson  * Structure used to hold information about the RCU for a queue pair.
105599a2dd95SBruce Richardson  */
105699a2dd95SBruce Richardson struct rte_cryptodev_cb_rcu {
1057ab1932afSTyler Retzlaff 	RTE_ATOMIC(struct rte_cryptodev_cb *) next;
105899a2dd95SBruce Richardson 	/**< Pointer to next callback */
105999a2dd95SBruce Richardson 	struct rte_rcu_qsbr *qsbr;
106099a2dd95SBruce Richardson 	/**< RCU QSBR variable per queue pair */
106199a2dd95SBruce Richardson };
106299a2dd95SBruce Richardson 
10631e71cb20SAnoob Joseph /**
10641e71cb20SAnoob Joseph  * Get the security context for the cryptodev.
10651e71cb20SAnoob Joseph  *
10661e71cb20SAnoob Joseph  * @param dev_id
10671e71cb20SAnoob Joseph  *   The device identifier.
10681e71cb20SAnoob Joseph  * @return
10691e71cb20SAnoob Joseph  *   - NULL on error.
10701e71cb20SAnoob Joseph  *   - Pointer to security context on success.
10711e71cb20SAnoob Joseph  */
107299a2dd95SBruce Richardson void *
107399a2dd95SBruce Richardson rte_cryptodev_get_sec_ctx(uint8_t dev_id);
107499a2dd95SBruce Richardson 
107599a2dd95SBruce Richardson /**
107699a2dd95SBruce Richardson  * Create a symmetric session mempool.
107799a2dd95SBruce Richardson  *
107899a2dd95SBruce Richardson  * @param name
107999a2dd95SBruce Richardson  *   The unique mempool name.
108099a2dd95SBruce Richardson  * @param nb_elts
108199a2dd95SBruce Richardson  *   The number of elements in the mempool.
108299a2dd95SBruce Richardson  * @param elt_size
10839a8569acSFan Zhang  *   The size of the element. This should be the size of the cryptodev PMD
10849a8569acSFan Zhang  *   session private data obtained through
10859a8569acSFan Zhang  *   rte_cryptodev_sym_get_private_session_size() function call.
10869a8569acSFan Zhang  *   For the user who wants to use the same mempool for heterogeneous PMDs
10879a8569acSFan Zhang  *   this value should be the maximum value of their private session sizes.
10889a8569acSFan Zhang  *   Please note the created mempool will have bigger elt size than this
10899a8569acSFan Zhang  *   value as necessary session header and the possible padding are filled
10909a8569acSFan Zhang  *   into each elt.
109199a2dd95SBruce Richardson  * @param cache_size
109299a2dd95SBruce Richardson  *   The number of per-lcore cache elements
109399a2dd95SBruce Richardson  * @param priv_size
109499a2dd95SBruce Richardson  *   The private data size of each session.
109599a2dd95SBruce Richardson  * @param socket_id
109699a2dd95SBruce Richardson  *   The *socket_id* argument is the socket identifier in the case of
109799a2dd95SBruce Richardson  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
109899a2dd95SBruce Richardson  *   constraint for the reserved zone.
109999a2dd95SBruce Richardson  *
110099a2dd95SBruce Richardson  * @return
11019a8569acSFan Zhang  *  - On success returns the created session mempool pointer
11029a8569acSFan Zhang  *  - On failure returns NULL
110399a2dd95SBruce Richardson  */
110499a2dd95SBruce Richardson struct rte_mempool *
110599a2dd95SBruce Richardson rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
110699a2dd95SBruce Richardson 	uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
110799a2dd95SBruce Richardson 	int socket_id);
110899a2dd95SBruce Richardson 
1109bdce2564SAkhil Goyal 
111099a2dd95SBruce Richardson /**
11111f1e4b7cSCiara Power  * Create an asymmetric session mempool.
11121f1e4b7cSCiara Power  *
11131f1e4b7cSCiara Power  * @param name
11141f1e4b7cSCiara Power  *   The unique mempool name.
11151f1e4b7cSCiara Power  * @param nb_elts
11161f1e4b7cSCiara Power  *   The number of elements in the mempool.
11171f1e4b7cSCiara Power  * @param cache_size
11181f1e4b7cSCiara Power  *   The number of per-lcore cache elements
111992d55afeSCiara Power  * @param user_data_size
112092d55afeSCiara Power  *   The size of user data to be placed after session private data.
11211f1e4b7cSCiara Power  * @param socket_id
11221f1e4b7cSCiara Power  *   The *socket_id* argument is the socket identifier in the case of
11231f1e4b7cSCiara Power  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
11241f1e4b7cSCiara Power  *   constraint for the reserved zone.
11251f1e4b7cSCiara Power  *
11261f1e4b7cSCiara Power  * @return
11271f1e4b7cSCiara Power  *  - On success return mempool
11281f1e4b7cSCiara Power  *  - On failure returns NULL
11291f1e4b7cSCiara Power  */
11301f1e4b7cSCiara Power struct rte_mempool *
11311f1e4b7cSCiara Power rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
113292d55afeSCiara Power 	uint32_t cache_size, uint16_t user_data_size, int socket_id);
11331f1e4b7cSCiara Power 
11341f1e4b7cSCiara Power /**
1135bdce2564SAkhil Goyal  * Create symmetric crypto session and fill out private data for the device id,
1136bdce2564SAkhil Goyal  * based on its device type.
113799a2dd95SBruce Richardson  *
1138bdce2564SAkhil Goyal  * @param   dev_id   ID of device that we want the session to be used on
1139bdce2564SAkhil Goyal  * @param   xforms   Symmetric crypto transform operations to apply on flow
1140bdce2564SAkhil Goyal  *                   processed with this session
11413a3bd785SAnoob Joseph  * @param   mp       Mempool to allocate symmetric session objects from
1142bdce2564SAkhil Goyal  *
114399a2dd95SBruce Richardson  * @return
1144bdce2564SAkhil Goyal  *  - On success return pointer to sym-session.
11453a3bd785SAnoob Joseph  *  - On failure returns NULL and rte_errno is set to the error code:
11463a3bd785SAnoob Joseph  *    - EINVAL on invalid arguments.
11473a3bd785SAnoob Joseph  *    - ENOMEM on memory error for session allocation.
11483a3bd785SAnoob Joseph  *    - ENOTSUP if device doesn't support session configuration.
114999a2dd95SBruce Richardson  */
1150bdce2564SAkhil Goyal void *
1151bdce2564SAkhil Goyal rte_cryptodev_sym_session_create(uint8_t dev_id,
1152bdce2564SAkhil Goyal 		struct rte_crypto_sym_xform *xforms,
1153bdce2564SAkhil Goyal 		struct rte_mempool *mp);
115499a2dd95SBruce Richardson /**
11551f1e4b7cSCiara Power  * Create and initialise an asymmetric crypto session structure.
11561f1e4b7cSCiara Power  * Calls the PMD to configure the private session data.
115799a2dd95SBruce Richardson  *
11581f1e4b7cSCiara Power  * @param   dev_id   ID of device that we want the session to be used on
11591f1e4b7cSCiara Power  * @param   xforms   Asymmetric crypto transform operations to apply on flow
11601f1e4b7cSCiara Power  *                   processed with this session
11611f1e4b7cSCiara Power  * @param   mp       mempool to allocate asymmetric session
116299a2dd95SBruce Richardson  *                   objects from
1163757f40e2SCiara Power  * @param   session  void ** for session to be used
1164757f40e2SCiara Power  *
116599a2dd95SBruce Richardson  * @return
1166757f40e2SCiara Power  *  - 0 on success.
1167757f40e2SCiara Power  *  - -EINVAL on invalid arguments.
1168757f40e2SCiara Power  *  - -ENOMEM on memory error for session allocation.
1169757f40e2SCiara Power  *  - -ENOTSUP if device doesn't support session configuration.
117099a2dd95SBruce Richardson  */
1171757f40e2SCiara Power int
11721f1e4b7cSCiara Power rte_cryptodev_asym_session_create(uint8_t dev_id,
1173757f40e2SCiara Power 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
1174757f40e2SCiara Power 		void **session);
117599a2dd95SBruce Richardson 
117699a2dd95SBruce Richardson /**
1177bdce2564SAkhil Goyal  * Frees session for the device id and returning it to its mempool.
1178bdce2564SAkhil Goyal  * It is the application's responsibility to ensure that the session
1179bdce2564SAkhil Goyal  * is not still in-flight operations using it.
118099a2dd95SBruce Richardson  *
1181bdce2564SAkhil Goyal  * @param   dev_id   ID of device that uses the session.
118299a2dd95SBruce Richardson  * @param   sess     Session header to be freed.
118399a2dd95SBruce Richardson  *
118499a2dd95SBruce Richardson  * @return
118599a2dd95SBruce Richardson  *  - 0 if successful.
1186bdce2564SAkhil Goyal  *  - -EINVAL if session is NULL or the mismatched device ids.
118799a2dd95SBruce Richardson  */
118899a2dd95SBruce Richardson int
1189bdce2564SAkhil Goyal rte_cryptodev_sym_session_free(uint8_t dev_id,
11902a440d6aSAkhil Goyal 	void *sess);
119199a2dd95SBruce Richardson 
119299a2dd95SBruce Richardson /**
11931f1e4b7cSCiara Power  * Clears and frees asymmetric crypto session header and private data,
11941f1e4b7cSCiara Power  * returning it to its original mempool.
119599a2dd95SBruce Richardson  *
11961f1e4b7cSCiara Power  * @param   dev_id   ID of device that uses the asymmetric session.
119799a2dd95SBruce Richardson  * @param   sess     Session header to be freed.
119899a2dd95SBruce Richardson  *
119999a2dd95SBruce Richardson  * @return
120099a2dd95SBruce Richardson  *  - 0 if successful.
12011f1e4b7cSCiara Power  *  - -EINVAL if device is invalid or session is NULL.
120299a2dd95SBruce Richardson  */
120399a2dd95SBruce Richardson int
1204a29bb248SCiara Power rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
120599a2dd95SBruce Richardson 
120699a2dd95SBruce Richardson /**
12071f1e4b7cSCiara Power  * Get the size of the asymmetric session header.
120899a2dd95SBruce Richardson  *
120999a2dd95SBruce Richardson  * @return
121099a2dd95SBruce Richardson  *   Size of the asymmetric header session.
121199a2dd95SBruce Richardson  */
121299a2dd95SBruce Richardson unsigned int
121399a2dd95SBruce Richardson rte_cryptodev_asym_get_header_session_size(void);
121499a2dd95SBruce Richardson 
121599a2dd95SBruce Richardson /**
121699a2dd95SBruce Richardson  * Get the size of the private symmetric session data
121799a2dd95SBruce Richardson  * for a device.
121899a2dd95SBruce Richardson  *
121999a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
122099a2dd95SBruce Richardson  *
122199a2dd95SBruce Richardson  * @return
122299a2dd95SBruce Richardson  *   - Size of the private data, if successful
122399a2dd95SBruce Richardson  *   - 0 if device is invalid or does not have private
122499a2dd95SBruce Richardson  *   symmetric session
122599a2dd95SBruce Richardson  */
122699a2dd95SBruce Richardson unsigned int
122799a2dd95SBruce Richardson rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
122899a2dd95SBruce Richardson 
122999a2dd95SBruce Richardson /**
123099a2dd95SBruce Richardson  * Get the size of the private data for asymmetric session
123199a2dd95SBruce Richardson  * on device
123299a2dd95SBruce Richardson  *
123399a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
123499a2dd95SBruce Richardson  *
123599a2dd95SBruce Richardson  * @return
123699a2dd95SBruce Richardson  *   - Size of the asymmetric private data, if successful
123799a2dd95SBruce Richardson  *   - 0 if device is invalid or does not have private session
123899a2dd95SBruce Richardson  */
123999a2dd95SBruce Richardson unsigned int
124099a2dd95SBruce Richardson rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
124199a2dd95SBruce Richardson 
124299a2dd95SBruce Richardson /**
1243e74abd48SAkhil Goyal  * Validate if the crypto device index is valid attached crypto device.
1244e74abd48SAkhil Goyal  *
1245e74abd48SAkhil Goyal  * @param	dev_id	Crypto device index.
1246e74abd48SAkhil Goyal  *
1247e74abd48SAkhil Goyal  * @return
1248e74abd48SAkhil Goyal  *   - If the device index is valid (1) or not (0).
1249e74abd48SAkhil Goyal  */
1250e74abd48SAkhil Goyal unsigned int
1251e74abd48SAkhil Goyal rte_cryptodev_is_valid_dev(uint8_t dev_id);
1252e74abd48SAkhil Goyal 
1253e74abd48SAkhil Goyal /**
125499a2dd95SBruce Richardson  * Provide driver identifier.
125599a2dd95SBruce Richardson  *
125699a2dd95SBruce Richardson  * @param name
125799a2dd95SBruce Richardson  *   The pointer to a driver name.
125899a2dd95SBruce Richardson  * @return
125999a2dd95SBruce Richardson  *  The driver type identifier or -1 if no driver found
126099a2dd95SBruce Richardson  */
126199a2dd95SBruce Richardson int rte_cryptodev_driver_id_get(const char *name);
126299a2dd95SBruce Richardson 
126399a2dd95SBruce Richardson /**
126499a2dd95SBruce Richardson  * Provide driver name.
126599a2dd95SBruce Richardson  *
126699a2dd95SBruce Richardson  * @param driver_id
126799a2dd95SBruce Richardson  *   The driver identifier.
126899a2dd95SBruce Richardson  * @return
126999a2dd95SBruce Richardson  *  The driver name or null if no driver found
127099a2dd95SBruce Richardson  */
127199a2dd95SBruce Richardson const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
127299a2dd95SBruce Richardson 
127399a2dd95SBruce Richardson /**
127499a2dd95SBruce Richardson  * Store user data in a session.
127599a2dd95SBruce Richardson  *
127699a2dd95SBruce Richardson  * @param	sess		Session pointer allocated by
127799a2dd95SBruce Richardson  *				*rte_cryptodev_sym_session_create*.
127899a2dd95SBruce Richardson  * @param	data		Pointer to the user data.
127999a2dd95SBruce Richardson  * @param	size		Size of the user data.
128099a2dd95SBruce Richardson  *
128199a2dd95SBruce Richardson  * @return
128299a2dd95SBruce Richardson  *  - On success, zero.
128399a2dd95SBruce Richardson  *  - On failure, a negative value.
128499a2dd95SBruce Richardson  */
128599a2dd95SBruce Richardson int
12862a440d6aSAkhil Goyal rte_cryptodev_sym_session_set_user_data(void *sess,
128799a2dd95SBruce Richardson 					void *data,
128899a2dd95SBruce Richardson 					uint16_t size);
128999a2dd95SBruce Richardson 
12902a440d6aSAkhil Goyal #define CRYPTO_SESS_OPAQUE_DATA_OFF 0
12912a440d6aSAkhil Goyal /**
12922a440d6aSAkhil Goyal  * Get opaque data from session handle
12932a440d6aSAkhil Goyal  */
12942a440d6aSAkhil Goyal static inline uint64_t
12952a440d6aSAkhil Goyal rte_cryptodev_sym_session_opaque_data_get(void *sess)
12962a440d6aSAkhil Goyal {
12972a440d6aSAkhil Goyal 	return *((uint64_t *)sess + CRYPTO_SESS_OPAQUE_DATA_OFF);
12982a440d6aSAkhil Goyal }
12992a440d6aSAkhil Goyal 
13002a440d6aSAkhil Goyal /**
13012a440d6aSAkhil Goyal  * Set opaque data in session handle
13022a440d6aSAkhil Goyal  */
13032a440d6aSAkhil Goyal static inline void
13042a440d6aSAkhil Goyal rte_cryptodev_sym_session_opaque_data_set(void *sess, uint64_t opaque)
13052a440d6aSAkhil Goyal {
13062a440d6aSAkhil Goyal 	uint64_t *data;
13072a440d6aSAkhil Goyal 	data = (((uint64_t *)sess) + CRYPTO_SESS_OPAQUE_DATA_OFF);
13082a440d6aSAkhil Goyal 	*data = opaque;
13092a440d6aSAkhil Goyal }
13102a440d6aSAkhil Goyal 
131199a2dd95SBruce Richardson /**
131299a2dd95SBruce Richardson  * Get user data stored in a session.
131399a2dd95SBruce Richardson  *
131499a2dd95SBruce Richardson  * @param	sess		Session pointer allocated by
131599a2dd95SBruce Richardson  *				*rte_cryptodev_sym_session_create*.
131699a2dd95SBruce Richardson  *
131799a2dd95SBruce Richardson  * @return
131899a2dd95SBruce Richardson  *  - On success return pointer to user data.
131999a2dd95SBruce Richardson  *  - On failure returns NULL.
132099a2dd95SBruce Richardson  */
132199a2dd95SBruce Richardson void *
13222a440d6aSAkhil Goyal rte_cryptodev_sym_session_get_user_data(void *sess);
132399a2dd95SBruce Richardson 
132499a2dd95SBruce Richardson /**
132592d55afeSCiara Power  * Store user data in an asymmetric session.
132692d55afeSCiara Power  *
132792d55afeSCiara Power  * @param	sess		Session pointer allocated by
132892d55afeSCiara Power  *				*rte_cryptodev_asym_session_create*.
132992d55afeSCiara Power  * @param	data		Pointer to the user data.
133092d55afeSCiara Power  * @param	size		Size of the user data.
133192d55afeSCiara Power  *
133292d55afeSCiara Power  * @return
133392d55afeSCiara Power  *  - On success, zero.
133492d55afeSCiara Power  *  - -EINVAL if the session pointer is invalid.
133592d55afeSCiara Power  *  - -ENOMEM if the available user data size is smaller than the size parameter.
133692d55afeSCiara Power  */
133792d55afeSCiara Power int
133892d55afeSCiara Power rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
133992d55afeSCiara Power 
134092d55afeSCiara Power /**
134192d55afeSCiara Power  * Get user data stored in an asymmetric session.
134292d55afeSCiara Power  *
134392d55afeSCiara Power  * @param	sess		Session pointer allocated by
134492d55afeSCiara Power  *				*rte_cryptodev_asym_session_create*.
134592d55afeSCiara Power  *
134692d55afeSCiara Power  * @return
134792d55afeSCiara Power  *  - On success return pointer to user data.
134892d55afeSCiara Power  *  - On failure returns NULL.
134992d55afeSCiara Power  */
135092d55afeSCiara Power void *
135192d55afeSCiara Power rte_cryptodev_asym_session_get_user_data(void *sess);
135292d55afeSCiara Power 
135392d55afeSCiara Power /**
135499a2dd95SBruce Richardson  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
135599a2dd95SBruce Richardson  * on user provided data.
135699a2dd95SBruce Richardson  *
135799a2dd95SBruce Richardson  * @param	dev_id	The device identifier.
135899a2dd95SBruce Richardson  * @param	sess	Cryptodev session structure
135999a2dd95SBruce Richardson  * @param	ofs	Start and stop offsets for auth and cipher operations
136099a2dd95SBruce Richardson  * @param	vec	Vectorized operation descriptor
136199a2dd95SBruce Richardson  *
136299a2dd95SBruce Richardson  * @return
136399a2dd95SBruce Richardson  *  - Returns number of successfully processed packets.
136499a2dd95SBruce Richardson  */
136599a2dd95SBruce Richardson uint32_t
136699a2dd95SBruce Richardson rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
13672a440d6aSAkhil Goyal 	void *sess, union rte_crypto_sym_ofs ofs,
136899a2dd95SBruce Richardson 	struct rte_crypto_sym_vec *vec);
136999a2dd95SBruce Richardson 
137099a2dd95SBruce Richardson /**
137199a2dd95SBruce Richardson  * Get the size of the raw data-path context buffer.
137299a2dd95SBruce Richardson  *
137399a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
137499a2dd95SBruce Richardson  *
137599a2dd95SBruce Richardson  * @return
137699a2dd95SBruce Richardson  *   - If the device supports raw data-path APIs, return the context size.
137799a2dd95SBruce Richardson  *   - If the device does not support the APIs, return -1.
137899a2dd95SBruce Richardson  */
137999a2dd95SBruce Richardson int
138099a2dd95SBruce Richardson rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id);
138199a2dd95SBruce Richardson 
138299a2dd95SBruce Richardson /**
1383a7ddfa9cSVolodymyr Fialko  * Set session event meta data
1384a7ddfa9cSVolodymyr Fialko  *
1385a7ddfa9cSVolodymyr Fialko  * @param	dev_id		The device identifier.
1386a7ddfa9cSVolodymyr Fialko  * @param	sess            Crypto or security session.
1387a7ddfa9cSVolodymyr Fialko  * @param	op_type         Operation type.
1388a7ddfa9cSVolodymyr Fialko  * @param	sess_type       Session type.
1389a7ddfa9cSVolodymyr Fialko  * @param	ev_mdata	Pointer to the event crypto meta data
1390a7ddfa9cSVolodymyr Fialko  *				(aka *union rte_event_crypto_metadata*)
1391a7ddfa9cSVolodymyr Fialko  * @param	size            Size of ev_mdata.
1392a7ddfa9cSVolodymyr Fialko  *
1393a7ddfa9cSVolodymyr Fialko  * @return
1394a7ddfa9cSVolodymyr Fialko  *  - On success, zero.
1395a7ddfa9cSVolodymyr Fialko  *  - On failure, a negative value.
1396a7ddfa9cSVolodymyr Fialko  */
1397a7ddfa9cSVolodymyr Fialko int
1398a7ddfa9cSVolodymyr Fialko rte_cryptodev_session_event_mdata_set(uint8_t dev_id, void *sess,
1399a7ddfa9cSVolodymyr Fialko 	enum rte_crypto_op_type op_type,
1400a7ddfa9cSVolodymyr Fialko 	enum rte_crypto_op_sess_type sess_type,
1401a7ddfa9cSVolodymyr Fialko 	void *ev_mdata, uint16_t size);
1402a7ddfa9cSVolodymyr Fialko 
1403a7ddfa9cSVolodymyr Fialko /**
140499a2dd95SBruce Richardson  * Union of different crypto session types, including session-less xform
140599a2dd95SBruce Richardson  * pointer.
140699a2dd95SBruce Richardson  */
14072a440d6aSAkhil Goyal union rte_cryptodev_session_ctx {void *crypto_sess;
140899a2dd95SBruce Richardson 	struct rte_crypto_sym_xform *xform;
140999a2dd95SBruce Richardson 	struct rte_security_session *sec_sess;
141099a2dd95SBruce Richardson };
141199a2dd95SBruce Richardson 
141299a2dd95SBruce Richardson /**
141399a2dd95SBruce Richardson  * Enqueue a vectorized operation descriptor into the device queue but the
141499a2dd95SBruce Richardson  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
141599a2dd95SBruce Richardson  * is called.
141699a2dd95SBruce Richardson  *
141799a2dd95SBruce Richardson  * @param	qp		Driver specific queue pair data.
141899a2dd95SBruce Richardson  * @param	drv_ctx		Driver specific context data.
141999a2dd95SBruce Richardson  * @param	vec		Vectorized operation descriptor.
142099a2dd95SBruce Richardson  * @param	ofs		Start and stop offsets for auth and cipher
142199a2dd95SBruce Richardson  *				operations.
142299a2dd95SBruce Richardson  * @param	user_data	The array of user data for dequeue later.
142399a2dd95SBruce Richardson  * @param	enqueue_status	Driver written value to specify the
142499a2dd95SBruce Richardson  *				enqueue status. Possible values:
142599a2dd95SBruce Richardson  *				- 1: The number of operations returned are
142699a2dd95SBruce Richardson  *				     enqueued successfully.
142799a2dd95SBruce Richardson  *				- 0: The number of operations returned are
142899a2dd95SBruce Richardson  *				     cached into the queue but are not processed
142999a2dd95SBruce Richardson  *				     until rte_cryptodev_raw_enqueue_done() is
143099a2dd95SBruce Richardson  *				     called.
143199a2dd95SBruce Richardson  *				- negative integer: Error occurred.
143299a2dd95SBruce Richardson  * @return
143399a2dd95SBruce Richardson  *   - The number of operations in the descriptor successfully enqueued or
143499a2dd95SBruce Richardson  *     cached into the queue but not enqueued yet, depends on the
143599a2dd95SBruce Richardson  *     "enqueue_status" value.
143699a2dd95SBruce Richardson  */
143799a2dd95SBruce Richardson typedef uint32_t (*cryptodev_sym_raw_enqueue_burst_t)(
143899a2dd95SBruce Richardson 	void *qp, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
143999a2dd95SBruce Richardson 	union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status);
144099a2dd95SBruce Richardson 
144199a2dd95SBruce Richardson /**
144299a2dd95SBruce Richardson  * Enqueue single raw data vector into the device queue but the driver may or
144399a2dd95SBruce Richardson  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
144499a2dd95SBruce Richardson  *
144599a2dd95SBruce Richardson  * @param	qp		Driver specific queue pair data.
144699a2dd95SBruce Richardson  * @param	drv_ctx		Driver specific context data.
144799a2dd95SBruce Richardson  * @param	data_vec	The buffer data vector.
144899a2dd95SBruce Richardson  * @param	n_data_vecs	Number of buffer data vectors.
144999a2dd95SBruce Richardson  * @param	ofs		Start and stop offsets for auth and cipher
145099a2dd95SBruce Richardson  *				operations.
145199a2dd95SBruce Richardson  * @param	iv		IV virtual and IOVA addresses
145299a2dd95SBruce Richardson  * @param	digest		digest virtual and IOVA addresses
145399a2dd95SBruce Richardson  * @param	aad_or_auth_iv	AAD or auth IV virtual and IOVA addresses,
145499a2dd95SBruce Richardson  *				depends on the algorithm used.
145599a2dd95SBruce Richardson  * @param	user_data	The user data.
145699a2dd95SBruce Richardson  * @return
145799a2dd95SBruce Richardson  *   - 1: The data vector is enqueued successfully.
145899a2dd95SBruce Richardson  *   - 0: The data vector is cached into the queue but is not processed
145999a2dd95SBruce Richardson  *        until rte_cryptodev_raw_enqueue_done() is called.
146099a2dd95SBruce Richardson  *   - negative integer: failure.
146199a2dd95SBruce Richardson  */
146299a2dd95SBruce Richardson typedef int (*cryptodev_sym_raw_enqueue_t)(
146399a2dd95SBruce Richardson 	void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
146499a2dd95SBruce Richardson 	uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
146599a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *iv,
146699a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *digest,
146799a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
146899a2dd95SBruce Richardson 	void *user_data);
146999a2dd95SBruce Richardson 
147099a2dd95SBruce Richardson /**
147199a2dd95SBruce Richardson  * Inform the cryptodev queue pair to start processing or finish dequeuing all
147299a2dd95SBruce Richardson  * enqueued/dequeued operations.
147399a2dd95SBruce Richardson  *
147499a2dd95SBruce Richardson  * @param	qp		Driver specific queue pair data.
147599a2dd95SBruce Richardson  * @param	drv_ctx		Driver specific context data.
147699a2dd95SBruce Richardson  * @param	n		The total number of processed operations.
147799a2dd95SBruce Richardson  * @return
147899a2dd95SBruce Richardson  *   - On success return 0.
147999a2dd95SBruce Richardson  *   - On failure return negative integer.
148099a2dd95SBruce Richardson  */
148199a2dd95SBruce Richardson typedef int (*cryptodev_sym_raw_operation_done_t)(void *qp, uint8_t *drv_ctx,
148299a2dd95SBruce Richardson 	uint32_t n);
148399a2dd95SBruce Richardson 
148499a2dd95SBruce Richardson /**
148599a2dd95SBruce Richardson  * Typedef that the user provided for the driver to get the dequeue count.
148699a2dd95SBruce Richardson  * The function may return a fixed number or the number parsed from the user
148799a2dd95SBruce Richardson  * data stored in the first processed operation.
148899a2dd95SBruce Richardson  *
148999a2dd95SBruce Richardson  * @param	user_data	Dequeued user data.
149099a2dd95SBruce Richardson  * @return
149199a2dd95SBruce Richardson  *  - The number of operations to be dequeued.
14923e4c5be9SThomas Monjalon  */
149399a2dd95SBruce Richardson typedef uint32_t (*rte_cryptodev_raw_get_dequeue_count_t)(void *user_data);
149499a2dd95SBruce Richardson 
149599a2dd95SBruce Richardson /**
149699a2dd95SBruce Richardson  * Typedef that the user provided to deal with post dequeue operation, such
149799a2dd95SBruce Richardson  * as filling status.
149899a2dd95SBruce Richardson  *
149999a2dd95SBruce Richardson  * @param	user_data	Dequeued user data.
150099a2dd95SBruce Richardson  * @param	index		Index number of the processed descriptor.
150199a2dd95SBruce Richardson  * @param	is_op_success	Operation status provided by the driver.
15023e4c5be9SThomas Monjalon  */
150399a2dd95SBruce Richardson typedef void (*rte_cryptodev_raw_post_dequeue_t)(void *user_data,
150499a2dd95SBruce Richardson 	uint32_t index, uint8_t is_op_success);
150599a2dd95SBruce Richardson 
150699a2dd95SBruce Richardson /**
150799a2dd95SBruce Richardson  * Dequeue a burst of symmetric crypto processing.
150899a2dd95SBruce Richardson  *
150999a2dd95SBruce Richardson  * @param	qp			Driver specific queue pair data.
151099a2dd95SBruce Richardson  * @param	drv_ctx			Driver specific context data.
151199a2dd95SBruce Richardson  * @param	get_dequeue_count	User provided callback function to
151299a2dd95SBruce Richardson  *					obtain dequeue operation count.
151399a2dd95SBruce Richardson  * @param	max_nb_to_dequeue	When get_dequeue_count is NULL this
151499a2dd95SBruce Richardson  *					value is used to pass the maximum
151599a2dd95SBruce Richardson  *					number of operations to be dequeued.
151699a2dd95SBruce Richardson  * @param	post_dequeue		User provided callback function to
151799a2dd95SBruce Richardson  *					post-process a dequeued operation.
151899a2dd95SBruce Richardson  * @param	out_user_data		User data pointer array to be retrieve
151999a2dd95SBruce Richardson  *					from device queue. In case of
152099a2dd95SBruce Richardson  *					*is_user_data_array* is set there
152199a2dd95SBruce Richardson  *					should be enough room to store all
152299a2dd95SBruce Richardson  *					user data.
152399a2dd95SBruce Richardson  * @param	is_user_data_array	Set 1 if every dequeued user data will
152499a2dd95SBruce Richardson  *					be written into out_user_data array.
152599a2dd95SBruce Richardson  *					Set 0 if only the first user data will
152699a2dd95SBruce Richardson  *					be written into out_user_data array.
152799a2dd95SBruce Richardson  * @param	n_success		Driver written value to specific the
152899a2dd95SBruce Richardson  *					total successful operations count.
152999a2dd95SBruce Richardson  * @param	dequeue_status		Driver written value to specify the
153099a2dd95SBruce Richardson  *					dequeue status. Possible values:
153199a2dd95SBruce Richardson  *					- 1: Successfully dequeued the number
153299a2dd95SBruce Richardson  *					     of operations returned. The user
153399a2dd95SBruce Richardson  *					     data previously set during enqueue
153499a2dd95SBruce Richardson  *					     is stored in the "out_user_data".
153599a2dd95SBruce Richardson  *					- 0: The number of operations returned
153699a2dd95SBruce Richardson  *					     are completed and the user data is
153799a2dd95SBruce Richardson  *					     stored in the "out_user_data", but
153899a2dd95SBruce Richardson  *					     they are not freed from the queue
153999a2dd95SBruce Richardson  *					     until
154099a2dd95SBruce Richardson  *					     rte_cryptodev_raw_dequeue_done()
154199a2dd95SBruce Richardson  *					     is called.
154299a2dd95SBruce Richardson  *					- negative integer: Error occurred.
154399a2dd95SBruce Richardson  * @return
154499a2dd95SBruce Richardson  *   - The number of operations dequeued or completed but not freed from the
154599a2dd95SBruce Richardson  *     queue, depends on "dequeue_status" value.
154699a2dd95SBruce Richardson  */
154799a2dd95SBruce Richardson typedef uint32_t (*cryptodev_sym_raw_dequeue_burst_t)(void *qp,
154899a2dd95SBruce Richardson 	uint8_t *drv_ctx,
154999a2dd95SBruce Richardson 	rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
155099a2dd95SBruce Richardson 	uint32_t max_nb_to_dequeue,
155199a2dd95SBruce Richardson 	rte_cryptodev_raw_post_dequeue_t post_dequeue,
155299a2dd95SBruce Richardson 	void **out_user_data, uint8_t is_user_data_array,
155399a2dd95SBruce Richardson 	uint32_t *n_success, int *dequeue_status);
155499a2dd95SBruce Richardson 
155599a2dd95SBruce Richardson /**
155699a2dd95SBruce Richardson  * Dequeue a symmetric crypto processing.
155799a2dd95SBruce Richardson  *
155899a2dd95SBruce Richardson  * @param	qp			Driver specific queue pair data.
155999a2dd95SBruce Richardson  * @param	drv_ctx			Driver specific context data.
156099a2dd95SBruce Richardson  * @param	dequeue_status		Driver written value to specify the
156199a2dd95SBruce Richardson  *					dequeue status. Possible values:
156299a2dd95SBruce Richardson  *					- 1: Successfully dequeued a operation.
156399a2dd95SBruce Richardson  *					     The user data is returned.
156499a2dd95SBruce Richardson  *					- 0: The first operation in the queue
156599a2dd95SBruce Richardson  *					     is completed and the user data
156699a2dd95SBruce Richardson  *					     previously set during enqueue is
156799a2dd95SBruce Richardson  *					     returned, but it is not freed from
156899a2dd95SBruce Richardson  *					     the queue until
156999a2dd95SBruce Richardson  *					     rte_cryptodev_raw_dequeue_done() is
157099a2dd95SBruce Richardson  *					     called.
157199a2dd95SBruce Richardson  *					- negative integer: Error occurred.
157299a2dd95SBruce Richardson  * @param	op_status		Driver written value to specify
157399a2dd95SBruce Richardson  *					operation status.
157499a2dd95SBruce Richardson  * @return
157599a2dd95SBruce Richardson  *   - The user data pointer retrieved from device queue or NULL if no
157699a2dd95SBruce Richardson  *     operation is ready for dequeue.
157799a2dd95SBruce Richardson  */
157899a2dd95SBruce Richardson typedef void * (*cryptodev_sym_raw_dequeue_t)(
157999a2dd95SBruce Richardson 		void *qp, uint8_t *drv_ctx, int *dequeue_status,
158099a2dd95SBruce Richardson 		enum rte_crypto_op_status *op_status);
158199a2dd95SBruce Richardson 
158299a2dd95SBruce Richardson /**
158399a2dd95SBruce Richardson  * Context data for raw data-path API crypto process. The buffer of this
158499a2dd95SBruce Richardson  * structure is to be allocated by the user application with the size equal
158599a2dd95SBruce Richardson  * or bigger than rte_cryptodev_get_raw_dp_ctx_size() returned value.
158699a2dd95SBruce Richardson  */
158799a2dd95SBruce Richardson struct rte_crypto_raw_dp_ctx {
158899a2dd95SBruce Richardson 	void *qp_data;
158999a2dd95SBruce Richardson 
159099a2dd95SBruce Richardson 	cryptodev_sym_raw_enqueue_t enqueue;
159199a2dd95SBruce Richardson 	cryptodev_sym_raw_enqueue_burst_t enqueue_burst;
159299a2dd95SBruce Richardson 	cryptodev_sym_raw_operation_done_t enqueue_done;
159399a2dd95SBruce Richardson 	cryptodev_sym_raw_dequeue_t dequeue;
159499a2dd95SBruce Richardson 	cryptodev_sym_raw_dequeue_burst_t dequeue_burst;
159599a2dd95SBruce Richardson 	cryptodev_sym_raw_operation_done_t dequeue_done;
159699a2dd95SBruce Richardson 
159799a2dd95SBruce Richardson 	/* Driver specific context data */
15983401a4afSDavid Marchand 	uint8_t drv_ctx_data[];
159999a2dd95SBruce Richardson };
160099a2dd95SBruce Richardson 
160199a2dd95SBruce Richardson /**
160299a2dd95SBruce Richardson  * Configure raw data-path context data.
160399a2dd95SBruce Richardson  *
160499a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
160599a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair from which to
160699a2dd95SBruce Richardson  *				retrieve processed packets. The value must be
160799a2dd95SBruce Richardson  *				in the range [0, nb_queue_pair - 1] previously
160899a2dd95SBruce Richardson  *				supplied to rte_cryptodev_configure().
160999a2dd95SBruce Richardson  * @param	ctx		The raw data-path context data.
161019218b42SAnoob Joseph  * @param	sess_type	Session type.
161199a2dd95SBruce Richardson  * @param	session_ctx	Session context data.
161299a2dd95SBruce Richardson  * @param	is_update	Set 0 if it is to initialize the ctx.
161399a2dd95SBruce Richardson  *				Set 1 if ctx is initialized and only to update
161499a2dd95SBruce Richardson  *				session context data.
161599a2dd95SBruce Richardson  * @return
161699a2dd95SBruce Richardson  *   - On success return 0.
161799a2dd95SBruce Richardson  *   - On failure return negative integer.
161819218b42SAnoob Joseph  *     - -EINVAL if input parameters are invalid.
161919218b42SAnoob Joseph  *     - -ENOTSUP if crypto device does not support raw DP operations with the
162019218b42SAnoob Joseph  *        provided session.
162199a2dd95SBruce Richardson  */
162299a2dd95SBruce Richardson int
162399a2dd95SBruce Richardson rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
162499a2dd95SBruce Richardson 	struct rte_crypto_raw_dp_ctx *ctx,
162599a2dd95SBruce Richardson 	enum rte_crypto_op_sess_type sess_type,
162699a2dd95SBruce Richardson 	union rte_cryptodev_session_ctx session_ctx,
162799a2dd95SBruce Richardson 	uint8_t is_update);
162899a2dd95SBruce Richardson 
162999a2dd95SBruce Richardson /**
163099a2dd95SBruce Richardson  * Enqueue a vectorized operation descriptor into the device queue but the
163199a2dd95SBruce Richardson  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
163299a2dd95SBruce Richardson  * is called.
163399a2dd95SBruce Richardson  *
163499a2dd95SBruce Richardson  * @param	ctx		The initialized raw data-path context data.
163599a2dd95SBruce Richardson  * @param	vec		Vectorized operation descriptor.
163699a2dd95SBruce Richardson  * @param	ofs		Start and stop offsets for auth and cipher
163799a2dd95SBruce Richardson  *				operations.
163899a2dd95SBruce Richardson  * @param	user_data	The array of user data for dequeue later.
163999a2dd95SBruce Richardson  * @param	enqueue_status	Driver written value to specify the
164099a2dd95SBruce Richardson  *				enqueue status. Possible values:
164199a2dd95SBruce Richardson  *				- 1: The number of operations returned are
164299a2dd95SBruce Richardson  *				     enqueued successfully.
164399a2dd95SBruce Richardson  *				- 0: The number of operations returned are
164499a2dd95SBruce Richardson  *				     cached into the queue but are not processed
164599a2dd95SBruce Richardson  *				     until rte_cryptodev_raw_enqueue_done() is
164699a2dd95SBruce Richardson  *				     called.
164799a2dd95SBruce Richardson  *				- negative integer: Error occurred.
164899a2dd95SBruce Richardson  * @return
164999a2dd95SBruce Richardson  *   - The number of operations in the descriptor successfully enqueued or
165099a2dd95SBruce Richardson  *     cached into the queue but not enqueued yet, depends on the
165199a2dd95SBruce Richardson  *     "enqueue_status" value.
165299a2dd95SBruce Richardson  */
165399a2dd95SBruce Richardson uint32_t
165499a2dd95SBruce Richardson rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
165599a2dd95SBruce Richardson 	struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
165699a2dd95SBruce Richardson 	void **user_data, int *enqueue_status);
165799a2dd95SBruce Richardson 
165899a2dd95SBruce Richardson /**
165999a2dd95SBruce Richardson  * Enqueue single raw data vector into the device queue but the driver may or
166099a2dd95SBruce Richardson  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
166199a2dd95SBruce Richardson  *
166299a2dd95SBruce Richardson  * @param	ctx		The initialized raw data-path context data.
166399a2dd95SBruce Richardson  * @param	data_vec	The buffer data vector.
166499a2dd95SBruce Richardson  * @param	n_data_vecs	Number of buffer data vectors.
166599a2dd95SBruce Richardson  * @param	ofs		Start and stop offsets for auth and cipher
166699a2dd95SBruce Richardson  *				operations.
166799a2dd95SBruce Richardson  * @param	iv		IV virtual and IOVA addresses
166899a2dd95SBruce Richardson  * @param	digest		digest virtual and IOVA addresses
166999a2dd95SBruce Richardson  * @param	aad_or_auth_iv	AAD or auth IV virtual and IOVA addresses,
167099a2dd95SBruce Richardson  *				depends on the algorithm used.
167199a2dd95SBruce Richardson  * @param	user_data	The user data.
167299a2dd95SBruce Richardson  * @return
167399a2dd95SBruce Richardson  *   - 1: The data vector is enqueued successfully.
167499a2dd95SBruce Richardson  *   - 0: The data vector is cached into the queue but is not processed
167599a2dd95SBruce Richardson  *        until rte_cryptodev_raw_enqueue_done() is called.
167699a2dd95SBruce Richardson  *   - negative integer: failure.
167799a2dd95SBruce Richardson  */
167899a2dd95SBruce Richardson __rte_experimental
167999a2dd95SBruce Richardson static __rte_always_inline int
168099a2dd95SBruce Richardson rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx *ctx,
168199a2dd95SBruce Richardson 	struct rte_crypto_vec *data_vec, uint16_t n_data_vecs,
168299a2dd95SBruce Richardson 	union rte_crypto_sym_ofs ofs,
168399a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *iv,
168499a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *digest,
168599a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
168699a2dd95SBruce Richardson 	void *user_data)
168799a2dd95SBruce Richardson {
168899a2dd95SBruce Richardson 	return (*ctx->enqueue)(ctx->qp_data, ctx->drv_ctx_data, data_vec,
168999a2dd95SBruce Richardson 		n_data_vecs, ofs, iv, digest, aad_or_auth_iv, user_data);
169099a2dd95SBruce Richardson }
169199a2dd95SBruce Richardson 
169299a2dd95SBruce Richardson /**
169399a2dd95SBruce Richardson  * Start processing all enqueued operations from last
169499a2dd95SBruce Richardson  * rte_cryptodev_configure_raw_dp_ctx() call.
169599a2dd95SBruce Richardson  *
169699a2dd95SBruce Richardson  * @param	ctx	The initialized raw data-path context data.
169799a2dd95SBruce Richardson  * @param	n	The number of operations cached.
169899a2dd95SBruce Richardson  * @return
169999a2dd95SBruce Richardson  *   - On success return 0.
170099a2dd95SBruce Richardson  *   - On failure return negative integer.
170199a2dd95SBruce Richardson  */
170299a2dd95SBruce Richardson int
170399a2dd95SBruce Richardson rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
170499a2dd95SBruce Richardson 		uint32_t n);
170599a2dd95SBruce Richardson 
170699a2dd95SBruce Richardson /**
170799a2dd95SBruce Richardson  * Dequeue a burst of symmetric crypto processing.
170899a2dd95SBruce Richardson  *
170999a2dd95SBruce Richardson  * @param	ctx			The initialized raw data-path context
171099a2dd95SBruce Richardson  *					data.
171199a2dd95SBruce Richardson  * @param	get_dequeue_count	User provided callback function to
171299a2dd95SBruce Richardson  *					obtain dequeue operation count.
171399a2dd95SBruce Richardson  * @param	max_nb_to_dequeue	When get_dequeue_count is NULL this
171499a2dd95SBruce Richardson  *					value is used to pass the maximum
171599a2dd95SBruce Richardson  *					number of operations to be dequeued.
171699a2dd95SBruce Richardson  * @param	post_dequeue		User provided callback function to
171799a2dd95SBruce Richardson  *					post-process a dequeued operation.
171899a2dd95SBruce Richardson  * @param	out_user_data		User data pointer array to be retrieve
171999a2dd95SBruce Richardson  *					from device queue. In case of
172099a2dd95SBruce Richardson  *					*is_user_data_array* is set there
172199a2dd95SBruce Richardson  *					should be enough room to store all
172299a2dd95SBruce Richardson  *					user data.
172399a2dd95SBruce Richardson  * @param	is_user_data_array	Set 1 if every dequeued user data will
172499a2dd95SBruce Richardson  *					be written into out_user_data array.
172599a2dd95SBruce Richardson  *					Set 0 if only the first user data will
172699a2dd95SBruce Richardson  *					be written into out_user_data array.
172799a2dd95SBruce Richardson  * @param	n_success		Driver written value to specific the
172899a2dd95SBruce Richardson  *					total successful operations count.
172999a2dd95SBruce Richardson  * @param	dequeue_status		Driver written value to specify the
173099a2dd95SBruce Richardson  *					dequeue status. Possible values:
173199a2dd95SBruce Richardson  *					- 1: Successfully dequeued the number
173299a2dd95SBruce Richardson  *					     of operations returned. The user
173399a2dd95SBruce Richardson  *					     data previously set during enqueue
173499a2dd95SBruce Richardson  *					     is stored in the "out_user_data".
173599a2dd95SBruce Richardson  *					- 0: The number of operations returned
173699a2dd95SBruce Richardson  *					     are completed and the user data is
173799a2dd95SBruce Richardson  *					     stored in the "out_user_data", but
173899a2dd95SBruce Richardson  *					     they are not freed from the queue
173999a2dd95SBruce Richardson  *					     until
174099a2dd95SBruce Richardson  *					     rte_cryptodev_raw_dequeue_done()
174199a2dd95SBruce Richardson  *					     is called.
174299a2dd95SBruce Richardson  *					- negative integer: Error occurred.
174399a2dd95SBruce Richardson  * @return
174499a2dd95SBruce Richardson  *   - The number of operations dequeued or completed but not freed from the
174599a2dd95SBruce Richardson  *     queue, depends on "dequeue_status" value.
174699a2dd95SBruce Richardson  */
174799a2dd95SBruce Richardson uint32_t
174899a2dd95SBruce Richardson rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
174999a2dd95SBruce Richardson 	rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
175099a2dd95SBruce Richardson 	uint32_t max_nb_to_dequeue,
175199a2dd95SBruce Richardson 	rte_cryptodev_raw_post_dequeue_t post_dequeue,
175299a2dd95SBruce Richardson 	void **out_user_data, uint8_t is_user_data_array,
175399a2dd95SBruce Richardson 	uint32_t *n_success, int *dequeue_status);
175499a2dd95SBruce Richardson 
175599a2dd95SBruce Richardson /**
175699a2dd95SBruce Richardson  * Dequeue a symmetric crypto processing.
175799a2dd95SBruce Richardson  *
175899a2dd95SBruce Richardson  * @param	ctx			The initialized raw data-path context
175999a2dd95SBruce Richardson  *					data.
176099a2dd95SBruce Richardson  * @param	dequeue_status		Driver written value to specify the
176199a2dd95SBruce Richardson  *					dequeue status. Possible values:
176299a2dd95SBruce Richardson  *					- 1: Successfully dequeued a operation.
176399a2dd95SBruce Richardson  *					     The user data is returned.
176499a2dd95SBruce Richardson  *					- 0: The first operation in the queue
176599a2dd95SBruce Richardson  *					     is completed and the user data
176699a2dd95SBruce Richardson  *					     previously set during enqueue is
176799a2dd95SBruce Richardson  *					     returned, but it is not freed from
176899a2dd95SBruce Richardson  *					     the queue until
176999a2dd95SBruce Richardson  *					     rte_cryptodev_raw_dequeue_done() is
177099a2dd95SBruce Richardson  *					     called.
177199a2dd95SBruce Richardson  *					- negative integer: Error occurred.
177299a2dd95SBruce Richardson  * @param	op_status		Driver written value to specify
177399a2dd95SBruce Richardson  *					operation status.
177499a2dd95SBruce Richardson  * @return
177599a2dd95SBruce Richardson  *   - The user data pointer retrieved from device queue or NULL if no
177699a2dd95SBruce Richardson  *     operation is ready for dequeue.
177799a2dd95SBruce Richardson  */
177899a2dd95SBruce Richardson __rte_experimental
177999a2dd95SBruce Richardson static __rte_always_inline void *
178099a2dd95SBruce Richardson rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx *ctx,
178199a2dd95SBruce Richardson 		int *dequeue_status, enum rte_crypto_op_status *op_status)
178299a2dd95SBruce Richardson {
178399a2dd95SBruce Richardson 	return (*ctx->dequeue)(ctx->qp_data, ctx->drv_ctx_data, dequeue_status,
178499a2dd95SBruce Richardson 			op_status);
178599a2dd95SBruce Richardson }
178699a2dd95SBruce Richardson 
178799a2dd95SBruce Richardson /**
178899a2dd95SBruce Richardson  * Inform the queue pair dequeue operations is finished.
178999a2dd95SBruce Richardson  *
179099a2dd95SBruce Richardson  * @param	ctx	The initialized raw data-path context data.
179199a2dd95SBruce Richardson  * @param	n	The number of operations.
179299a2dd95SBruce Richardson  * @return
179399a2dd95SBruce Richardson  *   - On success return 0.
179499a2dd95SBruce Richardson  *   - On failure return negative integer.
179599a2dd95SBruce Richardson  */
179699a2dd95SBruce Richardson int
179799a2dd95SBruce Richardson rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
179899a2dd95SBruce Richardson 		uint32_t n);
179999a2dd95SBruce Richardson 
180099a2dd95SBruce Richardson /**
180199a2dd95SBruce Richardson  * Add a user callback for a given crypto device and queue pair which will be
180299a2dd95SBruce Richardson  * called on crypto ops enqueue.
180399a2dd95SBruce Richardson  *
180499a2dd95SBruce Richardson  * This API configures a function to be called for each burst of crypto ops
180599a2dd95SBruce Richardson  * received on a given crypto device queue pair. The return value is a pointer
180699a2dd95SBruce Richardson  * that can be used later to remove the callback using
180799a2dd95SBruce Richardson  * rte_cryptodev_remove_enq_callback().
180899a2dd95SBruce Richardson  *
180999a2dd95SBruce Richardson  * Callbacks registered by application would not survive
181099a2dd95SBruce Richardson  * rte_cryptodev_configure() as it reinitializes the callback list.
181199a2dd95SBruce Richardson  * It is user responsibility to remove all installed callbacks before
181299a2dd95SBruce Richardson  * calling rte_cryptodev_configure() to avoid possible memory leakage.
181399a2dd95SBruce Richardson  * Application is expected to call add API after rte_cryptodev_configure().
181499a2dd95SBruce Richardson  *
181599a2dd95SBruce Richardson  * Multiple functions can be registered per queue pair & they are called
181699a2dd95SBruce Richardson  * in the order they were added. The API does not restrict on maximum number
181799a2dd95SBruce Richardson  * of callbacks.
181899a2dd95SBruce Richardson  *
181999a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
182099a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
182199a2dd95SBruce Richardson  *				to be enqueued for processing. The value
182299a2dd95SBruce Richardson  *				must be in the range [0, nb_queue_pairs - 1]
182399a2dd95SBruce Richardson  *				previously supplied to
182499a2dd95SBruce Richardson  *				*rte_cryptodev_configure*.
182599a2dd95SBruce Richardson  * @param	cb_fn		The callback function
182699a2dd95SBruce Richardson  * @param	cb_arg		A generic pointer parameter which will be passed
182799a2dd95SBruce Richardson  *				to each invocation of the callback function on
182899a2dd95SBruce Richardson  *				this crypto device and queue pair.
182999a2dd95SBruce Richardson  *
183099a2dd95SBruce Richardson  * @return
183199a2dd95SBruce Richardson  *  - NULL on error & rte_errno will contain the error code.
183299a2dd95SBruce Richardson  *  - On success, a pointer value which can later be used to remove the
183399a2dd95SBruce Richardson  *    callback.
183499a2dd95SBruce Richardson  */
183599a2dd95SBruce Richardson struct rte_cryptodev_cb *
183699a2dd95SBruce Richardson rte_cryptodev_add_enq_callback(uint8_t dev_id,
183799a2dd95SBruce Richardson 			       uint16_t qp_id,
183899a2dd95SBruce Richardson 			       rte_cryptodev_callback_fn cb_fn,
183999a2dd95SBruce Richardson 			       void *cb_arg);
184099a2dd95SBruce Richardson 
184199a2dd95SBruce Richardson /**
184299a2dd95SBruce Richardson  * Remove a user callback function for given crypto device and queue pair.
184399a2dd95SBruce Richardson  *
184499a2dd95SBruce Richardson  * This function is used to remove enqueue callbacks that were added to a
184599a2dd95SBruce Richardson  * crypto device queue pair using rte_cryptodev_add_enq_callback().
184699a2dd95SBruce Richardson  *
184799a2dd95SBruce Richardson  *
184899a2dd95SBruce Richardson  *
184999a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
185099a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
185199a2dd95SBruce Richardson  *				to be enqueued. The value must be in the
185299a2dd95SBruce Richardson  *				range [0, nb_queue_pairs - 1] previously
185399a2dd95SBruce Richardson  *				supplied to *rte_cryptodev_configure*.
185499a2dd95SBruce Richardson  * @param	cb		Pointer to user supplied callback created via
185599a2dd95SBruce Richardson  *				rte_cryptodev_add_enq_callback().
185699a2dd95SBruce Richardson  *
185799a2dd95SBruce Richardson  * @return
185899a2dd95SBruce Richardson  *   -  0: Success. Callback was removed.
185999a2dd95SBruce Richardson  *   - <0: The dev_id or the qp_id is out of range, or the callback
186099a2dd95SBruce Richardson  *         is NULL or not found for the crypto device queue pair.
186199a2dd95SBruce Richardson  */
186299a2dd95SBruce Richardson int rte_cryptodev_remove_enq_callback(uint8_t dev_id,
186399a2dd95SBruce Richardson 				      uint16_t qp_id,
186499a2dd95SBruce Richardson 				      struct rte_cryptodev_cb *cb);
186599a2dd95SBruce Richardson 
186699a2dd95SBruce Richardson /**
186799a2dd95SBruce Richardson  * Add a user callback for a given crypto device and queue pair which will be
186899a2dd95SBruce Richardson  * called on crypto ops dequeue.
186999a2dd95SBruce Richardson  *
187099a2dd95SBruce Richardson  * This API configures a function to be called for each burst of crypto ops
187199a2dd95SBruce Richardson  * received on a given crypto device queue pair. The return value is a pointer
187299a2dd95SBruce Richardson  * that can be used later to remove the callback using
187399a2dd95SBruce Richardson  * rte_cryptodev_remove_deq_callback().
187499a2dd95SBruce Richardson  *
187599a2dd95SBruce Richardson  * Callbacks registered by application would not survive
187699a2dd95SBruce Richardson  * rte_cryptodev_configure() as it reinitializes the callback list.
187799a2dd95SBruce Richardson  * It is user responsibility to remove all installed callbacks before
187899a2dd95SBruce Richardson  * calling rte_cryptodev_configure() to avoid possible memory leakage.
187999a2dd95SBruce Richardson  * Application is expected to call add API after rte_cryptodev_configure().
188099a2dd95SBruce Richardson  *
188199a2dd95SBruce Richardson  * Multiple functions can be registered per queue pair & they are called
188299a2dd95SBruce Richardson  * in the order they were added. The API does not restrict on maximum number
188399a2dd95SBruce Richardson  * of callbacks.
188499a2dd95SBruce Richardson  *
188599a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
188699a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
188799a2dd95SBruce Richardson  *				to be dequeued. The value must be in the
188899a2dd95SBruce Richardson  *				range [0, nb_queue_pairs - 1] previously
188999a2dd95SBruce Richardson  *				supplied to *rte_cryptodev_configure*.
189099a2dd95SBruce Richardson  * @param	cb_fn		The callback function
189199a2dd95SBruce Richardson  * @param	cb_arg		A generic pointer parameter which will be passed
189299a2dd95SBruce Richardson  *				to each invocation of the callback function on
189399a2dd95SBruce Richardson  *				this crypto device and queue pair.
189499a2dd95SBruce Richardson  *
189599a2dd95SBruce Richardson  * @return
189699a2dd95SBruce Richardson  *   - NULL on error & rte_errno will contain the error code.
189799a2dd95SBruce Richardson  *   - On success, a pointer value which can later be used to remove the
189899a2dd95SBruce Richardson  *     callback.
189999a2dd95SBruce Richardson  */
190099a2dd95SBruce Richardson struct rte_cryptodev_cb *
190199a2dd95SBruce Richardson rte_cryptodev_add_deq_callback(uint8_t dev_id,
190299a2dd95SBruce Richardson 			       uint16_t qp_id,
190399a2dd95SBruce Richardson 			       rte_cryptodev_callback_fn cb_fn,
190499a2dd95SBruce Richardson 			       void *cb_arg);
190599a2dd95SBruce Richardson 
190699a2dd95SBruce Richardson /**
190799a2dd95SBruce Richardson  * Remove a user callback function for given crypto device and queue pair.
190899a2dd95SBruce Richardson  *
190999a2dd95SBruce Richardson  * This function is used to remove dequeue callbacks that were added to a
191099a2dd95SBruce Richardson  * crypto device queue pair using rte_cryptodev_add_deq_callback().
191199a2dd95SBruce Richardson  *
191299a2dd95SBruce Richardson  *
191399a2dd95SBruce Richardson  *
191499a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
191599a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
191699a2dd95SBruce Richardson  *				to be dequeued. The value must be in the
191799a2dd95SBruce Richardson  *				range [0, nb_queue_pairs - 1] previously
191899a2dd95SBruce Richardson  *				supplied to *rte_cryptodev_configure*.
191999a2dd95SBruce Richardson  * @param	cb		Pointer to user supplied callback created via
192099a2dd95SBruce Richardson  *				rte_cryptodev_add_deq_callback().
192199a2dd95SBruce Richardson  *
192299a2dd95SBruce Richardson  * @return
192399a2dd95SBruce Richardson  *   -  0: Success. Callback was removed.
192499a2dd95SBruce Richardson  *   - <0: The dev_id or the qp_id is out of range, or the callback
192599a2dd95SBruce Richardson  *         is NULL or not found for the crypto device queue pair.
192699a2dd95SBruce Richardson  */
192799a2dd95SBruce Richardson int rte_cryptodev_remove_deq_callback(uint8_t dev_id,
192899a2dd95SBruce Richardson 				      uint16_t qp_id,
192999a2dd95SBruce Richardson 				      struct rte_cryptodev_cb *cb);
193099a2dd95SBruce Richardson 
1931691e1f4dSAkhil Goyal #include <rte_cryptodev_core.h>
1932719834a6SMattias Rönnblom 
1933719834a6SMattias Rönnblom #ifdef __cplusplus
1934719834a6SMattias Rönnblom extern "C" {
1935719834a6SMattias Rönnblom #endif
1936691e1f4dSAkhil Goyal /**
1937691e1f4dSAkhil Goyal  *
1938691e1f4dSAkhil Goyal  * Dequeue a burst of processed crypto operations from a queue on the crypto
1939691e1f4dSAkhil Goyal  * device. The dequeued operation are stored in *rte_crypto_op* structures
1940691e1f4dSAkhil Goyal  * whose pointers are supplied in the *ops* array.
1941691e1f4dSAkhil Goyal  *
1942691e1f4dSAkhil Goyal  * The rte_cryptodev_dequeue_burst() function returns the number of ops
1943691e1f4dSAkhil Goyal  * actually dequeued, which is the number of *rte_crypto_op* data structures
1944691e1f4dSAkhil Goyal  * effectively supplied into the *ops* array.
1945691e1f4dSAkhil Goyal  *
1946691e1f4dSAkhil Goyal  * A return value equal to *nb_ops* indicates that the queue contained
1947691e1f4dSAkhil Goyal  * at least *nb_ops* operations, and this is likely to signify that other
1948691e1f4dSAkhil Goyal  * processed operations remain in the devices output queue. Applications
1949691e1f4dSAkhil Goyal  * implementing a "retrieve as many processed operations as possible" policy
1950691e1f4dSAkhil Goyal  * can check this specific case and keep invoking the
1951691e1f4dSAkhil Goyal  * rte_cryptodev_dequeue_burst() function until a value less than
1952691e1f4dSAkhil Goyal  * *nb_ops* is returned.
1953691e1f4dSAkhil Goyal  *
1954691e1f4dSAkhil Goyal  * The rte_cryptodev_dequeue_burst() function does not provide any error
1955691e1f4dSAkhil Goyal  * notification to avoid the corresponding overhead.
1956691e1f4dSAkhil Goyal  *
1957691e1f4dSAkhil Goyal  * @param	dev_id		The symmetric crypto device identifier
1958691e1f4dSAkhil Goyal  * @param	qp_id		The index of the queue pair from which to
1959691e1f4dSAkhil Goyal  *				retrieve processed packets. The value must be
1960691e1f4dSAkhil Goyal  *				in the range [0, nb_queue_pair - 1] previously
1961691e1f4dSAkhil Goyal  *				supplied to rte_cryptodev_configure().
1962691e1f4dSAkhil Goyal  * @param	ops		The address of an array of pointers to
1963691e1f4dSAkhil Goyal  *				*rte_crypto_op* structures that must be
1964691e1f4dSAkhil Goyal  *				large enough to store *nb_ops* pointers in it.
1965691e1f4dSAkhil Goyal  * @param	nb_ops		The maximum number of operations to dequeue.
1966691e1f4dSAkhil Goyal  *
1967691e1f4dSAkhil Goyal  * @return
1968691e1f4dSAkhil Goyal  *   - The number of operations actually dequeued, which is the number
1969691e1f4dSAkhil Goyal  *   of pointers to *rte_crypto_op* structures effectively supplied to the
1970691e1f4dSAkhil Goyal  *   *ops* array.
1971691e1f4dSAkhil Goyal  */
1972691e1f4dSAkhil Goyal static inline uint16_t
1973691e1f4dSAkhil Goyal rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1974691e1f4dSAkhil Goyal 		struct rte_crypto_op **ops, uint16_t nb_ops)
1975691e1f4dSAkhil Goyal {
1976f6849cdcSAkhil Goyal 	const struct rte_crypto_fp_ops *fp_ops;
1977f6849cdcSAkhil Goyal 	void *qp;
1978691e1f4dSAkhil Goyal 
1979691e1f4dSAkhil Goyal 	rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1980f6849cdcSAkhil Goyal 
1981f6849cdcSAkhil Goyal 	fp_ops = &rte_crypto_fp_ops[dev_id];
1982f6849cdcSAkhil Goyal 	qp = fp_ops->qp.data[qp_id];
1983f6849cdcSAkhil Goyal 
1984f6849cdcSAkhil Goyal 	nb_ops = fp_ops->dequeue_burst(qp, ops, nb_ops);
1985f6849cdcSAkhil Goyal 
1986691e1f4dSAkhil Goyal #ifdef RTE_CRYPTO_CALLBACKS
1987e858d0c9SGanapati Kundapura 	if (unlikely(fp_ops->qp.deq_cb[qp_id].next != NULL)) {
1988691e1f4dSAkhil Goyal 		struct rte_cryptodev_cb_rcu *list;
1989691e1f4dSAkhil Goyal 		struct rte_cryptodev_cb *cb;
1990691e1f4dSAkhil Goyal 
1991ab1932afSTyler Retzlaff 		/* rte_memory_order_release memory order was used when the
1992691e1f4dSAkhil Goyal 		 * call back was inserted into the list.
1993691e1f4dSAkhil Goyal 		 * Since there is a clear dependency between loading
1994ab1932afSTyler Retzlaff 		 * cb and cb->fn/cb->next, rte_memory_order_acquire memory order is
1995691e1f4dSAkhil Goyal 		 * not required.
1996691e1f4dSAkhil Goyal 		 */
1997f6849cdcSAkhil Goyal 		list = &fp_ops->qp.deq_cb[qp_id];
1998691e1f4dSAkhil Goyal 		rte_rcu_qsbr_thread_online(list->qsbr, 0);
1999ab1932afSTyler Retzlaff 		cb = rte_atomic_load_explicit(&list->next, rte_memory_order_relaxed);
2000691e1f4dSAkhil Goyal 
2001691e1f4dSAkhil Goyal 		while (cb != NULL) {
2002691e1f4dSAkhil Goyal 			nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
2003691e1f4dSAkhil Goyal 					cb->arg);
2004691e1f4dSAkhil Goyal 			cb = cb->next;
2005691e1f4dSAkhil Goyal 		};
2006691e1f4dSAkhil Goyal 
2007691e1f4dSAkhil Goyal 		rte_rcu_qsbr_thread_offline(list->qsbr, 0);
2008691e1f4dSAkhil Goyal 	}
2009691e1f4dSAkhil Goyal #endif
2010691e1f4dSAkhil Goyal 	return nb_ops;
2011691e1f4dSAkhil Goyal }
2012691e1f4dSAkhil Goyal 
2013691e1f4dSAkhil Goyal /**
2014691e1f4dSAkhil Goyal  * Enqueue a burst of operations for processing on a crypto device.
2015691e1f4dSAkhil Goyal  *
2016691e1f4dSAkhil Goyal  * The rte_cryptodev_enqueue_burst() function is invoked to place
2017691e1f4dSAkhil Goyal  * crypto operations on the queue *qp_id* of the device designated by
2018691e1f4dSAkhil Goyal  * its *dev_id*.
2019691e1f4dSAkhil Goyal  *
2020691e1f4dSAkhil Goyal  * The *nb_ops* parameter is the number of operations to process which are
2021691e1f4dSAkhil Goyal  * supplied in the *ops* array of *rte_crypto_op* structures.
2022691e1f4dSAkhil Goyal  *
2023691e1f4dSAkhil Goyal  * The rte_cryptodev_enqueue_burst() function returns the number of
2024691e1f4dSAkhil Goyal  * operations it actually enqueued for processing. A return value equal to
2025691e1f4dSAkhil Goyal  * *nb_ops* means that all packets have been enqueued.
2026691e1f4dSAkhil Goyal  *
2027691e1f4dSAkhil Goyal  * @param	dev_id		The identifier of the device.
2028691e1f4dSAkhil Goyal  * @param	qp_id		The index of the queue pair which packets are
2029691e1f4dSAkhil Goyal  *				to be enqueued for processing. The value
2030691e1f4dSAkhil Goyal  *				must be in the range [0, nb_queue_pairs - 1]
2031691e1f4dSAkhil Goyal  *				previously supplied to
2032691e1f4dSAkhil Goyal  *				 *rte_cryptodev_configure*.
2033691e1f4dSAkhil Goyal  * @param	ops		The address of an array of *nb_ops* pointers
2034691e1f4dSAkhil Goyal  *				to *rte_crypto_op* structures which contain
2035691e1f4dSAkhil Goyal  *				the crypto operations to be processed.
2036691e1f4dSAkhil Goyal  * @param	nb_ops		The number of operations to process.
2037691e1f4dSAkhil Goyal  *
2038691e1f4dSAkhil Goyal  * @return
2039691e1f4dSAkhil Goyal  * The number of operations actually enqueued on the crypto device. The return
2040691e1f4dSAkhil Goyal  * value can be less than the value of the *nb_ops* parameter when the
2041691e1f4dSAkhil Goyal  * crypto devices queue is full or if invalid parameters are specified in
2042691e1f4dSAkhil Goyal  * a *rte_crypto_op*.
2043691e1f4dSAkhil Goyal  */
2044691e1f4dSAkhil Goyal static inline uint16_t
2045691e1f4dSAkhil Goyal rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
2046691e1f4dSAkhil Goyal 		struct rte_crypto_op **ops, uint16_t nb_ops)
2047691e1f4dSAkhil Goyal {
2048f6849cdcSAkhil Goyal 	const struct rte_crypto_fp_ops *fp_ops;
2049f6849cdcSAkhil Goyal 	void *qp;
2050691e1f4dSAkhil Goyal 
2051f6849cdcSAkhil Goyal 	fp_ops = &rte_crypto_fp_ops[dev_id];
2052f6849cdcSAkhil Goyal 	qp = fp_ops->qp.data[qp_id];
2053691e1f4dSAkhil Goyal #ifdef RTE_CRYPTO_CALLBACKS
2054e858d0c9SGanapati Kundapura 	if (unlikely(fp_ops->qp.enq_cb[qp_id].next != NULL)) {
2055691e1f4dSAkhil Goyal 		struct rte_cryptodev_cb_rcu *list;
2056691e1f4dSAkhil Goyal 		struct rte_cryptodev_cb *cb;
2057691e1f4dSAkhil Goyal 
2058ab1932afSTyler Retzlaff 		/* rte_memory_order_release memory order was used when the
2059691e1f4dSAkhil Goyal 		 * call back was inserted into the list.
2060691e1f4dSAkhil Goyal 		 * Since there is a clear dependency between loading
2061ab1932afSTyler Retzlaff 		 * cb and cb->fn/cb->next, rte_memory_order_acquire memory order is
2062691e1f4dSAkhil Goyal 		 * not required.
2063691e1f4dSAkhil Goyal 		 */
2064f6849cdcSAkhil Goyal 		list = &fp_ops->qp.enq_cb[qp_id];
2065691e1f4dSAkhil Goyal 		rte_rcu_qsbr_thread_online(list->qsbr, 0);
2066ab1932afSTyler Retzlaff 		cb = rte_atomic_load_explicit(&list->next, rte_memory_order_relaxed);
2067691e1f4dSAkhil Goyal 
2068691e1f4dSAkhil Goyal 		while (cb != NULL) {
2069691e1f4dSAkhil Goyal 			nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
2070691e1f4dSAkhil Goyal 					cb->arg);
2071691e1f4dSAkhil Goyal 			cb = cb->next;
2072691e1f4dSAkhil Goyal 		};
2073691e1f4dSAkhil Goyal 
2074691e1f4dSAkhil Goyal 		rte_rcu_qsbr_thread_offline(list->qsbr, 0);
2075691e1f4dSAkhil Goyal 	}
2076691e1f4dSAkhil Goyal #endif
2077691e1f4dSAkhil Goyal 
2078691e1f4dSAkhil Goyal 	rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
2079f6849cdcSAkhil Goyal 	return fp_ops->enqueue_burst(qp, ops, nb_ops);
2080691e1f4dSAkhil Goyal }
2081691e1f4dSAkhil Goyal 
208223d6f76dSAkhil Goyal /**
208323d6f76dSAkhil Goyal  * @warning
208423d6f76dSAkhil Goyal  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
208523d6f76dSAkhil Goyal  *
208623d6f76dSAkhil Goyal  * Get the number of used descriptors or depth of a cryptodev queue pair.
208723d6f76dSAkhil Goyal  *
208823d6f76dSAkhil Goyal  * This function retrieves the number of used descriptors in a crypto queue.
208923d6f76dSAkhil Goyal  * Applications can use this API in the fast path to inspect QP occupancy and
209023d6f76dSAkhil Goyal  * take appropriate action.
209123d6f76dSAkhil Goyal  *
209223d6f76dSAkhil Goyal  * Since it is a fast-path function, no check is performed on dev_id and qp_id.
209323d6f76dSAkhil Goyal  * Caller must therefore ensure that the device is enabled and queue pair is setup.
209423d6f76dSAkhil Goyal  *
209523d6f76dSAkhil Goyal  * @param	dev_id		The identifier of the device.
209623d6f76dSAkhil Goyal  * @param	qp_id		The index of the queue pair for which used descriptor
209723d6f76dSAkhil Goyal  *				count is to be retrieved. The value
209823d6f76dSAkhil Goyal  *				must be in the range [0, nb_queue_pairs - 1]
209923d6f76dSAkhil Goyal  *				previously supplied to *rte_cryptodev_configure*.
210023d6f76dSAkhil Goyal  *
210123d6f76dSAkhil Goyal  * @return
210223d6f76dSAkhil Goyal  *  The number of used descriptors on the specified queue pair, or:
210323d6f76dSAkhil Goyal  *   - (-ENOTSUP) if the device does not support this function.
210423d6f76dSAkhil Goyal  */
210523d6f76dSAkhil Goyal 
210623d6f76dSAkhil Goyal __rte_experimental
210723d6f76dSAkhil Goyal static inline int
210823d6f76dSAkhil Goyal rte_cryptodev_qp_depth_used(uint8_t dev_id, uint16_t qp_id)
210923d6f76dSAkhil Goyal {
211023d6f76dSAkhil Goyal 	const struct rte_crypto_fp_ops *fp_ops;
211123d6f76dSAkhil Goyal 	void *qp;
211223d6f76dSAkhil Goyal 	int rc;
211323d6f76dSAkhil Goyal 
211423d6f76dSAkhil Goyal 	fp_ops = &rte_crypto_fp_ops[dev_id];
211523d6f76dSAkhil Goyal 	qp = fp_ops->qp.data[qp_id];
211623d6f76dSAkhil Goyal 
211723d6f76dSAkhil Goyal 	if (fp_ops->qp_depth_used == NULL) {
211823d6f76dSAkhil Goyal 		rc = -ENOTSUP;
211923d6f76dSAkhil Goyal 		goto out;
212023d6f76dSAkhil Goyal 	}
212123d6f76dSAkhil Goyal 
212223d6f76dSAkhil Goyal 	rc = fp_ops->qp_depth_used(qp);
212323d6f76dSAkhil Goyal out:
212423d6f76dSAkhil Goyal 	rte_cryptodev_trace_qp_depth_used(dev_id, qp_id);
212523d6f76dSAkhil Goyal 	return rc;
212623d6f76dSAkhil Goyal }
2127691e1f4dSAkhil Goyal 
2128691e1f4dSAkhil Goyal 
212999a2dd95SBruce Richardson #ifdef __cplusplus
213099a2dd95SBruce Richardson }
213199a2dd95SBruce Richardson #endif
213299a2dd95SBruce Richardson 
213399a2dd95SBruce Richardson #endif /* _RTE_CRYPTODEV_H_ */
2134