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 / AEAD */
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 */
187 struct rte_crypto_param_range iv_size;
188 /**< Initialisation vector data size range */
190 /**< Symmetric Authentication transform capabilities */
192 enum rte_crypto_cipher_algorithm algo;
193 /**< cipher algorithm */
195 /**< algorithm block size */
196 struct rte_crypto_param_range key_size;
197 /**< cipher key size range */
198 struct rte_crypto_param_range iv_size;
199 /**< Initialisation vector data size range */
201 /**< Symmetric Cipher transform capabilities */
203 enum rte_crypto_aead_algorithm algo;
204 /**< AEAD algorithm */
206 /**< algorithm block size */
207 struct rte_crypto_param_range key_size;
208 /**< AEAD key size range */
209 struct rte_crypto_param_range digest_size;
210 /**< digest size range */
211 struct rte_crypto_param_range aad_size;
212 /**< Additional authentication data size range */
213 struct rte_crypto_param_range iv_size;
214 /**< Initialisation vector data size range */
219 /** Structure used to capture a capability of a crypto device */
220 struct rte_cryptodev_capabilities {
221 enum rte_crypto_op_type op;
222 /**< Operation type */
226 struct rte_cryptodev_symmetric_capability sym;
227 /**< Symmetric operation capability parameters */
231 /** Structure used to describe crypto algorithms */
232 struct rte_cryptodev_sym_capability_idx {
233 enum rte_crypto_sym_xform_type type;
235 enum rte_crypto_cipher_algorithm cipher;
236 enum rte_crypto_auth_algorithm auth;
237 enum rte_crypto_aead_algorithm aead;
242 * Provide capabilities available for defined device and algorithm
244 * @param dev_id The identifier of the device.
245 * @param idx Description of crypto algorithms.
248 * - Return description of the symmetric crypto capability if exist.
249 * - Return NULL if the capability not exist.
251 const struct rte_cryptodev_symmetric_capability *
252 rte_cryptodev_sym_capability_get(uint8_t dev_id,
253 const struct rte_cryptodev_sym_capability_idx *idx);
256 * Check if key size and initial vector are supported
257 * in crypto cipher capability
259 * @param capability Description of the symmetric crypto capability.
260 * @param key_size Cipher key size.
261 * @param iv_size Cipher initial vector size.
264 * - Return 0 if the parameters are in range of the capability.
265 * - Return -1 if the parameters are out of range of the capability.
268 rte_cryptodev_sym_capability_check_cipher(
269 const struct rte_cryptodev_symmetric_capability *capability,
270 uint16_t key_size, uint16_t iv_size);
273 * Check if key size and initial vector are supported
274 * in crypto auth capability
276 * @param capability Description of the symmetric crypto capability.
277 * @param key_size Auth key size.
278 * @param digest_size Auth digest size.
279 * @param aad_size Auth aad size.
280 * @param iv_size Auth initial vector size.
283 * - Return 0 if the parameters are in range of the capability.
284 * - Return -1 if the parameters are out of range of the capability.
287 rte_cryptodev_sym_capability_check_auth(
288 const struct rte_cryptodev_symmetric_capability *capability,
289 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
293 * Check if key, digest, AAD and initial vector sizes are supported
294 * in crypto AEAD capability
296 * @param capability Description of the symmetric crypto capability.
297 * @param key_size AEAD key size.
298 * @param digest_size AEAD digest size.
299 * @param aad_size AEAD AAD size.
300 * @param iv_size AEAD IV size.
303 * - Return 0 if the parameters are in range of the capability.
304 * - Return -1 if the parameters are out of range of the capability.
307 rte_cryptodev_sym_capability_check_aead(
308 const struct rte_cryptodev_symmetric_capability *capability,
309 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
313 * Provide the cipher algorithm enum, given an algorithm string
315 * @param algo_enum A pointer to the cipher algorithm
317 * @param algo_string Authentication algo string
320 * - Return -1 if string is not valid
321 * - Return 0 is the string is valid
324 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
325 const char *algo_string);
328 * Provide the authentication algorithm enum, given an algorithm string
330 * @param algo_enum A pointer to the authentication algorithm
332 * @param algo_string Authentication algo string
335 * - Return -1 if string is not valid
336 * - Return 0 is the string is valid
339 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
340 const char *algo_string);
343 * Provide the AEAD algorithm enum, given an algorithm string
345 * @param algo_enum A pointer to the AEAD algorithm
347 * @param algo_string AEAD algorithm string
350 * - Return -1 if string is not valid
351 * - Return 0 is the string is valid
354 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
355 const char *algo_string);
357 /** Macro used at end of crypto PMD list */
358 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
359 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
363 * Crypto device supported feature flags
366 * New features flags should be added to the end of the list
368 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
370 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
371 /**< Symmetric crypto operations are supported */
372 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
373 /**< Asymmetric crypto operations are supported */
374 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
375 /**< Chaining symmetric crypto operations are supported */
376 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
377 /**< Utilises CPU SIMD SSE instructions */
378 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
379 /**< Utilises CPU SIMD AVX instructions */
380 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
381 /**< Utilises CPU SIMD AVX2 instructions */
382 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
383 /**< Utilises CPU AES-NI instructions */
384 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
385 /**< Operations are off-loaded to an external hardware accelerator */
386 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
387 /**< Utilises CPU SIMD AVX512 instructions */
388 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
389 /**< Scatter-gather mbufs are supported */
390 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
391 /**< Utilises CPU NEON instructions */
392 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
393 /**< Utilises ARM CPU Cryptographic Extensions */
397 * Get the name of a crypto device feature flag
399 * @param flag The mask describing the flag.
402 * The name of this flag, or NULL if it's not a valid feature flag.
406 rte_cryptodev_get_feature_name(uint64_t flag);
408 /** Crypto device information */
409 struct rte_cryptodev_info {
410 const char *driver_name; /**< Driver name. */
411 enum rte_cryptodev_type dev_type; /**< Device type */
412 struct rte_pci_device *pci_dev; /**< PCI information. */
414 uint64_t feature_flags; /**< Feature flags */
416 const struct rte_cryptodev_capabilities *capabilities;
417 /**< Array of devices supported capabilities */
419 unsigned max_nb_queue_pairs;
420 /**< Maximum number of queues pairs supported by device. */
423 unsigned max_nb_sessions;
424 /**< Maximum number of sessions supported by device. */
425 unsigned int max_nb_sessions_per_qp;
426 /**< Maximum number of sessions per queue pair.
427 * Default 0 for infinite sessions
432 #define RTE_CRYPTODEV_DETACHED (0)
433 #define RTE_CRYPTODEV_ATTACHED (1)
435 /** Definitions of Crypto device event types */
436 enum rte_cryptodev_event_type {
437 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
438 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
439 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
442 /** Crypto device queue pair configuration structure. */
443 struct rte_cryptodev_qp_conf {
444 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
448 * Typedef for application callback function to be registered by application
449 * software for notification of device events
451 * @param dev_id Crypto device identifier
452 * @param event Crypto device event to register for notification of.
453 * @param cb_arg User specified parameter to be passed as to passed to
454 * users callback function.
456 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
457 enum rte_cryptodev_event_type event, void *cb_arg);
460 /** Crypto Device statistics */
461 struct rte_cryptodev_stats {
462 uint64_t enqueued_count;
463 /**< Count of all operations enqueued */
464 uint64_t dequeued_count;
465 /**< Count of all operations dequeued */
467 uint64_t enqueue_err_count;
468 /**< Total error count on operations enqueued */
469 uint64_t dequeue_err_count;
470 /**< Total error count on operations dequeued */
473 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
474 /**< Max length of name of crypto PMD */
477 * Create a virtual crypto device
479 * @param name Cryptodev PMD name of device to be created.
480 * @param args Options arguments for device.
483 * - On successful creation of the cryptodev the device index is returned,
484 * which will be between 0 and rte_cryptodev_count().
485 * - In the case of a failure, returns -1.
488 rte_cryptodev_create_vdev(const char *name, const char *args);
491 * Get the device identifier for the named crypto device.
493 * @param name device name to select the device structure.
496 * - Returns crypto device identifier on success.
497 * - Return -1 on failure to find named crypto device.
500 rte_cryptodev_get_dev_id(const char *name);
503 * Get the total number of crypto devices that have been successfully
507 * - The total number of usable crypto devices.
510 rte_cryptodev_count(void);
513 * Get number of crypto device defined type.
515 * @param type type of device.
518 * Returns number of crypto device.
521 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
524 * Get number and identifiers of attached crypto devices that
525 * use the same crypto driver.
527 * @param driver_name driver name.
528 * @param devices output devices identifiers.
529 * @param nb_devices maximal number of devices.
532 * Returns number of attached crypto device.
535 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
538 * Return the NUMA socket to which a device is connected
541 * The identifier of the device
543 * The NUMA socket id to which the device is connected or
544 * a default of zero if the socket could not be determined.
545 * -1 if returned is the dev_id value is out of range.
548 rte_cryptodev_socket_id(uint8_t dev_id);
550 /** Crypto device configuration structure */
551 struct rte_cryptodev_config {
552 int socket_id; /**< Socket to allocate resources on */
553 uint16_t nb_queue_pairs;
554 /**< Number of queue pairs to configure on device */
557 uint32_t nb_objs; /**< Number of objects in mempool */
558 uint32_t cache_size; /**< l-core object cache size */
559 } session_mp; /**< Session mempool configuration */
563 * Configure a device.
565 * This function must be invoked first before any other function in the
566 * API. This function can also be re-invoked when a device is in the
569 * @param dev_id The identifier of the device to configure.
570 * @param config The crypto device configuration structure.
573 * - 0: Success, device configured.
574 * - <0: Error code returned by the driver configuration function.
577 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
582 * The device start step is the last one and consists of setting the configured
583 * offload features and in starting the transmit and the receive units of the
585 * On success, all basic functions exported by the API (link status,
586 * receive/transmit, and so on) can be invoked.
589 * The identifier of the device.
591 * - 0: Success, device started.
592 * - <0: Error code of the driver device start function.
595 rte_cryptodev_start(uint8_t dev_id);
598 * Stop an device. The device can be restarted with a call to
599 * rte_cryptodev_start()
601 * @param dev_id The identifier of the device.
604 rte_cryptodev_stop(uint8_t dev_id);
607 * Close an device. The device cannot be restarted!
609 * @param dev_id The identifier of the device.
612 * - 0 on successfully closing device
613 * - <0 on failure to close device
616 rte_cryptodev_close(uint8_t dev_id);
619 * Allocate and set up a receive queue pair for a device.
622 * @param dev_id The identifier of the device.
623 * @param queue_pair_id The index of the queue pairs to set up. The
624 * value must be in the range [0, nb_queue_pair
625 * - 1] previously supplied to
626 * rte_cryptodev_configure().
627 * @param qp_conf The pointer to the configuration data to be
628 * used for the queue pair. NULL value is
629 * allowed, in which case default configuration
631 * @param socket_id The *socket_id* argument is the socket
632 * identifier in case of NUMA. The value can be
633 * *SOCKET_ID_ANY* if there is no NUMA constraint
634 * for the DMA memory allocated for the receive
638 * - 0: Success, queue pair correctly set up.
639 * - <0: Queue pair configuration failed
642 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
643 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
646 * Start a specified queue pair of a device. It is used
647 * when deferred_start flag of the specified queue is true.
649 * @param dev_id The identifier of the device
650 * @param queue_pair_id The index of the queue pair to start. The value
651 * must be in the range [0, nb_queue_pair - 1]
652 * previously supplied to
653 * rte_crypto_dev_configure().
655 * - 0: Success, the transmit queue is correctly set up.
656 * - -EINVAL: The dev_id or the queue_id out of range.
657 * - -ENOTSUP: The function not supported in PMD driver.
660 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
663 * Stop specified queue pair of a device
665 * @param dev_id The identifier of the device
666 * @param queue_pair_id The index of the queue pair to stop. The value
667 * must be in the range [0, nb_queue_pair - 1]
668 * previously supplied to
669 * rte_cryptodev_configure().
671 * - 0: Success, the transmit queue is correctly set up.
672 * - -EINVAL: The dev_id or the queue_id out of range.
673 * - -ENOTSUP: The function not supported in PMD driver.
676 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
679 * Get the number of queue pairs on a specific crypto device
681 * @param dev_id Crypto device identifier.
683 * - The number of configured queue pairs.
686 rte_cryptodev_queue_pair_count(uint8_t dev_id);
690 * Retrieve the general I/O statistics of a device.
692 * @param dev_id The identifier of the device.
693 * @param stats A pointer to a structure of type
694 * *rte_cryptodev_stats* to be filled with the
695 * values of device counters.
697 * - Zero if successful.
698 * - Non-zero otherwise.
701 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
704 * Reset the general I/O statistics of a device.
706 * @param dev_id The identifier of the device.
709 rte_cryptodev_stats_reset(uint8_t dev_id);
712 * Retrieve the contextual information of a device.
714 * @param dev_id The identifier of the device.
715 * @param dev_info A pointer to a structure of type
716 * *rte_cryptodev_info* to be filled with the
717 * contextual information of the device.
720 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
724 * Register a callback function for specific device id.
726 * @param dev_id Device id.
727 * @param event Event interested.
728 * @param cb_fn User supplied callback function to be called.
729 * @param cb_arg Pointer to the parameters for the registered
733 * - On success, zero.
734 * - On failure, a negative value.
737 rte_cryptodev_callback_register(uint8_t dev_id,
738 enum rte_cryptodev_event_type event,
739 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
742 * Unregister a callback function for specific device id.
744 * @param dev_id The device identifier.
745 * @param event Event interested.
746 * @param cb_fn User supplied callback function to be called.
747 * @param cb_arg Pointer to the parameters for the registered
751 * - On success, zero.
752 * - On failure, a negative value.
755 rte_cryptodev_callback_unregister(uint8_t dev_id,
756 enum rte_cryptodev_event_type event,
757 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
760 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
761 struct rte_crypto_op **ops, uint16_t nb_ops);
762 /**< Dequeue processed packets from queue pair of a device. */
764 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
765 struct rte_crypto_op **ops, uint16_t nb_ops);
766 /**< Enqueue packets for processing on queue pair of a device. */
771 struct rte_cryptodev_callback;
773 /** Structure to keep track of registered callbacks */
774 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
776 /** The data structure associated with each crypto device. */
777 struct rte_cryptodev {
778 dequeue_pkt_burst_t dequeue_burst;
779 /**< Pointer to PMD receive function. */
780 enqueue_pkt_burst_t enqueue_burst;
781 /**< Pointer to PMD transmit function. */
783 struct rte_cryptodev_data *data;
784 /**< Pointer to device data */
785 struct rte_cryptodev_ops *dev_ops;
786 /**< Functions exported by PMD */
787 uint64_t feature_flags;
788 /**< Supported features */
789 struct rte_device *device;
790 /**< Backing device */
792 enum rte_cryptodev_type dev_type;
793 /**< Crypto device type */
795 struct rte_cryptodev_cb_list link_intr_cbs;
796 /**< User application callback for interrupts if present */
799 uint8_t attached : 1;
800 /**< Flag indicating the device is attached */
801 } __rte_cache_aligned;
805 * The data part, with no function pointers, associated with each device.
807 * This structure is safe to place in shared memory to be common among
808 * different processes in a multi-process configuration.
810 struct rte_cryptodev_data {
812 /**< Device ID for this instance */
814 /**< Socket ID where memory is allocated */
815 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
816 /**< Unique identifier name */
819 uint8_t dev_started : 1;
820 /**< Device state: STARTED(1)/STOPPED(0) */
822 struct rte_mempool *session_pool;
823 /**< Session memory pool */
825 /**< Array of pointers to queue pairs. */
826 uint16_t nb_queue_pairs;
827 /**< Number of device queue pairs. */
830 /**< PMD-specific private data */
831 } __rte_cache_aligned;
833 extern struct rte_cryptodev *rte_cryptodevs;
836 * Dequeue a burst of processed crypto operations from a queue on the crypto
837 * device. The dequeued operation are stored in *rte_crypto_op* structures
838 * whose pointers are supplied in the *ops* array.
840 * The rte_cryptodev_dequeue_burst() function returns the number of ops
841 * actually dequeued, which is the number of *rte_crypto_op* data structures
842 * effectively supplied into the *ops* array.
844 * A return value equal to *nb_ops* indicates that the queue contained
845 * at least *nb_ops* operations, and this is likely to signify that other
846 * processed operations remain in the devices output queue. Applications
847 * implementing a "retrieve as many processed operations as possible" policy
848 * can check this specific case and keep invoking the
849 * rte_cryptodev_dequeue_burst() function until a value less than
850 * *nb_ops* is returned.
852 * The rte_cryptodev_dequeue_burst() function does not provide any error
853 * notification to avoid the corresponding overhead.
855 * @param dev_id The symmetric crypto device identifier
856 * @param qp_id The index of the queue pair from which to
857 * retrieve processed packets. The value must be
858 * in the range [0, nb_queue_pair - 1] previously
859 * supplied to rte_cryptodev_configure().
860 * @param ops The address of an array of pointers to
861 * *rte_crypto_op* structures that must be
862 * large enough to store *nb_ops* pointers in it.
863 * @param nb_ops The maximum number of operations to dequeue.
866 * - The number of operations actually dequeued, which is the number
867 * of pointers to *rte_crypto_op* structures effectively supplied to the
870 static inline uint16_t
871 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
872 struct rte_crypto_op **ops, uint16_t nb_ops)
874 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
876 nb_ops = (*dev->dequeue_burst)
877 (dev->data->queue_pairs[qp_id], ops, nb_ops);
883 * Enqueue a burst of operations for processing on a crypto device.
885 * The rte_cryptodev_enqueue_burst() function is invoked to place
886 * crypto operations on the queue *qp_id* of the device designated by
889 * The *nb_ops* parameter is the number of operations to process which are
890 * supplied in the *ops* array of *rte_crypto_op* structures.
892 * The rte_cryptodev_enqueue_burst() function returns the number of
893 * operations it actually enqueued for processing. A return value equal to
894 * *nb_ops* means that all packets have been enqueued.
896 * @param dev_id The identifier of the device.
897 * @param qp_id The index of the queue pair which packets are
898 * to be enqueued for processing. The value
899 * must be in the range [0, nb_queue_pairs - 1]
900 * previously supplied to
901 * *rte_cryptodev_configure*.
902 * @param ops The address of an array of *nb_ops* pointers
903 * to *rte_crypto_op* structures which contain
904 * the crypto operations to be processed.
905 * @param nb_ops The number of operations to process.
908 * The number of operations actually enqueued on the crypto device. The return
909 * value can be less than the value of the *nb_ops* parameter when the
910 * crypto devices queue is full or if invalid parameters are specified in
913 static inline uint16_t
914 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
915 struct rte_crypto_op **ops, uint16_t nb_ops)
917 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
919 return (*dev->enqueue_burst)(
920 dev->data->queue_pairs[qp_id], ops, nb_ops);
924 /** Cryptodev symmetric crypto session */
925 struct rte_cryptodev_sym_session {
930 enum rte_cryptodev_type dev_type;
931 /** Crypto Device type session created on */
932 struct rte_mempool *mp;
933 /**< Mempool session allocated from */
935 /**< Public symmetric session details */
937 __extension__ char _private[0];
938 /**< Private session material */
943 * Initialise a session for symmetric cryptographic operations.
945 * This function is used by the client to initialize immutable
946 * parameters of symmetric cryptographic operation.
947 * To perform the operation the rte_cryptodev_enqueue_burst function is
948 * used. Each mbuf should contain a reference to the session
949 * pointer returned from this function contained within it's crypto_op if a
950 * session-based operation is being provisioned. Memory to contain the session
951 * information is allocated from within mempool managed by the cryptodev.
953 * The rte_cryptodev_session_free must be called to free allocated
954 * memory when the session is no longer required.
956 * @param dev_id The device identifier.
957 * @param xform Crypto transform chain.
961 * Pointer to the created session or NULL
963 extern struct rte_cryptodev_sym_session *
964 rte_cryptodev_sym_session_create(uint8_t dev_id,
965 struct rte_crypto_sym_xform *xform);
968 * Free the memory associated with a previously allocated session.
970 * @param dev_id The device identifier.
971 * @param session Session pointer previously allocated by
972 * *rte_cryptodev_sym_session_create*.
975 * NULL on successful freeing of session.
976 * Session pointer on failure to free session.
978 extern struct rte_cryptodev_sym_session *
979 rte_cryptodev_sym_session_free(uint8_t dev_id,
980 struct rte_cryptodev_sym_session *session);
983 * Attach queue pair with sym session.
985 * @param qp_id Queue pair to which session will be attached.
986 * @param session Session pointer previously allocated by
987 * *rte_cryptodev_sym_session_create*.
990 * - On success, zero.
991 * - On failure, a negative value.
994 rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
995 struct rte_cryptodev_sym_session *session);
998 * Detach queue pair with sym session.
1000 * @param qp_id Queue pair to which session is 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.
1009 rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
1010 struct rte_cryptodev_sym_session *session);
1017 #endif /* _RTE_CRYPTODEV_H_ */