xref: /dpdk/lib/cryptodev/rte_cryptodev.h (revision 30a1de10)
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 
1799a2dd95SBruce Richardson #ifdef __cplusplus
1899a2dd95SBruce Richardson extern "C" {
1999a2dd95SBruce Richardson #endif
2099a2dd95SBruce Richardson 
2199a2dd95SBruce Richardson #include "rte_kvargs.h"
2299a2dd95SBruce Richardson #include "rte_crypto.h"
2399a2dd95SBruce Richardson #include <rte_common.h>
2499a2dd95SBruce Richardson #include <rte_rcu_qsbr.h>
2599a2dd95SBruce Richardson 
2699a2dd95SBruce Richardson #include "rte_cryptodev_trace_fp.h"
2799a2dd95SBruce Richardson 
2899a2dd95SBruce Richardson extern const char **rte_cyptodev_names;
2999a2dd95SBruce Richardson 
3099a2dd95SBruce Richardson /* Logging Macros */
3199a2dd95SBruce Richardson 
3299a2dd95SBruce Richardson #define CDEV_LOG_ERR(...) \
3399a2dd95SBruce Richardson 	RTE_LOG(ERR, CRYPTODEV, \
3499a2dd95SBruce Richardson 		RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
3599a2dd95SBruce Richardson 			__func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
3699a2dd95SBruce Richardson 
3799a2dd95SBruce Richardson #define CDEV_LOG_INFO(...) \
3899a2dd95SBruce Richardson 	RTE_LOG(INFO, CRYPTODEV, \
3999a2dd95SBruce Richardson 		RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
4099a2dd95SBruce Richardson 			RTE_FMT_TAIL(__VA_ARGS__,)))
4199a2dd95SBruce Richardson 
4299a2dd95SBruce Richardson #define CDEV_LOG_DEBUG(...) \
4399a2dd95SBruce Richardson 	RTE_LOG(DEBUG, CRYPTODEV, \
4499a2dd95SBruce Richardson 		RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
4599a2dd95SBruce Richardson 			__func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
4699a2dd95SBruce Richardson 
4799a2dd95SBruce Richardson #define CDEV_PMD_TRACE(...) \
4899a2dd95SBruce Richardson 	RTE_LOG(DEBUG, CRYPTODEV, \
4999a2dd95SBruce Richardson 		RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
5099a2dd95SBruce Richardson 			dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
5199a2dd95SBruce Richardson 
5299a2dd95SBruce Richardson /**
5399a2dd95SBruce Richardson  * A macro that points to an offset from the start
5499a2dd95SBruce Richardson  * of the crypto operation structure (rte_crypto_op)
5599a2dd95SBruce Richardson  *
5699a2dd95SBruce Richardson  * The returned pointer is cast to type t.
5799a2dd95SBruce Richardson  *
5899a2dd95SBruce Richardson  * @param c
5999a2dd95SBruce Richardson  *   The crypto operation.
6099a2dd95SBruce Richardson  * @param o
6199a2dd95SBruce Richardson  *   The offset from the start of the crypto operation.
6299a2dd95SBruce Richardson  * @param t
6399a2dd95SBruce Richardson  *   The type to cast the result into.
6499a2dd95SBruce Richardson  */
6599a2dd95SBruce Richardson #define rte_crypto_op_ctod_offset(c, t, o)	\
6699a2dd95SBruce Richardson 	((t)((char *)(c) + (o)))
6799a2dd95SBruce Richardson 
6899a2dd95SBruce Richardson /**
6999a2dd95SBruce Richardson  * A macro that returns the physical address that points
7099a2dd95SBruce Richardson  * to an offset from the start of the crypto operation
7199a2dd95SBruce Richardson  * (rte_crypto_op)
7299a2dd95SBruce Richardson  *
7399a2dd95SBruce Richardson  * @param c
7499a2dd95SBruce Richardson  *   The crypto operation.
7599a2dd95SBruce Richardson  * @param o
7699a2dd95SBruce Richardson  *   The offset from the start of the crypto operation
7799a2dd95SBruce Richardson  *   to calculate address from.
7899a2dd95SBruce Richardson  */
7999a2dd95SBruce Richardson #define rte_crypto_op_ctophys_offset(c, o)	\
8099a2dd95SBruce Richardson 	(rte_iova_t)((c)->phys_addr + (o))
8199a2dd95SBruce Richardson 
8299a2dd95SBruce Richardson /**
8399a2dd95SBruce Richardson  * Crypto parameters range description
8499a2dd95SBruce Richardson  */
8599a2dd95SBruce Richardson struct rte_crypto_param_range {
8699a2dd95SBruce Richardson 	uint16_t min;	/**< minimum size */
8799a2dd95SBruce Richardson 	uint16_t max;	/**< maximum size */
8899a2dd95SBruce Richardson 	uint16_t increment;
8999a2dd95SBruce Richardson 	/**< if a range of sizes are supported,
9099a2dd95SBruce Richardson 	 * this parameter is used to indicate
9199a2dd95SBruce Richardson 	 * increments in byte size that are supported
9299a2dd95SBruce Richardson 	 * between the minimum and maximum
9399a2dd95SBruce Richardson 	 */
9499a2dd95SBruce Richardson };
9599a2dd95SBruce Richardson 
9699a2dd95SBruce Richardson /**
9799a2dd95SBruce Richardson  * Data-unit supported lengths of cipher algorithms.
9899a2dd95SBruce Richardson  * A bit can represent any set of data-unit sizes
9999a2dd95SBruce Richardson  * (single size, multiple size, range, etc).
10099a2dd95SBruce Richardson  */
10199a2dd95SBruce Richardson #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_512_BYTES             RTE_BIT32(0)
10299a2dd95SBruce Richardson #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_4096_BYTES            RTE_BIT32(1)
1039ad77644SRaja Zidane #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_1_MEGABYTES           RTE_BIT32(2)
10499a2dd95SBruce Richardson 
10599a2dd95SBruce Richardson /**
10699a2dd95SBruce Richardson  * Symmetric Crypto Capability
10799a2dd95SBruce Richardson  */
10899a2dd95SBruce Richardson struct rte_cryptodev_symmetric_capability {
10999a2dd95SBruce Richardson 	enum rte_crypto_sym_xform_type xform_type;
11099a2dd95SBruce Richardson 	/**< Transform type : Authentication / Cipher / AEAD */
11199a2dd95SBruce Richardson 	RTE_STD_C11
11299a2dd95SBruce Richardson 	union {
11399a2dd95SBruce Richardson 		struct {
11499a2dd95SBruce Richardson 			enum rte_crypto_auth_algorithm algo;
11599a2dd95SBruce Richardson 			/**< authentication algorithm */
11699a2dd95SBruce Richardson 			uint16_t block_size;
11799a2dd95SBruce Richardson 			/**< algorithm block size */
11899a2dd95SBruce Richardson 			struct rte_crypto_param_range key_size;
11999a2dd95SBruce Richardson 			/**< auth key size range */
12099a2dd95SBruce Richardson 			struct rte_crypto_param_range digest_size;
12199a2dd95SBruce Richardson 			/**< digest size range */
12299a2dd95SBruce Richardson 			struct rte_crypto_param_range aad_size;
12399a2dd95SBruce Richardson 			/**< Additional authentication data size range */
12499a2dd95SBruce Richardson 			struct rte_crypto_param_range iv_size;
12599a2dd95SBruce Richardson 			/**< Initialisation vector data size range */
12699a2dd95SBruce Richardson 		} auth;
12799a2dd95SBruce Richardson 		/**< Symmetric Authentication transform capabilities */
12899a2dd95SBruce Richardson 		struct {
12999a2dd95SBruce Richardson 			enum rte_crypto_cipher_algorithm algo;
13099a2dd95SBruce Richardson 			/**< cipher algorithm */
13199a2dd95SBruce Richardson 			uint16_t block_size;
13299a2dd95SBruce Richardson 			/**< algorithm block size */
13399a2dd95SBruce Richardson 			struct rte_crypto_param_range key_size;
13499a2dd95SBruce Richardson 			/**< cipher key size range */
13599a2dd95SBruce Richardson 			struct rte_crypto_param_range iv_size;
13699a2dd95SBruce Richardson 			/**< Initialisation vector data size range */
13799a2dd95SBruce Richardson 			uint32_t dataunit_set;
13899a2dd95SBruce Richardson 			/**<
13999a2dd95SBruce Richardson 			 * Supported data-unit lengths:
14099a2dd95SBruce Richardson 			 * RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_* bits
14199a2dd95SBruce Richardson 			 * or 0 for lengths defined in the algorithm standard.
14299a2dd95SBruce Richardson 			 */
14399a2dd95SBruce Richardson 		} cipher;
14499a2dd95SBruce Richardson 		/**< Symmetric Cipher transform capabilities */
14599a2dd95SBruce Richardson 		struct {
14699a2dd95SBruce Richardson 			enum rte_crypto_aead_algorithm algo;
14799a2dd95SBruce Richardson 			/**< AEAD algorithm */
14899a2dd95SBruce Richardson 			uint16_t block_size;
14999a2dd95SBruce Richardson 			/**< algorithm block size */
15099a2dd95SBruce Richardson 			struct rte_crypto_param_range key_size;
15199a2dd95SBruce Richardson 			/**< AEAD key size range */
15299a2dd95SBruce Richardson 			struct rte_crypto_param_range digest_size;
15399a2dd95SBruce Richardson 			/**< digest size range */
15499a2dd95SBruce Richardson 			struct rte_crypto_param_range aad_size;
15599a2dd95SBruce Richardson 			/**< Additional authentication data size range */
15699a2dd95SBruce Richardson 			struct rte_crypto_param_range iv_size;
15799a2dd95SBruce Richardson 			/**< Initialisation vector data size range */
15899a2dd95SBruce Richardson 		} aead;
15999a2dd95SBruce Richardson 	};
16099a2dd95SBruce Richardson };
16199a2dd95SBruce Richardson 
16299a2dd95SBruce Richardson /**
16399a2dd95SBruce Richardson  * Asymmetric Xform Crypto Capability
16499a2dd95SBruce Richardson  *
16599a2dd95SBruce Richardson  */
16699a2dd95SBruce Richardson struct rte_cryptodev_asymmetric_xform_capability {
16799a2dd95SBruce Richardson 	enum rte_crypto_asym_xform_type xform_type;
16899a2dd95SBruce Richardson 	/**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
16999a2dd95SBruce Richardson 
17099a2dd95SBruce Richardson 	uint32_t op_types;
17199a2dd95SBruce Richardson 	/**< bitmask for supported rte_crypto_asym_op_type */
17299a2dd95SBruce Richardson 
17399a2dd95SBruce Richardson 	__extension__
17499a2dd95SBruce Richardson 	union {
17599a2dd95SBruce Richardson 		struct rte_crypto_param_range modlen;
17699a2dd95SBruce Richardson 		/**< Range of modulus length supported by modulus based xform.
17799a2dd95SBruce Richardson 		 * Value 0 mean implementation default
17899a2dd95SBruce Richardson 		 */
17999a2dd95SBruce Richardson 	};
18099a2dd95SBruce Richardson };
18199a2dd95SBruce Richardson 
18299a2dd95SBruce Richardson /**
18399a2dd95SBruce Richardson  * Asymmetric Crypto Capability
18499a2dd95SBruce Richardson  *
18599a2dd95SBruce Richardson  */
18699a2dd95SBruce Richardson struct rte_cryptodev_asymmetric_capability {
18799a2dd95SBruce Richardson 	struct rte_cryptodev_asymmetric_xform_capability xform_capa;
18899a2dd95SBruce Richardson };
18999a2dd95SBruce Richardson 
19099a2dd95SBruce Richardson 
19199a2dd95SBruce Richardson /** Structure used to capture a capability of a crypto device */
19299a2dd95SBruce Richardson struct rte_cryptodev_capabilities {
19399a2dd95SBruce Richardson 	enum rte_crypto_op_type op;
19499a2dd95SBruce Richardson 	/**< Operation type */
19599a2dd95SBruce Richardson 
19699a2dd95SBruce Richardson 	RTE_STD_C11
19799a2dd95SBruce Richardson 	union {
19899a2dd95SBruce Richardson 		struct rte_cryptodev_symmetric_capability sym;
19999a2dd95SBruce Richardson 		/**< Symmetric operation capability parameters */
20099a2dd95SBruce Richardson 		struct rte_cryptodev_asymmetric_capability asym;
20199a2dd95SBruce Richardson 		/**< Asymmetric operation capability parameters */
20299a2dd95SBruce Richardson 	};
20399a2dd95SBruce Richardson };
20499a2dd95SBruce Richardson 
20599a2dd95SBruce Richardson /** Structure used to describe crypto algorithms */
20699a2dd95SBruce Richardson struct rte_cryptodev_sym_capability_idx {
20799a2dd95SBruce Richardson 	enum rte_crypto_sym_xform_type type;
20899a2dd95SBruce Richardson 	union {
20999a2dd95SBruce Richardson 		enum rte_crypto_cipher_algorithm cipher;
21099a2dd95SBruce Richardson 		enum rte_crypto_auth_algorithm auth;
21199a2dd95SBruce Richardson 		enum rte_crypto_aead_algorithm aead;
21299a2dd95SBruce Richardson 	} algo;
21399a2dd95SBruce Richardson };
21499a2dd95SBruce Richardson 
21599a2dd95SBruce Richardson /**
21699a2dd95SBruce Richardson  * Structure used to describe asymmetric crypto xforms
21799a2dd95SBruce Richardson  * Each xform maps to one asym algorithm.
21899a2dd95SBruce Richardson  *
21999a2dd95SBruce Richardson  */
22099a2dd95SBruce Richardson struct rte_cryptodev_asym_capability_idx {
22199a2dd95SBruce Richardson 	enum rte_crypto_asym_xform_type type;
22299a2dd95SBruce Richardson 	/**< Asymmetric xform (algo) type */
22399a2dd95SBruce Richardson };
22499a2dd95SBruce Richardson 
22599a2dd95SBruce Richardson /**
22699a2dd95SBruce Richardson  * Provide capabilities available for defined device and algorithm
22799a2dd95SBruce Richardson  *
22899a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
22999a2dd95SBruce Richardson  * @param	idx		Description of crypto algorithms.
23099a2dd95SBruce Richardson  *
23199a2dd95SBruce Richardson  * @return
23299a2dd95SBruce Richardson  *   - Return description of the symmetric crypto capability if exist.
23399a2dd95SBruce Richardson  *   - Return NULL if the capability not exist.
23499a2dd95SBruce Richardson  */
23599a2dd95SBruce Richardson const struct rte_cryptodev_symmetric_capability *
23699a2dd95SBruce Richardson rte_cryptodev_sym_capability_get(uint8_t dev_id,
23799a2dd95SBruce Richardson 		const struct rte_cryptodev_sym_capability_idx *idx);
23899a2dd95SBruce Richardson 
23999a2dd95SBruce Richardson /**
24099a2dd95SBruce Richardson  *  Provide capabilities available for defined device and xform
24199a2dd95SBruce Richardson  *
24299a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
24399a2dd95SBruce Richardson  * @param	idx		Description of asym crypto xform.
24499a2dd95SBruce Richardson  *
24599a2dd95SBruce Richardson  * @return
24699a2dd95SBruce Richardson  *   - Return description of the asymmetric crypto capability if exist.
24799a2dd95SBruce Richardson  *   - Return NULL if the capability not exist.
24899a2dd95SBruce Richardson  */
24999a2dd95SBruce Richardson __rte_experimental
25099a2dd95SBruce Richardson const struct rte_cryptodev_asymmetric_xform_capability *
25199a2dd95SBruce Richardson rte_cryptodev_asym_capability_get(uint8_t dev_id,
25299a2dd95SBruce Richardson 		const struct rte_cryptodev_asym_capability_idx *idx);
25399a2dd95SBruce Richardson 
25499a2dd95SBruce Richardson /**
25599a2dd95SBruce Richardson  * Check if key size and initial vector are supported
25699a2dd95SBruce Richardson  * in crypto cipher capability
25799a2dd95SBruce Richardson  *
25899a2dd95SBruce Richardson  * @param	capability	Description of the symmetric crypto capability.
25999a2dd95SBruce Richardson  * @param	key_size	Cipher key size.
26099a2dd95SBruce Richardson  * @param	iv_size		Cipher initial vector size.
26199a2dd95SBruce Richardson  *
26299a2dd95SBruce Richardson  * @return
26399a2dd95SBruce Richardson  *   - Return 0 if the parameters are in range of the capability.
26499a2dd95SBruce Richardson  *   - Return -1 if the parameters are out of range of the capability.
26599a2dd95SBruce Richardson  */
26699a2dd95SBruce Richardson int
26799a2dd95SBruce Richardson rte_cryptodev_sym_capability_check_cipher(
26899a2dd95SBruce Richardson 		const struct rte_cryptodev_symmetric_capability *capability,
26999a2dd95SBruce Richardson 		uint16_t key_size, uint16_t iv_size);
27099a2dd95SBruce Richardson 
27199a2dd95SBruce Richardson /**
27299a2dd95SBruce Richardson  * Check if key size and initial vector are supported
27399a2dd95SBruce Richardson  * in crypto auth capability
27499a2dd95SBruce Richardson  *
27599a2dd95SBruce Richardson  * @param	capability	Description of the symmetric crypto capability.
27699a2dd95SBruce Richardson  * @param	key_size	Auth key size.
27799a2dd95SBruce Richardson  * @param	digest_size	Auth digest size.
27899a2dd95SBruce Richardson  * @param	iv_size		Auth initial vector size.
27999a2dd95SBruce Richardson  *
28099a2dd95SBruce Richardson  * @return
28199a2dd95SBruce Richardson  *   - Return 0 if the parameters are in range of the capability.
28299a2dd95SBruce Richardson  *   - Return -1 if the parameters are out of range of the capability.
28399a2dd95SBruce Richardson  */
28499a2dd95SBruce Richardson int
28599a2dd95SBruce Richardson rte_cryptodev_sym_capability_check_auth(
28699a2dd95SBruce Richardson 		const struct rte_cryptodev_symmetric_capability *capability,
28799a2dd95SBruce Richardson 		uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
28899a2dd95SBruce Richardson 
28999a2dd95SBruce Richardson /**
29099a2dd95SBruce Richardson  * Check if key, digest, AAD and initial vector sizes are supported
29199a2dd95SBruce Richardson  * in crypto AEAD capability
29299a2dd95SBruce Richardson  *
29399a2dd95SBruce Richardson  * @param	capability	Description of the symmetric crypto capability.
29499a2dd95SBruce Richardson  * @param	key_size	AEAD key size.
29599a2dd95SBruce Richardson  * @param	digest_size	AEAD digest size.
29699a2dd95SBruce Richardson  * @param	aad_size	AEAD AAD size.
29799a2dd95SBruce Richardson  * @param	iv_size		AEAD IV size.
29899a2dd95SBruce Richardson  *
29999a2dd95SBruce Richardson  * @return
30099a2dd95SBruce Richardson  *   - Return 0 if the parameters are in range of the capability.
30199a2dd95SBruce Richardson  *   - Return -1 if the parameters are out of range of the capability.
30299a2dd95SBruce Richardson  */
30399a2dd95SBruce Richardson int
30499a2dd95SBruce Richardson rte_cryptodev_sym_capability_check_aead(
30599a2dd95SBruce Richardson 		const struct rte_cryptodev_symmetric_capability *capability,
30699a2dd95SBruce Richardson 		uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
30799a2dd95SBruce Richardson 		uint16_t iv_size);
30899a2dd95SBruce Richardson 
30999a2dd95SBruce Richardson /**
31099a2dd95SBruce Richardson  * Check if op type is supported
31199a2dd95SBruce Richardson  *
31299a2dd95SBruce Richardson  * @param	capability	Description of the asymmetric crypto capability.
31399a2dd95SBruce Richardson  * @param	op_type		op type
31499a2dd95SBruce Richardson  *
31599a2dd95SBruce Richardson  * @return
31699a2dd95SBruce Richardson  *   - Return 1 if the op type is supported
31799a2dd95SBruce Richardson  *   - Return 0 if unsupported
31899a2dd95SBruce Richardson  */
31999a2dd95SBruce Richardson __rte_experimental
32099a2dd95SBruce Richardson int
32199a2dd95SBruce Richardson rte_cryptodev_asym_xform_capability_check_optype(
32299a2dd95SBruce Richardson 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
32399a2dd95SBruce Richardson 		enum rte_crypto_asym_op_type op_type);
32499a2dd95SBruce Richardson 
32599a2dd95SBruce Richardson /**
32699a2dd95SBruce Richardson  * Check if modulus length is in supported range
32799a2dd95SBruce Richardson  *
32899a2dd95SBruce Richardson  * @param	capability	Description of the asymmetric crypto capability.
32999a2dd95SBruce Richardson  * @param	modlen		modulus length.
33099a2dd95SBruce Richardson  *
33199a2dd95SBruce Richardson  * @return
33299a2dd95SBruce Richardson  *   - Return 0 if the parameters are in range of the capability.
33399a2dd95SBruce Richardson  *   - Return -1 if the parameters are out of range of the capability.
33499a2dd95SBruce Richardson  */
33599a2dd95SBruce Richardson __rte_experimental
33699a2dd95SBruce Richardson int
33799a2dd95SBruce Richardson rte_cryptodev_asym_xform_capability_check_modlen(
33899a2dd95SBruce Richardson 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
33999a2dd95SBruce Richardson 		uint16_t modlen);
34099a2dd95SBruce Richardson 
34199a2dd95SBruce Richardson /**
34299a2dd95SBruce Richardson  * Provide the cipher algorithm enum, given an algorithm string
34399a2dd95SBruce Richardson  *
34499a2dd95SBruce Richardson  * @param	algo_enum	A pointer to the cipher algorithm
34599a2dd95SBruce Richardson  *				enum to be filled
34699a2dd95SBruce Richardson  * @param	algo_string	Authentication algo string
34799a2dd95SBruce Richardson  *
34899a2dd95SBruce Richardson  * @return
34999a2dd95SBruce Richardson  * - Return -1 if string is not valid
35099a2dd95SBruce Richardson  * - Return 0 is the string is valid
35199a2dd95SBruce Richardson  */
35299a2dd95SBruce Richardson int
35399a2dd95SBruce Richardson rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
35499a2dd95SBruce Richardson 		const char *algo_string);
35599a2dd95SBruce Richardson 
35699a2dd95SBruce Richardson /**
35799a2dd95SBruce Richardson  * Provide the authentication algorithm enum, given an algorithm string
35899a2dd95SBruce Richardson  *
35999a2dd95SBruce Richardson  * @param	algo_enum	A pointer to the authentication algorithm
36099a2dd95SBruce Richardson  *				enum to be filled
36199a2dd95SBruce Richardson  * @param	algo_string	Authentication algo string
36299a2dd95SBruce Richardson  *
36399a2dd95SBruce Richardson  * @return
36499a2dd95SBruce Richardson  * - Return -1 if string is not valid
36599a2dd95SBruce Richardson  * - Return 0 is the string is valid
36699a2dd95SBruce Richardson  */
36799a2dd95SBruce Richardson int
36899a2dd95SBruce Richardson rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
36999a2dd95SBruce Richardson 		const char *algo_string);
37099a2dd95SBruce Richardson 
37199a2dd95SBruce Richardson /**
37299a2dd95SBruce Richardson  * Provide the AEAD algorithm enum, given an algorithm string
37399a2dd95SBruce Richardson  *
37499a2dd95SBruce Richardson  * @param	algo_enum	A pointer to the AEAD algorithm
37599a2dd95SBruce Richardson  *				enum to be filled
37699a2dd95SBruce Richardson  * @param	algo_string	AEAD algorithm string
37799a2dd95SBruce Richardson  *
37899a2dd95SBruce Richardson  * @return
37999a2dd95SBruce Richardson  * - Return -1 if string is not valid
38099a2dd95SBruce Richardson  * - Return 0 is the string is valid
38199a2dd95SBruce Richardson  */
38299a2dd95SBruce Richardson int
38399a2dd95SBruce Richardson rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
38499a2dd95SBruce Richardson 		const char *algo_string);
38599a2dd95SBruce Richardson 
38699a2dd95SBruce Richardson /**
38799a2dd95SBruce Richardson  * Provide the Asymmetric xform enum, given an xform string
38899a2dd95SBruce Richardson  *
38999a2dd95SBruce Richardson  * @param	xform_enum	A pointer to the xform type
39099a2dd95SBruce Richardson  *				enum to be filled
39199a2dd95SBruce Richardson  * @param	xform_string	xform string
39299a2dd95SBruce Richardson  *
39399a2dd95SBruce Richardson  * @return
39499a2dd95SBruce Richardson  * - Return -1 if string is not valid
39599a2dd95SBruce Richardson  * - Return 0 if the string is valid
39699a2dd95SBruce Richardson  */
39799a2dd95SBruce Richardson __rte_experimental
39899a2dd95SBruce Richardson int
39999a2dd95SBruce Richardson rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
40099a2dd95SBruce Richardson 		const char *xform_string);
40199a2dd95SBruce Richardson 
40299a2dd95SBruce Richardson 
40399a2dd95SBruce Richardson /** Macro used at end of crypto PMD list */
40499a2dd95SBruce Richardson #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
40599a2dd95SBruce Richardson 	{ RTE_CRYPTO_OP_TYPE_UNDEFINED }
40699a2dd95SBruce Richardson 
40799a2dd95SBruce Richardson 
40899a2dd95SBruce Richardson /**
40999a2dd95SBruce Richardson  * Crypto device supported feature flags
41099a2dd95SBruce Richardson  *
41199a2dd95SBruce Richardson  * Note:
41299a2dd95SBruce Richardson  * New features flags should be added to the end of the list
41399a2dd95SBruce Richardson  *
41499a2dd95SBruce Richardson  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
41599a2dd95SBruce Richardson  */
41699a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO		(1ULL << 0)
41799a2dd95SBruce Richardson /**< Symmetric crypto operations are supported */
41899a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO		(1ULL << 1)
41999a2dd95SBruce Richardson /**< Asymmetric crypto operations are supported */
42099a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING		(1ULL << 2)
42199a2dd95SBruce Richardson /**< Chaining symmetric crypto operations are supported */
42299a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_SSE			(1ULL << 3)
42399a2dd95SBruce Richardson /**< Utilises CPU SIMD SSE instructions */
42499a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_AVX			(1ULL << 4)
42599a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX instructions */
42699a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_AVX2			(1ULL << 5)
42799a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX2 instructions */
42899a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_AESNI			(1ULL << 6)
42999a2dd95SBruce Richardson /**< Utilises CPU AES-NI instructions */
43099a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_HW_ACCELERATED			(1ULL << 7)
43199a2dd95SBruce Richardson /**< Operations are off-loaded to an
43299a2dd95SBruce Richardson  * external hardware accelerator
43399a2dd95SBruce Richardson  */
43499a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_AVX512			(1ULL << 8)
43599a2dd95SBruce Richardson /**< Utilises CPU SIMD AVX512 instructions */
43699a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_IN_PLACE_SGL			(1ULL << 9)
43799a2dd95SBruce Richardson /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
43899a2dd95SBruce Richardson  * are supported
43999a2dd95SBruce Richardson  */
44099a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT		(1ULL << 10)
44199a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are
44299a2dd95SBruce Richardson  * supported in input and output
44399a2dd95SBruce Richardson  */
44499a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT		(1ULL << 11)
44599a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are supported
44699a2dd95SBruce Richardson  * in input, combined with linear buffers (LB), with a
44799a2dd95SBruce Richardson  * single segment in output
44899a2dd95SBruce Richardson  */
44999a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT		(1ULL << 12)
45099a2dd95SBruce Richardson /**< Out-of-place Scatter-gather (SGL) buffers are supported
45199a2dd95SBruce Richardson  * in output, combined with linear buffers (LB) in input
45299a2dd95SBruce Richardson  */
45399a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT		(1ULL << 13)
45499a2dd95SBruce Richardson /**< Out-of-place linear buffers (LB) are supported in input and output */
45599a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_NEON			(1ULL << 14)
45699a2dd95SBruce Richardson /**< Utilises CPU NEON instructions */
45799a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_CPU_ARM_CE			(1ULL << 15)
45899a2dd95SBruce Richardson /**< Utilises ARM CPU Cryptographic Extensions */
45999a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_SECURITY			(1ULL << 16)
46099a2dd95SBruce Richardson /**< Support Security Protocol Processing */
46199a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP		(1ULL << 17)
46299a2dd95SBruce Richardson /**< Support RSA Private Key OP with exponent */
46399a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT		(1ULL << 18)
46499a2dd95SBruce Richardson /**< Support RSA Private Key OP with CRT (quintuple) Keys */
46599a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED		(1ULL << 19)
46699a2dd95SBruce Richardson /**< Support encrypted-digest operations where digest is appended to data */
46799a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS		(1ULL << 20)
46899a2dd95SBruce Richardson /**< Support asymmetric session-less operations */
46999a2dd95SBruce Richardson #define	RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO			(1ULL << 21)
47099a2dd95SBruce Richardson /**< Support symmetric cpu-crypto processing */
47199a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS		(1ULL << 22)
47299a2dd95SBruce Richardson /**< Support symmetric session-less operations */
47399a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA		(1ULL << 23)
47499a2dd95SBruce Richardson /**< Support operations on data which is not byte aligned */
47599a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_SYM_RAW_DP			(1ULL << 24)
47699a2dd95SBruce Richardson /**< Support accelerator specific symmetric raw data-path APIs */
47799a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS	(1ULL << 25)
47899a2dd95SBruce Richardson /**< Support operations on multiple data-units message */
47999a2dd95SBruce Richardson #define RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY		(1ULL << 26)
48099a2dd95SBruce Richardson /**< Support wrapped key in cipher xform  */
48103ab51eaSArchana Muniganti #define RTE_CRYPTODEV_FF_SECURITY_INNER_CSUM		(1ULL << 27)
48203ab51eaSArchana Muniganti /**< Support inner checksum computation/verification */
48399a2dd95SBruce Richardson 
48499a2dd95SBruce Richardson /**
48599a2dd95SBruce Richardson  * Get the name of a crypto device feature flag
48699a2dd95SBruce Richardson  *
48799a2dd95SBruce Richardson  * @param	flag	The mask describing the flag.
48899a2dd95SBruce Richardson  *
48999a2dd95SBruce Richardson  * @return
49099a2dd95SBruce Richardson  *   The name of this flag, or NULL if it's not a valid feature flag.
49199a2dd95SBruce Richardson  */
49299a2dd95SBruce Richardson 
49399a2dd95SBruce Richardson extern const char *
49499a2dd95SBruce Richardson rte_cryptodev_get_feature_name(uint64_t flag);
49599a2dd95SBruce Richardson 
49699a2dd95SBruce Richardson /**  Crypto device information */
49799a2dd95SBruce Richardson struct rte_cryptodev_info {
49899a2dd95SBruce Richardson 	const char *driver_name;	/**< Driver name. */
49999a2dd95SBruce Richardson 	uint8_t driver_id;		/**< Driver identifier */
50099a2dd95SBruce Richardson 	struct rte_device *device;	/**< Generic device information. */
50199a2dd95SBruce Richardson 
50299a2dd95SBruce Richardson 	uint64_t feature_flags;
50399a2dd95SBruce Richardson 	/**< Feature flags exposes HW/SW features for the given device */
50499a2dd95SBruce Richardson 
50599a2dd95SBruce Richardson 	const struct rte_cryptodev_capabilities *capabilities;
50699a2dd95SBruce Richardson 	/**< Array of devices supported capabilities */
50799a2dd95SBruce Richardson 
50899a2dd95SBruce Richardson 	unsigned max_nb_queue_pairs;
50999a2dd95SBruce Richardson 	/**< Maximum number of queues pairs supported by device. */
51099a2dd95SBruce Richardson 
51199a2dd95SBruce Richardson 	uint16_t min_mbuf_headroom_req;
51299a2dd95SBruce Richardson 	/**< Minimum mbuf headroom required by device */
51399a2dd95SBruce Richardson 
51499a2dd95SBruce Richardson 	uint16_t min_mbuf_tailroom_req;
51599a2dd95SBruce Richardson 	/**< Minimum mbuf tailroom required by device */
51699a2dd95SBruce Richardson 
51799a2dd95SBruce Richardson 	struct {
51899a2dd95SBruce Richardson 		unsigned max_nb_sessions;
51999a2dd95SBruce Richardson 		/**< Maximum number of sessions supported by device.
52099a2dd95SBruce Richardson 		 * If 0, the device does not have any limitation in
52199a2dd95SBruce Richardson 		 * number of sessions that can be used.
52299a2dd95SBruce Richardson 		 */
52399a2dd95SBruce Richardson 	} sym;
52499a2dd95SBruce Richardson };
52599a2dd95SBruce Richardson 
52699a2dd95SBruce Richardson #define RTE_CRYPTODEV_DETACHED  (0)
52799a2dd95SBruce Richardson #define RTE_CRYPTODEV_ATTACHED  (1)
52899a2dd95SBruce Richardson 
52999a2dd95SBruce Richardson /** Definitions of Crypto device event types */
53099a2dd95SBruce Richardson enum rte_cryptodev_event_type {
53199a2dd95SBruce Richardson 	RTE_CRYPTODEV_EVENT_UNKNOWN,	/**< unknown event type */
53299a2dd95SBruce Richardson 	RTE_CRYPTODEV_EVENT_ERROR,	/**< error interrupt event */
53399a2dd95SBruce Richardson 	RTE_CRYPTODEV_EVENT_MAX		/**< max value of this enum */
53499a2dd95SBruce Richardson };
53599a2dd95SBruce Richardson 
53699a2dd95SBruce Richardson /** Crypto device queue pair configuration structure. */
53799a2dd95SBruce Richardson struct rte_cryptodev_qp_conf {
53899a2dd95SBruce Richardson 	uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
53999a2dd95SBruce Richardson 	struct rte_mempool *mp_session;
54099a2dd95SBruce Richardson 	/**< The mempool for creating session in sessionless mode */
54199a2dd95SBruce Richardson 	struct rte_mempool *mp_session_private;
54299a2dd95SBruce Richardson 	/**< The mempool for creating sess private data in sessionless mode */
54399a2dd95SBruce Richardson };
54499a2dd95SBruce Richardson 
54599a2dd95SBruce Richardson /**
54699a2dd95SBruce Richardson  * Function type used for processing crypto ops when enqueue/dequeue burst is
54799a2dd95SBruce Richardson  * called.
54899a2dd95SBruce Richardson  *
54999a2dd95SBruce Richardson  * The callback function is called on enqueue/dequeue burst immediately.
55099a2dd95SBruce Richardson  *
55199a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
55299a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
55399a2dd95SBruce Richardson  *				enqueued/dequeued. The value must be in the
55499a2dd95SBruce Richardson  *				range [0, nb_queue_pairs - 1] previously
55599a2dd95SBruce Richardson  *				supplied to *rte_cryptodev_configure*.
55699a2dd95SBruce Richardson  * @param	ops		The address of an array of *nb_ops* pointers
55799a2dd95SBruce Richardson  *				to *rte_crypto_op* structures which contain
55899a2dd95SBruce Richardson  *				the crypto operations to be processed.
55999a2dd95SBruce Richardson  * @param	nb_ops		The number of operations to process.
56099a2dd95SBruce Richardson  * @param	user_param	The arbitrary user parameter passed in by the
56199a2dd95SBruce Richardson  *				application when the callback was originally
56299a2dd95SBruce Richardson  *				registered.
56399a2dd95SBruce Richardson  * @return			The number of ops to be enqueued to the
56499a2dd95SBruce Richardson  *				crypto device.
56599a2dd95SBruce Richardson  */
56699a2dd95SBruce Richardson typedef uint16_t (*rte_cryptodev_callback_fn)(uint16_t dev_id, uint16_t qp_id,
56799a2dd95SBruce Richardson 		struct rte_crypto_op **ops, uint16_t nb_ops, void *user_param);
56899a2dd95SBruce Richardson 
56999a2dd95SBruce Richardson /**
57099a2dd95SBruce Richardson  * Typedef for application callback function to be registered by application
57199a2dd95SBruce Richardson  * software for notification of device events
57299a2dd95SBruce Richardson  *
57399a2dd95SBruce Richardson  * @param	dev_id	Crypto device identifier
57499a2dd95SBruce Richardson  * @param	event	Crypto device event to register for notification of.
57599a2dd95SBruce Richardson  * @param	cb_arg	User specified parameter to be passed as to passed to
57699a2dd95SBruce Richardson  *			users callback function.
57799a2dd95SBruce Richardson  */
57899a2dd95SBruce Richardson typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
57999a2dd95SBruce Richardson 		enum rte_cryptodev_event_type event, void *cb_arg);
58099a2dd95SBruce Richardson 
58199a2dd95SBruce Richardson 
58299a2dd95SBruce Richardson /** Crypto Device statistics */
58399a2dd95SBruce Richardson struct rte_cryptodev_stats {
58499a2dd95SBruce Richardson 	uint64_t enqueued_count;
58599a2dd95SBruce Richardson 	/**< Count of all operations enqueued */
58699a2dd95SBruce Richardson 	uint64_t dequeued_count;
58799a2dd95SBruce Richardson 	/**< Count of all operations dequeued */
58899a2dd95SBruce Richardson 
58999a2dd95SBruce Richardson 	uint64_t enqueue_err_count;
59099a2dd95SBruce Richardson 	/**< Total error count on operations enqueued */
59199a2dd95SBruce Richardson 	uint64_t dequeue_err_count;
59299a2dd95SBruce Richardson 	/**< Total error count on operations dequeued */
59399a2dd95SBruce Richardson };
59499a2dd95SBruce Richardson 
59599a2dd95SBruce Richardson #define RTE_CRYPTODEV_NAME_MAX_LEN	(64)
59699a2dd95SBruce Richardson /**< Max length of name of crypto PMD */
59799a2dd95SBruce Richardson 
59899a2dd95SBruce Richardson /**
59999a2dd95SBruce Richardson  * Get the device identifier for the named crypto device.
60099a2dd95SBruce Richardson  *
60199a2dd95SBruce Richardson  * @param	name	device name to select the device structure.
60299a2dd95SBruce Richardson  *
60399a2dd95SBruce Richardson  * @return
60499a2dd95SBruce Richardson  *   - Returns crypto device identifier on success.
60599a2dd95SBruce Richardson  *   - Return -1 on failure to find named crypto device.
60699a2dd95SBruce Richardson  */
60799a2dd95SBruce Richardson extern int
60899a2dd95SBruce Richardson rte_cryptodev_get_dev_id(const char *name);
60999a2dd95SBruce Richardson 
61099a2dd95SBruce Richardson /**
61199a2dd95SBruce Richardson  * Get the crypto device name given a device identifier.
61299a2dd95SBruce Richardson  *
61399a2dd95SBruce Richardson  * @param dev_id
61499a2dd95SBruce Richardson  *   The identifier of the device
61599a2dd95SBruce Richardson  *
61699a2dd95SBruce Richardson  * @return
61799a2dd95SBruce Richardson  *   - Returns crypto device name.
61899a2dd95SBruce Richardson  *   - Returns NULL if crypto device is not present.
61999a2dd95SBruce Richardson  */
62099a2dd95SBruce Richardson extern const char *
62199a2dd95SBruce Richardson rte_cryptodev_name_get(uint8_t dev_id);
62299a2dd95SBruce Richardson 
62399a2dd95SBruce Richardson /**
62499a2dd95SBruce Richardson  * Get the total number of crypto devices that have been successfully
62599a2dd95SBruce Richardson  * initialised.
62699a2dd95SBruce Richardson  *
62799a2dd95SBruce Richardson  * @return
62899a2dd95SBruce Richardson  *   - The total number of usable crypto devices.
62999a2dd95SBruce Richardson  */
63099a2dd95SBruce Richardson extern uint8_t
63199a2dd95SBruce Richardson rte_cryptodev_count(void);
63299a2dd95SBruce Richardson 
63399a2dd95SBruce Richardson /**
63499a2dd95SBruce Richardson  * Get number of crypto device defined type.
63599a2dd95SBruce Richardson  *
63699a2dd95SBruce Richardson  * @param	driver_id	driver identifier.
63799a2dd95SBruce Richardson  *
63899a2dd95SBruce Richardson  * @return
63999a2dd95SBruce Richardson  *   Returns number of crypto device.
64099a2dd95SBruce Richardson  */
64199a2dd95SBruce Richardson extern uint8_t
64299a2dd95SBruce Richardson rte_cryptodev_device_count_by_driver(uint8_t driver_id);
64399a2dd95SBruce Richardson 
64499a2dd95SBruce Richardson /**
64599a2dd95SBruce Richardson  * Get number and identifiers of attached crypto devices that
64699a2dd95SBruce Richardson  * use the same crypto driver.
64799a2dd95SBruce Richardson  *
64899a2dd95SBruce Richardson  * @param	driver_name	driver name.
64999a2dd95SBruce Richardson  * @param	devices		output devices identifiers.
65099a2dd95SBruce Richardson  * @param	nb_devices	maximal number of devices.
65199a2dd95SBruce Richardson  *
65299a2dd95SBruce Richardson  * @return
65399a2dd95SBruce Richardson  *   Returns number of attached crypto device.
65499a2dd95SBruce Richardson  */
65599a2dd95SBruce Richardson uint8_t
65699a2dd95SBruce Richardson rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
65799a2dd95SBruce Richardson 		uint8_t nb_devices);
65899a2dd95SBruce Richardson /*
65999a2dd95SBruce Richardson  * Return the NUMA socket to which a device is connected
66099a2dd95SBruce Richardson  *
66199a2dd95SBruce Richardson  * @param dev_id
66299a2dd95SBruce Richardson  *   The identifier of the device
66399a2dd95SBruce Richardson  * @return
66499a2dd95SBruce Richardson  *   The NUMA socket id to which the device is connected or
66599a2dd95SBruce Richardson  *   a default of zero if the socket could not be determined.
66699a2dd95SBruce Richardson  *   -1 if returned is the dev_id value is out of range.
66799a2dd95SBruce Richardson  */
66899a2dd95SBruce Richardson extern int
66999a2dd95SBruce Richardson rte_cryptodev_socket_id(uint8_t dev_id);
67099a2dd95SBruce Richardson 
67199a2dd95SBruce Richardson /** Crypto device configuration structure */
67299a2dd95SBruce Richardson struct rte_cryptodev_config {
67399a2dd95SBruce Richardson 	int socket_id;			/**< Socket to allocate resources on */
67499a2dd95SBruce Richardson 	uint16_t nb_queue_pairs;
67599a2dd95SBruce Richardson 	/**< Number of queue pairs to configure on device */
67699a2dd95SBruce Richardson 	uint64_t ff_disable;
67799a2dd95SBruce Richardson 	/**< Feature flags to be disabled. Only the following features are
67899a2dd95SBruce Richardson 	 * allowed to be disabled,
67999a2dd95SBruce Richardson 	 *  - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
68099a2dd95SBruce Richardson 	 *  - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
68199a2dd95SBruce Richardson 	 *  - RTE_CRYTPODEV_FF_SECURITY
68299a2dd95SBruce Richardson 	 */
68399a2dd95SBruce Richardson };
68499a2dd95SBruce Richardson 
68599a2dd95SBruce Richardson /**
68699a2dd95SBruce Richardson  * Configure a device.
68799a2dd95SBruce Richardson  *
68899a2dd95SBruce Richardson  * This function must be invoked first before any other function in the
68999a2dd95SBruce Richardson  * API. This function can also be re-invoked when a device is in the
69099a2dd95SBruce Richardson  * stopped state.
69199a2dd95SBruce Richardson  *
69299a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device to configure.
69399a2dd95SBruce Richardson  * @param	config		The crypto device configuration structure.
69499a2dd95SBruce Richardson  *
69599a2dd95SBruce Richardson  * @return
69699a2dd95SBruce Richardson  *   - 0: Success, device configured.
69799a2dd95SBruce Richardson  *   - <0: Error code returned by the driver configuration function.
69899a2dd95SBruce Richardson  */
69999a2dd95SBruce Richardson extern int
70099a2dd95SBruce Richardson rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
70199a2dd95SBruce Richardson 
70299a2dd95SBruce Richardson /**
70399a2dd95SBruce Richardson  * Start an device.
70499a2dd95SBruce Richardson  *
70599a2dd95SBruce Richardson  * The device start step is the last one and consists of setting the configured
70699a2dd95SBruce Richardson  * offload features and in starting the transmit and the receive units of the
70799a2dd95SBruce Richardson  * device.
70899a2dd95SBruce Richardson  * On success, all basic functions exported by the API (link status,
70999a2dd95SBruce Richardson  * receive/transmit, and so on) can be invoked.
71099a2dd95SBruce Richardson  *
71199a2dd95SBruce Richardson  * @param dev_id
71299a2dd95SBruce Richardson  *   The identifier of the device.
71399a2dd95SBruce Richardson  * @return
71499a2dd95SBruce Richardson  *   - 0: Success, device started.
71599a2dd95SBruce Richardson  *   - <0: Error code of the driver device start function.
71699a2dd95SBruce Richardson  */
71799a2dd95SBruce Richardson extern int
71899a2dd95SBruce Richardson rte_cryptodev_start(uint8_t dev_id);
71999a2dd95SBruce Richardson 
72099a2dd95SBruce Richardson /**
72199a2dd95SBruce Richardson  * Stop an device. The device can be restarted with a call to
72299a2dd95SBruce Richardson  * rte_cryptodev_start()
72399a2dd95SBruce Richardson  *
72499a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
72599a2dd95SBruce Richardson  */
72699a2dd95SBruce Richardson extern void
72799a2dd95SBruce Richardson rte_cryptodev_stop(uint8_t dev_id);
72899a2dd95SBruce Richardson 
72999a2dd95SBruce Richardson /**
73099a2dd95SBruce Richardson  * Close an device. The device cannot be restarted!
73199a2dd95SBruce Richardson  *
73299a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
73399a2dd95SBruce Richardson  *
73499a2dd95SBruce Richardson  * @return
73599a2dd95SBruce Richardson  *  - 0 on successfully closing device
73699a2dd95SBruce Richardson  *  - <0 on failure to close device
73799a2dd95SBruce Richardson  */
73899a2dd95SBruce Richardson extern int
73999a2dd95SBruce Richardson rte_cryptodev_close(uint8_t dev_id);
74099a2dd95SBruce Richardson 
74199a2dd95SBruce Richardson /**
74299a2dd95SBruce Richardson  * Allocate and set up a receive queue pair for a device.
74399a2dd95SBruce Richardson  *
74499a2dd95SBruce Richardson  *
74599a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
74699a2dd95SBruce Richardson  * @param	queue_pair_id	The index of the queue pairs to set up. The
74799a2dd95SBruce Richardson  *				value must be in the range [0, nb_queue_pair
74899a2dd95SBruce Richardson  *				- 1] previously supplied to
74999a2dd95SBruce Richardson  *				rte_cryptodev_configure().
75099a2dd95SBruce Richardson  * @param	qp_conf		The pointer to the configuration data to be
75199a2dd95SBruce Richardson  *				used for the queue pair.
75299a2dd95SBruce Richardson  * @param	socket_id	The *socket_id* argument is the socket
75399a2dd95SBruce Richardson  *				identifier in case of NUMA. The value can be
75499a2dd95SBruce Richardson  *				*SOCKET_ID_ANY* if there is no NUMA constraint
75599a2dd95SBruce Richardson  *				for the DMA memory allocated for the receive
75699a2dd95SBruce Richardson  *				queue pair.
75799a2dd95SBruce Richardson  *
75899a2dd95SBruce Richardson  * @return
75999a2dd95SBruce Richardson  *   - 0: Success, queue pair correctly set up.
76099a2dd95SBruce Richardson  *   - <0: Queue pair configuration failed
76199a2dd95SBruce Richardson  */
76299a2dd95SBruce Richardson extern int
76399a2dd95SBruce Richardson rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
76499a2dd95SBruce Richardson 		const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
76599a2dd95SBruce Richardson 
76699a2dd95SBruce Richardson /**
76799a2dd95SBruce Richardson  * Get the status of queue pairs setup on a specific crypto device
76899a2dd95SBruce Richardson  *
76999a2dd95SBruce Richardson  * @param	dev_id		Crypto device identifier.
77099a2dd95SBruce Richardson  * @param	queue_pair_id	The index of the queue pairs to set up. The
77199a2dd95SBruce Richardson  *				value must be in the range [0, nb_queue_pair
77299a2dd95SBruce Richardson  *				- 1] previously supplied to
77399a2dd95SBruce Richardson  *				rte_cryptodev_configure().
77499a2dd95SBruce Richardson  * @return
77599a2dd95SBruce Richardson  *   - 0: qp was not configured
77699a2dd95SBruce Richardson  *	 - 1: qp was configured
77799a2dd95SBruce Richardson  *	 - -EINVAL: device was not configured
77899a2dd95SBruce Richardson  */
77999a2dd95SBruce Richardson __rte_experimental
78099a2dd95SBruce Richardson int
78199a2dd95SBruce Richardson rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id);
78299a2dd95SBruce Richardson 
78399a2dd95SBruce Richardson /**
78499a2dd95SBruce Richardson  * Get the number of queue pairs on a specific crypto device
78599a2dd95SBruce Richardson  *
78699a2dd95SBruce Richardson  * @param	dev_id		Crypto device identifier.
78799a2dd95SBruce Richardson  * @return
78899a2dd95SBruce Richardson  *   - The number of configured queue pairs.
78999a2dd95SBruce Richardson  */
79099a2dd95SBruce Richardson extern uint16_t
79199a2dd95SBruce Richardson rte_cryptodev_queue_pair_count(uint8_t dev_id);
79299a2dd95SBruce Richardson 
79399a2dd95SBruce Richardson 
79499a2dd95SBruce Richardson /**
79599a2dd95SBruce Richardson  * Retrieve the general I/O statistics of a device.
79699a2dd95SBruce Richardson  *
79799a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
79899a2dd95SBruce Richardson  * @param	stats		A pointer to a structure of type
79999a2dd95SBruce Richardson  *				*rte_cryptodev_stats* to be filled with the
80099a2dd95SBruce Richardson  *				values of device counters.
80199a2dd95SBruce Richardson  * @return
80299a2dd95SBruce Richardson  *   - Zero if successful.
80399a2dd95SBruce Richardson  *   - Non-zero otherwise.
80499a2dd95SBruce Richardson  */
80599a2dd95SBruce Richardson extern int
80699a2dd95SBruce Richardson rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
80799a2dd95SBruce Richardson 
80899a2dd95SBruce Richardson /**
80999a2dd95SBruce Richardson  * Reset the general I/O statistics of a device.
81099a2dd95SBruce Richardson  *
81199a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
81299a2dd95SBruce Richardson  */
81399a2dd95SBruce Richardson extern void
81499a2dd95SBruce Richardson rte_cryptodev_stats_reset(uint8_t dev_id);
81599a2dd95SBruce Richardson 
81699a2dd95SBruce Richardson /**
81799a2dd95SBruce Richardson  * Retrieve the contextual information of a device.
81899a2dd95SBruce Richardson  *
81999a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
82099a2dd95SBruce Richardson  * @param	dev_info	A pointer to a structure of type
82199a2dd95SBruce Richardson  *				*rte_cryptodev_info* to be filled with the
82299a2dd95SBruce Richardson  *				contextual information of the device.
82399a2dd95SBruce Richardson  *
82499a2dd95SBruce Richardson  * @note The capabilities field of dev_info is set to point to the first
82599a2dd95SBruce Richardson  * element of an array of struct rte_cryptodev_capabilities. The element after
82699a2dd95SBruce Richardson  * the last valid element has it's op field set to
82799a2dd95SBruce Richardson  * RTE_CRYPTO_OP_TYPE_UNDEFINED.
82899a2dd95SBruce Richardson  */
82999a2dd95SBruce Richardson extern void
83099a2dd95SBruce Richardson rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
83199a2dd95SBruce Richardson 
83299a2dd95SBruce Richardson 
83399a2dd95SBruce Richardson /**
83499a2dd95SBruce Richardson  * Register a callback function for specific device id.
83599a2dd95SBruce Richardson  *
83699a2dd95SBruce Richardson  * @param	dev_id		Device id.
83799a2dd95SBruce Richardson  * @param	event		Event interested.
83899a2dd95SBruce Richardson  * @param	cb_fn		User supplied callback function to be called.
83999a2dd95SBruce Richardson  * @param	cb_arg		Pointer to the parameters for the registered
84099a2dd95SBruce Richardson  *				callback.
84199a2dd95SBruce Richardson  *
84299a2dd95SBruce Richardson  * @return
84399a2dd95SBruce Richardson  *  - On success, zero.
84499a2dd95SBruce Richardson  *  - On failure, a negative value.
84599a2dd95SBruce Richardson  */
84699a2dd95SBruce Richardson extern int
84799a2dd95SBruce Richardson rte_cryptodev_callback_register(uint8_t dev_id,
84899a2dd95SBruce Richardson 		enum rte_cryptodev_event_type event,
84999a2dd95SBruce Richardson 		rte_cryptodev_cb_fn cb_fn, void *cb_arg);
85099a2dd95SBruce Richardson 
85199a2dd95SBruce Richardson /**
85299a2dd95SBruce Richardson  * Unregister a callback function for specific device id.
85399a2dd95SBruce Richardson  *
85499a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
85599a2dd95SBruce Richardson  * @param	event		Event interested.
85699a2dd95SBruce Richardson  * @param	cb_fn		User supplied callback function to be called.
85799a2dd95SBruce Richardson  * @param	cb_arg		Pointer to the parameters for the registered
85899a2dd95SBruce Richardson  *				callback.
85999a2dd95SBruce Richardson  *
86099a2dd95SBruce Richardson  * @return
86199a2dd95SBruce Richardson  *  - On success, zero.
86299a2dd95SBruce Richardson  *  - On failure, a negative value.
86399a2dd95SBruce Richardson  */
86499a2dd95SBruce Richardson extern int
86599a2dd95SBruce Richardson rte_cryptodev_callback_unregister(uint8_t dev_id,
86699a2dd95SBruce Richardson 		enum rte_cryptodev_event_type event,
86799a2dd95SBruce Richardson 		rte_cryptodev_cb_fn cb_fn, void *cb_arg);
86899a2dd95SBruce Richardson 
86999a2dd95SBruce Richardson struct rte_cryptodev_callback;
87099a2dd95SBruce Richardson 
87199a2dd95SBruce Richardson /** Structure to keep track of registered callbacks */
872f1f6ebc0SWilliam Tu RTE_TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
87399a2dd95SBruce Richardson 
87499a2dd95SBruce Richardson /**
87599a2dd95SBruce Richardson  * Structure used to hold information about the callbacks to be called for a
87699a2dd95SBruce Richardson  * queue pair on enqueue/dequeue.
87799a2dd95SBruce Richardson  */
87899a2dd95SBruce Richardson struct rte_cryptodev_cb {
87999a2dd95SBruce Richardson 	struct rte_cryptodev_cb *next;
88099a2dd95SBruce Richardson 	/**< Pointer to next callback */
88199a2dd95SBruce Richardson 	rte_cryptodev_callback_fn fn;
88299a2dd95SBruce Richardson 	/**< Pointer to callback function */
88399a2dd95SBruce Richardson 	void *arg;
88499a2dd95SBruce Richardson 	/**< Pointer to argument */
88599a2dd95SBruce Richardson };
88699a2dd95SBruce Richardson 
88799a2dd95SBruce Richardson /**
88899a2dd95SBruce Richardson  * @internal
88999a2dd95SBruce Richardson  * Structure used to hold information about the RCU for a queue pair.
89099a2dd95SBruce Richardson  */
89199a2dd95SBruce Richardson struct rte_cryptodev_cb_rcu {
89299a2dd95SBruce Richardson 	struct rte_cryptodev_cb *next;
89399a2dd95SBruce Richardson 	/**< Pointer to next callback */
89499a2dd95SBruce Richardson 	struct rte_rcu_qsbr *qsbr;
89599a2dd95SBruce Richardson 	/**< RCU QSBR variable per queue pair */
89699a2dd95SBruce Richardson };
89799a2dd95SBruce Richardson 
89899a2dd95SBruce Richardson void *
89999a2dd95SBruce Richardson rte_cryptodev_get_sec_ctx(uint8_t dev_id);
90099a2dd95SBruce Richardson 
90199a2dd95SBruce Richardson /** Cryptodev symmetric crypto session
90299a2dd95SBruce Richardson  * Each session is derived from a fixed xform chain. Therefore each session
90399a2dd95SBruce Richardson  * has a fixed algo, key, op-type, digest_len etc.
90499a2dd95SBruce Richardson  */
90599a2dd95SBruce Richardson struct rte_cryptodev_sym_session {
90699a2dd95SBruce Richardson 	uint64_t opaque_data;
90799a2dd95SBruce Richardson 	/**< Can be used for external metadata */
90899a2dd95SBruce Richardson 	uint16_t nb_drivers;
90999a2dd95SBruce Richardson 	/**< number of elements in sess_data array */
91099a2dd95SBruce Richardson 	uint16_t user_data_sz;
91199a2dd95SBruce Richardson 	/**< session user data will be placed after sess_data */
91299a2dd95SBruce Richardson 	__extension__ struct {
91399a2dd95SBruce Richardson 		void *data;
91499a2dd95SBruce Richardson 		uint16_t refcnt;
91599a2dd95SBruce Richardson 	} sess_data[0];
91699a2dd95SBruce Richardson 	/**< Driver specific session material, variable size */
91799a2dd95SBruce Richardson };
91899a2dd95SBruce Richardson 
91999a2dd95SBruce Richardson /**
92099a2dd95SBruce Richardson  * Create a symmetric session mempool.
92199a2dd95SBruce Richardson  *
92299a2dd95SBruce Richardson  * @param name
92399a2dd95SBruce Richardson  *   The unique mempool name.
92499a2dd95SBruce Richardson  * @param nb_elts
92599a2dd95SBruce Richardson  *   The number of elements in the mempool.
92699a2dd95SBruce Richardson  * @param elt_size
92799a2dd95SBruce Richardson  *   The size of the element. This value will be ignored if it is smaller than
92899a2dd95SBruce Richardson  *   the minimum session header size required for the system. For the user who
92999a2dd95SBruce Richardson  *   want to use the same mempool for sym session and session private data it
93099a2dd95SBruce Richardson  *   can be the maximum value of all existing devices' private data and session
93199a2dd95SBruce Richardson  *   header sizes.
93299a2dd95SBruce Richardson  * @param cache_size
93399a2dd95SBruce Richardson  *   The number of per-lcore cache elements
93499a2dd95SBruce Richardson  * @param priv_size
93599a2dd95SBruce Richardson  *   The private data size of each session.
93699a2dd95SBruce Richardson  * @param socket_id
93799a2dd95SBruce Richardson  *   The *socket_id* argument is the socket identifier in the case of
93899a2dd95SBruce Richardson  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
93999a2dd95SBruce Richardson  *   constraint for the reserved zone.
94099a2dd95SBruce Richardson  *
94199a2dd95SBruce Richardson  * @return
94299a2dd95SBruce Richardson  *  - On success return size of the session
94399a2dd95SBruce Richardson  *  - On failure returns 0
94499a2dd95SBruce Richardson  */
94599a2dd95SBruce Richardson __rte_experimental
94699a2dd95SBruce Richardson struct rte_mempool *
94799a2dd95SBruce Richardson rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
94899a2dd95SBruce Richardson 	uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
94999a2dd95SBruce Richardson 	int socket_id);
95099a2dd95SBruce Richardson 
95199a2dd95SBruce Richardson /**
9521f1e4b7cSCiara Power  * Create an asymmetric session mempool.
9531f1e4b7cSCiara Power  *
9541f1e4b7cSCiara Power  * @param name
9551f1e4b7cSCiara Power  *   The unique mempool name.
9561f1e4b7cSCiara Power  * @param nb_elts
9571f1e4b7cSCiara Power  *   The number of elements in the mempool.
9581f1e4b7cSCiara Power  * @param cache_size
9591f1e4b7cSCiara Power  *   The number of per-lcore cache elements
96092d55afeSCiara Power  * @param user_data_size
96192d55afeSCiara Power  *   The size of user data to be placed after session private data.
9621f1e4b7cSCiara Power  * @param socket_id
9631f1e4b7cSCiara Power  *   The *socket_id* argument is the socket identifier in the case of
9641f1e4b7cSCiara Power  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
9651f1e4b7cSCiara Power  *   constraint for the reserved zone.
9661f1e4b7cSCiara Power  *
9671f1e4b7cSCiara Power  * @return
9681f1e4b7cSCiara Power  *  - On success return mempool
9691f1e4b7cSCiara Power  *  - On failure returns NULL
9701f1e4b7cSCiara Power  */
9711f1e4b7cSCiara Power __rte_experimental
9721f1e4b7cSCiara Power struct rte_mempool *
9731f1e4b7cSCiara Power rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
97492d55afeSCiara Power 	uint32_t cache_size, uint16_t user_data_size, int socket_id);
9751f1e4b7cSCiara Power 
9761f1e4b7cSCiara Power /**
97799a2dd95SBruce Richardson  * Create symmetric crypto session header (generic with no private data)
97899a2dd95SBruce Richardson  *
97999a2dd95SBruce Richardson  * @param   mempool    Symmetric session mempool to allocate session
98099a2dd95SBruce Richardson  *                     objects from
98199a2dd95SBruce Richardson  * @return
98299a2dd95SBruce Richardson  *  - On success return pointer to sym-session
98399a2dd95SBruce Richardson  *  - On failure returns NULL
98499a2dd95SBruce Richardson  */
98599a2dd95SBruce Richardson struct rte_cryptodev_sym_session *
98699a2dd95SBruce Richardson rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
98799a2dd95SBruce Richardson 
98899a2dd95SBruce Richardson /**
9891f1e4b7cSCiara Power  * Create and initialise an asymmetric crypto session structure.
9901f1e4b7cSCiara Power  * Calls the PMD to configure the private session data.
99199a2dd95SBruce Richardson  *
9921f1e4b7cSCiara Power  * @param   dev_id   ID of device that we want the session to be used on
9931f1e4b7cSCiara Power  * @param   xforms   Asymmetric crypto transform operations to apply on flow
9941f1e4b7cSCiara Power  *                   processed with this session
9951f1e4b7cSCiara Power  * @param   mp       mempool to allocate asymmetric session
99699a2dd95SBruce Richardson  *                   objects from
997*757f40e2SCiara Power  * @param   session  void ** for session to be used
998*757f40e2SCiara Power  *
99999a2dd95SBruce Richardson  * @return
1000*757f40e2SCiara Power  *  - 0 on success.
1001*757f40e2SCiara Power  *  - -EINVAL on invalid arguments.
1002*757f40e2SCiara Power  *  - -ENOMEM on memory error for session allocation.
1003*757f40e2SCiara Power  *  - -ENOTSUP if device doesn't support session configuration.
100499a2dd95SBruce Richardson  */
100599a2dd95SBruce Richardson __rte_experimental
1006*757f40e2SCiara Power int
10071f1e4b7cSCiara Power rte_cryptodev_asym_session_create(uint8_t dev_id,
1008*757f40e2SCiara Power 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
1009*757f40e2SCiara Power 		void **session);
101099a2dd95SBruce Richardson 
101199a2dd95SBruce Richardson /**
101299a2dd95SBruce Richardson  * Frees symmetric crypto session header, after checking that all
101399a2dd95SBruce Richardson  * the device private data has been freed, returning it
101499a2dd95SBruce Richardson  * to its original mempool.
101599a2dd95SBruce Richardson  *
101699a2dd95SBruce Richardson  * @param   sess     Session header to be freed.
101799a2dd95SBruce Richardson  *
101899a2dd95SBruce Richardson  * @return
101999a2dd95SBruce Richardson  *  - 0 if successful.
102099a2dd95SBruce Richardson  *  - -EINVAL if session is NULL.
102199a2dd95SBruce Richardson  *  - -EBUSY if not all device private data has been freed.
102299a2dd95SBruce Richardson  */
102399a2dd95SBruce Richardson int
102499a2dd95SBruce Richardson rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
102599a2dd95SBruce Richardson 
102699a2dd95SBruce Richardson /**
10271f1e4b7cSCiara Power  * Clears and frees asymmetric crypto session header and private data,
10281f1e4b7cSCiara Power  * returning it to its original mempool.
102999a2dd95SBruce Richardson  *
10301f1e4b7cSCiara Power  * @param   dev_id   ID of device that uses the asymmetric session.
103199a2dd95SBruce Richardson  * @param   sess     Session header to be freed.
103299a2dd95SBruce Richardson  *
103399a2dd95SBruce Richardson  * @return
103499a2dd95SBruce Richardson  *  - 0 if successful.
10351f1e4b7cSCiara Power  *  - -EINVAL if device is invalid or session is NULL.
103699a2dd95SBruce Richardson  */
103799a2dd95SBruce Richardson __rte_experimental
103899a2dd95SBruce Richardson int
1039a29bb248SCiara Power rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
104099a2dd95SBruce Richardson 
104199a2dd95SBruce Richardson /**
104299a2dd95SBruce Richardson  * Fill out private data for the device id, based on its device type.
104399a2dd95SBruce Richardson  *
104499a2dd95SBruce Richardson  * @param   dev_id   ID of device that we want the session to be used on
104599a2dd95SBruce Richardson  * @param   sess     Session where the private data will be attached to
104699a2dd95SBruce Richardson  * @param   xforms   Symmetric crypto transform operations to apply on flow
104799a2dd95SBruce Richardson  *                   processed with this session
104899a2dd95SBruce Richardson  * @param   mempool  Mempool where the private data is allocated.
104999a2dd95SBruce Richardson  *
105099a2dd95SBruce Richardson  * @return
105199a2dd95SBruce Richardson  *  - On success, zero.
105299a2dd95SBruce Richardson  *  - -EINVAL if input parameters are invalid.
105399a2dd95SBruce Richardson  *  - -ENOTSUP if crypto device does not support the crypto transform or
105499a2dd95SBruce Richardson  *    does not support symmetric operations.
105599a2dd95SBruce Richardson  *  - -ENOMEM if the private session could not be allocated.
105699a2dd95SBruce Richardson  */
105799a2dd95SBruce Richardson int
105899a2dd95SBruce Richardson rte_cryptodev_sym_session_init(uint8_t dev_id,
105999a2dd95SBruce Richardson 			struct rte_cryptodev_sym_session *sess,
106099a2dd95SBruce Richardson 			struct rte_crypto_sym_xform *xforms,
106199a2dd95SBruce Richardson 			struct rte_mempool *mempool);
106299a2dd95SBruce Richardson 
106399a2dd95SBruce Richardson /**
106499a2dd95SBruce Richardson  * Frees private data for the device id, based on its device type,
106599a2dd95SBruce Richardson  * returning it to its mempool. It is the application's responsibility
106699a2dd95SBruce Richardson  * to ensure that private session data is not cleared while there are
106799a2dd95SBruce Richardson  * still in-flight operations using it.
106899a2dd95SBruce Richardson  *
106999a2dd95SBruce Richardson  * @param   dev_id   ID of device that uses the session.
107099a2dd95SBruce Richardson  * @param   sess     Session containing the reference to the private data
107199a2dd95SBruce Richardson  *
107299a2dd95SBruce Richardson  * @return
107399a2dd95SBruce Richardson  *  - 0 if successful.
107499a2dd95SBruce Richardson  *  - -EINVAL if device is invalid or session is NULL.
107599a2dd95SBruce Richardson  *  - -ENOTSUP if crypto device does not support symmetric operations.
107699a2dd95SBruce Richardson  */
107799a2dd95SBruce Richardson int
107899a2dd95SBruce Richardson rte_cryptodev_sym_session_clear(uint8_t dev_id,
107999a2dd95SBruce Richardson 			struct rte_cryptodev_sym_session *sess);
108099a2dd95SBruce Richardson 
108199a2dd95SBruce Richardson /**
108299a2dd95SBruce Richardson  * Get the size of the header session, for all registered drivers excluding
108399a2dd95SBruce Richardson  * the user data size.
108499a2dd95SBruce Richardson  *
108599a2dd95SBruce Richardson  * @return
108699a2dd95SBruce Richardson  *   Size of the symmetric header session.
108799a2dd95SBruce Richardson  */
108899a2dd95SBruce Richardson unsigned int
108999a2dd95SBruce Richardson rte_cryptodev_sym_get_header_session_size(void);
109099a2dd95SBruce Richardson 
109199a2dd95SBruce Richardson /**
109299a2dd95SBruce Richardson  * Get the size of the header session from created session.
109399a2dd95SBruce Richardson  *
109499a2dd95SBruce Richardson  * @param sess
109599a2dd95SBruce Richardson  *   The sym cryptodev session pointer
109699a2dd95SBruce Richardson  *
109799a2dd95SBruce Richardson  * @return
109899a2dd95SBruce Richardson  *   - If sess is not NULL, return the size of the header session including
109999a2dd95SBruce Richardson  *   the private data size defined within sess.
110099a2dd95SBruce Richardson  *   - If sess is NULL, return 0.
110199a2dd95SBruce Richardson  */
110299a2dd95SBruce Richardson __rte_experimental
110399a2dd95SBruce Richardson unsigned int
110499a2dd95SBruce Richardson rte_cryptodev_sym_get_existing_header_session_size(
110599a2dd95SBruce Richardson 		struct rte_cryptodev_sym_session *sess);
110699a2dd95SBruce Richardson 
110799a2dd95SBruce Richardson /**
11081f1e4b7cSCiara Power  * Get the size of the asymmetric session header.
110999a2dd95SBruce Richardson  *
111099a2dd95SBruce Richardson  * @return
111199a2dd95SBruce Richardson  *   Size of the asymmetric header session.
111299a2dd95SBruce Richardson  */
111399a2dd95SBruce Richardson __rte_experimental
111499a2dd95SBruce Richardson unsigned int
111599a2dd95SBruce Richardson rte_cryptodev_asym_get_header_session_size(void);
111699a2dd95SBruce Richardson 
111799a2dd95SBruce Richardson /**
111899a2dd95SBruce Richardson  * Get the size of the private symmetric session data
111999a2dd95SBruce Richardson  * for a device.
112099a2dd95SBruce Richardson  *
112199a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
112299a2dd95SBruce Richardson  *
112399a2dd95SBruce Richardson  * @return
112499a2dd95SBruce Richardson  *   - Size of the private data, if successful
112599a2dd95SBruce Richardson  *   - 0 if device is invalid or does not have private
112699a2dd95SBruce Richardson  *   symmetric session
112799a2dd95SBruce Richardson  */
112899a2dd95SBruce Richardson unsigned int
112999a2dd95SBruce Richardson rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
113099a2dd95SBruce Richardson 
113199a2dd95SBruce Richardson /**
113299a2dd95SBruce Richardson  * Get the size of the private data for asymmetric session
113399a2dd95SBruce Richardson  * on device
113499a2dd95SBruce Richardson  *
113599a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
113699a2dd95SBruce Richardson  *
113799a2dd95SBruce Richardson  * @return
113899a2dd95SBruce Richardson  *   - Size of the asymmetric private data, if successful
113999a2dd95SBruce Richardson  *   - 0 if device is invalid or does not have private session
114099a2dd95SBruce Richardson  */
114199a2dd95SBruce Richardson __rte_experimental
114299a2dd95SBruce Richardson unsigned int
114399a2dd95SBruce Richardson rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
114499a2dd95SBruce Richardson 
114599a2dd95SBruce Richardson /**
1146e74abd48SAkhil Goyal  * Validate if the crypto device index is valid attached crypto device.
1147e74abd48SAkhil Goyal  *
1148e74abd48SAkhil Goyal  * @param	dev_id	Crypto device index.
1149e74abd48SAkhil Goyal  *
1150e74abd48SAkhil Goyal  * @return
1151e74abd48SAkhil Goyal  *   - If the device index is valid (1) or not (0).
1152e74abd48SAkhil Goyal  */
1153e74abd48SAkhil Goyal unsigned int
1154e74abd48SAkhil Goyal rte_cryptodev_is_valid_dev(uint8_t dev_id);
1155e74abd48SAkhil Goyal 
1156e74abd48SAkhil Goyal /**
115799a2dd95SBruce Richardson  * Provide driver identifier.
115899a2dd95SBruce Richardson  *
115999a2dd95SBruce Richardson  * @param name
116099a2dd95SBruce Richardson  *   The pointer to a driver name.
116199a2dd95SBruce Richardson  * @return
116299a2dd95SBruce Richardson  *  The driver type identifier or -1 if no driver found
116399a2dd95SBruce Richardson  */
116499a2dd95SBruce Richardson int rte_cryptodev_driver_id_get(const char *name);
116599a2dd95SBruce Richardson 
116699a2dd95SBruce Richardson /**
116799a2dd95SBruce Richardson  * Provide driver name.
116899a2dd95SBruce Richardson  *
116999a2dd95SBruce Richardson  * @param driver_id
117099a2dd95SBruce Richardson  *   The driver identifier.
117199a2dd95SBruce Richardson  * @return
117299a2dd95SBruce Richardson  *  The driver name or null if no driver found
117399a2dd95SBruce Richardson  */
117499a2dd95SBruce Richardson const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
117599a2dd95SBruce Richardson 
117699a2dd95SBruce Richardson /**
117799a2dd95SBruce Richardson  * Store user data in a session.
117899a2dd95SBruce Richardson  *
117999a2dd95SBruce Richardson  * @param	sess		Session pointer allocated by
118099a2dd95SBruce Richardson  *				*rte_cryptodev_sym_session_create*.
118199a2dd95SBruce Richardson  * @param	data		Pointer to the user data.
118299a2dd95SBruce Richardson  * @param	size		Size of the user data.
118399a2dd95SBruce Richardson  *
118499a2dd95SBruce Richardson  * @return
118599a2dd95SBruce Richardson  *  - On success, zero.
118699a2dd95SBruce Richardson  *  - On failure, a negative value.
118799a2dd95SBruce Richardson  */
118899a2dd95SBruce Richardson __rte_experimental
118999a2dd95SBruce Richardson int
119099a2dd95SBruce Richardson rte_cryptodev_sym_session_set_user_data(
119199a2dd95SBruce Richardson 					struct rte_cryptodev_sym_session *sess,
119299a2dd95SBruce Richardson 					void *data,
119399a2dd95SBruce Richardson 					uint16_t size);
119499a2dd95SBruce Richardson 
119599a2dd95SBruce Richardson /**
119699a2dd95SBruce Richardson  * Get user data stored in a session.
119799a2dd95SBruce Richardson  *
119899a2dd95SBruce Richardson  * @param	sess		Session pointer allocated by
119999a2dd95SBruce Richardson  *				*rte_cryptodev_sym_session_create*.
120099a2dd95SBruce Richardson  *
120199a2dd95SBruce Richardson  * @return
120299a2dd95SBruce Richardson  *  - On success return pointer to user data.
120399a2dd95SBruce Richardson  *  - On failure returns NULL.
120499a2dd95SBruce Richardson  */
120599a2dd95SBruce Richardson __rte_experimental
120699a2dd95SBruce Richardson void *
120799a2dd95SBruce Richardson rte_cryptodev_sym_session_get_user_data(
120899a2dd95SBruce Richardson 					struct rte_cryptodev_sym_session *sess);
120999a2dd95SBruce Richardson 
121099a2dd95SBruce Richardson /**
121192d55afeSCiara Power  * Store user data in an asymmetric session.
121292d55afeSCiara Power  *
121392d55afeSCiara Power  * @param	sess		Session pointer allocated by
121492d55afeSCiara Power  *				*rte_cryptodev_asym_session_create*.
121592d55afeSCiara Power  * @param	data		Pointer to the user data.
121692d55afeSCiara Power  * @param	size		Size of the user data.
121792d55afeSCiara Power  *
121892d55afeSCiara Power  * @return
121992d55afeSCiara Power  *  - On success, zero.
122092d55afeSCiara Power  *  - -EINVAL if the session pointer is invalid.
122192d55afeSCiara Power  *  - -ENOMEM if the available user data size is smaller than the size parameter.
122292d55afeSCiara Power  */
122392d55afeSCiara Power __rte_experimental
122492d55afeSCiara Power int
122592d55afeSCiara Power rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
122692d55afeSCiara Power 
122792d55afeSCiara Power /**
122892d55afeSCiara Power  * Get user data stored in an asymmetric session.
122992d55afeSCiara Power  *
123092d55afeSCiara Power  * @param	sess		Session pointer allocated by
123192d55afeSCiara Power  *				*rte_cryptodev_asym_session_create*.
123292d55afeSCiara Power  *
123392d55afeSCiara Power  * @return
123492d55afeSCiara Power  *  - On success return pointer to user data.
123592d55afeSCiara Power  *  - On failure returns NULL.
123692d55afeSCiara Power  */
123792d55afeSCiara Power __rte_experimental
123892d55afeSCiara Power void *
123992d55afeSCiara Power rte_cryptodev_asym_session_get_user_data(void *sess);
124092d55afeSCiara Power 
124192d55afeSCiara Power /**
124299a2dd95SBruce Richardson  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
124399a2dd95SBruce Richardson  * on user provided data.
124499a2dd95SBruce Richardson  *
124599a2dd95SBruce Richardson  * @param	dev_id	The device identifier.
124699a2dd95SBruce Richardson  * @param	sess	Cryptodev session structure
124799a2dd95SBruce Richardson  * @param	ofs	Start and stop offsets for auth and cipher operations
124899a2dd95SBruce Richardson  * @param	vec	Vectorized operation descriptor
124999a2dd95SBruce Richardson  *
125099a2dd95SBruce Richardson  * @return
125199a2dd95SBruce Richardson  *  - Returns number of successfully processed packets.
125299a2dd95SBruce Richardson  */
125399a2dd95SBruce Richardson __rte_experimental
125499a2dd95SBruce Richardson uint32_t
125599a2dd95SBruce Richardson rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
125699a2dd95SBruce Richardson 	struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
125799a2dd95SBruce Richardson 	struct rte_crypto_sym_vec *vec);
125899a2dd95SBruce Richardson 
125999a2dd95SBruce Richardson /**
126099a2dd95SBruce Richardson  * Get the size of the raw data-path context buffer.
126199a2dd95SBruce Richardson  *
126299a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
126399a2dd95SBruce Richardson  *
126499a2dd95SBruce Richardson  * @return
126599a2dd95SBruce Richardson  *   - If the device supports raw data-path APIs, return the context size.
126699a2dd95SBruce Richardson  *   - If the device does not support the APIs, return -1.
126799a2dd95SBruce Richardson  */
126899a2dd95SBruce Richardson __rte_experimental
126999a2dd95SBruce Richardson int
127099a2dd95SBruce Richardson rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id);
127199a2dd95SBruce Richardson 
127299a2dd95SBruce Richardson /**
127399a2dd95SBruce Richardson  * Union of different crypto session types, including session-less xform
127499a2dd95SBruce Richardson  * pointer.
127599a2dd95SBruce Richardson  */
127699a2dd95SBruce Richardson union rte_cryptodev_session_ctx {
127799a2dd95SBruce Richardson 	struct rte_cryptodev_sym_session *crypto_sess;
127899a2dd95SBruce Richardson 	struct rte_crypto_sym_xform *xform;
127999a2dd95SBruce Richardson 	struct rte_security_session *sec_sess;
128099a2dd95SBruce Richardson };
128199a2dd95SBruce Richardson 
128299a2dd95SBruce Richardson /**
128399a2dd95SBruce Richardson  * Enqueue a vectorized operation descriptor into the device queue but the
128499a2dd95SBruce Richardson  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
128599a2dd95SBruce Richardson  * is called.
128699a2dd95SBruce Richardson  *
128799a2dd95SBruce Richardson  * @param	qp		Driver specific queue pair data.
128899a2dd95SBruce Richardson  * @param	drv_ctx		Driver specific context data.
128999a2dd95SBruce Richardson  * @param	vec		Vectorized operation descriptor.
129099a2dd95SBruce Richardson  * @param	ofs		Start and stop offsets for auth and cipher
129199a2dd95SBruce Richardson  *				operations.
129299a2dd95SBruce Richardson  * @param	user_data	The array of user data for dequeue later.
129399a2dd95SBruce Richardson  * @param	enqueue_status	Driver written value to specify the
129499a2dd95SBruce Richardson  *				enqueue status. Possible values:
129599a2dd95SBruce Richardson  *				- 1: The number of operations returned are
129699a2dd95SBruce Richardson  *				     enqueued successfully.
129799a2dd95SBruce Richardson  *				- 0: The number of operations returned are
129899a2dd95SBruce Richardson  *				     cached into the queue but are not processed
129999a2dd95SBruce Richardson  *				     until rte_cryptodev_raw_enqueue_done() is
130099a2dd95SBruce Richardson  *				     called.
130199a2dd95SBruce Richardson  *				- negative integer: Error occurred.
130299a2dd95SBruce Richardson  * @return
130399a2dd95SBruce Richardson  *   - The number of operations in the descriptor successfully enqueued or
130499a2dd95SBruce Richardson  *     cached into the queue but not enqueued yet, depends on the
130599a2dd95SBruce Richardson  *     "enqueue_status" value.
130699a2dd95SBruce Richardson  */
130799a2dd95SBruce Richardson typedef uint32_t (*cryptodev_sym_raw_enqueue_burst_t)(
130899a2dd95SBruce Richardson 	void *qp, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
130999a2dd95SBruce Richardson 	union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status);
131099a2dd95SBruce Richardson 
131199a2dd95SBruce Richardson /**
131299a2dd95SBruce Richardson  * Enqueue single raw data vector into the device queue but the driver may or
131399a2dd95SBruce Richardson  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
131499a2dd95SBruce Richardson  *
131599a2dd95SBruce Richardson  * @param	qp		Driver specific queue pair data.
131699a2dd95SBruce Richardson  * @param	drv_ctx		Driver specific context data.
131799a2dd95SBruce Richardson  * @param	data_vec	The buffer data vector.
131899a2dd95SBruce Richardson  * @param	n_data_vecs	Number of buffer data vectors.
131999a2dd95SBruce Richardson  * @param	ofs		Start and stop offsets for auth and cipher
132099a2dd95SBruce Richardson  *				operations.
132199a2dd95SBruce Richardson  * @param	iv		IV virtual and IOVA addresses
132299a2dd95SBruce Richardson  * @param	digest		digest virtual and IOVA addresses
132399a2dd95SBruce Richardson  * @param	aad_or_auth_iv	AAD or auth IV virtual and IOVA addresses,
132499a2dd95SBruce Richardson  *				depends on the algorithm used.
132599a2dd95SBruce Richardson  * @param	user_data	The user data.
132699a2dd95SBruce Richardson  * @return
132799a2dd95SBruce Richardson  *   - 1: The data vector is enqueued successfully.
132899a2dd95SBruce Richardson  *   - 0: The data vector is cached into the queue but is not processed
132999a2dd95SBruce Richardson  *        until rte_cryptodev_raw_enqueue_done() is called.
133099a2dd95SBruce Richardson  *   - negative integer: failure.
133199a2dd95SBruce Richardson  */
133299a2dd95SBruce Richardson typedef int (*cryptodev_sym_raw_enqueue_t)(
133399a2dd95SBruce Richardson 	void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
133499a2dd95SBruce Richardson 	uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
133599a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *iv,
133699a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *digest,
133799a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
133899a2dd95SBruce Richardson 	void *user_data);
133999a2dd95SBruce Richardson 
134099a2dd95SBruce Richardson /**
134199a2dd95SBruce Richardson  * Inform the cryptodev queue pair to start processing or finish dequeuing all
134299a2dd95SBruce Richardson  * enqueued/dequeued operations.
134399a2dd95SBruce Richardson  *
134499a2dd95SBruce Richardson  * @param	qp		Driver specific queue pair data.
134599a2dd95SBruce Richardson  * @param	drv_ctx		Driver specific context data.
134699a2dd95SBruce Richardson  * @param	n		The total number of processed operations.
134799a2dd95SBruce Richardson  * @return
134899a2dd95SBruce Richardson  *   - On success return 0.
134999a2dd95SBruce Richardson  *   - On failure return negative integer.
135099a2dd95SBruce Richardson  */
135199a2dd95SBruce Richardson typedef int (*cryptodev_sym_raw_operation_done_t)(void *qp, uint8_t *drv_ctx,
135299a2dd95SBruce Richardson 	uint32_t n);
135399a2dd95SBruce Richardson 
135499a2dd95SBruce Richardson /**
135599a2dd95SBruce Richardson  * Typedef that the user provided for the driver to get the dequeue count.
135699a2dd95SBruce Richardson  * The function may return a fixed number or the number parsed from the user
135799a2dd95SBruce Richardson  * data stored in the first processed operation.
135899a2dd95SBruce Richardson  *
135999a2dd95SBruce Richardson  * @param	user_data	Dequeued user data.
136099a2dd95SBruce Richardson  * @return
136199a2dd95SBruce Richardson  *  - The number of operations to be dequeued.
136299a2dd95SBruce Richardson  **/
136399a2dd95SBruce Richardson typedef uint32_t (*rte_cryptodev_raw_get_dequeue_count_t)(void *user_data);
136499a2dd95SBruce Richardson 
136599a2dd95SBruce Richardson /**
136699a2dd95SBruce Richardson  * Typedef that the user provided to deal with post dequeue operation, such
136799a2dd95SBruce Richardson  * as filling status.
136899a2dd95SBruce Richardson  *
136999a2dd95SBruce Richardson  * @param	user_data	Dequeued user data.
137099a2dd95SBruce Richardson  * @param	index		Index number of the processed descriptor.
137199a2dd95SBruce Richardson  * @param	is_op_success	Operation status provided by the driver.
137299a2dd95SBruce Richardson  **/
137399a2dd95SBruce Richardson typedef void (*rte_cryptodev_raw_post_dequeue_t)(void *user_data,
137499a2dd95SBruce Richardson 	uint32_t index, uint8_t is_op_success);
137599a2dd95SBruce Richardson 
137699a2dd95SBruce Richardson /**
137799a2dd95SBruce Richardson  * Dequeue a burst of symmetric crypto processing.
137899a2dd95SBruce Richardson  *
137999a2dd95SBruce Richardson  * @param	qp			Driver specific queue pair data.
138099a2dd95SBruce Richardson  * @param	drv_ctx			Driver specific context data.
138199a2dd95SBruce Richardson  * @param	get_dequeue_count	User provided callback function to
138299a2dd95SBruce Richardson  *					obtain dequeue operation count.
138399a2dd95SBruce Richardson  * @param	max_nb_to_dequeue	When get_dequeue_count is NULL this
138499a2dd95SBruce Richardson  *					value is used to pass the maximum
138599a2dd95SBruce Richardson  *					number of operations to be dequeued.
138699a2dd95SBruce Richardson  * @param	post_dequeue		User provided callback function to
138799a2dd95SBruce Richardson  *					post-process a dequeued operation.
138899a2dd95SBruce Richardson  * @param	out_user_data		User data pointer array to be retrieve
138999a2dd95SBruce Richardson  *					from device queue. In case of
139099a2dd95SBruce Richardson  *					*is_user_data_array* is set there
139199a2dd95SBruce Richardson  *					should be enough room to store all
139299a2dd95SBruce Richardson  *					user data.
139399a2dd95SBruce Richardson  * @param	is_user_data_array	Set 1 if every dequeued user data will
139499a2dd95SBruce Richardson  *					be written into out_user_data array.
139599a2dd95SBruce Richardson  *					Set 0 if only the first user data will
139699a2dd95SBruce Richardson  *					be written into out_user_data array.
139799a2dd95SBruce Richardson  * @param	n_success		Driver written value to specific the
139899a2dd95SBruce Richardson  *					total successful operations count.
139999a2dd95SBruce Richardson  * @param	dequeue_status		Driver written value to specify the
140099a2dd95SBruce Richardson  *					dequeue status. Possible values:
140199a2dd95SBruce Richardson  *					- 1: Successfully dequeued the number
140299a2dd95SBruce Richardson  *					     of operations returned. The user
140399a2dd95SBruce Richardson  *					     data previously set during enqueue
140499a2dd95SBruce Richardson  *					     is stored in the "out_user_data".
140599a2dd95SBruce Richardson  *					- 0: The number of operations returned
140699a2dd95SBruce Richardson  *					     are completed and the user data is
140799a2dd95SBruce Richardson  *					     stored in the "out_user_data", but
140899a2dd95SBruce Richardson  *					     they are not freed from the queue
140999a2dd95SBruce Richardson  *					     until
141099a2dd95SBruce Richardson  *					     rte_cryptodev_raw_dequeue_done()
141199a2dd95SBruce Richardson  *					     is called.
141299a2dd95SBruce Richardson  *					- negative integer: Error occurred.
141399a2dd95SBruce Richardson  * @return
141499a2dd95SBruce Richardson  *   - The number of operations dequeued or completed but not freed from the
141599a2dd95SBruce Richardson  *     queue, depends on "dequeue_status" value.
141699a2dd95SBruce Richardson  */
141799a2dd95SBruce Richardson typedef uint32_t (*cryptodev_sym_raw_dequeue_burst_t)(void *qp,
141899a2dd95SBruce Richardson 	uint8_t *drv_ctx,
141999a2dd95SBruce Richardson 	rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
142099a2dd95SBruce Richardson 	uint32_t max_nb_to_dequeue,
142199a2dd95SBruce Richardson 	rte_cryptodev_raw_post_dequeue_t post_dequeue,
142299a2dd95SBruce Richardson 	void **out_user_data, uint8_t is_user_data_array,
142399a2dd95SBruce Richardson 	uint32_t *n_success, int *dequeue_status);
142499a2dd95SBruce Richardson 
142599a2dd95SBruce Richardson /**
142699a2dd95SBruce Richardson  * Dequeue a symmetric crypto processing.
142799a2dd95SBruce Richardson  *
142899a2dd95SBruce Richardson  * @param	qp			Driver specific queue pair data.
142999a2dd95SBruce Richardson  * @param	drv_ctx			Driver specific context data.
143099a2dd95SBruce Richardson  * @param	dequeue_status		Driver written value to specify the
143199a2dd95SBruce Richardson  *					dequeue status. Possible values:
143299a2dd95SBruce Richardson  *					- 1: Successfully dequeued a operation.
143399a2dd95SBruce Richardson  *					     The user data is returned.
143499a2dd95SBruce Richardson  *					- 0: The first operation in the queue
143599a2dd95SBruce Richardson  *					     is completed and the user data
143699a2dd95SBruce Richardson  *					     previously set during enqueue is
143799a2dd95SBruce Richardson  *					     returned, but it is not freed from
143899a2dd95SBruce Richardson  *					     the queue until
143999a2dd95SBruce Richardson  *					     rte_cryptodev_raw_dequeue_done() is
144099a2dd95SBruce Richardson  *					     called.
144199a2dd95SBruce Richardson  *					- negative integer: Error occurred.
144299a2dd95SBruce Richardson  * @param	op_status		Driver written value to specify
144399a2dd95SBruce Richardson  *					operation status.
144499a2dd95SBruce Richardson  * @return
144599a2dd95SBruce Richardson  *   - The user data pointer retrieved from device queue or NULL if no
144699a2dd95SBruce Richardson  *     operation is ready for dequeue.
144799a2dd95SBruce Richardson  */
144899a2dd95SBruce Richardson typedef void * (*cryptodev_sym_raw_dequeue_t)(
144999a2dd95SBruce Richardson 		void *qp, uint8_t *drv_ctx, int *dequeue_status,
145099a2dd95SBruce Richardson 		enum rte_crypto_op_status *op_status);
145199a2dd95SBruce Richardson 
145299a2dd95SBruce Richardson /**
145399a2dd95SBruce Richardson  * Context data for raw data-path API crypto process. The buffer of this
145499a2dd95SBruce Richardson  * structure is to be allocated by the user application with the size equal
145599a2dd95SBruce Richardson  * or bigger than rte_cryptodev_get_raw_dp_ctx_size() returned value.
145699a2dd95SBruce Richardson  */
145799a2dd95SBruce Richardson struct rte_crypto_raw_dp_ctx {
145899a2dd95SBruce Richardson 	void *qp_data;
145999a2dd95SBruce Richardson 
146099a2dd95SBruce Richardson 	cryptodev_sym_raw_enqueue_t enqueue;
146199a2dd95SBruce Richardson 	cryptodev_sym_raw_enqueue_burst_t enqueue_burst;
146299a2dd95SBruce Richardson 	cryptodev_sym_raw_operation_done_t enqueue_done;
146399a2dd95SBruce Richardson 	cryptodev_sym_raw_dequeue_t dequeue;
146499a2dd95SBruce Richardson 	cryptodev_sym_raw_dequeue_burst_t dequeue_burst;
146599a2dd95SBruce Richardson 	cryptodev_sym_raw_operation_done_t dequeue_done;
146699a2dd95SBruce Richardson 
146799a2dd95SBruce Richardson 	/* Driver specific context data */
146899a2dd95SBruce Richardson 	__extension__ uint8_t drv_ctx_data[];
146999a2dd95SBruce Richardson };
147099a2dd95SBruce Richardson 
147199a2dd95SBruce Richardson /**
147299a2dd95SBruce Richardson  * Configure raw data-path context data.
147399a2dd95SBruce Richardson  *
147499a2dd95SBruce Richardson  * NOTE:
147599a2dd95SBruce Richardson  * After the context data is configured, the user should call
147699a2dd95SBruce Richardson  * rte_cryptodev_raw_attach_session() before using it in
147799a2dd95SBruce Richardson  * rte_cryptodev_raw_enqueue/dequeue function call.
147899a2dd95SBruce Richardson  *
147999a2dd95SBruce Richardson  * @param	dev_id		The device identifier.
148099a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair from which to
148199a2dd95SBruce Richardson  *				retrieve processed packets. The value must be
148299a2dd95SBruce Richardson  *				in the range [0, nb_queue_pair - 1] previously
148399a2dd95SBruce Richardson  *				supplied to rte_cryptodev_configure().
148499a2dd95SBruce Richardson  * @param	ctx		The raw data-path context data.
148599a2dd95SBruce Richardson  * @param	sess_type	session type.
148699a2dd95SBruce Richardson  * @param	session_ctx	Session context data.
148799a2dd95SBruce Richardson  * @param	is_update	Set 0 if it is to initialize the ctx.
148899a2dd95SBruce Richardson  *				Set 1 if ctx is initialized and only to update
148999a2dd95SBruce Richardson  *				session context data.
149099a2dd95SBruce Richardson  * @return
149199a2dd95SBruce Richardson  *   - On success return 0.
149299a2dd95SBruce Richardson  *   - On failure return negative integer.
149399a2dd95SBruce Richardson  */
149499a2dd95SBruce Richardson __rte_experimental
149599a2dd95SBruce Richardson int
149699a2dd95SBruce Richardson rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
149799a2dd95SBruce Richardson 	struct rte_crypto_raw_dp_ctx *ctx,
149899a2dd95SBruce Richardson 	enum rte_crypto_op_sess_type sess_type,
149999a2dd95SBruce Richardson 	union rte_cryptodev_session_ctx session_ctx,
150099a2dd95SBruce Richardson 	uint8_t is_update);
150199a2dd95SBruce Richardson 
150299a2dd95SBruce Richardson /**
150399a2dd95SBruce Richardson  * Enqueue a vectorized operation descriptor into the device queue but the
150499a2dd95SBruce Richardson  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
150599a2dd95SBruce Richardson  * is called.
150699a2dd95SBruce Richardson  *
150799a2dd95SBruce Richardson  * @param	ctx		The initialized raw data-path context data.
150899a2dd95SBruce Richardson  * @param	vec		Vectorized operation descriptor.
150999a2dd95SBruce Richardson  * @param	ofs		Start and stop offsets for auth and cipher
151099a2dd95SBruce Richardson  *				operations.
151199a2dd95SBruce Richardson  * @param	user_data	The array of user data for dequeue later.
151299a2dd95SBruce Richardson  * @param	enqueue_status	Driver written value to specify the
151399a2dd95SBruce Richardson  *				enqueue status. Possible values:
151499a2dd95SBruce Richardson  *				- 1: The number of operations returned are
151599a2dd95SBruce Richardson  *				     enqueued successfully.
151699a2dd95SBruce Richardson  *				- 0: The number of operations returned are
151799a2dd95SBruce Richardson  *				     cached into the queue but are not processed
151899a2dd95SBruce Richardson  *				     until rte_cryptodev_raw_enqueue_done() is
151999a2dd95SBruce Richardson  *				     called.
152099a2dd95SBruce Richardson  *				- negative integer: Error occurred.
152199a2dd95SBruce Richardson  * @return
152299a2dd95SBruce Richardson  *   - The number of operations in the descriptor successfully enqueued or
152399a2dd95SBruce Richardson  *     cached into the queue but not enqueued yet, depends on the
152499a2dd95SBruce Richardson  *     "enqueue_status" value.
152599a2dd95SBruce Richardson  */
152699a2dd95SBruce Richardson __rte_experimental
152799a2dd95SBruce Richardson uint32_t
152899a2dd95SBruce Richardson rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
152999a2dd95SBruce Richardson 	struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
153099a2dd95SBruce Richardson 	void **user_data, int *enqueue_status);
153199a2dd95SBruce Richardson 
153299a2dd95SBruce Richardson /**
153399a2dd95SBruce Richardson  * Enqueue single raw data vector into the device queue but the driver may or
153499a2dd95SBruce Richardson  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
153599a2dd95SBruce Richardson  *
153699a2dd95SBruce Richardson  * @param	ctx		The initialized raw data-path context data.
153799a2dd95SBruce Richardson  * @param	data_vec	The buffer data vector.
153899a2dd95SBruce Richardson  * @param	n_data_vecs	Number of buffer data vectors.
153999a2dd95SBruce Richardson  * @param	ofs		Start and stop offsets for auth and cipher
154099a2dd95SBruce Richardson  *				operations.
154199a2dd95SBruce Richardson  * @param	iv		IV virtual and IOVA addresses
154299a2dd95SBruce Richardson  * @param	digest		digest virtual and IOVA addresses
154399a2dd95SBruce Richardson  * @param	aad_or_auth_iv	AAD or auth IV virtual and IOVA addresses,
154499a2dd95SBruce Richardson  *				depends on the algorithm used.
154599a2dd95SBruce Richardson  * @param	user_data	The user data.
154699a2dd95SBruce Richardson  * @return
154799a2dd95SBruce Richardson  *   - 1: The data vector is enqueued successfully.
154899a2dd95SBruce Richardson  *   - 0: The data vector is cached into the queue but is not processed
154999a2dd95SBruce Richardson  *        until rte_cryptodev_raw_enqueue_done() is called.
155099a2dd95SBruce Richardson  *   - negative integer: failure.
155199a2dd95SBruce Richardson  */
155299a2dd95SBruce Richardson __rte_experimental
155399a2dd95SBruce Richardson static __rte_always_inline int
rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx * ctx,struct rte_crypto_vec * data_vec,uint16_t n_data_vecs,union rte_crypto_sym_ofs ofs,struct rte_crypto_va_iova_ptr * iv,struct rte_crypto_va_iova_ptr * digest,struct rte_crypto_va_iova_ptr * aad_or_auth_iv,void * user_data)155499a2dd95SBruce Richardson rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx *ctx,
155599a2dd95SBruce Richardson 	struct rte_crypto_vec *data_vec, uint16_t n_data_vecs,
155699a2dd95SBruce Richardson 	union rte_crypto_sym_ofs ofs,
155799a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *iv,
155899a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *digest,
155999a2dd95SBruce Richardson 	struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
156099a2dd95SBruce Richardson 	void *user_data)
156199a2dd95SBruce Richardson {
156299a2dd95SBruce Richardson 	return (*ctx->enqueue)(ctx->qp_data, ctx->drv_ctx_data, data_vec,
156399a2dd95SBruce Richardson 		n_data_vecs, ofs, iv, digest, aad_or_auth_iv, user_data);
156499a2dd95SBruce Richardson }
156599a2dd95SBruce Richardson 
156699a2dd95SBruce Richardson /**
156799a2dd95SBruce Richardson  * Start processing all enqueued operations from last
156899a2dd95SBruce Richardson  * rte_cryptodev_configure_raw_dp_ctx() call.
156999a2dd95SBruce Richardson  *
157099a2dd95SBruce Richardson  * @param	ctx	The initialized raw data-path context data.
157199a2dd95SBruce Richardson  * @param	n	The number of operations cached.
157299a2dd95SBruce Richardson  * @return
157399a2dd95SBruce Richardson  *   - On success return 0.
157499a2dd95SBruce Richardson  *   - On failure return negative integer.
157599a2dd95SBruce Richardson  */
157699a2dd95SBruce Richardson __rte_experimental
157799a2dd95SBruce Richardson int
157899a2dd95SBruce Richardson rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
157999a2dd95SBruce Richardson 		uint32_t n);
158099a2dd95SBruce Richardson 
158199a2dd95SBruce Richardson /**
158299a2dd95SBruce Richardson  * Dequeue a burst of symmetric crypto processing.
158399a2dd95SBruce Richardson  *
158499a2dd95SBruce Richardson  * @param	ctx			The initialized raw data-path context
158599a2dd95SBruce Richardson  *					data.
158699a2dd95SBruce Richardson  * @param	get_dequeue_count	User provided callback function to
158799a2dd95SBruce Richardson  *					obtain dequeue operation count.
158899a2dd95SBruce Richardson  * @param	max_nb_to_dequeue	When get_dequeue_count is NULL this
158999a2dd95SBruce Richardson  *					value is used to pass the maximum
159099a2dd95SBruce Richardson  *					number of operations to be dequeued.
159199a2dd95SBruce Richardson  * @param	post_dequeue		User provided callback function to
159299a2dd95SBruce Richardson  *					post-process a dequeued operation.
159399a2dd95SBruce Richardson  * @param	out_user_data		User data pointer array to be retrieve
159499a2dd95SBruce Richardson  *					from device queue. In case of
159599a2dd95SBruce Richardson  *					*is_user_data_array* is set there
159699a2dd95SBruce Richardson  *					should be enough room to store all
159799a2dd95SBruce Richardson  *					user data.
159899a2dd95SBruce Richardson  * @param	is_user_data_array	Set 1 if every dequeued user data will
159999a2dd95SBruce Richardson  *					be written into out_user_data array.
160099a2dd95SBruce Richardson  *					Set 0 if only the first user data will
160199a2dd95SBruce Richardson  *					be written into out_user_data array.
160299a2dd95SBruce Richardson  * @param	n_success		Driver written value to specific the
160399a2dd95SBruce Richardson  *					total successful operations count.
160499a2dd95SBruce Richardson  * @param	dequeue_status		Driver written value to specify the
160599a2dd95SBruce Richardson  *					dequeue status. Possible values:
160699a2dd95SBruce Richardson  *					- 1: Successfully dequeued the number
160799a2dd95SBruce Richardson  *					     of operations returned. The user
160899a2dd95SBruce Richardson  *					     data previously set during enqueue
160999a2dd95SBruce Richardson  *					     is stored in the "out_user_data".
161099a2dd95SBruce Richardson  *					- 0: The number of operations returned
161199a2dd95SBruce Richardson  *					     are completed and the user data is
161299a2dd95SBruce Richardson  *					     stored in the "out_user_data", but
161399a2dd95SBruce Richardson  *					     they are not freed from the queue
161499a2dd95SBruce Richardson  *					     until
161599a2dd95SBruce Richardson  *					     rte_cryptodev_raw_dequeue_done()
161699a2dd95SBruce Richardson  *					     is called.
161799a2dd95SBruce Richardson  *					- negative integer: Error occurred.
161899a2dd95SBruce Richardson  * @return
161999a2dd95SBruce Richardson  *   - The number of operations dequeued or completed but not freed from the
162099a2dd95SBruce Richardson  *     queue, depends on "dequeue_status" value.
162199a2dd95SBruce Richardson  */
162299a2dd95SBruce Richardson __rte_experimental
162399a2dd95SBruce Richardson uint32_t
162499a2dd95SBruce Richardson rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
162599a2dd95SBruce Richardson 	rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
162699a2dd95SBruce Richardson 	uint32_t max_nb_to_dequeue,
162799a2dd95SBruce Richardson 	rte_cryptodev_raw_post_dequeue_t post_dequeue,
162899a2dd95SBruce Richardson 	void **out_user_data, uint8_t is_user_data_array,
162999a2dd95SBruce Richardson 	uint32_t *n_success, int *dequeue_status);
163099a2dd95SBruce Richardson 
163199a2dd95SBruce Richardson /**
163299a2dd95SBruce Richardson  * Dequeue a symmetric crypto processing.
163399a2dd95SBruce Richardson  *
163499a2dd95SBruce Richardson  * @param	ctx			The initialized raw data-path context
163599a2dd95SBruce Richardson  *					data.
163699a2dd95SBruce Richardson  * @param	dequeue_status		Driver written value to specify the
163799a2dd95SBruce Richardson  *					dequeue status. Possible values:
163899a2dd95SBruce Richardson  *					- 1: Successfully dequeued a operation.
163999a2dd95SBruce Richardson  *					     The user data is returned.
164099a2dd95SBruce Richardson  *					- 0: The first operation in the queue
164199a2dd95SBruce Richardson  *					     is completed and the user data
164299a2dd95SBruce Richardson  *					     previously set during enqueue is
164399a2dd95SBruce Richardson  *					     returned, but it is not freed from
164499a2dd95SBruce Richardson  *					     the queue until
164599a2dd95SBruce Richardson  *					     rte_cryptodev_raw_dequeue_done() is
164699a2dd95SBruce Richardson  *					     called.
164799a2dd95SBruce Richardson  *					- negative integer: Error occurred.
164899a2dd95SBruce Richardson  * @param	op_status		Driver written value to specify
164999a2dd95SBruce Richardson  *					operation status.
165099a2dd95SBruce Richardson  * @return
165199a2dd95SBruce Richardson  *   - The user data pointer retrieved from device queue or NULL if no
165299a2dd95SBruce Richardson  *     operation is ready for dequeue.
165399a2dd95SBruce Richardson  */
165499a2dd95SBruce Richardson __rte_experimental
165599a2dd95SBruce Richardson static __rte_always_inline void *
rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx * ctx,int * dequeue_status,enum rte_crypto_op_status * op_status)165699a2dd95SBruce Richardson rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx *ctx,
165799a2dd95SBruce Richardson 		int *dequeue_status, enum rte_crypto_op_status *op_status)
165899a2dd95SBruce Richardson {
165999a2dd95SBruce Richardson 	return (*ctx->dequeue)(ctx->qp_data, ctx->drv_ctx_data, dequeue_status,
166099a2dd95SBruce Richardson 			op_status);
166199a2dd95SBruce Richardson }
166299a2dd95SBruce Richardson 
166399a2dd95SBruce Richardson /**
166499a2dd95SBruce Richardson  * Inform the queue pair dequeue operations is finished.
166599a2dd95SBruce Richardson  *
166699a2dd95SBruce Richardson  * @param	ctx	The initialized raw data-path context data.
166799a2dd95SBruce Richardson  * @param	n	The number of operations.
166899a2dd95SBruce Richardson  * @return
166999a2dd95SBruce Richardson  *   - On success return 0.
167099a2dd95SBruce Richardson  *   - On failure return negative integer.
167199a2dd95SBruce Richardson  */
167299a2dd95SBruce Richardson __rte_experimental
167399a2dd95SBruce Richardson int
167499a2dd95SBruce Richardson rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
167599a2dd95SBruce Richardson 		uint32_t n);
167699a2dd95SBruce Richardson 
167799a2dd95SBruce Richardson /**
167899a2dd95SBruce Richardson  * Add a user callback for a given crypto device and queue pair which will be
167999a2dd95SBruce Richardson  * called on crypto ops enqueue.
168099a2dd95SBruce Richardson  *
168199a2dd95SBruce Richardson  * This API configures a function to be called for each burst of crypto ops
168299a2dd95SBruce Richardson  * received on a given crypto device queue pair. The return value is a pointer
168399a2dd95SBruce Richardson  * that can be used later to remove the callback using
168499a2dd95SBruce Richardson  * rte_cryptodev_remove_enq_callback().
168599a2dd95SBruce Richardson  *
168699a2dd95SBruce Richardson  * Callbacks registered by application would not survive
168799a2dd95SBruce Richardson  * rte_cryptodev_configure() as it reinitializes the callback list.
168899a2dd95SBruce Richardson  * It is user responsibility to remove all installed callbacks before
168999a2dd95SBruce Richardson  * calling rte_cryptodev_configure() to avoid possible memory leakage.
169099a2dd95SBruce Richardson  * Application is expected to call add API after rte_cryptodev_configure().
169199a2dd95SBruce Richardson  *
169299a2dd95SBruce Richardson  * Multiple functions can be registered per queue pair & they are called
169399a2dd95SBruce Richardson  * in the order they were added. The API does not restrict on maximum number
169499a2dd95SBruce Richardson  * of callbacks.
169599a2dd95SBruce Richardson  *
169699a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
169799a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
169899a2dd95SBruce Richardson  *				to be enqueued for processing. The value
169999a2dd95SBruce Richardson  *				must be in the range [0, nb_queue_pairs - 1]
170099a2dd95SBruce Richardson  *				previously supplied to
170199a2dd95SBruce Richardson  *				*rte_cryptodev_configure*.
170299a2dd95SBruce Richardson  * @param	cb_fn		The callback function
170399a2dd95SBruce Richardson  * @param	cb_arg		A generic pointer parameter which will be passed
170499a2dd95SBruce Richardson  *				to each invocation of the callback function on
170599a2dd95SBruce Richardson  *				this crypto device and queue pair.
170699a2dd95SBruce Richardson  *
170799a2dd95SBruce Richardson  * @return
170899a2dd95SBruce Richardson  *  - NULL on error & rte_errno will contain the error code.
170999a2dd95SBruce Richardson  *  - On success, a pointer value which can later be used to remove the
171099a2dd95SBruce Richardson  *    callback.
171199a2dd95SBruce Richardson  */
171299a2dd95SBruce Richardson 
171399a2dd95SBruce Richardson __rte_experimental
171499a2dd95SBruce Richardson struct rte_cryptodev_cb *
171599a2dd95SBruce Richardson rte_cryptodev_add_enq_callback(uint8_t dev_id,
171699a2dd95SBruce Richardson 			       uint16_t qp_id,
171799a2dd95SBruce Richardson 			       rte_cryptodev_callback_fn cb_fn,
171899a2dd95SBruce Richardson 			       void *cb_arg);
171999a2dd95SBruce Richardson 
172099a2dd95SBruce Richardson /**
172199a2dd95SBruce Richardson  * Remove a user callback function for given crypto device and queue pair.
172299a2dd95SBruce Richardson  *
172399a2dd95SBruce Richardson  * This function is used to remove enqueue callbacks that were added to a
172499a2dd95SBruce Richardson  * crypto device queue pair using rte_cryptodev_add_enq_callback().
172599a2dd95SBruce Richardson  *
172699a2dd95SBruce Richardson  *
172799a2dd95SBruce Richardson  *
172899a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
172999a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
173099a2dd95SBruce Richardson  *				to be enqueued. The value must be in the
173199a2dd95SBruce Richardson  *				range [0, nb_queue_pairs - 1] previously
173299a2dd95SBruce Richardson  *				supplied to *rte_cryptodev_configure*.
173399a2dd95SBruce Richardson  * @param	cb		Pointer to user supplied callback created via
173499a2dd95SBruce Richardson  *				rte_cryptodev_add_enq_callback().
173599a2dd95SBruce Richardson  *
173699a2dd95SBruce Richardson  * @return
173799a2dd95SBruce Richardson  *   -  0: Success. Callback was removed.
173899a2dd95SBruce Richardson  *   - <0: The dev_id or the qp_id is out of range, or the callback
173999a2dd95SBruce Richardson  *         is NULL or not found for the crypto device queue pair.
174099a2dd95SBruce Richardson  */
174199a2dd95SBruce Richardson 
174299a2dd95SBruce Richardson __rte_experimental
174399a2dd95SBruce Richardson int rte_cryptodev_remove_enq_callback(uint8_t dev_id,
174499a2dd95SBruce Richardson 				      uint16_t qp_id,
174599a2dd95SBruce Richardson 				      struct rte_cryptodev_cb *cb);
174699a2dd95SBruce Richardson 
174799a2dd95SBruce Richardson /**
174899a2dd95SBruce Richardson  * Add a user callback for a given crypto device and queue pair which will be
174999a2dd95SBruce Richardson  * called on crypto ops dequeue.
175099a2dd95SBruce Richardson  *
175199a2dd95SBruce Richardson  * This API configures a function to be called for each burst of crypto ops
175299a2dd95SBruce Richardson  * received on a given crypto device queue pair. The return value is a pointer
175399a2dd95SBruce Richardson  * that can be used later to remove the callback using
175499a2dd95SBruce Richardson  * rte_cryptodev_remove_deq_callback().
175599a2dd95SBruce Richardson  *
175699a2dd95SBruce Richardson  * Callbacks registered by application would not survive
175799a2dd95SBruce Richardson  * rte_cryptodev_configure() as it reinitializes the callback list.
175899a2dd95SBruce Richardson  * It is user responsibility to remove all installed callbacks before
175999a2dd95SBruce Richardson  * calling rte_cryptodev_configure() to avoid possible memory leakage.
176099a2dd95SBruce Richardson  * Application is expected to call add API after rte_cryptodev_configure().
176199a2dd95SBruce Richardson  *
176299a2dd95SBruce Richardson  * Multiple functions can be registered per queue pair & they are called
176399a2dd95SBruce Richardson  * in the order they were added. The API does not restrict on maximum number
176499a2dd95SBruce Richardson  * of callbacks.
176599a2dd95SBruce Richardson  *
176699a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
176799a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
176899a2dd95SBruce Richardson  *				to be dequeued. The value must be in the
176999a2dd95SBruce Richardson  *				range [0, nb_queue_pairs - 1] previously
177099a2dd95SBruce Richardson  *				supplied to *rte_cryptodev_configure*.
177199a2dd95SBruce Richardson  * @param	cb_fn		The callback function
177299a2dd95SBruce Richardson  * @param	cb_arg		A generic pointer parameter which will be passed
177399a2dd95SBruce Richardson  *				to each invocation of the callback function on
177499a2dd95SBruce Richardson  *				this crypto device and queue pair.
177599a2dd95SBruce Richardson  *
177699a2dd95SBruce Richardson  * @return
177799a2dd95SBruce Richardson  *   - NULL on error & rte_errno will contain the error code.
177899a2dd95SBruce Richardson  *   - On success, a pointer value which can later be used to remove the
177999a2dd95SBruce Richardson  *     callback.
178099a2dd95SBruce Richardson  */
178199a2dd95SBruce Richardson 
178299a2dd95SBruce Richardson __rte_experimental
178399a2dd95SBruce Richardson struct rte_cryptodev_cb *
178499a2dd95SBruce Richardson rte_cryptodev_add_deq_callback(uint8_t dev_id,
178599a2dd95SBruce Richardson 			       uint16_t qp_id,
178699a2dd95SBruce Richardson 			       rte_cryptodev_callback_fn cb_fn,
178799a2dd95SBruce Richardson 			       void *cb_arg);
178899a2dd95SBruce Richardson 
178999a2dd95SBruce Richardson /**
179099a2dd95SBruce Richardson  * Remove a user callback function for given crypto device and queue pair.
179199a2dd95SBruce Richardson  *
179299a2dd95SBruce Richardson  * This function is used to remove dequeue callbacks that were added to a
179399a2dd95SBruce Richardson  * crypto device queue pair using rte_cryptodev_add_deq_callback().
179499a2dd95SBruce Richardson  *
179599a2dd95SBruce Richardson  *
179699a2dd95SBruce Richardson  *
179799a2dd95SBruce Richardson  * @param	dev_id		The identifier of the device.
179899a2dd95SBruce Richardson  * @param	qp_id		The index of the queue pair on which ops are
179999a2dd95SBruce Richardson  *				to be dequeued. The value must be in the
180099a2dd95SBruce Richardson  *				range [0, nb_queue_pairs - 1] previously
180199a2dd95SBruce Richardson  *				supplied to *rte_cryptodev_configure*.
180299a2dd95SBruce Richardson  * @param	cb		Pointer to user supplied callback created via
180399a2dd95SBruce Richardson  *				rte_cryptodev_add_deq_callback().
180499a2dd95SBruce Richardson  *
180599a2dd95SBruce Richardson  * @return
180699a2dd95SBruce Richardson  *   -  0: Success. Callback was removed.
180799a2dd95SBruce Richardson  *   - <0: The dev_id or the qp_id is out of range, or the callback
180899a2dd95SBruce Richardson  *         is NULL or not found for the crypto device queue pair.
180999a2dd95SBruce Richardson  */
181099a2dd95SBruce Richardson __rte_experimental
181199a2dd95SBruce Richardson int rte_cryptodev_remove_deq_callback(uint8_t dev_id,
181299a2dd95SBruce Richardson 				      uint16_t qp_id,
181399a2dd95SBruce Richardson 				      struct rte_cryptodev_cb *cb);
181499a2dd95SBruce Richardson 
1815691e1f4dSAkhil Goyal #include <rte_cryptodev_core.h>
1816691e1f4dSAkhil Goyal /**
1817691e1f4dSAkhil Goyal  *
1818691e1f4dSAkhil Goyal  * Dequeue a burst of processed crypto operations from a queue on the crypto
1819691e1f4dSAkhil Goyal  * device. The dequeued operation are stored in *rte_crypto_op* structures
1820691e1f4dSAkhil Goyal  * whose pointers are supplied in the *ops* array.
1821691e1f4dSAkhil Goyal  *
1822691e1f4dSAkhil Goyal  * The rte_cryptodev_dequeue_burst() function returns the number of ops
1823691e1f4dSAkhil Goyal  * actually dequeued, which is the number of *rte_crypto_op* data structures
1824691e1f4dSAkhil Goyal  * effectively supplied into the *ops* array.
1825691e1f4dSAkhil Goyal  *
1826691e1f4dSAkhil Goyal  * A return value equal to *nb_ops* indicates that the queue contained
1827691e1f4dSAkhil Goyal  * at least *nb_ops* operations, and this is likely to signify that other
1828691e1f4dSAkhil Goyal  * processed operations remain in the devices output queue. Applications
1829691e1f4dSAkhil Goyal  * implementing a "retrieve as many processed operations as possible" policy
1830691e1f4dSAkhil Goyal  * can check this specific case and keep invoking the
1831691e1f4dSAkhil Goyal  * rte_cryptodev_dequeue_burst() function until a value less than
1832691e1f4dSAkhil Goyal  * *nb_ops* is returned.
1833691e1f4dSAkhil Goyal  *
1834691e1f4dSAkhil Goyal  * The rte_cryptodev_dequeue_burst() function does not provide any error
1835691e1f4dSAkhil Goyal  * notification to avoid the corresponding overhead.
1836691e1f4dSAkhil Goyal  *
1837691e1f4dSAkhil Goyal  * @param	dev_id		The symmetric crypto device identifier
1838691e1f4dSAkhil Goyal  * @param	qp_id		The index of the queue pair from which to
1839691e1f4dSAkhil Goyal  *				retrieve processed packets. The value must be
1840691e1f4dSAkhil Goyal  *				in the range [0, nb_queue_pair - 1] previously
1841691e1f4dSAkhil Goyal  *				supplied to rte_cryptodev_configure().
1842691e1f4dSAkhil Goyal  * @param	ops		The address of an array of pointers to
1843691e1f4dSAkhil Goyal  *				*rte_crypto_op* structures that must be
1844691e1f4dSAkhil Goyal  *				large enough to store *nb_ops* pointers in it.
1845691e1f4dSAkhil Goyal  * @param	nb_ops		The maximum number of operations to dequeue.
1846691e1f4dSAkhil Goyal  *
1847691e1f4dSAkhil Goyal  * @return
1848691e1f4dSAkhil Goyal  *   - The number of operations actually dequeued, which is the number
1849691e1f4dSAkhil Goyal  *   of pointers to *rte_crypto_op* structures effectively supplied to the
1850691e1f4dSAkhil Goyal  *   *ops* array.
1851691e1f4dSAkhil Goyal  */
1852691e1f4dSAkhil Goyal static inline uint16_t
rte_cryptodev_dequeue_burst(uint8_t dev_id,uint16_t qp_id,struct rte_crypto_op ** ops,uint16_t nb_ops)1853691e1f4dSAkhil Goyal rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1854691e1f4dSAkhil Goyal 		struct rte_crypto_op **ops, uint16_t nb_ops)
1855691e1f4dSAkhil Goyal {
1856f6849cdcSAkhil Goyal 	const struct rte_crypto_fp_ops *fp_ops;
1857f6849cdcSAkhil Goyal 	void *qp;
1858691e1f4dSAkhil Goyal 
1859691e1f4dSAkhil Goyal 	rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1860f6849cdcSAkhil Goyal 
1861f6849cdcSAkhil Goyal 	fp_ops = &rte_crypto_fp_ops[dev_id];
1862f6849cdcSAkhil Goyal 	qp = fp_ops->qp.data[qp_id];
1863f6849cdcSAkhil Goyal 
1864f6849cdcSAkhil Goyal 	nb_ops = fp_ops->dequeue_burst(qp, ops, nb_ops);
1865f6849cdcSAkhil Goyal 
1866691e1f4dSAkhil Goyal #ifdef RTE_CRYPTO_CALLBACKS
1867f6849cdcSAkhil Goyal 	if (unlikely(fp_ops->qp.deq_cb != NULL)) {
1868691e1f4dSAkhil Goyal 		struct rte_cryptodev_cb_rcu *list;
1869691e1f4dSAkhil Goyal 		struct rte_cryptodev_cb *cb;
1870691e1f4dSAkhil Goyal 
1871691e1f4dSAkhil Goyal 		/* __ATOMIC_RELEASE memory order was used when the
1872691e1f4dSAkhil Goyal 		 * call back was inserted into the list.
1873691e1f4dSAkhil Goyal 		 * Since there is a clear dependency between loading
1874691e1f4dSAkhil Goyal 		 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1875691e1f4dSAkhil Goyal 		 * not required.
1876691e1f4dSAkhil Goyal 		 */
1877f6849cdcSAkhil Goyal 		list = &fp_ops->qp.deq_cb[qp_id];
1878691e1f4dSAkhil Goyal 		rte_rcu_qsbr_thread_online(list->qsbr, 0);
1879691e1f4dSAkhil Goyal 		cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1880691e1f4dSAkhil Goyal 
1881691e1f4dSAkhil Goyal 		while (cb != NULL) {
1882691e1f4dSAkhil Goyal 			nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1883691e1f4dSAkhil Goyal 					cb->arg);
1884691e1f4dSAkhil Goyal 			cb = cb->next;
1885691e1f4dSAkhil Goyal 		};
1886691e1f4dSAkhil Goyal 
1887691e1f4dSAkhil Goyal 		rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1888691e1f4dSAkhil Goyal 	}
1889691e1f4dSAkhil Goyal #endif
1890691e1f4dSAkhil Goyal 	return nb_ops;
1891691e1f4dSAkhil Goyal }
1892691e1f4dSAkhil Goyal 
1893691e1f4dSAkhil Goyal /**
1894691e1f4dSAkhil Goyal  * Enqueue a burst of operations for processing on a crypto device.
1895691e1f4dSAkhil Goyal  *
1896691e1f4dSAkhil Goyal  * The rte_cryptodev_enqueue_burst() function is invoked to place
1897691e1f4dSAkhil Goyal  * crypto operations on the queue *qp_id* of the device designated by
1898691e1f4dSAkhil Goyal  * its *dev_id*.
1899691e1f4dSAkhil Goyal  *
1900691e1f4dSAkhil Goyal  * The *nb_ops* parameter is the number of operations to process which are
1901691e1f4dSAkhil Goyal  * supplied in the *ops* array of *rte_crypto_op* structures.
1902691e1f4dSAkhil Goyal  *
1903691e1f4dSAkhil Goyal  * The rte_cryptodev_enqueue_burst() function returns the number of
1904691e1f4dSAkhil Goyal  * operations it actually enqueued for processing. A return value equal to
1905691e1f4dSAkhil Goyal  * *nb_ops* means that all packets have been enqueued.
1906691e1f4dSAkhil Goyal  *
1907691e1f4dSAkhil Goyal  * @param	dev_id		The identifier of the device.
1908691e1f4dSAkhil Goyal  * @param	qp_id		The index of the queue pair which packets are
1909691e1f4dSAkhil Goyal  *				to be enqueued for processing. The value
1910691e1f4dSAkhil Goyal  *				must be in the range [0, nb_queue_pairs - 1]
1911691e1f4dSAkhil Goyal  *				previously supplied to
1912691e1f4dSAkhil Goyal  *				 *rte_cryptodev_configure*.
1913691e1f4dSAkhil Goyal  * @param	ops		The address of an array of *nb_ops* pointers
1914691e1f4dSAkhil Goyal  *				to *rte_crypto_op* structures which contain
1915691e1f4dSAkhil Goyal  *				the crypto operations to be processed.
1916691e1f4dSAkhil Goyal  * @param	nb_ops		The number of operations to process.
1917691e1f4dSAkhil Goyal  *
1918691e1f4dSAkhil Goyal  * @return
1919691e1f4dSAkhil Goyal  * The number of operations actually enqueued on the crypto device. The return
1920691e1f4dSAkhil Goyal  * value can be less than the value of the *nb_ops* parameter when the
1921691e1f4dSAkhil Goyal  * crypto devices queue is full or if invalid parameters are specified in
1922691e1f4dSAkhil Goyal  * a *rte_crypto_op*.
1923691e1f4dSAkhil Goyal  */
1924691e1f4dSAkhil Goyal static inline uint16_t
rte_cryptodev_enqueue_burst(uint8_t dev_id,uint16_t qp_id,struct rte_crypto_op ** ops,uint16_t nb_ops)1925691e1f4dSAkhil Goyal rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
1926691e1f4dSAkhil Goyal 		struct rte_crypto_op **ops, uint16_t nb_ops)
1927691e1f4dSAkhil Goyal {
1928f6849cdcSAkhil Goyal 	const struct rte_crypto_fp_ops *fp_ops;
1929f6849cdcSAkhil Goyal 	void *qp;
1930691e1f4dSAkhil Goyal 
1931f6849cdcSAkhil Goyal 	fp_ops = &rte_crypto_fp_ops[dev_id];
1932f6849cdcSAkhil Goyal 	qp = fp_ops->qp.data[qp_id];
1933691e1f4dSAkhil Goyal #ifdef RTE_CRYPTO_CALLBACKS
1934f6849cdcSAkhil Goyal 	if (unlikely(fp_ops->qp.enq_cb != NULL)) {
1935691e1f4dSAkhil Goyal 		struct rte_cryptodev_cb_rcu *list;
1936691e1f4dSAkhil Goyal 		struct rte_cryptodev_cb *cb;
1937691e1f4dSAkhil Goyal 
1938691e1f4dSAkhil Goyal 		/* __ATOMIC_RELEASE memory order was used when the
1939691e1f4dSAkhil Goyal 		 * call back was inserted into the list.
1940691e1f4dSAkhil Goyal 		 * Since there is a clear dependency between loading
1941691e1f4dSAkhil Goyal 		 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1942691e1f4dSAkhil Goyal 		 * not required.
1943691e1f4dSAkhil Goyal 		 */
1944f6849cdcSAkhil Goyal 		list = &fp_ops->qp.enq_cb[qp_id];
1945691e1f4dSAkhil Goyal 		rte_rcu_qsbr_thread_online(list->qsbr, 0);
1946691e1f4dSAkhil Goyal 		cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1947691e1f4dSAkhil Goyal 
1948691e1f4dSAkhil Goyal 		while (cb != NULL) {
1949691e1f4dSAkhil Goyal 			nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1950691e1f4dSAkhil Goyal 					cb->arg);
1951691e1f4dSAkhil Goyal 			cb = cb->next;
1952691e1f4dSAkhil Goyal 		};
1953691e1f4dSAkhil Goyal 
1954691e1f4dSAkhil Goyal 		rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1955691e1f4dSAkhil Goyal 	}
1956691e1f4dSAkhil Goyal #endif
1957691e1f4dSAkhil Goyal 
1958691e1f4dSAkhil Goyal 	rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1959f6849cdcSAkhil Goyal 	return fp_ops->enqueue_burst(qp, ops, nb_ops);
1960691e1f4dSAkhil Goyal }
1961691e1f4dSAkhil Goyal 
1962691e1f4dSAkhil Goyal 
1963691e1f4dSAkhil Goyal 
196499a2dd95SBruce Richardson #ifdef __cplusplus
196599a2dd95SBruce Richardson }
196699a2dd95SBruce Richardson #endif
196799a2dd95SBruce Richardson 
196899a2dd95SBruce Richardson #endif /* _RTE_CRYPTODEV_H_ */
1969