cryptodev: remove crypto device type enumeration
[dpdk.git] / 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 #include <rte_vdev.h>
53
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 */
76
77 extern const char **rte_cyptodev_names;
78
79 /* Logging Macros */
80
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__,)))
85
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__,)))
90
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__,)))
96
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__,)))
101
102 #else
103 #define CDEV_LOG_DEBUG(...) (void)0
104 #define CDEV_PMD_TRACE(...) (void)0
105 #endif
106
107
108
109 /**
110  * A macro that points to an offset from the start
111  * of the crypto operation structure (rte_crypto_op)
112  *
113  * The returned pointer is cast to type t.
114  *
115  * @param c
116  *   The crypto operation.
117  * @param o
118  *   The offset from the start of the crypto operation.
119  * @param t
120  *   The type to cast the result into.
121  */
122 #define rte_crypto_op_ctod_offset(c, t, o)      \
123         ((t)((char *)(c) + (o)))
124
125 /**
126  * A macro that returns the physical address that points
127  * to an offset from the start of the crypto operation
128  * (rte_crypto_op)
129  *
130  * @param c
131  *   The crypto operation.
132  * @param o
133  *   The offset from the start of the crypto operation
134  *   to calculate address from.
135  */
136 #define rte_crypto_op_ctophys_offset(c, o)      \
137         (phys_addr_t)((c)->phys_addr + (o))
138
139 /**
140  * Crypto parameters range description
141  */
142 struct rte_crypto_param_range {
143         uint16_t min;   /**< minimum size */
144         uint16_t max;   /**< maximum size */
145         uint16_t increment;
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
150          */
151 };
152
153 /**
154  * Symmetric Crypto Capability
155  */
156 struct rte_cryptodev_symmetric_capability {
157         enum rte_crypto_sym_xform_type xform_type;
158         /**< Transform type : Authentication / Cipher / AEAD */
159         RTE_STD_C11
160         union {
161                 struct {
162                         enum rte_crypto_auth_algorithm algo;
163                         /**< authentication algorithm */
164                         uint16_t block_size;
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 */
174                 } auth;
175                 /**< Symmetric Authentication transform capabilities */
176                 struct {
177                         enum rte_crypto_cipher_algorithm algo;
178                         /**< cipher algorithm */
179                         uint16_t block_size;
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 */
185                 } cipher;
186                 /**< Symmetric Cipher transform capabilities */
187                 struct {
188                         enum rte_crypto_aead_algorithm algo;
189                         /**< AEAD algorithm */
190                         uint16_t block_size;
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 */
200                 } aead;
201         };
202 };
203
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 */
208
209         RTE_STD_C11
210         union {
211                 struct rte_cryptodev_symmetric_capability sym;
212                 /**< Symmetric operation capability parameters */
213         };
214 };
215
216 /** Structure used to describe crypto algorithms */
217 struct rte_cryptodev_sym_capability_idx {
218         enum rte_crypto_sym_xform_type type;
219         union {
220                 enum rte_crypto_cipher_algorithm cipher;
221                 enum rte_crypto_auth_algorithm auth;
222                 enum rte_crypto_aead_algorithm aead;
223         } algo;
224 };
225
226 /**
227  *  Provide capabilities available for defined device and algorithm
228  *
229  * @param       dev_id          The identifier of the device.
230  * @param       idx             Description of crypto algorithms.
231  *
232  * @return
233  *   - Return description of the symmetric crypto capability if exist.
234  *   - Return NULL if the capability not exist.
235  */
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);
239
240 /**
241  * Check if key size and initial vector are supported
242  * in crypto cipher capability
243  *
244  * @param       capability      Description of the symmetric crypto capability.
245  * @param       key_size        Cipher key size.
246  * @param       iv_size         Cipher initial vector size.
247  *
248  * @return
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.
251  */
252 int
253 rte_cryptodev_sym_capability_check_cipher(
254                 const struct rte_cryptodev_symmetric_capability *capability,
255                 uint16_t key_size, uint16_t iv_size);
256
257 /**
258  * Check if key size and initial vector are supported
259  * in crypto auth capability
260  *
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.
266  *
267  * @return
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.
270  */
271 int
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,
275                 uint16_t iv_size);
276
277 /**
278  * Check if key, digest, AAD and initial vector sizes are supported
279  * in crypto AEAD capability
280  *
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.
286  *
287  * @return
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.
290  */
291 int
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,
295                 uint16_t iv_size);
296
297 /**
298  * Provide the cipher algorithm enum, given an algorithm string
299  *
300  * @param       algo_enum       A pointer to the cipher algorithm
301  *                              enum to be filled
302  * @param       algo_string     Authentication algo string
303  *
304  * @return
305  * - Return -1 if string is not valid
306  * - Return 0 is the string is valid
307  */
308 int
309 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
310                 const char *algo_string);
311
312 /**
313  * Provide the authentication algorithm enum, given an algorithm string
314  *
315  * @param       algo_enum       A pointer to the authentication algorithm
316  *                              enum to be filled
317  * @param       algo_string     Authentication algo string
318  *
319  * @return
320  * - Return -1 if string is not valid
321  * - Return 0 is the string is valid
322  */
323 int
324 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
325                 const char *algo_string);
326
327 /**
328  * Provide the AEAD algorithm enum, given an algorithm string
329  *
330  * @param       algo_enum       A pointer to the AEAD algorithm
331  *                              enum to be filled
332  * @param       algo_string     AEAD algorithm string
333  *
334  * @return
335  * - Return -1 if string is not valid
336  * - Return 0 is the string is valid
337  */
338 int
339 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
340                 const char *algo_string);
341
342 /** Macro used at end of crypto PMD list */
343 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
344         { RTE_CRYPTO_OP_TYPE_UNDEFINED }
345
346
347 /**
348  * Crypto device supported feature flags
349  *
350  * Note:
351  * New features flags should be added to the end of the list
352  *
353  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
354  */
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 */
379
380
381 /**
382  * Get the name of a crypto device feature flag
383  *
384  * @param       flag    The mask describing the flag.
385  *
386  * @return
387  *   The name of this flag, or NULL if it's not a valid feature flag.
388  */
389
390 extern const char *
391 rte_cryptodev_get_feature_name(uint64_t flag);
392
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. */
398
399         uint64_t feature_flags;                 /**< Feature flags */
400
401         const struct rte_cryptodev_capabilities *capabilities;
402         /**< Array of devices supported capabilities */
403
404         unsigned max_nb_queue_pairs;
405         /**< Maximum number of queues pairs supported by device. */
406
407         struct {
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
413                  */
414         } sym;
415 };
416
417 #define RTE_CRYPTODEV_DETACHED  (0)
418 #define RTE_CRYPTODEV_ATTACHED  (1)
419
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 */
425 };
426
427 /** Crypto device queue pair configuration structure. */
428 struct rte_cryptodev_qp_conf {
429         uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
430 };
431
432 /**
433  * Typedef for application callback function to be registered by application
434  * software for notification of device events
435  *
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.
440  */
441 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
442                 enum rte_cryptodev_event_type event, void *cb_arg);
443
444
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 */
451
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 */
456 };
457
458 #define RTE_CRYPTODEV_NAME_MAX_LEN      (64)
459 /**< Max length of name of crypto PMD */
460
461 /**
462  * Create a virtual crypto device
463  *
464  * @param       name    Cryptodev PMD name of device to be created.
465  * @param       args    Options arguments for device.
466  *
467  * @return
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.
471  */
472 extern int
473 rte_cryptodev_create_vdev(const char *name, const char *args);
474
475 /**
476  * Get the device identifier for the named crypto device.
477  *
478  * @param       name    device name to select the device structure.
479  *
480  * @return
481  *   - Returns crypto device identifier on success.
482  *   - Return -1 on failure to find named crypto device.
483  */
484 extern int
485 rte_cryptodev_get_dev_id(const char *name);
486
487 /**
488  * Get the total number of crypto devices that have been successfully
489  * initialised.
490  *
491  * @return
492  *   - The total number of usable crypto devices.
493  */
494 extern uint8_t
495 rte_cryptodev_count(void);
496
497 /**
498  * Get number of crypto device defined type.
499  *
500  * @param       driver_id       driver identifier.
501  *
502  * @return
503  *   Returns number of crypto device.
504  */
505 extern uint8_t
506 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
507
508 /**
509  * Get number and identifiers of attached crypto devices that
510  * use the same crypto driver.
511  *
512  * @param       driver_name     driver name.
513  * @param       devices         output devices identifiers.
514  * @param       nb_devices      maximal number of devices.
515  *
516  * @return
517  *   Returns number of attached crypto device.
518  */
519 uint8_t
520 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
521                 uint8_t nb_devices);
522 /*
523  * Return the NUMA socket to which a device is connected
524  *
525  * @param dev_id
526  *   The identifier of the device
527  * @return
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.
531  */
532 extern int
533 rte_cryptodev_socket_id(uint8_t dev_id);
534
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 */
540
541         struct {
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 */
545 };
546
547 /**
548  * Configure a device.
549  *
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
552  * stopped state.
553  *
554  * @param       dev_id          The identifier of the device to configure.
555  * @param       config          The crypto device configuration structure.
556  *
557  * @return
558  *   - 0: Success, device configured.
559  *   - <0: Error code returned by the driver configuration function.
560  */
561 extern int
562 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
563
564 /**
565  * Start an device.
566  *
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
569  * device.
570  * On success, all basic functions exported by the API (link status,
571  * receive/transmit, and so on) can be invoked.
572  *
573  * @param dev_id
574  *   The identifier of the device.
575  * @return
576  *   - 0: Success, device started.
577  *   - <0: Error code of the driver device start function.
578  */
579 extern int
580 rte_cryptodev_start(uint8_t dev_id);
581
582 /**
583  * Stop an device. The device can be restarted with a call to
584  * rte_cryptodev_start()
585  *
586  * @param       dev_id          The identifier of the device.
587  */
588 extern void
589 rte_cryptodev_stop(uint8_t dev_id);
590
591 /**
592  * Close an device. The device cannot be restarted!
593  *
594  * @param       dev_id          The identifier of the device.
595  *
596  * @return
597  *  - 0 on successfully closing device
598  *  - <0 on failure to close device
599  */
600 extern int
601 rte_cryptodev_close(uint8_t dev_id);
602
603 /**
604  * Allocate and set up a receive queue pair for a device.
605  *
606  *
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
615  *                              will be used.
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
620  *                              queue pair.
621  *
622  * @return
623  *   - 0: Success, queue pair correctly set up.
624  *   - <0: Queue pair configuration failed
625  */
626 extern int
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);
629
630 /**
631  * Start a specified queue pair of a device. It is used
632  * when deferred_start flag of the specified queue is true.
633  *
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().
639  * @return
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.
643  */
644 extern int
645 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
646
647 /**
648  * Stop specified queue pair of a device
649  *
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().
655  * @return
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.
659  */
660 extern int
661 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
662
663 /**
664  * Get the number of queue pairs on a specific crypto device
665  *
666  * @param       dev_id          Crypto device identifier.
667  * @return
668  *   - The number of configured queue pairs.
669  */
670 extern uint16_t
671 rte_cryptodev_queue_pair_count(uint8_t dev_id);
672
673
674 /**
675  * Retrieve the general I/O statistics of a device.
676  *
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.
681  * @return
682  *   - Zero if successful.
683  *   - Non-zero otherwise.
684  */
685 extern int
686 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
687
688 /**
689  * Reset the general I/O statistics of a device.
690  *
691  * @param       dev_id          The identifier of the device.
692  */
693 extern void
694 rte_cryptodev_stats_reset(uint8_t dev_id);
695
696 /**
697  * Retrieve the contextual information of a device.
698  *
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.
703  */
704 extern void
705 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
706
707
708 /**
709  * Register a callback function for specific device id.
710  *
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
715  *                              callback.
716  *
717  * @return
718  *  - On success, zero.
719  *  - On failure, a negative value.
720  */
721 extern int
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);
725
726 /**
727  * Unregister a callback function for specific device id.
728  *
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
733  *                              callback.
734  *
735  * @return
736  *  - On success, zero.
737  *  - On failure, a negative value.
738  */
739 extern int
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);
743
744
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. */
748
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. */
752
753
754
755
756 struct rte_cryptodev_callback;
757
758 /** Structure to keep track of registered callbacks */
759 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
760
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. */
767
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 */
776
777         uint8_t driver_id;
778         /**< Crypto driver identifier*/
779
780         struct rte_cryptodev_cb_list link_intr_cbs;
781         /**< User application callback for interrupts if present */
782
783         __extension__
784         uint8_t attached : 1;
785         /**< Flag indicating the device is attached */
786 } __rte_cache_aligned;
787
788 /**
789  *
790  * The data part, with no function pointers, associated with each device.
791  *
792  * This structure is safe to place in shared memory to be common among
793  * different processes in a multi-process configuration.
794  */
795 struct rte_cryptodev_data {
796         uint8_t dev_id;
797         /**< Device ID for this instance */
798         uint8_t socket_id;
799         /**< Socket ID where memory is allocated */
800         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
801         /**< Unique identifier name */
802
803         __extension__
804         uint8_t dev_started : 1;
805         /**< Device state: STARTED(1)/STOPPED(0) */
806
807         struct rte_mempool *session_pool;
808         /**< Session memory pool */
809         void **queue_pairs;
810         /**< Array of pointers to queue pairs. */
811         uint16_t nb_queue_pairs;
812         /**< Number of device queue pairs. */
813
814         void *dev_private;
815         /**< PMD-specific private data */
816 } __rte_cache_aligned;
817
818 extern struct rte_cryptodev *rte_cryptodevs;
819 /**
820  *
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.
824  *
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.
828  *
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.
836  *
837  * The rte_cryptodev_dequeue_burst() function does not provide any error
838  * notification to avoid the corresponding overhead.
839  *
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.
849  *
850  * @return
851  *   - The number of operations actually dequeued, which is the number
852  *   of pointers to *rte_crypto_op* structures effectively supplied to the
853  *   *ops* array.
854  */
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)
858 {
859         struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
860
861         nb_ops = (*dev->dequeue_burst)
862                         (dev->data->queue_pairs[qp_id], ops, nb_ops);
863
864         return nb_ops;
865 }
866
867 /**
868  * Enqueue a burst of operations for processing on a crypto device.
869  *
870  * The rte_cryptodev_enqueue_burst() function is invoked to place
871  * crypto operations on the queue *qp_id* of the device designated by
872  * its *dev_id*.
873  *
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.
876  *
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.
880  *
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.
891  *
892  * @return
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
896  * a *rte_crypto_op*.
897  */
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)
901 {
902         struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
903
904         return (*dev->enqueue_burst)(
905                         dev->data->queue_pairs[qp_id], ops, nb_ops);
906 }
907
908
909 /** Cryptodev symmetric crypto session */
910 struct rte_cryptodev_sym_session {
911         RTE_STD_C11
912         struct {
913                 uint8_t dev_id;
914                 /**< Device Id */
915                 uint8_t driver_id;
916                 /** Crypto driver identifier session created on */
917                 struct rte_mempool *mp;
918                 /**< Mempool session allocated from */
919         } __rte_aligned(8);
920         /**< Public symmetric session details */
921
922         __extension__ char _private[0];
923         /**< Private session material */
924 };
925
926
927 /**
928  * Initialise a session for symmetric cryptographic operations.
929  *
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.
937  *
938  * The rte_cryptodev_session_free must be called to free allocated
939  * memory when the session is no longer required.
940  *
941  * @param       dev_id          The device identifier.
942  * @param       xform           Crypto transform chain.
943
944  *
945  * @return
946  *  Pointer to the created session or NULL
947  */
948 extern struct rte_cryptodev_sym_session *
949 rte_cryptodev_sym_session_create(uint8_t dev_id,
950                 struct rte_crypto_sym_xform *xform);
951
952 /**
953  * Free the memory associated with a previously allocated session.
954  *
955  * @param       dev_id          The device identifier.
956  * @param       session         Session pointer previously allocated by
957  *                              *rte_cryptodev_sym_session_create*.
958  *
959  * @return
960  *   NULL on successful freeing of session.
961  *   Session pointer on failure to free session.
962  */
963 extern struct rte_cryptodev_sym_session *
964 rte_cryptodev_sym_session_free(uint8_t dev_id,
965                 struct rte_cryptodev_sym_session *session);
966
967 /**
968  * Attach queue pair with sym session.
969  *
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*.
973  *
974  * @return
975  *  - On success, zero.
976  *  - On failure, a negative value.
977  */
978 int
979 rte_cryptodev_queue_pair_attach_sym_session(uint16_t qp_id,
980                 struct rte_cryptodev_sym_session *session);
981
982 /**
983  * Detach queue pair with sym session.
984  *
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*.
988  *
989  * @return
990  *  - On success, zero.
991  *  - On failure, a negative value.
992  */
993 int
994 rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
995                 struct rte_cryptodev_sym_session *session);
996
997 /**
998  * Provide driver identifier.
999  *
1000  * @param name
1001  *   The pointer to a driver name.
1002  * @return
1003  *  The driver type identifier or -1 if no driver found
1004  */
1005 int rte_cryptodev_driver_id_get(const char *name);
1006
1007 /**
1008  * Provide driver name.
1009  *
1010  * @param driver_id
1011  *   The driver identifier.
1012  * @return
1013  *  The driver name or null if no driver found
1014  */
1015 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1016
1017 /**
1018  * @internal
1019  * Allocate Cryptodev driver.
1020  *
1021  * @param driver
1022  *   Pointer to rte_driver.
1023  * @return
1024  *  The driver type identifier
1025  */
1026 uint8_t rte_cryptodev_allocate_driver(const struct rte_driver *driver);
1027
1028
1029 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(drv, driver_id)\
1030 RTE_INIT(init_ ##driver_id);\
1031 static void init_ ##driver_id(void)\
1032 {\
1033         driver_id = rte_cryptodev_allocate_driver(&(drv).driver);\
1034 }
1035
1036
1037 #ifdef __cplusplus
1038 }
1039 #endif
1040
1041 #endif /* _RTE_CRYPTODEV_H_ */