3 * Copyright(c) 2015-2017 Intel Corporation. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
15 * * Neither the name of Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _RTE_CRYPTODEV_H_
33 #define _RTE_CRYPTODEV_H_
36 * @file rte_cryptodev.h
38 * RTE Cryptographic Device APIs
40 * Defines RTE Crypto Device APIs for the provisioning of cipher and
41 * authentication operations.
48 #include "rte_kvargs.h"
49 #include "rte_crypto.h"
51 #include <rte_common.h>
53 extern const char **rte_cyptodev_names;
57 #define CDEV_LOG_ERR(...) \
58 RTE_LOG(ERR, CRYPTODEV, \
59 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
60 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
62 #define CDEV_PMD_LOG_ERR(dev, ...) \
63 RTE_LOG(ERR, CRYPTODEV, \
64 RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
65 dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
67 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
68 #define CDEV_LOG_DEBUG(...) \
69 RTE_LOG(DEBUG, CRYPTODEV, \
70 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
71 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
73 #define CDEV_PMD_TRACE(...) \
74 RTE_LOG(DEBUG, CRYPTODEV, \
75 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
76 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
79 #define CDEV_LOG_DEBUG(...) (void)0
80 #define CDEV_PMD_TRACE(...) (void)0
86 * A macro that points to an offset from the start
87 * of the crypto operation structure (rte_crypto_op)
89 * The returned pointer is cast to type t.
92 * The crypto operation.
94 * The offset from the start of the crypto operation.
96 * The type to cast the result into.
98 #define rte_crypto_op_ctod_offset(c, t, o) \
99 ((t)((char *)(c) + (o)))
102 * A macro that returns the physical address that points
103 * to an offset from the start of the crypto operation
107 * The crypto operation.
109 * The offset from the start of the crypto operation
110 * to calculate address from.
112 #define rte_crypto_op_ctophys_offset(c, o) \
113 (phys_addr_t)((c)->phys_addr + (o))
116 * Crypto parameters range description
118 struct rte_crypto_param_range {
119 uint16_t min; /**< minimum size */
120 uint16_t max; /**< maximum size */
122 /**< if a range of sizes are supported,
123 * this parameter is used to indicate
124 * increments in byte size that are supported
125 * between the minimum and maximum
130 * Symmetric Crypto Capability
132 struct rte_cryptodev_symmetric_capability {
133 enum rte_crypto_sym_xform_type xform_type;
134 /**< Transform type : Authentication / Cipher / AEAD */
138 enum rte_crypto_auth_algorithm algo;
139 /**< authentication algorithm */
141 /**< algorithm block size */
142 struct rte_crypto_param_range key_size;
143 /**< auth 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 */
151 /**< Symmetric Authentication transform capabilities */
153 enum rte_crypto_cipher_algorithm algo;
154 /**< cipher algorithm */
156 /**< algorithm block size */
157 struct rte_crypto_param_range key_size;
158 /**< cipher key size range */
159 struct rte_crypto_param_range iv_size;
160 /**< Initialisation vector data size range */
162 /**< Symmetric Cipher transform capabilities */
164 enum rte_crypto_aead_algorithm algo;
165 /**< AEAD algorithm */
167 /**< algorithm block size */
168 struct rte_crypto_param_range key_size;
169 /**< AEAD key size range */
170 struct rte_crypto_param_range digest_size;
171 /**< digest size range */
172 struct rte_crypto_param_range aad_size;
173 /**< Additional authentication data size range */
174 struct rte_crypto_param_range iv_size;
175 /**< Initialisation vector data size range */
180 /** Structure used to capture a capability of a crypto device */
181 struct rte_cryptodev_capabilities {
182 enum rte_crypto_op_type op;
183 /**< Operation type */
187 struct rte_cryptodev_symmetric_capability sym;
188 /**< Symmetric operation capability parameters */
192 /** Structure used to describe crypto algorithms */
193 struct rte_cryptodev_sym_capability_idx {
194 enum rte_crypto_sym_xform_type type;
196 enum rte_crypto_cipher_algorithm cipher;
197 enum rte_crypto_auth_algorithm auth;
198 enum rte_crypto_aead_algorithm aead;
203 * Provide capabilities available for defined device and algorithm
205 * @param dev_id The identifier of the device.
206 * @param idx Description of crypto algorithms.
209 * - Return description of the symmetric crypto capability if exist.
210 * - Return NULL if the capability not exist.
212 const struct rte_cryptodev_symmetric_capability *
213 rte_cryptodev_sym_capability_get(uint8_t dev_id,
214 const struct rte_cryptodev_sym_capability_idx *idx);
217 * Check if key size and initial vector are supported
218 * in crypto cipher capability
220 * @param capability Description of the symmetric crypto capability.
221 * @param key_size Cipher key size.
222 * @param iv_size Cipher initial vector size.
225 * - Return 0 if the parameters are in range of the capability.
226 * - Return -1 if the parameters are out of range of the capability.
229 rte_cryptodev_sym_capability_check_cipher(
230 const struct rte_cryptodev_symmetric_capability *capability,
231 uint16_t key_size, uint16_t iv_size);
234 * Check if key size and initial vector are supported
235 * in crypto auth capability
237 * @param capability Description of the symmetric crypto capability.
238 * @param key_size Auth key size.
239 * @param digest_size Auth digest size.
240 * @param iv_size Auth initial vector size.
243 * - Return 0 if the parameters are in range of the capability.
244 * - Return -1 if the parameters are out of range of the capability.
247 rte_cryptodev_sym_capability_check_auth(
248 const struct rte_cryptodev_symmetric_capability *capability,
249 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
252 * Check if key, digest, AAD and initial vector sizes are supported
253 * in crypto AEAD capability
255 * @param capability Description of the symmetric crypto capability.
256 * @param key_size AEAD key size.
257 * @param digest_size AEAD digest size.
258 * @param aad_size AEAD AAD size.
259 * @param iv_size AEAD IV size.
262 * - Return 0 if the parameters are in range of the capability.
263 * - Return -1 if the parameters are out of range of the capability.
266 rte_cryptodev_sym_capability_check_aead(
267 const struct rte_cryptodev_symmetric_capability *capability,
268 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
272 * Provide the cipher algorithm enum, given an algorithm string
274 * @param algo_enum A pointer to the cipher algorithm
276 * @param algo_string Authentication algo string
279 * - Return -1 if string is not valid
280 * - Return 0 is the string is valid
283 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
284 const char *algo_string);
287 * Provide the authentication algorithm enum, given an algorithm string
289 * @param algo_enum A pointer to the authentication algorithm
291 * @param algo_string Authentication algo string
294 * - Return -1 if string is not valid
295 * - Return 0 is the string is valid
298 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
299 const char *algo_string);
302 * Provide the AEAD algorithm enum, given an algorithm string
304 * @param algo_enum A pointer to the AEAD algorithm
306 * @param algo_string AEAD algorithm string
309 * - Return -1 if string is not valid
310 * - Return 0 is the string is valid
313 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
314 const char *algo_string);
316 /** Macro used at end of crypto PMD list */
317 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
318 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
322 * Crypto device supported feature flags
325 * New features flags should be added to the end of the list
327 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
329 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
330 /**< Symmetric crypto operations are supported */
331 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
332 /**< Asymmetric crypto operations are supported */
333 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
334 /**< Chaining symmetric crypto operations are supported */
335 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
336 /**< Utilises CPU SIMD SSE instructions */
337 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
338 /**< Utilises CPU SIMD AVX instructions */
339 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
340 /**< Utilises CPU SIMD AVX2 instructions */
341 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
342 /**< Utilises CPU AES-NI instructions */
343 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
344 /**< Operations are off-loaded to an external hardware accelerator */
345 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
346 /**< Utilises CPU SIMD AVX512 instructions */
347 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
348 /**< Scatter-gather mbufs are supported */
349 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
350 /**< Utilises CPU NEON instructions */
351 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
352 /**< Utilises ARM CPU Cryptographic Extensions */
356 * Get the name of a crypto device feature flag
358 * @param flag The mask describing the flag.
361 * The name of this flag, or NULL if it's not a valid feature flag.
365 rte_cryptodev_get_feature_name(uint64_t flag);
367 /** Crypto device information */
368 struct rte_cryptodev_info {
369 const char *driver_name; /**< Driver name. */
370 uint8_t driver_id; /**< Driver identifier */
371 struct rte_pci_device *pci_dev; /**< PCI information. */
373 uint64_t feature_flags; /**< Feature flags */
375 const struct rte_cryptodev_capabilities *capabilities;
376 /**< Array of devices supported capabilities */
378 unsigned max_nb_queue_pairs;
379 /**< Maximum number of queues pairs supported by device. */
382 unsigned max_nb_sessions;
383 /**< Maximum number of sessions supported by device. */
384 unsigned int max_nb_sessions_per_qp;
385 /**< Maximum number of sessions per queue pair.
386 * Default 0 for infinite sessions
391 #define RTE_CRYPTODEV_DETACHED (0)
392 #define RTE_CRYPTODEV_ATTACHED (1)
394 /** Definitions of Crypto device event types */
395 enum rte_cryptodev_event_type {
396 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
397 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
398 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
401 /** Crypto device queue pair configuration structure. */
402 struct rte_cryptodev_qp_conf {
403 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
407 * Typedef for application callback function to be registered by application
408 * software for notification of device events
410 * @param dev_id Crypto device identifier
411 * @param event Crypto device event to register for notification of.
412 * @param cb_arg User specified parameter to be passed as to passed to
413 * users callback function.
415 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
416 enum rte_cryptodev_event_type event, void *cb_arg);
419 /** Crypto Device statistics */
420 struct rte_cryptodev_stats {
421 uint64_t enqueued_count;
422 /**< Count of all operations enqueued */
423 uint64_t dequeued_count;
424 /**< Count of all operations dequeued */
426 uint64_t enqueue_err_count;
427 /**< Total error count on operations enqueued */
428 uint64_t dequeue_err_count;
429 /**< Total error count on operations dequeued */
432 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
433 /**< Max length of name of crypto PMD */
438 * Create a virtual crypto device
440 * @param name Cryptodev PMD name of device to be created.
441 * @param args Options arguments for device.
444 * - On successful creation of the cryptodev the device index is returned,
445 * which will be between 0 and rte_cryptodev_count().
446 * - In the case of a failure, returns -1.
450 rte_cryptodev_create_vdev(const char *name, const char *args);
453 * Get the device identifier for the named crypto device.
455 * @param name device name to select the device structure.
458 * - Returns crypto device identifier on success.
459 * - Return -1 on failure to find named crypto device.
462 rte_cryptodev_get_dev_id(const char *name);
465 * Get the crypto device name given a device identifier.
468 * The identifier of the device
471 * - Returns crypto device name.
472 * - Returns NULL if crypto device is not present.
475 rte_cryptodev_name_get(uint8_t dev_id);
478 * Get the total number of crypto devices that have been successfully
482 * - The total number of usable crypto devices.
485 rte_cryptodev_count(void);
488 * Get number of crypto device defined type.
490 * @param driver_id driver identifier.
493 * Returns number of crypto device.
496 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
499 * Get number and identifiers of attached crypto devices that
500 * use the same crypto driver.
502 * @param driver_name driver name.
503 * @param devices output devices identifiers.
504 * @param nb_devices maximal number of devices.
507 * Returns number of attached crypto device.
510 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
513 * Return the NUMA socket to which a device is connected
516 * The identifier of the device
518 * The NUMA socket id to which the device is connected or
519 * a default of zero if the socket could not be determined.
520 * -1 if returned is the dev_id value is out of range.
523 rte_cryptodev_socket_id(uint8_t dev_id);
525 /** Crypto device configuration structure */
526 struct rte_cryptodev_config {
527 int socket_id; /**< Socket to allocate resources on */
528 uint16_t nb_queue_pairs;
529 /**< Number of queue pairs to configure on device */
533 * Configure a device.
535 * This function must be invoked first before any other function in the
536 * API. This function can also be re-invoked when a device is in the
539 * @param dev_id The identifier of the device to configure.
540 * @param config The crypto device configuration structure.
543 * - 0: Success, device configured.
544 * - <0: Error code returned by the driver configuration function.
547 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
552 * The device start step is the last one and consists of setting the configured
553 * offload features and in starting the transmit and the receive units of the
555 * On success, all basic functions exported by the API (link status,
556 * receive/transmit, and so on) can be invoked.
559 * The identifier of the device.
561 * - 0: Success, device started.
562 * - <0: Error code of the driver device start function.
565 rte_cryptodev_start(uint8_t dev_id);
568 * Stop an device. The device can be restarted with a call to
569 * rte_cryptodev_start()
571 * @param dev_id The identifier of the device.
574 rte_cryptodev_stop(uint8_t dev_id);
577 * Close an device. The device cannot be restarted!
579 * @param dev_id The identifier of the device.
582 * - 0 on successfully closing device
583 * - <0 on failure to close device
586 rte_cryptodev_close(uint8_t dev_id);
589 * Allocate and set up a receive queue pair for a device.
592 * @param dev_id The identifier of the device.
593 * @param queue_pair_id The index of the queue pairs to set up. The
594 * value must be in the range [0, nb_queue_pair
595 * - 1] previously supplied to
596 * rte_cryptodev_configure().
597 * @param qp_conf The pointer to the configuration data to be
598 * used for the queue pair. NULL value is
599 * allowed, in which case default configuration
601 * @param socket_id The *socket_id* argument is the socket
602 * identifier in case of NUMA. The value can be
603 * *SOCKET_ID_ANY* if there is no NUMA constraint
604 * for the DMA memory allocated for the receive
606 * @param session_pool Pointer to device session mempool, used
607 * for session-less operations.
610 * - 0: Success, queue pair correctly set up.
611 * - <0: Queue pair configuration failed
614 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
615 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
616 struct rte_mempool *session_pool);
619 * Start a specified queue pair of a device. It is used
620 * when deferred_start flag of the specified queue is true.
622 * @param dev_id The identifier of the device
623 * @param queue_pair_id The index of the queue pair to start. The value
624 * must be in the range [0, nb_queue_pair - 1]
625 * previously supplied to
626 * rte_crypto_dev_configure().
628 * - 0: Success, the transmit queue is correctly set up.
629 * - -EINVAL: The dev_id or the queue_id out of range.
630 * - -ENOTSUP: The function not supported in PMD driver.
633 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
636 * Stop specified queue pair of a device
638 * @param dev_id The identifier of the device
639 * @param queue_pair_id The index of the queue pair to stop. The value
640 * must be in the range [0, nb_queue_pair - 1]
641 * previously supplied to
642 * rte_cryptodev_configure().
644 * - 0: Success, the transmit queue is correctly set up.
645 * - -EINVAL: The dev_id or the queue_id out of range.
646 * - -ENOTSUP: The function not supported in PMD driver.
649 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
652 * Get the number of queue pairs on a specific crypto device
654 * @param dev_id Crypto device identifier.
656 * - The number of configured queue pairs.
659 rte_cryptodev_queue_pair_count(uint8_t dev_id);
663 * Retrieve the general I/O statistics of a device.
665 * @param dev_id The identifier of the device.
666 * @param stats A pointer to a structure of type
667 * *rte_cryptodev_stats* to be filled with the
668 * values of device counters.
670 * - Zero if successful.
671 * - Non-zero otherwise.
674 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
677 * Reset the general I/O statistics of a device.
679 * @param dev_id The identifier of the device.
682 rte_cryptodev_stats_reset(uint8_t dev_id);
685 * Retrieve the contextual information of a device.
687 * @param dev_id The identifier of the device.
688 * @param dev_info A pointer to a structure of type
689 * *rte_cryptodev_info* to be filled with the
690 * contextual information of the device.
693 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
697 * Register a callback function for specific device id.
699 * @param dev_id Device id.
700 * @param event Event interested.
701 * @param cb_fn User supplied callback function to be called.
702 * @param cb_arg Pointer to the parameters for the registered
706 * - On success, zero.
707 * - On failure, a negative value.
710 rte_cryptodev_callback_register(uint8_t dev_id,
711 enum rte_cryptodev_event_type event,
712 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
715 * Unregister a callback function for specific device id.
717 * @param dev_id The device identifier.
718 * @param event Event interested.
719 * @param cb_fn User supplied callback function to be called.
720 * @param cb_arg Pointer to the parameters for the registered
724 * - On success, zero.
725 * - On failure, a negative value.
728 rte_cryptodev_callback_unregister(uint8_t dev_id,
729 enum rte_cryptodev_event_type event,
730 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
733 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
734 struct rte_crypto_op **ops, uint16_t nb_ops);
735 /**< Dequeue processed packets from queue pair of a device. */
737 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
738 struct rte_crypto_op **ops, uint16_t nb_ops);
739 /**< Enqueue packets for processing on queue pair of a device. */
744 struct rte_cryptodev_callback;
746 /** Structure to keep track of registered callbacks */
747 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
749 /** The data structure associated with each crypto device. */
750 struct rte_cryptodev {
751 dequeue_pkt_burst_t dequeue_burst;
752 /**< Pointer to PMD receive function. */
753 enqueue_pkt_burst_t enqueue_burst;
754 /**< Pointer to PMD transmit function. */
756 struct rte_cryptodev_data *data;
757 /**< Pointer to device data */
758 struct rte_cryptodev_ops *dev_ops;
759 /**< Functions exported by PMD */
760 uint64_t feature_flags;
761 /**< Supported features */
762 struct rte_device *device;
763 /**< Backing device */
766 /**< Crypto driver identifier*/
768 struct rte_cryptodev_cb_list link_intr_cbs;
769 /**< User application callback for interrupts if present */
772 uint8_t attached : 1;
773 /**< Flag indicating the device is attached */
774 } __rte_cache_aligned;
778 * The data part, with no function pointers, associated with each device.
780 * This structure is safe to place in shared memory to be common among
781 * different processes in a multi-process configuration.
783 struct rte_cryptodev_data {
785 /**< Device ID for this instance */
787 /**< Socket ID where memory is allocated */
788 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
789 /**< Unique identifier name */
792 uint8_t dev_started : 1;
793 /**< Device state: STARTED(1)/STOPPED(0) */
795 struct rte_mempool *session_pool;
796 /**< Session memory pool */
798 /**< Array of pointers to queue pairs. */
799 uint16_t nb_queue_pairs;
800 /**< Number of device queue pairs. */
803 /**< PMD-specific private data */
804 } __rte_cache_aligned;
806 extern struct rte_cryptodev *rte_cryptodevs;
809 * Dequeue a burst of processed crypto operations from a queue on the crypto
810 * device. The dequeued operation are stored in *rte_crypto_op* structures
811 * whose pointers are supplied in the *ops* array.
813 * The rte_cryptodev_dequeue_burst() function returns the number of ops
814 * actually dequeued, which is the number of *rte_crypto_op* data structures
815 * effectively supplied into the *ops* array.
817 * A return value equal to *nb_ops* indicates that the queue contained
818 * at least *nb_ops* operations, and this is likely to signify that other
819 * processed operations remain in the devices output queue. Applications
820 * implementing a "retrieve as many processed operations as possible" policy
821 * can check this specific case and keep invoking the
822 * rte_cryptodev_dequeue_burst() function until a value less than
823 * *nb_ops* is returned.
825 * The rte_cryptodev_dequeue_burst() function does not provide any error
826 * notification to avoid the corresponding overhead.
828 * @param dev_id The symmetric crypto device identifier
829 * @param qp_id The index of the queue pair from which to
830 * retrieve processed packets. The value must be
831 * in the range [0, nb_queue_pair - 1] previously
832 * supplied to rte_cryptodev_configure().
833 * @param ops The address of an array of pointers to
834 * *rte_crypto_op* structures that must be
835 * large enough to store *nb_ops* pointers in it.
836 * @param nb_ops The maximum number of operations to dequeue.
839 * - The number of operations actually dequeued, which is the number
840 * of pointers to *rte_crypto_op* structures effectively supplied to the
843 static inline uint16_t
844 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
845 struct rte_crypto_op **ops, uint16_t nb_ops)
847 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
849 nb_ops = (*dev->dequeue_burst)
850 (dev->data->queue_pairs[qp_id], ops, nb_ops);
856 * Enqueue a burst of operations for processing on a crypto device.
858 * The rte_cryptodev_enqueue_burst() function is invoked to place
859 * crypto operations on the queue *qp_id* of the device designated by
862 * The *nb_ops* parameter is the number of operations to process which are
863 * supplied in the *ops* array of *rte_crypto_op* structures.
865 * The rte_cryptodev_enqueue_burst() function returns the number of
866 * operations it actually enqueued for processing. A return value equal to
867 * *nb_ops* means that all packets have been enqueued.
869 * @param dev_id The identifier of the device.
870 * @param qp_id The index of the queue pair which packets are
871 * to be enqueued for processing. The value
872 * must be in the range [0, nb_queue_pairs - 1]
873 * previously supplied to
874 * *rte_cryptodev_configure*.
875 * @param ops The address of an array of *nb_ops* pointers
876 * to *rte_crypto_op* structures which contain
877 * the crypto operations to be processed.
878 * @param nb_ops The number of operations to process.
881 * The number of operations actually enqueued on the crypto device. The return
882 * value can be less than the value of the *nb_ops* parameter when the
883 * crypto devices queue is full or if invalid parameters are specified in
886 static inline uint16_t
887 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
888 struct rte_crypto_op **ops, uint16_t nb_ops)
890 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
892 return (*dev->enqueue_burst)(
893 dev->data->queue_pairs[qp_id], ops, nb_ops);
897 /** Cryptodev symmetric crypto session */
898 struct rte_cryptodev_sym_session {
899 __extension__ void *sess_private_data[0];
900 /**< Private session material */
905 * Create symmetric crypto session header (generic with no private data)
907 * @param mempool Symmetric session mempool to allocate session
910 * - On success return pointer to sym-session
911 * - On failure returns NULL
913 struct rte_cryptodev_sym_session *
914 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
917 * Frees symmetric crypto session header, after checking that all
918 * the device private data has been freed, returning it
919 * to its original mempool.
921 * @param sess Session header to be freed.
925 * - -EINVAL if session is NULL.
926 * - -EBUSY if not all device private data has been freed.
929 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
932 * Fill out private data for the device id, based on its device type.
934 * @param dev_id ID of device that we want the session to be used on
935 * @param sess Session where the private data will be attached to
936 * @param xforms Symmetric crypto transform operations to apply on flow
937 * processed with this session
938 * @param mempool Mempool where the private data is allocated.
941 * - On success, zero.
942 * - -EINVAL if input parameters are invalid.
943 * - -ENOTSUP if crypto device does not support the crypto transform.
944 * - -ENOMEM if the private session could not be allocated.
947 rte_cryptodev_sym_session_init(uint8_t dev_id,
948 struct rte_cryptodev_sym_session *sess,
949 struct rte_crypto_sym_xform *xforms,
950 struct rte_mempool *mempool);
953 * Frees private data for the device id, based on its device type,
954 * returning it to its mempool.
956 * @param dev_id ID of device that uses the session.
957 * @param sess Session containing the reference to the private data
961 * - -EINVAL if device is invalid or session is NULL.
964 rte_cryptodev_sym_session_clear(uint8_t dev_id,
965 struct rte_cryptodev_sym_session *sess);
968 * Get the size of the header session, for all registered drivers.
971 * Size of the header session.
974 rte_cryptodev_get_header_session_size(void);
977 * Get the size of the private session data for a device.
979 * @param dev_id The device identifier.
982 * - Size of the private data, if successful
983 * - 0 if device is invalid or does not have private session
986 rte_cryptodev_get_private_session_size(uint8_t dev_id);
989 * Attach queue pair with sym session.
991 * @param dev_id Device to which the session will be attached.
992 * @param qp_id Queue pair to which the session will be attached.
993 * @param session Session pointer previously allocated by
994 * *rte_cryptodev_sym_session_create*.
997 * - On success, zero.
998 * - On failure, a negative value.
1001 rte_cryptodev_queue_pair_attach_sym_session(uint8_t dev_id, uint16_t qp_id,
1002 struct rte_cryptodev_sym_session *session);
1005 * Detach queue pair with sym session.
1007 * @param dev_id Device to which the session is attached.
1008 * @param qp_id Queue pair to which the session is attached.
1009 * @param session Session pointer previously allocated by
1010 * *rte_cryptodev_sym_session_create*.
1013 * - On success, zero.
1014 * - On failure, a negative value.
1017 rte_cryptodev_queue_pair_detach_sym_session(uint8_t dev_id, uint16_t qp_id,
1018 struct rte_cryptodev_sym_session *session);
1021 * Provide driver identifier.
1024 * The pointer to a driver name.
1026 * The driver type identifier or -1 if no driver found
1028 int rte_cryptodev_driver_id_get(const char *name);
1031 * Provide driver name.
1034 * The driver identifier.
1036 * The driver name or null if no driver found
1038 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1044 #endif /* _RTE_CRYPTODEV_H_ */