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