]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/dpdk/lib/librte_cryptodev/rte_cryptodev.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / seastar / dpdk / lib / librte_cryptodev / rte_cryptodev.h
1 /*-
2 *
3 * Copyright(c) 2015-2017 Intel Corporation. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
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
14 * distribution.
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.
18 *
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.
30 */
31
32 #ifndef _RTE_CRYPTODEV_H_
33 #define _RTE_CRYPTODEV_H_
34
35 /**
36 * @file rte_cryptodev.h
37 *
38 * RTE Cryptographic Device APIs
39 *
40 * Defines RTE Crypto Device APIs for the provisioning of cipher and
41 * authentication operations.
42 */
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 #include "rte_kvargs.h"
49 #include "rte_crypto.h"
50 #include "rte_dev.h"
51 #include <rte_common.h>
52
53 #define CRYPTODEV_NAME_NULL_PMD crypto_null
54 /**< Null crypto PMD device name */
55 #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
56 /**< AES-NI Multi buffer PMD device name */
57 #define CRYPTODEV_NAME_AESNI_GCM_PMD crypto_aesni_gcm
58 /**< AES-NI GCM PMD device name */
59 #define CRYPTODEV_NAME_OPENSSL_PMD crypto_openssl
60 /**< Open SSL Crypto PMD device name */
61 #define CRYPTODEV_NAME_QAT_SYM_PMD crypto_qat
62 /**< Intel QAT Symmetric Crypto PMD device name */
63 #define CRYPTODEV_NAME_SNOW3G_PMD crypto_snow3g
64 /**< SNOW 3G PMD device name */
65 #define CRYPTODEV_NAME_KASUMI_PMD crypto_kasumi
66 /**< KASUMI PMD device name */
67 #define CRYPTODEV_NAME_ZUC_PMD crypto_zuc
68 /**< KASUMI PMD device name */
69 #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
70 /**< ARMv8 Crypto PMD device name */
71 #define CRYPTODEV_NAME_SCHEDULER_PMD crypto_scheduler
72 /**< Scheduler Crypto PMD device name */
73 #define CRYPTODEV_NAME_DPAA2_SEC_PMD cryptodev_dpaa2_sec_pmd
74 /**< NXP DPAA2 - SEC PMD device name */
75
76 /** Crypto device type */
77 enum rte_cryptodev_type {
78 RTE_CRYPTODEV_NULL_PMD = 1, /**< Null crypto PMD */
79 RTE_CRYPTODEV_AESNI_GCM_PMD, /**< AES-NI GCM PMD */
80 RTE_CRYPTODEV_AESNI_MB_PMD, /**< AES-NI multi buffer PMD */
81 RTE_CRYPTODEV_QAT_SYM_PMD, /**< QAT PMD Symmetric Crypto */
82 RTE_CRYPTODEV_SNOW3G_PMD, /**< SNOW 3G PMD */
83 RTE_CRYPTODEV_KASUMI_PMD, /**< KASUMI PMD */
84 RTE_CRYPTODEV_ZUC_PMD, /**< ZUC PMD */
85 RTE_CRYPTODEV_OPENSSL_PMD, /**< OpenSSL PMD */
86 RTE_CRYPTODEV_ARMV8_PMD, /**< ARMv8 crypto PMD */
87 RTE_CRYPTODEV_SCHEDULER_PMD, /**< Crypto Scheduler PMD */
88 RTE_CRYPTODEV_DPAA2_SEC_PMD, /**< NXP DPAA2 - SEC PMD */
89 };
90
91 extern const char **rte_cyptodev_names;
92
93 /* Logging Macros */
94
95 #define CDEV_LOG_ERR(...) \
96 RTE_LOG(ERR, CRYPTODEV, \
97 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
98 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
99
100 #define CDEV_PMD_LOG_ERR(dev, ...) \
101 RTE_LOG(ERR, CRYPTODEV, \
102 RTE_FMT("[%s] %s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
103 dev, __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
104
105 #ifdef RTE_LIBRTE_CRYPTODEV_DEBUG
106 #define CDEV_LOG_DEBUG(...) \
107 RTE_LOG(DEBUG, CRYPTODEV, \
108 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
109 __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
110
111 #define CDEV_PMD_TRACE(...) \
112 RTE_LOG(DEBUG, CRYPTODEV, \
113 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
114 dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
115
116 #else
117 #define CDEV_LOG_DEBUG(...) (void)0
118 #define CDEV_PMD_TRACE(...) (void)0
119 #endif
120
121 /**
122 * Crypto parameters range description
123 */
124 struct rte_crypto_param_range {
125 uint16_t min; /**< minimum size */
126 uint16_t max; /**< maximum size */
127 uint16_t increment;
128 /**< if a range of sizes are supported,
129 * this parameter is used to indicate
130 * increments in byte size that are supported
131 * between the minimum and maximum
132 */
133 };
134
135 /**
136 * Symmetric Crypto Capability
137 */
138 struct rte_cryptodev_symmetric_capability {
139 enum rte_crypto_sym_xform_type xform_type;
140 /**< Transform type : Authentication / Cipher */
141 RTE_STD_C11
142 union {
143 struct {
144 enum rte_crypto_auth_algorithm algo;
145 /**< authentication algorithm */
146 uint16_t block_size;
147 /**< algorithm block size */
148 struct rte_crypto_param_range key_size;
149 /**< auth key size range */
150 struct rte_crypto_param_range digest_size;
151 /**< digest size range */
152 struct rte_crypto_param_range aad_size;
153 /**< Additional authentication data size range */
154 } auth;
155 /**< Symmetric Authentication transform capabilities */
156 struct {
157 enum rte_crypto_cipher_algorithm algo;
158 /**< cipher algorithm */
159 uint16_t block_size;
160 /**< algorithm block size */
161 struct rte_crypto_param_range key_size;
162 /**< cipher key size range */
163 struct rte_crypto_param_range iv_size;
164 /**< Initialisation vector data size range */
165 } cipher;
166 /**< Symmetric Cipher transform capabilities */
167 };
168 };
169
170 /** Structure used to capture a capability of a crypto device */
171 struct rte_cryptodev_capabilities {
172 enum rte_crypto_op_type op;
173 /**< Operation type */
174
175 RTE_STD_C11
176 union {
177 struct rte_cryptodev_symmetric_capability sym;
178 /**< Symmetric operation capability parameters */
179 };
180 };
181
182 /** Structure used to describe crypto algorithms */
183 struct rte_cryptodev_sym_capability_idx {
184 enum rte_crypto_sym_xform_type type;
185 union {
186 enum rte_crypto_cipher_algorithm cipher;
187 enum rte_crypto_auth_algorithm auth;
188 } algo;
189 };
190
191 /**
192 * Provide capabilities available for defined device and algorithm
193 *
194 * @param dev_id The identifier of the device.
195 * @param idx Description of crypto algorithms.
196 *
197 * @return
198 * - Return description of the symmetric crypto capability if exist.
199 * - Return NULL if the capability not exist.
200 */
201 const struct rte_cryptodev_symmetric_capability *
202 rte_cryptodev_sym_capability_get(uint8_t dev_id,
203 const struct rte_cryptodev_sym_capability_idx *idx);
204
205 /**
206 * Check if key size and initial vector are supported
207 * in crypto cipher capability
208 *
209 * @param capability Description of the symmetric crypto capability.
210 * @param key_size Cipher key size.
211 * @param iv_size Cipher initial vector size.
212 *
213 * @return
214 * - Return 0 if the parameters are in range of the capability.
215 * - Return -1 if the parameters are out of range of the capability.
216 */
217 int
218 rte_cryptodev_sym_capability_check_cipher(
219 const struct rte_cryptodev_symmetric_capability *capability,
220 uint16_t key_size, uint16_t iv_size);
221
222 /**
223 * Check if key size and initial vector are supported
224 * in crypto auth capability
225 *
226 * @param capability Description of the symmetric crypto capability.
227 * @param key_size Auth key size.
228 * @param digest_size Auth digest size.
229 * @param aad_size Auth aad size.
230 *
231 * @return
232 * - Return 0 if the parameters are in range of the capability.
233 * - Return -1 if the parameters are out of range of the capability.
234 */
235 int
236 rte_cryptodev_sym_capability_check_auth(
237 const struct rte_cryptodev_symmetric_capability *capability,
238 uint16_t key_size, uint16_t digest_size, uint16_t aad_size);
239
240 /**
241 * Provide the cipher algorithm enum, given an algorithm string
242 *
243 * @param algo_enum A pointer to the cipher algorithm
244 * enum to be filled
245 * @param algo_string Authentication algo string
246 *
247 * @return
248 * - Return -1 if string is not valid
249 * - Return 0 is the string is valid
250 */
251 int
252 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
253 const char *algo_string);
254
255 /**
256 * Provide the authentication algorithm enum, given an algorithm string
257 *
258 * @param algo_enum A pointer to the authentication algorithm
259 * enum to be filled
260 * @param algo_string Authentication algo string
261 *
262 * @return
263 * - Return -1 if string is not valid
264 * - Return 0 is the string is valid
265 */
266 int
267 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
268 const char *algo_string);
269
270 /** Macro used at end of crypto PMD list */
271 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
272 { RTE_CRYPTO_OP_TYPE_UNDEFINED }
273
274
275 /**
276 * Crypto device supported feature flags
277 *
278 * Note:
279 * New features flags should be added to the end of the list
280 *
281 * Keep these flags synchronised with rte_cryptodev_get_feature_name()
282 */
283 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO (1ULL << 0)
284 /**< Symmetric crypto operations are supported */
285 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO (1ULL << 1)
286 /**< Asymmetric crypto operations are supported */
287 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
288 /**< Chaining symmetric crypto operations are supported */
289 #define RTE_CRYPTODEV_FF_CPU_SSE (1ULL << 3)
290 /**< Utilises CPU SIMD SSE instructions */
291 #define RTE_CRYPTODEV_FF_CPU_AVX (1ULL << 4)
292 /**< Utilises CPU SIMD AVX instructions */
293 #define RTE_CRYPTODEV_FF_CPU_AVX2 (1ULL << 5)
294 /**< Utilises CPU SIMD AVX2 instructions */
295 #define RTE_CRYPTODEV_FF_CPU_AESNI (1ULL << 6)
296 /**< Utilises CPU AES-NI instructions */
297 #define RTE_CRYPTODEV_FF_HW_ACCELERATED (1ULL << 7)
298 /**< Operations are off-loaded to an external hardware accelerator */
299 #define RTE_CRYPTODEV_FF_CPU_AVX512 (1ULL << 8)
300 /**< Utilises CPU SIMD AVX512 instructions */
301 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER (1ULL << 9)
302 /**< Scatter-gather mbufs are supported */
303 #define RTE_CRYPTODEV_FF_CPU_NEON (1ULL << 10)
304 /**< Utilises CPU NEON instructions */
305 #define RTE_CRYPTODEV_FF_CPU_ARM_CE (1ULL << 11)
306 /**< Utilises ARM CPU Cryptographic Extensions */
307
308
309 /**
310 * Get the name of a crypto device feature flag
311 *
312 * @param flag The mask describing the flag.
313 *
314 * @return
315 * The name of this flag, or NULL if it's not a valid feature flag.
316 */
317
318 extern const char *
319 rte_cryptodev_get_feature_name(uint64_t flag);
320
321 /** Crypto device information */
322 struct rte_cryptodev_info {
323 const char *driver_name; /**< Driver name. */
324 enum rte_cryptodev_type dev_type; /**< Device type */
325 struct rte_pci_device *pci_dev; /**< PCI information. */
326
327 uint64_t feature_flags; /**< Feature flags */
328
329 const struct rte_cryptodev_capabilities *capabilities;
330 /**< Array of devices supported capabilities */
331
332 unsigned max_nb_queue_pairs;
333 /**< Maximum number of queues pairs supported by device. */
334
335 struct {
336 unsigned max_nb_sessions;
337 /**< Maximum number of sessions supported by device. */
338 unsigned int max_nb_sessions_per_qp;
339 /**< Maximum number of sessions per queue pair.
340 * Default 0 for infinite sessions
341 */
342 } sym;
343 };
344
345 #define RTE_CRYPTODEV_DETACHED (0)
346 #define RTE_CRYPTODEV_ATTACHED (1)
347
348 /** Definitions of Crypto device event types */
349 enum rte_cryptodev_event_type {
350 RTE_CRYPTODEV_EVENT_UNKNOWN, /**< unknown event type */
351 RTE_CRYPTODEV_EVENT_ERROR, /**< error interrupt event */
352 RTE_CRYPTODEV_EVENT_MAX /**< max value of this enum */
353 };
354
355 /** Crypto device queue pair configuration structure. */
356 struct rte_cryptodev_qp_conf {
357 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
358 };
359
360 /**
361 * Typedef for application callback function to be registered by application
362 * software for notification of device events
363 *
364 * @param dev_id Crypto device identifier
365 * @param event Crypto device event to register for notification of.
366 * @param cb_arg User specified parameter to be passed as to passed to
367 * users callback function.
368 */
369 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
370 enum rte_cryptodev_event_type event, void *cb_arg);
371
372
373 /** Crypto Device statistics */
374 struct rte_cryptodev_stats {
375 uint64_t enqueued_count;
376 /**< Count of all operations enqueued */
377 uint64_t dequeued_count;
378 /**< Count of all operations dequeued */
379
380 uint64_t enqueue_err_count;
381 /**< Total error count on operations enqueued */
382 uint64_t dequeue_err_count;
383 /**< Total error count on operations dequeued */
384 };
385
386 #define RTE_CRYPTODEV_NAME_MAX_LEN (64)
387 /**< Max length of name of crypto PMD */
388 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS 8
389 #define RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS 2048
390
391 /**
392 * @internal
393 * Initialisation parameters for virtual crypto devices
394 */
395 struct rte_crypto_vdev_init_params {
396 unsigned max_nb_queue_pairs;
397 unsigned max_nb_sessions;
398 uint8_t socket_id;
399 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
400 };
401
402 /**
403 * Parse virtual device initialisation parameters input arguments
404 * @internal
405 *
406 * @params params Initialisation parameters with defaults set.
407 * @params input_args Command line arguments
408 *
409 * @return
410 * 0 on successful parse
411 * <0 on failure to parse
412 */
413 int
414 rte_cryptodev_parse_vdev_init_params(
415 struct rte_crypto_vdev_init_params *params,
416 const char *input_args);
417
418 /**
419 * Create a virtual crypto device
420 *
421 * @param name Cryptodev PMD name of device to be created.
422 * @param args Options arguments for device.
423 *
424 * @return
425 * - On successful creation of the cryptodev the device index is returned,
426 * which will be between 0 and rte_cryptodev_count().
427 * - In the case of a failure, returns -1.
428 */
429 extern int
430 rte_cryptodev_create_vdev(const char *name, const char *args);
431
432 /**
433 * Get the device identifier for the named crypto device.
434 *
435 * @param name device name to select the device structure.
436 *
437 * @return
438 * - Returns crypto device identifier on success.
439 * - Return -1 on failure to find named crypto device.
440 */
441 extern int
442 rte_cryptodev_get_dev_id(const char *name);
443
444 /**
445 * Get the total number of crypto devices that have been successfully
446 * initialised.
447 *
448 * @return
449 * - The total number of usable crypto devices.
450 */
451 extern uint8_t
452 rte_cryptodev_count(void);
453
454 /**
455 * Get number of crypto device defined type.
456 *
457 * @param type type of device.
458 *
459 * @return
460 * Returns number of crypto device.
461 */
462 extern uint8_t
463 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
464
465 /**
466 * Get number and identifiers of attached crypto device.
467 *
468 * @param dev_name device name.
469 * @param devices output devices identifiers.
470 * @param nb_devices maximal number of devices.
471 *
472 * @return
473 * Returns number of attached crypto device.
474 */
475 uint8_t
476 rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices,
477 uint8_t nb_devices);
478 /*
479 * Return the NUMA socket to which a device is connected
480 *
481 * @param dev_id
482 * The identifier of the device
483 * @return
484 * The NUMA socket id to which the device is connected or
485 * a default of zero if the socket could not be determined.
486 * -1 if returned is the dev_id value is out of range.
487 */
488 extern int
489 rte_cryptodev_socket_id(uint8_t dev_id);
490
491 /** Crypto device configuration structure */
492 struct rte_cryptodev_config {
493 int socket_id; /**< Socket to allocate resources on */
494 uint16_t nb_queue_pairs;
495 /**< Number of queue pairs to configure on device */
496
497 struct {
498 uint32_t nb_objs; /**< Number of objects in mempool */
499 uint32_t cache_size; /**< l-core object cache size */
500 } session_mp; /**< Session mempool configuration */
501 };
502
503 /**
504 * Configure a device.
505 *
506 * This function must be invoked first before any other function in the
507 * API. This function can also be re-invoked when a device is in the
508 * stopped state.
509 *
510 * @param dev_id The identifier of the device to configure.
511 * @param config The crypto device configuration structure.
512 *
513 * @return
514 * - 0: Success, device configured.
515 * - <0: Error code returned by the driver configuration function.
516 */
517 extern int
518 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
519
520 /**
521 * Start an device.
522 *
523 * The device start step is the last one and consists of setting the configured
524 * offload features and in starting the transmit and the receive units of the
525 * device.
526 * On success, all basic functions exported by the API (link status,
527 * receive/transmit, and so on) can be invoked.
528 *
529 * @param dev_id
530 * The identifier of the device.
531 * @return
532 * - 0: Success, device started.
533 * - <0: Error code of the driver device start function.
534 */
535 extern int
536 rte_cryptodev_start(uint8_t dev_id);
537
538 /**
539 * Stop an device. The device can be restarted with a call to
540 * rte_cryptodev_start()
541 *
542 * @param dev_id The identifier of the device.
543 */
544 extern void
545 rte_cryptodev_stop(uint8_t dev_id);
546
547 /**
548 * Close an device. The device cannot be restarted!
549 *
550 * @param dev_id The identifier of the device.
551 *
552 * @return
553 * - 0 on successfully closing device
554 * - <0 on failure to close device
555 */
556 extern int
557 rte_cryptodev_close(uint8_t dev_id);
558
559 /**
560 * Allocate and set up a receive queue pair for a device.
561 *
562 *
563 * @param dev_id The identifier of the device.
564 * @param queue_pair_id The index of the queue pairs to set up. The
565 * value must be in the range [0, nb_queue_pair
566 * - 1] previously supplied to
567 * rte_cryptodev_configure().
568 * @param qp_conf The pointer to the configuration data to be
569 * used for the queue pair. NULL value is
570 * allowed, in which case default configuration
571 * will be used.
572 * @param socket_id The *socket_id* argument is the socket
573 * identifier in case of NUMA. The value can be
574 * *SOCKET_ID_ANY* if there is no NUMA constraint
575 * for the DMA memory allocated for the receive
576 * queue pair.
577 *
578 * @return
579 * - 0: Success, queue pair correctly set up.
580 * - <0: Queue pair configuration failed
581 */
582 extern int
583 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
584 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
585
586 /**
587 * Start a specified queue pair of a device. It is used
588 * when deferred_start flag of the specified queue is true.
589 *
590 * @param dev_id The identifier of the device
591 * @param queue_pair_id The index of the queue pair to start. The value
592 * must be in the range [0, nb_queue_pair - 1]
593 * previously supplied to
594 * rte_crypto_dev_configure().
595 * @return
596 * - 0: Success, the transmit queue is correctly set up.
597 * - -EINVAL: The dev_id or the queue_id out of range.
598 * - -ENOTSUP: The function not supported in PMD driver.
599 */
600 extern int
601 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
602
603 /**
604 * Stop specified queue pair of a device
605 *
606 * @param dev_id The identifier of the device
607 * @param queue_pair_id The index of the queue pair to stop. The value
608 * must be in the range [0, nb_queue_pair - 1]
609 * previously supplied to
610 * rte_cryptodev_configure().
611 * @return
612 * - 0: Success, the transmit queue is correctly set up.
613 * - -EINVAL: The dev_id or the queue_id out of range.
614 * - -ENOTSUP: The function not supported in PMD driver.
615 */
616 extern int
617 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
618
619 /**
620 * Get the number of queue pairs on a specific crypto device
621 *
622 * @param dev_id Crypto device identifier.
623 * @return
624 * - The number of configured queue pairs.
625 */
626 extern uint16_t
627 rte_cryptodev_queue_pair_count(uint8_t dev_id);
628
629
630 /**
631 * Retrieve the general I/O statistics of a device.
632 *
633 * @param dev_id The identifier of the device.
634 * @param stats A pointer to a structure of type
635 * *rte_cryptodev_stats* to be filled with the
636 * values of device counters.
637 * @return
638 * - Zero if successful.
639 * - Non-zero otherwise.
640 */
641 extern int
642 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
643
644 /**
645 * Reset the general I/O statistics of a device.
646 *
647 * @param dev_id The identifier of the device.
648 */
649 extern void
650 rte_cryptodev_stats_reset(uint8_t dev_id);
651
652 /**
653 * Retrieve the contextual information of a device.
654 *
655 * @param dev_id The identifier of the device.
656 * @param dev_info A pointer to a structure of type
657 * *rte_cryptodev_info* to be filled with the
658 * contextual information of the device.
659 */
660 extern void
661 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
662
663
664 /**
665 * Register a callback function for specific device id.
666 *
667 * @param dev_id Device id.
668 * @param event Event interested.
669 * @param cb_fn User supplied callback function to be called.
670 * @param cb_arg Pointer to the parameters for the registered
671 * callback.
672 *
673 * @return
674 * - On success, zero.
675 * - On failure, a negative value.
676 */
677 extern int
678 rte_cryptodev_callback_register(uint8_t dev_id,
679 enum rte_cryptodev_event_type event,
680 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
681
682 /**
683 * Unregister a callback function for specific device id.
684 *
685 * @param dev_id The device identifier.
686 * @param event Event interested.
687 * @param cb_fn User supplied callback function to be called.
688 * @param cb_arg Pointer to the parameters for the registered
689 * callback.
690 *
691 * @return
692 * - On success, zero.
693 * - On failure, a negative value.
694 */
695 extern int
696 rte_cryptodev_callback_unregister(uint8_t dev_id,
697 enum rte_cryptodev_event_type event,
698 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
699
700
701 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
702 struct rte_crypto_op **ops, uint16_t nb_ops);
703 /**< Dequeue processed packets from queue pair of a device. */
704
705 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
706 struct rte_crypto_op **ops, uint16_t nb_ops);
707 /**< Enqueue packets for processing on queue pair of a device. */
708
709
710
711
712 struct rte_cryptodev_callback;
713
714 /** Structure to keep track of registered callbacks */
715 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
716
717 /** The data structure associated with each crypto device. */
718 struct rte_cryptodev {
719 dequeue_pkt_burst_t dequeue_burst;
720 /**< Pointer to PMD receive function. */
721 enqueue_pkt_burst_t enqueue_burst;
722 /**< Pointer to PMD transmit function. */
723
724 const struct rte_cryptodev_driver *driver;
725 /**< Driver for this device */
726 struct rte_cryptodev_data *data;
727 /**< Pointer to device data */
728 struct rte_cryptodev_ops *dev_ops;
729 /**< Functions exported by PMD */
730 uint64_t feature_flags;
731 /**< Supported features */
732 struct rte_device *device;
733 /**< Backing device */
734
735 enum rte_cryptodev_type dev_type;
736 /**< Crypto device type */
737
738 struct rte_cryptodev_cb_list link_intr_cbs;
739 /**< User application callback for interrupts if present */
740
741 __extension__
742 uint8_t attached : 1;
743 /**< Flag indicating the device is attached */
744 } __rte_cache_aligned;
745
746 /**
747 *
748 * The data part, with no function pointers, associated with each device.
749 *
750 * This structure is safe to place in shared memory to be common among
751 * different processes in a multi-process configuration.
752 */
753 struct rte_cryptodev_data {
754 uint8_t dev_id;
755 /**< Device ID for this instance */
756 uint8_t socket_id;
757 /**< Socket ID where memory is allocated */
758 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
759 /**< Unique identifier name */
760
761 __extension__
762 uint8_t dev_started : 1;
763 /**< Device state: STARTED(1)/STOPPED(0) */
764
765 struct rte_mempool *session_pool;
766 /**< Session memory pool */
767 void **queue_pairs;
768 /**< Array of pointers to queue pairs. */
769 uint16_t nb_queue_pairs;
770 /**< Number of device queue pairs. */
771
772 void *dev_private;
773 /**< PMD-specific private data */
774 } __rte_cache_aligned;
775
776 extern struct rte_cryptodev *rte_cryptodevs;
777 /**
778 *
779 * Dequeue a burst of processed crypto operations from a queue on the crypto
780 * device. The dequeued operation are stored in *rte_crypto_op* structures
781 * whose pointers are supplied in the *ops* array.
782 *
783 * The rte_cryptodev_dequeue_burst() function returns the number of ops
784 * actually dequeued, which is the number of *rte_crypto_op* data structures
785 * effectively supplied into the *ops* array.
786 *
787 * A return value equal to *nb_ops* indicates that the queue contained
788 * at least *nb_ops* operations, and this is likely to signify that other
789 * processed operations remain in the devices output queue. Applications
790 * implementing a "retrieve as many processed operations as possible" policy
791 * can check this specific case and keep invoking the
792 * rte_cryptodev_dequeue_burst() function until a value less than
793 * *nb_ops* is returned.
794 *
795 * The rte_cryptodev_dequeue_burst() function does not provide any error
796 * notification to avoid the corresponding overhead.
797 *
798 * @param dev_id The symmetric crypto device identifier
799 * @param qp_id The index of the queue pair from which to
800 * retrieve processed packets. The value must be
801 * in the range [0, nb_queue_pair - 1] previously
802 * supplied to rte_cryptodev_configure().
803 * @param ops The address of an array of pointers to
804 * *rte_crypto_op* structures that must be
805 * large enough to store *nb_ops* pointers in it.
806 * @param nb_ops The maximum number of operations to dequeue.
807 *
808 * @return
809 * - The number of operations actually dequeued, which is the number
810 * of pointers to *rte_crypto_op* structures effectively supplied to the
811 * *ops* array.
812 */
813 static inline uint16_t
814 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
815 struct rte_crypto_op **ops, uint16_t nb_ops)
816 {
817 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
818
819 nb_ops = (*dev->dequeue_burst)
820 (dev->data->queue_pairs[qp_id], ops, nb_ops);
821
822 return nb_ops;
823 }
824
825 /**
826 * Enqueue a burst of operations for processing on a crypto device.
827 *
828 * The rte_cryptodev_enqueue_burst() function is invoked to place
829 * crypto operations on the queue *qp_id* of the device designated by
830 * its *dev_id*.
831 *
832 * The *nb_ops* parameter is the number of operations to process which are
833 * supplied in the *ops* array of *rte_crypto_op* structures.
834 *
835 * The rte_cryptodev_enqueue_burst() function returns the number of
836 * operations it actually enqueued for processing. A return value equal to
837 * *nb_ops* means that all packets have been enqueued.
838 *
839 * @param dev_id The identifier of the device.
840 * @param qp_id The index of the queue pair which packets are
841 * to be enqueued for processing. The value
842 * must be in the range [0, nb_queue_pairs - 1]
843 * previously supplied to
844 * *rte_cryptodev_configure*.
845 * @param ops The address of an array of *nb_ops* pointers
846 * to *rte_crypto_op* structures which contain
847 * the crypto operations to be processed.
848 * @param nb_ops The number of operations to process.
849 *
850 * @return
851 * The number of operations actually enqueued on the crypto device. The return
852 * value can be less than the value of the *nb_ops* parameter when the
853 * crypto devices queue is full or if invalid parameters are specified in
854 * a *rte_crypto_op*.
855 */
856 static inline uint16_t
857 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
858 struct rte_crypto_op **ops, uint16_t nb_ops)
859 {
860 struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
861
862 return (*dev->enqueue_burst)(
863 dev->data->queue_pairs[qp_id], ops, nb_ops);
864 }
865
866
867 /** Cryptodev symmetric crypto session */
868 struct rte_cryptodev_sym_session {
869 RTE_STD_C11
870 struct {
871 uint8_t dev_id;
872 /**< Device Id */
873 enum rte_cryptodev_type dev_type;
874 /** Crypto Device type session created on */
875 struct rte_mempool *mp;
876 /**< Mempool session allocated from */
877 } __rte_aligned(8);
878 /**< Public symmetric session details */
879
880 __extension__ char _private[0];
881 /**< Private session material */
882 };
883
884
885 /**
886 * Initialise a session for symmetric cryptographic operations.
887 *
888 * This function is used by the client to initialize immutable
889 * parameters of symmetric cryptographic operation.
890 * To perform the operation the rte_cryptodev_enqueue_burst function is
891 * used. Each mbuf should contain a reference to the session
892 * pointer returned from this function contained within it's crypto_op if a
893 * session-based operation is being provisioned. Memory to contain the session
894 * information is allocated from within mempool managed by the cryptodev.
895 *
896 * The rte_cryptodev_session_free must be called to free allocated
897 * memory when the session is no longer required.
898 *
899 * @param dev_id The device identifier.
900 * @param xform Crypto transform chain.
901
902 *
903 * @return
904 * Pointer to the created session or NULL
905 */
906 extern struct rte_cryptodev_sym_session *
907 rte_cryptodev_sym_session_create(uint8_t dev_id,
908 struct rte_crypto_sym_xform *xform);
909
910 /**
911 * Free the memory associated with a previously allocated session.
912 *
913 * @param dev_id The device identifier.
914 * @param session Session pointer previously allocated by
915 * *rte_cryptodev_sym_session_create*.
916 *
917 * @return
918 * NULL on successful freeing of session.
919 * Session pointer on failure to free session.
920 */
921 extern struct rte_cryptodev_sym_session *
922 rte_cryptodev_sym_session_free(uint8_t dev_id,
923 struct rte_cryptodev_sym_session *session);
924
925 /**
926 * Attach queue pair with sym session.
927 *
928 * @param qp_id Queue pair to which session will be attached.
929 * @param session Session pointer previously allocated by
930 * *rte_cryptodev_sym_session_create*.
931 *
932 * @return
933 * - On success, zero.
934 * - On failure, a negative value.
935 */
936 int
937 rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
938 struct rte_cryptodev_sym_session *session);
939
940 /**
941 * Detach queue pair with sym session.
942 *
943 * @param qp_id Queue pair to which session is attached.
944 * @param session Session pointer previously allocated by
945 * *rte_cryptodev_sym_session_create*.
946 *
947 * @return
948 * - On success, zero.
949 * - On failure, a negative value.
950 */
951 int
952 rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
953 struct rte_cryptodev_sym_session *session);
954
955
956 #ifdef __cplusplus
957 }
958 #endif
959
960 #endif /* _RTE_CRYPTODEV_H_ */