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