1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Intel Corporation.
5 #ifndef _RTE_CRYPTODEV_H_
6 #define _RTE_CRYPTODEV_H_
9 * @file rte_cryptodev.h
11 * RTE Cryptographic Device APIs
13 * Defines RTE Crypto Device APIs for the provisioning of cipher and
14 * authentication operations.
21 #include "rte_kvargs.h"
22 #include "rte_crypto.h"
23 #include <rte_common.h>
24 #include <rte_rcu_qsbr.h>
26 #include "rte_cryptodev_trace_fp.h"
28 extern const char **rte_cyptodev_names;
32 #define CDEV_LOG_ERR(...) \
33 RTE_LOG(ERR, CRYPTODEV, \
34 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
35 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
37 #define CDEV_LOG_INFO(...) \
38 RTE_LOG(INFO, CRYPTODEV, \
39 RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
40 RTE_FMT_TAIL(__VA_ARGS__,)))
42 #define CDEV_LOG_DEBUG(...) \
43 RTE_LOG(DEBUG, CRYPTODEV, \
44 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
45 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
47 #define CDEV_PMD_TRACE(...) \
48 RTE_LOG(DEBUG, CRYPTODEV, \
49 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
50 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
53 * A macro that points to an offset from the start
54 * of the crypto operation structure (rte_crypto_op)
56 * The returned pointer is cast to type t.
59 * The crypto operation.
61 * The offset from the start of the crypto operation.
63 * The type to cast the result into.
65 #define rte_crypto_op_ctod_offset(c, t, o) \
66 ((t)((char *)(c) + (o)))
69 * A macro that returns the physical address that points
70 * to an offset from the start of the crypto operation
74 * The crypto operation.
76 * The offset from the start of the crypto operation
77 * to calculate address from.
79 #define rte_crypto_op_ctophys_offset(c, o) \
80 (rte_iova_t)((c)->phys_addr + (o))
83 * Crypto parameters range description
85 struct rte_crypto_param_range {
86 uint16_t min; /**< minimum size */
87 uint16_t max; /**< maximum size */
89 /**< if a range of sizes are supported,
90 * this parameter is used to indicate
91 * increments in byte size that are supported
92 * between the minimum and maximum
97 * Data-unit supported lengths of cipher algorithms.
98 * A bit can represent any set of data-unit sizes
99 * (single size, multiple size, range, etc).
101 #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_512_BYTES RTE_BIT32(0)
102 #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_4096_BYTES RTE_BIT32(1)
103 #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_1_MEGABYTES RTE_BIT32(2)
106 * Symmetric Crypto Capability
108 struct rte_cryptodev_symmetric_capability {
109 enum rte_crypto_sym_xform_type xform_type;
110 /**< Transform type : Authentication / Cipher / AEAD */
114 enum rte_crypto_auth_algorithm algo;
115 /**< authentication algorithm */
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 */
127 /**< Symmetric Authentication transform capabilities */
129 enum rte_crypto_cipher_algorithm algo;
130 /**< cipher algorithm */
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;
139 * Supported data-unit lengths:
140 * RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_* bits
141 * or 0 for lengths defined in the algorithm standard.
144 /**< Symmetric Cipher transform capabilities */
146 enum rte_crypto_aead_algorithm algo;
147 /**< AEAD algorithm */
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 */
163 * Asymmetric Xform Crypto Capability
166 struct rte_cryptodev_asymmetric_xform_capability {
167 enum rte_crypto_asym_xform_type xform_type;
168 /**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
172 * Bitmask for supported rte_crypto_asym_op_type or
173 * rte_crypto_asym_ke_type. Which enum is used is determined
174 * by the rte_crypto_asym_xform_type. For key exchange algorithms
175 * like Diffie-Hellman it is rte_crypto_asym_ke_type, for others
176 * it is rte_crypto_asym_op_type.
181 struct rte_crypto_param_range modlen;
182 /**< Range of modulus length supported by modulus based xform.
183 * Value 0 mean implementation default
189 * Asymmetric Crypto Capability
192 struct rte_cryptodev_asymmetric_capability {
193 struct rte_cryptodev_asymmetric_xform_capability xform_capa;
197 /** Structure used to capture a capability of a crypto device */
198 struct rte_cryptodev_capabilities {
199 enum rte_crypto_op_type op;
200 /**< Operation type */
204 struct rte_cryptodev_symmetric_capability sym;
205 /**< Symmetric operation capability parameters */
206 struct rte_cryptodev_asymmetric_capability asym;
207 /**< Asymmetric operation capability parameters */
211 /** Structure used to describe crypto algorithms */
212 struct rte_cryptodev_sym_capability_idx {
213 enum rte_crypto_sym_xform_type type;
215 enum rte_crypto_cipher_algorithm cipher;
216 enum rte_crypto_auth_algorithm auth;
217 enum rte_crypto_aead_algorithm aead;
222 * Structure used to describe asymmetric crypto xforms
223 * Each xform maps to one asym algorithm.
226 struct rte_cryptodev_asym_capability_idx {
227 enum rte_crypto_asym_xform_type type;
228 /**< Asymmetric xform (algo) type */
232 * Provide capabilities available for defined device and algorithm
234 * @param dev_id The identifier of the device.
235 * @param idx Description of crypto algorithms.
238 * - Return description of the symmetric crypto capability if exist.
239 * - Return NULL if the capability not exist.
241 const struct rte_cryptodev_symmetric_capability *
242 rte_cryptodev_sym_capability_get(uint8_t dev_id,
243 const struct rte_cryptodev_sym_capability_idx *idx);
246 * Provide capabilities available for defined device and xform
248 * @param dev_id The identifier of the device.
249 * @param idx Description of asym crypto xform.
252 * - Return description of the asymmetric crypto capability if exist.
253 * - Return NULL if the capability not exist.
256 const struct rte_cryptodev_asymmetric_xform_capability *
257 rte_cryptodev_asym_capability_get(uint8_t dev_id,
258 const struct rte_cryptodev_asym_capability_idx *idx);
261 * Check if key size and initial vector are supported
262 * in crypto cipher capability
264 * @param capability Description of the symmetric crypto capability.
265 * @param key_size Cipher key size.
266 * @param iv_size Cipher initial vector size.
269 * - Return 0 if the parameters are in range of the capability.
270 * - Return -1 if the parameters are out of range of the capability.
273 rte_cryptodev_sym_capability_check_cipher(
274 const struct rte_cryptodev_symmetric_capability *capability,
275 uint16_t key_size, uint16_t iv_size);
278 * Check if key size and initial vector are supported
279 * in crypto auth capability
281 * @param capability Description of the symmetric crypto capability.
282 * @param key_size Auth key size.
283 * @param digest_size Auth digest size.
284 * @param iv_size Auth initial vector size.
287 * - Return 0 if the parameters are in range of the capability.
288 * - Return -1 if the parameters are out of range of the capability.
291 rte_cryptodev_sym_capability_check_auth(
292 const struct rte_cryptodev_symmetric_capability *capability,
293 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
296 * Check if key, digest, AAD and initial vector sizes are supported
297 * in crypto AEAD capability
299 * @param capability Description of the symmetric crypto capability.
300 * @param key_size AEAD key size.
301 * @param digest_size AEAD digest size.
302 * @param aad_size AEAD AAD size.
303 * @param iv_size AEAD IV size.
306 * - Return 0 if the parameters are in range of the capability.
307 * - Return -1 if the parameters are out of range of the capability.
310 rte_cryptodev_sym_capability_check_aead(
311 const struct rte_cryptodev_symmetric_capability *capability,
312 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
316 * Check if op type is supported
318 * @param capability Description of the asymmetric crypto capability.
319 * @param op_type op type
322 * - Return 1 if the op type is supported
323 * - Return 0 if unsupported
327 rte_cryptodev_asym_xform_capability_check_optype(
328 const struct rte_cryptodev_asymmetric_xform_capability *capability,
329 enum rte_crypto_asym_op_type op_type);
332 * Check if modulus length is in supported range
334 * @param capability Description of the asymmetric crypto capability.
335 * @param modlen modulus length.
338 * - Return 0 if the parameters are in range of the capability.
339 * - Return -1 if the parameters are out of range of the capability.
343 rte_cryptodev_asym_xform_capability_check_modlen(
344 const struct rte_cryptodev_asymmetric_xform_capability *capability,
348 * Provide the cipher algorithm enum, given an algorithm string
350 * @param algo_enum A pointer to the cipher algorithm
352 * @param algo_string Authentication algo string
355 * - Return -1 if string is not valid
356 * - Return 0 is the string is valid
359 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
360 const char *algo_string);
363 * Provide the authentication algorithm enum, given an algorithm string
365 * @param algo_enum A pointer to the authentication algorithm
367 * @param algo_string Authentication algo string
370 * - Return -1 if string is not valid
371 * - Return 0 is the string is valid
374 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
375 const char *algo_string);
378 * Provide the AEAD algorithm enum, given an algorithm string
380 * @param algo_enum A pointer to the AEAD algorithm
382 * @param algo_string AEAD algorithm string
385 * - Return -1 if string is not valid
386 * - Return 0 is the string is valid
389 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
390 const char *algo_string);
393 * Provide the Asymmetric xform enum, given an xform string
395 * @param xform_enum A pointer to the xform type
397 * @param xform_string xform string
400 * - Return -1 if string is not valid
401 * - Return 0 if the string is valid
405 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
406 const char *xform_string);
409 /** Macro used at end of crypto PMD list */
410 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
411 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
415 * Crypto device supported feature flags
418 * New features flags should be added to the end of the list
420 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
422 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
423 /**< Symmetric crypto operations are supported */
424 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
425 /**< Asymmetric crypto operations are supported */
426 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
427 /**< Chaining symmetric crypto operations are supported */
428 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
429 /**< Utilises CPU SIMD SSE instructions */
430 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
431 /**< Utilises CPU SIMD AVX instructions */
432 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
433 /**< Utilises CPU SIMD AVX2 instructions */
434 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
435 /**< Utilises CPU AES-NI instructions */
436 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
437 /**< Operations are off-loaded to an
438 * external hardware accelerator
440 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
441 /**< Utilises CPU SIMD AVX512 instructions */
442 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL (1ULL << 9)
443 /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
446 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT (1ULL << 10)
447 /**< Out-of-place Scatter-gather (SGL) buffers are
448 * supported in input and output
450 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT (1ULL << 11)
451 /**< Out-of-place Scatter-gather (SGL) buffers are supported
452 * in input, combined with linear buffers (LB), with a
453 * single segment in output
455 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT (1ULL << 12)
456 /**< Out-of-place Scatter-gather (SGL) buffers are supported
457 * in output, combined with linear buffers (LB) in input
459 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT (1ULL << 13)
460 /**< Out-of-place linear buffers (LB) are supported in input and output */
461 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 14)
462 /**< Utilises CPU NEON instructions */
463 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 15)
464 /**< Utilises ARM CPU Cryptographic Extensions */
465 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 16)
466 /**< Support Security Protocol Processing */
467 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP (1ULL << 17)
468 /**< Support RSA Private Key OP with exponent */
469 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT (1ULL << 18)
470 /**< Support RSA Private Key OP with CRT (quintuple) Keys */
471 #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED (1ULL << 19)
472 /**< Support encrypted-digest operations where digest is appended to data */
473 #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS (1ULL << 20)
474 /**< Support asymmetric session-less operations */
475 #define RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO (1ULL << 21)
476 /**< Support symmetric cpu-crypto processing */
477 #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS (1ULL << 22)
478 /**< Support symmetric session-less operations */
479 #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA (1ULL << 23)
480 /**< Support operations on data which is not byte aligned */
481 #define RTE_CRYPTODEV_FF_SYM_RAW_DP (1ULL << 24)
482 /**< Support accelerator specific symmetric raw data-path APIs */
483 #define RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS (1ULL << 25)
484 /**< Support operations on multiple data-units message */
485 #define RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY (1ULL << 26)
486 /**< Support wrapped key in cipher xform */
487 #define RTE_CRYPTODEV_FF_SECURITY_INNER_CSUM (1ULL << 27)
488 /**< Support inner checksum computation/verification */
491 * Get the name of a crypto device feature flag
493 * @param flag The mask describing the flag.
496 * The name of this flag, or NULL if it's not a valid feature flag.
500 rte_cryptodev_get_feature_name(uint64_t flag);
502 /** Crypto device information */
503 struct rte_cryptodev_info {
504 const char *driver_name; /**< Driver name. */
505 uint8_t driver_id; /**< Driver identifier */
506 struct rte_device *device; /**< Generic device information. */
508 uint64_t feature_flags;
509 /**< Feature flags exposes HW/SW features for the given device */
511 const struct rte_cryptodev_capabilities *capabilities;
512 /**< Array of devices supported capabilities */
514 unsigned max_nb_queue_pairs;
515 /**< Maximum number of queues pairs supported by device. */
517 uint16_t min_mbuf_headroom_req;
518 /**< Minimum mbuf headroom required by device */
520 uint16_t min_mbuf_tailroom_req;
521 /**< Minimum mbuf tailroom required by device */
524 unsigned max_nb_sessions;
525 /**< Maximum number of sessions supported by device.
526 * If 0, the device does not have any limitation in
527 * number of sessions that can be used.
532 #define RTE_CRYPTODEV_DETACHED (0)
533 #define RTE_CRYPTODEV_ATTACHED (1)
535 /** Definitions of Crypto device event types */
536 enum rte_cryptodev_event_type {
537 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
538 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
539 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
542 /** Crypto device queue pair configuration structure. */
543 struct rte_cryptodev_qp_conf {
544 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
545 struct rte_mempool *mp_session;
546 /**< The mempool for creating session in sessionless mode */
547 struct rte_mempool *mp_session_private;
548 /**< The mempool for creating sess private data in sessionless mode */
552 * Function type used for processing crypto ops when enqueue/dequeue burst is
555 * The callback function is called on enqueue/dequeue burst immediately.
557 * @param dev_id The identifier of the device.
558 * @param qp_id The index of the queue pair on which ops are
559 * enqueued/dequeued. The value must be in the
560 * range [0, nb_queue_pairs - 1] previously
561 * supplied to *rte_cryptodev_configure*.
562 * @param ops The address of an array of *nb_ops* pointers
563 * to *rte_crypto_op* structures which contain
564 * the crypto operations to be processed.
565 * @param nb_ops The number of operations to process.
566 * @param user_param The arbitrary user parameter passed in by the
567 * application when the callback was originally
569 * @return The number of ops to be enqueued to the
572 typedef uint16_t (*rte_cryptodev_callback_fn)(uint16_t dev_id, uint16_t qp_id,
573 struct rte_crypto_op **ops, uint16_t nb_ops, void *user_param);
576 * Typedef for application callback function to be registered by application
577 * software for notification of device events
579 * @param dev_id Crypto device identifier
580 * @param event Crypto device event to register for notification of.
581 * @param cb_arg User specified parameter to be passed as to passed to
582 * users callback function.
584 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
585 enum rte_cryptodev_event_type event, void *cb_arg);
588 /** Crypto Device statistics */
589 struct rte_cryptodev_stats {
590 uint64_t enqueued_count;
591 /**< Count of all operations enqueued */
592 uint64_t dequeued_count;
593 /**< Count of all operations dequeued */
595 uint64_t enqueue_err_count;
596 /**< Total error count on operations enqueued */
597 uint64_t dequeue_err_count;
598 /**< Total error count on operations dequeued */
601 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
602 /**< Max length of name of crypto PMD */
605 * Get the device identifier for the named crypto device.
607 * @param name device name to select the device structure.
610 * - Returns crypto device identifier on success.
611 * - Return -1 on failure to find named crypto device.
614 rte_cryptodev_get_dev_id(const char *name);
617 * Get the crypto device name given a device identifier.
620 * The identifier of the device
623 * - Returns crypto device name.
624 * - Returns NULL if crypto device is not present.
627 rte_cryptodev_name_get(uint8_t dev_id);
630 * Get the total number of crypto devices that have been successfully
634 * - The total number of usable crypto devices.
637 rte_cryptodev_count(void);
640 * Get number of crypto device defined type.
642 * @param driver_id driver identifier.
645 * Returns number of crypto device.
648 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
651 * Get number and identifiers of attached crypto devices that
652 * use the same crypto driver.
654 * @param driver_name driver name.
655 * @param devices output devices identifiers.
656 * @param nb_devices maximal number of devices.
659 * Returns number of attached crypto device.
662 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
665 * Return the NUMA socket to which a device is connected
668 * The identifier of the device
670 * The NUMA socket id to which the device is connected or
671 * a default of zero if the socket could not be determined.
672 * -1 if returned is the dev_id value is out of range.
675 rte_cryptodev_socket_id(uint8_t dev_id);
677 /** Crypto device configuration structure */
678 struct rte_cryptodev_config {
679 int socket_id; /**< Socket to allocate resources on */
680 uint16_t nb_queue_pairs;
681 /**< Number of queue pairs to configure on device */
683 /**< Feature flags to be disabled. Only the following features are
684 * allowed to be disabled,
685 * - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
686 * - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
687 * - RTE_CRYTPODEV_FF_SECURITY
692 * Configure a device.
694 * This function must be invoked first before any other function in the
695 * API. This function can also be re-invoked when a device is in the
698 * @param dev_id The identifier of the device to configure.
699 * @param config The crypto device configuration structure.
702 * - 0: Success, device configured.
703 * - <0: Error code returned by the driver configuration function.
706 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
711 * The device start step is the last one and consists of setting the configured
712 * offload features and in starting the transmit and the receive units of the
714 * On success, all basic functions exported by the API (link status,
715 * receive/transmit, and so on) can be invoked.
718 * The identifier of the device.
720 * - 0: Success, device started.
721 * - <0: Error code of the driver device start function.
724 rte_cryptodev_start(uint8_t dev_id);
727 * Stop an device. The device can be restarted with a call to
728 * rte_cryptodev_start()
730 * @param dev_id The identifier of the device.
733 rte_cryptodev_stop(uint8_t dev_id);
736 * Close an device. The device cannot be restarted!
738 * @param dev_id The identifier of the device.
741 * - 0 on successfully closing device
742 * - <0 on failure to close device
745 rte_cryptodev_close(uint8_t dev_id);
748 * Allocate and set up a receive queue pair for a device.
751 * @param dev_id The identifier of the device.
752 * @param queue_pair_id The index of the queue pairs to set up. The
753 * value must be in the range [0, nb_queue_pair
754 * - 1] previously supplied to
755 * rte_cryptodev_configure().
756 * @param qp_conf The pointer to the configuration data to be
757 * used for the queue pair.
758 * @param socket_id The *socket_id* argument is the socket
759 * identifier in case of NUMA. The value can be
760 * *SOCKET_ID_ANY* if there is no NUMA constraint
761 * for the DMA memory allocated for the receive
765 * - 0: Success, queue pair correctly set up.
766 * - <0: Queue pair configuration failed
769 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
770 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
773 * Get the status of queue pairs setup on a specific crypto device
775 * @param dev_id Crypto device identifier.
776 * @param queue_pair_id The index of the queue pairs to set up. The
777 * value must be in the range [0, nb_queue_pair
778 * - 1] previously supplied to
779 * rte_cryptodev_configure().
781 * - 0: qp was not configured
782 * - 1: qp was configured
783 * - -EINVAL: device was not configured
787 rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id);
790 * Get the number of queue pairs on a specific crypto device
792 * @param dev_id Crypto device identifier.
794 * - The number of configured queue pairs.
797 rte_cryptodev_queue_pair_count(uint8_t dev_id);
801 * Retrieve the general I/O statistics of a device.
803 * @param dev_id The identifier of the device.
804 * @param stats A pointer to a structure of type
805 * *rte_cryptodev_stats* to be filled with the
806 * values of device counters.
808 * - Zero if successful.
809 * - Non-zero otherwise.
812 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
815 * Reset the general I/O statistics of a device.
817 * @param dev_id The identifier of the device.
820 rte_cryptodev_stats_reset(uint8_t dev_id);
823 * Retrieve the contextual information of a device.
825 * @param dev_id The identifier of the device.
826 * @param dev_info A pointer to a structure of type
827 * *rte_cryptodev_info* to be filled with the
828 * contextual information of the device.
830 * @note The capabilities field of dev_info is set to point to the first
831 * element of an array of struct rte_cryptodev_capabilities. The element after
832 * the last valid element has it's op field set to
833 * RTE_CRYPTO_OP_TYPE_UNDEFINED.
836 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
840 * Register a callback function for specific device id.
842 * @param dev_id Device id.
843 * @param event Event interested.
844 * @param cb_fn User supplied callback function to be called.
845 * @param cb_arg Pointer to the parameters for the registered
849 * - On success, zero.
850 * - On failure, a negative value.
853 rte_cryptodev_callback_register(uint8_t dev_id,
854 enum rte_cryptodev_event_type event,
855 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
858 * Unregister a callback function for specific device id.
860 * @param dev_id The device identifier.
861 * @param event Event interested.
862 * @param cb_fn User supplied callback function to be called.
863 * @param cb_arg Pointer to the parameters for the registered
867 * - On success, zero.
868 * - On failure, a negative value.
871 rte_cryptodev_callback_unregister(uint8_t dev_id,
872 enum rte_cryptodev_event_type event,
873 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
875 struct rte_cryptodev_callback;
877 /** Structure to keep track of registered callbacks */
878 RTE_TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
881 * Structure used to hold information about the callbacks to be called for a
882 * queue pair on enqueue/dequeue.
884 struct rte_cryptodev_cb {
885 struct rte_cryptodev_cb *next;
886 /**< Pointer to next callback */
887 rte_cryptodev_callback_fn fn;
888 /**< Pointer to callback function */
890 /**< Pointer to argument */
895 * Structure used to hold information about the RCU for a queue pair.
897 struct rte_cryptodev_cb_rcu {
898 struct rte_cryptodev_cb *next;
899 /**< Pointer to next callback */
900 struct rte_rcu_qsbr *qsbr;
901 /**< RCU QSBR variable per queue pair */
905 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
907 /** Cryptodev symmetric crypto session
908 * Each session is derived from a fixed xform chain. Therefore each session
909 * has a fixed algo, key, op-type, digest_len etc.
911 struct rte_cryptodev_sym_session {
912 uint64_t opaque_data;
913 /**< Can be used for external metadata */
915 /**< number of elements in sess_data array */
916 uint16_t user_data_sz;
917 /**< session user data will be placed after sess_data */
918 __extension__ struct {
922 /**< Driver specific session material, variable size */
926 * Create a symmetric session mempool.
929 * The unique mempool name.
931 * The number of elements in the mempool.
933 * The size of the element. This value will be ignored if it is smaller than
934 * the minimum session header size required for the system. For the user who
935 * want to use the same mempool for sym session and session private data it
936 * can be the maximum value of all existing devices' private data and session
939 * The number of per-lcore cache elements
941 * The private data size of each session.
943 * The *socket_id* argument is the socket identifier in the case of
944 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
945 * constraint for the reserved zone.
948 * - On success return size of the session
949 * - On failure returns 0
953 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
954 uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
958 * Create an asymmetric session mempool.
961 * The unique mempool name.
963 * The number of elements in the mempool.
965 * The number of per-lcore cache elements
966 * @param user_data_size
967 * The size of user data to be placed after session private data.
969 * The *socket_id* argument is the socket identifier in the case of
970 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
971 * constraint for the reserved zone.
974 * - On success return mempool
975 * - On failure returns NULL
979 rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
980 uint32_t cache_size, uint16_t user_data_size, int socket_id);
983 * Create symmetric crypto session header (generic with no private data)
985 * @param mempool Symmetric session mempool to allocate session
988 * - On success return pointer to sym-session
989 * - On failure returns NULL
991 struct rte_cryptodev_sym_session *
992 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
995 * Create and initialise an asymmetric crypto session structure.
996 * Calls the PMD to configure the private session data.
998 * @param dev_id ID of device that we want the session to be used on
999 * @param xforms Asymmetric crypto transform operations to apply on flow
1000 * processed with this session
1001 * @param mp mempool to allocate asymmetric session
1003 * @param session void ** for session to be used
1007 * - -EINVAL on invalid arguments.
1008 * - -ENOMEM on memory error for session allocation.
1009 * - -ENOTSUP if device doesn't support session configuration.
1013 rte_cryptodev_asym_session_create(uint8_t dev_id,
1014 struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
1018 * Frees symmetric crypto session header, after checking that all
1019 * the device private data has been freed, returning it
1020 * to its original mempool.
1022 * @param sess Session header to be freed.
1025 * - 0 if successful.
1026 * - -EINVAL if session is NULL.
1027 * - -EBUSY if not all device private data has been freed.
1030 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
1033 * Clears and frees asymmetric crypto session header and private data,
1034 * returning it to its original mempool.
1036 * @param dev_id ID of device that uses the asymmetric session.
1037 * @param sess Session header to be freed.
1040 * - 0 if successful.
1041 * - -EINVAL if device is invalid or session is NULL.
1045 rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
1048 * Fill out private data for the device id, based on its device type.
1050 * @param dev_id ID of device that we want the session to be used on
1051 * @param sess Session where the private data will be attached to
1052 * @param xforms Symmetric crypto transform operations to apply on flow
1053 * processed with this session
1054 * @param mempool Mempool where the private data is allocated.
1057 * - On success, zero.
1058 * - -EINVAL if input parameters are invalid.
1059 * - -ENOTSUP if crypto device does not support the crypto transform or
1060 * does not support symmetric operations.
1061 * - -ENOMEM if the private session could not be allocated.
1064 rte_cryptodev_sym_session_init(uint8_t dev_id,
1065 struct rte_cryptodev_sym_session *sess,
1066 struct rte_crypto_sym_xform *xforms,
1067 struct rte_mempool *mempool);
1070 * Frees private data for the device id, based on its device type,
1071 * returning it to its mempool. It is the application's responsibility
1072 * to ensure that private session data is not cleared while there are
1073 * still in-flight operations using it.
1075 * @param dev_id ID of device that uses the session.
1076 * @param sess Session containing the reference to the private data
1079 * - 0 if successful.
1080 * - -EINVAL if device is invalid or session is NULL.
1081 * - -ENOTSUP if crypto device does not support symmetric operations.
1084 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1085 struct rte_cryptodev_sym_session *sess);
1088 * Get the size of the header session, for all registered drivers excluding
1089 * the user data size.
1092 * Size of the symmetric header session.
1095 rte_cryptodev_sym_get_header_session_size(void);
1098 * Get the size of the header session from created session.
1101 * The sym cryptodev session pointer
1104 * - If sess is not NULL, return the size of the header session including
1105 * the private data size defined within sess.
1106 * - If sess is NULL, return 0.
1110 rte_cryptodev_sym_get_existing_header_session_size(
1111 struct rte_cryptodev_sym_session *sess);
1114 * Get the size of the asymmetric session header.
1117 * Size of the asymmetric header session.
1121 rte_cryptodev_asym_get_header_session_size(void);
1124 * Get the size of the private symmetric session data
1127 * @param dev_id The device identifier.
1130 * - Size of the private data, if successful
1131 * - 0 if device is invalid or does not have private
1135 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
1138 * Get the size of the private data for asymmetric session
1141 * @param dev_id The device identifier.
1144 * - Size of the asymmetric private data, if successful
1145 * - 0 if device is invalid or does not have private session
1149 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
1152 * Validate if the crypto device index is valid attached crypto device.
1154 * @param dev_id Crypto device index.
1157 * - If the device index is valid (1) or not (0).
1160 rte_cryptodev_is_valid_dev(uint8_t dev_id);
1163 * Provide driver identifier.
1166 * The pointer to a driver name.
1168 * The driver type identifier or -1 if no driver found
1170 int rte_cryptodev_driver_id_get(const char *name);
1173 * Provide driver name.
1176 * The driver identifier.
1178 * The driver name or null if no driver found
1180 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1183 * Store user data in a session.
1185 * @param sess Session pointer allocated by
1186 * *rte_cryptodev_sym_session_create*.
1187 * @param data Pointer to the user data.
1188 * @param size Size of the user data.
1191 * - On success, zero.
1192 * - On failure, a negative value.
1196 rte_cryptodev_sym_session_set_user_data(
1197 struct rte_cryptodev_sym_session *sess,
1202 * Get user data stored in a session.
1204 * @param sess Session pointer allocated by
1205 * *rte_cryptodev_sym_session_create*.
1208 * - On success return pointer to user data.
1209 * - On failure returns NULL.
1213 rte_cryptodev_sym_session_get_user_data(
1214 struct rte_cryptodev_sym_session *sess);
1217 * Store user data in an asymmetric session.
1219 * @param sess Session pointer allocated by
1220 * *rte_cryptodev_asym_session_create*.
1221 * @param data Pointer to the user data.
1222 * @param size Size of the user data.
1225 * - On success, zero.
1226 * - -EINVAL if the session pointer is invalid.
1227 * - -ENOMEM if the available user data size is smaller than the size parameter.
1231 rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
1234 * Get user data stored in an asymmetric session.
1236 * @param sess Session pointer allocated by
1237 * *rte_cryptodev_asym_session_create*.
1240 * - On success return pointer to user data.
1241 * - On failure returns NULL.
1245 rte_cryptodev_asym_session_get_user_data(void *sess);
1248 * Perform actual crypto processing (encrypt/digest or auth/decrypt)
1249 * on user provided data.
1251 * @param dev_id The device identifier.
1252 * @param sess Cryptodev session structure
1253 * @param ofs Start and stop offsets for auth and cipher operations
1254 * @param vec Vectorized operation descriptor
1257 * - Returns number of successfully processed packets.
1261 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
1262 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
1263 struct rte_crypto_sym_vec *vec);
1266 * Get the size of the raw data-path context buffer.
1268 * @param dev_id The device identifier.
1271 * - If the device supports raw data-path APIs, return the context size.
1272 * - If the device does not support the APIs, return -1.
1276 rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id);
1279 * Set session event meta data
1281 * @param dev_id The device identifier.
1282 * @param sess Crypto or security session.
1283 * @param op_type Operation type.
1284 * @param sess_type Session type.
1285 * @param ev_mdata Pointer to the event crypto meta data
1286 * (aka *union rte_event_crypto_metadata*)
1287 * @param size Size of ev_mdata.
1290 * - On success, zero.
1291 * - On failure, a negative value.
1295 rte_cryptodev_session_event_mdata_set(uint8_t dev_id, void *sess,
1296 enum rte_crypto_op_type op_type,
1297 enum rte_crypto_op_sess_type sess_type,
1298 void *ev_mdata, uint16_t size);
1301 * Union of different crypto session types, including session-less xform
1304 union rte_cryptodev_session_ctx {
1305 struct rte_cryptodev_sym_session *crypto_sess;
1306 struct rte_crypto_sym_xform *xform;
1307 struct rte_security_session *sec_sess;
1311 * Enqueue a vectorized operation descriptor into the device queue but the
1312 * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1315 * @param qp Driver specific queue pair data.
1316 * @param drv_ctx Driver specific context data.
1317 * @param vec Vectorized operation descriptor.
1318 * @param ofs Start and stop offsets for auth and cipher
1320 * @param user_data The array of user data for dequeue later.
1321 * @param enqueue_status Driver written value to specify the
1322 * enqueue status. Possible values:
1323 * - 1: The number of operations returned are
1324 * enqueued successfully.
1325 * - 0: The number of operations returned are
1326 * cached into the queue but are not processed
1327 * until rte_cryptodev_raw_enqueue_done() is
1329 * - negative integer: Error occurred.
1331 * - The number of operations in the descriptor successfully enqueued or
1332 * cached into the queue but not enqueued yet, depends on the
1333 * "enqueue_status" value.
1335 typedef uint32_t (*cryptodev_sym_raw_enqueue_burst_t)(
1336 void *qp, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1337 union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status);
1340 * Enqueue single raw data vector into the device queue but the driver may or
1341 * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1343 * @param qp Driver specific queue pair data.
1344 * @param drv_ctx Driver specific context data.
1345 * @param data_vec The buffer data vector.
1346 * @param n_data_vecs Number of buffer data vectors.
1347 * @param ofs Start and stop offsets for auth and cipher
1349 * @param iv IV virtual and IOVA addresses
1350 * @param digest digest virtual and IOVA addresses
1351 * @param aad_or_auth_iv AAD or auth IV virtual and IOVA addresses,
1352 * depends on the algorithm used.
1353 * @param user_data The user data.
1355 * - 1: The data vector is enqueued successfully.
1356 * - 0: The data vector is cached into the queue but is not processed
1357 * until rte_cryptodev_raw_enqueue_done() is called.
1358 * - negative integer: failure.
1360 typedef int (*cryptodev_sym_raw_enqueue_t)(
1361 void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1362 uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1363 struct rte_crypto_va_iova_ptr *iv,
1364 struct rte_crypto_va_iova_ptr *digest,
1365 struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1369 * Inform the cryptodev queue pair to start processing or finish dequeuing all
1370 * enqueued/dequeued operations.
1372 * @param qp Driver specific queue pair data.
1373 * @param drv_ctx Driver specific context data.
1374 * @param n The total number of processed operations.
1376 * - On success return 0.
1377 * - On failure return negative integer.
1379 typedef int (*cryptodev_sym_raw_operation_done_t)(void *qp, uint8_t *drv_ctx,
1383 * Typedef that the user provided for the driver to get the dequeue count.
1384 * The function may return a fixed number or the number parsed from the user
1385 * data stored in the first processed operation.
1387 * @param user_data Dequeued user data.
1389 * - The number of operations to be dequeued.
1391 typedef uint32_t (*rte_cryptodev_raw_get_dequeue_count_t)(void *user_data);
1394 * Typedef that the user provided to deal with post dequeue operation, such
1395 * as filling status.
1397 * @param user_data Dequeued user data.
1398 * @param index Index number of the processed descriptor.
1399 * @param is_op_success Operation status provided by the driver.
1401 typedef void (*rte_cryptodev_raw_post_dequeue_t)(void *user_data,
1402 uint32_t index, uint8_t is_op_success);
1405 * Dequeue a burst of symmetric crypto processing.
1407 * @param qp Driver specific queue pair data.
1408 * @param drv_ctx Driver specific context data.
1409 * @param get_dequeue_count User provided callback function to
1410 * obtain dequeue operation count.
1411 * @param max_nb_to_dequeue When get_dequeue_count is NULL this
1412 * value is used to pass the maximum
1413 * number of operations to be dequeued.
1414 * @param post_dequeue User provided callback function to
1415 * post-process a dequeued operation.
1416 * @param out_user_data User data pointer array to be retrieve
1417 * from device queue. In case of
1418 * *is_user_data_array* is set there
1419 * should be enough room to store all
1421 * @param is_user_data_array Set 1 if every dequeued user data will
1422 * be written into out_user_data array.
1423 * Set 0 if only the first user data will
1424 * be written into out_user_data array.
1425 * @param n_success Driver written value to specific the
1426 * total successful operations count.
1427 * @param dequeue_status Driver written value to specify the
1428 * dequeue status. Possible values:
1429 * - 1: Successfully dequeued the number
1430 * of operations returned. The user
1431 * data previously set during enqueue
1432 * is stored in the "out_user_data".
1433 * - 0: The number of operations returned
1434 * are completed and the user data is
1435 * stored in the "out_user_data", but
1436 * they are not freed from the queue
1438 * rte_cryptodev_raw_dequeue_done()
1440 * - negative integer: Error occurred.
1442 * - The number of operations dequeued or completed but not freed from the
1443 * queue, depends on "dequeue_status" value.
1445 typedef uint32_t (*cryptodev_sym_raw_dequeue_burst_t)(void *qp,
1447 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1448 uint32_t max_nb_to_dequeue,
1449 rte_cryptodev_raw_post_dequeue_t post_dequeue,
1450 void **out_user_data, uint8_t is_user_data_array,
1451 uint32_t *n_success, int *dequeue_status);
1454 * Dequeue a symmetric crypto processing.
1456 * @param qp Driver specific queue pair data.
1457 * @param drv_ctx Driver specific context data.
1458 * @param dequeue_status Driver written value to specify the
1459 * dequeue status. Possible values:
1460 * - 1: Successfully dequeued a operation.
1461 * The user data is returned.
1462 * - 0: The first operation in the queue
1463 * is completed and the user data
1464 * previously set during enqueue is
1465 * returned, but it is not freed from
1467 * rte_cryptodev_raw_dequeue_done() is
1469 * - negative integer: Error occurred.
1470 * @param op_status Driver written value to specify
1473 * - The user data pointer retrieved from device queue or NULL if no
1474 * operation is ready for dequeue.
1476 typedef void * (*cryptodev_sym_raw_dequeue_t)(
1477 void *qp, uint8_t *drv_ctx, int *dequeue_status,
1478 enum rte_crypto_op_status *op_status);
1481 * Context data for raw data-path API crypto process. The buffer of this
1482 * structure is to be allocated by the user application with the size equal
1483 * or bigger than rte_cryptodev_get_raw_dp_ctx_size() returned value.
1485 struct rte_crypto_raw_dp_ctx {
1488 cryptodev_sym_raw_enqueue_t enqueue;
1489 cryptodev_sym_raw_enqueue_burst_t enqueue_burst;
1490 cryptodev_sym_raw_operation_done_t enqueue_done;
1491 cryptodev_sym_raw_dequeue_t dequeue;
1492 cryptodev_sym_raw_dequeue_burst_t dequeue_burst;
1493 cryptodev_sym_raw_operation_done_t dequeue_done;
1495 /* Driver specific context data */
1496 __extension__ uint8_t drv_ctx_data[];
1500 * Configure raw data-path context data.
1503 * After the context data is configured, the user should call
1504 * rte_cryptodev_raw_attach_session() before using it in
1505 * rte_cryptodev_raw_enqueue/dequeue function call.
1507 * @param dev_id The device identifier.
1508 * @param qp_id The index of the queue pair from which to
1509 * retrieve processed packets. The value must be
1510 * in the range [0, nb_queue_pair - 1] previously
1511 * supplied to rte_cryptodev_configure().
1512 * @param ctx The raw data-path context data.
1513 * @param sess_type session type.
1514 * @param session_ctx Session context data.
1515 * @param is_update Set 0 if it is to initialize the ctx.
1516 * Set 1 if ctx is initialized and only to update
1517 * session context data.
1519 * - On success return 0.
1520 * - On failure return negative integer.
1524 rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
1525 struct rte_crypto_raw_dp_ctx *ctx,
1526 enum rte_crypto_op_sess_type sess_type,
1527 union rte_cryptodev_session_ctx session_ctx,
1531 * Enqueue a vectorized operation descriptor into the device queue but the
1532 * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1535 * @param ctx The initialized raw data-path context data.
1536 * @param vec Vectorized operation descriptor.
1537 * @param ofs Start and stop offsets for auth and cipher
1539 * @param user_data The array of user data for dequeue later.
1540 * @param enqueue_status Driver written value to specify the
1541 * enqueue status. Possible values:
1542 * - 1: The number of operations returned are
1543 * enqueued successfully.
1544 * - 0: The number of operations returned are
1545 * cached into the queue but are not processed
1546 * until rte_cryptodev_raw_enqueue_done() is
1548 * - negative integer: Error occurred.
1550 * - The number of operations in the descriptor successfully enqueued or
1551 * cached into the queue but not enqueued yet, depends on the
1552 * "enqueue_status" value.
1556 rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1557 struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
1558 void **user_data, int *enqueue_status);
1561 * Enqueue single raw data vector into the device queue but the driver may or
1562 * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1564 * @param ctx The initialized raw data-path context data.
1565 * @param data_vec The buffer data vector.
1566 * @param n_data_vecs Number of buffer data vectors.
1567 * @param ofs Start and stop offsets for auth and cipher
1569 * @param iv IV virtual and IOVA addresses
1570 * @param digest digest virtual and IOVA addresses
1571 * @param aad_or_auth_iv AAD or auth IV virtual and IOVA addresses,
1572 * depends on the algorithm used.
1573 * @param user_data The user data.
1575 * - 1: The data vector is enqueued successfully.
1576 * - 0: The data vector is cached into the queue but is not processed
1577 * until rte_cryptodev_raw_enqueue_done() is called.
1578 * - negative integer: failure.
1581 static __rte_always_inline int
1582 rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx *ctx,
1583 struct rte_crypto_vec *data_vec, uint16_t n_data_vecs,
1584 union rte_crypto_sym_ofs ofs,
1585 struct rte_crypto_va_iova_ptr *iv,
1586 struct rte_crypto_va_iova_ptr *digest,
1587 struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1590 return (*ctx->enqueue)(ctx->qp_data, ctx->drv_ctx_data, data_vec,
1591 n_data_vecs, ofs, iv, digest, aad_or_auth_iv, user_data);
1595 * Start processing all enqueued operations from last
1596 * rte_cryptodev_configure_raw_dp_ctx() call.
1598 * @param ctx The initialized raw data-path context data.
1599 * @param n The number of operations cached.
1601 * - On success return 0.
1602 * - On failure return negative integer.
1606 rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
1610 * Dequeue a burst of symmetric crypto processing.
1612 * @param ctx The initialized raw data-path context
1614 * @param get_dequeue_count User provided callback function to
1615 * obtain dequeue operation count.
1616 * @param max_nb_to_dequeue When get_dequeue_count is NULL this
1617 * value is used to pass the maximum
1618 * number of operations to be dequeued.
1619 * @param post_dequeue User provided callback function to
1620 * post-process a dequeued operation.
1621 * @param out_user_data User data pointer array to be retrieve
1622 * from device queue. In case of
1623 * *is_user_data_array* is set there
1624 * should be enough room to store all
1626 * @param is_user_data_array Set 1 if every dequeued user data will
1627 * be written into out_user_data array.
1628 * Set 0 if only the first user data will
1629 * be written into out_user_data array.
1630 * @param n_success Driver written value to specific the
1631 * total successful operations count.
1632 * @param dequeue_status Driver written value to specify the
1633 * dequeue status. Possible values:
1634 * - 1: Successfully dequeued the number
1635 * of operations returned. The user
1636 * data previously set during enqueue
1637 * is stored in the "out_user_data".
1638 * - 0: The number of operations returned
1639 * are completed and the user data is
1640 * stored in the "out_user_data", but
1641 * they are not freed from the queue
1643 * rte_cryptodev_raw_dequeue_done()
1645 * - negative integer: Error occurred.
1647 * - The number of operations dequeued or completed but not freed from the
1648 * queue, depends on "dequeue_status" value.
1652 rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1653 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1654 uint32_t max_nb_to_dequeue,
1655 rte_cryptodev_raw_post_dequeue_t post_dequeue,
1656 void **out_user_data, uint8_t is_user_data_array,
1657 uint32_t *n_success, int *dequeue_status);
1660 * Dequeue a symmetric crypto processing.
1662 * @param ctx The initialized raw data-path context
1664 * @param dequeue_status Driver written value to specify the
1665 * dequeue status. Possible values:
1666 * - 1: Successfully dequeued a operation.
1667 * The user data is returned.
1668 * - 0: The first operation in the queue
1669 * is completed and the user data
1670 * previously set during enqueue is
1671 * returned, but it is not freed from
1673 * rte_cryptodev_raw_dequeue_done() is
1675 * - negative integer: Error occurred.
1676 * @param op_status Driver written value to specify
1679 * - The user data pointer retrieved from device queue or NULL if no
1680 * operation is ready for dequeue.
1683 static __rte_always_inline void *
1684 rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx *ctx,
1685 int *dequeue_status, enum rte_crypto_op_status *op_status)
1687 return (*ctx->dequeue)(ctx->qp_data, ctx->drv_ctx_data, dequeue_status,
1692 * Inform the queue pair dequeue operations is finished.
1694 * @param ctx The initialized raw data-path context data.
1695 * @param n The number of operations.
1697 * - On success return 0.
1698 * - On failure return negative integer.
1702 rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
1706 * Add a user callback for a given crypto device and queue pair which will be
1707 * called on crypto ops enqueue.
1709 * This API configures a function to be called for each burst of crypto ops
1710 * received on a given crypto device queue pair. The return value is a pointer
1711 * that can be used later to remove the callback using
1712 * rte_cryptodev_remove_enq_callback().
1714 * Callbacks registered by application would not survive
1715 * rte_cryptodev_configure() as it reinitializes the callback list.
1716 * It is user responsibility to remove all installed callbacks before
1717 * calling rte_cryptodev_configure() to avoid possible memory leakage.
1718 * Application is expected to call add API after rte_cryptodev_configure().
1720 * Multiple functions can be registered per queue pair & they are called
1721 * in the order they were added. The API does not restrict on maximum number
1724 * @param dev_id The identifier of the device.
1725 * @param qp_id The index of the queue pair on which ops are
1726 * to be enqueued for processing. The value
1727 * must be in the range [0, nb_queue_pairs - 1]
1728 * previously supplied to
1729 * *rte_cryptodev_configure*.
1730 * @param cb_fn The callback function
1731 * @param cb_arg A generic pointer parameter which will be passed
1732 * to each invocation of the callback function on
1733 * this crypto device and queue pair.
1736 * - NULL on error & rte_errno will contain the error code.
1737 * - On success, a pointer value which can later be used to remove the
1742 struct rte_cryptodev_cb *
1743 rte_cryptodev_add_enq_callback(uint8_t dev_id,
1745 rte_cryptodev_callback_fn cb_fn,
1749 * Remove a user callback function for given crypto device and queue pair.
1751 * This function is used to remove enqueue callbacks that were added to a
1752 * crypto device queue pair using rte_cryptodev_add_enq_callback().
1756 * @param dev_id The identifier of the device.
1757 * @param qp_id The index of the queue pair on which ops are
1758 * to be enqueued. The value must be in the
1759 * range [0, nb_queue_pairs - 1] previously
1760 * supplied to *rte_cryptodev_configure*.
1761 * @param cb Pointer to user supplied callback created via
1762 * rte_cryptodev_add_enq_callback().
1765 * - 0: Success. Callback was removed.
1766 * - <0: The dev_id or the qp_id is out of range, or the callback
1767 * is NULL or not found for the crypto device queue pair.
1771 int rte_cryptodev_remove_enq_callback(uint8_t dev_id,
1773 struct rte_cryptodev_cb *cb);
1776 * Add a user callback for a given crypto device and queue pair which will be
1777 * called on crypto ops dequeue.
1779 * This API configures a function to be called for each burst of crypto ops
1780 * received on a given crypto device queue pair. The return value is a pointer
1781 * that can be used later to remove the callback using
1782 * rte_cryptodev_remove_deq_callback().
1784 * Callbacks registered by application would not survive
1785 * rte_cryptodev_configure() as it reinitializes the callback list.
1786 * It is user responsibility to remove all installed callbacks before
1787 * calling rte_cryptodev_configure() to avoid possible memory leakage.
1788 * Application is expected to call add API after rte_cryptodev_configure().
1790 * Multiple functions can be registered per queue pair & they are called
1791 * in the order they were added. The API does not restrict on maximum number
1794 * @param dev_id The identifier of the device.
1795 * @param qp_id The index of the queue pair on which ops are
1796 * to be dequeued. The value must be in the
1797 * range [0, nb_queue_pairs - 1] previously
1798 * supplied to *rte_cryptodev_configure*.
1799 * @param cb_fn The callback function
1800 * @param cb_arg A generic pointer parameter which will be passed
1801 * to each invocation of the callback function on
1802 * this crypto device and queue pair.
1805 * - NULL on error & rte_errno will contain the error code.
1806 * - On success, a pointer value which can later be used to remove the
1811 struct rte_cryptodev_cb *
1812 rte_cryptodev_add_deq_callback(uint8_t dev_id,
1814 rte_cryptodev_callback_fn cb_fn,
1818 * Remove a user callback function for given crypto device and queue pair.
1820 * This function is used to remove dequeue callbacks that were added to a
1821 * crypto device queue pair using rte_cryptodev_add_deq_callback().
1825 * @param dev_id The identifier of the device.
1826 * @param qp_id The index of the queue pair on which ops are
1827 * to be dequeued. The value must be in the
1828 * range [0, nb_queue_pairs - 1] previously
1829 * supplied to *rte_cryptodev_configure*.
1830 * @param cb Pointer to user supplied callback created via
1831 * rte_cryptodev_add_deq_callback().
1834 * - 0: Success. Callback was removed.
1835 * - <0: The dev_id or the qp_id is out of range, or the callback
1836 * is NULL or not found for the crypto device queue pair.
1839 int rte_cryptodev_remove_deq_callback(uint8_t dev_id,
1841 struct rte_cryptodev_cb *cb);
1843 #include <rte_cryptodev_core.h>
1846 * Dequeue a burst of processed crypto operations from a queue on the crypto
1847 * device. The dequeued operation are stored in *rte_crypto_op* structures
1848 * whose pointers are supplied in the *ops* array.
1850 * The rte_cryptodev_dequeue_burst() function returns the number of ops
1851 * actually dequeued, which is the number of *rte_crypto_op* data structures
1852 * effectively supplied into the *ops* array.
1854 * A return value equal to *nb_ops* indicates that the queue contained
1855 * at least *nb_ops* operations, and this is likely to signify that other
1856 * processed operations remain in the devices output queue. Applications
1857 * implementing a "retrieve as many processed operations as possible" policy
1858 * can check this specific case and keep invoking the
1859 * rte_cryptodev_dequeue_burst() function until a value less than
1860 * *nb_ops* is returned.
1862 * The rte_cryptodev_dequeue_burst() function does not provide any error
1863 * notification to avoid the corresponding overhead.
1865 * @param dev_id The symmetric crypto device identifier
1866 * @param qp_id The index of the queue pair from which to
1867 * retrieve processed packets. The value must be
1868 * in the range [0, nb_queue_pair - 1] previously
1869 * supplied to rte_cryptodev_configure().
1870 * @param ops The address of an array of pointers to
1871 * *rte_crypto_op* structures that must be
1872 * large enough to store *nb_ops* pointers in it.
1873 * @param nb_ops The maximum number of operations to dequeue.
1876 * - The number of operations actually dequeued, which is the number
1877 * of pointers to *rte_crypto_op* structures effectively supplied to the
1880 static inline uint16_t
1881 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1882 struct rte_crypto_op **ops, uint16_t nb_ops)
1884 const struct rte_crypto_fp_ops *fp_ops;
1887 rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1889 fp_ops = &rte_crypto_fp_ops[dev_id];
1890 qp = fp_ops->qp.data[qp_id];
1892 nb_ops = fp_ops->dequeue_burst(qp, ops, nb_ops);
1894 #ifdef RTE_CRYPTO_CALLBACKS
1895 if (unlikely(fp_ops->qp.deq_cb != NULL)) {
1896 struct rte_cryptodev_cb_rcu *list;
1897 struct rte_cryptodev_cb *cb;
1899 /* __ATOMIC_RELEASE memory order was used when the
1900 * call back was inserted into the list.
1901 * Since there is a clear dependency between loading
1902 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1905 list = &fp_ops->qp.deq_cb[qp_id];
1906 rte_rcu_qsbr_thread_online(list->qsbr, 0);
1907 cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1909 while (cb != NULL) {
1910 nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1915 rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1922 * Enqueue a burst of operations for processing on a crypto device.
1924 * The rte_cryptodev_enqueue_burst() function is invoked to place
1925 * crypto operations on the queue *qp_id* of the device designated by
1928 * The *nb_ops* parameter is the number of operations to process which are
1929 * supplied in the *ops* array of *rte_crypto_op* structures.
1931 * The rte_cryptodev_enqueue_burst() function returns the number of
1932 * operations it actually enqueued for processing. A return value equal to
1933 * *nb_ops* means that all packets have been enqueued.
1935 * @param dev_id The identifier of the device.
1936 * @param qp_id The index of the queue pair which packets are
1937 * to be enqueued for processing. The value
1938 * must be in the range [0, nb_queue_pairs - 1]
1939 * previously supplied to
1940 * *rte_cryptodev_configure*.
1941 * @param ops The address of an array of *nb_ops* pointers
1942 * to *rte_crypto_op* structures which contain
1943 * the crypto operations to be processed.
1944 * @param nb_ops The number of operations to process.
1947 * The number of operations actually enqueued on the crypto device. The return
1948 * value can be less than the value of the *nb_ops* parameter when the
1949 * crypto devices queue is full or if invalid parameters are specified in
1950 * a *rte_crypto_op*.
1952 static inline uint16_t
1953 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
1954 struct rte_crypto_op **ops, uint16_t nb_ops)
1956 const struct rte_crypto_fp_ops *fp_ops;
1959 fp_ops = &rte_crypto_fp_ops[dev_id];
1960 qp = fp_ops->qp.data[qp_id];
1961 #ifdef RTE_CRYPTO_CALLBACKS
1962 if (unlikely(fp_ops->qp.enq_cb != NULL)) {
1963 struct rte_cryptodev_cb_rcu *list;
1964 struct rte_cryptodev_cb *cb;
1966 /* __ATOMIC_RELEASE memory order was used when the
1967 * call back was inserted into the list.
1968 * Since there is a clear dependency between loading
1969 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1972 list = &fp_ops->qp.enq_cb[qp_id];
1973 rte_rcu_qsbr_thread_online(list->qsbr, 0);
1974 cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1976 while (cb != NULL) {
1977 nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1982 rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1986 rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1987 return fp_ops->enqueue_burst(qp, ops, nb_ops);
1996 #endif /* _RTE_CRYPTODEV_H_ */