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