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