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 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
42 #define CDEV_LOG_DEBUG(...) \
43 RTE_LOG(DEBUG, CRYPTODEV, \
44 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
45 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
47 #define CDEV_PMD_TRACE(...) \
48 RTE_LOG(DEBUG, CRYPTODEV, \
49 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
50 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
53 #define CDEV_LOG_DEBUG(...) (void)0
54 #define CDEV_PMD_TRACE(...) (void)0
60 * A macro that points to an offset from the start
61 * of the crypto operation structure (rte_crypto_op)
63 * The returned pointer is cast to type t.
66 * The crypto operation.
68 * The offset from the start of the crypto operation.
70 * The type to cast the result into.
72 #define rte_crypto_op_ctod_offset(c, t, o) \
73 ((t)((char *)(c) + (o)))
76 * A macro that returns the physical address that points
77 * to an offset from the start of the crypto operation
81 * The crypto operation.
83 * The offset from the start of the crypto operation
84 * to calculate address from.
86 #define rte_crypto_op_ctophys_offset(c, o) \
87 (rte_iova_t)((c)->phys_addr + (o))
90 * Crypto parameters range description
92 struct rte_crypto_param_range {
93 uint16_t min; /**< minimum size */
94 uint16_t max; /**< maximum size */
96 /**< if a range of sizes are supported,
97 * this parameter is used to indicate
98 * increments in byte size that are supported
99 * between the minimum and maximum
104 * Symmetric Crypto Capability
106 struct rte_cryptodev_symmetric_capability {
107 enum rte_crypto_sym_xform_type xform_type;
108 /**< Transform type : Authentication / Cipher / AEAD */
112 enum rte_crypto_auth_algorithm algo;
113 /**< authentication algorithm */
115 /**< algorithm block size */
116 struct rte_crypto_param_range key_size;
117 /**< auth key size range */
118 struct rte_crypto_param_range digest_size;
119 /**< digest size range */
120 struct rte_crypto_param_range aad_size;
121 /**< Additional authentication data size range */
122 struct rte_crypto_param_range iv_size;
123 /**< Initialisation vector data size range */
125 /**< Symmetric Authentication transform capabilities */
127 enum rte_crypto_cipher_algorithm algo;
128 /**< cipher algorithm */
130 /**< algorithm block size */
131 struct rte_crypto_param_range key_size;
132 /**< cipher key size range */
133 struct rte_crypto_param_range iv_size;
134 /**< Initialisation vector data size range */
136 /**< Symmetric Cipher transform capabilities */
138 enum rte_crypto_aead_algorithm algo;
139 /**< AEAD algorithm */
141 /**< algorithm block size */
142 struct rte_crypto_param_range key_size;
143 /**< AEAD key size range */
144 struct rte_crypto_param_range digest_size;
145 /**< digest size range */
146 struct rte_crypto_param_range aad_size;
147 /**< Additional authentication data size range */
148 struct rte_crypto_param_range iv_size;
149 /**< Initialisation vector data size range */
154 /** Structure used to capture a capability of a crypto device */
155 struct rte_cryptodev_capabilities {
156 enum rte_crypto_op_type op;
157 /**< Operation type */
161 struct rte_cryptodev_symmetric_capability sym;
162 /**< Symmetric operation capability parameters */
166 /** Structure used to describe crypto algorithms */
167 struct rte_cryptodev_sym_capability_idx {
168 enum rte_crypto_sym_xform_type type;
170 enum rte_crypto_cipher_algorithm cipher;
171 enum rte_crypto_auth_algorithm auth;
172 enum rte_crypto_aead_algorithm aead;
177 * Provide capabilities available for defined device and algorithm
179 * @param dev_id The identifier of the device.
180 * @param idx Description of crypto algorithms.
183 * - Return description of the symmetric crypto capability if exist.
184 * - Return NULL if the capability not exist.
186 const struct rte_cryptodev_symmetric_capability *
187 rte_cryptodev_sym_capability_get(uint8_t dev_id,
188 const struct rte_cryptodev_sym_capability_idx *idx);
191 * Check if key size and initial vector are supported
192 * in crypto cipher capability
194 * @param capability Description of the symmetric crypto capability.
195 * @param key_size Cipher key size.
196 * @param iv_size Cipher initial vector size.
199 * - Return 0 if the parameters are in range of the capability.
200 * - Return -1 if the parameters are out of range of the capability.
203 rte_cryptodev_sym_capability_check_cipher(
204 const struct rte_cryptodev_symmetric_capability *capability,
205 uint16_t key_size, uint16_t iv_size);
208 * Check if key size and initial vector are supported
209 * in crypto auth capability
211 * @param capability Description of the symmetric crypto capability.
212 * @param key_size Auth key size.
213 * @param digest_size Auth digest size.
214 * @param iv_size Auth initial vector size.
217 * - Return 0 if the parameters are in range of the capability.
218 * - Return -1 if the parameters are out of range of the capability.
221 rte_cryptodev_sym_capability_check_auth(
222 const struct rte_cryptodev_symmetric_capability *capability,
223 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
226 * Check if key, digest, AAD and initial vector sizes are supported
227 * in crypto AEAD capability
229 * @param capability Description of the symmetric crypto capability.
230 * @param key_size AEAD key size.
231 * @param digest_size AEAD digest size.
232 * @param aad_size AEAD AAD size.
233 * @param iv_size AEAD IV size.
236 * - Return 0 if the parameters are in range of the capability.
237 * - Return -1 if the parameters are out of range of the capability.
240 rte_cryptodev_sym_capability_check_aead(
241 const struct rte_cryptodev_symmetric_capability *capability,
242 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
246 * Provide the cipher algorithm enum, given an algorithm string
248 * @param algo_enum A pointer to the cipher algorithm
250 * @param algo_string Authentication algo string
253 * - Return -1 if string is not valid
254 * - Return 0 is the string is valid
257 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
258 const char *algo_string);
261 * Provide the authentication algorithm enum, given an algorithm string
263 * @param algo_enum A pointer to the authentication algorithm
265 * @param algo_string Authentication algo string
268 * - Return -1 if string is not valid
269 * - Return 0 is the string is valid
272 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
273 const char *algo_string);
276 * Provide the AEAD algorithm enum, given an algorithm string
278 * @param algo_enum A pointer to the AEAD algorithm
280 * @param algo_string AEAD algorithm string
283 * - Return -1 if string is not valid
284 * - Return 0 is the string is valid
287 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
288 const char *algo_string);
290 /** Macro used at end of crypto PMD list */
291 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
292 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
296 * Crypto device supported feature flags
299 * New features flags should be added to the end of the list
301 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
303 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
304 /**< Symmetric crypto operations are supported */
305 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
306 /**< Asymmetric crypto operations are supported */
307 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
308 /**< Chaining symmetric crypto operations are supported */
309 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
310 /**< Utilises CPU SIMD SSE instructions */
311 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
312 /**< Utilises CPU SIMD AVX instructions */
313 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
314 /**< Utilises CPU SIMD AVX2 instructions */
315 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
316 /**< Utilises CPU AES-NI instructions */
317 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
318 /**< Operations are off-loaded to an external hardware accelerator */
319 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
320 /**< Utilises CPU SIMD AVX512 instructions */
321 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
322 /**< Scatter-gather mbufs are supported */
323 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
324 /**< Utilises CPU NEON instructions */
325 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
326 /**< Utilises ARM CPU Cryptographic Extensions */
327 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 12)
328 /**< Support Security Protocol Processing */
332 * Get the name of a crypto device feature flag
334 * @param flag The mask describing the flag.
337 * The name of this flag, or NULL if it's not a valid feature flag.
341 rte_cryptodev_get_feature_name(uint64_t flag);
343 /** Crypto device information */
344 struct rte_cryptodev_info {
345 const char *driver_name; /**< Driver name. */
346 uint8_t driver_id; /**< Driver identifier */
347 struct rte_pci_device *pci_dev; /**< PCI information. */
349 uint64_t feature_flags;
350 /**< Feature flags exposes HW/SW features for the given device */
352 const struct rte_cryptodev_capabilities *capabilities;
353 /**< Array of devices supported capabilities */
355 unsigned max_nb_queue_pairs;
356 /**< Maximum number of queues pairs supported by device. */
359 unsigned max_nb_sessions;
360 /**< Maximum number of sessions supported by device. */
361 unsigned int max_nb_sessions_per_qp;
362 /**< Maximum number of sessions per queue pair.
363 * Default 0 for infinite sessions
368 #define RTE_CRYPTODEV_DETACHED (0)
369 #define RTE_CRYPTODEV_ATTACHED (1)
371 /** Definitions of Crypto device event types */
372 enum rte_cryptodev_event_type {
373 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
374 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
375 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
378 /** Crypto device queue pair configuration structure. */
379 struct rte_cryptodev_qp_conf {
380 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
384 * Typedef for application callback function to be registered by application
385 * software for notification of device events
387 * @param dev_id Crypto device identifier
388 * @param event Crypto device event to register for notification of.
389 * @param cb_arg User specified parameter to be passed as to passed to
390 * users callback function.
392 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
393 enum rte_cryptodev_event_type event, void *cb_arg);
396 /** Crypto Device statistics */
397 struct rte_cryptodev_stats {
398 uint64_t enqueued_count;
399 /**< Count of all operations enqueued */
400 uint64_t dequeued_count;
401 /**< Count of all operations dequeued */
403 uint64_t enqueue_err_count;
404 /**< Total error count on operations enqueued */
405 uint64_t dequeue_err_count;
406 /**< Total error count on operations dequeued */
409 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
410 /**< Max length of name of crypto PMD */
413 * Get the device identifier for the named crypto device.
415 * @param name device name to select the device structure.
418 * - Returns crypto device identifier on success.
419 * - Return -1 on failure to find named crypto device.
422 rte_cryptodev_get_dev_id(const char *name);
425 * Get the crypto device name given a device identifier.
428 * The identifier of the device
431 * - Returns crypto device name.
432 * - Returns NULL if crypto device is not present.
435 rte_cryptodev_name_get(uint8_t dev_id);
438 * Get the total number of crypto devices that have been successfully
442 * - The total number of usable crypto devices.
445 rte_cryptodev_count(void);
448 * Get number of crypto device defined type.
450 * @param driver_id driver identifier.
453 * Returns number of crypto device.
456 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
459 * Get number and identifiers of attached crypto devices that
460 * use the same crypto driver.
462 * @param driver_name driver name.
463 * @param devices output devices identifiers.
464 * @param nb_devices maximal number of devices.
467 * Returns number of attached crypto device.
470 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
473 * Return the NUMA socket to which a device is connected
476 * The identifier of the device
478 * The NUMA socket id to which the device is connected or
479 * a default of zero if the socket could not be determined.
480 * -1 if returned is the dev_id value is out of range.
483 rte_cryptodev_socket_id(uint8_t dev_id);
485 /** Crypto device configuration structure */
486 struct rte_cryptodev_config {
487 int socket_id; /**< Socket to allocate resources on */
488 uint16_t nb_queue_pairs;
489 /**< Number of queue pairs to configure on device */
493 * Configure a device.
495 * This function must be invoked first before any other function in the
496 * API. This function can also be re-invoked when a device is in the
499 * @param dev_id The identifier of the device to configure.
500 * @param config The crypto device configuration structure.
503 * - 0: Success, device configured.
504 * - <0: Error code returned by the driver configuration function.
507 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
512 * The device start step is the last one and consists of setting the configured
513 * offload features and in starting the transmit and the receive units of the
515 * On success, all basic functions exported by the API (link status,
516 * receive/transmit, and so on) can be invoked.
519 * The identifier of the device.
521 * - 0: Success, device started.
522 * - <0: Error code of the driver device start function.
525 rte_cryptodev_start(uint8_t dev_id);
528 * Stop an device. The device can be restarted with a call to
529 * rte_cryptodev_start()
531 * @param dev_id The identifier of the device.
534 rte_cryptodev_stop(uint8_t dev_id);
537 * Close an device. The device cannot be restarted!
539 * @param dev_id The identifier of the device.
542 * - 0 on successfully closing device
543 * - <0 on failure to close device
546 rte_cryptodev_close(uint8_t dev_id);
549 * Allocate and set up a receive queue pair for a device.
552 * @param dev_id The identifier of the device.
553 * @param queue_pair_id The index of the queue pairs to set up. The
554 * value must be in the range [0, nb_queue_pair
555 * - 1] previously supplied to
556 * rte_cryptodev_configure().
557 * @param qp_conf The pointer to the configuration data to be
558 * used for the queue pair. NULL value is
559 * allowed, in which case default configuration
561 * @param socket_id The *socket_id* argument is the socket
562 * identifier in case of NUMA. The value can be
563 * *SOCKET_ID_ANY* if there is no NUMA constraint
564 * for the DMA memory allocated for the receive
566 * @param session_pool Pointer to device session mempool, used
567 * for session-less operations.
570 * - 0: Success, queue pair correctly set up.
571 * - <0: Queue pair configuration failed
574 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
575 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
576 struct rte_mempool *session_pool);
580 * Start a specified queue pair of a device. It is used
581 * when deferred_start flag of the specified queue is true.
583 * @param dev_id The identifier of the device
584 * @param queue_pair_id The index of the queue pair to start. The value
585 * must be in the range [0, nb_queue_pair - 1]
586 * previously supplied to
587 * rte_crypto_dev_configure().
589 * - 0: Success, the transmit queue is correctly set up.
590 * - -EINVAL: The dev_id or the queue_id out of range.
591 * - -ENOTSUP: The function not supported in PMD driver.
595 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
599 * Stop specified queue pair of a device
601 * @param dev_id The identifier of the device
602 * @param queue_pair_id The index of the queue pair to stop. The value
603 * must be in the range [0, nb_queue_pair - 1]
604 * previously supplied to
605 * rte_cryptodev_configure().
607 * - 0: Success, the transmit queue is correctly set up.
608 * - -EINVAL: The dev_id or the queue_id out of range.
609 * - -ENOTSUP: The function not supported in PMD driver.
613 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
616 * Get the number of queue pairs on a specific crypto device
618 * @param dev_id Crypto device identifier.
620 * - The number of configured queue pairs.
623 rte_cryptodev_queue_pair_count(uint8_t dev_id);
627 * Retrieve the general I/O statistics of a device.
629 * @param dev_id The identifier of the device.
630 * @param stats A pointer to a structure of type
631 * *rte_cryptodev_stats* to be filled with the
632 * values of device counters.
634 * - Zero if successful.
635 * - Non-zero otherwise.
638 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
641 * Reset the general I/O statistics of a device.
643 * @param dev_id The identifier of the device.
646 rte_cryptodev_stats_reset(uint8_t dev_id);
649 * Retrieve the contextual information of a device.
651 * @param dev_id The identifier of the device.
652 * @param dev_info A pointer to a structure of type
653 * *rte_cryptodev_info* to be filled with the
654 * contextual information of the device.
656 * @note The capabilities field of dev_info is set to point to the first
657 * element of an array of struct rte_cryptodev_capabilities. The element after
658 * the last valid element has it's op field set to
659 * RTE_CRYPTO_OP_TYPE_UNDEFINED.
662 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
666 * Register a callback function for specific device id.
668 * @param dev_id Device id.
669 * @param event Event interested.
670 * @param cb_fn User supplied callback function to be called.
671 * @param cb_arg Pointer to the parameters for the registered
675 * - On success, zero.
676 * - On failure, a negative value.
679 rte_cryptodev_callback_register(uint8_t dev_id,
680 enum rte_cryptodev_event_type event,
681 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
684 * Unregister a callback function for specific device id.
686 * @param dev_id The device identifier.
687 * @param event Event interested.
688 * @param cb_fn User supplied callback function to be called.
689 * @param cb_arg Pointer to the parameters for the registered
693 * - On success, zero.
694 * - On failure, a negative value.
697 rte_cryptodev_callback_unregister(uint8_t dev_id,
698 enum rte_cryptodev_event_type event,
699 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
702 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
703 struct rte_crypto_op **ops, uint16_t nb_ops);
704 /**< Dequeue processed packets from queue pair of a device. */
706 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
707 struct rte_crypto_op **ops, uint16_t nb_ops);
708 /**< Enqueue packets for processing on queue pair of a device. */
713 struct rte_cryptodev_callback;
715 /** Structure to keep track of registered callbacks */
716 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
718 /** The data structure associated with each crypto device. */
719 struct rte_cryptodev {
720 dequeue_pkt_burst_t dequeue_burst;
721 /**< Pointer to PMD receive function. */
722 enqueue_pkt_burst_t enqueue_burst;
723 /**< Pointer to PMD transmit function. */
725 struct rte_cryptodev_data *data;
726 /**< Pointer to device data */
727 struct rte_cryptodev_ops *dev_ops;
728 /**< Functions exported by PMD */
729 uint64_t feature_flags;
730 /**< Feature flags exposes HW/SW features for the given device */
731 struct rte_device *device;
732 /**< Backing device */
735 /**< Crypto driver identifier*/
737 struct rte_cryptodev_cb_list link_intr_cbs;
738 /**< User application callback for interrupts if present */
741 /**< Context for security ops */
744 uint8_t attached : 1;
745 /**< Flag indicating the device is attached */
746 } __rte_cache_aligned;
749 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
753 * The data part, with no function pointers, associated with each device.
755 * This structure is safe to place in shared memory to be common among
756 * different processes in a multi-process configuration.
758 struct rte_cryptodev_data {
760 /**< Device ID for this instance */
762 /**< Socket ID where memory is allocated */
763 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
764 /**< Unique identifier name */
767 uint8_t dev_started : 1;
768 /**< Device state: STARTED(1)/STOPPED(0) */
770 struct rte_mempool *session_pool;
771 /**< Session memory pool */
773 /**< Array of pointers to queue pairs. */
774 uint16_t nb_queue_pairs;
775 /**< Number of device queue pairs. */
778 /**< PMD-specific private data */
779 } __rte_cache_aligned;
781 extern struct rte_cryptodev *rte_cryptodevs;
784 * Dequeue a burst of processed crypto operations from a queue on the crypto
785 * device. The dequeued operation are stored in *rte_crypto_op* structures
786 * whose pointers are supplied in the *ops* array.
788 * The rte_cryptodev_dequeue_burst() function returns the number of ops
789 * actually dequeued, which is the number of *rte_crypto_op* data structures
790 * effectively supplied into the *ops* array.
792 * A return value equal to *nb_ops* indicates that the queue contained
793 * at least *nb_ops* operations, and this is likely to signify that other
794 * processed operations remain in the devices output queue. Applications
795 * implementing a "retrieve as many processed operations as possible" policy
796 * can check this specific case and keep invoking the
797 * rte_cryptodev_dequeue_burst() function until a value less than
798 * *nb_ops* is returned.
800 * The rte_cryptodev_dequeue_burst() function does not provide any error
801 * notification to avoid the corresponding overhead.
803 * @param dev_id The symmetric crypto device identifier
804 * @param qp_id The index of the queue pair from which to
805 * retrieve processed packets. The value must be
806 * in the range [0, nb_queue_pair - 1] previously
807 * supplied to rte_cryptodev_configure().
808 * @param ops The address of an array of pointers to
809 * *rte_crypto_op* structures that must be
810 * large enough to store *nb_ops* pointers in it.
811 * @param nb_ops The maximum number of operations to dequeue.
814 * - The number of operations actually dequeued, which is the number
815 * of pointers to *rte_crypto_op* structures effectively supplied to the
818 static inline uint16_t
819 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
820 struct rte_crypto_op **ops, uint16_t nb_ops)
822 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
824 nb_ops = (*dev->dequeue_burst)
825 (dev->data->queue_pairs[qp_id], ops, nb_ops);
831 * Enqueue a burst of operations for processing on a crypto device.
833 * The rte_cryptodev_enqueue_burst() function is invoked to place
834 * crypto operations on the queue *qp_id* of the device designated by
837 * The *nb_ops* parameter is the number of operations to process which are
838 * supplied in the *ops* array of *rte_crypto_op* structures.
840 * The rte_cryptodev_enqueue_burst() function returns the number of
841 * operations it actually enqueued for processing. A return value equal to
842 * *nb_ops* means that all packets have been enqueued.
844 * @param dev_id The identifier of the device.
845 * @param qp_id The index of the queue pair which packets are
846 * to be enqueued for processing. The value
847 * must be in the range [0, nb_queue_pairs - 1]
848 * previously supplied to
849 * *rte_cryptodev_configure*.
850 * @param ops The address of an array of *nb_ops* pointers
851 * to *rte_crypto_op* structures which contain
852 * the crypto operations to be processed.
853 * @param nb_ops The number of operations to process.
856 * The number of operations actually enqueued on the crypto device. The return
857 * value can be less than the value of the *nb_ops* parameter when the
858 * crypto devices queue is full or if invalid parameters are specified in
861 static inline uint16_t
862 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
863 struct rte_crypto_op **ops, uint16_t nb_ops)
865 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
867 return (*dev->enqueue_burst)(
868 dev->data->queue_pairs[qp_id], ops, nb_ops);
872 /** Cryptodev symmetric crypto session
873 * Each session is derived from a fixed xform chain. Therefore each session
874 * has a fixed algo, key, op-type, digest_len etc.
876 struct rte_cryptodev_sym_session {
877 __extension__ void *sess_private_data[0];
878 /**< Private session material */
883 * Create symmetric crypto session header (generic with no private data)
885 * @param mempool Symmetric session mempool to allocate session
888 * - On success return pointer to sym-session
889 * - On failure returns NULL
891 struct rte_cryptodev_sym_session *
892 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
895 * Frees symmetric crypto session header, after checking that all
896 * the device private data has been freed, returning it
897 * to its original mempool.
899 * @param sess Session header to be freed.
903 * - -EINVAL if session is NULL.
904 * - -EBUSY if not all device private data has been freed.
907 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
910 * Fill out private data for the device id, based on its device type.
912 * @param dev_id ID of device that we want the session to be used on
913 * @param sess Session where the private data will be attached to
914 * @param xforms Symmetric crypto transform operations to apply on flow
915 * processed with this session
916 * @param mempool Mempool where the private data is allocated.
919 * - On success, zero.
920 * - -EINVAL if input parameters are invalid.
921 * - -ENOTSUP if crypto device does not support the crypto transform.
922 * - -ENOMEM if the private session could not be allocated.
925 rte_cryptodev_sym_session_init(uint8_t dev_id,
926 struct rte_cryptodev_sym_session *sess,
927 struct rte_crypto_sym_xform *xforms,
928 struct rte_mempool *mempool);
931 * Frees private data for the device id, based on its device type,
932 * returning it to its mempool. It is the application's responsibility
933 * to ensure that private session data is not cleared while there are
934 * still in-flight operations using it.
936 * @param dev_id ID of device that uses the session.
937 * @param sess Session containing the reference to the private data
941 * - -EINVAL if device is invalid or session is NULL.
944 rte_cryptodev_sym_session_clear(uint8_t dev_id,
945 struct rte_cryptodev_sym_session *sess);
949 * Get the size of the header session, for all registered drivers.
952 * Size of the header session.
956 rte_cryptodev_get_header_session_size(void);
960 * Get the size of the private session data for a device.
962 * @param dev_id The device identifier.
965 * - Size of the private data, if successful
966 * - 0 if device is invalid or does not have private session
970 rte_cryptodev_get_private_session_size(uint8_t dev_id);
973 * Get the size of the header session, for all registered drivers.
976 * Size of the symmetric eader session.
979 rte_cryptodev_sym_get_header_session_size(void);
982 * Get the size of the private symmetric session data
985 * @param dev_id The device identifier.
988 * - Size of the private data, if successful
989 * - 0 if device is invalid or does not have private
993 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
997 * Attach queue pair with sym session.
999 * @param dev_id Device to which the session will be attached.
1000 * @param qp_id Queue pair to which the session will be attached.
1001 * @param session Session pointer previously allocated by
1002 * *rte_cryptodev_sym_session_create*.
1005 * - On success, zero.
1006 * - On failure, a negative value.
1010 rte_cryptodev_queue_pair_attach_sym_session(uint8_t dev_id, uint16_t qp_id,
1011 struct rte_cryptodev_sym_session *session);
1015 * Detach queue pair with sym session.
1017 * @param dev_id Device to which the session is attached.
1018 * @param qp_id Queue pair to which the session is attached.
1019 * @param session Session pointer previously allocated by
1020 * *rte_cryptodev_sym_session_create*.
1023 * - On success, zero.
1024 * - On failure, a negative value.
1028 rte_cryptodev_queue_pair_detach_sym_session(uint8_t dev_id, uint16_t qp_id,
1029 struct rte_cryptodev_sym_session *session);
1032 * Provide driver identifier.
1035 * The pointer to a driver name.
1037 * The driver type identifier or -1 if no driver found
1039 int rte_cryptodev_driver_id_get(const char *name);
1042 * Provide driver name.
1045 * The driver identifier.
1047 * The driver name or null if no driver found
1049 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1052 * Set private data for a session.
1054 * @param sess Session pointer allocated by
1055 * *rte_cryptodev_sym_session_create*.
1056 * @param data Pointer to the private data.
1057 * @param size Size of the private data.
1060 * - On success, zero.
1061 * - On failure, a negative value.
1063 int __rte_experimental
1064 rte_cryptodev_sym_session_set_private_data(
1065 struct rte_cryptodev_sym_session *sess,
1070 * Get private data of a session.
1072 * @param sess Session pointer allocated by
1073 * *rte_cryptodev_sym_session_create*.
1076 * - On success return pointer to private data.
1077 * - On failure returns NULL.
1079 void * __rte_experimental
1080 rte_cryptodev_sym_session_get_private_data(
1081 struct rte_cryptodev_sym_session *sess);
1087 #endif /* _RTE_CRYPTODEV_H_ */