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