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"
24 #include <rte_common.h>
25 #include <rte_config.h>
26 #include <rte_rcu_qsbr.h>
28 #include "rte_cryptodev_trace_fp.h"
30 extern const char **rte_cyptodev_names;
34 #define CDEV_LOG_ERR(...) \
35 RTE_LOG(ERR, CRYPTODEV, \
36 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
37 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
39 #define CDEV_LOG_INFO(...) \
40 RTE_LOG(INFO, CRYPTODEV, \
41 RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
42 RTE_FMT_TAIL(__VA_ARGS__,)))
44 #define CDEV_LOG_DEBUG(...) \
45 RTE_LOG(DEBUG, CRYPTODEV, \
46 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
47 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
49 #define CDEV_PMD_TRACE(...) \
50 RTE_LOG(DEBUG, CRYPTODEV, \
51 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
52 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
55 * A macro that points to an offset from the start
56 * of the crypto operation structure (rte_crypto_op)
58 * The returned pointer is cast to type t.
61 * The crypto operation.
63 * The offset from the start of the crypto operation.
65 * The type to cast the result into.
67 #define rte_crypto_op_ctod_offset(c, t, o) \
68 ((t)((char *)(c) + (o)))
71 * A macro that returns the physical address that points
72 * to an offset from the start of the crypto operation
76 * The crypto operation.
78 * The offset from the start of the crypto operation
79 * to calculate address from.
81 #define rte_crypto_op_ctophys_offset(c, o) \
82 (rte_iova_t)((c)->phys_addr + (o))
85 * Crypto parameters range description
87 struct rte_crypto_param_range {
88 uint16_t min; /**< minimum size */
89 uint16_t max; /**< maximum size */
91 /**< if a range of sizes are supported,
92 * this parameter is used to indicate
93 * increments in byte size that are supported
94 * between the minimum and maximum
99 * Data-unit supported lengths of cipher algorithms.
100 * A bit can represent any set of data-unit sizes
101 * (single size, multiple size, range, etc).
103 #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_512_BYTES RTE_BIT32(0)
104 #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_4096_BYTES RTE_BIT32(1)
107 * Symmetric Crypto Capability
109 struct rte_cryptodev_symmetric_capability {
110 enum rte_crypto_sym_xform_type xform_type;
111 /**< Transform type : Authentication / Cipher / AEAD */
115 enum rte_crypto_auth_algorithm algo;
116 /**< authentication algorithm */
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 */
128 /**< Symmetric Authentication transform capabilities */
130 enum rte_crypto_cipher_algorithm algo;
131 /**< cipher algorithm */
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;
140 * Supported data-unit lengths:
141 * RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_* bits
142 * or 0 for lengths defined in the algorithm standard.
145 /**< Symmetric Cipher transform capabilities */
147 enum rte_crypto_aead_algorithm algo;
148 /**< AEAD algorithm */
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 */
164 * Asymmetric Xform Crypto Capability
167 struct rte_cryptodev_asymmetric_xform_capability {
168 enum rte_crypto_asym_xform_type xform_type;
169 /**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
172 /**< bitmask for supported rte_crypto_asym_op_type */
176 struct rte_crypto_param_range modlen;
177 /**< Range of modulus length supported by modulus based xform.
178 * Value 0 mean implementation default
184 * Asymmetric Crypto Capability
187 struct rte_cryptodev_asymmetric_capability {
188 struct rte_cryptodev_asymmetric_xform_capability xform_capa;
192 /** Structure used to capture a capability of a crypto device */
193 struct rte_cryptodev_capabilities {
194 enum rte_crypto_op_type op;
195 /**< Operation type */
199 struct rte_cryptodev_symmetric_capability sym;
200 /**< Symmetric operation capability parameters */
201 struct rte_cryptodev_asymmetric_capability asym;
202 /**< Asymmetric operation capability parameters */
206 /** Structure used to describe crypto algorithms */
207 struct rte_cryptodev_sym_capability_idx {
208 enum rte_crypto_sym_xform_type type;
210 enum rte_crypto_cipher_algorithm cipher;
211 enum rte_crypto_auth_algorithm auth;
212 enum rte_crypto_aead_algorithm aead;
217 * Structure used to describe asymmetric crypto xforms
218 * Each xform maps to one asym algorithm.
221 struct rte_cryptodev_asym_capability_idx {
222 enum rte_crypto_asym_xform_type type;
223 /**< Asymmetric xform (algo) type */
227 * Provide capabilities available for defined device and algorithm
229 * @param dev_id The identifier of the device.
230 * @param idx Description of crypto algorithms.
233 * - Return description of the symmetric crypto capability if exist.
234 * - Return NULL if the capability not exist.
236 const struct rte_cryptodev_symmetric_capability *
237 rte_cryptodev_sym_capability_get(uint8_t dev_id,
238 const struct rte_cryptodev_sym_capability_idx *idx);
241 * Provide capabilities available for defined device and xform
243 * @param dev_id The identifier of the device.
244 * @param idx Description of asym crypto xform.
247 * - Return description of the asymmetric crypto capability if exist.
248 * - Return NULL if the capability not exist.
251 const struct rte_cryptodev_asymmetric_xform_capability *
252 rte_cryptodev_asym_capability_get(uint8_t dev_id,
253 const struct rte_cryptodev_asym_capability_idx *idx);
256 * Check if key size and initial vector are supported
257 * in crypto cipher capability
259 * @param capability Description of the symmetric crypto capability.
260 * @param key_size Cipher key size.
261 * @param iv_size Cipher initial vector size.
264 * - Return 0 if the parameters are in range of the capability.
265 * - Return -1 if the parameters are out of range of the capability.
268 rte_cryptodev_sym_capability_check_cipher(
269 const struct rte_cryptodev_symmetric_capability *capability,
270 uint16_t key_size, uint16_t iv_size);
273 * Check if key size and initial vector are supported
274 * in crypto auth capability
276 * @param capability Description of the symmetric crypto capability.
277 * @param key_size Auth key size.
278 * @param digest_size Auth digest size.
279 * @param iv_size Auth initial vector size.
282 * - Return 0 if the parameters are in range of the capability.
283 * - Return -1 if the parameters are out of range of the capability.
286 rte_cryptodev_sym_capability_check_auth(
287 const struct rte_cryptodev_symmetric_capability *capability,
288 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
291 * Check if key, digest, AAD and initial vector sizes are supported
292 * in crypto AEAD capability
294 * @param capability Description of the symmetric crypto capability.
295 * @param key_size AEAD key size.
296 * @param digest_size AEAD digest size.
297 * @param aad_size AEAD AAD size.
298 * @param iv_size AEAD IV size.
301 * - Return 0 if the parameters are in range of the capability.
302 * - Return -1 if the parameters are out of range of the capability.
305 rte_cryptodev_sym_capability_check_aead(
306 const struct rte_cryptodev_symmetric_capability *capability,
307 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
311 * Check if op type is supported
313 * @param capability Description of the asymmetric crypto capability.
314 * @param op_type op type
317 * - Return 1 if the op type is supported
318 * - Return 0 if unsupported
322 rte_cryptodev_asym_xform_capability_check_optype(
323 const struct rte_cryptodev_asymmetric_xform_capability *capability,
324 enum rte_crypto_asym_op_type op_type);
327 * Check if modulus length is in supported range
329 * @param capability Description of the asymmetric crypto capability.
330 * @param modlen modulus length.
333 * - Return 0 if the parameters are in range of the capability.
334 * - Return -1 if the parameters are out of range of the capability.
338 rte_cryptodev_asym_xform_capability_check_modlen(
339 const struct rte_cryptodev_asymmetric_xform_capability *capability,
343 * Provide the cipher algorithm enum, given an algorithm string
345 * @param algo_enum A pointer to the cipher algorithm
347 * @param algo_string Authentication algo string
350 * - Return -1 if string is not valid
351 * - Return 0 is the string is valid
354 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
355 const char *algo_string);
358 * Provide the authentication algorithm enum, given an algorithm string
360 * @param algo_enum A pointer to the authentication algorithm
362 * @param algo_string Authentication algo string
365 * - Return -1 if string is not valid
366 * - Return 0 is the string is valid
369 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
370 const char *algo_string);
373 * Provide the AEAD algorithm enum, given an algorithm string
375 * @param algo_enum A pointer to the AEAD algorithm
377 * @param algo_string AEAD algorithm string
380 * - Return -1 if string is not valid
381 * - Return 0 is the string is valid
384 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
385 const char *algo_string);
388 * Provide the Asymmetric xform enum, given an xform string
390 * @param xform_enum A pointer to the xform type
392 * @param xform_string xform string
395 * - Return -1 if string is not valid
396 * - Return 0 if the string is valid
400 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
401 const char *xform_string);
404 /** Macro used at end of crypto PMD list */
405 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
406 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
410 * Crypto device supported feature flags
413 * New features flags should be added to the end of the list
415 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
417 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
418 /**< Symmetric crypto operations are supported */
419 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
420 /**< Asymmetric crypto operations are supported */
421 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
422 /**< Chaining symmetric crypto operations are supported */
423 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
424 /**< Utilises CPU SIMD SSE instructions */
425 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
426 /**< Utilises CPU SIMD AVX instructions */
427 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
428 /**< Utilises CPU SIMD AVX2 instructions */
429 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
430 /**< Utilises CPU AES-NI instructions */
431 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
432 /**< Operations are off-loaded to an
433 * external hardware accelerator
435 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
436 /**< Utilises CPU SIMD AVX512 instructions */
437 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL (1ULL << 9)
438 /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
441 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT (1ULL << 10)
442 /**< Out-of-place Scatter-gather (SGL) buffers are
443 * supported in input and output
445 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT (1ULL << 11)
446 /**< Out-of-place Scatter-gather (SGL) buffers are supported
447 * in input, combined with linear buffers (LB), with a
448 * single segment in output
450 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT (1ULL << 12)
451 /**< Out-of-place Scatter-gather (SGL) buffers are supported
452 * in output, combined with linear buffers (LB) in input
454 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT (1ULL << 13)
455 /**< Out-of-place linear buffers (LB) are supported in input and output */
456 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 14)
457 /**< Utilises CPU NEON instructions */
458 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 15)
459 /**< Utilises ARM CPU Cryptographic Extensions */
460 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 16)
461 /**< Support Security Protocol Processing */
462 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP (1ULL << 17)
463 /**< Support RSA Private Key OP with exponent */
464 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT (1ULL << 18)
465 /**< Support RSA Private Key OP with CRT (quintuple) Keys */
466 #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED (1ULL << 19)
467 /**< Support encrypted-digest operations where digest is appended to data */
468 #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS (1ULL << 20)
469 /**< Support asymmetric session-less operations */
470 #define RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO (1ULL << 21)
471 /**< Support symmetric cpu-crypto processing */
472 #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS (1ULL << 22)
473 /**< Support symmetric session-less operations */
474 #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA (1ULL << 23)
475 /**< Support operations on data which is not byte aligned */
476 #define RTE_CRYPTODEV_FF_SYM_RAW_DP (1ULL << 24)
477 /**< Support accelerator specific symmetric raw data-path APIs */
478 #define RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS (1ULL << 25)
479 /**< Support operations on multiple data-units message */
480 #define RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY (1ULL << 26)
481 /**< Support wrapped key in cipher xform */
482 #define RTE_CRYPTODEV_FF_SECURITY_INNER_CSUM (1ULL << 27)
483 /**< Support inner checksum computation/verification */
486 * Get the name of a crypto device feature flag
488 * @param flag The mask describing the flag.
491 * The name of this flag, or NULL if it's not a valid feature flag.
495 rte_cryptodev_get_feature_name(uint64_t flag);
497 /** Crypto device information */
498 struct rte_cryptodev_info {
499 const char *driver_name; /**< Driver name. */
500 uint8_t driver_id; /**< Driver identifier */
501 struct rte_device *device; /**< Generic device information. */
503 uint64_t feature_flags;
504 /**< Feature flags exposes HW/SW features for the given device */
506 const struct rte_cryptodev_capabilities *capabilities;
507 /**< Array of devices supported capabilities */
509 unsigned max_nb_queue_pairs;
510 /**< Maximum number of queues pairs supported by device. */
512 uint16_t min_mbuf_headroom_req;
513 /**< Minimum mbuf headroom required by device */
515 uint16_t min_mbuf_tailroom_req;
516 /**< Minimum mbuf tailroom required by device */
519 unsigned max_nb_sessions;
520 /**< Maximum number of sessions supported by device.
521 * If 0, the device does not have any limitation in
522 * number of sessions that can be used.
527 #define RTE_CRYPTODEV_DETACHED (0)
528 #define RTE_CRYPTODEV_ATTACHED (1)
530 /** Definitions of Crypto device event types */
531 enum rte_cryptodev_event_type {
532 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
533 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
534 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
537 /** Crypto device queue pair configuration structure. */
538 struct rte_cryptodev_qp_conf {
539 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
540 struct rte_mempool *mp_session;
541 /**< The mempool for creating session in sessionless mode */
542 struct rte_mempool *mp_session_private;
543 /**< The mempool for creating sess private data in sessionless mode */
547 * Function type used for processing crypto ops when enqueue/dequeue burst is
550 * The callback function is called on enqueue/dequeue burst immediately.
552 * @param dev_id The identifier of the device.
553 * @param qp_id The index of the queue pair on which ops are
554 * enqueued/dequeued. The value must be in the
555 * range [0, nb_queue_pairs - 1] previously
556 * supplied to *rte_cryptodev_configure*.
557 * @param ops The address of an array of *nb_ops* pointers
558 * to *rte_crypto_op* structures which contain
559 * the crypto operations to be processed.
560 * @param nb_ops The number of operations to process.
561 * @param user_param The arbitrary user parameter passed in by the
562 * application when the callback was originally
564 * @return The number of ops to be enqueued to the
567 typedef uint16_t (*rte_cryptodev_callback_fn)(uint16_t dev_id, uint16_t qp_id,
568 struct rte_crypto_op **ops, uint16_t nb_ops, void *user_param);
571 * Typedef for application callback function to be registered by application
572 * software for notification of device events
574 * @param dev_id Crypto device identifier
575 * @param event Crypto device event to register for notification of.
576 * @param cb_arg User specified parameter to be passed as to passed to
577 * users callback function.
579 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
580 enum rte_cryptodev_event_type event, void *cb_arg);
583 /** Crypto Device statistics */
584 struct rte_cryptodev_stats {
585 uint64_t enqueued_count;
586 /**< Count of all operations enqueued */
587 uint64_t dequeued_count;
588 /**< Count of all operations dequeued */
590 uint64_t enqueue_err_count;
591 /**< Total error count on operations enqueued */
592 uint64_t dequeue_err_count;
593 /**< Total error count on operations dequeued */
596 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
597 /**< Max length of name of crypto PMD */
600 * Get the device identifier for the named crypto device.
602 * @param name device name to select the device structure.
605 * - Returns crypto device identifier on success.
606 * - Return -1 on failure to find named crypto device.
609 rte_cryptodev_get_dev_id(const char *name);
612 * Get the crypto device name given a device identifier.
615 * The identifier of the device
618 * - Returns crypto device name.
619 * - Returns NULL if crypto device is not present.
622 rte_cryptodev_name_get(uint8_t dev_id);
625 * Get the total number of crypto devices that have been successfully
629 * - The total number of usable crypto devices.
632 rte_cryptodev_count(void);
635 * Get number of crypto device defined type.
637 * @param driver_id driver identifier.
640 * Returns number of crypto device.
643 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
646 * Get number and identifiers of attached crypto devices that
647 * use the same crypto driver.
649 * @param driver_name driver name.
650 * @param devices output devices identifiers.
651 * @param nb_devices maximal number of devices.
654 * Returns number of attached crypto device.
657 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
660 * Return the NUMA socket to which a device is connected
663 * The identifier of the device
665 * The NUMA socket id to which the device is connected or
666 * a default of zero if the socket could not be determined.
667 * -1 if returned is the dev_id value is out of range.
670 rte_cryptodev_socket_id(uint8_t dev_id);
672 /** Crypto device configuration structure */
673 struct rte_cryptodev_config {
674 int socket_id; /**< Socket to allocate resources on */
675 uint16_t nb_queue_pairs;
676 /**< Number of queue pairs to configure on device */
678 /**< Feature flags to be disabled. Only the following features are
679 * allowed to be disabled,
680 * - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
681 * - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
682 * - RTE_CRYTPODEV_FF_SECURITY
687 * Configure a device.
689 * This function must be invoked first before any other function in the
690 * API. This function can also be re-invoked when a device is in the
693 * @param dev_id The identifier of the device to configure.
694 * @param config The crypto device configuration structure.
697 * - 0: Success, device configured.
698 * - <0: Error code returned by the driver configuration function.
701 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
706 * The device start step is the last one and consists of setting the configured
707 * offload features and in starting the transmit and the receive units of the
709 * On success, all basic functions exported by the API (link status,
710 * receive/transmit, and so on) can be invoked.
713 * The identifier of the device.
715 * - 0: Success, device started.
716 * - <0: Error code of the driver device start function.
719 rte_cryptodev_start(uint8_t dev_id);
722 * Stop an device. The device can be restarted with a call to
723 * rte_cryptodev_start()
725 * @param dev_id The identifier of the device.
728 rte_cryptodev_stop(uint8_t dev_id);
731 * Close an device. The device cannot be restarted!
733 * @param dev_id The identifier of the device.
736 * - 0 on successfully closing device
737 * - <0 on failure to close device
740 rte_cryptodev_close(uint8_t dev_id);
743 * Allocate and set up a receive queue pair for a device.
746 * @param dev_id The identifier of the device.
747 * @param queue_pair_id The index of the queue pairs to set up. The
748 * value must be in the range [0, nb_queue_pair
749 * - 1] previously supplied to
750 * rte_cryptodev_configure().
751 * @param qp_conf The pointer to the configuration data to be
752 * used for the queue pair.
753 * @param socket_id The *socket_id* argument is the socket
754 * identifier in case of NUMA. The value can be
755 * *SOCKET_ID_ANY* if there is no NUMA constraint
756 * for the DMA memory allocated for the receive
760 * - 0: Success, queue pair correctly set up.
761 * - <0: Queue pair configuration failed
764 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
765 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
768 * Get the status of queue pairs setup on a specific crypto device
770 * @param dev_id Crypto device identifier.
771 * @param queue_pair_id The index of the queue pairs to set up. The
772 * value must be in the range [0, nb_queue_pair
773 * - 1] previously supplied to
774 * rte_cryptodev_configure().
776 * - 0: qp was not configured
777 * - 1: qp was configured
778 * - -EINVAL: device was not configured
782 rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id);
785 * Get the number of queue pairs on a specific crypto device
787 * @param dev_id Crypto device identifier.
789 * - The number of configured queue pairs.
792 rte_cryptodev_queue_pair_count(uint8_t dev_id);
796 * Retrieve the general I/O statistics of a device.
798 * @param dev_id The identifier of the device.
799 * @param stats A pointer to a structure of type
800 * *rte_cryptodev_stats* to be filled with the
801 * values of device counters.
803 * - Zero if successful.
804 * - Non-zero otherwise.
807 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
810 * Reset the general I/O statistics of a device.
812 * @param dev_id The identifier of the device.
815 rte_cryptodev_stats_reset(uint8_t dev_id);
818 * Retrieve the contextual information of a device.
820 * @param dev_id The identifier of the device.
821 * @param dev_info A pointer to a structure of type
822 * *rte_cryptodev_info* to be filled with the
823 * contextual information of the device.
825 * @note The capabilities field of dev_info is set to point to the first
826 * element of an array of struct rte_cryptodev_capabilities. The element after
827 * the last valid element has it's op field set to
828 * RTE_CRYPTO_OP_TYPE_UNDEFINED.
831 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
835 * Register a callback function for specific device id.
837 * @param dev_id Device id.
838 * @param event Event interested.
839 * @param cb_fn User supplied callback function to be called.
840 * @param cb_arg Pointer to the parameters for the registered
844 * - On success, zero.
845 * - On failure, a negative value.
848 rte_cryptodev_callback_register(uint8_t dev_id,
849 enum rte_cryptodev_event_type event,
850 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
853 * Unregister a callback function for specific device id.
855 * @param dev_id The device identifier.
856 * @param event Event interested.
857 * @param cb_fn User supplied callback function to be called.
858 * @param cb_arg Pointer to the parameters for the registered
862 * - On success, zero.
863 * - On failure, a negative value.
866 rte_cryptodev_callback_unregister(uint8_t dev_id,
867 enum rte_cryptodev_event_type event,
868 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
870 struct rte_cryptodev_callback;
872 /** Structure to keep track of registered callbacks */
873 RTE_TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
876 * Structure used to hold information about the callbacks to be called for a
877 * queue pair on enqueue/dequeue.
879 struct rte_cryptodev_cb {
880 struct rte_cryptodev_cb *next;
881 /**< Pointer to next callback */
882 rte_cryptodev_callback_fn fn;
883 /**< Pointer to callback function */
885 /**< Pointer to argument */
890 * Structure used to hold information about the RCU for a queue pair.
892 struct rte_cryptodev_cb_rcu {
893 struct rte_cryptodev_cb *next;
894 /**< Pointer to next callback */
895 struct rte_rcu_qsbr *qsbr;
896 /**< RCU QSBR variable per queue pair */
900 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
902 /** Cryptodev symmetric crypto session
903 * Each session is derived from a fixed xform chain. Therefore each session
904 * has a fixed algo, key, op-type, digest_len etc.
906 struct rte_cryptodev_sym_session {
907 uint64_t opaque_data;
908 /**< Can be used for external metadata */
910 /**< number of elements in sess_data array */
911 uint16_t user_data_sz;
912 /**< session user data will be placed after sess_data */
913 __extension__ struct {
917 /**< Driver specific session material, variable size */
920 /** Cryptodev asymmetric crypto session */
921 struct rte_cryptodev_asym_session {
922 __extension__ void *sess_private_data[0];
923 /**< Private asymmetric session material */
927 * Create a symmetric session mempool.
930 * The unique mempool name.
932 * The number of elements in the mempool.
934 * The size of the element. This value will be ignored if it is smaller than
935 * the minimum session header size required for the system. For the user who
936 * want to use the same mempool for sym session and session private data it
937 * can be the maximum value of all existing devices' private data and session
940 * The number of per-lcore cache elements
942 * The private data size of each session.
944 * The *socket_id* argument is the socket identifier in the case of
945 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
946 * constraint for the reserved zone.
949 * - On success return size of the session
950 * - On failure returns 0
954 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
955 uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
959 * Create symmetric crypto session header (generic with no private data)
961 * @param mempool Symmetric session mempool to allocate session
964 * - On success return pointer to sym-session
965 * - On failure returns NULL
967 struct rte_cryptodev_sym_session *
968 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
971 * Create asymmetric crypto session header (generic with no private data)
973 * @param mempool mempool to allocate asymmetric session
976 * - On success return pointer to asym-session
977 * - On failure returns NULL
980 struct rte_cryptodev_asym_session *
981 rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
984 * Frees symmetric crypto session header, after checking that all
985 * the device private data has been freed, returning it
986 * to its original mempool.
988 * @param sess Session header to be freed.
992 * - -EINVAL if session is NULL.
993 * - -EBUSY if not all device private data has been freed.
996 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
999 * Frees asymmetric crypto session header, after checking that all
1000 * the device private data has been freed, returning it
1001 * to its original mempool.
1003 * @param sess Session header to be freed.
1006 * - 0 if successful.
1007 * - -EINVAL if session is NULL.
1008 * - -EBUSY if not all device private data has been freed.
1012 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
1015 * Fill out private data for the device id, based on its device type.
1017 * @param dev_id ID of device that we want the session to be used on
1018 * @param sess Session where the private data will be attached to
1019 * @param xforms Symmetric crypto transform operations to apply on flow
1020 * processed with this session
1021 * @param mempool Mempool where the private data is allocated.
1024 * - On success, zero.
1025 * - -EINVAL if input parameters are invalid.
1026 * - -ENOTSUP if crypto device does not support the crypto transform or
1027 * does not support symmetric operations.
1028 * - -ENOMEM if the private session could not be allocated.
1031 rte_cryptodev_sym_session_init(uint8_t dev_id,
1032 struct rte_cryptodev_sym_session *sess,
1033 struct rte_crypto_sym_xform *xforms,
1034 struct rte_mempool *mempool);
1037 * Initialize asymmetric session on a device with specific asymmetric xform
1039 * @param dev_id ID of device that we want the session to be used on
1040 * @param sess Session to be set up on a device
1041 * @param xforms Asymmetric crypto transform operations to apply on flow
1042 * processed with this session
1043 * @param mempool Mempool to be used for internal allocation.
1046 * - On success, zero.
1047 * - -EINVAL if input parameters are invalid.
1048 * - -ENOTSUP if crypto device does not support the crypto transform.
1049 * - -ENOMEM if the private session could not be allocated.
1053 rte_cryptodev_asym_session_init(uint8_t dev_id,
1054 struct rte_cryptodev_asym_session *sess,
1055 struct rte_crypto_asym_xform *xforms,
1056 struct rte_mempool *mempool);
1059 * Frees private data for the device id, based on its device type,
1060 * returning it to its mempool. It is the application's responsibility
1061 * to ensure that private session data is not cleared while there are
1062 * still in-flight operations using it.
1064 * @param dev_id ID of device that uses the session.
1065 * @param sess Session containing the reference to the private data
1068 * - 0 if successful.
1069 * - -EINVAL if device is invalid or session is NULL.
1070 * - -ENOTSUP if crypto device does not support symmetric operations.
1073 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1074 struct rte_cryptodev_sym_session *sess);
1077 * Frees resources held by asymmetric session during rte_cryptodev_session_init
1079 * @param dev_id ID of device that uses the asymmetric session.
1080 * @param sess Asymmetric session setup on device using
1081 * rte_cryptodev_session_init
1083 * - 0 if successful.
1084 * - -EINVAL if device is invalid or session is NULL.
1088 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1089 struct rte_cryptodev_asym_session *sess);
1092 * Get the size of the header session, for all registered drivers excluding
1093 * the user data size.
1096 * Size of the symmetric header session.
1099 rte_cryptodev_sym_get_header_session_size(void);
1102 * Get the size of the header session from created session.
1105 * The sym cryptodev session pointer
1108 * - If sess is not NULL, return the size of the header session including
1109 * the private data size defined within sess.
1110 * - If sess is NULL, return 0.
1114 rte_cryptodev_sym_get_existing_header_session_size(
1115 struct rte_cryptodev_sym_session *sess);
1118 * Get the size of the asymmetric session header, for all registered drivers.
1121 * Size of the asymmetric header session.
1125 rte_cryptodev_asym_get_header_session_size(void);
1128 * Get the size of the private symmetric session data
1131 * @param dev_id The device identifier.
1134 * - Size of the private data, if successful
1135 * - 0 if device is invalid or does not have private
1139 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
1142 * Get the size of the private data for asymmetric session
1145 * @param dev_id The device identifier.
1148 * - Size of the asymmetric private data, if successful
1149 * - 0 if device is invalid or does not have private session
1153 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
1156 * Validate if the crypto device index is valid attached crypto device.
1158 * @param dev_id Crypto device index.
1161 * - If the device index is valid (1) or not (0).
1164 rte_cryptodev_is_valid_dev(uint8_t dev_id);
1167 * Provide driver identifier.
1170 * The pointer to a driver name.
1172 * The driver type identifier or -1 if no driver found
1174 int rte_cryptodev_driver_id_get(const char *name);
1177 * Provide driver name.
1180 * The driver identifier.
1182 * The driver name or null if no driver found
1184 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1187 * Store user data in a session.
1189 * @param sess Session pointer allocated by
1190 * *rte_cryptodev_sym_session_create*.
1191 * @param data Pointer to the user data.
1192 * @param size Size of the user data.
1195 * - On success, zero.
1196 * - On failure, a negative value.
1200 rte_cryptodev_sym_session_set_user_data(
1201 struct rte_cryptodev_sym_session *sess,
1206 * Get user data stored in a session.
1208 * @param sess Session pointer allocated by
1209 * *rte_cryptodev_sym_session_create*.
1212 * - On success return pointer to user data.
1213 * - On failure returns NULL.
1217 rte_cryptodev_sym_session_get_user_data(
1218 struct rte_cryptodev_sym_session *sess);
1221 * Perform actual crypto processing (encrypt/digest or auth/decrypt)
1222 * on user provided data.
1224 * @param dev_id The device identifier.
1225 * @param sess Cryptodev session structure
1226 * @param ofs Start and stop offsets for auth and cipher operations
1227 * @param vec Vectorized operation descriptor
1230 * - Returns number of successfully processed packets.
1234 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
1235 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
1236 struct rte_crypto_sym_vec *vec);
1239 * Get the size of the raw data-path context buffer.
1241 * @param dev_id The device identifier.
1244 * - If the device supports raw data-path APIs, return the context size.
1245 * - If the device does not support the APIs, return -1.
1249 rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id);
1252 * Union of different crypto session types, including session-less xform
1255 union rte_cryptodev_session_ctx {
1256 struct rte_cryptodev_sym_session *crypto_sess;
1257 struct rte_crypto_sym_xform *xform;
1258 struct rte_security_session *sec_sess;
1262 * Enqueue a vectorized operation descriptor into the device queue but the
1263 * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1266 * @param qp Driver specific queue pair data.
1267 * @param drv_ctx Driver specific context data.
1268 * @param vec Vectorized operation descriptor.
1269 * @param ofs Start and stop offsets for auth and cipher
1271 * @param user_data The array of user data for dequeue later.
1272 * @param enqueue_status Driver written value to specify the
1273 * enqueue status. Possible values:
1274 * - 1: The number of operations returned are
1275 * enqueued successfully.
1276 * - 0: The number of operations returned are
1277 * cached into the queue but are not processed
1278 * until rte_cryptodev_raw_enqueue_done() is
1280 * - negative integer: Error occurred.
1282 * - The number of operations in the descriptor successfully enqueued or
1283 * cached into the queue but not enqueued yet, depends on the
1284 * "enqueue_status" value.
1286 typedef uint32_t (*cryptodev_sym_raw_enqueue_burst_t)(
1287 void *qp, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1288 union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status);
1291 * Enqueue single raw data vector into the device queue but the driver may or
1292 * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1294 * @param qp Driver specific queue pair data.
1295 * @param drv_ctx Driver specific context data.
1296 * @param data_vec The buffer data vector.
1297 * @param n_data_vecs Number of buffer data vectors.
1298 * @param ofs Start and stop offsets for auth and cipher
1300 * @param iv IV virtual and IOVA addresses
1301 * @param digest digest virtual and IOVA addresses
1302 * @param aad_or_auth_iv AAD or auth IV virtual and IOVA addresses,
1303 * depends on the algorithm used.
1304 * @param user_data The user data.
1306 * - 1: The data vector is enqueued successfully.
1307 * - 0: The data vector is cached into the queue but is not processed
1308 * until rte_cryptodev_raw_enqueue_done() is called.
1309 * - negative integer: failure.
1311 typedef int (*cryptodev_sym_raw_enqueue_t)(
1312 void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1313 uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1314 struct rte_crypto_va_iova_ptr *iv,
1315 struct rte_crypto_va_iova_ptr *digest,
1316 struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1320 * Inform the cryptodev queue pair to start processing or finish dequeuing all
1321 * enqueued/dequeued operations.
1323 * @param qp Driver specific queue pair data.
1324 * @param drv_ctx Driver specific context data.
1325 * @param n The total number of processed operations.
1327 * - On success return 0.
1328 * - On failure return negative integer.
1330 typedef int (*cryptodev_sym_raw_operation_done_t)(void *qp, uint8_t *drv_ctx,
1334 * Typedef that the user provided for the driver to get the dequeue count.
1335 * The function may return a fixed number or the number parsed from the user
1336 * data stored in the first processed operation.
1338 * @param user_data Dequeued user data.
1340 * - The number of operations to be dequeued.
1342 typedef uint32_t (*rte_cryptodev_raw_get_dequeue_count_t)(void *user_data);
1345 * Typedef that the user provided to deal with post dequeue operation, such
1346 * as filling status.
1348 * @param user_data Dequeued user data.
1349 * @param index Index number of the processed descriptor.
1350 * @param is_op_success Operation status provided by the driver.
1352 typedef void (*rte_cryptodev_raw_post_dequeue_t)(void *user_data,
1353 uint32_t index, uint8_t is_op_success);
1356 * Dequeue a burst of symmetric crypto processing.
1358 * @param qp Driver specific queue pair data.
1359 * @param drv_ctx Driver specific context data.
1360 * @param get_dequeue_count User provided callback function to
1361 * obtain dequeue operation count.
1362 * @param max_nb_to_dequeue When get_dequeue_count is NULL this
1363 * value is used to pass the maximum
1364 * number of operations to be dequeued.
1365 * @param post_dequeue User provided callback function to
1366 * post-process a dequeued operation.
1367 * @param out_user_data User data pointer array to be retrieve
1368 * from device queue. In case of
1369 * *is_user_data_array* is set there
1370 * should be enough room to store all
1372 * @param is_user_data_array Set 1 if every dequeued user data will
1373 * be written into out_user_data array.
1374 * Set 0 if only the first user data will
1375 * be written into out_user_data array.
1376 * @param n_success Driver written value to specific the
1377 * total successful operations count.
1378 * @param dequeue_status Driver written value to specify the
1379 * dequeue status. Possible values:
1380 * - 1: Successfully dequeued the number
1381 * of operations returned. The user
1382 * data previously set during enqueue
1383 * is stored in the "out_user_data".
1384 * - 0: The number of operations returned
1385 * are completed and the user data is
1386 * stored in the "out_user_data", but
1387 * they are not freed from the queue
1389 * rte_cryptodev_raw_dequeue_done()
1391 * - negative integer: Error occurred.
1393 * - The number of operations dequeued or completed but not freed from the
1394 * queue, depends on "dequeue_status" value.
1396 typedef uint32_t (*cryptodev_sym_raw_dequeue_burst_t)(void *qp,
1398 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1399 uint32_t max_nb_to_dequeue,
1400 rte_cryptodev_raw_post_dequeue_t post_dequeue,
1401 void **out_user_data, uint8_t is_user_data_array,
1402 uint32_t *n_success, int *dequeue_status);
1405 * Dequeue a symmetric crypto processing.
1407 * @param qp Driver specific queue pair data.
1408 * @param drv_ctx Driver specific context data.
1409 * @param dequeue_status Driver written value to specify the
1410 * dequeue status. Possible values:
1411 * - 1: Successfully dequeued a operation.
1412 * The user data is returned.
1413 * - 0: The first operation in the queue
1414 * is completed and the user data
1415 * previously set during enqueue is
1416 * returned, but it is not freed from
1418 * rte_cryptodev_raw_dequeue_done() is
1420 * - negative integer: Error occurred.
1421 * @param op_status Driver written value to specify
1424 * - The user data pointer retrieved from device queue or NULL if no
1425 * operation is ready for dequeue.
1427 typedef void * (*cryptodev_sym_raw_dequeue_t)(
1428 void *qp, uint8_t *drv_ctx, int *dequeue_status,
1429 enum rte_crypto_op_status *op_status);
1432 * Context data for raw data-path API crypto process. The buffer of this
1433 * structure is to be allocated by the user application with the size equal
1434 * or bigger than rte_cryptodev_get_raw_dp_ctx_size() returned value.
1436 struct rte_crypto_raw_dp_ctx {
1439 cryptodev_sym_raw_enqueue_t enqueue;
1440 cryptodev_sym_raw_enqueue_burst_t enqueue_burst;
1441 cryptodev_sym_raw_operation_done_t enqueue_done;
1442 cryptodev_sym_raw_dequeue_t dequeue;
1443 cryptodev_sym_raw_dequeue_burst_t dequeue_burst;
1444 cryptodev_sym_raw_operation_done_t dequeue_done;
1446 /* Driver specific context data */
1447 __extension__ uint8_t drv_ctx_data[];
1451 * Configure raw data-path context data.
1454 * After the context data is configured, the user should call
1455 * rte_cryptodev_raw_attach_session() before using it in
1456 * rte_cryptodev_raw_enqueue/dequeue function call.
1458 * @param dev_id The device identifier.
1459 * @param qp_id The index of the queue pair from which to
1460 * retrieve processed packets. The value must be
1461 * in the range [0, nb_queue_pair - 1] previously
1462 * supplied to rte_cryptodev_configure().
1463 * @param ctx The raw data-path context data.
1464 * @param sess_type session type.
1465 * @param session_ctx Session context data.
1466 * @param is_update Set 0 if it is to initialize the ctx.
1467 * Set 1 if ctx is initialized and only to update
1468 * session context data.
1470 * - On success return 0.
1471 * - On failure return negative integer.
1475 rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
1476 struct rte_crypto_raw_dp_ctx *ctx,
1477 enum rte_crypto_op_sess_type sess_type,
1478 union rte_cryptodev_session_ctx session_ctx,
1482 * Enqueue a vectorized operation descriptor into the device queue but the
1483 * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
1486 * @param ctx The initialized raw data-path context data.
1487 * @param vec Vectorized operation descriptor.
1488 * @param ofs Start and stop offsets for auth and cipher
1490 * @param user_data The array of user data for dequeue later.
1491 * @param enqueue_status Driver written value to specify the
1492 * enqueue status. Possible values:
1493 * - 1: The number of operations returned are
1494 * enqueued successfully.
1495 * - 0: The number of operations returned are
1496 * cached into the queue but are not processed
1497 * until rte_cryptodev_raw_enqueue_done() is
1499 * - negative integer: Error occurred.
1501 * - The number of operations in the descriptor successfully enqueued or
1502 * cached into the queue but not enqueued yet, depends on the
1503 * "enqueue_status" value.
1507 rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1508 struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
1509 void **user_data, int *enqueue_status);
1512 * Enqueue single raw data vector into the device queue but the driver may or
1513 * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
1515 * @param ctx The initialized raw data-path context data.
1516 * @param data_vec The buffer data vector.
1517 * @param n_data_vecs Number of buffer data vectors.
1518 * @param ofs Start and stop offsets for auth and cipher
1520 * @param iv IV virtual and IOVA addresses
1521 * @param digest digest virtual and IOVA addresses
1522 * @param aad_or_auth_iv AAD or auth IV virtual and IOVA addresses,
1523 * depends on the algorithm used.
1524 * @param user_data The user data.
1526 * - 1: The data vector is enqueued successfully.
1527 * - 0: The data vector is cached into the queue but is not processed
1528 * until rte_cryptodev_raw_enqueue_done() is called.
1529 * - negative integer: failure.
1532 static __rte_always_inline int
1533 rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx *ctx,
1534 struct rte_crypto_vec *data_vec, uint16_t n_data_vecs,
1535 union rte_crypto_sym_ofs ofs,
1536 struct rte_crypto_va_iova_ptr *iv,
1537 struct rte_crypto_va_iova_ptr *digest,
1538 struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
1541 return (*ctx->enqueue)(ctx->qp_data, ctx->drv_ctx_data, data_vec,
1542 n_data_vecs, ofs, iv, digest, aad_or_auth_iv, user_data);
1546 * Start processing all enqueued operations from last
1547 * rte_cryptodev_configure_raw_dp_ctx() call.
1549 * @param ctx The initialized raw data-path context data.
1550 * @param n The number of operations cached.
1552 * - On success return 0.
1553 * - On failure return negative integer.
1557 rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
1561 * Dequeue a burst of symmetric crypto processing.
1563 * @param ctx The initialized raw data-path context
1565 * @param get_dequeue_count User provided callback function to
1566 * obtain dequeue operation count.
1567 * @param max_nb_to_dequeue When get_dequeue_count is NULL this
1568 * value is used to pass the maximum
1569 * number of operations to be dequeued.
1570 * @param post_dequeue User provided callback function to
1571 * post-process a dequeued operation.
1572 * @param out_user_data User data pointer array to be retrieve
1573 * from device queue. In case of
1574 * *is_user_data_array* is set there
1575 * should be enough room to store all
1577 * @param is_user_data_array Set 1 if every dequeued user data will
1578 * be written into out_user_data array.
1579 * Set 0 if only the first user data will
1580 * be written into out_user_data array.
1581 * @param n_success Driver written value to specific the
1582 * total successful operations count.
1583 * @param dequeue_status Driver written value to specify the
1584 * dequeue status. Possible values:
1585 * - 1: Successfully dequeued the number
1586 * of operations returned. The user
1587 * data previously set during enqueue
1588 * is stored in the "out_user_data".
1589 * - 0: The number of operations returned
1590 * are completed and the user data is
1591 * stored in the "out_user_data", but
1592 * they are not freed from the queue
1594 * rte_cryptodev_raw_dequeue_done()
1596 * - negative integer: Error occurred.
1598 * - The number of operations dequeued or completed but not freed from the
1599 * queue, depends on "dequeue_status" value.
1603 rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
1604 rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1605 uint32_t max_nb_to_dequeue,
1606 rte_cryptodev_raw_post_dequeue_t post_dequeue,
1607 void **out_user_data, uint8_t is_user_data_array,
1608 uint32_t *n_success, int *dequeue_status);
1611 * Dequeue a symmetric crypto processing.
1613 * @param ctx The initialized raw data-path context
1615 * @param dequeue_status Driver written value to specify the
1616 * dequeue status. Possible values:
1617 * - 1: Successfully dequeued a operation.
1618 * The user data is returned.
1619 * - 0: The first operation in the queue
1620 * is completed and the user data
1621 * previously set during enqueue is
1622 * returned, but it is not freed from
1624 * rte_cryptodev_raw_dequeue_done() is
1626 * - negative integer: Error occurred.
1627 * @param op_status Driver written value to specify
1630 * - The user data pointer retrieved from device queue or NULL if no
1631 * operation is ready for dequeue.
1634 static __rte_always_inline void *
1635 rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx *ctx,
1636 int *dequeue_status, enum rte_crypto_op_status *op_status)
1638 return (*ctx->dequeue)(ctx->qp_data, ctx->drv_ctx_data, dequeue_status,
1643 * Inform the queue pair dequeue operations is finished.
1645 * @param ctx The initialized raw data-path context data.
1646 * @param n The number of operations.
1648 * - On success return 0.
1649 * - On failure return negative integer.
1653 rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
1657 * Add a user callback for a given crypto device and queue pair which will be
1658 * called on crypto ops enqueue.
1660 * This API configures a function to be called for each burst of crypto ops
1661 * received on a given crypto device queue pair. The return value is a pointer
1662 * that can be used later to remove the callback using
1663 * rte_cryptodev_remove_enq_callback().
1665 * Callbacks registered by application would not survive
1666 * rte_cryptodev_configure() as it reinitializes the callback list.
1667 * It is user responsibility to remove all installed callbacks before
1668 * calling rte_cryptodev_configure() to avoid possible memory leakage.
1669 * Application is expected to call add API after rte_cryptodev_configure().
1671 * Multiple functions can be registered per queue pair & they are called
1672 * in the order they were added. The API does not restrict on maximum number
1675 * @param dev_id The identifier of the device.
1676 * @param qp_id The index of the queue pair on which ops are
1677 * to be enqueued for processing. The value
1678 * must be in the range [0, nb_queue_pairs - 1]
1679 * previously supplied to
1680 * *rte_cryptodev_configure*.
1681 * @param cb_fn The callback function
1682 * @param cb_arg A generic pointer parameter which will be passed
1683 * to each invocation of the callback function on
1684 * this crypto device and queue pair.
1687 * - NULL on error & rte_errno will contain the error code.
1688 * - On success, a pointer value which can later be used to remove the
1693 struct rte_cryptodev_cb *
1694 rte_cryptodev_add_enq_callback(uint8_t dev_id,
1696 rte_cryptodev_callback_fn cb_fn,
1700 * Remove a user callback function for given crypto device and queue pair.
1702 * This function is used to remove enqueue callbacks that were added to a
1703 * crypto device queue pair using rte_cryptodev_add_enq_callback().
1707 * @param dev_id The identifier of the device.
1708 * @param qp_id The index of the queue pair on which ops are
1709 * to be enqueued. The value must be in the
1710 * range [0, nb_queue_pairs - 1] previously
1711 * supplied to *rte_cryptodev_configure*.
1712 * @param cb Pointer to user supplied callback created via
1713 * rte_cryptodev_add_enq_callback().
1716 * - 0: Success. Callback was removed.
1717 * - <0: The dev_id or the qp_id is out of range, or the callback
1718 * is NULL or not found for the crypto device queue pair.
1722 int rte_cryptodev_remove_enq_callback(uint8_t dev_id,
1724 struct rte_cryptodev_cb *cb);
1727 * Add a user callback for a given crypto device and queue pair which will be
1728 * called on crypto ops dequeue.
1730 * This API configures a function to be called for each burst of crypto ops
1731 * received on a given crypto device queue pair. The return value is a pointer
1732 * that can be used later to remove the callback using
1733 * rte_cryptodev_remove_deq_callback().
1735 * Callbacks registered by application would not survive
1736 * rte_cryptodev_configure() as it reinitializes the callback list.
1737 * It is user responsibility to remove all installed callbacks before
1738 * calling rte_cryptodev_configure() to avoid possible memory leakage.
1739 * Application is expected to call add API after rte_cryptodev_configure().
1741 * Multiple functions can be registered per queue pair & they are called
1742 * in the order they were added. The API does not restrict on maximum number
1745 * @param dev_id The identifier of the device.
1746 * @param qp_id The index of the queue pair on which ops are
1747 * to be dequeued. The value must be in the
1748 * range [0, nb_queue_pairs - 1] previously
1749 * supplied to *rte_cryptodev_configure*.
1750 * @param cb_fn The callback function
1751 * @param cb_arg A generic pointer parameter which will be passed
1752 * to each invocation of the callback function on
1753 * this crypto device and queue pair.
1756 * - NULL on error & rte_errno will contain the error code.
1757 * - On success, a pointer value which can later be used to remove the
1762 struct rte_cryptodev_cb *
1763 rte_cryptodev_add_deq_callback(uint8_t dev_id,
1765 rte_cryptodev_callback_fn cb_fn,
1769 * Remove a user callback function for given crypto device and queue pair.
1771 * This function is used to remove dequeue callbacks that were added to a
1772 * crypto device queue pair using rte_cryptodev_add_deq_callback().
1776 * @param dev_id The identifier of the device.
1777 * @param qp_id The index of the queue pair on which ops are
1778 * to be dequeued. The value must be in the
1779 * range [0, nb_queue_pairs - 1] previously
1780 * supplied to *rte_cryptodev_configure*.
1781 * @param cb Pointer to user supplied callback created via
1782 * rte_cryptodev_add_deq_callback().
1785 * - 0: Success. Callback was removed.
1786 * - <0: The dev_id or the qp_id is out of range, or the callback
1787 * is NULL or not found for the crypto device queue pair.
1790 int rte_cryptodev_remove_deq_callback(uint8_t dev_id,
1792 struct rte_cryptodev_cb *cb);
1794 #include <rte_cryptodev_core.h>
1797 * Dequeue a burst of processed crypto operations from a queue on the crypto
1798 * device. The dequeued operation are stored in *rte_crypto_op* structures
1799 * whose pointers are supplied in the *ops* array.
1801 * The rte_cryptodev_dequeue_burst() function returns the number of ops
1802 * actually dequeued, which is the number of *rte_crypto_op* data structures
1803 * effectively supplied into the *ops* array.
1805 * A return value equal to *nb_ops* indicates that the queue contained
1806 * at least *nb_ops* operations, and this is likely to signify that other
1807 * processed operations remain in the devices output queue. Applications
1808 * implementing a "retrieve as many processed operations as possible" policy
1809 * can check this specific case and keep invoking the
1810 * rte_cryptodev_dequeue_burst() function until a value less than
1811 * *nb_ops* is returned.
1813 * The rte_cryptodev_dequeue_burst() function does not provide any error
1814 * notification to avoid the corresponding overhead.
1816 * @param dev_id The symmetric crypto device identifier
1817 * @param qp_id The index of the queue pair from which to
1818 * retrieve processed packets. The value must be
1819 * in the range [0, nb_queue_pair - 1] previously
1820 * supplied to rte_cryptodev_configure().
1821 * @param ops The address of an array of pointers to
1822 * *rte_crypto_op* structures that must be
1823 * large enough to store *nb_ops* pointers in it.
1824 * @param nb_ops The maximum number of operations to dequeue.
1827 * - The number of operations actually dequeued, which is the number
1828 * of pointers to *rte_crypto_op* structures effectively supplied to the
1831 static inline uint16_t
1832 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
1833 struct rte_crypto_op **ops, uint16_t nb_ops)
1835 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
1837 rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1838 nb_ops = (*dev->dequeue_burst)
1839 (dev->data->queue_pairs[qp_id], ops, nb_ops);
1840 #ifdef RTE_CRYPTO_CALLBACKS
1841 if (unlikely(dev->deq_cbs != NULL)) {
1842 struct rte_cryptodev_cb_rcu *list;
1843 struct rte_cryptodev_cb *cb;
1845 /* __ATOMIC_RELEASE memory order was used when the
1846 * call back was inserted into the list.
1847 * Since there is a clear dependency between loading
1848 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1851 list = &dev->deq_cbs[qp_id];
1852 rte_rcu_qsbr_thread_online(list->qsbr, 0);
1853 cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1855 while (cb != NULL) {
1856 nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1861 rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1868 * Enqueue a burst of operations for processing on a crypto device.
1870 * The rte_cryptodev_enqueue_burst() function is invoked to place
1871 * crypto operations on the queue *qp_id* of the device designated by
1874 * The *nb_ops* parameter is the number of operations to process which are
1875 * supplied in the *ops* array of *rte_crypto_op* structures.
1877 * The rte_cryptodev_enqueue_burst() function returns the number of
1878 * operations it actually enqueued for processing. A return value equal to
1879 * *nb_ops* means that all packets have been enqueued.
1881 * @param dev_id The identifier of the device.
1882 * @param qp_id The index of the queue pair which packets are
1883 * to be enqueued for processing. The value
1884 * must be in the range [0, nb_queue_pairs - 1]
1885 * previously supplied to
1886 * *rte_cryptodev_configure*.
1887 * @param ops The address of an array of *nb_ops* pointers
1888 * to *rte_crypto_op* structures which contain
1889 * the crypto operations to be processed.
1890 * @param nb_ops The number of operations to process.
1893 * The number of operations actually enqueued on the crypto device. The return
1894 * value can be less than the value of the *nb_ops* parameter when the
1895 * crypto devices queue is full or if invalid parameters are specified in
1896 * a *rte_crypto_op*.
1898 static inline uint16_t
1899 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
1900 struct rte_crypto_op **ops, uint16_t nb_ops)
1902 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
1904 #ifdef RTE_CRYPTO_CALLBACKS
1905 if (unlikely(dev->enq_cbs != NULL)) {
1906 struct rte_cryptodev_cb_rcu *list;
1907 struct rte_cryptodev_cb *cb;
1909 /* __ATOMIC_RELEASE memory order was used when the
1910 * call back was inserted into the list.
1911 * Since there is a clear dependency between loading
1912 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
1915 list = &dev->enq_cbs[qp_id];
1916 rte_rcu_qsbr_thread_online(list->qsbr, 0);
1917 cb = __atomic_load_n(&list->next, __ATOMIC_RELAXED);
1919 while (cb != NULL) {
1920 nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
1925 rte_rcu_qsbr_thread_offline(list->qsbr, 0);
1929 rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
1930 return (*dev->enqueue_burst)(
1931 dev->data->queue_pairs[qp_id], ops, nb_ops);
1940 #endif /* _RTE_CRYPTODEV_H_ */