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 crypto_dpaa2_sec
75 /**< NXP DPAA2 - SEC PMD device name */
77 extern const char **rte_cyptodev_names;
81 #define CDEV_LOG_ERR(...) \
82 RTE_LOG(ERR, CRYPTODEV, \
83 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
84 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
86 #define CDEV_PMD_LOG_ERR(dev, ...) \
87 RTE_LOG(ERR, CRYPTODEV, \
88 RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
89 dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
91 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
92 #define CDEV_LOG_DEBUG(...) \
93 RTE_LOG(DEBUG, 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_TRACE(...) \
98 RTE_LOG(DEBUG, CRYPTODEV, \
99 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
100 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
103 #define CDEV_LOG_DEBUG(...) (void)0
104 #define CDEV_PMD_TRACE(...) (void)0
110 * A macro that points to an offset from the start
111 * of the crypto operation structure (rte_crypto_op)
113 * The returned pointer is cast to type t.
116 * The crypto operation.
118 * The offset from the start of the crypto operation.
120 * The type to cast the result into.
122 #define rte_crypto_op_ctod_offset(c, t, o) \
123 ((t)((char *)(c) + (o)))
126 * A macro that returns the physical address that points
127 * to an offset from the start of the crypto operation
131 * The crypto operation.
133 * The offset from the start of the crypto operation
134 * to calculate address from.
136 #define rte_crypto_op_ctophys_offset(c, o) \
137 (phys_addr_t)((c)->phys_addr + (o))
140 * Crypto parameters range description
142 struct rte_crypto_param_range {
143 uint16_t min; /**< minimum size */
144 uint16_t max; /**< maximum size */
146 /**< if a range of sizes are supported,
147 * this parameter is used to indicate
148 * increments in byte size that are supported
149 * between the minimum and maximum
154 * Symmetric Crypto Capability
156 struct rte_cryptodev_symmetric_capability {
157 enum rte_crypto_sym_xform_type xform_type;
158 /**< Transform type : Authentication / Cipher / AEAD */
162 enum rte_crypto_auth_algorithm algo;
163 /**< authentication algorithm */
165 /**< algorithm block size */
166 struct rte_crypto_param_range key_size;
167 /**< auth key size range */
168 struct rte_crypto_param_range digest_size;
169 /**< digest size range */
170 struct rte_crypto_param_range aad_size;
171 /**< Additional authentication data size range */
172 struct rte_crypto_param_range iv_size;
173 /**< Initialisation vector data size range */
175 /**< Symmetric Authentication transform capabilities */
177 enum rte_crypto_cipher_algorithm algo;
178 /**< cipher algorithm */
180 /**< algorithm block size */
181 struct rte_crypto_param_range key_size;
182 /**< cipher key size range */
183 struct rte_crypto_param_range iv_size;
184 /**< Initialisation vector data size range */
186 /**< Symmetric Cipher transform capabilities */
188 enum rte_crypto_aead_algorithm algo;
189 /**< AEAD algorithm */
191 /**< algorithm block size */
192 struct rte_crypto_param_range key_size;
193 /**< AEAD key size range */
194 struct rte_crypto_param_range digest_size;
195 /**< digest size range */
196 struct rte_crypto_param_range aad_size;
197 /**< Additional authentication data size range */
198 struct rte_crypto_param_range iv_size;
199 /**< Initialisation vector data size range */
204 /** Structure used to capture a capability of a crypto device */
205 struct rte_cryptodev_capabilities {
206 enum rte_crypto_op_type op;
207 /**< Operation type */
211 struct rte_cryptodev_symmetric_capability sym;
212 /**< Symmetric operation capability parameters */
216 /** Structure used to describe crypto algorithms */
217 struct rte_cryptodev_sym_capability_idx {
218 enum rte_crypto_sym_xform_type type;
220 enum rte_crypto_cipher_algorithm cipher;
221 enum rte_crypto_auth_algorithm auth;
222 enum rte_crypto_aead_algorithm aead;
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 * Check if key, digest, AAD and initial vector sizes are supported
279 * in crypto AEAD capability
281 * @param capability Description of the symmetric crypto capability.
282 * @param key_size AEAD key size.
283 * @param digest_size AEAD digest size.
284 * @param aad_size AEAD AAD size.
285 * @param iv_size AEAD IV size.
288 * - Return 0 if the parameters are in range of the capability.
289 * - Return -1 if the parameters are out of range of the capability.
292 rte_cryptodev_sym_capability_check_aead(
293 const struct rte_cryptodev_symmetric_capability *capability,
294 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
298 * Provide the cipher algorithm enum, given an algorithm string
300 * @param algo_enum A pointer to the cipher algorithm
302 * @param algo_string Authentication algo string
305 * - Return -1 if string is not valid
306 * - Return 0 is the string is valid
309 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
310 const char *algo_string);
313 * Provide the authentication algorithm enum, given an algorithm string
315 * @param algo_enum A pointer to the authentication 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_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
325 const char *algo_string);
328 * Provide the AEAD algorithm enum, given an algorithm string
330 * @param algo_enum A pointer to the AEAD algorithm
332 * @param algo_string AEAD algorithm string
335 * - Return -1 if string is not valid
336 * - Return 0 is the string is valid
339 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
340 const char *algo_string);
342 /** Macro used at end of crypto PMD list */
343 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
344 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
348 * Crypto device supported feature flags
351 * New features flags should be added to the end of the list
353 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
355 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
356 /**< Symmetric crypto operations are supported */
357 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
358 /**< Asymmetric crypto operations are supported */
359 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
360 /**< Chaining symmetric crypto operations are supported */
361 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
362 /**< Utilises CPU SIMD SSE instructions */
363 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
364 /**< Utilises CPU SIMD AVX instructions */
365 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
366 /**< Utilises CPU SIMD AVX2 instructions */
367 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
368 /**< Utilises CPU AES-NI instructions */
369 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
370 /**< Operations are off-loaded to an external hardware accelerator */
371 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
372 /**< Utilises CPU SIMD AVX512 instructions */
373 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
374 /**< Scatter-gather mbufs are supported */
375 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
376 /**< Utilises CPU NEON instructions */
377 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
378 /**< Utilises ARM CPU Cryptographic Extensions */
382 * Get the name of a crypto device feature flag
384 * @param flag The mask describing the flag.
387 * The name of this flag, or NULL if it's not a valid feature flag.
391 rte_cryptodev_get_feature_name(uint64_t flag);
393 /** Crypto device information */
394 struct rte_cryptodev_info {
395 const char *driver_name; /**< Driver name. */
396 uint8_t driver_id; /**< Driver identifier */
397 struct rte_pci_device *pci_dev; /**< PCI information. */
399 uint64_t feature_flags; /**< Feature flags */
401 const struct rte_cryptodev_capabilities *capabilities;
402 /**< Array of devices supported capabilities */
404 unsigned max_nb_queue_pairs;
405 /**< Maximum number of queues pairs supported by device. */
408 unsigned max_nb_sessions;
409 /**< Maximum number of sessions supported by device. */
410 unsigned int max_nb_sessions_per_qp;
411 /**< Maximum number of sessions per queue pair.
412 * Default 0 for infinite sessions
417 #define RTE_CRYPTODEV_DETACHED (0)
418 #define RTE_CRYPTODEV_ATTACHED (1)
420 /** Definitions of Crypto device event types */
421 enum rte_cryptodev_event_type {
422 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
423 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
424 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
427 /** Crypto device queue pair configuration structure. */
428 struct rte_cryptodev_qp_conf {
429 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
433 * Typedef for application callback function to be registered by application
434 * software for notification of device events
436 * @param dev_id Crypto device identifier
437 * @param event Crypto device event to register for notification of.
438 * @param cb_arg User specified parameter to be passed as to passed to
439 * users callback function.
441 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
442 enum rte_cryptodev_event_type event, void *cb_arg);
445 /** Crypto Device statistics */
446 struct rte_cryptodev_stats {
447 uint64_t enqueued_count;
448 /**< Count of all operations enqueued */
449 uint64_t dequeued_count;
450 /**< Count of all operations dequeued */
452 uint64_t enqueue_err_count;
453 /**< Total error count on operations enqueued */
454 uint64_t dequeue_err_count;
455 /**< Total error count on operations dequeued */
458 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
459 /**< Max length of name of crypto PMD */
462 * Create a virtual crypto device
464 * @param name Cryptodev PMD name of device to be created.
465 * @param args Options arguments for device.
468 * - On successful creation of the cryptodev the device index is returned,
469 * which will be between 0 and rte_cryptodev_count().
470 * - In the case of a failure, returns -1.
473 rte_cryptodev_create_vdev(const char *name, const char *args);
476 * Get the device identifier for the named crypto device.
478 * @param name device name to select the device structure.
481 * - Returns crypto device identifier on success.
482 * - Return -1 on failure to find named crypto device.
485 rte_cryptodev_get_dev_id(const char *name);
488 * Get the total number of crypto devices that have been successfully
492 * - The total number of usable crypto devices.
495 rte_cryptodev_count(void);
498 * Get number of crypto device defined type.
500 * @param driver_id driver identifier.
503 * Returns number of crypto device.
506 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
509 * Get number and identifiers of attached crypto devices that
510 * use the same crypto driver.
512 * @param driver_name driver name.
513 * @param devices output devices identifiers.
514 * @param nb_devices maximal number of devices.
517 * Returns number of attached crypto device.
520 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
523 * Return the NUMA socket to which a device is connected
526 * The identifier of the device
528 * The NUMA socket id to which the device is connected or
529 * a default of zero if the socket could not be determined.
530 * -1 if returned is the dev_id value is out of range.
533 rte_cryptodev_socket_id(uint8_t dev_id);
535 /** Crypto device configuration structure */
536 struct rte_cryptodev_config {
537 int socket_id; /**< Socket to allocate resources on */
538 uint16_t nb_queue_pairs;
539 /**< Number of queue pairs to configure on device */
542 uint32_t nb_objs; /**< Number of objects in mempool */
543 uint32_t cache_size; /**< l-core object cache size */
544 } session_mp; /**< Session mempool configuration */
548 * Configure a device.
550 * This function must be invoked first before any other function in the
551 * API. This function can also be re-invoked when a device is in the
554 * @param dev_id The identifier of the device to configure.
555 * @param config The crypto device configuration structure.
558 * - 0: Success, device configured.
559 * - <0: Error code returned by the driver configuration function.
562 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
567 * The device start step is the last one and consists of setting the configured
568 * offload features and in starting the transmit and the receive units of the
570 * On success, all basic functions exported by the API (link status,
571 * receive/transmit, and so on) can be invoked.
574 * The identifier of the device.
576 * - 0: Success, device started.
577 * - <0: Error code of the driver device start function.
580 rte_cryptodev_start(uint8_t dev_id);
583 * Stop an device. The device can be restarted with a call to
584 * rte_cryptodev_start()
586 * @param dev_id The identifier of the device.
589 rte_cryptodev_stop(uint8_t dev_id);
592 * Close an device. The device cannot be restarted!
594 * @param dev_id The identifier of the device.
597 * - 0 on successfully closing device
598 * - <0 on failure to close device
601 rte_cryptodev_close(uint8_t dev_id);
604 * Allocate and set up a receive queue pair for a device.
607 * @param dev_id The identifier of the device.
608 * @param queue_pair_id The index of the queue pairs to set up. The
609 * value must be in the range [0, nb_queue_pair
610 * - 1] previously supplied to
611 * rte_cryptodev_configure().
612 * @param qp_conf The pointer to the configuration data to be
613 * used for the queue pair. NULL value is
614 * allowed, in which case default configuration
616 * @param socket_id The *socket_id* argument is the socket
617 * identifier in case of NUMA. The value can be
618 * *SOCKET_ID_ANY* if there is no NUMA constraint
619 * for the DMA memory allocated for the receive
623 * - 0: Success, queue pair correctly set up.
624 * - <0: Queue pair configuration failed
627 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
628 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
631 * Start a specified queue pair of a device. It is used
632 * when deferred_start flag of the specified queue is true.
634 * @param dev_id The identifier of the device
635 * @param queue_pair_id The index of the queue pair to start. The value
636 * must be in the range [0, nb_queue_pair - 1]
637 * previously supplied to
638 * rte_crypto_dev_configure().
640 * - 0: Success, the transmit queue is correctly set up.
641 * - -EINVAL: The dev_id or the queue_id out of range.
642 * - -ENOTSUP: The function not supported in PMD driver.
645 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
648 * Stop specified queue pair of a device
650 * @param dev_id The identifier of the device
651 * @param queue_pair_id The index of the queue pair to stop. The value
652 * must be in the range [0, nb_queue_pair - 1]
653 * previously supplied to
654 * rte_cryptodev_configure().
656 * - 0: Success, the transmit queue is correctly set up.
657 * - -EINVAL: The dev_id or the queue_id out of range.
658 * - -ENOTSUP: The function not supported in PMD driver.
661 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
664 * Get the number of queue pairs on a specific crypto device
666 * @param dev_id Crypto device identifier.
668 * - The number of configured queue pairs.
671 rte_cryptodev_queue_pair_count(uint8_t dev_id);
675 * Retrieve the general I/O statistics of a device.
677 * @param dev_id The identifier of the device.
678 * @param stats A pointer to a structure of type
679 * *rte_cryptodev_stats* to be filled with the
680 * values of device counters.
682 * - Zero if successful.
683 * - Non-zero otherwise.
686 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
689 * Reset the general I/O statistics of a device.
691 * @param dev_id The identifier of the device.
694 rte_cryptodev_stats_reset(uint8_t dev_id);
697 * Retrieve the contextual information of a device.
699 * @param dev_id The identifier of the device.
700 * @param dev_info A pointer to a structure of type
701 * *rte_cryptodev_info* to be filled with the
702 * contextual information of the device.
705 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
709 * Register a callback function for specific device id.
711 * @param dev_id Device id.
712 * @param event Event interested.
713 * @param cb_fn User supplied callback function to be called.
714 * @param cb_arg Pointer to the parameters for the registered
718 * - On success, zero.
719 * - On failure, a negative value.
722 rte_cryptodev_callback_register(uint8_t dev_id,
723 enum rte_cryptodev_event_type event,
724 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
727 * Unregister a callback function for specific device id.
729 * @param dev_id The device identifier.
730 * @param event Event interested.
731 * @param cb_fn User supplied callback function to be called.
732 * @param cb_arg Pointer to the parameters for the registered
736 * - On success, zero.
737 * - On failure, a negative value.
740 rte_cryptodev_callback_unregister(uint8_t dev_id,
741 enum rte_cryptodev_event_type event,
742 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
745 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
746 struct rte_crypto_op **ops, uint16_t nb_ops);
747 /**< Dequeue processed packets from queue pair of a device. */
749 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
750 struct rte_crypto_op **ops, uint16_t nb_ops);
751 /**< Enqueue packets for processing on queue pair of a device. */
756 struct rte_cryptodev_callback;
758 /** Structure to keep track of registered callbacks */
759 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
761 /** The data structure associated with each crypto device. */
762 struct rte_cryptodev {
763 dequeue_pkt_burst_t dequeue_burst;
764 /**< Pointer to PMD receive function. */
765 enqueue_pkt_burst_t enqueue_burst;
766 /**< Pointer to PMD transmit function. */
768 struct rte_cryptodev_data *data;
769 /**< Pointer to device data */
770 struct rte_cryptodev_ops *dev_ops;
771 /**< Functions exported by PMD */
772 uint64_t feature_flags;
773 /**< Supported features */
774 struct rte_device *device;
775 /**< Backing device */
778 /**< Crypto driver identifier*/
780 struct rte_cryptodev_cb_list link_intr_cbs;
781 /**< User application callback for interrupts if present */
784 uint8_t attached : 1;
785 /**< Flag indicating the device is attached */
786 } __rte_cache_aligned;
790 * The data part, with no function pointers, associated with each device.
792 * This structure is safe to place in shared memory to be common among
793 * different processes in a multi-process configuration.
795 struct rte_cryptodev_data {
797 /**< Device ID for this instance */
799 /**< Socket ID where memory is allocated */
800 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
801 /**< Unique identifier name */
804 uint8_t dev_started : 1;
805 /**< Device state: STARTED(1)/STOPPED(0) */
807 struct rte_mempool *session_pool;
808 /**< Session memory pool */
810 /**< Array of pointers to queue pairs. */
811 uint16_t nb_queue_pairs;
812 /**< Number of device queue pairs. */
815 /**< PMD-specific private data */
816 } __rte_cache_aligned;
818 extern struct rte_cryptodev *rte_cryptodevs;
821 * Dequeue a burst of processed crypto operations from a queue on the crypto
822 * device. The dequeued operation are stored in *rte_crypto_op* structures
823 * whose pointers are supplied in the *ops* array.
825 * The rte_cryptodev_dequeue_burst() function returns the number of ops
826 * actually dequeued, which is the number of *rte_crypto_op* data structures
827 * effectively supplied into the *ops* array.
829 * A return value equal to *nb_ops* indicates that the queue contained
830 * at least *nb_ops* operations, and this is likely to signify that other
831 * processed operations remain in the devices output queue. Applications
832 * implementing a "retrieve as many processed operations as possible" policy
833 * can check this specific case and keep invoking the
834 * rte_cryptodev_dequeue_burst() function until a value less than
835 * *nb_ops* is returned.
837 * The rte_cryptodev_dequeue_burst() function does not provide any error
838 * notification to avoid the corresponding overhead.
840 * @param dev_id The symmetric crypto device identifier
841 * @param qp_id The index of the queue pair from which to
842 * retrieve processed packets. The value must be
843 * in the range [0, nb_queue_pair - 1] previously
844 * supplied to rte_cryptodev_configure().
845 * @param ops The address of an array of pointers to
846 * *rte_crypto_op* structures that must be
847 * large enough to store *nb_ops* pointers in it.
848 * @param nb_ops The maximum number of operations to dequeue.
851 * - The number of operations actually dequeued, which is the number
852 * of pointers to *rte_crypto_op* structures effectively supplied to the
855 static inline uint16_t
856 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
857 struct rte_crypto_op **ops, uint16_t nb_ops)
859 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
861 nb_ops = (*dev->dequeue_burst)
862 (dev->data->queue_pairs[qp_id], ops, nb_ops);
868 * Enqueue a burst of operations for processing on a crypto device.
870 * The rte_cryptodev_enqueue_burst() function is invoked to place
871 * crypto operations on the queue *qp_id* of the device designated by
874 * The *nb_ops* parameter is the number of operations to process which are
875 * supplied in the *ops* array of *rte_crypto_op* structures.
877 * The rte_cryptodev_enqueue_burst() function returns the number of
878 * operations it actually enqueued for processing. A return value equal to
879 * *nb_ops* means that all packets have been enqueued.
881 * @param dev_id The identifier of the device.
882 * @param qp_id The index of the queue pair which packets are
883 * to be enqueued for processing. The value
884 * must be in the range [0, nb_queue_pairs - 1]
885 * previously supplied to
886 * *rte_cryptodev_configure*.
887 * @param ops The address of an array of *nb_ops* pointers
888 * to *rte_crypto_op* structures which contain
889 * the crypto operations to be processed.
890 * @param nb_ops The number of operations to process.
893 * The number of operations actually enqueued on the crypto device. The return
894 * value can be less than the value of the *nb_ops* parameter when the
895 * crypto devices queue is full or if invalid parameters are specified in
898 static inline uint16_t
899 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
900 struct rte_crypto_op **ops, uint16_t nb_ops)
902 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
904 return (*dev->enqueue_burst)(
905 dev->data->queue_pairs[qp_id], ops, nb_ops);
909 /** Cryptodev symmetric crypto session */
910 struct rte_cryptodev_sym_session {
916 /** Crypto driver identifier session created on */
917 struct rte_mempool *mp;
918 /**< Mempool session allocated from */
920 /**< Public symmetric session details */
922 __extension__ char _private[0];
923 /**< Private session material */
928 * Initialise a session for symmetric cryptographic operations.
930 * This function is used by the client to initialize immutable
931 * parameters of symmetric cryptographic operation.
932 * To perform the operation the rte_cryptodev_enqueue_burst function is
933 * used. Each mbuf should contain a reference to the session
934 * pointer returned from this function contained within it's crypto_op if a
935 * session-based operation is being provisioned. Memory to contain the session
936 * information is allocated from within mempool managed by the cryptodev.
938 * The rte_cryptodev_session_free must be called to free allocated
939 * memory when the session is no longer required.
941 * @param dev_id The device identifier.
942 * @param xform Crypto transform chain.
946 * Pointer to the created session or NULL
948 extern struct rte_cryptodev_sym_session *
949 rte_cryptodev_sym_session_create(uint8_t dev_id,
950 struct rte_crypto_sym_xform *xform);
953 * Free the memory associated with a previously allocated session.
955 * @param dev_id The device identifier.
956 * @param session Session pointer previously allocated by
957 * *rte_cryptodev_sym_session_create*.
960 * NULL on successful freeing of session.
961 * Session pointer on failure to free session.
963 extern struct rte_cryptodev_sym_session *
964 rte_cryptodev_sym_session_free(uint8_t dev_id,
965 struct rte_cryptodev_sym_session *session);
968 * Attach queue pair with sym session.
970 * @param qp_id Queue pair to which session will be attached.
971 * @param session Session pointer previously allocated by
972 * *rte_cryptodev_sym_session_create*.
975 * - On success, zero.
976 * - On failure, a negative value.
979 rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
980 struct rte_cryptodev_sym_session *session);
983 * Detach queue pair with sym session.
985 * @param qp_id Queue pair to which session is 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_detach_sym_session(uint16_t qp_id,
995 struct rte_cryptodev_sym_session *session);
998 * Provide driver identifier.
1001 * The pointer to a driver name.
1003 * The driver type identifier or -1 if no driver found
1005 int rte_cryptodev_driver_id_get(const char *name);
1008 * Provide driver name.
1011 * The driver identifier.
1013 * The driver name or null if no driver found
1015 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1019 * Allocate Cryptodev driver.
1022 * Pointer to rte_driver.
1024 * The driver type identifier
1026 uint8_t rte_cryptodev_allocate_driver(const struct rte_driver *driver);
1029 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(drv, driver_id)\
1030 RTE_INIT(init_ ##driver_id);\
1031 static void init_ ##driver_id(void)\
1033 driver_id = rte_cryptodev_allocate_driver(&(drv).driver);\
1041 #endif /* _RTE_CRYPTODEV_H_ */