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>
54 #define CRYPTODEV_NAME_NULL_PMD crypto_null
55 /**< Null crypto PMD device name */
56 #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
57 /**< AES-NI Multi buffer PMD device name */
58 #define CRYPTODEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm
59 /**< AES-NI GCM PMD device name */
60 #define CRYPTODEV_NAME_OPENSSL_PMD crypto_openssl
61 /**< Open SSL Crypto PMD device name */
62 #define CRYPTODEV_NAME_QAT_SYM_PMD crypto_qat
63 /**< Intel QAT Symmetric Crypto PMD device name */
64 #define CRYPTODEV_NAME_SNOW3G_PMD crypto_snow3g
65 /**< SNOW 3G PMD device name */
66 #define CRYPTODEV_NAME_KASUMI_PMD crypto_kasumi
67 /**< KASUMI PMD device name */
68 #define CRYPTODEV_NAME_ZUC_PMD crypto_zuc
69 /**< KASUMI PMD device name */
70 #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
71 /**< ARMv8 Crypto PMD device name */
72 #define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler
73 /**< Scheduler Crypto PMD device name */
74 #define CRYPTODEV_NAME_DPAA2_SEC_PMD cryptodev_dpaa2_sec_pmd
75 /**< NXP DPAA2 - SEC PMD device name */
77 /** Crypto device type */
78 enum rte_cryptodev_type {
79 RTE_CRYPTODEV_NULL_PMD = 1, /**< Null crypto PMD */
80 RTE_CRYPTODEV_AESNI_GCM_PMD, /**< AES-NI GCM PMD */
81 RTE_CRYPTODEV_AESNI_MB_PMD, /**< AES-NI multi buffer PMD */
82 RTE_CRYPTODEV_QAT_SYM_PMD, /**< QAT PMD Symmetric Crypto */
83 RTE_CRYPTODEV_SNOW3G_PMD, /**< SNOW 3G PMD */
84 RTE_CRYPTODEV_KASUMI_PMD, /**< KASUMI PMD */
85 RTE_CRYPTODEV_ZUC_PMD, /**< ZUC PMD */
86 RTE_CRYPTODEV_OPENSSL_PMD, /**< OpenSSL PMD */
87 RTE_CRYPTODEV_ARMV8_PMD, /**< ARMv8 crypto PMD */
88 RTE_CRYPTODEV_SCHEDULER_PMD, /**< Crypto Scheduler PMD */
89 RTE_CRYPTODEV_DPAA2_SEC_PMD, /**< NXP DPAA2 - SEC PMD */
92 extern const char **rte_cyptodev_names;
96 #define CDEV_LOG_ERR(...) \
97 RTE_LOG(ERR, CRYPTODEV, \
98 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
99 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
101 #define CDEV_PMD_LOG_ERR(dev, ...) \
102 RTE_LOG(ERR, CRYPTODEV, \
103 RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
104 dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
106 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
107 #define CDEV_LOG_DEBUG(...) \
108 RTE_LOG(DEBUG, CRYPTODEV, \
109 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
110 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
112 #define CDEV_PMD_TRACE(...) \
113 RTE_LOG(DEBUG, CRYPTODEV, \
114 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
115 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
118 #define CDEV_LOG_DEBUG(...) (void)0
119 #define CDEV_PMD_TRACE(...) (void)0
125 * A macro that points to an offset from the start
126 * of the crypto operation structure (rte_crypto_op)
128 * The returned pointer is cast to type t.
131 * The crypto operation.
133 * The offset from the start of the crypto operation.
135 * The type to cast the result into.
137 #define rte_crypto_op_ctod_offset(c, t, o) \
138 ((t)((char *)(c) + (o)))
141 * A macro that returns the physical address that points
142 * to an offset from the start of the crypto operation
146 * The crypto operation.
148 * The offset from the start of the crypto operation
149 * to calculate address from.
151 #define rte_crypto_op_ctophys_offset(c, o) \
152 (phys_addr_t)((c)->phys_addr + (o))
155 * Crypto parameters range description
157 struct rte_crypto_param_range {
158 uint16_t min; /**< minimum size */
159 uint16_t max; /**< maximum size */
161 /**< if a range of sizes are supported,
162 * this parameter is used to indicate
163 * increments in byte size that are supported
164 * between the minimum and maximum
169 * Symmetric Crypto Capability
171 struct rte_cryptodev_symmetric_capability {
172 enum rte_crypto_sym_xform_type xform_type;
173 /**< Transform type : Authentication / Cipher */
177 enum rte_crypto_auth_algorithm algo;
178 /**< authentication algorithm */
180 /**< algorithm block size */
181 struct rte_crypto_param_range key_size;
182 /**< auth key size range */
183 struct rte_crypto_param_range digest_size;
184 /**< digest size range */
185 struct rte_crypto_param_range aad_size;
186 /**< Additional authentication data size range */
188 /**< Symmetric Authentication transform capabilities */
190 enum rte_crypto_cipher_algorithm algo;
191 /**< cipher algorithm */
193 /**< algorithm block size */
194 struct rte_crypto_param_range key_size;
195 /**< cipher key size range */
196 struct rte_crypto_param_range iv_size;
197 /**< Initialisation vector data size range */
199 /**< Symmetric Cipher transform capabilities */
203 /** Structure used to capture a capability of a crypto device */
204 struct rte_cryptodev_capabilities {
205 enum rte_crypto_op_type op;
206 /**< Operation type */
210 struct rte_cryptodev_symmetric_capability sym;
211 /**< Symmetric operation capability parameters */
215 /** Structure used to describe crypto algorithms */
216 struct rte_cryptodev_sym_capability_idx {
217 enum rte_crypto_sym_xform_type type;
219 enum rte_crypto_cipher_algorithm cipher;
220 enum rte_crypto_auth_algorithm auth;
225 * Provide capabilities available for defined device and algorithm
227 * @param dev_id The identifier of the device.
228 * @param idx Description of crypto algorithms.
231 * - Return description of the symmetric crypto capability if exist.
232 * - Return NULL if the capability not exist.
234 const struct rte_cryptodev_symmetric_capability *
235 rte_cryptodev_sym_capability_get(uint8_t dev_id,
236 const struct rte_cryptodev_sym_capability_idx *idx);
239 * Check if key size and initial vector are supported
240 * in crypto cipher capability
242 * @param capability Description of the symmetric crypto capability.
243 * @param key_size Cipher key size.
244 * @param iv_size Cipher initial vector size.
247 * - Return 0 if the parameters are in range of the capability.
248 * - Return -1 if the parameters are out of range of the capability.
251 rte_cryptodev_sym_capability_check_cipher(
252 const struct rte_cryptodev_symmetric_capability *capability,
253 uint16_t key_size, uint16_t iv_size);
256 * Check if key size and initial vector are supported
257 * in crypto auth capability
259 * @param capability Description of the symmetric crypto capability.
260 * @param key_size Auth key size.
261 * @param digest_size Auth digest size.
262 * @param aad_size Auth aad size.
265 * - Return 0 if the parameters are in range of the capability.
266 * - Return -1 if the parameters are out of range of the capability.
269 rte_cryptodev_sym_capability_check_auth(
270 const struct rte_cryptodev_symmetric_capability *capability,
271 uint16_t key_size, uint16_t digest_size, uint16_t aad_size);
274 * Provide the cipher algorithm enum, given an algorithm string
276 * @param algo_enum A pointer to the cipher algorithm
278 * @param algo_string Authentication algo string
281 * - Return -1 if string is not valid
282 * - Return 0 is the string is valid
285 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
286 const char *algo_string);
289 * Provide the authentication algorithm enum, given an algorithm string
291 * @param algo_enum A pointer to the authentication algorithm
293 * @param algo_string Authentication algo string
296 * - Return -1 if string is not valid
297 * - Return 0 is the string is valid
300 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
301 const char *algo_string);
303 /** Macro used at end of crypto PMD list */
304 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
305 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
309 * Crypto device supported feature flags
312 * New features flags should be added to the end of the list
314 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
316 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
317 /**< Symmetric crypto operations are supported */
318 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
319 /**< Asymmetric crypto operations are supported */
320 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
321 /**< Chaining symmetric crypto operations are supported */
322 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
323 /**< Utilises CPU SIMD SSE instructions */
324 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
325 /**< Utilises CPU SIMD AVX instructions */
326 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
327 /**< Utilises CPU SIMD AVX2 instructions */
328 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
329 /**< Utilises CPU AES-NI instructions */
330 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
331 /**< Operations are off-loaded to an external hardware accelerator */
332 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
333 /**< Utilises CPU SIMD AVX512 instructions */
334 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
335 /**< Scatter-gather mbufs are supported */
336 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
337 /**< Utilises CPU NEON instructions */
338 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
339 /**< Utilises ARM CPU Cryptographic Extensions */
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 enum rte_cryptodev_type dev_type; /**< Device type */
358 struct rte_pci_device *pci_dev; /**< PCI information. */
360 uint64_t feature_flags; /**< Feature flags */
362 const struct rte_cryptodev_capabilities *capabilities;
363 /**< Array of devices supported capabilities */
365 unsigned max_nb_queue_pairs;
366 /**< Maximum number of queues pairs supported by device. */
369 unsigned max_nb_sessions;
370 /**< Maximum number of sessions supported by device. */
371 unsigned int max_nb_sessions_per_qp;
372 /**< Maximum number of sessions per queue pair.
373 * Default 0 for infinite sessions
378 #define RTE_CRYPTODEV_DETACHED (0)
379 #define RTE_CRYPTODEV_ATTACHED (1)
381 /** Definitions of Crypto device event types */
382 enum rte_cryptodev_event_type {
383 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
384 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
385 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
388 /** Crypto device queue pair configuration structure. */
389 struct rte_cryptodev_qp_conf {
390 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
394 * Typedef for application callback function to be registered by application
395 * software for notification of device events
397 * @param dev_id Crypto device identifier
398 * @param event Crypto device event to register for notification of.
399 * @param cb_arg User specified parameter to be passed as to passed to
400 * users callback function.
402 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
403 enum rte_cryptodev_event_type event, void *cb_arg);
406 /** Crypto Device statistics */
407 struct rte_cryptodev_stats {
408 uint64_t enqueued_count;
409 /**< Count of all operations enqueued */
410 uint64_t dequeued_count;
411 /**< Count of all operations dequeued */
413 uint64_t enqueue_err_count;
414 /**< Total error count on operations enqueued */
415 uint64_t dequeue_err_count;
416 /**< Total error count on operations dequeued */
419 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
420 /**< Max length of name of crypto PMD */
423 * Create a virtual crypto device
425 * @param name Cryptodev PMD name of device to be created.
426 * @param args Options arguments for device.
429 * - On successful creation of the cryptodev the device index is returned,
430 * which will be between 0 and rte_cryptodev_count().
431 * - In the case of a failure, returns -1.
434 rte_cryptodev_create_vdev(const char *name, const char *args);
437 * Get the device identifier for the named crypto device.
439 * @param name device name to select the device structure.
442 * - Returns crypto device identifier on success.
443 * - Return -1 on failure to find named crypto device.
446 rte_cryptodev_get_dev_id(const char *name);
449 * Get the total number of crypto devices that have been successfully
453 * - The total number of usable crypto devices.
456 rte_cryptodev_count(void);
459 * Get number of crypto device defined type.
461 * @param type type of device.
464 * Returns number of crypto device.
467 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
470 * Get number and identifiers of attached crypto devices that
471 * use the same crypto driver.
473 * @param driver_name driver name.
474 * @param devices output devices identifiers.
475 * @param nb_devices maximal number of devices.
478 * Returns number of attached crypto device.
481 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
484 * Return the NUMA socket to which a device is connected
487 * The identifier of the device
489 * The NUMA socket id to which the device is connected or
490 * a default of zero if the socket could not be determined.
491 * -1 if returned is the dev_id value is out of range.
494 rte_cryptodev_socket_id(uint8_t dev_id);
496 /** Crypto device configuration structure */
497 struct rte_cryptodev_config {
498 int socket_id; /**< Socket to allocate resources on */
499 uint16_t nb_queue_pairs;
500 /**< Number of queue pairs to configure on device */
503 uint32_t nb_objs; /**< Number of objects in mempool */
504 uint32_t cache_size; /**< l-core object cache size */
505 } session_mp; /**< Session mempool configuration */
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
584 * - 0: Success, queue pair correctly set up.
585 * - <0: Queue pair configuration failed
588 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
589 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
592 * Start a specified queue pair of a device. It is used
593 * when deferred_start flag of the specified queue is true.
595 * @param dev_id The identifier of the device
596 * @param queue_pair_id The index of the queue pair to start. The value
597 * must be in the range [0, nb_queue_pair - 1]
598 * previously supplied to
599 * rte_crypto_dev_configure().
601 * - 0: Success, the transmit queue is correctly set up.
602 * - -EINVAL: The dev_id or the queue_id out of range.
603 * - -ENOTSUP: The function not supported in PMD driver.
606 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
609 * Stop specified queue pair of a device
611 * @param dev_id The identifier of the device
612 * @param queue_pair_id The index of the queue pair to stop. The value
613 * must be in the range [0, nb_queue_pair - 1]
614 * previously supplied to
615 * rte_cryptodev_configure().
617 * - 0: Success, the transmit queue is correctly set up.
618 * - -EINVAL: The dev_id or the queue_id out of range.
619 * - -ENOTSUP: The function not supported in PMD driver.
622 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
625 * Get the number of queue pairs on a specific crypto device
627 * @param dev_id Crypto device identifier.
629 * - The number of configured queue pairs.
632 rte_cryptodev_queue_pair_count(uint8_t dev_id);
636 * Retrieve the general I/O statistics of a device.
638 * @param dev_id The identifier of the device.
639 * @param stats A pointer to a structure of type
640 * *rte_cryptodev_stats* to be filled with the
641 * values of device counters.
643 * - Zero if successful.
644 * - Non-zero otherwise.
647 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
650 * Reset the general I/O statistics of a device.
652 * @param dev_id The identifier of the device.
655 rte_cryptodev_stats_reset(uint8_t dev_id);
658 * Retrieve the contextual information of a device.
660 * @param dev_id The identifier of the device.
661 * @param dev_info A pointer to a structure of type
662 * *rte_cryptodev_info* to be filled with the
663 * contextual information of the device.
666 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
670 * Register a callback function for specific device id.
672 * @param dev_id Device id.
673 * @param event Event interested.
674 * @param cb_fn User supplied callback function to be called.
675 * @param cb_arg Pointer to the parameters for the registered
679 * - On success, zero.
680 * - On failure, a negative value.
683 rte_cryptodev_callback_register(uint8_t dev_id,
684 enum rte_cryptodev_event_type event,
685 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
688 * Unregister a callback function for specific device id.
690 * @param dev_id The device identifier.
691 * @param event Event interested.
692 * @param cb_fn User supplied callback function to be called.
693 * @param cb_arg Pointer to the parameters for the registered
697 * - On success, zero.
698 * - On failure, a negative value.
701 rte_cryptodev_callback_unregister(uint8_t dev_id,
702 enum rte_cryptodev_event_type event,
703 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
706 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
707 struct rte_crypto_op **ops, uint16_t nb_ops);
708 /**< Dequeue processed packets from queue pair of a device. */
710 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
711 struct rte_crypto_op **ops, uint16_t nb_ops);
712 /**< Enqueue packets for processing on queue pair of a device. */
717 struct rte_cryptodev_callback;
719 /** Structure to keep track of registered callbacks */
720 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
722 /** The data structure associated with each crypto device. */
723 struct rte_cryptodev {
724 dequeue_pkt_burst_t dequeue_burst;
725 /**< Pointer to PMD receive function. */
726 enqueue_pkt_burst_t enqueue_burst;
727 /**< Pointer to PMD transmit function. */
729 struct rte_cryptodev_data *data;
730 /**< Pointer to device data */
731 struct rte_cryptodev_ops *dev_ops;
732 /**< Functions exported by PMD */
733 uint64_t feature_flags;
734 /**< Supported features */
735 struct rte_device *device;
736 /**< Backing device */
738 enum rte_cryptodev_type dev_type;
739 /**< Crypto device type */
741 struct rte_cryptodev_cb_list link_intr_cbs;
742 /**< User application callback for interrupts if present */
745 uint8_t attached : 1;
746 /**< Flag indicating the device is attached */
747 } __rte_cache_aligned;
751 * The data part, with no function pointers, associated with each device.
753 * This structure is safe to place in shared memory to be common among
754 * different processes in a multi-process configuration.
756 struct rte_cryptodev_data {
758 /**< Device ID for this instance */
760 /**< Socket ID where memory is allocated */
761 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
762 /**< Unique identifier name */
765 uint8_t dev_started : 1;
766 /**< Device state: STARTED(1)/STOPPED(0) */
768 struct rte_mempool *session_pool;
769 /**< Session memory pool */
771 /**< Array of pointers to queue pairs. */
772 uint16_t nb_queue_pairs;
773 /**< Number of device queue pairs. */
776 /**< PMD-specific private data */
777 } __rte_cache_aligned;
779 extern struct rte_cryptodev *rte_cryptodevs;
782 * Dequeue a burst of processed crypto operations from a queue on the crypto
783 * device. The dequeued operation are stored in *rte_crypto_op* structures
784 * whose pointers are supplied in the *ops* array.
786 * The rte_cryptodev_dequeue_burst() function returns the number of ops
787 * actually dequeued, which is the number of *rte_crypto_op* data structures
788 * effectively supplied into the *ops* array.
790 * A return value equal to *nb_ops* indicates that the queue contained
791 * at least *nb_ops* operations, and this is likely to signify that other
792 * processed operations remain in the devices output queue. Applications
793 * implementing a "retrieve as many processed operations as possible" policy
794 * can check this specific case and keep invoking the
795 * rte_cryptodev_dequeue_burst() function until a value less than
796 * *nb_ops* is returned.
798 * The rte_cryptodev_dequeue_burst() function does not provide any error
799 * notification to avoid the corresponding overhead.
801 * @param dev_id The symmetric crypto device identifier
802 * @param qp_id The index of the queue pair from which to
803 * retrieve processed packets. The value must be
804 * in the range [0, nb_queue_pair - 1] previously
805 * supplied to rte_cryptodev_configure().
806 * @param ops The address of an array of pointers to
807 * *rte_crypto_op* structures that must be
808 * large enough to store *nb_ops* pointers in it.
809 * @param nb_ops The maximum number of operations to dequeue.
812 * - The number of operations actually dequeued, which is the number
813 * of pointers to *rte_crypto_op* structures effectively supplied to the
816 static inline uint16_t
817 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
818 struct rte_crypto_op **ops, uint16_t nb_ops)
820 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
822 nb_ops = (*dev->dequeue_burst)
823 (dev->data->queue_pairs[qp_id], ops, nb_ops);
829 * Enqueue a burst of operations for processing on a crypto device.
831 * The rte_cryptodev_enqueue_burst() function is invoked to place
832 * crypto operations on the queue *qp_id* of the device designated by
835 * The *nb_ops* parameter is the number of operations to process which are
836 * supplied in the *ops* array of *rte_crypto_op* structures.
838 * The rte_cryptodev_enqueue_burst() function returns the number of
839 * operations it actually enqueued for processing. A return value equal to
840 * *nb_ops* means that all packets have been enqueued.
842 * @param dev_id The identifier of the device.
843 * @param qp_id The index of the queue pair which packets are
844 * to be enqueued for processing. The value
845 * must be in the range [0, nb_queue_pairs - 1]
846 * previously supplied to
847 * *rte_cryptodev_configure*.
848 * @param ops The address of an array of *nb_ops* pointers
849 * to *rte_crypto_op* structures which contain
850 * the crypto operations to be processed.
851 * @param nb_ops The number of operations to process.
854 * The number of operations actually enqueued on the crypto device. The return
855 * value can be less than the value of the *nb_ops* parameter when the
856 * crypto devices queue is full or if invalid parameters are specified in
859 static inline uint16_t
860 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
861 struct rte_crypto_op **ops, uint16_t nb_ops)
863 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
865 return (*dev->enqueue_burst)(
866 dev->data->queue_pairs[qp_id], ops, nb_ops);
870 /** Cryptodev symmetric crypto session */
871 struct rte_cryptodev_sym_session {
876 enum rte_cryptodev_type dev_type;
877 /** Crypto Device type session created on */
878 struct rte_mempool *mp;
879 /**< Mempool session allocated from */
881 /**< Public symmetric session details */
883 __extension__ char _private[0];
884 /**< Private session material */
889 * Initialise a session for symmetric cryptographic operations.
891 * This function is used by the client to initialize immutable
892 * parameters of symmetric cryptographic operation.
893 * To perform the operation the rte_cryptodev_enqueue_burst function is
894 * used. Each mbuf should contain a reference to the session
895 * pointer returned from this function contained within it's crypto_op if a
896 * session-based operation is being provisioned. Memory to contain the session
897 * information is allocated from within mempool managed by the cryptodev.
899 * The rte_cryptodev_session_free must be called to free allocated
900 * memory when the session is no longer required.
902 * @param dev_id The device identifier.
903 * @param xform Crypto transform chain.
907 * Pointer to the created session or NULL
909 extern struct rte_cryptodev_sym_session *
910 rte_cryptodev_sym_session_create(uint8_t dev_id,
911 struct rte_crypto_sym_xform *xform);
914 * Free the memory associated with a previously allocated session.
916 * @param dev_id The device identifier.
917 * @param session Session pointer previously allocated by
918 * *rte_cryptodev_sym_session_create*.
921 * NULL on successful freeing of session.
922 * Session pointer on failure to free session.
924 extern struct rte_cryptodev_sym_session *
925 rte_cryptodev_sym_session_free(uint8_t dev_id,
926 struct rte_cryptodev_sym_session *session);
929 * Attach queue pair with sym session.
931 * @param qp_id Queue pair to which session will be attached.
932 * @param session Session pointer previously allocated by
933 * *rte_cryptodev_sym_session_create*.
936 * - On success, zero.
937 * - On failure, a negative value.
940 rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
941 struct rte_cryptodev_sym_session *session);
944 * Detach queue pair with sym session.
946 * @param qp_id Queue pair to which session is attached.
947 * @param session Session pointer previously allocated by
948 * *rte_cryptodev_sym_session_create*.
951 * - On success, zero.
952 * - On failure, a negative value.
955 rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
956 struct rte_cryptodev_sym_session *session);
963 #endif /* _RTE_CRYPTODEV_H_ */