xref: /dpdk/lib/cryptodev/rte_cryptodev.h (revision 5686b573e4bb23c49aed23f09e66fd23cf603bdb)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation.
3  */
4 
5 #ifndef _RTE_CRYPTODEV_H_
6 #define _RTE_CRYPTODEV_H_
7 
8 /**
9  * @file rte_cryptodev.h
10  *
11  * RTE Cryptographic Device APIs
12  *
13  * Defines RTE Crypto Device APIs for the provisioning of cipher and
14  * authentication operations.
15  */
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <rte_compat.h>
22 #include "rte_kvargs.h"
23 #include "rte_crypto.h"
24 #include <rte_common.h>
25 #include <rte_rcu_qsbr.h>
26 
27 #include "rte_cryptodev_trace_fp.h"
28 
29 extern const char **rte_cyptodev_names;
30 
31 /* Logging Macros */
32 
33 #define CDEV_LOG_ERR(...) \
34 	RTE_LOG(ERR, CRYPTODEV, \
35 		RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
36 			__func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
37 
38 #define CDEV_LOG_INFO(...) \
39 	RTE_LOG(INFO, CRYPTODEV, \
40 		RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
41 			RTE_FMT_TAIL(__VA_ARGS__,)))
42 
43 #define CDEV_LOG_DEBUG(...) \
44 	RTE_LOG(DEBUG, CRYPTODEV, \
45 		RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
46 			__func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
47 
48 #define CDEV_PMD_TRACE(...) \
49 	RTE_LOG(DEBUG, CRYPTODEV, \
50 		RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
51 			dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
52 
53 /**
54  * A macro that points to an offset from the start
55  * of the crypto operation structure (rte_crypto_op)
56  *
57  * The returned pointer is cast to type t.
58  *
59  * @param c
60  *   The crypto operation.
61  * @param o
62  *   The offset from the start of the crypto operation.
63  * @param t
64  *   The type to cast the result into.
65  */
66 #define rte_crypto_op_ctod_offset(c, t, o)	\
67 	((t)((char *)(c) + (o)))
68 
69 /**
70  * A macro that returns the physical address that points
71  * to an offset from the start of the crypto operation
72  * (rte_crypto_op)
73  *
74  * @param c
75  *   The crypto operation.
76  * @param o
77  *   The offset from the start of the crypto operation
78  *   to calculate address from.
79  */
80 #define rte_crypto_op_ctophys_offset(c, o)	\
81 	(rte_iova_t)((c)->phys_addr + (o))
82 
83 /**
84  * Crypto parameters range description
85  */
86 struct rte_crypto_param_range {
87 	uint16_t min;	/**< minimum size */
88 	uint16_t max;	/**< maximum size */
89 	uint16_t increment;
90 	/**< if a range of sizes are supported,
91 	 * this parameter is used to indicate
92 	 * increments in byte size that are supported
93 	 * between the minimum and maximum
94 	 */
95 };
96 
97 /**
98  * Data-unit supported lengths of cipher algorithms.
99  * A bit can represent any set of data-unit sizes
100  * (single size, multiple size, range, etc).
101  */
102 #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_512_BYTES             RTE_BIT32(0)
103 #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_4096_BYTES            RTE_BIT32(1)
104 #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_1_MEGABYTES           RTE_BIT32(2)
105 
106 /**
107  * Symmetric Crypto Capability
108  */
109 struct rte_cryptodev_symmetric_capability {
110 	enum rte_crypto_sym_xform_type xform_type;
111 	/**< Transform type : Authentication / Cipher / AEAD */
112 	union {
113 		struct {
114 			enum rte_crypto_auth_algorithm algo;
115 			/**< authentication algorithm */
116 			uint16_t block_size;
117 			/**< algorithm block size */
118 			struct rte_crypto_param_range key_size;
119 			/**< auth key size range */
120 			struct rte_crypto_param_range digest_size;
121 			/**< digest size range */
122 			struct rte_crypto_param_range aad_size;
123 			/**< Additional authentication data size range */
124 			struct rte_crypto_param_range iv_size;
125 			/**< Initialisation vector data size range */
126 		} auth;
127 		/**< Symmetric Authentication transform capabilities */
128 		struct {
129 			enum rte_crypto_cipher_algorithm algo;
130 			/**< cipher algorithm */
131 			uint16_t block_size;
132 			/**< algorithm block size */
133 			struct rte_crypto_param_range key_size;
134 			/**< cipher key size range */
135 			struct rte_crypto_param_range iv_size;
136 			/**< Initialisation vector data size range */
137 			uint32_t dataunit_set;
138 			/**<
139 			 * Supported data-unit lengths:
140 			 * RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_* bits
141 			 * or 0 for lengths defined in the algorithm standard.
142 			 */
143 		} cipher;
144 		/**< Symmetric Cipher transform capabilities */
145 		struct {
146 			enum rte_crypto_aead_algorithm algo;
147 			/**< AEAD algorithm */
148 			uint16_t block_size;
149 			/**< algorithm block size */
150 			struct rte_crypto_param_range key_size;
151 			/**< AEAD key size range */
152 			struct rte_crypto_param_range digest_size;
153 			/**< digest size range */
154 			struct rte_crypto_param_range aad_size;
155 			/**< Additional authentication data size range */
156 			struct rte_crypto_param_range iv_size;
157 			/**< Initialisation vector data size range */
158 		} aead;
159 	};
160 };
161 
162 /**
163  * Asymmetric Xform Crypto Capability
164  */
165 struct rte_cryptodev_asymmetric_xform_capability {
166 	enum rte_crypto_asym_xform_type xform_type;
167 	/**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
168 
169 	uint32_t op_types;
170 	/**<
171 	 * Bitmask for supported rte_crypto_asym_op_type or
172 	 * rte_crypto_asym_ke_type. Which enum is used is determined
173 	 * by the rte_crypto_asym_xform_type. For key exchange algorithms
174 	 * like Diffie-Hellman it is rte_crypto_asym_ke_type, for others
175 	 * it is rte_crypto_asym_op_type.
176 	 */
177 
178 	__extension__
179 	union {
180 		struct rte_crypto_param_range modlen;
181 		/**< Range of modulus length supported by modulus based xform.
182 		 * Value 0 mean implementation default
183 		 */
184 
185 		uint8_t internal_rng;
186 		/**< Availability of random number generator for Elliptic curve based xform.
187 		 * Value 0 means unavailable, and application should pass the required
188 		 * random value. Otherwise, PMD would internally compute the random number.
189 		 */
190 	};
191 
192 	uint64_t hash_algos;
193 	/**< Bitmask of hash algorithms supported for op_type. */
194 };
195 
196 /**
197  * Asymmetric Crypto Capability
198  */
199 struct rte_cryptodev_asymmetric_capability {
200 	struct rte_cryptodev_asymmetric_xform_capability xform_capa;
201 };
202 
203 
204 /** Structure used to capture a capability of a crypto device */
205 struct rte_cryptodev_capabilities {
206 	enum rte_crypto_op_type op;
207 	/**< Operation type */
208 
209 	union {
210 		struct rte_cryptodev_symmetric_capability sym;
211 		/**< Symmetric operation capability parameters */
212 		struct rte_cryptodev_asymmetric_capability asym;
213 		/**< Asymmetric operation capability parameters */
214 	};
215 };
216 
217 /** Structure used to describe crypto algorithms */
218 struct rte_cryptodev_sym_capability_idx {
219 	enum rte_crypto_sym_xform_type type;
220 	union {
221 		enum rte_crypto_cipher_algorithm cipher;
222 		enum rte_crypto_auth_algorithm auth;
223 		enum rte_crypto_aead_algorithm aead;
224 	} algo;
225 };
226 
227 /**
228  * Structure used to describe asymmetric crypto xforms
229  * Each xform maps to one asym algorithm.
230  */
231 struct rte_cryptodev_asym_capability_idx {
232 	enum rte_crypto_asym_xform_type type;
233 	/**< Asymmetric xform (algo) type */
234 };
235 
236 /**
237  * Provide capabilities available for defined device and algorithm
238  *
239  * @param	dev_id		The identifier of the device.
240  * @param	idx		Description of crypto algorithms.
241  *
242  * @return
243  *   - Return description of the symmetric crypto capability if exist.
244  *   - Return NULL if the capability not exist.
245  */
246 const struct rte_cryptodev_symmetric_capability *
247 rte_cryptodev_sym_capability_get(uint8_t dev_id,
248 		const struct rte_cryptodev_sym_capability_idx *idx);
249 
250 /**
251  *  Provide capabilities available for defined device and xform
252  *
253  * @param	dev_id		The identifier of the device.
254  * @param	idx		Description of asym crypto xform.
255  *
256  * @return
257  *   - Return description of the asymmetric crypto capability if exist.
258  *   - Return NULL if the capability not exist.
259  */
260 __rte_experimental
261 const struct rte_cryptodev_asymmetric_xform_capability *
262 rte_cryptodev_asym_capability_get(uint8_t dev_id,
263 		const struct rte_cryptodev_asym_capability_idx *idx);
264 
265 /**
266  * Check if key size and initial vector are supported
267  * in crypto cipher capability
268  *
269  * @param	capability	Description of the symmetric crypto capability.
270  * @param	key_size	Cipher key size.
271  * @param	iv_size		Cipher initial vector size.
272  *
273  * @return
274  *   - Return 0 if the parameters are in range of the capability.
275  *   - Return -1 if the parameters are out of range of the capability.
276  */
277 int
278 rte_cryptodev_sym_capability_check_cipher(
279 		const struct rte_cryptodev_symmetric_capability *capability,
280 		uint16_t key_size, uint16_t iv_size);
281 
282 /**
283  * Check if key size and initial vector are supported
284  * in crypto auth capability
285  *
286  * @param	capability	Description of the symmetric crypto capability.
287  * @param	key_size	Auth key size.
288  * @param	digest_size	Auth digest size.
289  * @param	iv_size		Auth initial vector size.
290  *
291  * @return
292  *   - Return 0 if the parameters are in range of the capability.
293  *   - Return -1 if the parameters are out of range of the capability.
294  */
295 int
296 rte_cryptodev_sym_capability_check_auth(
297 		const struct rte_cryptodev_symmetric_capability *capability,
298 		uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
299 
300 /**
301  * Check if key, digest, AAD and initial vector sizes are supported
302  * in crypto AEAD capability
303  *
304  * @param	capability	Description of the symmetric crypto capability.
305  * @param	key_size	AEAD key size.
306  * @param	digest_size	AEAD digest size.
307  * @param	aad_size	AEAD AAD size.
308  * @param	iv_size		AEAD IV size.
309  *
310  * @return
311  *   - Return 0 if the parameters are in range of the capability.
312  *   - Return -1 if the parameters are out of range of the capability.
313  */
314 int
315 rte_cryptodev_sym_capability_check_aead(
316 		const struct rte_cryptodev_symmetric_capability *capability,
317 		uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
318 		uint16_t iv_size);
319 
320 /**
321  * Check if op type is supported
322  *
323  * @param	capability	Description of the asymmetric crypto capability.
324  * @param	op_type		op type
325  *
326  * @return
327  *   - Return 1 if the op type is supported
328  *   - Return 0 if unsupported
329  */
330 __rte_experimental
331 int
332 rte_cryptodev_asym_xform_capability_check_optype(
333 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
334 		enum rte_crypto_asym_op_type op_type);
335 
336 /**
337  * Check if modulus length is in supported range
338  *
339  * @param	capability	Description of the asymmetric crypto capability.
340  * @param	modlen		modulus length.
341  *
342  * @return
343  *   - Return 0 if the parameters are in range of the capability.
344  *   - Return -1 if the parameters are out of range of the capability.
345  */
346 __rte_experimental
347 int
348 rte_cryptodev_asym_xform_capability_check_modlen(
349 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
350 		uint16_t modlen);
351 
352 /**
353  * Check if hash algorithm is supported.
354  *
355  * @param	capability	Asymmetric crypto capability.
356  * @param	hash		Hash algorithm.
357  *
358  * @return
359  *   - Return true if the hash algorithm is supported.
360  *   - Return false if the hash algorithm is not supported.
361  */
362 __rte_experimental
363 bool
364 rte_cryptodev_asym_xform_capability_check_hash(
365 	const struct rte_cryptodev_asymmetric_xform_capability *capability,
366 	enum rte_crypto_auth_algorithm hash);
367 
368 /**
369  * Provide the cipher algorithm enum, given an algorithm string
370  *
371  * @param	algo_enum	A pointer to the cipher algorithm
372  *				enum to be filled
373  * @param	algo_string	Authentication algo string
374  *
375  * @return
376  * - Return -1 if string is not valid
377  * - Return 0 is the string is valid
378  */
379 int
380 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
381 		const char *algo_string);
382 
383 /**
384  * Provide the authentication algorithm enum, given an algorithm string
385  *
386  * @param	algo_enum	A pointer to the authentication algorithm
387  *				enum to be filled
388  * @param	algo_string	Authentication algo string
389  *
390  * @return
391  * - Return -1 if string is not valid
392  * - Return 0 is the string is valid
393  */
394 int
395 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
396 		const char *algo_string);
397 
398 /**
399  * Provide the AEAD algorithm enum, given an algorithm string
400  *
401  * @param	algo_enum	A pointer to the AEAD algorithm
402  *				enum to be filled
403  * @param	algo_string	AEAD algorithm string
404  *
405  * @return
406  * - Return -1 if string is not valid
407  * - Return 0 is the string is valid
408  */
409 int
410 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
411 		const char *algo_string);
412 
413 /**
414  * Provide the Asymmetric xform enum, given an xform string
415  *
416  * @param	xform_enum	A pointer to the xform type
417  *				enum to be filled
418  * @param	xform_string	xform string
419  *
420  * @return
421  * - Return -1 if string is not valid
422  * - Return 0 if the string is valid
423  */
424 __rte_experimental
425 int
426 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
427 		const char *xform_string);
428 
429 /**
430  * Provide the cipher algorithm string, given an algorithm enum.
431  *
432  * @param	algo_enum	cipher algorithm enum
433  *
434  * @return
435  * - Return NULL if enum is not valid
436  * - Return algo_string corresponding to enum
437  */
438 __rte_experimental
439 const char *
440 rte_cryptodev_get_cipher_algo_string(enum rte_crypto_cipher_algorithm algo_enum);
441 
442 /**
443  * Provide the authentication algorithm string, given an algorithm enum.
444  *
445  * @param	algo_enum	auth algorithm enum
446  *
447  * @return
448  * - Return NULL if enum is not valid
449  * - Return algo_string corresponding to enum
450  */
451 __rte_experimental
452 const char *
453 rte_cryptodev_get_auth_algo_string(enum rte_crypto_auth_algorithm algo_enum);
454 
455 /**
456  * Provide the AEAD algorithm string, given an algorithm enum.
457  *
458  * @param	algo_enum	AEAD algorithm enum
459  *
460  * @return
461  * - Return NULL if enum is not valid
462  * - Return algo_string corresponding to enum
463  */
464 __rte_experimental
465 const char *
466 rte_cryptodev_get_aead_algo_string(enum rte_crypto_aead_algorithm algo_enum);
467 
468 /**
469  * Provide the Asymmetric xform string, given an xform enum.
470  *
471  * @param	xform_enum	xform type enum
472  *
473  * @return
474  * - Return NULL, if enum is not valid.
475  * - Return xform string, for valid enum.
476  */
477 __rte_experimental
478 const char *
479 rte_cryptodev_asym_get_xform_string(enum rte_crypto_asym_xform_type xform_enum);
480 
481 
482 /** Macro used at end of crypto PMD list */
483 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
484 	{ RTE_CRYPTO_OP_TYPE_UNDEFINED }
485 
486 
487 /**
488  * Crypto device supported feature flags
489  *
490  * Note:
491  * New features flags should be added to the end of the list
492  *
493  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
494  */
495 #define	RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO		(1ULL << 0)
496 /**< Symmetric crypto operations are supported */
497 #define	RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO		(1ULL << 1)
498 /**< Asymmetric crypto operations are supported */
499 #define	RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING		(1ULL << 2)
500 /**< Chaining symmetric crypto operations are supported */
501 #define	RTE_CRYPTODEV_FF_CPU_SSE			(1ULL << 3)
502 /**< Utilises CPU SIMD SSE instructions */
503 #define	RTE_CRYPTODEV_FF_CPU_AVX			(1ULL << 4)
504 /**< Utilises CPU SIMD AVX instructions */
505 #define	RTE_CRYPTODEV_FF_CPU_AVX2			(1ULL << 5)
506 /**< Utilises CPU SIMD AVX2 instructions */
507 #define	RTE_CRYPTODEV_FF_CPU_AESNI			(1ULL << 6)
508 /**< Utilises CPU AES-NI instructions */
509 #define	RTE_CRYPTODEV_FF_HW_ACCELERATED			(1ULL << 7)
510 /**< Operations are off-loaded to an
511  * external hardware accelerator
512  */
513 #define	RTE_CRYPTODEV_FF_CPU_AVX512			(1ULL << 8)
514 /**< Utilises CPU SIMD AVX512 instructions */
515 #define	RTE_CRYPTODEV_FF_IN_PLACE_SGL			(1ULL << 9)
516 /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
517  * are supported
518  */
519 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT		(1ULL << 10)
520 /**< Out-of-place Scatter-gather (SGL) buffers are
521  * supported in input and output
522  */
523 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT		(1ULL << 11)
524 /**< Out-of-place Scatter-gather (SGL) buffers are supported
525  * in input, combined with linear buffers (LB), with a
526  * single segment in output
527  */
528 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT		(1ULL << 12)
529 /**< Out-of-place Scatter-gather (SGL) buffers are supported
530  * in output, combined with linear buffers (LB) in input
531  */
532 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT		(1ULL << 13)
533 /**< Out-of-place linear buffers (LB) are supported in input and output */
534 #define	RTE_CRYPTODEV_FF_CPU_NEON			(1ULL << 14)
535 /**< Utilises CPU NEON instructions */
536 #define	RTE_CRYPTODEV_FF_CPU_ARM_CE			(1ULL << 15)
537 /**< Utilises ARM CPU Cryptographic Extensions */
538 #define	RTE_CRYPTODEV_FF_SECURITY			(1ULL << 16)
539 /**< Support Security Protocol Processing */
540 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP		(1ULL << 17)
541 /**< Support RSA Private Key OP with exponent */
542 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT		(1ULL << 18)
543 /**< Support RSA Private Key OP with CRT (quintuple) Keys */
544 #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED		(1ULL << 19)
545 /**< Support encrypted-digest operations where digest is appended to data */
546 #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS		(1ULL << 20)
547 /**< Support asymmetric session-less operations */
548 #define	RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO			(1ULL << 21)
549 /**< Support symmetric cpu-crypto processing */
550 #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS		(1ULL << 22)
551 /**< Support symmetric session-less operations */
552 #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA		(1ULL << 23)
553 /**< Support operations on data which is not byte aligned */
554 #define RTE_CRYPTODEV_FF_SYM_RAW_DP			(1ULL << 24)
555 /**< Support accelerator specific symmetric raw data-path APIs */
556 #define RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS	(1ULL << 25)
557 /**< Support operations on multiple data-units message */
558 #define RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY		(1ULL << 26)
559 /**< Support wrapped key in cipher xform  */
560 #define RTE_CRYPTODEV_FF_SECURITY_INNER_CSUM		(1ULL << 27)
561 /**< Support inner checksum computation/verification */
562 
563 /**
564  * Get the name of a crypto device feature flag
565  *
566  * @param	flag	The mask describing the flag.
567  *
568  * @return
569  *   The name of this flag, or NULL if it's not a valid feature flag.
570  */
571 const char *
572 rte_cryptodev_get_feature_name(uint64_t flag);
573 
574 /**  Crypto device information */
575 /* Structure rte_cryptodev_info 8< */
576 struct rte_cryptodev_info {
577 	const char *driver_name;	/**< Driver name. */
578 	uint8_t driver_id;		/**< Driver identifier */
579 	struct rte_device *device;	/**< Generic device information. */
580 
581 	uint64_t feature_flags;
582 	/**< Feature flags exposes HW/SW features for the given device */
583 
584 	const struct rte_cryptodev_capabilities *capabilities;
585 	/**< Array of devices supported capabilities */
586 
587 	unsigned max_nb_queue_pairs;
588 	/**< Maximum number of queues pairs supported by device. */
589 
590 	uint16_t min_mbuf_headroom_req;
591 	/**< Minimum mbuf headroom required by device */
592 
593 	uint16_t min_mbuf_tailroom_req;
594 	/**< Minimum mbuf tailroom required by device */
595 
596 	struct {
597 		unsigned max_nb_sessions;
598 		/**< Maximum number of sessions supported by device.
599 		 * If 0, the device does not have any limitation in
600 		 * number of sessions that can be used.
601 		 */
602 	} sym;
603 };
604 /* >8 End of structure rte_cryptodev_info. */
605 
606 #define RTE_CRYPTODEV_DETACHED  (0)
607 #define RTE_CRYPTODEV_ATTACHED  (1)
608 
609 /** Definitions of Crypto device event types */
610 enum rte_cryptodev_event_type {
611 	RTE_CRYPTODEV_EVENT_UNKNOWN,	/**< unknown event type */
612 	RTE_CRYPTODEV_EVENT_ERROR,	/**< error interrupt event */
613 	RTE_CRYPTODEV_EVENT_MAX		/**< max value of this enum */
614 };
615 
616 /** Crypto device queue pair configuration structure. */
617 /* Structure rte_cryptodev_qp_conf 8<*/
618 struct rte_cryptodev_qp_conf {
619 	uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
620 	struct rte_mempool *mp_session;
621 	/**< The mempool for creating session in sessionless mode */
622 };
623 /* >8 End of structure rte_cryptodev_qp_conf. */
624 
625 /**
626  * Function type used for processing crypto ops when enqueue/dequeue burst is
627  * called.
628  *
629  * The callback function is called on enqueue/dequeue burst immediately.
630  *
631  * @param	dev_id		The identifier of the device.
632  * @param	qp_id		The index of the queue pair on which ops are
633  *				enqueued/dequeued. The value must be in the
634  *				range [0, nb_queue_pairs - 1] previously
635  *				supplied to *rte_cryptodev_configure*.
636  * @param	ops		The address of an array of *nb_ops* pointers
637  *				to *rte_crypto_op* structures which contain
638  *				the crypto operations to be processed.
639  * @param	nb_ops		The number of operations to process.
640  * @param	user_param	The arbitrary user parameter passed in by the
641  *				application when the callback was originally
642  *				registered.
643  * @return			The number of ops to be enqueued to the
644  *				crypto device.
645  */
646 typedef uint16_t (*rte_cryptodev_callback_fn)(uint16_t dev_id, uint16_t qp_id,
647 		struct rte_crypto_op **ops, uint16_t nb_ops, void *user_param);
648 
649 /**
650  * Typedef for application callback function to be registered by application
651  * software for notification of device events
652  *
653  * @param	dev_id	Crypto device identifier
654  * @param	event	Crypto device event to register for notification of.
655  * @param	cb_arg	User specified parameter to be passed as to passed to
656  *			users callback function.
657  */
658 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
659 		enum rte_cryptodev_event_type event, void *cb_arg);
660 
661 
662 /** Crypto Device statistics */
663 struct rte_cryptodev_stats {
664 	uint64_t enqueued_count;
665 	/**< Count of all operations enqueued */
666 	uint64_t dequeued_count;
667 	/**< Count of all operations dequeued */
668 
669 	uint64_t enqueue_err_count;
670 	/**< Total error count on operations enqueued */
671 	uint64_t dequeue_err_count;
672 	/**< Total error count on operations dequeued */
673 };
674 
675 #define RTE_CRYPTODEV_NAME_MAX_LEN	(64)
676 /**< Max length of name of crypto PMD */
677 
678 /**
679  * Get the device identifier for the named crypto device.
680  *
681  * @param	name	device name to select the device structure.
682  *
683  * @return
684  *   - Returns crypto device identifier on success.
685  *   - Return -1 on failure to find named crypto device.
686  */
687 int
688 rte_cryptodev_get_dev_id(const char *name);
689 
690 /**
691  * Get the crypto device name given a device identifier.
692  *
693  * @param dev_id
694  *   The identifier of the device
695  *
696  * @return
697  *   - Returns crypto device name.
698  *   - Returns NULL if crypto device is not present.
699  */
700 const char *
701 rte_cryptodev_name_get(uint8_t dev_id);
702 
703 /**
704  * Get the total number of crypto devices that have been successfully
705  * initialised.
706  *
707  * @return
708  *   - The total number of usable crypto devices.
709  */
710 uint8_t
711 rte_cryptodev_count(void);
712 
713 /**
714  * Get number of crypto device defined type.
715  *
716  * @param	driver_id	driver identifier.
717  *
718  * @return
719  *   Returns number of crypto device.
720  */
721 uint8_t
722 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
723 
724 /**
725  * Get number and identifiers of attached crypto devices that
726  * use the same crypto driver.
727  *
728  * @param	driver_name	driver name.
729  * @param	devices		output devices identifiers.
730  * @param	nb_devices	maximal number of devices.
731  *
732  * @return
733  *   Returns number of attached crypto device.
734  */
735 uint8_t
736 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
737 		uint8_t nb_devices);
738 /*
739  * Return the NUMA socket to which a device is connected
740  *
741  * @param dev_id
742  *   The identifier of the device
743  * @return
744  *   The NUMA socket id to which the device is connected or
745  *   a default of zero if the socket could not be determined.
746  *   -1 if returned is the dev_id value is out of range.
747  */
748 int
749 rte_cryptodev_socket_id(uint8_t dev_id);
750 
751 /** Crypto device configuration structure */
752 /* Structure rte_cryptodev_config 8< */
753 struct rte_cryptodev_config {
754 	int socket_id;			/**< Socket to allocate resources on */
755 	uint16_t nb_queue_pairs;
756 	/**< Number of queue pairs to configure on device */
757 	uint64_t ff_disable;
758 	/**< Feature flags to be disabled. Only the following features are
759 	 * allowed to be disabled,
760 	 *  - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
761 	 *  - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
762 	 *  - RTE_CRYTPODEV_FF_SECURITY
763 	 */
764 };
765 /* >8 End of structure rte_cryptodev_config. */
766 
767 /**
768  * Configure a device.
769  *
770  * This function must be invoked first before any other function in the
771  * API. This function can also be re-invoked when a device is in the
772  * stopped state.
773  *
774  * @param	dev_id		The identifier of the device to configure.
775  * @param	config		The crypto device configuration structure.
776  *
777  * @return
778  *   - 0: Success, device configured.
779  *   - <0: Error code returned by the driver configuration function.
780  */
781 int
782 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
783 
784 /**
785  * Start an device.
786  *
787  * The device start step is the last one and consists of setting the configured
788  * offload features and in starting the transmit and the receive units of the
789  * device.
790  * On success, all basic functions exported by the API (link status,
791  * receive/transmit, and so on) can be invoked.
792  *
793  * @param dev_id
794  *   The identifier of the device.
795  * @return
796  *   - 0: Success, device started.
797  *   - <0: Error code of the driver device start function.
798  */
799 int
800 rte_cryptodev_start(uint8_t dev_id);
801 
802 /**
803  * Stop an device. The device can be restarted with a call to
804  * rte_cryptodev_start()
805  *
806  * @param	dev_id		The identifier of the device.
807  */
808 void
809 rte_cryptodev_stop(uint8_t dev_id);
810 
811 /**
812  * Close an device. The device cannot be restarted!
813  *
814  * @param	dev_id		The identifier of the device.
815  *
816  * @return
817  *  - 0 on successfully closing device
818  *  - <0 on failure to close device
819  */
820 int
821 rte_cryptodev_close(uint8_t dev_id);
822 
823 /**
824  * Allocate and set up a receive queue pair for a device.
825  *
826  *
827  * @param	dev_id		The identifier of the device.
828  * @param	queue_pair_id	The index of the queue pairs to set up. The
829  *				value must be in the range [0, nb_queue_pair
830  *				- 1] previously supplied to
831  *				rte_cryptodev_configure().
832  * @param	qp_conf		The pointer to the configuration data to be
833  *				used for the queue pair.
834  * @param	socket_id	The *socket_id* argument is the socket
835  *				identifier in case of NUMA. The value can be
836  *				*SOCKET_ID_ANY* if there is no NUMA constraint
837  *				for the DMA memory allocated for the receive
838  *				queue pair.
839  *
840  * @return
841  *   - 0: Success, queue pair correctly set up.
842  *   - <0: Queue pair configuration failed
843  */
844 int
845 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
846 		const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
847 
848 /**
849  * Get the status of queue pairs setup on a specific crypto device
850  *
851  * @param	dev_id		Crypto device identifier.
852  * @param	queue_pair_id	The index of the queue pairs to set up. The
853  *				value must be in the range [0, nb_queue_pair
854  *				- 1] previously supplied to
855  *				rte_cryptodev_configure().
856  * @return
857  *   - 0: qp was not configured
858  *	 - 1: qp was configured
859  *	 - -EINVAL: device was not configured
860  */
861 __rte_experimental
862 int
863 rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id);
864 
865 /**
866  * Get the number of queue pairs on a specific crypto device
867  *
868  * @param	dev_id		Crypto device identifier.
869  * @return
870  *   - The number of configured queue pairs.
871  */
872 uint16_t
873 rte_cryptodev_queue_pair_count(uint8_t dev_id);
874 
875 
876 /**
877  * Retrieve the general I/O statistics of a device.
878  *
879  * @param	dev_id		The identifier of the device.
880  * @param	stats		A pointer to a structure of type
881  *				*rte_cryptodev_stats* to be filled with the
882  *				values of device counters.
883  * @return
884  *   - Zero if successful.
885  *   - Non-zero otherwise.
886  */
887 int
888 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
889 
890 /**
891  * Reset the general I/O statistics of a device.
892  *
893  * @param	dev_id		The identifier of the device.
894  */
895 void
896 rte_cryptodev_stats_reset(uint8_t dev_id);
897 
898 /**
899  * Retrieve the contextual information of a device.
900  *
901  * @param	dev_id		The identifier of the device.
902  * @param	dev_info	A pointer to a structure of type
903  *				*rte_cryptodev_info* to be filled with the
904  *				contextual information of the device.
905  *
906  * @note The capabilities field of dev_info is set to point to the first
907  * element of an array of struct rte_cryptodev_capabilities. The element after
908  * the last valid element has it's op field set to
909  * RTE_CRYPTO_OP_TYPE_UNDEFINED.
910  */
911 void
912 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
913 
914 
915 /**
916  * Register a callback function for specific device id.
917  *
918  * @param	dev_id		Device id.
919  * @param	event		Event interested.
920  * @param	cb_fn		User supplied callback function to be called.
921  * @param	cb_arg		Pointer to the parameters for the registered
922  *				callback.
923  *
924  * @return
925  *  - On success, zero.
926  *  - On failure, a negative value.
927  */
928 int
929 rte_cryptodev_callback_register(uint8_t dev_id,
930 		enum rte_cryptodev_event_type event,
931 		rte_cryptodev_cb_fn cb_fn, void *cb_arg);
932 
933 /**
934  * Unregister a callback function for specific device id.
935  *
936  * @param	dev_id		The device identifier.
937  * @param	event		Event interested.
938  * @param	cb_fn		User supplied callback function to be called.
939  * @param	cb_arg		Pointer to the parameters for the registered
940  *				callback.
941  *
942  * @return
943  *  - On success, zero.
944  *  - On failure, a negative value.
945  */
946 int
947 rte_cryptodev_callback_unregister(uint8_t dev_id,
948 		enum rte_cryptodev_event_type event,
949 		rte_cryptodev_cb_fn cb_fn, void *cb_arg);
950 
951 /**
952  * @warning
953  * @b EXPERIMENTAL: this API may change without prior notice.
954  *
955  * Query a cryptodev queue pair if there are pending RTE_CRYPTODEV_EVENT_ERROR
956  * events.
957  *
958  * @param          dev_id	The device identifier.
959  * @param          qp_id	Queue pair index to be queried.
960  *
961  * @return
962  *   - 1 if requested queue has a pending event.
963  *   - 0 if no pending event is found.
964  *   - a negative value on failure
965  */
966 __rte_experimental
967 int
968 rte_cryptodev_queue_pair_event_error_query(uint8_t dev_id, uint16_t qp_id);
969 
970 struct rte_cryptodev_callback;
971 
972 /** Structure to keep track of registered callbacks */
973 RTE_TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
974 
975 /**
976  * Structure used to hold information about the callbacks to be called for a
977  * queue pair on enqueue/dequeue.
978  */
979 struct rte_cryptodev_cb {
980 	struct rte_cryptodev_cb *next;
981 	/**< Pointer to next callback */
982 	rte_cryptodev_callback_fn fn;
983 	/**< Pointer to callback function */
984 	void *arg;
985 	/**< Pointer to argument */
986 };
987 
988 /**
989  * @internal
990  * Structure used to hold information about the RCU for a queue pair.
991  */
992 struct rte_cryptodev_cb_rcu {
993 	struct rte_cryptodev_cb *next;
994 	/**< Pointer to next callback */
995 	struct rte_rcu_qsbr *qsbr;
996 	/**< RCU QSBR variable per queue pair */
997 };
998 
999 /**
1000  * Get the security context for the cryptodev.
1001  *
1002  * @param dev_id
1003  *   The device identifier.
1004  * @return
1005  *   - NULL on error.
1006  *   - Pointer to security context on success.
1007  */
1008 void *
1009 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
1010 
1011 /**
1012  * Create a symmetric session mempool.
1013  *
1014  * @param name
1015  *   The unique mempool name.
1016  * @param nb_elts
1017  *   The number of elements in the mempool.
1018  * @param elt_size
1019  *   The size of the element. This should be the size of the cryptodev PMD
1020  *   session private data obtained through
1021  *   rte_cryptodev_sym_get_private_session_size() function call.
1022  *   For the user who wants to use the same mempool for heterogeneous PMDs
1023  *   this value should be the maximum value of their private session sizes.
1024  *   Please note the created mempool will have bigger elt size than this
1025  *   value as necessary session header and the possible padding are filled
1026  *   into each elt.
1027  * @param cache_size
1028  *   The number of per-lcore cache elements
1029  * @param priv_size
1030  *   The private data size of each session.
1031  * @param socket_id
1032  *   The *socket_id* argument is the socket identifier in the case of
1033  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
1034  *   constraint for the reserved zone.
1035  *
1036  * @return
1037  *  - On success returns the created session mempool pointer
1038  *  - On failure returns NULL
1039  */
1040 __rte_experimental
1041 struct rte_mempool *
1042 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1043 	uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1044 	int socket_id);
1045 
1046 
1047 /**
1048  * Create an asymmetric session mempool.
1049  *
1050  * @param name
1051  *   The unique mempool name.
1052  * @param nb_elts
1053  *   The number of elements in the mempool.
1054  * @param cache_size
1055  *   The number of per-lcore cache elements
1056  * @param user_data_size
1057  *   The size of user data to be placed after session private data.
1058  * @param socket_id
1059  *   The *socket_id* argument is the socket identifier in the case of
1060  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
1061  *   constraint for the reserved zone.
1062  *
1063  * @return
1064  *  - On success return mempool
1065  *  - On failure returns NULL
1066  */
1067 __rte_experimental
1068 struct rte_mempool *
1069 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
1070 	uint32_t cache_size, uint16_t user_data_size, int socket_id);
1071 
1072 /**
1073  * Create symmetric crypto session and fill out private data for the device id,
1074  * based on its device type.
1075  *
1076  * @param   dev_id   ID of device that we want the session to be used on
1077  * @param   xforms   Symmetric crypto transform operations to apply on flow
1078  *                   processed with this session
1079  * @param   mp       Mempool to allocate symmetric session objects from
1080  *
1081  * @return
1082  *  - On success return pointer to sym-session.
1083  *  - On failure returns NULL and rte_errno is set to the error code:
1084  *    - EINVAL on invalid arguments.
1085  *    - ENOMEM on memory error for session allocation.
1086  *    - ENOTSUP if device doesn't support session configuration.
1087  */
1088 void *
1089 rte_cryptodev_sym_session_create(uint8_t dev_id,
1090 		struct rte_crypto_sym_xform *xforms,
1091 		struct rte_mempool *mp);
1092 /**
1093  * Create and initialise an asymmetric crypto session structure.
1094  * Calls the PMD to configure the private session data.
1095  *
1096  * @param   dev_id   ID of device that we want the session to be used on
1097  * @param   xforms   Asymmetric crypto transform operations to apply on flow
1098  *                   processed with this session
1099  * @param   mp       mempool to allocate asymmetric session
1100  *                   objects from
1101  * @param   session  void ** for session to be used
1102  *
1103  * @return
1104  *  - 0 on success.
1105  *  - -EINVAL on invalid arguments.
1106  *  - -ENOMEM on memory error for session allocation.
1107  *  - -ENOTSUP if device doesn't support session configuration.
1108  */
1109 __rte_experimental
1110 int
1111 rte_cryptodev_asym_session_create(uint8_t dev_id,
1112 		struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
1113 		void **session);
1114 
1115 /**
1116  * Frees session for the device id and returning it to its mempool.
1117  * It is the application's responsibility to ensure that the session
1118  * is not still in-flight operations using it.
1119  *
1120  * @param   dev_id   ID of device that uses the session.
1121  * @param   sess     Session header to be freed.
1122  *
1123  * @return
1124  *  - 0 if successful.
1125  *  - -EINVAL if session is NULL or the mismatched device ids.
1126  */
1127 int
1128 rte_cryptodev_sym_session_free(uint8_t dev_id,
1129 	void *sess);
1130 
1131 /**
1132  * Clears and frees asymmetric crypto session header and private data,
1133  * returning it to its original mempool.
1134  *
1135  * @param   dev_id   ID of device that uses the asymmetric session.
1136  * @param   sess     Session header to be freed.
1137  *
1138  * @return
1139  *  - 0 if successful.
1140  *  - -EINVAL if device is invalid or session is NULL.
1141  */
1142 __rte_experimental
1143 int
1144 rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
1145 
1146 /**
1147  * Get the size of the asymmetric session header.
1148  *
1149  * @return
1150  *   Size of the asymmetric header session.
1151  */
1152 __rte_experimental
1153 unsigned int
1154 rte_cryptodev_asym_get_header_session_size(void);
1155 
1156 /**
1157  * Get the size of the private symmetric session data
1158  * for a device.
1159  *
1160  * @param	dev_id		The device identifier.
1161  *
1162  * @return
1163  *   - Size of the private data, if successful
1164  *   - 0 if device is invalid or does not have private
1165  *   symmetric session
1166  */
1167 unsigned int
1168 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
1169 
1170 /**
1171  * Get the size of the private data for asymmetric session
1172  * on device
1173  *
1174  * @param	dev_id		The device identifier.
1175  *
1176  * @return
1177  *   - Size of the asymmetric private data, if successful
1178  *   - 0 if device is invalid or does not have private session
1179  */
1180 __rte_experimental
1181 unsigned int
1182 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
1183 
1184 /**
1185  * Validate if the crypto device index is valid attached crypto device.
1186  *
1187  * @param	dev_id	Crypto device index.
1188  *
1189  * @return
1190  *   - If the device index is valid (1) or not (0).
1191  */
1192 unsigned int
1193 rte_cryptodev_is_valid_dev(uint8_t dev_id);
1194 
1195 /**
1196  * Provide driver identifier.
1197  *
1198  * @param name
1199  *   The pointer to a driver name.
1200  * @return
1201  *  The driver type identifier or -1 if no driver found
1202  */
1203 int rte_cryptodev_driver_id_get(const char *name);
1204 
1205 /**
1206  * Provide driver name.
1207  *
1208  * @param driver_id
1209  *   The driver identifier.
1210  * @return
1211  *  The driver name or null if no driver found
1212  */
1213 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1214 
1215 /**
1216  * Store user data in a session.
1217  *
1218  * @param	sess		Session pointer allocated by
1219  *				*rte_cryptodev_sym_session_create*.
1220  * @param	data		Pointer to the user data.
1221  * @param	size		Size of the user data.
1222  *
1223  * @return
1224  *  - On success, zero.
1225  *  - On failure, a negative value.
1226  */
1227 __rte_experimental
1228 int
1229 rte_cryptodev_sym_session_set_user_data(void *sess,
1230 					void *data,
1231 					uint16_t size);
1232 
1233 #define CRYPTO_SESS_OPAQUE_DATA_OFF 0
1234 /**
1235  * Get opaque data from session handle
1236  */
1237 static inline uint64_t
1238 rte_cryptodev_sym_session_opaque_data_get(void *sess)
1239 {
1240 	return *((uint64_t *)sess + CRYPTO_SESS_OPAQUE_DATA_OFF);
1241 }
1242 
1243 /**
1244  * Set opaque data in session handle
1245  */
1246 static inline void
1247 rte_cryptodev_sym_session_opaque_data_set(void *sess, uint64_t opaque)
1248 {
1249 	uint64_t *data;
1250 	data = (((uint64_t *)sess) + CRYPTO_SESS_OPAQUE_DATA_OFF);
1251 	*data = opaque;
1252 }
1253 
1254 /**
1255  * Get user data stored in a session.
1256  *
1257  * @param	sess		Session pointer allocated by
1258  *				*rte_cryptodev_sym_session_create*.
1259  *
1260  * @return
1261  *  - On success return pointer to user data.
1262  *  - On failure returns NULL.
1263  */
1264 __rte_experimental
1265 void *
1266 rte_cryptodev_sym_session_get_user_data(void *sess);
1267 
1268 /**
1269  * Store user data in an asymmetric session.
1270  *
1271  * @param	sess		Session pointer allocated by
1272  *				*rte_cryptodev_asym_session_create*.
1273  * @param	data		Pointer to the user data.
1274  * @param	size		Size of the user data.
1275  *
1276  * @return
1277  *  - On success, zero.
1278  *  - -EINVAL if the session pointer is invalid.
1279  *  - -ENOMEM if the available user data size is smaller than the size parameter.
1280  */
1281 __rte_experimental
1282 int
1283 rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
1284 
1285 /**
1286  * Get user data stored in an asymmetric session.
1287  *
1288  * @param	sess		Session pointer allocated by
1289  *				*rte_cryptodev_asym_session_create*.
1290  *
1291  * @return
1292  *  - On success return pointer to user data.
1293  *  - On failure returns NULL.
1294  */
1295 __rte_experimental
1296 void *
1297 rte_cryptodev_asym_session_get_user_data(void *sess);
1298 
1299 /**
1300  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
1301  * on user provided data.
1302  *
1303  * @param	dev_id	The device identifier.
1304  * @param	sess	Cryptodev session structure
1305  * @param	ofs	Start and stop offsets for auth and cipher operations
1306  * @param	vec	Vectorized operation descriptor
1307  *
1308  * @return
1309  *  - Returns number of successfully processed packets.
1310  */
1311 __rte_experimental
1312 uint32_t
1313 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
1314 	void *sess, union rte_crypto_sym_ofs ofs,
1315 	struct rte_crypto_sym_vec *vec);
1316 
1317 /**
1318  * Get the size of the raw data-path context buffer.
1319  *
1320  * @param	dev_id		The device identifier.
1321  *
1322  * @return
1323  *   - If the device supports raw data-path APIs, return the context size.
1324  *   - If the device does not support the APIs, return -1.
1325  */
1326 __rte_experimental
1327 int
1328 rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id);
1329 
1330 /**
1331  * Set session event meta data
1332  *
1333  * @param	dev_id		The device identifier.
1334  * @param	sess            Crypto or security session.
1335  * @param	op_type         Operation type.
1336  * @param	sess_type       Session type.
1337  * @param	ev_mdata	Pointer to the event crypto meta data
1338  *				(aka *union rte_event_crypto_metadata*)
1339  * @param	size            Size of ev_mdata.
1340  *
1341  * @return
1342  *  - On success, zero.
1343  *  - On failure, a negative value.
1344  */
1345 __rte_experimental
1346 int
1347 rte_cryptodev_session_event_mdata_set(uint8_t dev_id, void *sess,
1348 	enum rte_crypto_op_type op_type,
1349 	enum rte_crypto_op_sess_type sess_type,
1350 	void *ev_mdata, uint16_t size);
1351 
1352 /**
1353  * Union of different crypto session types, including session-less xform
1354  * pointer.
1355  */
1356 union rte_cryptodev_session_ctx {void *crypto_sess;
1357 	struct rte_crypto_sym_xform *xform;
1358 	struct rte_security_session *sec_sess;
1359 };
1360 
1361 /**
1362  * Enqueue a vectorized operation descriptor into the device queue but the
1363  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1364  * is called.
1365  *
1366  * @param	qp		Driver specific queue pair data.
1367  * @param	drv_ctx		Driver specific context data.
1368  * @param	vec		Vectorized operation descriptor.
1369  * @param	ofs		Start and stop offsets for auth and cipher
1370  *				operations.
1371  * @param	user_data	The array of user data for dequeue later.
1372  * @param	enqueue_status	Driver written value to specify the
1373  *				enqueue status. Possible values:
1374  *				- 1: The number of operations returned are
1375  *				     enqueued successfully.
1376  *				- 0: The number of operations returned are
1377  *				     cached into the queue but are not processed
1378  *				     until rte_cryptodev_raw_enqueue_done() is
1379  *				     called.
1380  *				- negative integer: Error occurred.
1381  * @return
1382  *   - The number of operations in the descriptor successfully enqueued or
1383  *     cached into the queue but not enqueued yet, depends on the
1384  *     "enqueue_status" value.
1385  */
1386 typedef uint32_t (*cryptodev_sym_raw_enqueue_burst_t)(
1387 	void *qp, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1388 	union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status);
1389 
1390 /**
1391  * Enqueue single raw data vector into the device queue but the driver may or
1392  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1393  *
1394  * @param	qp		Driver specific queue pair data.
1395  * @param	drv_ctx		Driver specific context data.
1396  * @param	data_vec	The buffer data vector.
1397  * @param	n_data_vecs	Number of buffer data vectors.
1398  * @param	ofs		Start and stop offsets for auth and cipher
1399  *				operations.
1400  * @param	iv		IV virtual and IOVA addresses
1401  * @param	digest		digest virtual and IOVA addresses
1402  * @param	aad_or_auth_iv	AAD or auth IV virtual and IOVA addresses,
1403  *				depends on the algorithm used.
1404  * @param	user_data	The user data.
1405  * @return
1406  *   - 1: The data vector is enqueued successfully.
1407  *   - 0: The data vector is cached into the queue but is not processed
1408  *        until rte_cryptodev_raw_enqueue_done() is called.
1409  *   - negative integer: failure.
1410  */
1411 typedef int (*cryptodev_sym_raw_enqueue_t)(
1412 	void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1413 	uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1414 	struct rte_crypto_va_iova_ptr *iv,
1415 	struct rte_crypto_va_iova_ptr *digest,
1416 	struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1417 	void *user_data);
1418 
1419 /**
1420  * Inform the cryptodev queue pair to start processing or finish dequeuing all
1421  * enqueued/dequeued operations.
1422  *
1423  * @param	qp		Driver specific queue pair data.
1424  * @param	drv_ctx		Driver specific context data.
1425  * @param	n		The total number of processed operations.
1426  * @return
1427  *   - On success return 0.
1428  *   - On failure return negative integer.
1429  */
1430 typedef int (*cryptodev_sym_raw_operation_done_t)(void *qp, uint8_t *drv_ctx,
1431 	uint32_t n);
1432 
1433 /**
1434  * Typedef that the user provided for the driver to get the dequeue count.
1435  * The function may return a fixed number or the number parsed from the user
1436  * data stored in the first processed operation.
1437  *
1438  * @param	user_data	Dequeued user data.
1439  * @return
1440  *  - The number of operations to be dequeued.
1441  */
1442 typedef uint32_t (*rte_cryptodev_raw_get_dequeue_count_t)(void *user_data);
1443 
1444 /**
1445  * Typedef that the user provided to deal with post dequeue operation, such
1446  * as filling status.
1447  *
1448  * @param	user_data	Dequeued user data.
1449  * @param	index		Index number of the processed descriptor.
1450  * @param	is_op_success	Operation status provided by the driver.
1451  */
1452 typedef void (*rte_cryptodev_raw_post_dequeue_t)(void *user_data,
1453 	uint32_t index, uint8_t is_op_success);
1454 
1455 /**
1456  * Dequeue a burst of symmetric crypto processing.
1457  *
1458  * @param	qp			Driver specific queue pair data.
1459  * @param	drv_ctx			Driver specific context data.
1460  * @param	get_dequeue_count	User provided callback function to
1461  *					obtain dequeue operation count.
1462  * @param	max_nb_to_dequeue	When get_dequeue_count is NULL this
1463  *					value is used to pass the maximum
1464  *					number of operations to be dequeued.
1465  * @param	post_dequeue		User provided callback function to
1466  *					post-process a dequeued operation.
1467  * @param	out_user_data		User data pointer array to be retrieve
1468  *					from device queue. In case of
1469  *					*is_user_data_array* is set there
1470  *					should be enough room to store all
1471  *					user data.
1472  * @param	is_user_data_array	Set 1 if every dequeued user data will
1473  *					be written into out_user_data array.
1474  *					Set 0 if only the first user data will
1475  *					be written into out_user_data array.
1476  * @param	n_success		Driver written value to specific the
1477  *					total successful operations count.
1478  * @param	dequeue_status		Driver written value to specify the
1479  *					dequeue status. Possible values:
1480  *					- 1: Successfully dequeued the number
1481  *					     of operations returned. The user
1482  *					     data previously set during enqueue
1483  *					     is stored in the "out_user_data".
1484  *					- 0: The number of operations returned
1485  *					     are completed and the user data is
1486  *					     stored in the "out_user_data", but
1487  *					     they are not freed from the queue
1488  *					     until
1489  *					     rte_cryptodev_raw_dequeue_done()
1490  *					     is called.
1491  *					- negative integer: Error occurred.
1492  * @return
1493  *   - The number of operations dequeued or completed but not freed from the
1494  *     queue, depends on "dequeue_status" value.
1495  */
1496 typedef uint32_t (*cryptodev_sym_raw_dequeue_burst_t)(void *qp,
1497 	uint8_t *drv_ctx,
1498 	rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1499 	uint32_t max_nb_to_dequeue,
1500 	rte_cryptodev_raw_post_dequeue_t post_dequeue,
1501 	void **out_user_data, uint8_t is_user_data_array,
1502 	uint32_t *n_success, int *dequeue_status);
1503 
1504 /**
1505  * Dequeue a symmetric crypto processing.
1506  *
1507  * @param	qp			Driver specific queue pair data.
1508  * @param	drv_ctx			Driver specific context data.
1509  * @param	dequeue_status		Driver written value to specify the
1510  *					dequeue status. Possible values:
1511  *					- 1: Successfully dequeued a operation.
1512  *					     The user data is returned.
1513  *					- 0: The first operation in the queue
1514  *					     is completed and the user data
1515  *					     previously set during enqueue is
1516  *					     returned, but it is not freed from
1517  *					     the queue until
1518  *					     rte_cryptodev_raw_dequeue_done() is
1519  *					     called.
1520  *					- negative integer: Error occurred.
1521  * @param	op_status		Driver written value to specify
1522  *					operation status.
1523  * @return
1524  *   - The user data pointer retrieved from device queue or NULL if no
1525  *     operation is ready for dequeue.
1526  */
1527 typedef void * (*cryptodev_sym_raw_dequeue_t)(
1528 		void *qp, uint8_t *drv_ctx, int *dequeue_status,
1529 		enum rte_crypto_op_status *op_status);
1530 
1531 /**
1532  * Context data for raw data-path API crypto process. The buffer of this
1533  * structure is to be allocated by the user application with the size equal
1534  * or bigger than rte_cryptodev_get_raw_dp_ctx_size() returned value.
1535  */
1536 struct rte_crypto_raw_dp_ctx {
1537 	void *qp_data;
1538 
1539 	cryptodev_sym_raw_enqueue_t enqueue;
1540 	cryptodev_sym_raw_enqueue_burst_t enqueue_burst;
1541 	cryptodev_sym_raw_operation_done_t enqueue_done;
1542 	cryptodev_sym_raw_dequeue_t dequeue;
1543 	cryptodev_sym_raw_dequeue_burst_t dequeue_burst;
1544 	cryptodev_sym_raw_operation_done_t dequeue_done;
1545 
1546 	/* Driver specific context data */
1547 	__extension__ uint8_t drv_ctx_data[];
1548 };
1549 
1550 /**
1551  * Configure raw data-path context data.
1552  *
1553  * @param	dev_id		The device identifier.
1554  * @param	qp_id		The index of the queue pair from which to
1555  *				retrieve processed packets. The value must be
1556  *				in the range [0, nb_queue_pair - 1] previously
1557  *				supplied to rte_cryptodev_configure().
1558  * @param	ctx		The raw data-path context data.
1559  * @param	sess_type	Session type.
1560  * @param	session_ctx	Session context data.
1561  * @param	is_update	Set 0 if it is to initialize the ctx.
1562  *				Set 1 if ctx is initialized and only to update
1563  *				session context data.
1564  * @return
1565  *   - On success return 0.
1566  *   - On failure return negative integer.
1567  *     - -EINVAL if input parameters are invalid.
1568  *     - -ENOTSUP if crypto device does not support raw DP operations with the
1569  *        provided session.
1570  */
1571 __rte_experimental
1572 int
1573 rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
1574 	struct rte_crypto_raw_dp_ctx *ctx,
1575 	enum rte_crypto_op_sess_type sess_type,
1576 	union rte_cryptodev_session_ctx session_ctx,
1577 	uint8_t is_update);
1578 
1579 /**
1580  * Enqueue a vectorized operation descriptor into the device queue but the
1581  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1582  * is called.
1583  *
1584  * @param	ctx		The initialized raw data-path context data.
1585  * @param	vec		Vectorized operation descriptor.
1586  * @param	ofs		Start and stop offsets for auth and cipher
1587  *				operations.
1588  * @param	user_data	The array of user data for dequeue later.
1589  * @param	enqueue_status	Driver written value to specify the
1590  *				enqueue status. Possible values:
1591  *				- 1: The number of operations returned are
1592  *				     enqueued successfully.
1593  *				- 0: The number of operations returned are
1594  *				     cached into the queue but are not processed
1595  *				     until rte_cryptodev_raw_enqueue_done() is
1596  *				     called.
1597  *				- negative integer: Error occurred.
1598  * @return
1599  *   - The number of operations in the descriptor successfully enqueued or
1600  *     cached into the queue but not enqueued yet, depends on the
1601  *     "enqueue_status" value.
1602  */
1603 __rte_experimental
1604 uint32_t
1605 rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1606 	struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
1607 	void **user_data, int *enqueue_status);
1608 
1609 /**
1610  * Enqueue single raw data vector into the device queue but the driver may or
1611  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1612  *
1613  * @param	ctx		The initialized raw data-path context data.
1614  * @param	data_vec	The buffer data vector.
1615  * @param	n_data_vecs	Number of buffer data vectors.
1616  * @param	ofs		Start and stop offsets for auth and cipher
1617  *				operations.
1618  * @param	iv		IV virtual and IOVA addresses
1619  * @param	digest		digest virtual and IOVA addresses
1620  * @param	aad_or_auth_iv	AAD or auth IV virtual and IOVA addresses,
1621  *				depends on the algorithm used.
1622  * @param	user_data	The user data.
1623  * @return
1624  *   - 1: The data vector is enqueued successfully.
1625  *   - 0: The data vector is cached into the queue but is not processed
1626  *        until rte_cryptodev_raw_enqueue_done() is called.
1627  *   - negative integer: failure.
1628  */
1629 __rte_experimental
1630 static __rte_always_inline int
1631 rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx *ctx,
1632 	struct rte_crypto_vec *data_vec, uint16_t n_data_vecs,
1633 	union rte_crypto_sym_ofs ofs,
1634 	struct rte_crypto_va_iova_ptr *iv,
1635 	struct rte_crypto_va_iova_ptr *digest,
1636 	struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1637 	void *user_data)
1638 {
1639 	return (*ctx->enqueue)(ctx->qp_data, ctx->drv_ctx_data, data_vec,
1640 		n_data_vecs, ofs, iv, digest, aad_or_auth_iv, user_data);
1641 }
1642 
1643 /**
1644  * Start processing all enqueued operations from last
1645  * rte_cryptodev_configure_raw_dp_ctx() call.
1646  *
1647  * @param	ctx	The initialized raw data-path context data.
1648  * @param	n	The number of operations cached.
1649  * @return
1650  *   - On success return 0.
1651  *   - On failure return negative integer.
1652  */
1653 __rte_experimental
1654 int
1655 rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
1656 		uint32_t n);
1657 
1658 /**
1659  * Dequeue a burst of symmetric crypto processing.
1660  *
1661  * @param	ctx			The initialized raw data-path context
1662  *					data.
1663  * @param	get_dequeue_count	User provided callback function to
1664  *					obtain dequeue operation count.
1665  * @param	max_nb_to_dequeue	When get_dequeue_count is NULL this
1666  *					value is used to pass the maximum
1667  *					number of operations to be dequeued.
1668  * @param	post_dequeue		User provided callback function to
1669  *					post-process a dequeued operation.
1670  * @param	out_user_data		User data pointer array to be retrieve
1671  *					from device queue. In case of
1672  *					*is_user_data_array* is set there
1673  *					should be enough room to store all
1674  *					user data.
1675  * @param	is_user_data_array	Set 1 if every dequeued user data will
1676  *					be written into out_user_data array.
1677  *					Set 0 if only the first user data will
1678  *					be written into out_user_data array.
1679  * @param	n_success		Driver written value to specific the
1680  *					total successful operations count.
1681  * @param	dequeue_status		Driver written value to specify the
1682  *					dequeue status. Possible values:
1683  *					- 1: Successfully dequeued the number
1684  *					     of operations returned. The user
1685  *					     data previously set during enqueue
1686  *					     is stored in the "out_user_data".
1687  *					- 0: The number of operations returned
1688  *					     are completed and the user data is
1689  *					     stored in the "out_user_data", but
1690  *					     they are not freed from the queue
1691  *					     until
1692  *					     rte_cryptodev_raw_dequeue_done()
1693  *					     is called.
1694  *					- negative integer: Error occurred.
1695  * @return
1696  *   - The number of operations dequeued or completed but not freed from the
1697  *     queue, depends on "dequeue_status" value.
1698  */
1699 __rte_experimental
1700 uint32_t
1701 rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1702 	rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1703 	uint32_t max_nb_to_dequeue,
1704 	rte_cryptodev_raw_post_dequeue_t post_dequeue,
1705 	void **out_user_data, uint8_t is_user_data_array,
1706 	uint32_t *n_success, int *dequeue_status);
1707 
1708 /**
1709  * Dequeue a symmetric crypto processing.
1710  *
1711  * @param	ctx			The initialized raw data-path context
1712  *					data.
1713  * @param	dequeue_status		Driver written value to specify the
1714  *					dequeue status. Possible values:
1715  *					- 1: Successfully dequeued a operation.
1716  *					     The user data is returned.
1717  *					- 0: The first operation in the queue
1718  *					     is completed and the user data
1719  *					     previously set during enqueue is
1720  *					     returned, but it is not freed from
1721  *					     the queue until
1722  *					     rte_cryptodev_raw_dequeue_done() is
1723  *					     called.
1724  *					- negative integer: Error occurred.
1725  * @param	op_status		Driver written value to specify
1726  *					operation status.
1727  * @return
1728  *   - The user data pointer retrieved from device queue or NULL if no
1729  *     operation is ready for dequeue.
1730  */
1731 __rte_experimental
1732 static __rte_always_inline void *
1733 rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx *ctx,
1734 		int *dequeue_status, enum rte_crypto_op_status *op_status)
1735 {
1736 	return (*ctx->dequeue)(ctx->qp_data, ctx->drv_ctx_data, dequeue_status,
1737 			op_status);
1738 }
1739 
1740 /**
1741  * Inform the queue pair dequeue operations is finished.
1742  *
1743  * @param	ctx	The initialized raw data-path context data.
1744  * @param	n	The number of operations.
1745  * @return
1746  *   - On success return 0.
1747  *   - On failure return negative integer.
1748  */
1749 __rte_experimental
1750 int
1751 rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
1752 		uint32_t n);
1753 
1754 /**
1755  * Add a user callback for a given crypto device and queue pair which will be
1756  * called on crypto ops enqueue.
1757  *
1758  * This API configures a function to be called for each burst of crypto ops
1759  * received on a given crypto device queue pair. The return value is a pointer
1760  * that can be used later to remove the callback using
1761  * rte_cryptodev_remove_enq_callback().
1762  *
1763  * Callbacks registered by application would not survive
1764  * rte_cryptodev_configure() as it reinitializes the callback list.
1765  * It is user responsibility to remove all installed callbacks before
1766  * calling rte_cryptodev_configure() to avoid possible memory leakage.
1767  * Application is expected to call add API after rte_cryptodev_configure().
1768  *
1769  * Multiple functions can be registered per queue pair & they are called
1770  * in the order they were added. The API does not restrict on maximum number
1771  * of callbacks.
1772  *
1773  * @param	dev_id		The identifier of the device.
1774  * @param	qp_id		The index of the queue pair on which ops are
1775  *				to be enqueued for processing. The value
1776  *				must be in the range [0, nb_queue_pairs - 1]
1777  *				previously supplied to
1778  *				*rte_cryptodev_configure*.
1779  * @param	cb_fn		The callback function
1780  * @param	cb_arg		A generic pointer parameter which will be passed
1781  *				to each invocation of the callback function on
1782  *				this crypto device and queue pair.
1783  *
1784  * @return
1785  *  - NULL on error & rte_errno will contain the error code.
1786  *  - On success, a pointer value which can later be used to remove the
1787  *    callback.
1788  */
1789 
1790 __rte_experimental
1791 struct rte_cryptodev_cb *
1792 rte_cryptodev_add_enq_callback(uint8_t dev_id,
1793 			       uint16_t qp_id,
1794 			       rte_cryptodev_callback_fn cb_fn,
1795 			       void *cb_arg);
1796 
1797 /**
1798  * Remove a user callback function for given crypto device and queue pair.
1799  *
1800  * This function is used to remove enqueue callbacks that were added to a
1801  * crypto device queue pair using rte_cryptodev_add_enq_callback().
1802  *
1803  *
1804  *
1805  * @param	dev_id		The identifier of the device.
1806  * @param	qp_id		The index of the queue pair on which ops are
1807  *				to be enqueued. The value must be in the
1808  *				range [0, nb_queue_pairs - 1] previously
1809  *				supplied to *rte_cryptodev_configure*.
1810  * @param	cb		Pointer to user supplied callback created via
1811  *				rte_cryptodev_add_enq_callback().
1812  *
1813  * @return
1814  *   -  0: Success. Callback was removed.
1815  *   - <0: The dev_id or the qp_id is out of range, or the callback
1816  *         is NULL or not found for the crypto device queue pair.
1817  */
1818 
1819 __rte_experimental
1820 int rte_cryptodev_remove_enq_callback(uint8_t dev_id,
1821 				      uint16_t qp_id,
1822 				      struct rte_cryptodev_cb *cb);
1823 
1824 /**
1825  * Add a user callback for a given crypto device and queue pair which will be
1826  * called on crypto ops dequeue.
1827  *
1828  * This API configures a function to be called for each burst of crypto ops
1829  * received on a given crypto device queue pair. The return value is a pointer
1830  * that can be used later to remove the callback using
1831  * rte_cryptodev_remove_deq_callback().
1832  *
1833  * Callbacks registered by application would not survive
1834  * rte_cryptodev_configure() as it reinitializes the callback list.
1835  * It is user responsibility to remove all installed callbacks before
1836  * calling rte_cryptodev_configure() to avoid possible memory leakage.
1837  * Application is expected to call add API after rte_cryptodev_configure().
1838  *
1839  * Multiple functions can be registered per queue pair & they are called
1840  * in the order they were added. The API does not restrict on maximum number
1841  * of callbacks.
1842  *
1843  * @param	dev_id		The identifier of the device.
1844  * @param	qp_id		The index of the queue pair on which ops are
1845  *				to be dequeued. The value must be in the
1846  *				range [0, nb_queue_pairs - 1] previously
1847  *				supplied to *rte_cryptodev_configure*.
1848  * @param	cb_fn		The callback function
1849  * @param	cb_arg		A generic pointer parameter which will be passed
1850  *				to each invocation of the callback function on
1851  *				this crypto device and queue pair.
1852  *
1853  * @return
1854  *   - NULL on error & rte_errno will contain the error code.
1855  *   - On success, a pointer value which can later be used to remove the
1856  *     callback.
1857  */
1858 
1859 __rte_experimental
1860 struct rte_cryptodev_cb *
1861 rte_cryptodev_add_deq_callback(uint8_t dev_id,
1862 			       uint16_t qp_id,
1863 			       rte_cryptodev_callback_fn cb_fn,
1864 			       void *cb_arg);
1865 
1866 /**
1867  * Remove a user callback function for given crypto device and queue pair.
1868  *
1869  * This function is used to remove dequeue callbacks that were added to a
1870  * crypto device queue pair using rte_cryptodev_add_deq_callback().
1871  *
1872  *
1873  *
1874  * @param	dev_id		The identifier of the device.
1875  * @param	qp_id		The index of the queue pair on which ops are
1876  *				to be dequeued. The value must be in the
1877  *				range [0, nb_queue_pairs - 1] previously
1878  *				supplied to *rte_cryptodev_configure*.
1879  * @param	cb		Pointer to user supplied callback created via
1880  *				rte_cryptodev_add_deq_callback().
1881  *
1882  * @return
1883  *   -  0: Success. Callback was removed.
1884  *   - <0: The dev_id or the qp_id is out of range, or the callback
1885  *         is NULL or not found for the crypto device queue pair.
1886  */
1887 __rte_experimental
1888 int rte_cryptodev_remove_deq_callback(uint8_t dev_id,
1889 				      uint16_t qp_id,
1890 				      struct rte_cryptodev_cb *cb);
1891 
1892 #include <rte_cryptodev_core.h>
1893 /**
1894  *
1895  * Dequeue a burst of processed crypto operations from a queue on the crypto
1896  * device. The dequeued operation are stored in *rte_crypto_op* structures
1897  * whose pointers are supplied in the *ops* array.
1898  *
1899  * The rte_cryptodev_dequeue_burst() function returns the number of ops
1900  * actually dequeued, which is the number of *rte_crypto_op* data structures
1901  * effectively supplied into the *ops* array.
1902  *
1903  * A return value equal to *nb_ops* indicates that the queue contained
1904  * at least *nb_ops* operations, and this is likely to signify that other
1905  * processed operations remain in the devices output queue. Applications
1906  * implementing a "retrieve as many processed operations as possible" policy
1907  * can check this specific case and keep invoking the
1908  * rte_cryptodev_dequeue_burst() function until a value less than
1909  * *nb_ops* is returned.
1910  *
1911  * The rte_cryptodev_dequeue_burst() function does not provide any error
1912  * notification to avoid the corresponding overhead.
1913  *
1914  * @param	dev_id		The symmetric crypto device identifier
1915  * @param	qp_id		The index of the queue pair from which to
1916  *				retrieve processed packets. The value must be
1917  *				in the range [0, nb_queue_pair - 1] previously
1918  *				supplied to rte_cryptodev_configure().
1919  * @param	ops		The address of an array of pointers to
1920  *				*rte_crypto_op* structures that must be
1921  *				large enough to store *nb_ops* pointers in it.
1922  * @param	nb_ops		The maximum number of operations to dequeue.
1923  *
1924  * @return
1925  *   - The number of operations actually dequeued, which is the number
1926  *   of pointers to *rte_crypto_op* structures effectively supplied to the
1927  *   *ops* array.
1928  */
1929 static inline uint16_t
1930 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1931 		struct rte_crypto_op **ops, uint16_t nb_ops)
1932 {
1933 	const struct rte_crypto_fp_ops *fp_ops;
1934 	void *qp;
1935 
1936 	rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1937 
1938 	fp_ops = &rte_crypto_fp_ops[dev_id];
1939 	qp = fp_ops->qp.data[qp_id];
1940 
1941 	nb_ops = fp_ops->dequeue_burst(qp, ops, nb_ops);
1942 
1943 #ifdef RTE_CRYPTO_CALLBACKS
1944 	if (unlikely(fp_ops->qp.deq_cb != NULL)) {
1945 		struct rte_cryptodev_cb_rcu *list;
1946 		struct rte_cryptodev_cb *cb;
1947 
1948 		/* __ATOMIC_RELEASE memory order was used when the
1949 		 * call back was inserted into the list.
1950 		 * Since there is a clear dependency between loading
1951 		 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1952 		 * not required.
1953 		 */
1954 		list = &fp_ops->qp.deq_cb[qp_id];
1955 		rte_rcu_qsbr_thread_online(list->qsbr, 0);
1956 		cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1957 
1958 		while (cb != NULL) {
1959 			nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1960 					cb->arg);
1961 			cb = cb->next;
1962 		};
1963 
1964 		rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1965 	}
1966 #endif
1967 	return nb_ops;
1968 }
1969 
1970 /**
1971  * Enqueue a burst of operations for processing on a crypto device.
1972  *
1973  * The rte_cryptodev_enqueue_burst() function is invoked to place
1974  * crypto operations on the queue *qp_id* of the device designated by
1975  * its *dev_id*.
1976  *
1977  * The *nb_ops* parameter is the number of operations to process which are
1978  * supplied in the *ops* array of *rte_crypto_op* structures.
1979  *
1980  * The rte_cryptodev_enqueue_burst() function returns the number of
1981  * operations it actually enqueued for processing. A return value equal to
1982  * *nb_ops* means that all packets have been enqueued.
1983  *
1984  * @param	dev_id		The identifier of the device.
1985  * @param	qp_id		The index of the queue pair which packets are
1986  *				to be enqueued for processing. The value
1987  *				must be in the range [0, nb_queue_pairs - 1]
1988  *				previously supplied to
1989  *				 *rte_cryptodev_configure*.
1990  * @param	ops		The address of an array of *nb_ops* pointers
1991  *				to *rte_crypto_op* structures which contain
1992  *				the crypto operations to be processed.
1993  * @param	nb_ops		The number of operations to process.
1994  *
1995  * @return
1996  * The number of operations actually enqueued on the crypto device. The return
1997  * value can be less than the value of the *nb_ops* parameter when the
1998  * crypto devices queue is full or if invalid parameters are specified in
1999  * a *rte_crypto_op*.
2000  */
2001 static inline uint16_t
2002 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
2003 		struct rte_crypto_op **ops, uint16_t nb_ops)
2004 {
2005 	const struct rte_crypto_fp_ops *fp_ops;
2006 	void *qp;
2007 
2008 	fp_ops = &rte_crypto_fp_ops[dev_id];
2009 	qp = fp_ops->qp.data[qp_id];
2010 #ifdef RTE_CRYPTO_CALLBACKS
2011 	if (unlikely(fp_ops->qp.enq_cb != NULL)) {
2012 		struct rte_cryptodev_cb_rcu *list;
2013 		struct rte_cryptodev_cb *cb;
2014 
2015 		/* __ATOMIC_RELEASE memory order was used when the
2016 		 * call back was inserted into the list.
2017 		 * Since there is a clear dependency between loading
2018 		 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
2019 		 * not required.
2020 		 */
2021 		list = &fp_ops->qp.enq_cb[qp_id];
2022 		rte_rcu_qsbr_thread_online(list->qsbr, 0);
2023 		cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
2024 
2025 		while (cb != NULL) {
2026 			nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
2027 					cb->arg);
2028 			cb = cb->next;
2029 		};
2030 
2031 		rte_rcu_qsbr_thread_offline(list->qsbr, 0);
2032 	}
2033 #endif
2034 
2035 	rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
2036 	return fp_ops->enqueue_burst(qp, ops, nb_ops);
2037 }
2038 
2039 
2040 
2041 #ifdef __cplusplus
2042 }
2043 #endif
2044 
2045 #endif /* _RTE_CRYPTODEV_H_ */
2046