cryptodev: add AEAD specific data
[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 / AEAD */
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                 struct {
203                         enum rte_crypto_aead_algorithm algo;
204                         /**< AEAD algorithm */
205                         uint16_t block_size;
206                         /**< algorithm block size */
207                         struct rte_crypto_param_range key_size;
208                         /**< AEAD key size range */
209                         struct rte_crypto_param_range digest_size;
210                         /**< digest size range */
211                         struct rte_crypto_param_range aad_size;
212                         /**< Additional authentication data size range */
213                         struct rte_crypto_param_range iv_size;
214                         /**< Initialisation vector data size range */
215                 } aead;
216         };
217 };
218
219 /** Structure used to capture a capability of a crypto device */
220 struct rte_cryptodev_capabilities {
221         enum rte_crypto_op_type op;
222         /**< Operation type */
223
224         RTE_STD_C11
225         union {
226                 struct rte_cryptodev_symmetric_capability sym;
227                 /**< Symmetric operation capability parameters */
228         };
229 };
230
231 /** Structure used to describe crypto algorithms */
232 struct rte_cryptodev_sym_capability_idx {
233         enum rte_crypto_sym_xform_type type;
234         union {
235                 enum rte_crypto_cipher_algorithm cipher;
236                 enum rte_crypto_auth_algorithm auth;
237                 enum rte_crypto_aead_algorithm aead;
238         } algo;
239 };
240
241 /**
242  *  Provide capabilities available for defined device and algorithm
243  *
244  * @param       dev_id          The identifier of the device.
245  * @param       idx             Description of crypto algorithms.
246  *
247  * @return
248  *   - Return description of the symmetric crypto capability if exist.
249  *   - Return NULL if the capability not exist.
250  */
251 const struct rte_cryptodev_symmetric_capability *
252 rte_cryptodev_sym_capability_get(uint8_t dev_id,
253                 const struct rte_cryptodev_sym_capability_idx *idx);
254
255 /**
256  * Check if key size and initial vector are supported
257  * in crypto cipher capability
258  *
259  * @param       capability      Description of the symmetric crypto capability.
260  * @param       key_size        Cipher key size.
261  * @param       iv_size         Cipher initial vector size.
262  *
263  * @return
264  *   - Return 0 if the parameters are in range of the capability.
265  *   - Return -1 if the parameters are out of range of the capability.
266  */
267 int
268 rte_cryptodev_sym_capability_check_cipher(
269                 const struct rte_cryptodev_symmetric_capability *capability,
270                 uint16_t key_size, uint16_t iv_size);
271
272 /**
273  * Check if key size and initial vector are supported
274  * in crypto auth capability
275  *
276  * @param       capability      Description of the symmetric crypto capability.
277  * @param       key_size        Auth key size.
278  * @param       digest_size     Auth digest size.
279  * @param       aad_size        Auth aad size.
280  * @param       iv_size         Auth initial vector size.
281  *
282  * @return
283  *   - Return 0 if the parameters are in range of the capability.
284  *   - Return -1 if the parameters are out of range of the capability.
285  */
286 int
287 rte_cryptodev_sym_capability_check_auth(
288                 const struct rte_cryptodev_symmetric_capability *capability,
289                 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
290                 uint16_t iv_size);
291
292 /**
293  * Check if key, digest, AAD and initial vector sizes are supported
294  * in crypto AEAD capability
295  *
296  * @param       capability      Description of the symmetric crypto capability.
297  * @param       key_size        AEAD key size.
298  * @param       digest_size     AEAD digest size.
299  * @param       aad_size        AEAD AAD size.
300  * @param       iv_size         AEAD IV size.
301  *
302  * @return
303  *   - Return 0 if the parameters are in range of the capability.
304  *   - Return -1 if the parameters are out of range of the capability.
305  */
306 int
307 rte_cryptodev_sym_capability_check_aead(
308                 const struct rte_cryptodev_symmetric_capability *capability,
309                 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
310                 uint16_t iv_size);
311
312 /**
313  * Provide the cipher algorithm enum, given an algorithm string
314  *
315  * @param       algo_enum       A pointer to the cipher 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_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
325                 const char *algo_string);
326
327 /**
328  * Provide the authentication algorithm enum, given an algorithm string
329  *
330  * @param       algo_enum       A pointer to the authentication algorithm
331  *                              enum to be filled
332  * @param       algo_string     Authentication algo 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_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
340                 const char *algo_string);
341
342 /**
343  * Provide the AEAD algorithm enum, given an algorithm string
344  *
345  * @param       algo_enum       A pointer to the AEAD algorithm
346  *                              enum to be filled
347  * @param       algo_string     AEAD algorithm string
348  *
349  * @return
350  * - Return -1 if string is not valid
351  * - Return 0 is the string is valid
352  */
353 int
354 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
355                 const char *algo_string);
356
357 /** Macro used at end of crypto PMD list */
358 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
359         { RTE_CRYPTO_OP_TYPE_UNDEFINED }
360
361
362 /**
363  * Crypto device supported feature flags
364  *
365  * Note:
366  * New features flags should be added to the end of the list
367  *
368  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
369  */
370 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO       (1ULL << 0)
371 /**< Symmetric crypto operations are supported */
372 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO      (1ULL << 1)
373 /**< Asymmetric crypto operations are supported */
374 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
375 /**< Chaining symmetric crypto operations are supported */
376 #define RTE_CRYPTODEV_FF_CPU_SSE                (1ULL << 3)
377 /**< Utilises CPU SIMD SSE instructions */
378 #define RTE_CRYPTODEV_FF_CPU_AVX                (1ULL << 4)
379 /**< Utilises CPU SIMD AVX instructions */
380 #define RTE_CRYPTODEV_FF_CPU_AVX2               (1ULL << 5)
381 /**< Utilises CPU SIMD AVX2 instructions */
382 #define RTE_CRYPTODEV_FF_CPU_AESNI              (1ULL << 6)
383 /**< Utilises CPU AES-NI instructions */
384 #define RTE_CRYPTODEV_FF_HW_ACCELERATED         (1ULL << 7)
385 /**< Operations are off-loaded to an external hardware accelerator */
386 #define RTE_CRYPTODEV_FF_CPU_AVX512             (1ULL << 8)
387 /**< Utilises CPU SIMD AVX512 instructions */
388 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER    (1ULL << 9)
389 /**< Scatter-gather mbufs are supported */
390 #define RTE_CRYPTODEV_FF_CPU_NEON               (1ULL << 10)
391 /**< Utilises CPU NEON instructions */
392 #define RTE_CRYPTODEV_FF_CPU_ARM_CE             (1ULL << 11)
393 /**< Utilises ARM CPU Cryptographic Extensions */
394
395
396 /**
397  * Get the name of a crypto device feature flag
398  *
399  * @param       flag    The mask describing the flag.
400  *
401  * @return
402  *   The name of this flag, or NULL if it's not a valid feature flag.
403  */
404
405 extern const char *
406 rte_cryptodev_get_feature_name(uint64_t flag);
407
408 /**  Crypto device information */
409 struct rte_cryptodev_info {
410         const char *driver_name;                /**< Driver name. */
411         enum rte_cryptodev_type dev_type;       /**< Device type */
412         struct rte_pci_device *pci_dev;         /**< PCI information. */
413
414         uint64_t feature_flags;                 /**< Feature flags */
415
416         const struct rte_cryptodev_capabilities *capabilities;
417         /**< Array of devices supported capabilities */
418
419         unsigned max_nb_queue_pairs;
420         /**< Maximum number of queues pairs supported by device. */
421
422         struct {
423                 unsigned max_nb_sessions;
424                 /**< Maximum number of sessions supported by device. */
425                 unsigned int max_nb_sessions_per_qp;
426                 /**< Maximum number of sessions per queue pair.
427                  * Default 0 for infinite sessions
428                  */
429         } sym;
430 };
431
432 #define RTE_CRYPTODEV_DETACHED  (0)
433 #define RTE_CRYPTODEV_ATTACHED  (1)
434
435 /** Definitions of Crypto device event types */
436 enum rte_cryptodev_event_type {
437         RTE_CRYPTODEV_EVENT_UNKNOWN,    /**< unknown event type */
438         RTE_CRYPTODEV_EVENT_ERROR,      /**< error interrupt event */
439         RTE_CRYPTODEV_EVENT_MAX         /**< max value of this enum */
440 };
441
442 /** Crypto device queue pair configuration structure. */
443 struct rte_cryptodev_qp_conf {
444         uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
445 };
446
447 /**
448  * Typedef for application callback function to be registered by application
449  * software for notification of device events
450  *
451  * @param       dev_id  Crypto device identifier
452  * @param       event   Crypto device event to register for notification of.
453  * @param       cb_arg  User specified parameter to be passed as to passed to
454  *                      users callback function.
455  */
456 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
457                 enum rte_cryptodev_event_type event, void *cb_arg);
458
459
460 /** Crypto Device statistics */
461 struct rte_cryptodev_stats {
462         uint64_t enqueued_count;
463         /**< Count of all operations enqueued */
464         uint64_t dequeued_count;
465         /**< Count of all operations dequeued */
466
467         uint64_t enqueue_err_count;
468         /**< Total error count on operations enqueued */
469         uint64_t dequeue_err_count;
470         /**< Total error count on operations dequeued */
471 };
472
473 #define RTE_CRYPTODEV_NAME_MAX_LEN      (64)
474 /**< Max length of name of crypto PMD */
475
476 /**
477  * Create a virtual crypto device
478  *
479  * @param       name    Cryptodev PMD name of device to be created.
480  * @param       args    Options arguments for device.
481  *
482  * @return
483  * - On successful creation of the cryptodev the device index is returned,
484  *   which will be between 0 and rte_cryptodev_count().
485  * - In the case of a failure, returns -1.
486  */
487 extern int
488 rte_cryptodev_create_vdev(const char *name, const char *args);
489
490 /**
491  * Get the device identifier for the named crypto device.
492  *
493  * @param       name    device name to select the device structure.
494  *
495  * @return
496  *   - Returns crypto device identifier on success.
497  *   - Return -1 on failure to find named crypto device.
498  */
499 extern int
500 rte_cryptodev_get_dev_id(const char *name);
501
502 /**
503  * Get the total number of crypto devices that have been successfully
504  * initialised.
505  *
506  * @return
507  *   - The total number of usable crypto devices.
508  */
509 extern uint8_t
510 rte_cryptodev_count(void);
511
512 /**
513  * Get number of crypto device defined type.
514  *
515  * @param       type    type of device.
516  *
517  * @return
518  *   Returns number of crypto device.
519  */
520 extern uint8_t
521 rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
522
523 /**
524  * Get number and identifiers of attached crypto devices that
525  * use the same crypto driver.
526  *
527  * @param       driver_name     driver name.
528  * @param       devices         output devices identifiers.
529  * @param       nb_devices      maximal number of devices.
530  *
531  * @return
532  *   Returns number of attached crypto device.
533  */
534 uint8_t
535 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
536                 uint8_t nb_devices);
537 /*
538  * Return the NUMA socket to which a device is connected
539  *
540  * @param dev_id
541  *   The identifier of the device
542  * @return
543  *   The NUMA socket id to which the device is connected or
544  *   a default of zero if the socket could not be determined.
545  *   -1 if returned is the dev_id value is out of range.
546  */
547 extern int
548 rte_cryptodev_socket_id(uint8_t dev_id);
549
550 /** Crypto device configuration structure */
551 struct rte_cryptodev_config {
552         int socket_id;                  /**< Socket to allocate resources on */
553         uint16_t nb_queue_pairs;
554         /**< Number of queue pairs to configure on device */
555
556         struct {
557                 uint32_t nb_objs;       /**< Number of objects in mempool */
558                 uint32_t cache_size;    /**< l-core object cache size */
559         } session_mp;           /**< Session mempool configuration */
560 };
561
562 /**
563  * Configure a device.
564  *
565  * This function must be invoked first before any other function in the
566  * API. This function can also be re-invoked when a device is in the
567  * stopped state.
568  *
569  * @param       dev_id          The identifier of the device to configure.
570  * @param       config          The crypto device configuration structure.
571  *
572  * @return
573  *   - 0: Success, device configured.
574  *   - <0: Error code returned by the driver configuration function.
575  */
576 extern int
577 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
578
579 /**
580  * Start an device.
581  *
582  * The device start step is the last one and consists of setting the configured
583  * offload features and in starting the transmit and the receive units of the
584  * device.
585  * On success, all basic functions exported by the API (link status,
586  * receive/transmit, and so on) can be invoked.
587  *
588  * @param dev_id
589  *   The identifier of the device.
590  * @return
591  *   - 0: Success, device started.
592  *   - <0: Error code of the driver device start function.
593  */
594 extern int
595 rte_cryptodev_start(uint8_t dev_id);
596
597 /**
598  * Stop an device. The device can be restarted with a call to
599  * rte_cryptodev_start()
600  *
601  * @param       dev_id          The identifier of the device.
602  */
603 extern void
604 rte_cryptodev_stop(uint8_t dev_id);
605
606 /**
607  * Close an device. The device cannot be restarted!
608  *
609  * @param       dev_id          The identifier of the device.
610  *
611  * @return
612  *  - 0 on successfully closing device
613  *  - <0 on failure to close device
614  */
615 extern int
616 rte_cryptodev_close(uint8_t dev_id);
617
618 /**
619  * Allocate and set up a receive queue pair for a device.
620  *
621  *
622  * @param       dev_id          The identifier of the device.
623  * @param       queue_pair_id   The index of the queue pairs to set up. The
624  *                              value must be in the range [0, nb_queue_pair
625  *                              - 1] previously supplied to
626  *                              rte_cryptodev_configure().
627  * @param       qp_conf         The pointer to the configuration data to be
628  *                              used for the queue pair. NULL value is
629  *                              allowed, in which case default configuration
630  *                              will be used.
631  * @param       socket_id       The *socket_id* argument is the socket
632  *                              identifier in case of NUMA. The value can be
633  *                              *SOCKET_ID_ANY* if there is no NUMA constraint
634  *                              for the DMA memory allocated for the receive
635  *                              queue pair.
636  *
637  * @return
638  *   - 0: Success, queue pair correctly set up.
639  *   - <0: Queue pair configuration failed
640  */
641 extern int
642 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
643                 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
644
645 /**
646  * Start a specified queue pair of a device. It is used
647  * when deferred_start flag of the specified queue is true.
648  *
649  * @param       dev_id          The identifier of the device
650  * @param       queue_pair_id   The index of the queue pair to start. The value
651  *                              must be in the range [0, nb_queue_pair - 1]
652  *                              previously supplied to
653  *                              rte_crypto_dev_configure().
654  * @return
655  *   - 0: Success, the transmit queue is correctly set up.
656  *   - -EINVAL: The dev_id or the queue_id out of range.
657  *   - -ENOTSUP: The function not supported in PMD driver.
658  */
659 extern int
660 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
661
662 /**
663  * Stop specified queue pair of a device
664  *
665  * @param       dev_id          The identifier of the device
666  * @param       queue_pair_id   The index of the queue pair to stop. The value
667  *                              must be in the range [0, nb_queue_pair - 1]
668  *                              previously supplied to
669  *                              rte_cryptodev_configure().
670  * @return
671  *   - 0: Success, the transmit queue is correctly set up.
672  *   - -EINVAL: The dev_id or the queue_id out of range.
673  *   - -ENOTSUP: The function not supported in PMD driver.
674  */
675 extern int
676 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
677
678 /**
679  * Get the number of queue pairs on a specific crypto device
680  *
681  * @param       dev_id          Crypto device identifier.
682  * @return
683  *   - The number of configured queue pairs.
684  */
685 extern uint16_t
686 rte_cryptodev_queue_pair_count(uint8_t dev_id);
687
688
689 /**
690  * Retrieve the general I/O statistics of a device.
691  *
692  * @param       dev_id          The identifier of the device.
693  * @param       stats           A pointer to a structure of type
694  *                              *rte_cryptodev_stats* to be filled with the
695  *                              values of device counters.
696  * @return
697  *   - Zero if successful.
698  *   - Non-zero otherwise.
699  */
700 extern int
701 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
702
703 /**
704  * Reset the general I/O statistics of a device.
705  *
706  * @param       dev_id          The identifier of the device.
707  */
708 extern void
709 rte_cryptodev_stats_reset(uint8_t dev_id);
710
711 /**
712  * Retrieve the contextual information of a device.
713  *
714  * @param       dev_id          The identifier of the device.
715  * @param       dev_info        A pointer to a structure of type
716  *                              *rte_cryptodev_info* to be filled with the
717  *                              contextual information of the device.
718  */
719 extern void
720 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
721
722
723 /**
724  * Register a callback function for specific device id.
725  *
726  * @param       dev_id          Device id.
727  * @param       event           Event interested.
728  * @param       cb_fn           User supplied callback function to be called.
729  * @param       cb_arg          Pointer to the parameters for the registered
730  *                              callback.
731  *
732  * @return
733  *  - On success, zero.
734  *  - On failure, a negative value.
735  */
736 extern int
737 rte_cryptodev_callback_register(uint8_t dev_id,
738                 enum rte_cryptodev_event_type event,
739                 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
740
741 /**
742  * Unregister a callback function for specific device id.
743  *
744  * @param       dev_id          The device identifier.
745  * @param       event           Event interested.
746  * @param       cb_fn           User supplied callback function to be called.
747  * @param       cb_arg          Pointer to the parameters for the registered
748  *                              callback.
749  *
750  * @return
751  *  - On success, zero.
752  *  - On failure, a negative value.
753  */
754 extern int
755 rte_cryptodev_callback_unregister(uint8_t dev_id,
756                 enum rte_cryptodev_event_type event,
757                 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
758
759
760 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
761                 struct rte_crypto_op **ops,     uint16_t nb_ops);
762 /**< Dequeue processed packets from queue pair of a device. */
763
764 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
765                 struct rte_crypto_op **ops,     uint16_t nb_ops);
766 /**< Enqueue packets for processing on queue pair of a device. */
767
768
769
770
771 struct rte_cryptodev_callback;
772
773 /** Structure to keep track of registered callbacks */
774 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
775
776 /** The data structure associated with each crypto device. */
777 struct rte_cryptodev {
778         dequeue_pkt_burst_t dequeue_burst;
779         /**< Pointer to PMD receive function. */
780         enqueue_pkt_burst_t enqueue_burst;
781         /**< Pointer to PMD transmit function. */
782
783         struct rte_cryptodev_data *data;
784         /**< Pointer to device data */
785         struct rte_cryptodev_ops *dev_ops;
786         /**< Functions exported by PMD */
787         uint64_t feature_flags;
788         /**< Supported features */
789         struct rte_device *device;
790         /**< Backing device */
791
792         enum rte_cryptodev_type dev_type;
793         /**< Crypto device type */
794
795         struct rte_cryptodev_cb_list link_intr_cbs;
796         /**< User application callback for interrupts if present */
797
798         __extension__
799         uint8_t attached : 1;
800         /**< Flag indicating the device is attached */
801 } __rte_cache_aligned;
802
803 /**
804  *
805  * The data part, with no function pointers, associated with each device.
806  *
807  * This structure is safe to place in shared memory to be common among
808  * different processes in a multi-process configuration.
809  */
810 struct rte_cryptodev_data {
811         uint8_t dev_id;
812         /**< Device ID for this instance */
813         uint8_t socket_id;
814         /**< Socket ID where memory is allocated */
815         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
816         /**< Unique identifier name */
817
818         __extension__
819         uint8_t dev_started : 1;
820         /**< Device state: STARTED(1)/STOPPED(0) */
821
822         struct rte_mempool *session_pool;
823         /**< Session memory pool */
824         void **queue_pairs;
825         /**< Array of pointers to queue pairs. */
826         uint16_t nb_queue_pairs;
827         /**< Number of device queue pairs. */
828
829         void *dev_private;
830         /**< PMD-specific private data */
831 } __rte_cache_aligned;
832
833 extern struct rte_cryptodev *rte_cryptodevs;
834 /**
835  *
836  * Dequeue a burst of processed crypto operations from a queue on the crypto
837  * device. The dequeued operation are stored in *rte_crypto_op* structures
838  * whose pointers are supplied in the *ops* array.
839  *
840  * The rte_cryptodev_dequeue_burst() function returns the number of ops
841  * actually dequeued, which is the number of *rte_crypto_op* data structures
842  * effectively supplied into the *ops* array.
843  *
844  * A return value equal to *nb_ops* indicates that the queue contained
845  * at least *nb_ops* operations, and this is likely to signify that other
846  * processed operations remain in the devices output queue. Applications
847  * implementing a "retrieve as many processed operations as possible" policy
848  * can check this specific case and keep invoking the
849  * rte_cryptodev_dequeue_burst() function until a value less than
850  * *nb_ops* is returned.
851  *
852  * The rte_cryptodev_dequeue_burst() function does not provide any error
853  * notification to avoid the corresponding overhead.
854  *
855  * @param       dev_id          The symmetric crypto device identifier
856  * @param       qp_id           The index of the queue pair from which to
857  *                              retrieve processed packets. The value must be
858  *                              in the range [0, nb_queue_pair - 1] previously
859  *                              supplied to rte_cryptodev_configure().
860  * @param       ops             The address of an array of pointers to
861  *                              *rte_crypto_op* structures that must be
862  *                              large enough to store *nb_ops* pointers in it.
863  * @param       nb_ops          The maximum number of operations to dequeue.
864  *
865  * @return
866  *   - The number of operations actually dequeued, which is the number
867  *   of pointers to *rte_crypto_op* structures effectively supplied to the
868  *   *ops* array.
869  */
870 static inline uint16_t
871 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
872                 struct rte_crypto_op **ops, uint16_t nb_ops)
873 {
874         struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
875
876         nb_ops = (*dev->dequeue_burst)
877                         (dev->data->queue_pairs[qp_id], ops, nb_ops);
878
879         return nb_ops;
880 }
881
882 /**
883  * Enqueue a burst of operations for processing on a crypto device.
884  *
885  * The rte_cryptodev_enqueue_burst() function is invoked to place
886  * crypto operations on the queue *qp_id* of the device designated by
887  * its *dev_id*.
888  *
889  * The *nb_ops* parameter is the number of operations to process which are
890  * supplied in the *ops* array of *rte_crypto_op* structures.
891  *
892  * The rte_cryptodev_enqueue_burst() function returns the number of
893  * operations it actually enqueued for processing. A return value equal to
894  * *nb_ops* means that all packets have been enqueued.
895  *
896  * @param       dev_id          The identifier of the device.
897  * @param       qp_id           The index of the queue pair which packets are
898  *                              to be enqueued for processing. The value
899  *                              must be in the range [0, nb_queue_pairs - 1]
900  *                              previously supplied to
901  *                               *rte_cryptodev_configure*.
902  * @param       ops             The address of an array of *nb_ops* pointers
903  *                              to *rte_crypto_op* structures which contain
904  *                              the crypto operations to be processed.
905  * @param       nb_ops          The number of operations to process.
906  *
907  * @return
908  * The number of operations actually enqueued on the crypto device. The return
909  * value can be less than the value of the *nb_ops* parameter when the
910  * crypto devices queue is full or if invalid parameters are specified in
911  * a *rte_crypto_op*.
912  */
913 static inline uint16_t
914 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
915                 struct rte_crypto_op **ops, uint16_t nb_ops)
916 {
917         struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
918
919         return (*dev->enqueue_burst)(
920                         dev->data->queue_pairs[qp_id], ops, nb_ops);
921 }
922
923
924 /** Cryptodev symmetric crypto session */
925 struct rte_cryptodev_sym_session {
926         RTE_STD_C11
927         struct {
928                 uint8_t dev_id;
929                 /**< Device Id */
930                 enum rte_cryptodev_type dev_type;
931                 /** Crypto Device type session created on */
932                 struct rte_mempool *mp;
933                 /**< Mempool session allocated from */
934         } __rte_aligned(8);
935         /**< Public symmetric session details */
936
937         __extension__ char _private[0];
938         /**< Private session material */
939 };
940
941
942 /**
943  * Initialise a session for symmetric cryptographic operations.
944  *
945  * This function is used by the client to initialize immutable
946  * parameters of symmetric cryptographic operation.
947  * To perform the operation the rte_cryptodev_enqueue_burst function is
948  * used.  Each mbuf should contain a reference to the session
949  * pointer returned from this function contained within it's crypto_op if a
950  * session-based operation is being provisioned. Memory to contain the session
951  * information is allocated from within mempool managed by the cryptodev.
952  *
953  * The rte_cryptodev_session_free must be called to free allocated
954  * memory when the session is no longer required.
955  *
956  * @param       dev_id          The device identifier.
957  * @param       xform           Crypto transform chain.
958
959  *
960  * @return
961  *  Pointer to the created session or NULL
962  */
963 extern struct rte_cryptodev_sym_session *
964 rte_cryptodev_sym_session_create(uint8_t dev_id,
965                 struct rte_crypto_sym_xform *xform);
966
967 /**
968  * Free the memory associated with a previously allocated session.
969  *
970  * @param       dev_id          The device identifier.
971  * @param       session         Session pointer previously allocated by
972  *                              *rte_cryptodev_sym_session_create*.
973  *
974  * @return
975  *   NULL on successful freeing of session.
976  *   Session pointer on failure to free session.
977  */
978 extern struct rte_cryptodev_sym_session *
979 rte_cryptodev_sym_session_free(uint8_t dev_id,
980                 struct rte_cryptodev_sym_session *session);
981
982 /**
983  * Attach queue pair with sym session.
984  *
985  * @param       qp_id           Queue pair to which session will be 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_attach_sym_session(uint16_t qp_id,
995                 struct rte_cryptodev_sym_session *session);
996
997 /**
998  * Detach queue pair with sym session.
999  *
1000  * @param       qp_id           Queue pair to which session is attached.
1001  * @param       session         Session pointer previously allocated by
1002  *                              *rte_cryptodev_sym_session_create*.
1003  *
1004  * @return
1005  *  - On success, zero.
1006  *  - On failure, a negative value.
1007  */
1008 int
1009 rte_cryptodev_queue_pair_detach_sym_session(uint16_t qp_id,
1010                 struct rte_cryptodev_sym_session *session);
1011
1012
1013 #ifdef __cplusplus
1014 }
1015 #endif
1016
1017 #endif /* _RTE_CRYPTODEV_H_ */