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