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