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