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