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