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 */
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 */
205 /** Structure used to capture a capability of a crypto device */
206 struct rte_cryptodev_capabilities {
207 enum rte_crypto_op_type op;
208 /**< Operation type */
212 struct rte_cryptodev_symmetric_capability sym;
213 /**< Symmetric operation capability parameters */
217 /** Structure used to describe crypto algorithms */
218 struct rte_cryptodev_sym_capability_idx {
219 enum rte_crypto_sym_xform_type type;
221 enum rte_crypto_cipher_algorithm cipher;
222 enum rte_crypto_auth_algorithm auth;
227 * Provide capabilities available for defined device and algorithm
229 * @param dev_id The identifier of the device.
230 * @param idx Description of crypto algorithms.
233 * - Return description of the symmetric crypto capability if exist.
234 * - Return NULL if the capability not exist.
236 const struct rte_cryptodev_symmetric_capability *
237 rte_cryptodev_sym_capability_get(uint8_t dev_id,
238 const struct rte_cryptodev_sym_capability_idx *idx);
241 * Check if key size and initial vector are supported
242 * in crypto cipher capability
244 * @param capability Description of the symmetric crypto capability.
245 * @param key_size Cipher key size.
246 * @param iv_size Cipher initial vector size.
249 * - Return 0 if the parameters are in range of the capability.
250 * - Return -1 if the parameters are out of range of the capability.
253 rte_cryptodev_sym_capability_check_cipher(
254 const struct rte_cryptodev_symmetric_capability *capability,
255 uint16_t key_size, uint16_t iv_size);
258 * Check if key size and initial vector are supported
259 * in crypto auth capability
261 * @param capability Description of the symmetric crypto capability.
262 * @param key_size Auth key size.
263 * @param digest_size Auth digest size.
264 * @param aad_size Auth aad size.
265 * @param iv_size Auth initial vector size.
268 * - Return 0 if the parameters are in range of the capability.
269 * - Return -1 if the parameters are out of range of the capability.
272 rte_cryptodev_sym_capability_check_auth(
273 const struct rte_cryptodev_symmetric_capability *capability,
274 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
278 * Provide the cipher algorithm enum, given an algorithm string
280 * @param algo_enum A pointer to the cipher algorithm
282 * @param algo_string Authentication algo string
285 * - Return -1 if string is not valid
286 * - Return 0 is the string is valid
289 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
290 const char *algo_string);
293 * Provide the authentication algorithm enum, given an algorithm string
295 * @param algo_enum A pointer to the authentication algorithm
297 * @param algo_string Authentication algo string
300 * - Return -1 if string is not valid
301 * - Return 0 is the string is valid
304 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
305 const char *algo_string);
307 /** Macro used at end of crypto PMD list */
308 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
309 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
313 * Crypto device supported feature flags
316 * New features flags should be added to the end of the list
318 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
320 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
321 /**< Symmetric crypto operations are supported */
322 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
323 /**< Asymmetric crypto operations are supported */
324 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
325 /**< Chaining symmetric crypto operations are supported */
326 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
327 /**< Utilises CPU SIMD SSE instructions */
328 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
329 /**< Utilises CPU SIMD AVX instructions */
330 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
331 /**< Utilises CPU SIMD AVX2 instructions */
332 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
333 /**< Utilises CPU AES-NI instructions */
334 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
335 /**< Operations are off-loaded to an external hardware accelerator */
336 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
337 /**< Utilises CPU SIMD AVX512 instructions */
338 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
339 /**< Scatter-gather mbufs are supported */
340 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
341 /**< Utilises CPU NEON instructions */
342 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
343 /**< Utilises ARM CPU Cryptographic Extensions */
347 * Get the name of a crypto device feature flag
349 * @param flag The mask describing the flag.
352 * The name of this flag, or NULL if it's not a valid feature flag.
356 rte_cryptodev_get_feature_name(uint64_t flag);
358 /** Crypto device information */
359 struct rte_cryptodev_info {
360 const char *driver_name; /**< Driver name. */
361 enum rte_cryptodev_type dev_type; /**< Device type */
362 struct rte_pci_device *pci_dev; /**< PCI information. */
364 uint64_t feature_flags; /**< Feature flags */
366 const struct rte_cryptodev_capabilities *capabilities;
367 /**< Array of devices supported capabilities */
369 unsigned max_nb_queue_pairs;
370 /**< Maximum number of queues pairs supported by device. */
373 unsigned max_nb_sessions;
374 /**< Maximum number of sessions supported by device. */
375 unsigned int max_nb_sessions_per_qp;
376 /**< Maximum number of sessions per queue pair.
377 * Default 0 for infinite sessions
382 #define RTE_CRYPTODEV_DETACHED (0)
383 #define RTE_CRYPTODEV_ATTACHED (1)
385 /** Definitions of Crypto device event types */
386 enum rte_cryptodev_event_type {
387 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
388 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
389 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
392 /** Crypto device queue pair configuration structure. */
393 struct rte_cryptodev_qp_conf {
394 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
398 * Typedef for application callback function to be registered by application
399 * software for notification of device events
401 * @param dev_id Crypto device identifier
402 * @param event Crypto device event to register for notification of.
403 * @param cb_arg User specified parameter to be passed as to passed to
404 * users callback function.
406 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
407 enum rte_cryptodev_event_type event, void *cb_arg);
410 /** Crypto Device statistics */
411 struct rte_cryptodev_stats {
412 uint64_t enqueued_count;
413 /**< Count of all operations enqueued */
414 uint64_t dequeued_count;
415 /**< Count of all operations dequeued */
417 uint64_t enqueue_err_count;
418 /**< Total error count on operations enqueued */
419 uint64_t dequeue_err_count;
420 /**< Total error count on operations dequeued */
423 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
424 /**< Max length of name of crypto PMD */
427 * Create a virtual crypto device
429 * @param name Cryptodev PMD name of device to be created.
430 * @param args Options arguments for device.
433 * - On successful creation of the cryptodev the device index is returned,
434 * which will be between 0 and rte_cryptodev_count().
435 * - In the case of a failure, returns -1.
438 rte_cryptodev_create_vdev(const char *name, const char *args);
441 * Get the device identifier for the named crypto device.
443 * @param name device name to select the device structure.
446 * - Returns crypto device identifier on success.
447 * - Return -1 on failure to find named crypto device.
450 rte_cryptodev_get_dev_id(const char *name);
453 * Get the total number of crypto devices that have been successfully
457 * - The total number of usable crypto devices.
460 rte_cryptodev_count(void);
463 * Get number of crypto device defined type.
465 * @param type type of device.
468 * Returns number of crypto device.
471 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
474 * Get number and identifiers of attached crypto devices that
475 * use the same crypto driver.
477 * @param driver_name driver name.
478 * @param devices output devices identifiers.
479 * @param nb_devices maximal number of devices.
482 * Returns number of attached crypto device.
485 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
488 * Return the NUMA socket to which a device is connected
491 * The identifier of the device
493 * The NUMA socket id to which the device is connected or
494 * a default of zero if the socket could not be determined.
495 * -1 if returned is the dev_id value is out of range.
498 rte_cryptodev_socket_id(uint8_t dev_id);
500 /** Crypto device configuration structure */
501 struct rte_cryptodev_config {
502 int socket_id; /**< Socket to allocate resources on */
503 uint16_t nb_queue_pairs;
504 /**< Number of queue pairs to configure on device */
507 uint32_t nb_objs; /**< Number of objects in mempool */
508 uint32_t cache_size; /**< l-core object cache size */
509 } session_mp; /**< Session mempool configuration */
513 * Configure a device.
515 * This function must be invoked first before any other function in the
516 * API. This function can also be re-invoked when a device is in the
519 * @param dev_id The identifier of the device to configure.
520 * @param config The crypto device configuration structure.
523 * - 0: Success, device configured.
524 * - <0: Error code returned by the driver configuration function.
527 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
532 * The device start step is the last one and consists of setting the configured
533 * offload features and in starting the transmit and the receive units of the
535 * On success, all basic functions exported by the API (link status,
536 * receive/transmit, and so on) can be invoked.
539 * The identifier of the device.
541 * - 0: Success, device started.
542 * - <0: Error code of the driver device start function.
545 rte_cryptodev_start(uint8_t dev_id);
548 * Stop an device. The device can be restarted with a call to
549 * rte_cryptodev_start()
551 * @param dev_id The identifier of the device.
554 rte_cryptodev_stop(uint8_t dev_id);
557 * Close an device. The device cannot be restarted!
559 * @param dev_id The identifier of the device.
562 * - 0 on successfully closing device
563 * - <0 on failure to close device
566 rte_cryptodev_close(uint8_t dev_id);
569 * Allocate and set up a receive queue pair for a device.
572 * @param dev_id The identifier of the device.
573 * @param queue_pair_id The index of the queue pairs to set up. The
574 * value must be in the range [0, nb_queue_pair
575 * - 1] previously supplied to
576 * rte_cryptodev_configure().
577 * @param qp_conf The pointer to the configuration data to be
578 * used for the queue pair. NULL value is
579 * allowed, in which case default configuration
581 * @param socket_id The *socket_id* argument is the socket
582 * identifier in case of NUMA. The value can be
583 * *SOCKET_ID_ANY* if there is no NUMA constraint
584 * for the DMA memory allocated for the receive
588 * - 0: Success, queue pair correctly set up.
589 * - <0: Queue pair configuration failed
592 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
593 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
596 * Start a specified queue pair of a device. It is used
597 * when deferred_start flag of the specified queue is true.
599 * @param dev_id The identifier of the device
600 * @param queue_pair_id The index of the queue pair to start. The value
601 * must be in the range [0, nb_queue_pair - 1]
602 * previously supplied to
603 * rte_crypto_dev_configure().
605 * - 0: Success, the transmit queue is correctly set up.
606 * - -EINVAL: The dev_id or the queue_id out of range.
607 * - -ENOTSUP: The function not supported in PMD driver.
610 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
613 * Stop specified queue pair of a device
615 * @param dev_id The identifier of the device
616 * @param queue_pair_id The index of the queue pair to stop. The value
617 * must be in the range [0, nb_queue_pair - 1]
618 * previously supplied to
619 * rte_cryptodev_configure().
621 * - 0: Success, the transmit queue is correctly set up.
622 * - -EINVAL: The dev_id or the queue_id out of range.
623 * - -ENOTSUP: The function not supported in PMD driver.
626 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
629 * Get the number of queue pairs on a specific crypto device
631 * @param dev_id Crypto device identifier.
633 * - The number of configured queue pairs.
636 rte_cryptodev_queue_pair_count(uint8_t dev_id);
640 * Retrieve the general I/O statistics of a device.
642 * @param dev_id The identifier of the device.
643 * @param stats A pointer to a structure of type
644 * *rte_cryptodev_stats* to be filled with the
645 * values of device counters.
647 * - Zero if successful.
648 * - Non-zero otherwise.
651 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
654 * Reset the general I/O statistics of a device.
656 * @param dev_id The identifier of the device.
659 rte_cryptodev_stats_reset(uint8_t dev_id);
662 * Retrieve the contextual information of a device.
664 * @param dev_id The identifier of the device.
665 * @param dev_info A pointer to a structure of type
666 * *rte_cryptodev_info* to be filled with the
667 * contextual information of the device.
670 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
674 * Register a callback function for specific device id.
676 * @param dev_id Device id.
677 * @param event Event interested.
678 * @param cb_fn User supplied callback function to be called.
679 * @param cb_arg Pointer to the parameters for the registered
683 * - On success, zero.
684 * - On failure, a negative value.
687 rte_cryptodev_callback_register(uint8_t dev_id,
688 enum rte_cryptodev_event_type event,
689 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
692 * Unregister a callback function for specific device id.
694 * @param dev_id The device identifier.
695 * @param event Event interested.
696 * @param cb_fn User supplied callback function to be called.
697 * @param cb_arg Pointer to the parameters for the registered
701 * - On success, zero.
702 * - On failure, a negative value.
705 rte_cryptodev_callback_unregister(uint8_t dev_id,
706 enum rte_cryptodev_event_type event,
707 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
710 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
711 struct rte_crypto_op **ops, uint16_t nb_ops);
712 /**< Dequeue processed packets from queue pair of a device. */
714 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
715 struct rte_crypto_op **ops, uint16_t nb_ops);
716 /**< Enqueue packets for processing on queue pair of a device. */
721 struct rte_cryptodev_callback;
723 /** Structure to keep track of registered callbacks */
724 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
726 /** The data structure associated with each crypto device. */
727 struct rte_cryptodev {
728 dequeue_pkt_burst_t dequeue_burst;
729 /**< Pointer to PMD receive function. */
730 enqueue_pkt_burst_t enqueue_burst;
731 /**< Pointer to PMD transmit function. */
733 struct rte_cryptodev_data *data;
734 /**< Pointer to device data */
735 struct rte_cryptodev_ops *dev_ops;
736 /**< Functions exported by PMD */
737 uint64_t feature_flags;
738 /**< Supported features */
739 struct rte_device *device;
740 /**< Backing device */
742 enum rte_cryptodev_type dev_type;
743 /**< Crypto device type */
745 struct rte_cryptodev_cb_list link_intr_cbs;
746 /**< User application callback for interrupts if present */
749 uint8_t attached : 1;
750 /**< Flag indicating the device is attached */
751 } __rte_cache_aligned;
755 * The data part, with no function pointers, associated with each device.
757 * This structure is safe to place in shared memory to be common among
758 * different processes in a multi-process configuration.
760 struct rte_cryptodev_data {
762 /**< Device ID for this instance */
764 /**< Socket ID where memory is allocated */
765 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
766 /**< Unique identifier name */
769 uint8_t dev_started : 1;
770 /**< Device state: STARTED(1)/STOPPED(0) */
772 struct rte_mempool *session_pool;
773 /**< Session memory pool */
775 /**< Array of pointers to queue pairs. */
776 uint16_t nb_queue_pairs;
777 /**< Number of device queue pairs. */
780 /**< PMD-specific private data */
781 } __rte_cache_aligned;
783 extern struct rte_cryptodev *rte_cryptodevs;
786 * Dequeue a burst of processed crypto operations from a queue on the crypto
787 * device. The dequeued operation are stored in *rte_crypto_op* structures
788 * whose pointers are supplied in the *ops* array.
790 * The rte_cryptodev_dequeue_burst() function returns the number of ops
791 * actually dequeued, which is the number of *rte_crypto_op* data structures
792 * effectively supplied into the *ops* array.
794 * A return value equal to *nb_ops* indicates that the queue contained
795 * at least *nb_ops* operations, and this is likely to signify that other
796 * processed operations remain in the devices output queue. Applications
797 * implementing a "retrieve as many processed operations as possible" policy
798 * can check this specific case and keep invoking the
799 * rte_cryptodev_dequeue_burst() function until a value less than
800 * *nb_ops* is returned.
802 * The rte_cryptodev_dequeue_burst() function does not provide any error
803 * notification to avoid the corresponding overhead.
805 * @param dev_id The symmetric crypto device identifier
806 * @param qp_id The index of the queue pair from which to
807 * retrieve processed packets. The value must be
808 * in the range [0, nb_queue_pair - 1] previously
809 * supplied to rte_cryptodev_configure().
810 * @param ops The address of an array of pointers to
811 * *rte_crypto_op* structures that must be
812 * large enough to store *nb_ops* pointers in it.
813 * @param nb_ops The maximum number of operations to dequeue.
816 * - The number of operations actually dequeued, which is the number
817 * of pointers to *rte_crypto_op* structures effectively supplied to the
820 static inline uint16_t
821 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
822 struct rte_crypto_op **ops, uint16_t nb_ops)
824 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
826 nb_ops = (*dev->dequeue_burst)
827 (dev->data->queue_pairs[qp_id], ops, nb_ops);
833 * Enqueue a burst of operations for processing on a crypto device.
835 * The rte_cryptodev_enqueue_burst() function is invoked to place
836 * crypto operations on the queue *qp_id* of the device designated by
839 * The *nb_ops* parameter is the number of operations to process which are
840 * supplied in the *ops* array of *rte_crypto_op* structures.
842 * The rte_cryptodev_enqueue_burst() function returns the number of
843 * operations it actually enqueued for processing. A return value equal to
844 * *nb_ops* means that all packets have been enqueued.
846 * @param dev_id The identifier of the device.
847 * @param qp_id The index of the queue pair which packets are
848 * to be enqueued for processing. The value
849 * must be in the range [0, nb_queue_pairs - 1]
850 * previously supplied to
851 * *rte_cryptodev_configure*.
852 * @param ops The address of an array of *nb_ops* pointers
853 * to *rte_crypto_op* structures which contain
854 * the crypto operations to be processed.
855 * @param nb_ops The number of operations to process.
858 * The number of operations actually enqueued on the crypto device. The return
859 * value can be less than the value of the *nb_ops* parameter when the
860 * crypto devices queue is full or if invalid parameters are specified in
863 static inline uint16_t
864 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
865 struct rte_crypto_op **ops, uint16_t nb_ops)
867 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
869 return (*dev->enqueue_burst)(
870 dev->data->queue_pairs[qp_id], ops, nb_ops);
874 /** Cryptodev symmetric crypto session */
875 struct rte_cryptodev_sym_session {
880 enum rte_cryptodev_type dev_type;
881 /** Crypto Device type session created on */
882 struct rte_mempool *mp;
883 /**< Mempool session allocated from */
885 /**< Public symmetric session details */
887 __extension__ char _private[0];
888 /**< Private session material */
893 * Initialise a session for symmetric cryptographic operations.
895 * This function is used by the client to initialize immutable
896 * parameters of symmetric cryptographic operation.
897 * To perform the operation the rte_cryptodev_enqueue_burst function is
898 * used. Each mbuf should contain a reference to the session
899 * pointer returned from this function contained within it's crypto_op if a
900 * session-based operation is being provisioned. Memory to contain the session
901 * information is allocated from within mempool managed by the cryptodev.
903 * The rte_cryptodev_session_free must be called to free allocated
904 * memory when the session is no longer required.
906 * @param dev_id The device identifier.
907 * @param xform Crypto transform chain.
911 * Pointer to the created session or NULL
913 extern struct rte_cryptodev_sym_session *
914 rte_cryptodev_sym_session_create(uint8_t dev_id,
915 struct rte_crypto_sym_xform *xform);
918 * Free the memory associated with a previously allocated session.
920 * @param dev_id The device identifier.
921 * @param session Session pointer previously allocated by
922 * *rte_cryptodev_sym_session_create*.
925 * NULL on successful freeing of session.
926 * Session pointer on failure to free session.
928 extern struct rte_cryptodev_sym_session *
929 rte_cryptodev_sym_session_free(uint8_t dev_id,
930 struct rte_cryptodev_sym_session *session);
933 * Attach queue pair with sym session.
935 * @param qp_id Queue pair to which session will be attached.
936 * @param session Session pointer previously allocated by
937 * *rte_cryptodev_sym_session_create*.
940 * - On success, zero.
941 * - On failure, a negative value.
944 rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
945 struct rte_cryptodev_sym_session *session);
948 * Detach queue pair with sym session.
950 * @param qp_id Queue pair to which session is attached.
951 * @param session Session pointer previously allocated by
952 * *rte_cryptodev_sym_session_create*.
955 * - On success, zero.
956 * - On failure, a negative value.
959 rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
960 struct rte_cryptodev_sym_session *session);
967 #endif /* _RTE_CRYPTODEV_H_ */