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