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