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 #define CRYPTODEV_NAME_NULL_PMD crypto_null
54 /**< Null crypto PMD device name */
55 #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
56 /**< AES-NI Multi buffer PMD device name */
57 #define CRYPTODEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm
58 /**< AES-NI GCM PMD device name */
59 #define CRYPTODEV_NAME_OPENSSL_PMD crypto_openssl
60 /**< Open SSL Crypto PMD device name */
61 #define CRYPTODEV_NAME_QAT_SYM_PMD crypto_qat
62 /**< Intel QAT Symmetric Crypto PMD device name */
63 #define CRYPTODEV_NAME_SNOW3G_PMD crypto_snow3g
64 /**< SNOW 3G PMD device name */
65 #define CRYPTODEV_NAME_KASUMI_PMD crypto_kasumi
66 /**< KASUMI PMD device name */
67 #define CRYPTODEV_NAME_ZUC_PMD crypto_zuc
68 /**< KASUMI PMD device name */
69 #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
70 /**< ARMv8 Crypto PMD device name */
71 #define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler
72 /**< Scheduler Crypto PMD device name */
74 /** Crypto device type */
75 enum rte_cryptodev_type {
76 RTE_CRYPTODEV_NULL_PMD = 1, /**< Null crypto PMD */
77 RTE_CRYPTODEV_AESNI_GCM_PMD, /**< AES-NI GCM PMD */
78 RTE_CRYPTODEV_AESNI_MB_PMD, /**< AES-NI multi buffer PMD */
79 RTE_CRYPTODEV_QAT_SYM_PMD, /**< QAT PMD Symmetric Crypto */
80 RTE_CRYPTODEV_SNOW3G_PMD, /**< SNOW 3G PMD */
81 RTE_CRYPTODEV_KASUMI_PMD, /**< KASUMI PMD */
82 RTE_CRYPTODEV_ZUC_PMD, /**< ZUC PMD */
83 RTE_CRYPTODEV_OPENSSL_PMD, /**< OpenSSL PMD */
84 RTE_CRYPTODEV_ARMV8_PMD, /**< ARMv8 crypto PMD */
85 RTE_CRYPTODEV_SCHEDULER_PMD, /**< Crypto Scheduler PMD */
88 extern const char **rte_cyptodev_names;
92 #define CDEV_LOG_ERR(...) \
93 RTE_LOG(ERR, CRYPTODEV, \
94 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
95 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
97 #define CDEV_PMD_LOG_ERR(dev, ...) \
98 RTE_LOG(ERR, CRYPTODEV, \
99 RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
100 dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
102 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
103 #define CDEV_LOG_DEBUG(...) \
104 RTE_LOG(DEBUG, CRYPTODEV, \
105 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
106 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
108 #define CDEV_PMD_TRACE(...) \
109 RTE_LOG(DEBUG, CRYPTODEV, \
110 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
111 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
114 #define CDEV_LOG_DEBUG(...) (void)0
115 #define CDEV_PMD_TRACE(...) (void)0
119 * Crypto parameters range description
121 struct rte_crypto_param_range {
122 uint16_t min; /**< minimum size */
123 uint16_t max; /**< maximum size */
125 /**< if a range of sizes are supported,
126 * this parameter is used to indicate
127 * increments in byte size that are supported
128 * between the minimum and maximum
133 * Symmetric Crypto Capability
135 struct rte_cryptodev_symmetric_capability {
136 enum rte_crypto_sym_xform_type xform_type;
137 /**< Transform type : Authentication / Cipher */
141 enum rte_crypto_auth_algorithm algo;
142 /**< authentication algorithm */
144 /**< algorithm block size */
145 struct rte_crypto_param_range key_size;
146 /**< auth key size range */
147 struct rte_crypto_param_range digest_size;
148 /**< digest size range */
149 struct rte_crypto_param_range aad_size;
150 /**< Additional authentication 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 */
167 /** Structure used to capture a capability of a crypto device */
168 struct rte_cryptodev_capabilities {
169 enum rte_crypto_op_type op;
170 /**< Operation type */
174 struct rte_cryptodev_symmetric_capability sym;
175 /**< Symmetric operation capability parameters */
179 /** Structure used to describe crypto algorithms */
180 struct rte_cryptodev_sym_capability_idx {
181 enum rte_crypto_sym_xform_type type;
183 enum rte_crypto_cipher_algorithm cipher;
184 enum rte_crypto_auth_algorithm auth;
189 * Provide capabilities available for defined device and algorithm
191 * @param dev_id The identifier of the device.
192 * @param idx Description of crypto algorithms.
195 * - Return description of the symmetric crypto capability if exist.
196 * - Return NULL if the capability not exist.
198 const struct rte_cryptodev_symmetric_capability *
199 rte_cryptodev_sym_capability_get(uint8_t dev_id,
200 const struct rte_cryptodev_sym_capability_idx *idx);
203 * Check if key size and initial vector are supported
204 * in crypto cipher capability
206 * @param capability Description of the symmetric crypto capability.
207 * @param key_size Cipher key size.
208 * @param iv_size Cipher initial vector size.
211 * - Return 0 if the parameters are in range of the capability.
212 * - Return -1 if the parameters are out of range of the capability.
215 rte_cryptodev_sym_capability_check_cipher(
216 const struct rte_cryptodev_symmetric_capability *capability,
217 uint16_t key_size, uint16_t iv_size);
220 * Check if key size and initial vector are supported
221 * in crypto auth capability
223 * @param capability Description of the symmetric crypto capability.
224 * @param key_size Auth key size.
225 * @param digest_size Auth digest size.
226 * @param aad_size Auth aad size.
229 * - Return 0 if the parameters are in range of the capability.
230 * - Return -1 if the parameters are out of range of the capability.
233 rte_cryptodev_sym_capability_check_auth(
234 const struct rte_cryptodev_symmetric_capability *capability,
235 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);
267 /** Macro used at end of crypto PMD list */
268 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
269 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
273 * Crypto device supported feature flags
276 * New features flags should be added to the end of the list
278 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
280 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
281 /**< Symmetric crypto operations are supported */
282 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
283 /**< Asymmetric crypto operations are supported */
284 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
285 /**< Chaining symmetric crypto operations are supported */
286 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
287 /**< Utilises CPU SIMD SSE instructions */
288 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
289 /**< Utilises CPU SIMD AVX instructions */
290 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
291 /**< Utilises CPU SIMD AVX2 instructions */
292 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
293 /**< Utilises CPU AES-NI instructions */
294 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
295 /**< Operations are off-loaded to an external hardware accelerator */
296 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
297 /**< Utilises CPU SIMD AVX512 instructions */
298 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
299 /**< Scatter-gather mbufs are supported */
300 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
301 /**< Utilises CPU NEON instructions */
302 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
303 /**< Utilises ARM CPU Cryptographic Extensions */
307 * Get the name of a crypto device feature flag
309 * @param flag The mask describing the flag.
312 * The name of this flag, or NULL if it's not a valid feature flag.
316 rte_cryptodev_get_feature_name(uint64_t flag);
318 /** Crypto device information */
319 struct rte_cryptodev_info {
320 const char *driver_name; /**< Driver name. */
321 enum rte_cryptodev_type dev_type; /**< Device type */
322 struct rte_pci_device *pci_dev; /**< PCI information. */
324 uint64_t feature_flags; /**< Feature flags */
326 const struct rte_cryptodev_capabilities *capabilities;
327 /**< Array of devices supported capabilities */
329 unsigned max_nb_queue_pairs;
330 /**< Maximum number of queues pairs supported by device. */
333 unsigned max_nb_sessions;
334 /**< Maximum number of sessions supported by device. */
335 unsigned int max_nb_sessions_per_qp;
336 /**< Maximum number of sessions per queue pair.
337 * Default 0 for infinite sessions
342 #define RTE_CRYPTODEV_DETACHED (0)
343 #define RTE_CRYPTODEV_ATTACHED (1)
345 /** Definitions of Crypto device event types */
346 enum rte_cryptodev_event_type {
347 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
348 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
349 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
352 /** Crypto device queue pair configuration structure. */
353 struct rte_cryptodev_qp_conf {
354 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
358 * Typedef for application callback function to be registered by application
359 * software for notification of device events
361 * @param dev_id Crypto device identifier
362 * @param event Crypto device event to register for notification of.
363 * @param cb_arg User specified parameter to be passed as to passed to
364 * users callback function.
366 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
367 enum rte_cryptodev_event_type event, void *cb_arg);
370 /** Crypto Device statistics */
371 struct rte_cryptodev_stats {
372 uint64_t enqueued_count;
373 /**< Count of all operations enqueued */
374 uint64_t dequeued_count;
375 /**< Count of all operations dequeued */
377 uint64_t enqueue_err_count;
378 /**< Total error count on operations enqueued */
379 uint64_t dequeue_err_count;
380 /**< Total error count on operations dequeued */
383 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
384 /**< Max length of name of crypto PMD */
385 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS 8
386 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS 2048
390 * Initialisation parameters for virtual crypto devices
392 struct rte_crypto_vdev_init_params {
393 unsigned max_nb_queue_pairs;
394 unsigned max_nb_sessions;
396 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
400 * Parse virtual device initialisation parameters input arguments
403 * @params params Initialisation parameters with defaults set.
404 * @params input_args Command line arguments
407 * 0 on successful parse
408 * <0 on failure to parse
411 rte_cryptodev_parse_vdev_init_params(
412 struct rte_crypto_vdev_init_params *params,
413 const char *input_args);
416 * Create a virtual crypto device
418 * @param name Cryptodev PMD name of device to be created.
419 * @param args Options arguments for device.
422 * - On successful creation of the cryptodev the device index is returned,
423 * which will be between 0 and rte_cryptodev_count().
424 * - In the case of a failure, returns -1.
427 rte_cryptodev_create_vdev(const char *name, const char *args);
430 * Get the device identifier for the named crypto device.
432 * @param name device name to select the device structure.
435 * - Returns crypto device identifier on success.
436 * - Return -1 on failure to find named crypto device.
439 rte_cryptodev_get_dev_id(const char *name);
442 * Get the total number of crypto devices that have been successfully
446 * - The total number of usable crypto devices.
449 rte_cryptodev_count(void);
452 * Get number of crypto device defined type.
454 * @param type type of device.
457 * Returns number of crypto device.
460 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
463 * Get number and identifiers of attached crypto device.
465 * @param dev_name device name.
466 * @param devices output devices identifiers.
467 * @param nb_devices maximal number of devices.
470 * Returns number of attached crypto device.
473 rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices,
476 * Return the NUMA socket to which a device is connected
479 * The identifier of the device
481 * The NUMA socket id to which the device is connected or
482 * a default of zero if the socket could not be determined.
483 * -1 if returned is the dev_id value is out of range.
486 rte_cryptodev_socket_id(uint8_t dev_id);
488 /** Crypto device configuration structure */
489 struct rte_cryptodev_config {
490 int socket_id; /**< Socket to allocate resources on */
491 uint16_t nb_queue_pairs;
492 /**< Number of queue pairs to configure on device */
495 uint32_t nb_objs; /**< Number of objects in mempool */
496 uint32_t cache_size; /**< l-core object cache size */
497 } session_mp; /**< Session mempool configuration */
501 * Configure a device.
503 * This function must be invoked first before any other function in the
504 * API. This function can also be re-invoked when a device is in the
507 * @param dev_id The identifier of the device to configure.
508 * @param config The crypto device configuration structure.
511 * - 0: Success, device configured.
512 * - <0: Error code returned by the driver configuration function.
515 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
520 * The device start step is the last one and consists of setting the configured
521 * offload features and in starting the transmit and the receive units of the
523 * On success, all basic functions exported by the API (link status,
524 * receive/transmit, and so on) can be invoked.
527 * The identifier of the device.
529 * - 0: Success, device started.
530 * - <0: Error code of the driver device start function.
533 rte_cryptodev_start(uint8_t dev_id);
536 * Stop an device. The device can be restarted with a call to
537 * rte_cryptodev_start()
539 * @param dev_id The identifier of the device.
542 rte_cryptodev_stop(uint8_t dev_id);
545 * Close an device. The device cannot be restarted!
547 * @param dev_id The identifier of the device.
550 * - 0 on successfully closing device
551 * - <0 on failure to close device
554 rte_cryptodev_close(uint8_t dev_id);
557 * Allocate and set up a receive queue pair for a device.
560 * @param dev_id The identifier of the device.
561 * @param queue_pair_id The index of the queue pairs to set up. The
562 * value must be in the range [0, nb_queue_pair
563 * - 1] previously supplied to
564 * rte_cryptodev_configure().
565 * @param qp_conf The pointer to the configuration data to be
566 * used for the queue pair. NULL value is
567 * allowed, in which case default configuration
569 * @param socket_id The *socket_id* argument is the socket
570 * identifier in case of NUMA. The value can be
571 * *SOCKET_ID_ANY* if there is no NUMA constraint
572 * for the DMA memory allocated for the receive
576 * - 0: Success, queue pair correctly set up.
577 * - <0: Queue pair configuration failed
580 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
581 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
584 * Start a specified queue pair of a device. It is used
585 * when deferred_start flag of the specified queue is true.
587 * @param dev_id The identifier of the device
588 * @param queue_pair_id The index of the queue pair to start. The value
589 * must be in the range [0, nb_queue_pair - 1]
590 * previously supplied to
591 * rte_crypto_dev_configure().
593 * - 0: Success, the transmit queue is correctly set up.
594 * - -EINVAL: The dev_id or the queue_id out of range.
595 * - -ENOTSUP: The function not supported in PMD driver.
598 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
601 * Stop specified queue pair of a device
603 * @param dev_id The identifier of the device
604 * @param queue_pair_id The index of the queue pair to stop. The value
605 * must be in the range [0, nb_queue_pair - 1]
606 * previously supplied to
607 * rte_cryptodev_configure().
609 * - 0: Success, the transmit queue is correctly set up.
610 * - -EINVAL: The dev_id or the queue_id out of range.
611 * - -ENOTSUP: The function not supported in PMD driver.
614 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
617 * Get the number of queue pairs on a specific crypto device
619 * @param dev_id Crypto device identifier.
621 * - The number of configured queue pairs.
624 rte_cryptodev_queue_pair_count(uint8_t dev_id);
628 * Retrieve the general I/O statistics of a device.
630 * @param dev_id The identifier of the device.
631 * @param stats A pointer to a structure of type
632 * *rte_cryptodev_stats* to be filled with the
633 * values of device counters.
635 * - Zero if successful.
636 * - Non-zero otherwise.
639 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
642 * Reset the general I/O statistics of a device.
644 * @param dev_id The identifier of the device.
647 rte_cryptodev_stats_reset(uint8_t dev_id);
650 * Retrieve the contextual information of a device.
652 * @param dev_id The identifier of the device.
653 * @param dev_info A pointer to a structure of type
654 * *rte_cryptodev_info* to be filled with the
655 * contextual information of the device.
658 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
662 * Register a callback function for specific device id.
664 * @param dev_id Device id.
665 * @param event Event interested.
666 * @param cb_fn User supplied callback function to be called.
667 * @param cb_arg Pointer to the parameters for the registered
671 * - On success, zero.
672 * - On failure, a negative value.
675 rte_cryptodev_callback_register(uint8_t dev_id,
676 enum rte_cryptodev_event_type event,
677 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
680 * Unregister a callback function for specific device id.
682 * @param dev_id The device identifier.
683 * @param event Event interested.
684 * @param cb_fn User supplied callback function to be called.
685 * @param cb_arg Pointer to the parameters for the registered
689 * - On success, zero.
690 * - On failure, a negative value.
693 rte_cryptodev_callback_unregister(uint8_t dev_id,
694 enum rte_cryptodev_event_type event,
695 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
698 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
699 struct rte_crypto_op **ops, uint16_t nb_ops);
700 /**< Dequeue processed packets from queue pair of a device. */
702 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
703 struct rte_crypto_op **ops, uint16_t nb_ops);
704 /**< Enqueue packets for processing on queue pair of a device. */
709 struct rte_cryptodev_callback;
711 /** Structure to keep track of registered callbacks */
712 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
714 /** The data structure associated with each crypto device. */
715 struct rte_cryptodev {
716 dequeue_pkt_burst_t dequeue_burst;
717 /**< Pointer to PMD receive function. */
718 enqueue_pkt_burst_t enqueue_burst;
719 /**< Pointer to PMD transmit function. */
721 const struct rte_cryptodev_driver *driver;
722 /**< Driver for this device */
723 struct rte_cryptodev_data *data;
724 /**< Pointer to device data */
725 struct rte_cryptodev_ops *dev_ops;
726 /**< Functions exported by PMD */
727 uint64_t feature_flags;
728 /**< Supported features */
729 struct rte_device *device;
730 /**< Backing device */
732 enum rte_cryptodev_type dev_type;
733 /**< Crypto device type */
735 struct rte_cryptodev_cb_list link_intr_cbs;
736 /**< User application callback for interrupts if present */
739 uint8_t attached : 1;
740 /**< Flag indicating the device is attached */
741 } __rte_cache_aligned;
745 * The data part, with no function pointers, associated with each device.
747 * This structure is safe to place in shared memory to be common among
748 * different processes in a multi-process configuration.
750 struct rte_cryptodev_data {
752 /**< Device ID for this instance */
754 /**< Socket ID where memory is allocated */
755 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
756 /**< Unique identifier name */
759 uint8_t dev_started : 1;
760 /**< Device state: STARTED(1)/STOPPED(0) */
762 struct rte_mempool *session_pool;
763 /**< Session memory pool */
765 /**< Array of pointers to queue pairs. */
766 uint16_t nb_queue_pairs;
767 /**< Number of device queue pairs. */
770 /**< PMD-specific private data */
771 } __rte_cache_aligned;
773 extern struct rte_cryptodev *rte_cryptodevs;
776 * Dequeue a burst of processed crypto operations from a queue on the crypto
777 * device. The dequeued operation are stored in *rte_crypto_op* structures
778 * whose pointers are supplied in the *ops* array.
780 * The rte_cryptodev_dequeue_burst() function returns the number of ops
781 * actually dequeued, which is the number of *rte_crypto_op* data structures
782 * effectively supplied into the *ops* array.
784 * A return value equal to *nb_ops* indicates that the queue contained
785 * at least *nb_ops* operations, and this is likely to signify that other
786 * processed operations remain in the devices output queue. Applications
787 * implementing a "retrieve as many processed operations as possible" policy
788 * can check this specific case and keep invoking the
789 * rte_cryptodev_dequeue_burst() function until a value less than
790 * *nb_ops* is returned.
792 * The rte_cryptodev_dequeue_burst() function does not provide any error
793 * notification to avoid the corresponding overhead.
795 * @param dev_id The symmetric crypto device identifier
796 * @param qp_id The index of the queue pair from which to
797 * retrieve processed packets. The value must be
798 * in the range [0, nb_queue_pair - 1] previously
799 * supplied to rte_cryptodev_configure().
800 * @param ops The address of an array of pointers to
801 * *rte_crypto_op* structures that must be
802 * large enough to store *nb_ops* pointers in it.
803 * @param nb_ops The maximum number of operations to dequeue.
806 * - The number of operations actually dequeued, which is the number
807 * of pointers to *rte_crypto_op* structures effectively supplied to the
810 static inline uint16_t
811 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
812 struct rte_crypto_op **ops, uint16_t nb_ops)
814 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
816 nb_ops = (*dev->dequeue_burst)
817 (dev->data->queue_pairs[qp_id], ops, nb_ops);
823 * Enqueue a burst of operations for processing on a crypto device.
825 * The rte_cryptodev_enqueue_burst() function is invoked to place
826 * crypto operations on the queue *qp_id* of the device designated by
829 * The *nb_ops* parameter is the number of operations to process which are
830 * supplied in the *ops* array of *rte_crypto_op* structures.
832 * The rte_cryptodev_enqueue_burst() function returns the number of
833 * operations it actually enqueued for processing. A return value equal to
834 * *nb_ops* means that all packets have been enqueued.
836 * @param dev_id The identifier of the device.
837 * @param qp_id The index of the queue pair which packets are
838 * to be enqueued for processing. The value
839 * must be in the range [0, nb_queue_pairs - 1]
840 * previously supplied to
841 * *rte_cryptodev_configure*.
842 * @param ops The address of an array of *nb_ops* pointers
843 * to *rte_crypto_op* structures which contain
844 * the crypto operations to be processed.
845 * @param nb_ops The number of operations to process.
848 * The number of operations actually enqueued on the crypto device. The return
849 * value can be less than the value of the *nb_ops* parameter when the
850 * crypto devices queue is full or if invalid parameters are specified in
853 static inline uint16_t
854 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
855 struct rte_crypto_op **ops, uint16_t nb_ops)
857 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
859 return (*dev->enqueue_burst)(
860 dev->data->queue_pairs[qp_id], ops, nb_ops);
864 /** Cryptodev symmetric crypto session */
865 struct rte_cryptodev_sym_session {
870 enum rte_cryptodev_type dev_type;
871 /** Crypto Device type session created on */
872 struct rte_mempool *mp;
873 /**< Mempool session allocated from */
875 /**< Public symmetric session details */
877 __extension__ char _private[0];
878 /**< Private session material */
883 * Initialise a session for symmetric cryptographic operations.
885 * This function is used by the client to initialize immutable
886 * parameters of symmetric cryptographic operation.
887 * To perform the operation the rte_cryptodev_enqueue_burst function is
888 * used. Each mbuf should contain a reference to the session
889 * pointer returned from this function contained within it's crypto_op if a
890 * session-based operation is being provisioned. Memory to contain the session
891 * information is allocated from within mempool managed by the cryptodev.
893 * The rte_cryptodev_session_free must be called to free allocated
894 * memory when the session is no longer required.
896 * @param dev_id The device identifier.
897 * @param xform Crypto transform chain.
901 * Pointer to the created session or NULL
903 extern struct rte_cryptodev_sym_session *
904 rte_cryptodev_sym_session_create(uint8_t dev_id,
905 struct rte_crypto_sym_xform *xform);
908 * Free the memory associated with a previously allocated session.
910 * @param dev_id The device identifier.
911 * @param session Session pointer previously allocated by
912 * *rte_cryptodev_sym_session_create*.
915 * NULL on successful freeing of session.
916 * Session pointer on failure to free session.
918 extern struct rte_cryptodev_sym_session *
919 rte_cryptodev_sym_session_free(uint8_t dev_id,
920 struct rte_cryptodev_sym_session *session);
923 * Attach queue pair with sym session.
925 * @param qp_id Queue pair to which session will be attached.
926 * @param session Session pointer previously allocated by
927 * *rte_cryptodev_sym_session_create*.
930 * - On success, zero.
931 * - On failure, a negative value.
934 rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
935 struct rte_cryptodev_sym_session *session);
938 * Detach queue pair with sym session.
940 * @param qp_id Queue pair to which session is attached.
941 * @param session Session pointer previously allocated by
942 * *rte_cryptodev_sym_session_create*.
945 * - On success, zero.
946 * - On failure, a negative value.
949 rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
950 struct rte_cryptodev_sym_session *session);
957 #endif /* _RTE_CRYPTODEV_H_ */