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