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>
27 #include "rte_cryptodev_trace_fp.h"
29 extern const char **rte_cyptodev_names;
33 #define CDEV_LOG_ERR(...) \
34 RTE_LOG(ERR, CRYPTODEV, \
35 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
36 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
38 #define CDEV_LOG_INFO(...) \
39 RTE_LOG(INFO, CRYPTODEV, \
40 RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
41 RTE_FMT_TAIL(__VA_ARGS__,)))
43 #define CDEV_LOG_DEBUG(...) \
44 RTE_LOG(DEBUG, CRYPTODEV, \
45 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
46 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
48 #define CDEV_PMD_TRACE(...) \
49 RTE_LOG(DEBUG, CRYPTODEV, \
50 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
51 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
54 * A macro that points to an offset from the start
55 * of the crypto operation structure (rte_crypto_op)
57 * The returned pointer is cast to type t.
60 * The crypto operation.
62 * The offset from the start of the crypto operation.
64 * The type to cast the result into.
66 #define rte_crypto_op_ctod_offset(c, t, o) \
67 ((t)((char *)(c) + (o)))
70 * A macro that returns the physical address that points
71 * to an offset from the start of the crypto operation
75 * The crypto operation.
77 * The offset from the start of the crypto operation
78 * to calculate address from.
80 #define rte_crypto_op_ctophys_offset(c, o) \
81 (rte_iova_t)((c)->phys_addr + (o))
84 * Crypto parameters range description
86 struct rte_crypto_param_range {
87 uint16_t min; /**< minimum size */
88 uint16_t max; /**< maximum size */
90 /**< if a range of sizes are supported,
91 * this parameter is used to indicate
92 * increments in byte size that are supported
93 * between the minimum and maximum
98 * Symmetric Crypto Capability
100 struct rte_cryptodev_symmetric_capability {
101 enum rte_crypto_sym_xform_type xform_type;
102 /**< Transform type : Authentication / Cipher / AEAD */
106 enum rte_crypto_auth_algorithm algo;
107 /**< authentication algorithm */
109 /**< algorithm block size */
110 struct rte_crypto_param_range key_size;
111 /**< auth key size range */
112 struct rte_crypto_param_range digest_size;
113 /**< digest size range */
114 struct rte_crypto_param_range aad_size;
115 /**< Additional authentication data size range */
116 struct rte_crypto_param_range iv_size;
117 /**< Initialisation vector data size range */
119 /**< Symmetric Authentication transform capabilities */
121 enum rte_crypto_cipher_algorithm algo;
122 /**< cipher algorithm */
124 /**< algorithm block size */
125 struct rte_crypto_param_range key_size;
126 /**< cipher key size range */
127 struct rte_crypto_param_range iv_size;
128 /**< Initialisation vector data size range */
130 /**< Symmetric Cipher transform capabilities */
132 enum rte_crypto_aead_algorithm algo;
133 /**< AEAD algorithm */
135 /**< algorithm block size */
136 struct rte_crypto_param_range key_size;
137 /**< AEAD key size range */
138 struct rte_crypto_param_range digest_size;
139 /**< digest size range */
140 struct rte_crypto_param_range aad_size;
141 /**< Additional authentication data size range */
142 struct rte_crypto_param_range iv_size;
143 /**< Initialisation vector data size range */
149 * Asymmetric Xform Crypto Capability
152 struct rte_cryptodev_asymmetric_xform_capability {
153 enum rte_crypto_asym_xform_type xform_type;
154 /**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
157 /**< bitmask for supported rte_crypto_asym_op_type */
161 struct rte_crypto_param_range modlen;
162 /**< Range of modulus length supported by modulus based xform.
163 * Value 0 mean implementation default
169 * Asymmetric Crypto Capability
172 struct rte_cryptodev_asymmetric_capability {
173 struct rte_cryptodev_asymmetric_xform_capability xform_capa;
177 /** Structure used to capture a capability of a crypto device */
178 struct rte_cryptodev_capabilities {
179 enum rte_crypto_op_type op;
180 /**< Operation type */
184 struct rte_cryptodev_symmetric_capability sym;
185 /**< Symmetric operation capability parameters */
186 struct rte_cryptodev_asymmetric_capability asym;
187 /**< Asymmetric operation capability parameters */
191 /** Structure used to describe crypto algorithms */
192 struct rte_cryptodev_sym_capability_idx {
193 enum rte_crypto_sym_xform_type type;
195 enum rte_crypto_cipher_algorithm cipher;
196 enum rte_crypto_auth_algorithm auth;
197 enum rte_crypto_aead_algorithm aead;
202 * Structure used to describe asymmetric crypto xforms
203 * Each xform maps to one asym algorithm.
206 struct rte_cryptodev_asym_capability_idx {
207 enum rte_crypto_asym_xform_type type;
208 /**< Asymmetric xform (algo) type */
212 * Provide capabilities available for defined device and algorithm
214 * @param dev_id The identifier of the device.
215 * @param idx Description of crypto algorithms.
218 * - Return description of the symmetric crypto capability if exist.
219 * - Return NULL if the capability not exist.
221 const struct rte_cryptodev_symmetric_capability *
222 rte_cryptodev_sym_capability_get(uint8_t dev_id,
223 const struct rte_cryptodev_sym_capability_idx *idx);
226 * Provide capabilities available for defined device and xform
228 * @param dev_id The identifier of the device.
229 * @param idx Description of asym crypto xform.
232 * - Return description of the asymmetric crypto capability if exist.
233 * - Return NULL if the capability not exist.
236 const struct rte_cryptodev_asymmetric_xform_capability *
237 rte_cryptodev_asym_capability_get(uint8_t dev_id,
238 const struct rte_cryptodev_asym_capability_idx *idx);
241 * Check if key size and initial vector are supported
242 * in crypto cipher capability
244 * @param capability Description of the symmetric crypto capability.
245 * @param key_size Cipher key size.
246 * @param iv_size Cipher initial vector size.
249 * - Return 0 if the parameters are in range of the capability.
250 * - Return -1 if the parameters are out of range of the capability.
253 rte_cryptodev_sym_capability_check_cipher(
254 const struct rte_cryptodev_symmetric_capability *capability,
255 uint16_t key_size, uint16_t iv_size);
258 * Check if key size and initial vector are supported
259 * in crypto auth capability
261 * @param capability Description of the symmetric crypto capability.
262 * @param key_size Auth key size.
263 * @param digest_size Auth digest size.
264 * @param iv_size Auth initial vector size.
267 * - Return 0 if the parameters are in range of the capability.
268 * - Return -1 if the parameters are out of range of the capability.
271 rte_cryptodev_sym_capability_check_auth(
272 const struct rte_cryptodev_symmetric_capability *capability,
273 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
276 * Check if key, digest, AAD and initial vector sizes are supported
277 * in crypto AEAD capability
279 * @param capability Description of the symmetric crypto capability.
280 * @param key_size AEAD key size.
281 * @param digest_size AEAD digest size.
282 * @param aad_size AEAD AAD size.
283 * @param iv_size AEAD IV size.
286 * - Return 0 if the parameters are in range of the capability.
287 * - Return -1 if the parameters are out of range of the capability.
290 rte_cryptodev_sym_capability_check_aead(
291 const struct rte_cryptodev_symmetric_capability *capability,
292 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
296 * Check if op type is supported
298 * @param capability Description of the asymmetric crypto capability.
299 * @param op_type op type
302 * - Return 1 if the op type is supported
303 * - Return 0 if unsupported
307 rte_cryptodev_asym_xform_capability_check_optype(
308 const struct rte_cryptodev_asymmetric_xform_capability *capability,
309 enum rte_crypto_asym_op_type op_type);
312 * Check if modulus length is in supported range
314 * @param capability Description of the asymmetric crypto capability.
315 * @param modlen modulus length.
318 * - Return 0 if the parameters are in range of the capability.
319 * - Return -1 if the parameters are out of range of the capability.
323 rte_cryptodev_asym_xform_capability_check_modlen(
324 const struct rte_cryptodev_asymmetric_xform_capability *capability,
328 * Provide the cipher algorithm enum, given an algorithm string
330 * @param algo_enum A pointer to the cipher algorithm
332 * @param algo_string Authentication algo string
335 * - Return -1 if string is not valid
336 * - Return 0 is the string is valid
339 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
340 const char *algo_string);
343 * Provide the authentication algorithm enum, given an algorithm string
345 * @param algo_enum A pointer to the authentication 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_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
355 const char *algo_string);
358 * Provide the AEAD algorithm enum, given an algorithm string
360 * @param algo_enum A pointer to the AEAD algorithm
362 * @param algo_string AEAD algorithm string
365 * - Return -1 if string is not valid
366 * - Return 0 is the string is valid
369 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
370 const char *algo_string);
373 * Provide the Asymmetric xform enum, given an xform string
375 * @param xform_enum A pointer to the xform type
377 * @param xform_string xform string
380 * - Return -1 if string is not valid
381 * - Return 0 if the string is valid
385 rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
386 const char *xform_string);
389 /** Macro used at end of crypto PMD list */
390 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
391 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
395 * Crypto device supported feature flags
398 * New features flags should be added to the end of the list
400 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
402 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
403 /**< Symmetric crypto operations are supported */
404 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
405 /**< Asymmetric crypto operations are supported */
406 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
407 /**< Chaining symmetric crypto operations are supported */
408 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
409 /**< Utilises CPU SIMD SSE instructions */
410 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
411 /**< Utilises CPU SIMD AVX instructions */
412 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
413 /**< Utilises CPU SIMD AVX2 instructions */
414 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
415 /**< Utilises CPU AES-NI instructions */
416 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
417 /**< Operations are off-loaded to an
418 * external hardware accelerator
420 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
421 /**< Utilises CPU SIMD AVX512 instructions */
422 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL (1ULL << 9)
423 /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
426 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT (1ULL << 10)
427 /**< Out-of-place Scatter-gather (SGL) buffers are
428 * supported in input and output
430 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT (1ULL << 11)
431 /**< Out-of-place Scatter-gather (SGL) buffers are supported
432 * in input, combined with linear buffers (LB), with a
433 * single segment in output
435 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT (1ULL << 12)
436 /**< Out-of-place Scatter-gather (SGL) buffers are supported
437 * in output, combined with linear buffers (LB) in input
439 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT (1ULL << 13)
440 /**< Out-of-place linear buffers (LB) are supported in input and output */
441 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 14)
442 /**< Utilises CPU NEON instructions */
443 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 15)
444 /**< Utilises ARM CPU Cryptographic Extensions */
445 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 16)
446 /**< Support Security Protocol Processing */
447 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP (1ULL << 17)
448 /**< Support RSA Private Key OP with exponent */
449 #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT (1ULL << 18)
450 /**< Support RSA Private Key OP with CRT (quintuple) Keys */
451 #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED (1ULL << 19)
452 /**< Support encrypted-digest operations where digest is appended to data */
453 #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS (1ULL << 20)
454 /**< Support asymmetric session-less operations */
455 #define RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO (1ULL << 21)
456 /**< Support symmetric cpu-crypto processing */
457 #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS (1ULL << 22)
458 /**< Support symmetric session-less operations */
462 * Get the name of a crypto device feature flag
464 * @param flag The mask describing the flag.
467 * The name of this flag, or NULL if it's not a valid feature flag.
471 rte_cryptodev_get_feature_name(uint64_t flag);
473 /** Crypto device information */
474 struct rte_cryptodev_info {
475 const char *driver_name; /**< Driver name. */
476 uint8_t driver_id; /**< Driver identifier */
477 struct rte_device *device; /**< Generic device information. */
479 uint64_t feature_flags;
480 /**< Feature flags exposes HW/SW features for the given device */
482 const struct rte_cryptodev_capabilities *capabilities;
483 /**< Array of devices supported capabilities */
485 unsigned max_nb_queue_pairs;
486 /**< Maximum number of queues pairs supported by device. */
488 uint16_t min_mbuf_headroom_req;
489 /**< Minimum mbuf headroom required by device */
491 uint16_t min_mbuf_tailroom_req;
492 /**< Minimum mbuf tailroom required by device */
495 unsigned max_nb_sessions;
496 /**< Maximum number of sessions supported by device.
497 * If 0, the device does not have any limitation in
498 * number of sessions that can be used.
503 #define RTE_CRYPTODEV_DETACHED (0)
504 #define RTE_CRYPTODEV_ATTACHED (1)
506 /** Definitions of Crypto device event types */
507 enum rte_cryptodev_event_type {
508 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
509 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
510 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
513 /** Crypto device queue pair configuration structure. */
514 struct rte_cryptodev_qp_conf {
515 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
516 struct rte_mempool *mp_session;
517 /**< The mempool for creating session in sessionless mode */
518 struct rte_mempool *mp_session_private;
519 /**< The mempool for creating sess private data in sessionless mode */
523 * Typedef for application callback function to be registered by application
524 * software for notification of device events
526 * @param dev_id Crypto device identifier
527 * @param event Crypto device event to register for notification of.
528 * @param cb_arg User specified parameter to be passed as to passed to
529 * users callback function.
531 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
532 enum rte_cryptodev_event_type event, void *cb_arg);
535 /** Crypto Device statistics */
536 struct rte_cryptodev_stats {
537 uint64_t enqueued_count;
538 /**< Count of all operations enqueued */
539 uint64_t dequeued_count;
540 /**< Count of all operations dequeued */
542 uint64_t enqueue_err_count;
543 /**< Total error count on operations enqueued */
544 uint64_t dequeue_err_count;
545 /**< Total error count on operations dequeued */
548 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
549 /**< Max length of name of crypto PMD */
552 * Get the device identifier for the named crypto device.
554 * @param name device name to select the device structure.
557 * - Returns crypto device identifier on success.
558 * - Return -1 on failure to find named crypto device.
561 rte_cryptodev_get_dev_id(const char *name);
564 * Get the crypto device name given a device identifier.
567 * The identifier of the device
570 * - Returns crypto device name.
571 * - Returns NULL if crypto device is not present.
574 rte_cryptodev_name_get(uint8_t dev_id);
577 * Get the total number of crypto devices that have been successfully
581 * - The total number of usable crypto devices.
584 rte_cryptodev_count(void);
587 * Get number of crypto device defined type.
589 * @param driver_id driver identifier.
592 * Returns number of crypto device.
595 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
598 * Get number and identifiers of attached crypto devices that
599 * use the same crypto driver.
601 * @param driver_name driver name.
602 * @param devices output devices identifiers.
603 * @param nb_devices maximal number of devices.
606 * Returns number of attached crypto device.
609 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
612 * Return the NUMA socket to which a device is connected
615 * The identifier of the device
617 * The NUMA socket id to which the device is connected or
618 * a default of zero if the socket could not be determined.
619 * -1 if returned is the dev_id value is out of range.
622 rte_cryptodev_socket_id(uint8_t dev_id);
624 /** Crypto device configuration structure */
625 struct rte_cryptodev_config {
626 int socket_id; /**< Socket to allocate resources on */
627 uint16_t nb_queue_pairs;
628 /**< Number of queue pairs to configure on device */
630 /**< Feature flags to be disabled. Only the following features are
631 * allowed to be disabled,
632 * - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
633 * - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
634 * - RTE_CRYTPODEV_FF_SECURITY
639 * Configure a device.
641 * This function must be invoked first before any other function in the
642 * API. This function can also be re-invoked when a device is in the
645 * @param dev_id The identifier of the device to configure.
646 * @param config The crypto device configuration structure.
649 * - 0: Success, device configured.
650 * - <0: Error code returned by the driver configuration function.
653 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
658 * The device start step is the last one and consists of setting the configured
659 * offload features and in starting the transmit and the receive units of the
661 * On success, all basic functions exported by the API (link status,
662 * receive/transmit, and so on) can be invoked.
665 * The identifier of the device.
667 * - 0: Success, device started.
668 * - <0: Error code of the driver device start function.
671 rte_cryptodev_start(uint8_t dev_id);
674 * Stop an device. The device can be restarted with a call to
675 * rte_cryptodev_start()
677 * @param dev_id The identifier of the device.
680 rte_cryptodev_stop(uint8_t dev_id);
683 * Close an device. The device cannot be restarted!
685 * @param dev_id The identifier of the device.
688 * - 0 on successfully closing device
689 * - <0 on failure to close device
692 rte_cryptodev_close(uint8_t dev_id);
695 * Allocate and set up a receive queue pair for a device.
698 * @param dev_id The identifier of the device.
699 * @param queue_pair_id The index of the queue pairs to set up. The
700 * value must be in the range [0, nb_queue_pair
701 * - 1] previously supplied to
702 * rte_cryptodev_configure().
703 * @param qp_conf The pointer to the configuration data to be
704 * used for the queue pair.
705 * @param socket_id The *socket_id* argument is the socket
706 * identifier in case of NUMA. The value can be
707 * *SOCKET_ID_ANY* if there is no NUMA constraint
708 * for the DMA memory allocated for the receive
712 * - 0: Success, queue pair correctly set up.
713 * - <0: Queue pair configuration failed
716 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
717 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
720 * Get the number of queue pairs on a specific crypto device
722 * @param dev_id Crypto device identifier.
724 * - The number of configured queue pairs.
727 rte_cryptodev_queue_pair_count(uint8_t dev_id);
731 * Retrieve the general I/O statistics of a device.
733 * @param dev_id The identifier of the device.
734 * @param stats A pointer to a structure of type
735 * *rte_cryptodev_stats* to be filled with the
736 * values of device counters.
738 * - Zero if successful.
739 * - Non-zero otherwise.
742 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
745 * Reset the general I/O statistics of a device.
747 * @param dev_id The identifier of the device.
750 rte_cryptodev_stats_reset(uint8_t dev_id);
753 * Retrieve the contextual information of a device.
755 * @param dev_id The identifier of the device.
756 * @param dev_info A pointer to a structure of type
757 * *rte_cryptodev_info* to be filled with the
758 * contextual information of the device.
760 * @note The capabilities field of dev_info is set to point to the first
761 * element of an array of struct rte_cryptodev_capabilities. The element after
762 * the last valid element has it's op field set to
763 * RTE_CRYPTO_OP_TYPE_UNDEFINED.
766 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
770 * Register a callback function for specific device id.
772 * @param dev_id Device id.
773 * @param event Event interested.
774 * @param cb_fn User supplied callback function to be called.
775 * @param cb_arg Pointer to the parameters for the registered
779 * - On success, zero.
780 * - On failure, a negative value.
783 rte_cryptodev_callback_register(uint8_t dev_id,
784 enum rte_cryptodev_event_type event,
785 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
788 * Unregister a callback function for specific device id.
790 * @param dev_id The device identifier.
791 * @param event Event interested.
792 * @param cb_fn User supplied callback function to be called.
793 * @param cb_arg Pointer to the parameters for the registered
797 * - On success, zero.
798 * - On failure, a negative value.
801 rte_cryptodev_callback_unregister(uint8_t dev_id,
802 enum rte_cryptodev_event_type event,
803 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
806 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
807 struct rte_crypto_op **ops, uint16_t nb_ops);
808 /**< Dequeue processed packets from queue pair of a device. */
810 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
811 struct rte_crypto_op **ops, uint16_t nb_ops);
812 /**< Enqueue packets for processing on queue pair of a device. */
817 struct rte_cryptodev_callback;
819 /** Structure to keep track of registered callbacks */
820 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
822 /** The data structure associated with each crypto device. */
823 struct rte_cryptodev {
824 dequeue_pkt_burst_t dequeue_burst;
825 /**< Pointer to PMD receive function. */
826 enqueue_pkt_burst_t enqueue_burst;
827 /**< Pointer to PMD transmit function. */
829 struct rte_cryptodev_data *data;
830 /**< Pointer to device data */
831 struct rte_cryptodev_ops *dev_ops;
832 /**< Functions exported by PMD */
833 uint64_t feature_flags;
834 /**< Feature flags exposes HW/SW features for the given device */
835 struct rte_device *device;
836 /**< Backing device */
839 /**< Crypto driver identifier*/
841 struct rte_cryptodev_cb_list link_intr_cbs;
842 /**< User application callback for interrupts if present */
845 /**< Context for security ops */
848 uint8_t attached : 1;
849 /**< Flag indicating the device is attached */
850 } __rte_cache_aligned;
853 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
857 * The data part, with no function pointers, associated with each device.
859 * This structure is safe to place in shared memory to be common among
860 * different processes in a multi-process configuration.
862 struct rte_cryptodev_data {
864 /**< Device ID for this instance */
866 /**< Socket ID where memory is allocated */
867 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
868 /**< Unique identifier name */
871 uint8_t dev_started : 1;
872 /**< Device state: STARTED(1)/STOPPED(0) */
874 struct rte_mempool *session_pool;
875 /**< Session memory pool */
877 /**< Array of pointers to queue pairs. */
878 uint16_t nb_queue_pairs;
879 /**< Number of device queue pairs. */
882 /**< PMD-specific private data */
883 } __rte_cache_aligned;
885 extern struct rte_cryptodev *rte_cryptodevs;
888 * Dequeue a burst of processed crypto operations from a queue on the crypto
889 * device. The dequeued operation are stored in *rte_crypto_op* structures
890 * whose pointers are supplied in the *ops* array.
892 * The rte_cryptodev_dequeue_burst() function returns the number of ops
893 * actually dequeued, which is the number of *rte_crypto_op* data structures
894 * effectively supplied into the *ops* array.
896 * A return value equal to *nb_ops* indicates that the queue contained
897 * at least *nb_ops* operations, and this is likely to signify that other
898 * processed operations remain in the devices output queue. Applications
899 * implementing a "retrieve as many processed operations as possible" policy
900 * can check this specific case and keep invoking the
901 * rte_cryptodev_dequeue_burst() function until a value less than
902 * *nb_ops* is returned.
904 * The rte_cryptodev_dequeue_burst() function does not provide any error
905 * notification to avoid the corresponding overhead.
907 * @param dev_id The symmetric crypto device identifier
908 * @param qp_id The index of the queue pair from which to
909 * retrieve processed packets. The value must be
910 * in the range [0, nb_queue_pair - 1] previously
911 * supplied to rte_cryptodev_configure().
912 * @param ops The address of an array of pointers to
913 * *rte_crypto_op* structures that must be
914 * large enough to store *nb_ops* pointers in it.
915 * @param nb_ops The maximum number of operations to dequeue.
918 * - The number of operations actually dequeued, which is the number
919 * of pointers to *rte_crypto_op* structures effectively supplied to the
922 static inline uint16_t
923 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
924 struct rte_crypto_op **ops, uint16_t nb_ops)
926 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
928 nb_ops = (*dev->dequeue_burst)
929 (dev->data->queue_pairs[qp_id], ops, nb_ops);
931 rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
936 * Enqueue a burst of operations for processing on a crypto device.
938 * The rte_cryptodev_enqueue_burst() function is invoked to place
939 * crypto operations on the queue *qp_id* of the device designated by
942 * The *nb_ops* parameter is the number of operations to process which are
943 * supplied in the *ops* array of *rte_crypto_op* structures.
945 * The rte_cryptodev_enqueue_burst() function returns the number of
946 * operations it actually enqueued for processing. A return value equal to
947 * *nb_ops* means that all packets have been enqueued.
949 * @param dev_id The identifier of the device.
950 * @param qp_id The index of the queue pair which packets are
951 * to be enqueued for processing. The value
952 * must be in the range [0, nb_queue_pairs - 1]
953 * previously supplied to
954 * *rte_cryptodev_configure*.
955 * @param ops The address of an array of *nb_ops* pointers
956 * to *rte_crypto_op* structures which contain
957 * the crypto operations to be processed.
958 * @param nb_ops The number of operations to process.
961 * The number of operations actually enqueued on the crypto device. The return
962 * value can be less than the value of the *nb_ops* parameter when the
963 * crypto devices queue is full or if invalid parameters are specified in
966 static inline uint16_t
967 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
968 struct rte_crypto_op **ops, uint16_t nb_ops)
970 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
972 rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
973 return (*dev->enqueue_burst)(
974 dev->data->queue_pairs[qp_id], ops, nb_ops);
978 /** Cryptodev symmetric crypto session
979 * Each session is derived from a fixed xform chain. Therefore each session
980 * has a fixed algo, key, op-type, digest_len etc.
982 struct rte_cryptodev_sym_session {
983 uint64_t opaque_data;
984 /**< Can be used for external metadata */
986 /**< number of elements in sess_data array */
987 uint16_t user_data_sz;
988 /**< session user data will be placed after sess_data */
989 __extension__ struct {
993 /**< Driver specific session material, variable size */
996 /** Cryptodev asymmetric crypto session */
997 struct rte_cryptodev_asym_session {
998 __extension__ void *sess_private_data[0];
999 /**< Private asymmetric session material */
1003 * Create a symmetric session mempool.
1006 * The unique mempool name.
1008 * The number of elements in the mempool.
1010 * The size of the element. This value will be ignored if it is smaller than
1011 * the minimum session header size required for the system. For the user who
1012 * want to use the same mempool for sym session and session private data it
1013 * can be the maximum value of all existing devices' private data and session
1016 * The number of per-lcore cache elements
1018 * The private data size of each session.
1020 * The *socket_id* argument is the socket identifier in the case of
1021 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
1022 * constraint for the reserved zone.
1025 * - On success return size of the session
1026 * - On failure returns 0
1029 struct rte_mempool *
1030 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1031 uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1035 * Create symmetric crypto session header (generic with no private data)
1037 * @param mempool Symmetric session mempool to allocate session
1040 * - On success return pointer to sym-session
1041 * - On failure returns NULL
1043 struct rte_cryptodev_sym_session *
1044 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
1047 * Create asymmetric crypto session header (generic with no private data)
1049 * @param mempool mempool to allocate asymmetric session
1052 * - On success return pointer to asym-session
1053 * - On failure returns NULL
1056 struct rte_cryptodev_asym_session *
1057 rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
1060 * Frees symmetric crypto session header, after checking that all
1061 * the device private data has been freed, returning it
1062 * to its original mempool.
1064 * @param sess Session header to be freed.
1067 * - 0 if successful.
1068 * - -EINVAL if session is NULL.
1069 * - -EBUSY if not all device private data has been freed.
1072 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
1075 * Frees asymmetric crypto session header, after checking that all
1076 * the device private data has been freed, returning it
1077 * to its original mempool.
1079 * @param sess Session header to be freed.
1082 * - 0 if successful.
1083 * - -EINVAL if session is NULL.
1084 * - -EBUSY if not all device private data has been freed.
1088 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
1091 * Fill out private data for the device id, based on its device type.
1093 * @param dev_id ID of device that we want the session to be used on
1094 * @param sess Session where the private data will be attached to
1095 * @param xforms Symmetric crypto transform operations to apply on flow
1096 * processed with this session
1097 * @param mempool Mempool where the private data is allocated.
1100 * - On success, zero.
1101 * - -EINVAL if input parameters are invalid.
1102 * - -ENOTSUP if crypto device does not support the crypto transform or
1103 * does not support symmetric operations.
1104 * - -ENOMEM if the private session could not be allocated.
1107 rte_cryptodev_sym_session_init(uint8_t dev_id,
1108 struct rte_cryptodev_sym_session *sess,
1109 struct rte_crypto_sym_xform *xforms,
1110 struct rte_mempool *mempool);
1113 * Initialize asymmetric session on a device with specific asymmetric xform
1115 * @param dev_id ID of device that we want the session to be used on
1116 * @param sess Session to be set up on a device
1117 * @param xforms Asymmetric crypto transform operations to apply on flow
1118 * processed with this session
1119 * @param mempool Mempool to be used for internal allocation.
1122 * - On success, zero.
1123 * - -EINVAL if input parameters are invalid.
1124 * - -ENOTSUP if crypto device does not support the crypto transform.
1125 * - -ENOMEM if the private session could not be allocated.
1129 rte_cryptodev_asym_session_init(uint8_t dev_id,
1130 struct rte_cryptodev_asym_session *sess,
1131 struct rte_crypto_asym_xform *xforms,
1132 struct rte_mempool *mempool);
1135 * Frees private data for the device id, based on its device type,
1136 * returning it to its mempool. It is the application's responsibility
1137 * to ensure that private session data is not cleared while there are
1138 * still in-flight operations using it.
1140 * @param dev_id ID of device that uses the session.
1141 * @param sess Session containing the reference to the private data
1144 * - 0 if successful.
1145 * - -EINVAL if device is invalid or session is NULL.
1146 * - -ENOTSUP if crypto device does not support symmetric operations.
1149 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1150 struct rte_cryptodev_sym_session *sess);
1153 * Frees resources held by asymmetric session during rte_cryptodev_session_init
1155 * @param dev_id ID of device that uses the asymmetric session.
1156 * @param sess Asymmetric session setup on device using
1157 * rte_cryptodev_session_init
1159 * - 0 if successful.
1160 * - -EINVAL if device is invalid or session is NULL.
1164 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1165 struct rte_cryptodev_asym_session *sess);
1168 * Get the size of the header session, for all registered drivers excluding
1169 * the user data size.
1172 * Size of the symmetric header session.
1175 rte_cryptodev_sym_get_header_session_size(void);
1178 * Get the size of the header session from created session.
1181 * The sym cryptodev session pointer
1184 * - If sess is not NULL, return the size of the header session including
1185 * the private data size defined within sess.
1186 * - If sess is NULL, return 0.
1190 rte_cryptodev_sym_get_existing_header_session_size(
1191 struct rte_cryptodev_sym_session *sess);
1194 * Get the size of the asymmetric session header, for all registered drivers.
1197 * Size of the asymmetric header session.
1201 rte_cryptodev_asym_get_header_session_size(void);
1204 * Get the size of the private symmetric session data
1207 * @param dev_id The device identifier.
1210 * - Size of the private data, if successful
1211 * - 0 if device is invalid or does not have private
1215 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
1218 * Get the size of the private data for asymmetric session
1221 * @param dev_id The device identifier.
1224 * - Size of the asymmetric private data, if successful
1225 * - 0 if device is invalid or does not have private session
1229 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
1232 * Provide driver identifier.
1235 * The pointer to a driver name.
1237 * The driver type identifier or -1 if no driver found
1239 int rte_cryptodev_driver_id_get(const char *name);
1242 * Provide driver name.
1245 * The driver identifier.
1247 * The driver name or null if no driver found
1249 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1252 * Store user data in a session.
1254 * @param sess Session pointer allocated by
1255 * *rte_cryptodev_sym_session_create*.
1256 * @param data Pointer to the user data.
1257 * @param size Size of the user data.
1260 * - On success, zero.
1261 * - On failure, a negative value.
1265 rte_cryptodev_sym_session_set_user_data(
1266 struct rte_cryptodev_sym_session *sess,
1271 * Get user data stored in a session.
1273 * @param sess Session pointer allocated by
1274 * *rte_cryptodev_sym_session_create*.
1277 * - On success return pointer to user data.
1278 * - On failure returns NULL.
1282 rte_cryptodev_sym_session_get_user_data(
1283 struct rte_cryptodev_sym_session *sess);
1286 * Perform actual crypto processing (encrypt/digest or auth/decrypt)
1287 * on user provided data.
1289 * @param dev_id The device identifier.
1290 * @param sess Cryptodev session structure
1291 * @param ofs Start and stop offsets for auth and cipher operations
1292 * @param vec Vectorized operation descriptor
1295 * - Returns number of successfully processed packets.
1299 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
1300 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
1301 struct rte_crypto_sym_vec *vec);
1307 #endif /* _RTE_CRYPTODEV_H_ */