1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2017 Intel Corporation.
5 #ifndef _RTE_CRYPTODEV_H_
6 #define _RTE_CRYPTODEV_H_
9 * @file rte_cryptodev.h
11 * RTE Cryptographic Device APIs
13 * Defines RTE Crypto Device APIs for the provisioning of cipher and
14 * authentication operations.
21 #include "rte_kvargs.h"
22 #include "rte_crypto.h"
24 #include <rte_common.h>
25 #include <rte_config.h>
27 extern const char **rte_cyptodev_names;
31 #define CDEV_LOG_ERR(...) \
32 RTE_LOG(ERR, CRYPTODEV, \
33 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
34 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
36 #define CDEV_LOG_INFO(...) \
37 RTE_LOG(INFO, CRYPTODEV, \
38 RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
39 RTE_FMT_TAIL(__VA_ARGS__,)))
41 #define CDEV_LOG_DEBUG(...) \
42 RTE_LOG(DEBUG, CRYPTODEV, \
43 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
44 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
46 #define CDEV_PMD_TRACE(...) \
47 RTE_LOG(DEBUG, CRYPTODEV, \
48 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
49 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
52 * A macro that points to an offset from the start
53 * of the crypto operation structure (rte_crypto_op)
55 * The returned pointer is cast to type t.
58 * The crypto operation.
60 * The offset from the start of the crypto operation.
62 * The type to cast the result into.
64 #define rte_crypto_op_ctod_offset(c, t, o) \
65 ((t)((char *)(c) + (o)))
68 * A macro that returns the physical address that points
69 * to an offset from the start of the crypto operation
73 * The crypto operation.
75 * The offset from the start of the crypto operation
76 * to calculate address from.
78 #define rte_crypto_op_ctophys_offset(c, o) \
79 (rte_iova_t)((c)->phys_addr + (o))
82 * Crypto parameters range description
84 struct rte_crypto_param_range {
85 uint16_t min; /**< minimum size */
86 uint16_t max; /**< maximum size */
88 /**< if a range of sizes are supported,
89 * this parameter is used to indicate
90 * increments in byte size that are supported
91 * between the minimum and maximum
96 * Symmetric Crypto Capability
98 struct rte_cryptodev_symmetric_capability {
99 enum rte_crypto_sym_xform_type xform_type;
100 /**< Transform type : Authentication / Cipher / AEAD */
104 enum rte_crypto_auth_algorithm algo;
105 /**< authentication algorithm */
107 /**< algorithm block size */
108 struct rte_crypto_param_range key_size;
109 /**< auth key size range */
110 struct rte_crypto_param_range digest_size;
111 /**< digest size range */
112 struct rte_crypto_param_range aad_size;
113 /**< Additional authentication data size range */
114 struct rte_crypto_param_range iv_size;
115 /**< Initialisation vector data size range */
117 /**< Symmetric Authentication transform capabilities */
119 enum rte_crypto_cipher_algorithm algo;
120 /**< cipher algorithm */
122 /**< algorithm block size */
123 struct rte_crypto_param_range key_size;
124 /**< cipher key size range */
125 struct rte_crypto_param_range iv_size;
126 /**< Initialisation vector data size range */
128 /**< Symmetric Cipher transform capabilities */
130 enum rte_crypto_aead_algorithm algo;
131 /**< AEAD algorithm */
133 /**< algorithm block size */
134 struct rte_crypto_param_range key_size;
135 /**< AEAD key size range */
136 struct rte_crypto_param_range digest_size;
137 /**< digest size range */
138 struct rte_crypto_param_range aad_size;
139 /**< Additional authentication data size range */
140 struct rte_crypto_param_range iv_size;
141 /**< Initialisation vector data size range */
146 /** Structure used to capture a capability of a crypto device */
147 struct rte_cryptodev_capabilities {
148 enum rte_crypto_op_type op;
149 /**< Operation type */
153 struct rte_cryptodev_symmetric_capability sym;
154 /**< Symmetric operation capability parameters */
158 /** Structure used to describe crypto algorithms */
159 struct rte_cryptodev_sym_capability_idx {
160 enum rte_crypto_sym_xform_type type;
162 enum rte_crypto_cipher_algorithm cipher;
163 enum rte_crypto_auth_algorithm auth;
164 enum rte_crypto_aead_algorithm aead;
169 * Provide capabilities available for defined device and algorithm
171 * @param dev_id The identifier of the device.
172 * @param idx Description of crypto algorithms.
175 * - Return description of the symmetric crypto capability if exist.
176 * - Return NULL if the capability not exist.
178 const struct rte_cryptodev_symmetric_capability *
179 rte_cryptodev_sym_capability_get(uint8_t dev_id,
180 const struct rte_cryptodev_sym_capability_idx *idx);
183 * Check if key size and initial vector are supported
184 * in crypto cipher capability
186 * @param capability Description of the symmetric crypto capability.
187 * @param key_size Cipher key size.
188 * @param iv_size Cipher initial vector size.
191 * - Return 0 if the parameters are in range of the capability.
192 * - Return -1 if the parameters are out of range of the capability.
195 rte_cryptodev_sym_capability_check_cipher(
196 const struct rte_cryptodev_symmetric_capability *capability,
197 uint16_t key_size, uint16_t iv_size);
200 * Check if key size and initial vector are supported
201 * in crypto auth capability
203 * @param capability Description of the symmetric crypto capability.
204 * @param key_size Auth key size.
205 * @param digest_size Auth digest size.
206 * @param iv_size Auth initial vector size.
209 * - Return 0 if the parameters are in range of the capability.
210 * - Return -1 if the parameters are out of range of the capability.
213 rte_cryptodev_sym_capability_check_auth(
214 const struct rte_cryptodev_symmetric_capability *capability,
215 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
218 * Check if key, digest, AAD and initial vector sizes are supported
219 * in crypto AEAD capability
221 * @param capability Description of the symmetric crypto capability.
222 * @param key_size AEAD key size.
223 * @param digest_size AEAD digest size.
224 * @param aad_size AEAD AAD size.
225 * @param iv_size AEAD IV size.
228 * - Return 0 if the parameters are in range of the capability.
229 * - Return -1 if the parameters are out of range of the capability.
232 rte_cryptodev_sym_capability_check_aead(
233 const struct rte_cryptodev_symmetric_capability *capability,
234 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
238 * Provide the cipher algorithm enum, given an algorithm string
240 * @param algo_enum A pointer to the cipher algorithm
242 * @param algo_string Authentication algo string
245 * - Return -1 if string is not valid
246 * - Return 0 is the string is valid
249 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
250 const char *algo_string);
253 * Provide the authentication algorithm enum, given an algorithm string
255 * @param algo_enum A pointer to the authentication algorithm
257 * @param algo_string Authentication algo string
260 * - Return -1 if string is not valid
261 * - Return 0 is the string is valid
264 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
265 const char *algo_string);
268 * Provide the AEAD algorithm enum, given an algorithm string
270 * @param algo_enum A pointer to the AEAD algorithm
272 * @param algo_string AEAD algorithm string
275 * - Return -1 if string is not valid
276 * - Return 0 is the string is valid
279 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
280 const char *algo_string);
282 /** Macro used at end of crypto PMD list */
283 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
284 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
288 * Crypto device supported feature flags
291 * New features flags should be added to the end of the list
293 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
295 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
296 /**< Symmetric crypto operations are supported */
297 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
298 /**< Asymmetric crypto operations are supported */
299 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
300 /**< Chaining symmetric crypto operations are supported */
301 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
302 /**< Utilises CPU SIMD SSE instructions */
303 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
304 /**< Utilises CPU SIMD AVX instructions */
305 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
306 /**< Utilises CPU SIMD AVX2 instructions */
307 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
308 /**< Utilises CPU AES-NI instructions */
309 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
310 /**< Operations are off-loaded to an
311 * external hardware accelerator
313 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
314 /**< Utilises CPU SIMD AVX512 instructions */
315 #define RTE_CRYPTODEV_FF_IN_PLACE_SGL (1ULL << 9)
316 /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
319 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT (1ULL << 10)
320 /**< Out-of-place Scatter-gather (SGL) buffers are
321 * supported in input and output
323 #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT (1ULL << 11)
324 /**< Out-of-place Scatter-gather (SGL) buffers are supported
325 * in input, combined with linear buffers (LB), with a
326 * single segment in output
328 #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT (1ULL << 12)
329 /**< Out-of-place Scatter-gather (SGL) buffers are supported
330 * in output, combined with linear buffers (LB) in input
332 #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT (1ULL << 13)
333 /**< Out-of-place linear buffers (LB) are supported in input and output */
334 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 14)
335 /**< Utilises CPU NEON instructions */
336 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 15)
337 /**< Utilises ARM CPU Cryptographic Extensions */
338 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 16)
339 /**< Support Security Protocol Processing */
343 * Get the name of a crypto device feature flag
345 * @param flag The mask describing the flag.
348 * The name of this flag, or NULL if it's not a valid feature flag.
352 rte_cryptodev_get_feature_name(uint64_t flag);
354 /** Crypto device information */
355 struct rte_cryptodev_info {
356 const char *driver_name; /**< Driver name. */
357 uint8_t driver_id; /**< Driver identifier */
358 struct rte_device *device; /**< Generic device information. */
360 uint64_t feature_flags;
361 /**< Feature flags exposes HW/SW features for the given device */
363 const struct rte_cryptodev_capabilities *capabilities;
364 /**< Array of devices supported capabilities */
366 unsigned max_nb_queue_pairs;
367 /**< Maximum number of queues pairs supported by device. */
369 uint16_t min_mbuf_headroom_req;
370 /**< Minimum mbuf headroom required by device */
372 uint16_t min_mbuf_tailroom_req;
373 /**< Minimum mbuf tailroom required by device */
376 unsigned max_nb_sessions;
377 /**< Maximum number of sessions supported by device.
378 * If 0, the device does not have any limitation in
379 * number of sessions that can be used.
384 #define RTE_CRYPTODEV_DETACHED (0)
385 #define RTE_CRYPTODEV_ATTACHED (1)
387 /** Definitions of Crypto device event types */
388 enum rte_cryptodev_event_type {
389 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
390 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
391 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
394 /** Crypto device queue pair configuration structure. */
395 struct rte_cryptodev_qp_conf {
396 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
400 * Typedef for application callback function to be registered by application
401 * software for notification of device events
403 * @param dev_id Crypto device identifier
404 * @param event Crypto device event to register for notification of.
405 * @param cb_arg User specified parameter to be passed as to passed to
406 * users callback function.
408 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
409 enum rte_cryptodev_event_type event, void *cb_arg);
412 /** Crypto Device statistics */
413 struct rte_cryptodev_stats {
414 uint64_t enqueued_count;
415 /**< Count of all operations enqueued */
416 uint64_t dequeued_count;
417 /**< Count of all operations dequeued */
419 uint64_t enqueue_err_count;
420 /**< Total error count on operations enqueued */
421 uint64_t dequeue_err_count;
422 /**< Total error count on operations dequeued */
425 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
426 /**< Max length of name of crypto PMD */
429 * Get the device identifier for the named crypto device.
431 * @param name device name to select the device structure.
434 * - Returns crypto device identifier on success.
435 * - Return -1 on failure to find named crypto device.
438 rte_cryptodev_get_dev_id(const char *name);
441 * Get the crypto device name given a device identifier.
444 * The identifier of the device
447 * - Returns crypto device name.
448 * - Returns NULL if crypto device is not present.
451 rte_cryptodev_name_get(uint8_t dev_id);
454 * Get the total number of crypto devices that have been successfully
458 * - The total number of usable crypto devices.
461 rte_cryptodev_count(void);
464 * Get number of crypto device defined type.
466 * @param driver_id driver identifier.
469 * Returns number of crypto device.
472 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
475 * Get number and identifiers of attached crypto devices that
476 * use the same crypto driver.
478 * @param driver_name driver name.
479 * @param devices output devices identifiers.
480 * @param nb_devices maximal number of devices.
483 * Returns number of attached crypto device.
486 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
489 * Return the NUMA socket to which a device is connected
492 * The identifier of the device
494 * The NUMA socket id to which the device is connected or
495 * a default of zero if the socket could not be determined.
496 * -1 if returned is the dev_id value is out of range.
499 rte_cryptodev_socket_id(uint8_t dev_id);
501 /** Crypto device configuration structure */
502 struct rte_cryptodev_config {
503 int socket_id; /**< Socket to allocate resources on */
504 uint16_t nb_queue_pairs;
505 /**< Number of queue pairs to configure on device */
509 * Configure a device.
511 * This function must be invoked first before any other function in the
512 * API. This function can also be re-invoked when a device is in the
515 * @param dev_id The identifier of the device to configure.
516 * @param config The crypto device configuration structure.
519 * - 0: Success, device configured.
520 * - <0: Error code returned by the driver configuration function.
523 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
528 * The device start step is the last one and consists of setting the configured
529 * offload features and in starting the transmit and the receive units of the
531 * On success, all basic functions exported by the API (link status,
532 * receive/transmit, and so on) can be invoked.
535 * The identifier of the device.
537 * - 0: Success, device started.
538 * - <0: Error code of the driver device start function.
541 rte_cryptodev_start(uint8_t dev_id);
544 * Stop an device. The device can be restarted with a call to
545 * rte_cryptodev_start()
547 * @param dev_id The identifier of the device.
550 rte_cryptodev_stop(uint8_t dev_id);
553 * Close an device. The device cannot be restarted!
555 * @param dev_id The identifier of the device.
558 * - 0 on successfully closing device
559 * - <0 on failure to close device
562 rte_cryptodev_close(uint8_t dev_id);
565 * Allocate and set up a receive queue pair for a device.
568 * @param dev_id The identifier of the device.
569 * @param queue_pair_id The index of the queue pairs to set up. The
570 * value must be in the range [0, nb_queue_pair
571 * - 1] previously supplied to
572 * rte_cryptodev_configure().
573 * @param qp_conf The pointer to the configuration data to be
574 * used for the queue pair. NULL value is
575 * allowed, in which case default configuration
577 * @param socket_id The *socket_id* argument is the socket
578 * identifier in case of NUMA. The value can be
579 * *SOCKET_ID_ANY* if there is no NUMA constraint
580 * for the DMA memory allocated for the receive
582 * @param session_pool Pointer to device session mempool, used
583 * for session-less operations.
586 * - 0: Success, queue pair correctly set up.
587 * - <0: Queue pair configuration failed
590 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
591 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
592 struct rte_mempool *session_pool);
595 * Get the number of queue pairs on a specific crypto device
597 * @param dev_id Crypto device identifier.
599 * - The number of configured queue pairs.
602 rte_cryptodev_queue_pair_count(uint8_t dev_id);
606 * Retrieve the general I/O statistics of a device.
608 * @param dev_id The identifier of the device.
609 * @param stats A pointer to a structure of type
610 * *rte_cryptodev_stats* to be filled with the
611 * values of device counters.
613 * - Zero if successful.
614 * - Non-zero otherwise.
617 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
620 * Reset the general I/O statistics of a device.
622 * @param dev_id The identifier of the device.
625 rte_cryptodev_stats_reset(uint8_t dev_id);
628 * Retrieve the contextual information of a device.
630 * @param dev_id The identifier of the device.
631 * @param dev_info A pointer to a structure of type
632 * *rte_cryptodev_info* to be filled with the
633 * contextual information of the device.
635 * @note The capabilities field of dev_info is set to point to the first
636 * element of an array of struct rte_cryptodev_capabilities. The element after
637 * the last valid element has it's op field set to
638 * RTE_CRYPTO_OP_TYPE_UNDEFINED.
641 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
645 * Register a callback function for specific device id.
647 * @param dev_id Device id.
648 * @param event Event interested.
649 * @param cb_fn User supplied callback function to be called.
650 * @param cb_arg Pointer to the parameters for the registered
654 * - On success, zero.
655 * - On failure, a negative value.
658 rte_cryptodev_callback_register(uint8_t dev_id,
659 enum rte_cryptodev_event_type event,
660 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
663 * Unregister a callback function for specific device id.
665 * @param dev_id The device identifier.
666 * @param event Event interested.
667 * @param cb_fn User supplied callback function to be called.
668 * @param cb_arg Pointer to the parameters for the registered
672 * - On success, zero.
673 * - On failure, a negative value.
676 rte_cryptodev_callback_unregister(uint8_t dev_id,
677 enum rte_cryptodev_event_type event,
678 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
681 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
682 struct rte_crypto_op **ops, uint16_t nb_ops);
683 /**< Dequeue processed packets from queue pair of a device. */
685 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
686 struct rte_crypto_op **ops, uint16_t nb_ops);
687 /**< Enqueue packets for processing on queue pair of a device. */
692 struct rte_cryptodev_callback;
694 /** Structure to keep track of registered callbacks */
695 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
697 /** The data structure associated with each crypto device. */
698 struct rte_cryptodev {
699 dequeue_pkt_burst_t dequeue_burst;
700 /**< Pointer to PMD receive function. */
701 enqueue_pkt_burst_t enqueue_burst;
702 /**< Pointer to PMD transmit function. */
704 struct rte_cryptodev_data *data;
705 /**< Pointer to device data */
706 struct rte_cryptodev_ops *dev_ops;
707 /**< Functions exported by PMD */
708 uint64_t feature_flags;
709 /**< Feature flags exposes HW/SW features for the given device */
710 struct rte_device *device;
711 /**< Backing device */
714 /**< Crypto driver identifier*/
716 struct rte_cryptodev_cb_list link_intr_cbs;
717 /**< User application callback for interrupts if present */
720 /**< Context for security ops */
723 uint8_t attached : 1;
724 /**< Flag indicating the device is attached */
725 } __rte_cache_aligned;
728 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
732 * The data part, with no function pointers, associated with each device.
734 * This structure is safe to place in shared memory to be common among
735 * different processes in a multi-process configuration.
737 struct rte_cryptodev_data {
739 /**< Device ID for this instance */
741 /**< Socket ID where memory is allocated */
742 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
743 /**< Unique identifier name */
746 uint8_t dev_started : 1;
747 /**< Device state: STARTED(1)/STOPPED(0) */
749 struct rte_mempool *session_pool;
750 /**< Session memory pool */
752 /**< Array of pointers to queue pairs. */
753 uint16_t nb_queue_pairs;
754 /**< Number of device queue pairs. */
757 /**< PMD-specific private data */
758 } __rte_cache_aligned;
760 extern struct rte_cryptodev *rte_cryptodevs;
763 * Dequeue a burst of processed crypto operations from a queue on the crypto
764 * device. The dequeued operation are stored in *rte_crypto_op* structures
765 * whose pointers are supplied in the *ops* array.
767 * The rte_cryptodev_dequeue_burst() function returns the number of ops
768 * actually dequeued, which is the number of *rte_crypto_op* data structures
769 * effectively supplied into the *ops* array.
771 * A return value equal to *nb_ops* indicates that the queue contained
772 * at least *nb_ops* operations, and this is likely to signify that other
773 * processed operations remain in the devices output queue. Applications
774 * implementing a "retrieve as many processed operations as possible" policy
775 * can check this specific case and keep invoking the
776 * rte_cryptodev_dequeue_burst() function until a value less than
777 * *nb_ops* is returned.
779 * The rte_cryptodev_dequeue_burst() function does not provide any error
780 * notification to avoid the corresponding overhead.
782 * @param dev_id The symmetric crypto device identifier
783 * @param qp_id The index of the queue pair from which to
784 * retrieve processed packets. The value must be
785 * in the range [0, nb_queue_pair - 1] previously
786 * supplied to rte_cryptodev_configure().
787 * @param ops The address of an array of pointers to
788 * *rte_crypto_op* structures that must be
789 * large enough to store *nb_ops* pointers in it.
790 * @param nb_ops The maximum number of operations to dequeue.
793 * - The number of operations actually dequeued, which is the number
794 * of pointers to *rte_crypto_op* structures effectively supplied to the
797 static inline uint16_t
798 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
799 struct rte_crypto_op **ops, uint16_t nb_ops)
801 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
803 nb_ops = (*dev->dequeue_burst)
804 (dev->data->queue_pairs[qp_id], ops, nb_ops);
810 * Enqueue a burst of operations for processing on a crypto device.
812 * The rte_cryptodev_enqueue_burst() function is invoked to place
813 * crypto operations on the queue *qp_id* of the device designated by
816 * The *nb_ops* parameter is the number of operations to process which are
817 * supplied in the *ops* array of *rte_crypto_op* structures.
819 * The rte_cryptodev_enqueue_burst() function returns the number of
820 * operations it actually enqueued for processing. A return value equal to
821 * *nb_ops* means that all packets have been enqueued.
823 * @param dev_id The identifier of the device.
824 * @param qp_id The index of the queue pair which packets are
825 * to be enqueued for processing. The value
826 * must be in the range [0, nb_queue_pairs - 1]
827 * previously supplied to
828 * *rte_cryptodev_configure*.
829 * @param ops The address of an array of *nb_ops* pointers
830 * to *rte_crypto_op* structures which contain
831 * the crypto operations to be processed.
832 * @param nb_ops The number of operations to process.
835 * The number of operations actually enqueued on the crypto device. The return
836 * value can be less than the value of the *nb_ops* parameter when the
837 * crypto devices queue is full or if invalid parameters are specified in
840 static inline uint16_t
841 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
842 struct rte_crypto_op **ops, uint16_t nb_ops)
844 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
846 return (*dev->enqueue_burst)(
847 dev->data->queue_pairs[qp_id], ops, nb_ops);
851 /** Cryptodev symmetric crypto session
852 * Each session is derived from a fixed xform chain. Therefore each session
853 * has a fixed algo, key, op-type, digest_len etc.
855 struct rte_cryptodev_sym_session {
856 __extension__ void *sess_private_data[0];
857 /**< Private session material */
862 * Create symmetric crypto session header (generic with no private data)
864 * @param mempool Symmetric session mempool to allocate session
867 * - On success return pointer to sym-session
868 * - On failure returns NULL
870 struct rte_cryptodev_sym_session *
871 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
874 * Frees symmetric crypto session header, after checking that all
875 * the device private data has been freed, returning it
876 * to its original mempool.
878 * @param sess Session header to be freed.
882 * - -EINVAL if session is NULL.
883 * - -EBUSY if not all device private data has been freed.
886 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
889 * Fill out private data for the device id, based on its device type.
891 * @param dev_id ID of device that we want the session to be used on
892 * @param sess Session where the private data will be attached to
893 * @param xforms Symmetric crypto transform operations to apply on flow
894 * processed with this session
895 * @param mempool Mempool where the private data is allocated.
898 * - On success, zero.
899 * - -EINVAL if input parameters are invalid.
900 * - -ENOTSUP if crypto device does not support the crypto transform or
901 * does not support symmetric operations.
902 * - -ENOMEM if the private session could not be allocated.
905 rte_cryptodev_sym_session_init(uint8_t dev_id,
906 struct rte_cryptodev_sym_session *sess,
907 struct rte_crypto_sym_xform *xforms,
908 struct rte_mempool *mempool);
911 * Frees private data for the device id, based on its device type,
912 * returning it to its mempool. It is the application's responsibility
913 * to ensure that private session data is not cleared while there are
914 * still in-flight operations using it.
916 * @param dev_id ID of device that uses the session.
917 * @param sess Session containing the reference to the private data
921 * - -EINVAL if device is invalid or session is NULL.
922 * - -ENOTSUP if crypto device does not support symmetric operations.
925 rte_cryptodev_sym_session_clear(uint8_t dev_id,
926 struct rte_cryptodev_sym_session *sess);
929 * Get the size of the header session, for all registered drivers.
932 * Size of the symmetric eader session.
935 rte_cryptodev_sym_get_header_session_size(void);
938 * Get the size of the private symmetric session data
941 * @param dev_id The device identifier.
944 * - Size of the private data, if successful
945 * - 0 if device is invalid or does not have private
949 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
952 * Provide driver identifier.
955 * The pointer to a driver name.
957 * The driver type identifier or -1 if no driver found
959 int rte_cryptodev_driver_id_get(const char *name);
962 * Provide driver name.
965 * The driver identifier.
967 * The driver name or null if no driver found
969 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
972 * Store user data in a session.
974 * @param sess Session pointer allocated by
975 * *rte_cryptodev_sym_session_create*.
976 * @param data Pointer to the user data.
977 * @param size Size of the user data.
980 * - On success, zero.
981 * - On failure, a negative value.
983 int __rte_experimental
984 rte_cryptodev_sym_session_set_user_data(
985 struct rte_cryptodev_sym_session *sess,
990 * Get user data stored in a session.
992 * @param sess Session pointer allocated by
993 * *rte_cryptodev_sym_session_create*.
996 * - On success return pointer to user data.
997 * - On failure returns NULL.
999 void * __rte_experimental
1000 rte_cryptodev_sym_session_get_user_data(
1001 struct rte_cryptodev_sym_session *sess);
1007 #endif /* _RTE_CRYPTODEV_H_ */