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 */
459 #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA (1ULL << 23)
460 /**< Support operations on data which is not byte aligned */
464 * Get the name of a crypto device feature flag
466 * @param flag The mask describing the flag.
469 * The name of this flag, or NULL if it's not a valid feature flag.
473 rte_cryptodev_get_feature_name(uint64_t flag);
475 /** Crypto device information */
476 struct rte_cryptodev_info {
477 const char *driver_name; /**< Driver name. */
478 uint8_t driver_id; /**< Driver identifier */
479 struct rte_device *device; /**< Generic device information. */
481 uint64_t feature_flags;
482 /**< Feature flags exposes HW/SW features for the given device */
484 const struct rte_cryptodev_capabilities *capabilities;
485 /**< Array of devices supported capabilities */
487 unsigned max_nb_queue_pairs;
488 /**< Maximum number of queues pairs supported by device. */
490 uint16_t min_mbuf_headroom_req;
491 /**< Minimum mbuf headroom required by device */
493 uint16_t min_mbuf_tailroom_req;
494 /**< Minimum mbuf tailroom required by device */
497 unsigned max_nb_sessions;
498 /**< Maximum number of sessions supported by device.
499 * If 0, the device does not have any limitation in
500 * number of sessions that can be used.
505 #define RTE_CRYPTODEV_DETACHED (0)
506 #define RTE_CRYPTODEV_ATTACHED (1)
508 /** Definitions of Crypto device event types */
509 enum rte_cryptodev_event_type {
510 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
511 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
512 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
515 /** Crypto device queue pair configuration structure. */
516 struct rte_cryptodev_qp_conf {
517 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
518 struct rte_mempool *mp_session;
519 /**< The mempool for creating session in sessionless mode */
520 struct rte_mempool *mp_session_private;
521 /**< The mempool for creating sess private data in sessionless mode */
525 * Typedef for application callback function to be registered by application
526 * software for notification of device events
528 * @param dev_id Crypto device identifier
529 * @param event Crypto device event to register for notification of.
530 * @param cb_arg User specified parameter to be passed as to passed to
531 * users callback function.
533 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
534 enum rte_cryptodev_event_type event, void *cb_arg);
537 /** Crypto Device statistics */
538 struct rte_cryptodev_stats {
539 uint64_t enqueued_count;
540 /**< Count of all operations enqueued */
541 uint64_t dequeued_count;
542 /**< Count of all operations dequeued */
544 uint64_t enqueue_err_count;
545 /**< Total error count on operations enqueued */
546 uint64_t dequeue_err_count;
547 /**< Total error count on operations dequeued */
550 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
551 /**< Max length of name of crypto PMD */
554 * Get the device identifier for the named crypto device.
556 * @param name device name to select the device structure.
559 * - Returns crypto device identifier on success.
560 * - Return -1 on failure to find named crypto device.
563 rte_cryptodev_get_dev_id(const char *name);
566 * Get the crypto device name given a device identifier.
569 * The identifier of the device
572 * - Returns crypto device name.
573 * - Returns NULL if crypto device is not present.
576 rte_cryptodev_name_get(uint8_t dev_id);
579 * Get the total number of crypto devices that have been successfully
583 * - The total number of usable crypto devices.
586 rte_cryptodev_count(void);
589 * Get number of crypto device defined type.
591 * @param driver_id driver identifier.
594 * Returns number of crypto device.
597 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
600 * Get number and identifiers of attached crypto devices that
601 * use the same crypto driver.
603 * @param driver_name driver name.
604 * @param devices output devices identifiers.
605 * @param nb_devices maximal number of devices.
608 * Returns number of attached crypto device.
611 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
614 * Return the NUMA socket to which a device is connected
617 * The identifier of the device
619 * The NUMA socket id to which the device is connected or
620 * a default of zero if the socket could not be determined.
621 * -1 if returned is the dev_id value is out of range.
624 rte_cryptodev_socket_id(uint8_t dev_id);
626 /** Crypto device configuration structure */
627 struct rte_cryptodev_config {
628 int socket_id; /**< Socket to allocate resources on */
629 uint16_t nb_queue_pairs;
630 /**< Number of queue pairs to configure on device */
632 /**< Feature flags to be disabled. Only the following features are
633 * allowed to be disabled,
634 * - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
635 * - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
636 * - RTE_CRYTPODEV_FF_SECURITY
641 * Configure a device.
643 * This function must be invoked first before any other function in the
644 * API. This function can also be re-invoked when a device is in the
647 * @param dev_id The identifier of the device to configure.
648 * @param config The crypto device configuration structure.
651 * - 0: Success, device configured.
652 * - <0: Error code returned by the driver configuration function.
655 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
660 * The device start step is the last one and consists of setting the configured
661 * offload features and in starting the transmit and the receive units of the
663 * On success, all basic functions exported by the API (link status,
664 * receive/transmit, and so on) can be invoked.
667 * The identifier of the device.
669 * - 0: Success, device started.
670 * - <0: Error code of the driver device start function.
673 rte_cryptodev_start(uint8_t dev_id);
676 * Stop an device. The device can be restarted with a call to
677 * rte_cryptodev_start()
679 * @param dev_id The identifier of the device.
682 rte_cryptodev_stop(uint8_t dev_id);
685 * Close an device. The device cannot be restarted!
687 * @param dev_id The identifier of the device.
690 * - 0 on successfully closing device
691 * - <0 on failure to close device
694 rte_cryptodev_close(uint8_t dev_id);
697 * Allocate and set up a receive queue pair for a device.
700 * @param dev_id The identifier of the device.
701 * @param queue_pair_id The index of the queue pairs to set up. The
702 * value must be in the range [0, nb_queue_pair
703 * - 1] previously supplied to
704 * rte_cryptodev_configure().
705 * @param qp_conf The pointer to the configuration data to be
706 * used for the queue pair.
707 * @param socket_id The *socket_id* argument is the socket
708 * identifier in case of NUMA. The value can be
709 * *SOCKET_ID_ANY* if there is no NUMA constraint
710 * for the DMA memory allocated for the receive
714 * - 0: Success, queue pair correctly set up.
715 * - <0: Queue pair configuration failed
718 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
719 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
722 * Get the number of queue pairs on a specific crypto device
724 * @param dev_id Crypto device identifier.
726 * - The number of configured queue pairs.
729 rte_cryptodev_queue_pair_count(uint8_t dev_id);
733 * Retrieve the general I/O statistics of a device.
735 * @param dev_id The identifier of the device.
736 * @param stats A pointer to a structure of type
737 * *rte_cryptodev_stats* to be filled with the
738 * values of device counters.
740 * - Zero if successful.
741 * - Non-zero otherwise.
744 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
747 * Reset the general I/O statistics of a device.
749 * @param dev_id The identifier of the device.
752 rte_cryptodev_stats_reset(uint8_t dev_id);
755 * Retrieve the contextual information of a device.
757 * @param dev_id The identifier of the device.
758 * @param dev_info A pointer to a structure of type
759 * *rte_cryptodev_info* to be filled with the
760 * contextual information of the device.
762 * @note The capabilities field of dev_info is set to point to the first
763 * element of an array of struct rte_cryptodev_capabilities. The element after
764 * the last valid element has it's op field set to
765 * RTE_CRYPTO_OP_TYPE_UNDEFINED.
768 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
772 * Register a callback function for specific device id.
774 * @param dev_id Device id.
775 * @param event Event interested.
776 * @param cb_fn User supplied callback function to be called.
777 * @param cb_arg Pointer to the parameters for the registered
781 * - On success, zero.
782 * - On failure, a negative value.
785 rte_cryptodev_callback_register(uint8_t dev_id,
786 enum rte_cryptodev_event_type event,
787 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
790 * Unregister a callback function for specific device id.
792 * @param dev_id The device identifier.
793 * @param event Event interested.
794 * @param cb_fn User supplied callback function to be called.
795 * @param cb_arg Pointer to the parameters for the registered
799 * - On success, zero.
800 * - On failure, a negative value.
803 rte_cryptodev_callback_unregister(uint8_t dev_id,
804 enum rte_cryptodev_event_type event,
805 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
808 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
809 struct rte_crypto_op **ops, uint16_t nb_ops);
810 /**< Dequeue processed packets from queue pair of a device. */
812 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
813 struct rte_crypto_op **ops, uint16_t nb_ops);
814 /**< Enqueue packets for processing on queue pair of a device. */
819 struct rte_cryptodev_callback;
821 /** Structure to keep track of registered callbacks */
822 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
824 /** The data structure associated with each crypto device. */
825 struct rte_cryptodev {
826 dequeue_pkt_burst_t dequeue_burst;
827 /**< Pointer to PMD receive function. */
828 enqueue_pkt_burst_t enqueue_burst;
829 /**< Pointer to PMD transmit function. */
831 struct rte_cryptodev_data *data;
832 /**< Pointer to device data */
833 struct rte_cryptodev_ops *dev_ops;
834 /**< Functions exported by PMD */
835 uint64_t feature_flags;
836 /**< Feature flags exposes HW/SW features for the given device */
837 struct rte_device *device;
838 /**< Backing device */
841 /**< Crypto driver identifier*/
843 struct rte_cryptodev_cb_list link_intr_cbs;
844 /**< User application callback for interrupts if present */
847 /**< Context for security ops */
850 uint8_t attached : 1;
851 /**< Flag indicating the device is attached */
852 } __rte_cache_aligned;
855 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
859 * The data part, with no function pointers, associated with each device.
861 * This structure is safe to place in shared memory to be common among
862 * different processes in a multi-process configuration.
864 struct rte_cryptodev_data {
866 /**< Device ID for this instance */
868 /**< Socket ID where memory is allocated */
869 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
870 /**< Unique identifier name */
873 uint8_t dev_started : 1;
874 /**< Device state: STARTED(1)/STOPPED(0) */
876 struct rte_mempool *session_pool;
877 /**< Session memory pool */
879 /**< Array of pointers to queue pairs. */
880 uint16_t nb_queue_pairs;
881 /**< Number of device queue pairs. */
884 /**< PMD-specific private data */
885 } __rte_cache_aligned;
887 extern struct rte_cryptodev *rte_cryptodevs;
890 * Dequeue a burst of processed crypto operations from a queue on the crypto
891 * device. The dequeued operation are stored in *rte_crypto_op* structures
892 * whose pointers are supplied in the *ops* array.
894 * The rte_cryptodev_dequeue_burst() function returns the number of ops
895 * actually dequeued, which is the number of *rte_crypto_op* data structures
896 * effectively supplied into the *ops* array.
898 * A return value equal to *nb_ops* indicates that the queue contained
899 * at least *nb_ops* operations, and this is likely to signify that other
900 * processed operations remain in the devices output queue. Applications
901 * implementing a "retrieve as many processed operations as possible" policy
902 * can check this specific case and keep invoking the
903 * rte_cryptodev_dequeue_burst() function until a value less than
904 * *nb_ops* is returned.
906 * The rte_cryptodev_dequeue_burst() function does not provide any error
907 * notification to avoid the corresponding overhead.
909 * @param dev_id The symmetric crypto device identifier
910 * @param qp_id The index of the queue pair from which to
911 * retrieve processed packets. The value must be
912 * in the range [0, nb_queue_pair - 1] previously
913 * supplied to rte_cryptodev_configure().
914 * @param ops The address of an array of pointers to
915 * *rte_crypto_op* structures that must be
916 * large enough to store *nb_ops* pointers in it.
917 * @param nb_ops The maximum number of operations to dequeue.
920 * - The number of operations actually dequeued, which is the number
921 * of pointers to *rte_crypto_op* structures effectively supplied to the
924 static inline uint16_t
925 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
926 struct rte_crypto_op **ops, uint16_t nb_ops)
928 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
930 nb_ops = (*dev->dequeue_burst)
931 (dev->data->queue_pairs[qp_id], ops, nb_ops);
933 rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
938 * Enqueue a burst of operations for processing on a crypto device.
940 * The rte_cryptodev_enqueue_burst() function is invoked to place
941 * crypto operations on the queue *qp_id* of the device designated by
944 * The *nb_ops* parameter is the number of operations to process which are
945 * supplied in the *ops* array of *rte_crypto_op* structures.
947 * The rte_cryptodev_enqueue_burst() function returns the number of
948 * operations it actually enqueued for processing. A return value equal to
949 * *nb_ops* means that all packets have been enqueued.
951 * @param dev_id The identifier of the device.
952 * @param qp_id The index of the queue pair which packets are
953 * to be enqueued for processing. The value
954 * must be in the range [0, nb_queue_pairs - 1]
955 * previously supplied to
956 * *rte_cryptodev_configure*.
957 * @param ops The address of an array of *nb_ops* pointers
958 * to *rte_crypto_op* structures which contain
959 * the crypto operations to be processed.
960 * @param nb_ops The number of operations to process.
963 * The number of operations actually enqueued on the crypto device. The return
964 * value can be less than the value of the *nb_ops* parameter when the
965 * crypto devices queue is full or if invalid parameters are specified in
968 static inline uint16_t
969 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
970 struct rte_crypto_op **ops, uint16_t nb_ops)
972 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
974 rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
975 return (*dev->enqueue_burst)(
976 dev->data->queue_pairs[qp_id], ops, nb_ops);
980 /** Cryptodev symmetric crypto session
981 * Each session is derived from a fixed xform chain. Therefore each session
982 * has a fixed algo, key, op-type, digest_len etc.
984 struct rte_cryptodev_sym_session {
985 uint64_t opaque_data;
986 /**< Can be used for external metadata */
988 /**< number of elements in sess_data array */
989 uint16_t user_data_sz;
990 /**< session user data will be placed after sess_data */
991 __extension__ struct {
995 /**< Driver specific session material, variable size */
998 /** Cryptodev asymmetric crypto session */
999 struct rte_cryptodev_asym_session {
1000 __extension__ void *sess_private_data[0];
1001 /**< Private asymmetric session material */
1005 * Create a symmetric session mempool.
1008 * The unique mempool name.
1010 * The number of elements in the mempool.
1012 * The size of the element. This value will be ignored if it is smaller than
1013 * the minimum session header size required for the system. For the user who
1014 * want to use the same mempool for sym session and session private data it
1015 * can be the maximum value of all existing devices' private data and session
1018 * The number of per-lcore cache elements
1020 * The private data size of each session.
1022 * The *socket_id* argument is the socket identifier in the case of
1023 * NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
1024 * constraint for the reserved zone.
1027 * - On success return size of the session
1028 * - On failure returns 0
1031 struct rte_mempool *
1032 rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
1033 uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
1037 * Create symmetric crypto session header (generic with no private data)
1039 * @param mempool Symmetric session mempool to allocate session
1042 * - On success return pointer to sym-session
1043 * - On failure returns NULL
1045 struct rte_cryptodev_sym_session *
1046 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
1049 * Create asymmetric crypto session header (generic with no private data)
1051 * @param mempool mempool to allocate asymmetric session
1054 * - On success return pointer to asym-session
1055 * - On failure returns NULL
1058 struct rte_cryptodev_asym_session *
1059 rte_cryptodev_asym_session_create(struct rte_mempool *mempool);
1062 * Frees symmetric crypto session header, after checking that all
1063 * the device private data has been freed, returning it
1064 * to its original mempool.
1066 * @param sess Session header to be freed.
1069 * - 0 if successful.
1070 * - -EINVAL if session is NULL.
1071 * - -EBUSY if not all device private data has been freed.
1074 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
1077 * Frees asymmetric crypto session header, after checking that all
1078 * the device private data has been freed, returning it
1079 * to its original mempool.
1081 * @param sess Session header to be freed.
1084 * - 0 if successful.
1085 * - -EINVAL if session is NULL.
1086 * - -EBUSY if not all device private data has been freed.
1090 rte_cryptodev_asym_session_free(struct rte_cryptodev_asym_session *sess);
1093 * Fill out private data for the device id, based on its device type.
1095 * @param dev_id ID of device that we want the session to be used on
1096 * @param sess Session where the private data will be attached to
1097 * @param xforms Symmetric crypto transform operations to apply on flow
1098 * processed with this session
1099 * @param mempool Mempool where the private data is allocated.
1102 * - On success, zero.
1103 * - -EINVAL if input parameters are invalid.
1104 * - -ENOTSUP if crypto device does not support the crypto transform or
1105 * does not support symmetric operations.
1106 * - -ENOMEM if the private session could not be allocated.
1109 rte_cryptodev_sym_session_init(uint8_t dev_id,
1110 struct rte_cryptodev_sym_session *sess,
1111 struct rte_crypto_sym_xform *xforms,
1112 struct rte_mempool *mempool);
1115 * Initialize asymmetric session on a device with specific asymmetric xform
1117 * @param dev_id ID of device that we want the session to be used on
1118 * @param sess Session to be set up on a device
1119 * @param xforms Asymmetric crypto transform operations to apply on flow
1120 * processed with this session
1121 * @param mempool Mempool to be used for internal allocation.
1124 * - On success, zero.
1125 * - -EINVAL if input parameters are invalid.
1126 * - -ENOTSUP if crypto device does not support the crypto transform.
1127 * - -ENOMEM if the private session could not be allocated.
1131 rte_cryptodev_asym_session_init(uint8_t dev_id,
1132 struct rte_cryptodev_asym_session *sess,
1133 struct rte_crypto_asym_xform *xforms,
1134 struct rte_mempool *mempool);
1137 * Frees private data for the device id, based on its device type,
1138 * returning it to its mempool. It is the application's responsibility
1139 * to ensure that private session data is not cleared while there are
1140 * still in-flight operations using it.
1142 * @param dev_id ID of device that uses the session.
1143 * @param sess Session containing the reference to the private data
1146 * - 0 if successful.
1147 * - -EINVAL if device is invalid or session is NULL.
1148 * - -ENOTSUP if crypto device does not support symmetric operations.
1151 rte_cryptodev_sym_session_clear(uint8_t dev_id,
1152 struct rte_cryptodev_sym_session *sess);
1155 * Frees resources held by asymmetric session during rte_cryptodev_session_init
1157 * @param dev_id ID of device that uses the asymmetric session.
1158 * @param sess Asymmetric session setup on device using
1159 * rte_cryptodev_session_init
1161 * - 0 if successful.
1162 * - -EINVAL if device is invalid or session is NULL.
1166 rte_cryptodev_asym_session_clear(uint8_t dev_id,
1167 struct rte_cryptodev_asym_session *sess);
1170 * Get the size of the header session, for all registered drivers excluding
1171 * the user data size.
1174 * Size of the symmetric header session.
1177 rte_cryptodev_sym_get_header_session_size(void);
1180 * Get the size of the header session from created session.
1183 * The sym cryptodev session pointer
1186 * - If sess is not NULL, return the size of the header session including
1187 * the private data size defined within sess.
1188 * - If sess is NULL, return 0.
1192 rte_cryptodev_sym_get_existing_header_session_size(
1193 struct rte_cryptodev_sym_session *sess);
1196 * Get the size of the asymmetric session header, for all registered drivers.
1199 * Size of the asymmetric header session.
1203 rte_cryptodev_asym_get_header_session_size(void);
1206 * Get the size of the private symmetric session data
1209 * @param dev_id The device identifier.
1212 * - Size of the private data, if successful
1213 * - 0 if device is invalid or does not have private
1217 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
1220 * Get the size of the private data for asymmetric session
1223 * @param dev_id The device identifier.
1226 * - Size of the asymmetric private data, if successful
1227 * - 0 if device is invalid or does not have private session
1231 rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
1234 * Provide driver identifier.
1237 * The pointer to a driver name.
1239 * The driver type identifier or -1 if no driver found
1241 int rte_cryptodev_driver_id_get(const char *name);
1244 * Provide driver name.
1247 * The driver identifier.
1249 * The driver name or null if no driver found
1251 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1254 * Store user data in a session.
1256 * @param sess Session pointer allocated by
1257 * *rte_cryptodev_sym_session_create*.
1258 * @param data Pointer to the user data.
1259 * @param size Size of the user data.
1262 * - On success, zero.
1263 * - On failure, a negative value.
1267 rte_cryptodev_sym_session_set_user_data(
1268 struct rte_cryptodev_sym_session *sess,
1273 * Get user data stored in a session.
1275 * @param sess Session pointer allocated by
1276 * *rte_cryptodev_sym_session_create*.
1279 * - On success return pointer to user data.
1280 * - On failure returns NULL.
1284 rte_cryptodev_sym_session_get_user_data(
1285 struct rte_cryptodev_sym_session *sess);
1288 * Perform actual crypto processing (encrypt/digest or auth/decrypt)
1289 * on user provided data.
1291 * @param dev_id The device identifier.
1292 * @param sess Cryptodev session structure
1293 * @param ofs Start and stop offsets for auth and cipher operations
1294 * @param vec Vectorized operation descriptor
1297 * - Returns number of successfully processed packets.
1301 rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
1302 struct rte_cryptodev_sym_session *sess, union rte_crypto_sym_ofs ofs,
1303 struct rte_crypto_sym_vec *vec);
1309 #endif /* _RTE_CRYPTODEV_H_ */