1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2017 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>
27 extern const char **rte_cyptodev_names;
31 #define CDEV_LOG_ERR(...) \
32 RTE_LOG(ERR, CRYPTODEV, \
33 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
34 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
36 #define CDEV_LOG_INFO(...) \
37 RTE_LOG(INFO, CRYPTODEV, \
38 RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
39 RTE_FMT_TAIL(__VA_ARGS__,)))
41 #define CDEV_LOG_DEBUG(...) \
42 RTE_LOG(DEBUG, CRYPTODEV, \
43 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
44 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
46 #define CDEV_PMD_TRACE(...) \
47 RTE_LOG(DEBUG, CRYPTODEV, \
48 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
49 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
52 * A macro that points to an offset from the start
53 * of the crypto operation structure (rte_crypto_op)
55 * The returned pointer is cast to type t.
58 * The crypto operation.
60 * The offset from the start of the crypto operation.
62 * The type to cast the result into.
64 #define rte_crypto_op_ctod_offset(c, t, o) \
65 ((t)((char *)(c) + (o)))
68 * A macro that returns the physical address that points
69 * to an offset from the start of the crypto operation
73 * The crypto operation.
75 * The offset from the start of the crypto operation
76 * to calculate address from.
78 #define rte_crypto_op_ctophys_offset(c, o) \
79 (rte_iova_t)((c)->phys_addr + (o))
82 * Crypto parameters range description
84 struct rte_crypto_param_range {
85 uint16_t min; /**< minimum size */
86 uint16_t max; /**< maximum size */
88 /**< if a range of sizes are supported,
89 * this parameter is used to indicate
90 * increments in byte size that are supported
91 * between the minimum and maximum
96 * Symmetric Crypto Capability
98 struct rte_cryptodev_symmetric_capability {
99 enum rte_crypto_sym_xform_type xform_type;
100 /**< Transform type : Authentication / Cipher / AEAD */
104 enum rte_crypto_auth_algorithm algo;
105 /**< authentication algorithm */
107 /**< algorithm block size */
108 struct rte_crypto_param_range key_size;
109 /**< auth key size range */
110 struct rte_crypto_param_range digest_size;
111 /**< digest size range */
112 struct rte_crypto_param_range aad_size;
113 /**< Additional authentication data size range */
114 struct rte_crypto_param_range iv_size;
115 /**< Initialisation vector data size range */
117 /**< Symmetric Authentication transform capabilities */
119 enum rte_crypto_cipher_algorithm algo;
120 /**< cipher algorithm */
122 /**< algorithm block size */
123 struct rte_crypto_param_range key_size;
124 /**< cipher key size range */
125 struct rte_crypto_param_range iv_size;
126 /**< Initialisation vector data size range */
128 /**< Symmetric Cipher transform capabilities */
130 enum rte_crypto_aead_algorithm algo;
131 /**< AEAD algorithm */
133 /**< algorithm block size */
134 struct rte_crypto_param_range key_size;
135 /**< AEAD key size range */
136 struct rte_crypto_param_range digest_size;
137 /**< digest size range */
138 struct rte_crypto_param_range aad_size;
139 /**< Additional authentication data size range */
140 struct rte_crypto_param_range iv_size;
141 /**< Initialisation vector data size range */
147 * Asymmetric Xform Crypto Capability
150 struct rte_cryptodev_asymmetric_xform_capability {
151 enum rte_crypto_asym_xform_type xform_type;
152 /**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
155 /**< bitmask for supported rte_crypto_asym_op_type */
159 struct rte_crypto_param_range modlen;
160 /**< Range of modulus length supported by modulus based xform.
161 * Value 0 mean implementation default
167 * Asymmetric Crypto Capability
170 struct rte_cryptodev_asymmetric_capability {
171 struct rte_cryptodev_asymmetric_xform_capability xform_capa;
175 /** Structure used to capture a capability of a crypto device */
176 struct rte_cryptodev_capabilities {
177 enum rte_crypto_op_type op;
178 /**< Operation type */
182 struct rte_cryptodev_symmetric_capability sym;
183 /**< Symmetric operation capability parameters */
184 struct rte_cryptodev_asymmetric_capability asym;
185 /**< Asymmetric operation capability parameters */
189 /** Structure used to describe crypto algorithms */
190 struct rte_cryptodev_sym_capability_idx {
191 enum rte_crypto_sym_xform_type type;
193 enum rte_crypto_cipher_algorithm cipher;
194 enum rte_crypto_auth_algorithm auth;
195 enum rte_crypto_aead_algorithm aead;
200 * Structure used to describe asymmetric crypto xforms
201 * Each xform maps to one asym algorithm.
204 struct rte_cryptodev_asym_capability_idx {
205 enum rte_crypto_asym_xform_type type;
206 /**< Asymmetric xform (algo) type */
210 * Provide capabilities available for defined device and algorithm
212 * @param dev_id The identifier of the device.
213 * @param idx Description of crypto algorithms.
216 * - Return description of the symmetric crypto capability if exist.
217 * - Return NULL if the capability not exist.
219 const struct rte_cryptodev_symmetric_capability *
220 rte_cryptodev_sym_capability_get(uint8_t dev_id,
221 const struct rte_cryptodev_sym_capability_idx *idx);
224 * Provide capabilities available for defined device and xform
226 * @param dev_id The identifier of the device.
227 * @param idx Description of asym crypto xform.
230 * - Return description of the asymmetric crypto capability if exist.
231 * - Return NULL if the capability not exist.
234 const struct rte_cryptodev_asymmetric_xform_capability *
235 rte_cryptodev_asym_capability_get(uint8_t dev_id,
236 const struct rte_cryptodev_asym_capability_idx *idx);
239 * Check if key size and initial vector are supported
240 * in crypto cipher capability
242 * @param capability Description of the symmetric crypto capability.
243 * @param key_size Cipher key size.
244 * @param iv_size Cipher initial vector size.
247 * - Return 0 if the parameters are in range of the capability.
248 * - Return -1 if the parameters are out of range of the capability.
251 rte_cryptodev_sym_capability_check_cipher(
252 const struct rte_cryptodev_symmetric_capability *capability,
253 uint16_t key_size, uint16_t iv_size);
256 * Check if key size and initial vector are supported
257 * in crypto auth capability
259 * @param capability Description of the symmetric crypto capability.
260 * @param key_size Auth key size.
261 * @param digest_size Auth digest size.
262 * @param iv_size Auth initial vector size.
265 * - Return 0 if the parameters are in range of the capability.
266 * - Return -1 if the parameters are out of range of the capability.
269 rte_cryptodev_sym_capability_check_auth(
270 const struct rte_cryptodev_symmetric_capability *capability,
271 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
274 * Check if key, digest, AAD and initial vector sizes are supported
275 * in crypto AEAD capability
277 * @param capability Description of the symmetric crypto capability.
278 * @param key_size AEAD key size.
279 * @param digest_size AEAD digest size.
280 * @param aad_size AEAD AAD size.
281 * @param iv_size AEAD IV size.
284 * - Return 0 if the parameters are in range of the capability.
285 * - Return -1 if the parameters are out of range of the capability.
288 rte_cryptodev_sym_capability_check_aead(
289 const struct rte_cryptodev_symmetric_capability *capability,
290 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
294 * Check if op type is supported
296 * @param capability Description of the asymmetric crypto capability.
297 * @param op_type op type
300 * - Return 1 if the op type is supported
301 * - Return 0 if unsupported
305 rte_cryptodev_asym_xform_capability_check_optype(
306 const struct rte_cryptodev_asymmetric_xform_capability *capability,
307 enum rte_crypto_asym_op_type op_type);
310 * Check if modulus length is in supported range
312 * @param capability Description of the asymmetric crypto capability.
313 * @param modlen modulus length.
316 * - Return 0 if the parameters are in range of the capability.
317 * - Return -1 if the parameters are out of range of the capability.
321 rte_cryptodev_asym_xform_capability_check_modlen(
322 const struct rte_cryptodev_asymmetric_xform_capability *capability,
326 * Provide the cipher algorithm enum, given an algorithm string
328 * @param algo_enum A pointer to the cipher algorithm
330 * @param algo_string Authentication algo string
333 * - Return -1 if string is not valid
334 * - Return 0 is the string is valid
337 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
338 const char *algo_string);
341 * Provide the authentication algorithm enum, given an algorithm string
343 * @param algo_enum A pointer to the authentication algorithm
345 * @param algo_string Authentication algo string
348 * - Return -1 if string is not valid
349 * - Return 0 is the string is valid
352 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
353 const char *algo_string);
356 * Provide the AEAD algorithm enum, given an algorithm string
358 * @param algo_enum A pointer to the AEAD algorithm
360 * @param algo_string AEAD algorithm string
363 * - Return -1 if string is not valid
364 * - Return 0 is the string is valid
367 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
368 const char *algo_string);
371 * Provide the Asymmetric xform enum, given an xform string
373 * @param xform_enum A pointer to the xform type
375 * @param xform_string xform string
378 * - Return -1 if string is not valid
379 * - Return 0 if the string is valid
383 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
384 const char *xform_string);
387 /** Macro used at end of crypto PMD list */
388 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
389 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
393 * Crypto device supported feature flags
396 * New features flags should be added to the end of the list
398 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
400 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
401 /**< Symmetric crypto operations are supported */
402 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
403 /**< Asymmetric crypto operations are supported */
404 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
405 /**< Chaining symmetric crypto operations are supported */
406 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
407 /**< Utilises CPU SIMD SSE instructions */
408 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
409 /**< Utilises CPU SIMD AVX instructions */
410 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
411 /**< Utilises CPU SIMD AVX2 instructions */
412 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
413 /**< Utilises CPU AES-NI instructions */
414 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
415 /**< Operations are off-loaded to an
416 * external hardware accelerator
418 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
419 /**< Utilises CPU SIMD AVX512 instructions */
420 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL (1ULL << 9)
421 /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
424 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT (1ULL << 10)
425 /**< Out-of-place Scatter-gather (SGL) buffers are
426 * supported in input and output
428 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT (1ULL << 11)
429 /**< Out-of-place Scatter-gather (SGL) buffers are supported
430 * in input, combined with linear buffers (LB), with a
431 * single segment in output
433 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT (1ULL << 12)
434 /**< Out-of-place Scatter-gather (SGL) buffers are supported
435 * in output, combined with linear buffers (LB) in input
437 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT (1ULL << 13)
438 /**< Out-of-place linear buffers (LB) are supported in input and output */
439 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 14)
440 /**< Utilises CPU NEON instructions */
441 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 15)
442 /**< Utilises ARM CPU Cryptographic Extensions */
443 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 16)
444 /**< Support Security Protocol Processing */
445 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP (1ULL << 17)
446 /**< Support RSA Private Key OP with exponent */
447 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT (1ULL << 18)
448 /**< Support RSA Private Key OP with CRT (quintuple) Keys */
449 #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED (1ULL << 19)
450 /**< Support encrypted-digest operations where digest is appended to data */
454 * Get the name of a crypto device feature flag
456 * @param flag The mask describing the flag.
459 * The name of this flag, or NULL if it's not a valid feature flag.
463 rte_cryptodev_get_feature_name(uint64_t flag);
465 /** Crypto device information */
466 struct rte_cryptodev_info {
467 const char *driver_name; /**< Driver name. */
468 uint8_t driver_id; /**< Driver identifier */
469 struct rte_device *device; /**< Generic device information. */
471 uint64_t feature_flags;
472 /**< Feature flags exposes HW/SW features for the given device */
474 const struct rte_cryptodev_capabilities *capabilities;
475 /**< Array of devices supported capabilities */
477 unsigned max_nb_queue_pairs;
478 /**< Maximum number of queues pairs supported by device. */
480 uint16_t min_mbuf_headroom_req;
481 /**< Minimum mbuf headroom required by device */
483 uint16_t min_mbuf_tailroom_req;
484 /**< Minimum mbuf tailroom required by device */
487 unsigned max_nb_sessions;
488 /**< Maximum number of sessions supported by device.
489 * If 0, the device does not have any limitation in
490 * number of sessions that can be used.
495 #define RTE_CRYPTODEV_DETACHED (0)
496 #define RTE_CRYPTODEV_ATTACHED (1)
498 /** Definitions of Crypto device event types */
499 enum rte_cryptodev_event_type {
500 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
501 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
502 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
505 /** Crypto device queue pair configuration structure. */
506 struct rte_cryptodev_qp_conf {
507 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
508 struct rte_mempool *mp_session;
509 /**< The mempool for creating session in sessionless mode */
510 struct rte_mempool *mp_session_private;
511 /**< The mempool for creating sess private data in sessionless mode */
515 * Typedef for application callback function to be registered by application
516 * software for notification of device events
518 * @param dev_id Crypto device identifier
519 * @param event Crypto device event to register for notification of.
520 * @param cb_arg User specified parameter to be passed as to passed to
521 * users callback function.
523 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
524 enum rte_cryptodev_event_type event, void *cb_arg);
527 /** Crypto Device statistics */
528 struct rte_cryptodev_stats {
529 uint64_t enqueued_count;
530 /**< Count of all operations enqueued */
531 uint64_t dequeued_count;
532 /**< Count of all operations dequeued */
534 uint64_t enqueue_err_count;
535 /**< Total error count on operations enqueued */
536 uint64_t dequeue_err_count;
537 /**< Total error count on operations dequeued */
540 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
541 /**< Max length of name of crypto PMD */
544 * Get the device identifier for the named crypto device.
546 * @param name device name to select the device structure.
549 * - Returns crypto device identifier on success.
550 * - Return -1 on failure to find named crypto device.
553 rte_cryptodev_get_dev_id(const char *name);
556 * Get the crypto device name given a device identifier.
559 * The identifier of the device
562 * - Returns crypto device name.
563 * - Returns NULL if crypto device is not present.
566 rte_cryptodev_name_get(uint8_t dev_id);
569 * Get the total number of crypto devices that have been successfully
573 * - The total number of usable crypto devices.
576 rte_cryptodev_count(void);
579 * Get number of crypto device defined type.
581 * @param driver_id driver identifier.
584 * Returns number of crypto device.
587 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
590 * Get number and identifiers of attached crypto devices that
591 * use the same crypto driver.
593 * @param driver_name driver name.
594 * @param devices output devices identifiers.
595 * @param nb_devices maximal number of devices.
598 * Returns number of attached crypto device.
601 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
604 * Return the NUMA socket to which a device is connected
607 * The identifier of the device
609 * The NUMA socket id to which the device is connected or
610 * a default of zero if the socket could not be determined.
611 * -1 if returned is the dev_id value is out of range.
614 rte_cryptodev_socket_id(uint8_t dev_id);
616 /** Crypto device configuration structure */
617 struct rte_cryptodev_config {
618 int socket_id; /**< Socket to allocate resources on */
619 uint16_t nb_queue_pairs;
620 /**< Number of queue pairs to configure on device */
622 /**< Feature flags to be disabled. Only the following features are
623 * allowed to be disabled,
624 * - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
625 * - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
626 * - RTE_CRYTPODEV_FF_SECURITY
631 * Configure a device.
633 * This function must be invoked first before any other function in the
634 * API. This function can also be re-invoked when a device is in the
637 * @param dev_id The identifier of the device to configure.
638 * @param config The crypto device configuration structure.
641 * - 0: Success, device configured.
642 * - <0: Error code returned by the driver configuration function.
645 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
650 * The device start step is the last one and consists of setting the configured
651 * offload features and in starting the transmit and the receive units of the
653 * On success, all basic functions exported by the API (link status,
654 * receive/transmit, and so on) can be invoked.
657 * The identifier of the device.
659 * - 0: Success, device started.
660 * - <0: Error code of the driver device start function.
663 rte_cryptodev_start(uint8_t dev_id);
666 * Stop an device. The device can be restarted with a call to
667 * rte_cryptodev_start()
669 * @param dev_id The identifier of the device.
672 rte_cryptodev_stop(uint8_t dev_id);
675 * Close an device. The device cannot be restarted!
677 * @param dev_id The identifier of the device.
680 * - 0 on successfully closing device
681 * - <0 on failure to close device
684 rte_cryptodev_close(uint8_t dev_id);
687 * Allocate and set up a receive queue pair for a device.
690 * @param dev_id The identifier of the device.
691 * @param queue_pair_id The index of the queue pairs to set up. The
692 * value must be in the range [0, nb_queue_pair
693 * - 1] previously supplied to
694 * rte_cryptodev_configure().
695 * @param qp_conf The pointer to the configuration data to be
696 * used for the queue pair.
697 * @param socket_id The *socket_id* argument is the socket
698 * identifier in case of NUMA. The value can be
699 * *SOCKET_ID_ANY* if there is no NUMA constraint
700 * for the DMA memory allocated for the receive
704 * - 0: Success, queue pair correctly set up.
705 * - <0: Queue pair configuration failed
708 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
709 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
712 * Get the number of queue pairs on a specific crypto device
714 * @param dev_id Crypto device identifier.
716 * - The number of configured queue pairs.
719 rte_cryptodev_queue_pair_count(uint8_t dev_id);
723 * Retrieve the general I/O statistics of a device.
725 * @param dev_id The identifier of the device.
726 * @param stats A pointer to a structure of type
727 * *rte_cryptodev_stats* to be filled with the
728 * values of device counters.
730 * - Zero if successful.
731 * - Non-zero otherwise.
734 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
737 * Reset the general I/O statistics of a device.
739 * @param dev_id The identifier of the device.
742 rte_cryptodev_stats_reset(uint8_t dev_id);
745 * Retrieve the contextual information of a device.
747 * @param dev_id The identifier of the device.
748 * @param dev_info A pointer to a structure of type
749 * *rte_cryptodev_info* to be filled with the
750 * contextual information of the device.
752 * @note The capabilities field of dev_info is set to point to the first
753 * element of an array of struct rte_cryptodev_capabilities. The element after
754 * the last valid element has it's op field set to
755 * RTE_CRYPTO_OP_TYPE_UNDEFINED.
758 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
762 * Register a callback function for specific device id.
764 * @param dev_id Device id.
765 * @param event Event interested.
766 * @param cb_fn User supplied callback function to be called.
767 * @param cb_arg Pointer to the parameters for the registered
771 * - On success, zero.
772 * - On failure, a negative value.
775 rte_cryptodev_callback_register(uint8_t dev_id,
776 enum rte_cryptodev_event_type event,
777 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
780 * Unregister a callback function for specific device id.
782 * @param dev_id The device identifier.
783 * @param event Event interested.
784 * @param cb_fn User supplied callback function to be called.
785 * @param cb_arg Pointer to the parameters for the registered
789 * - On success, zero.
790 * - On failure, a negative value.
793 rte_cryptodev_callback_unregister(uint8_t dev_id,
794 enum rte_cryptodev_event_type event,
795 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
798 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
799 struct rte_crypto_op **ops, uint16_t nb_ops);
800 /**< Dequeue processed packets from queue pair of a device. */
802 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
803 struct rte_crypto_op **ops, uint16_t nb_ops);
804 /**< Enqueue packets for processing on queue pair of a device. */
809 struct rte_cryptodev_callback;
811 /** Structure to keep track of registered callbacks */
812 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
814 /** The data structure associated with each crypto device. */
815 struct rte_cryptodev {
816 dequeue_pkt_burst_t dequeue_burst;
817 /**< Pointer to PMD receive function. */
818 enqueue_pkt_burst_t enqueue_burst;
819 /**< Pointer to PMD transmit function. */
821 struct rte_cryptodev_data *data;
822 /**< Pointer to device data */
823 struct rte_cryptodev_ops *dev_ops;
824 /**< Functions exported by PMD */
825 uint64_t feature_flags;
826 /**< Feature flags exposes HW/SW features for the given device */
827 struct rte_device *device;
828 /**< Backing device */
831 /**< Crypto driver identifier*/
833 struct rte_cryptodev_cb_list link_intr_cbs;
834 /**< User application callback for interrupts if present */
837 /**< Context for security ops */
840 uint8_t attached : 1;
841 /**< Flag indicating the device is attached */
842 } __rte_cache_aligned;
845 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
849 * The data part, with no function pointers, associated with each device.
851 * This structure is safe to place in shared memory to be common among
852 * different processes in a multi-process configuration.
854 struct rte_cryptodev_data {
856 /**< Device ID for this instance */
858 /**< Socket ID where memory is allocated */
859 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
860 /**< Unique identifier name */
863 uint8_t dev_started : 1;
864 /**< Device state: STARTED(1)/STOPPED(0) */
866 struct rte_mempool *session_pool;
867 /**< Session memory pool */
869 /**< Array of pointers to queue pairs. */
870 uint16_t nb_queue_pairs;
871 /**< Number of device queue pairs. */
874 /**< PMD-specific private data */
875 } __rte_cache_aligned;
877 extern struct rte_cryptodev *rte_cryptodevs;
880 * Dequeue a burst of processed crypto operations from a queue on the crypto
881 * device. The dequeued operation are stored in *rte_crypto_op* structures
882 * whose pointers are supplied in the *ops* array.
884 * The rte_cryptodev_dequeue_burst() function returns the number of ops
885 * actually dequeued, which is the number of *rte_crypto_op* data structures
886 * effectively supplied into the *ops* array.
888 * A return value equal to *nb_ops* indicates that the queue contained
889 * at least *nb_ops* operations, and this is likely to signify that other
890 * processed operations remain in the devices output queue. Applications
891 * implementing a "retrieve as many processed operations as possible" policy
892 * can check this specific case and keep invoking the
893 * rte_cryptodev_dequeue_burst() function until a value less than
894 * *nb_ops* is returned.
896 * The rte_cryptodev_dequeue_burst() function does not provide any error
897 * notification to avoid the corresponding overhead.
899 * @param dev_id The symmetric crypto device identifier
900 * @param qp_id The index of the queue pair from which to
901 * retrieve processed packets. The value must be
902 * in the range [0, nb_queue_pair - 1] previously
903 * supplied to rte_cryptodev_configure().
904 * @param ops The address of an array of pointers to
905 * *rte_crypto_op* structures that must be
906 * large enough to store *nb_ops* pointers in it.
907 * @param nb_ops The maximum number of operations to dequeue.
910 * - The number of operations actually dequeued, which is the number
911 * of pointers to *rte_crypto_op* structures effectively supplied to the
914 static inline uint16_t
915 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
916 struct rte_crypto_op **ops, uint16_t nb_ops)
918 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
920 nb_ops = (*dev->dequeue_burst)
921 (dev->data->queue_pairs[qp_id], ops, nb_ops);
927 * Enqueue a burst of operations for processing on a crypto device.
929 * The rte_cryptodev_enqueue_burst() function is invoked to place
930 * crypto operations on the queue *qp_id* of the device designated by
933 * The *nb_ops* parameter is the number of operations to process which are
934 * supplied in the *ops* array of *rte_crypto_op* structures.
936 * The rte_cryptodev_enqueue_burst() function returns the number of
937 * operations it actually enqueued for processing. A return value equal to
938 * *nb_ops* means that all packets have been enqueued.
940 * @param dev_id The identifier of the device.
941 * @param qp_id The index of the queue pair which packets are
942 * to be enqueued for processing. The value
943 * must be in the range [0, nb_queue_pairs - 1]
944 * previously supplied to
945 * *rte_cryptodev_configure*.
946 * @param ops The address of an array of *nb_ops* pointers
947 * to *rte_crypto_op* structures which contain
948 * the crypto operations to be processed.
949 * @param nb_ops The number of operations to process.
952 * The number of operations actually enqueued on the crypto device. The return
953 * value can be less than the value of the *nb_ops* parameter when the
954 * crypto devices queue is full or if invalid parameters are specified in
957 static inline uint16_t
958 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
959 struct rte_crypto_op **ops, uint16_t nb_ops)
961 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
963 return (*dev->enqueue_burst)(
964 dev->data->queue_pairs[qp_id], ops, nb_ops);
968 /** Cryptodev symmetric crypto session
969 * Each session is derived from a fixed xform chain. Therefore each session
970 * has a fixed algo, key, op-type, digest_len etc.
972 struct rte_cryptodev_sym_session {
973 uint64_t opaque_data;
974 /**< Can be used for external metadata */
976 /**< number of elements in sess_data array */
977 uint16_t user_data_sz;
978 /**< session user data will be placed after sess_data */
979 __extension__ struct {
983 /**< Driver specific session material, variable size */
986 /** Cryptodev asymmetric crypto session */
987 struct rte_cryptodev_asym_session {
988 __extension__ void *sess_private_data[0];
989 /**< Private asymmetric session material */
993 * Create a symmetric session mempool.
996 * The unique mempool name.
998 * The number of elements in the mempool.
1000 * The size of the element. This value will be ignored if it is smaller than
1001 * the minimum session header size required for the system. For the user who
1002 * want to use the same mempool for sym session and session private data it
1003 * can be the maximum value of all existing devices' private data and session
1006 * The number of per-lcore cache elements
1008 * The private data size of each session.
1010 * The *socket_id* argument is the socket identifier in the case of
1011 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
1012 * constraint for the reserved zone.
1015 * - On success return size of the session
1016 * - On failure returns 0
1019 struct rte_mempool *
1020 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1021 uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1025 * Create symmetric crypto session header (generic with no private data)
1027 * @param mempool Symmetric session mempool to allocate session
1030 * - On success return pointer to sym-session
1031 * - On failure returns NULL
1033 struct rte_cryptodev_sym_session *
1034 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
1037 * Create asymmetric crypto session header (generic with no private data)
1039 * @param mempool mempool to allocate asymmetric session
1042 * - On success return pointer to asym-session
1043 * - On failure returns NULL
1046 struct rte_cryptodev_asym_session *
1047 rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
1050 * Frees symmetric crypto session header, after checking that all
1051 * the device private data has been freed, returning it
1052 * to its original mempool.
1054 * @param sess Session header to be freed.
1057 * - 0 if successful.
1058 * - -EINVAL if session is NULL.
1059 * - -EBUSY if not all device private data has been freed.
1062 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
1065 * Frees asymmetric crypto session header, after checking that all
1066 * the device private data has been freed, returning it
1067 * to its original mempool.
1069 * @param sess Session header to be freed.
1072 * - 0 if successful.
1073 * - -EINVAL if session is NULL.
1074 * - -EBUSY if not all device private data has been freed.
1078 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
1081 * Fill out private data for the device id, based on its device type.
1083 * @param dev_id ID of device that we want the session to be used on
1084 * @param sess Session where the private data will be attached to
1085 * @param xforms Symmetric crypto transform operations to apply on flow
1086 * processed with this session
1087 * @param mempool Mempool where the private data is allocated.
1090 * - On success, zero.
1091 * - -EINVAL if input parameters are invalid.
1092 * - -ENOTSUP if crypto device does not support the crypto transform or
1093 * does not support symmetric operations.
1094 * - -ENOMEM if the private session could not be allocated.
1097 rte_cryptodev_sym_session_init(uint8_t dev_id,
1098 struct rte_cryptodev_sym_session *sess,
1099 struct rte_crypto_sym_xform *xforms,
1100 struct rte_mempool *mempool);
1103 * Initialize asymmetric session on a device with specific asymmetric xform
1105 * @param dev_id ID of device that we want the session to be used on
1106 * @param sess Session to be set up on a device
1107 * @param xforms Asymmetric crypto transform operations to apply on flow
1108 * processed with this session
1109 * @param mempool Mempool to be used for internal allocation.
1112 * - On success, zero.
1113 * - -EINVAL if input parameters are invalid.
1114 * - -ENOTSUP if crypto device does not support the crypto transform.
1115 * - -ENOMEM if the private session could not be allocated.
1119 rte_cryptodev_asym_session_init(uint8_t dev_id,
1120 struct rte_cryptodev_asym_session *sess,
1121 struct rte_crypto_asym_xform *xforms,
1122 struct rte_mempool *mempool);
1125 * Frees private data for the device id, based on its device type,
1126 * returning it to its mempool. It is the application's responsibility
1127 * to ensure that private session data is not cleared while there are
1128 * still in-flight operations using it.
1130 * @param dev_id ID of device that uses the session.
1131 * @param sess Session containing the reference to the private data
1134 * - 0 if successful.
1135 * - -EINVAL if device is invalid or session is NULL.
1136 * - -ENOTSUP if crypto device does not support symmetric operations.
1139 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1140 struct rte_cryptodev_sym_session *sess);
1143 * Frees resources held by asymmetric session during rte_cryptodev_session_init
1145 * @param dev_id ID of device that uses the asymmetric session.
1146 * @param sess Asymmetric session setup on device using
1147 * rte_cryptodev_session_init
1149 * - 0 if successful.
1150 * - -EINVAL if device is invalid or session is NULL.
1154 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1155 struct rte_cryptodev_asym_session *sess);
1158 * Get the size of the header session, for all registered drivers excluding
1159 * the user data size.
1162 * Size of the symmetric header session.
1165 rte_cryptodev_sym_get_header_session_size(void);
1168 * Get the size of the header session from created session.
1171 * The sym cryptodev session pointer
1174 * - If sess is not NULL, return the size of the header session including
1175 * the private data size defined within sess.
1176 * - If sess is NULL, return 0.
1180 rte_cryptodev_sym_get_existing_header_session_size(
1181 struct rte_cryptodev_sym_session *sess);
1184 * Get the size of the asymmetric session header, for all registered drivers.
1187 * Size of the asymmetric header session.
1191 rte_cryptodev_asym_get_header_session_size(void);
1194 * Get the size of the private symmetric session data
1197 * @param dev_id The device identifier.
1200 * - Size of the private data, if successful
1201 * - 0 if device is invalid or does not have private
1205 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
1208 * Get the size of the private data for asymmetric session
1211 * @param dev_id The device identifier.
1214 * - Size of the asymmetric private data, if successful
1215 * - 0 if device is invalid or does not have private session
1219 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
1222 * Provide driver identifier.
1225 * The pointer to a driver name.
1227 * The driver type identifier or -1 if no driver found
1229 int rte_cryptodev_driver_id_get(const char *name);
1232 * Provide driver name.
1235 * The driver identifier.
1237 * The driver name or null if no driver found
1239 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1242 * Store user data in a session.
1244 * @param sess Session pointer allocated by
1245 * *rte_cryptodev_sym_session_create*.
1246 * @param data Pointer to the user data.
1247 * @param size Size of the user data.
1250 * - On success, zero.
1251 * - On failure, a negative value.
1255 rte_cryptodev_sym_session_set_user_data(
1256 struct rte_cryptodev_sym_session *sess,
1261 * Get user data stored in a session.
1263 * @param sess Session pointer allocated by
1264 * *rte_cryptodev_sym_session_create*.
1267 * - On success return pointer to user data.
1268 * - On failure returns NULL.
1272 rte_cryptodev_sym_session_get_user_data(
1273 struct rte_cryptodev_sym_session *sess);
1279 #endif /* _RTE_CRYPTODEV_H_ */