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>
52 #include <rte_config.h>
54 extern const char **rte_cyptodev_names;
58 #define CDEV_LOG_ERR(...) \
59 RTE_LOG(ERR, CRYPTODEV, \
60 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
61 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
63 #define CDEV_LOG_INFO(...) \
64 RTE_LOG(INFO, CRYPTODEV, \
65 RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
66 RTE_FMT_TAIL(__VA_ARGS__,)))
68 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
69 #define CDEV_LOG_DEBUG(...) \
70 RTE_LOG(DEBUG, CRYPTODEV, \
71 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
72 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
74 #define CDEV_PMD_TRACE(...) \
75 RTE_LOG(DEBUG, CRYPTODEV, \
76 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
77 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
80 #define CDEV_LOG_DEBUG(...) (void)0
81 #define CDEV_PMD_TRACE(...) (void)0
87 * A macro that points to an offset from the start
88 * of the crypto operation structure (rte_crypto_op)
90 * The returned pointer is cast to type t.
93 * The crypto operation.
95 * The offset from the start of the crypto operation.
97 * The type to cast the result into.
99 #define rte_crypto_op_ctod_offset(c, t, o) \
100 ((t)((char *)(c) + (o)))
103 * A macro that returns the physical address that points
104 * to an offset from the start of the crypto operation
108 * The crypto operation.
110 * The offset from the start of the crypto operation
111 * to calculate address from.
113 #define rte_crypto_op_ctophys_offset(c, o) \
114 (rte_iova_t)((c)->phys_addr + (o))
117 * Crypto parameters range description
119 struct rte_crypto_param_range {
120 uint16_t min; /**< minimum size */
121 uint16_t max; /**< maximum size */
123 /**< if a range of sizes are supported,
124 * this parameter is used to indicate
125 * increments in byte size that are supported
126 * between the minimum and maximum
131 * Symmetric Crypto Capability
133 struct rte_cryptodev_symmetric_capability {
134 enum rte_crypto_sym_xform_type xform_type;
135 /**< Transform type : Authentication / Cipher / AEAD */
139 enum rte_crypto_auth_algorithm algo;
140 /**< authentication algorithm */
142 /**< algorithm block size */
143 struct rte_crypto_param_range key_size;
144 /**< auth key size range */
145 struct rte_crypto_param_range digest_size;
146 /**< digest size range */
147 struct rte_crypto_param_range aad_size;
148 /**< Additional authentication data size range */
149 struct rte_crypto_param_range iv_size;
150 /**< Initialisation vector data size range */
152 /**< Symmetric Authentication transform capabilities */
154 enum rte_crypto_cipher_algorithm algo;
155 /**< cipher algorithm */
157 /**< algorithm block size */
158 struct rte_crypto_param_range key_size;
159 /**< cipher key size range */
160 struct rte_crypto_param_range iv_size;
161 /**< Initialisation vector data size range */
163 /**< Symmetric Cipher transform capabilities */
165 enum rte_crypto_aead_algorithm algo;
166 /**< AEAD algorithm */
168 /**< algorithm block size */
169 struct rte_crypto_param_range key_size;
170 /**< AEAD key size range */
171 struct rte_crypto_param_range digest_size;
172 /**< digest size range */
173 struct rte_crypto_param_range aad_size;
174 /**< Additional authentication data size range */
175 struct rte_crypto_param_range iv_size;
176 /**< Initialisation vector data size range */
181 /** Structure used to capture a capability of a crypto device */
182 struct rte_cryptodev_capabilities {
183 enum rte_crypto_op_type op;
184 /**< Operation type */
188 struct rte_cryptodev_symmetric_capability sym;
189 /**< Symmetric operation capability parameters */
193 /** Structure used to describe crypto algorithms */
194 struct rte_cryptodev_sym_capability_idx {
195 enum rte_crypto_sym_xform_type type;
197 enum rte_crypto_cipher_algorithm cipher;
198 enum rte_crypto_auth_algorithm auth;
199 enum rte_crypto_aead_algorithm aead;
204 * Provide capabilities available for defined device and algorithm
206 * @param dev_id The identifier of the device.
207 * @param idx Description of crypto algorithms.
210 * - Return description of the symmetric crypto capability if exist.
211 * - Return NULL if the capability not exist.
213 const struct rte_cryptodev_symmetric_capability *
214 rte_cryptodev_sym_capability_get(uint8_t dev_id,
215 const struct rte_cryptodev_sym_capability_idx *idx);
218 * Check if key size and initial vector are supported
219 * in crypto cipher capability
221 * @param capability Description of the symmetric crypto capability.
222 * @param key_size Cipher key size.
223 * @param iv_size Cipher initial vector size.
226 * - Return 0 if the parameters are in range of the capability.
227 * - Return -1 if the parameters are out of range of the capability.
230 rte_cryptodev_sym_capability_check_cipher(
231 const struct rte_cryptodev_symmetric_capability *capability,
232 uint16_t key_size, uint16_t iv_size);
235 * Check if key size and initial vector are supported
236 * in crypto auth capability
238 * @param capability Description of the symmetric crypto capability.
239 * @param key_size Auth key size.
240 * @param digest_size Auth digest size.
241 * @param iv_size Auth initial vector size.
244 * - Return 0 if the parameters are in range of the capability.
245 * - Return -1 if the parameters are out of range of the capability.
248 rte_cryptodev_sym_capability_check_auth(
249 const struct rte_cryptodev_symmetric_capability *capability,
250 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
253 * Check if key, digest, AAD and initial vector sizes are supported
254 * in crypto AEAD capability
256 * @param capability Description of the symmetric crypto capability.
257 * @param key_size AEAD key size.
258 * @param digest_size AEAD digest size.
259 * @param aad_size AEAD AAD size.
260 * @param iv_size AEAD IV size.
263 * - Return 0 if the parameters are in range of the capability.
264 * - Return -1 if the parameters are out of range of the capability.
267 rte_cryptodev_sym_capability_check_aead(
268 const struct rte_cryptodev_symmetric_capability *capability,
269 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
273 * Provide the cipher algorithm enum, given an algorithm string
275 * @param algo_enum A pointer to the cipher algorithm
277 * @param algo_string Authentication algo string
280 * - Return -1 if string is not valid
281 * - Return 0 is the string is valid
284 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
285 const char *algo_string);
288 * Provide the authentication algorithm enum, given an algorithm string
290 * @param algo_enum A pointer to the authentication algorithm
292 * @param algo_string Authentication algo string
295 * - Return -1 if string is not valid
296 * - Return 0 is the string is valid
299 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
300 const char *algo_string);
303 * Provide the AEAD algorithm enum, given an algorithm string
305 * @param algo_enum A pointer to the AEAD algorithm
307 * @param algo_string AEAD algorithm string
310 * - Return -1 if string is not valid
311 * - Return 0 is the string is valid
314 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
315 const char *algo_string);
317 /** Macro used at end of crypto PMD list */
318 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
319 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
323 * Crypto device supported feature flags
326 * New features flags should be added to the end of the list
328 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
330 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
331 /**< Symmetric crypto operations are supported */
332 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
333 /**< Asymmetric crypto operations are supported */
334 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
335 /**< Chaining symmetric crypto operations are supported */
336 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
337 /**< Utilises CPU SIMD SSE instructions */
338 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
339 /**< Utilises CPU SIMD AVX instructions */
340 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
341 /**< Utilises CPU SIMD AVX2 instructions */
342 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
343 /**< Utilises CPU AES-NI instructions */
344 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
345 /**< Operations are off-loaded to an external hardware accelerator */
346 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
347 /**< Utilises CPU SIMD AVX512 instructions */
348 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
349 /**< Scatter-gather mbufs are supported */
350 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
351 /**< Utilises CPU NEON instructions */
352 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
353 /**< Utilises ARM CPU Cryptographic Extensions */
354 #define RTE_CRYPTODEV_FF_SECURITY (1ULL << 12)
355 /**< Support Security Protocol Processing */
359 * Get the name of a crypto device feature flag
361 * @param flag The mask describing the flag.
364 * The name of this flag, or NULL if it's not a valid feature flag.
368 rte_cryptodev_get_feature_name(uint64_t flag);
370 /** Crypto device information */
371 struct rte_cryptodev_info {
372 const char *driver_name; /**< Driver name. */
373 uint8_t driver_id; /**< Driver identifier */
374 struct rte_pci_device *pci_dev; /**< PCI information. */
376 uint64_t feature_flags;
377 /**< Feature flags exposes HW/SW features for the given device */
379 const struct rte_cryptodev_capabilities *capabilities;
380 /**< Array of devices supported capabilities */
382 unsigned max_nb_queue_pairs;
383 /**< Maximum number of queues pairs supported by device. */
386 unsigned max_nb_sessions;
387 /**< Maximum number of sessions supported by device. */
388 unsigned int max_nb_sessions_per_qp;
389 /**< Maximum number of sessions per queue pair.
390 * Default 0 for infinite sessions
395 #define RTE_CRYPTODEV_DETACHED (0)
396 #define RTE_CRYPTODEV_ATTACHED (1)
398 /** Definitions of Crypto device event types */
399 enum rte_cryptodev_event_type {
400 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
401 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
402 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
405 /** Crypto device queue pair configuration structure. */
406 struct rte_cryptodev_qp_conf {
407 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
411 * Typedef for application callback function to be registered by application
412 * software for notification of device events
414 * @param dev_id Crypto device identifier
415 * @param event Crypto device event to register for notification of.
416 * @param cb_arg User specified parameter to be passed as to passed to
417 * users callback function.
419 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
420 enum rte_cryptodev_event_type event, void *cb_arg);
423 /** Crypto Device statistics */
424 struct rte_cryptodev_stats {
425 uint64_t enqueued_count;
426 /**< Count of all operations enqueued */
427 uint64_t dequeued_count;
428 /**< Count of all operations dequeued */
430 uint64_t enqueue_err_count;
431 /**< Total error count on operations enqueued */
432 uint64_t dequeue_err_count;
433 /**< Total error count on operations dequeued */
436 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
437 /**< Max length of name of crypto PMD */
440 * Get the device identifier for the named crypto device.
442 * @param name device name to select the device structure.
445 * - Returns crypto device identifier on success.
446 * - Return -1 on failure to find named crypto device.
449 rte_cryptodev_get_dev_id(const char *name);
452 * Get the crypto device name given a device identifier.
455 * The identifier of the device
458 * - Returns crypto device name.
459 * - Returns NULL if crypto device is not present.
462 rte_cryptodev_name_get(uint8_t dev_id);
465 * Get the total number of crypto devices that have been successfully
469 * - The total number of usable crypto devices.
472 rte_cryptodev_count(void);
475 * Get number of crypto device defined type.
477 * @param driver_id driver identifier.
480 * Returns number of crypto device.
483 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
486 * Get number and identifiers of attached crypto devices that
487 * use the same crypto driver.
489 * @param driver_name driver name.
490 * @param devices output devices identifiers.
491 * @param nb_devices maximal number of devices.
494 * Returns number of attached crypto device.
497 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
500 * Return the NUMA socket to which a device is connected
503 * The identifier of the device
505 * The NUMA socket id to which the device is connected or
506 * a default of zero if the socket could not be determined.
507 * -1 if returned is the dev_id value is out of range.
510 rte_cryptodev_socket_id(uint8_t dev_id);
512 /** Crypto device configuration structure */
513 struct rte_cryptodev_config {
514 int socket_id; /**< Socket to allocate resources on */
515 uint16_t nb_queue_pairs;
516 /**< Number of queue pairs to configure on device */
520 * Configure a device.
522 * This function must be invoked first before any other function in the
523 * API. This function can also be re-invoked when a device is in the
526 * @param dev_id The identifier of the device to configure.
527 * @param config The crypto device configuration structure.
530 * - 0: Success, device configured.
531 * - <0: Error code returned by the driver configuration function.
534 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
539 * The device start step is the last one and consists of setting the configured
540 * offload features and in starting the transmit and the receive units of the
542 * On success, all basic functions exported by the API (link status,
543 * receive/transmit, and so on) can be invoked.
546 * The identifier of the device.
548 * - 0: Success, device started.
549 * - <0: Error code of the driver device start function.
552 rte_cryptodev_start(uint8_t dev_id);
555 * Stop an device. The device can be restarted with a call to
556 * rte_cryptodev_start()
558 * @param dev_id The identifier of the device.
561 rte_cryptodev_stop(uint8_t dev_id);
564 * Close an device. The device cannot be restarted!
566 * @param dev_id The identifier of the device.
569 * - 0 on successfully closing device
570 * - <0 on failure to close device
573 rte_cryptodev_close(uint8_t dev_id);
576 * Allocate and set up a receive queue pair for a device.
579 * @param dev_id The identifier of the device.
580 * @param queue_pair_id The index of the queue pairs to set up. The
581 * value must be in the range [0, nb_queue_pair
582 * - 1] previously supplied to
583 * rte_cryptodev_configure().
584 * @param qp_conf The pointer to the configuration data to be
585 * used for the queue pair. NULL value is
586 * allowed, in which case default configuration
588 * @param socket_id The *socket_id* argument is the socket
589 * identifier in case of NUMA. The value can be
590 * *SOCKET_ID_ANY* if there is no NUMA constraint
591 * for the DMA memory allocated for the receive
593 * @param session_pool Pointer to device session mempool, used
594 * for session-less operations.
597 * - 0: Success, queue pair correctly set up.
598 * - <0: Queue pair configuration failed
601 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
602 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
603 struct rte_mempool *session_pool);
607 * Start a specified queue pair of a device. It is used
608 * when deferred_start flag of the specified queue is true.
610 * @param dev_id The identifier of the device
611 * @param queue_pair_id The index of the queue pair to start. The value
612 * must be in the range [0, nb_queue_pair - 1]
613 * previously supplied to
614 * rte_crypto_dev_configure().
616 * - 0: Success, the transmit queue is correctly set up.
617 * - -EINVAL: The dev_id or the queue_id out of range.
618 * - -ENOTSUP: The function not supported in PMD driver.
622 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
626 * Stop specified queue pair of a device
628 * @param dev_id The identifier of the device
629 * @param queue_pair_id The index of the queue pair to stop. The value
630 * must be in the range [0, nb_queue_pair - 1]
631 * previously supplied to
632 * rte_cryptodev_configure().
634 * - 0: Success, the transmit queue is correctly set up.
635 * - -EINVAL: The dev_id or the queue_id out of range.
636 * - -ENOTSUP: The function not supported in PMD driver.
640 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
643 * Get the number of queue pairs on a specific crypto device
645 * @param dev_id Crypto device identifier.
647 * - The number of configured queue pairs.
650 rte_cryptodev_queue_pair_count(uint8_t dev_id);
654 * Retrieve the general I/O statistics of a device.
656 * @param dev_id The identifier of the device.
657 * @param stats A pointer to a structure of type
658 * *rte_cryptodev_stats* to be filled with the
659 * values of device counters.
661 * - Zero if successful.
662 * - Non-zero otherwise.
665 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
668 * Reset the general I/O statistics of a device.
670 * @param dev_id The identifier of the device.
673 rte_cryptodev_stats_reset(uint8_t dev_id);
676 * Retrieve the contextual information of a device.
678 * @param dev_id The identifier of the device.
679 * @param dev_info A pointer to a structure of type
680 * *rte_cryptodev_info* to be filled with the
681 * contextual information of the device.
683 * @note The capabilities field of dev_info is set to point to the first
684 * element of an array of struct rte_cryptodev_capabilities. The element after
685 * the last valid element has it's op field set to
686 * RTE_CRYPTO_OP_TYPE_UNDEFINED.
689 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
693 * Register a callback function for specific device id.
695 * @param dev_id Device id.
696 * @param event Event interested.
697 * @param cb_fn User supplied callback function to be called.
698 * @param cb_arg Pointer to the parameters for the registered
702 * - On success, zero.
703 * - On failure, a negative value.
706 rte_cryptodev_callback_register(uint8_t dev_id,
707 enum rte_cryptodev_event_type event,
708 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
711 * Unregister a callback function for specific device id.
713 * @param dev_id The device identifier.
714 * @param event Event interested.
715 * @param cb_fn User supplied callback function to be called.
716 * @param cb_arg Pointer to the parameters for the registered
720 * - On success, zero.
721 * - On failure, a negative value.
724 rte_cryptodev_callback_unregister(uint8_t dev_id,
725 enum rte_cryptodev_event_type event,
726 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
729 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
730 struct rte_crypto_op **ops, uint16_t nb_ops);
731 /**< Dequeue processed packets from queue pair of a device. */
733 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
734 struct rte_crypto_op **ops, uint16_t nb_ops);
735 /**< Enqueue packets for processing on queue pair of a device. */
740 struct rte_cryptodev_callback;
742 /** Structure to keep track of registered callbacks */
743 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
745 /** The data structure associated with each crypto device. */
746 struct rte_cryptodev {
747 dequeue_pkt_burst_t dequeue_burst;
748 /**< Pointer to PMD receive function. */
749 enqueue_pkt_burst_t enqueue_burst;
750 /**< Pointer to PMD transmit function. */
752 struct rte_cryptodev_data *data;
753 /**< Pointer to device data */
754 struct rte_cryptodev_ops *dev_ops;
755 /**< Functions exported by PMD */
756 uint64_t feature_flags;
757 /**< Feature flags exposes HW/SW features for the given device */
758 struct rte_device *device;
759 /**< Backing device */
762 /**< Crypto driver identifier*/
764 struct rte_cryptodev_cb_list link_intr_cbs;
765 /**< User application callback for interrupts if present */
768 /**< Context for security ops */
771 uint8_t attached : 1;
772 /**< Flag indicating the device is attached */
773 } __rte_cache_aligned;
776 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
780 * The data part, with no function pointers, associated with each device.
782 * This structure is safe to place in shared memory to be common among
783 * different processes in a multi-process configuration.
785 struct rte_cryptodev_data {
787 /**< Device ID for this instance */
789 /**< Socket ID where memory is allocated */
790 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
791 /**< Unique identifier name */
794 uint8_t dev_started : 1;
795 /**< Device state: STARTED(1)/STOPPED(0) */
797 struct rte_mempool *session_pool;
798 /**< Session memory pool */
800 /**< Array of pointers to queue pairs. */
801 uint16_t nb_queue_pairs;
802 /**< Number of device queue pairs. */
805 /**< PMD-specific private data */
806 } __rte_cache_aligned;
808 extern struct rte_cryptodev *rte_cryptodevs;
811 * Dequeue a burst of processed crypto operations from a queue on the crypto
812 * device. The dequeued operation are stored in *rte_crypto_op* structures
813 * whose pointers are supplied in the *ops* array.
815 * The rte_cryptodev_dequeue_burst() function returns the number of ops
816 * actually dequeued, which is the number of *rte_crypto_op* data structures
817 * effectively supplied into the *ops* array.
819 * A return value equal to *nb_ops* indicates that the queue contained
820 * at least *nb_ops* operations, and this is likely to signify that other
821 * processed operations remain in the devices output queue. Applications
822 * implementing a "retrieve as many processed operations as possible" policy
823 * can check this specific case and keep invoking the
824 * rte_cryptodev_dequeue_burst() function until a value less than
825 * *nb_ops* is returned.
827 * The rte_cryptodev_dequeue_burst() function does not provide any error
828 * notification to avoid the corresponding overhead.
830 * @param dev_id The symmetric crypto device identifier
831 * @param qp_id The index of the queue pair from which to
832 * retrieve processed packets. The value must be
833 * in the range [0, nb_queue_pair - 1] previously
834 * supplied to rte_cryptodev_configure().
835 * @param ops The address of an array of pointers to
836 * *rte_crypto_op* structures that must be
837 * large enough to store *nb_ops* pointers in it.
838 * @param nb_ops The maximum number of operations to dequeue.
841 * - The number of operations actually dequeued, which is the number
842 * of pointers to *rte_crypto_op* structures effectively supplied to the
845 static inline uint16_t
846 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
847 struct rte_crypto_op **ops, uint16_t nb_ops)
849 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
851 nb_ops = (*dev->dequeue_burst)
852 (dev->data->queue_pairs[qp_id], ops, nb_ops);
858 * Enqueue a burst of operations for processing on a crypto device.
860 * The rte_cryptodev_enqueue_burst() function is invoked to place
861 * crypto operations on the queue *qp_id* of the device designated by
864 * The *nb_ops* parameter is the number of operations to process which are
865 * supplied in the *ops* array of *rte_crypto_op* structures.
867 * The rte_cryptodev_enqueue_burst() function returns the number of
868 * operations it actually enqueued for processing. A return value equal to
869 * *nb_ops* means that all packets have been enqueued.
871 * @param dev_id The identifier of the device.
872 * @param qp_id The index of the queue pair which packets are
873 * to be enqueued for processing. The value
874 * must be in the range [0, nb_queue_pairs - 1]
875 * previously supplied to
876 * *rte_cryptodev_configure*.
877 * @param ops The address of an array of *nb_ops* pointers
878 * to *rte_crypto_op* structures which contain
879 * the crypto operations to be processed.
880 * @param nb_ops The number of operations to process.
883 * The number of operations actually enqueued on the crypto device. The return
884 * value can be less than the value of the *nb_ops* parameter when the
885 * crypto devices queue is full or if invalid parameters are specified in
888 static inline uint16_t
889 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
890 struct rte_crypto_op **ops, uint16_t nb_ops)
892 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
894 return (*dev->enqueue_burst)(
895 dev->data->queue_pairs[qp_id], ops, nb_ops);
899 /** Cryptodev symmetric crypto session
900 * Each session is derived from a fixed xform chain. Therefore each session
901 * has a fixed algo, key, op-type, digest_len etc.
903 struct rte_cryptodev_sym_session {
904 __extension__ void *sess_private_data[0];
905 /**< Private session material */
910 * Create symmetric crypto session header (generic with no private data)
912 * @param mempool Symmetric session mempool to allocate session
915 * - On success return pointer to sym-session
916 * - On failure returns NULL
918 struct rte_cryptodev_sym_session *
919 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
922 * Frees symmetric crypto session header, after checking that all
923 * the device private data has been freed, returning it
924 * to its original mempool.
926 * @param sess Session header to be freed.
930 * - -EINVAL if session is NULL.
931 * - -EBUSY if not all device private data has been freed.
934 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
937 * Fill out private data for the device id, based on its device type.
939 * @param dev_id ID of device that we want the session to be used on
940 * @param sess Session where the private data will be attached to
941 * @param xforms Symmetric crypto transform operations to apply on flow
942 * processed with this session
943 * @param mempool Mempool where the private data is allocated.
946 * - On success, zero.
947 * - -EINVAL if input parameters are invalid.
948 * - -ENOTSUP if crypto device does not support the crypto transform.
949 * - -ENOMEM if the private session could not be allocated.
952 rte_cryptodev_sym_session_init(uint8_t dev_id,
953 struct rte_cryptodev_sym_session *sess,
954 struct rte_crypto_sym_xform *xforms,
955 struct rte_mempool *mempool);
958 * Frees private data for the device id, based on its device type,
959 * returning it to its mempool. It is the application's responsibility
960 * to ensure that private session data is not cleared while there are
961 * still in-flight operations using it.
963 * @param dev_id ID of device that uses the session.
964 * @param sess Session containing the reference to the private data
968 * - -EINVAL if device is invalid or session is NULL.
971 rte_cryptodev_sym_session_clear(uint8_t dev_id,
972 struct rte_cryptodev_sym_session *sess);
975 * Get the size of the header session, for all registered drivers.
978 * Size of the header session.
981 rte_cryptodev_get_header_session_size(void);
984 * Get the size of the private session data for a device.
986 * @param dev_id The device identifier.
989 * - Size of the private data, if successful
990 * - 0 if device is invalid or does not have private session
993 rte_cryptodev_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_ */