cryptodev: remove debug compilation option
[dpdk.git] / lib / librte_cryptodev / rte_cryptodev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2017 Intel Corporation.
3  */
4
5 #ifndef _RTE_CRYPTODEV_H_
6 #define _RTE_CRYPTODEV_H_
7
8 /**
9  * @file rte_cryptodev.h
10  *
11  * RTE Cryptographic Device APIs
12  *
13  * Defines RTE Crypto Device APIs for the provisioning of cipher and
14  * authentication operations.
15  */
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #include "rte_kvargs.h"
22 #include "rte_crypto.h"
23 #include "rte_dev.h"
24 #include <rte_common.h>
25 #include <rte_config.h>
26
27 extern const char **rte_cyptodev_names;
28
29 /* Logging Macros */
30
31 #define CDEV_LOG_ERR(...) \
32         RTE_LOG(ERR, CRYPTODEV, \
33                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
34                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
35
36 #define CDEV_LOG_INFO(...) \
37         RTE_LOG(INFO, CRYPTODEV, \
38                 RTE_FMT(RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
39                         RTE_FMT_TAIL(__VA_ARGS__,)))
40
41 #define CDEV_LOG_DEBUG(...) \
42         RTE_LOG(DEBUG, CRYPTODEV, \
43                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
44                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__,)))
45
46 #define CDEV_PMD_TRACE(...) \
47         RTE_LOG(DEBUG, CRYPTODEV, \
48                 RTE_FMT("[%s] %s: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \
49                         dev, __func__, RTE_FMT_TAIL(__VA_ARGS__,)))
50
51 /**
52  * A macro that points to an offset from the start
53  * of the crypto operation structure (rte_crypto_op)
54  *
55  * The returned pointer is cast to type t.
56  *
57  * @param c
58  *   The crypto operation.
59  * @param o
60  *   The offset from the start of the crypto operation.
61  * @param t
62  *   The type to cast the result into.
63  */
64 #define rte_crypto_op_ctod_offset(c, t, o)      \
65         ((t)((char *)(c) + (o)))
66
67 /**
68  * A macro that returns the physical address that points
69  * to an offset from the start of the crypto operation
70  * (rte_crypto_op)
71  *
72  * @param c
73  *   The crypto operation.
74  * @param o
75  *   The offset from the start of the crypto operation
76  *   to calculate address from.
77  */
78 #define rte_crypto_op_ctophys_offset(c, o)      \
79         (rte_iova_t)((c)->phys_addr + (o))
80
81 /**
82  * Crypto parameters range description
83  */
84 struct rte_crypto_param_range {
85         uint16_t min;   /**< minimum size */
86         uint16_t max;   /**< maximum size */
87         uint16_t increment;
88         /**< if a range of sizes are supported,
89          * this parameter is used to indicate
90          * increments in byte size that are supported
91          * between the minimum and maximum
92          */
93 };
94
95 /**
96  * Symmetric Crypto Capability
97  */
98 struct rte_cryptodev_symmetric_capability {
99         enum rte_crypto_sym_xform_type xform_type;
100         /**< Transform type : Authentication / Cipher / AEAD */
101         RTE_STD_C11
102         union {
103                 struct {
104                         enum rte_crypto_auth_algorithm algo;
105                         /**< authentication algorithm */
106                         uint16_t block_size;
107                         /**< algorithm block size */
108                         struct rte_crypto_param_range key_size;
109                         /**< auth key size range */
110                         struct rte_crypto_param_range digest_size;
111                         /**< digest size range */
112                         struct rte_crypto_param_range aad_size;
113                         /**< Additional authentication data size range */
114                         struct rte_crypto_param_range iv_size;
115                         /**< Initialisation vector data size range */
116                 } auth;
117                 /**< Symmetric Authentication transform capabilities */
118                 struct {
119                         enum rte_crypto_cipher_algorithm algo;
120                         /**< cipher algorithm */
121                         uint16_t block_size;
122                         /**< algorithm block size */
123                         struct rte_crypto_param_range key_size;
124                         /**< cipher key size range */
125                         struct rte_crypto_param_range iv_size;
126                         /**< Initialisation vector data size range */
127                 } cipher;
128                 /**< Symmetric Cipher transform capabilities */
129                 struct {
130                         enum rte_crypto_aead_algorithm algo;
131                         /**< AEAD algorithm */
132                         uint16_t block_size;
133                         /**< algorithm block size */
134                         struct rte_crypto_param_range key_size;
135                         /**< AEAD key size range */
136                         struct rte_crypto_param_range digest_size;
137                         /**< digest size range */
138                         struct rte_crypto_param_range aad_size;
139                         /**< Additional authentication data size range */
140                         struct rte_crypto_param_range iv_size;
141                         /**< Initialisation vector data size range */
142                 } aead;
143         };
144 };
145
146 /** Structure used to capture a capability of a crypto device */
147 struct rte_cryptodev_capabilities {
148         enum rte_crypto_op_type op;
149         /**< Operation type */
150
151         RTE_STD_C11
152         union {
153                 struct rte_cryptodev_symmetric_capability sym;
154                 /**< Symmetric operation capability parameters */
155         };
156 };
157
158 /** Structure used to describe crypto algorithms */
159 struct rte_cryptodev_sym_capability_idx {
160         enum rte_crypto_sym_xform_type type;
161         union {
162                 enum rte_crypto_cipher_algorithm cipher;
163                 enum rte_crypto_auth_algorithm auth;
164                 enum rte_crypto_aead_algorithm aead;
165         } algo;
166 };
167
168 /**
169  *  Provide capabilities available for defined device and algorithm
170  *
171  * @param       dev_id          The identifier of the device.
172  * @param       idx             Description of crypto algorithms.
173  *
174  * @return
175  *   - Return description of the symmetric crypto capability if exist.
176  *   - Return NULL if the capability not exist.
177  */
178 const struct rte_cryptodev_symmetric_capability *
179 rte_cryptodev_sym_capability_get(uint8_t dev_id,
180                 const struct rte_cryptodev_sym_capability_idx *idx);
181
182 /**
183  * Check if key size and initial vector are supported
184  * in crypto cipher capability
185  *
186  * @param       capability      Description of the symmetric crypto capability.
187  * @param       key_size        Cipher key size.
188  * @param       iv_size         Cipher initial vector size.
189  *
190  * @return
191  *   - Return 0 if the parameters are in range of the capability.
192  *   - Return -1 if the parameters are out of range of the capability.
193  */
194 int
195 rte_cryptodev_sym_capability_check_cipher(
196                 const struct rte_cryptodev_symmetric_capability *capability,
197                 uint16_t key_size, uint16_t iv_size);
198
199 /**
200  * Check if key size and initial vector are supported
201  * in crypto auth capability
202  *
203  * @param       capability      Description of the symmetric crypto capability.
204  * @param       key_size        Auth key size.
205  * @param       digest_size     Auth digest size.
206  * @param       iv_size         Auth initial vector size.
207  *
208  * @return
209  *   - Return 0 if the parameters are in range of the capability.
210  *   - Return -1 if the parameters are out of range of the capability.
211  */
212 int
213 rte_cryptodev_sym_capability_check_auth(
214                 const struct rte_cryptodev_symmetric_capability *capability,
215                 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
216
217 /**
218  * Check if key, digest, AAD and initial vector sizes are supported
219  * in crypto AEAD capability
220  *
221  * @param       capability      Description of the symmetric crypto capability.
222  * @param       key_size        AEAD key size.
223  * @param       digest_size     AEAD digest size.
224  * @param       aad_size        AEAD AAD size.
225  * @param       iv_size         AEAD IV size.
226  *
227  * @return
228  *   - Return 0 if the parameters are in range of the capability.
229  *   - Return -1 if the parameters are out of range of the capability.
230  */
231 int
232 rte_cryptodev_sym_capability_check_aead(
233                 const struct rte_cryptodev_symmetric_capability *capability,
234                 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
235                 uint16_t iv_size);
236
237 /**
238  * Provide the cipher algorithm enum, given an algorithm string
239  *
240  * @param       algo_enum       A pointer to the cipher algorithm
241  *                              enum to be filled
242  * @param       algo_string     Authentication algo string
243  *
244  * @return
245  * - Return -1 if string is not valid
246  * - Return 0 is the string is valid
247  */
248 int
249 rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
250                 const char *algo_string);
251
252 /**
253  * Provide the authentication algorithm enum, given an algorithm string
254  *
255  * @param       algo_enum       A pointer to the authentication algorithm
256  *                              enum to be filled
257  * @param       algo_string     Authentication algo string
258  *
259  * @return
260  * - Return -1 if string is not valid
261  * - Return 0 is the string is valid
262  */
263 int
264 rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
265                 const char *algo_string);
266
267 /**
268  * Provide the AEAD algorithm enum, given an algorithm string
269  *
270  * @param       algo_enum       A pointer to the AEAD algorithm
271  *                              enum to be filled
272  * @param       algo_string     AEAD algorithm string
273  *
274  * @return
275  * - Return -1 if string is not valid
276  * - Return 0 is the string is valid
277  */
278 int
279 rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
280                 const char *algo_string);
281
282 /** Macro used at end of crypto PMD list */
283 #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
284         { RTE_CRYPTO_OP_TYPE_UNDEFINED }
285
286
287 /**
288  * Crypto device supported feature flags
289  *
290  * Note:
291  * New features flags should be added to the end of the list
292  *
293  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
294  */
295 #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO       (1ULL << 0)
296 /**< Symmetric crypto operations are supported */
297 #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO      (1ULL << 1)
298 /**< Asymmetric crypto operations are supported */
299 #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING (1ULL << 2)
300 /**< Chaining symmetric crypto operations are supported */
301 #define RTE_CRYPTODEV_FF_CPU_SSE                (1ULL << 3)
302 /**< Utilises CPU SIMD SSE instructions */
303 #define RTE_CRYPTODEV_FF_CPU_AVX                (1ULL << 4)
304 /**< Utilises CPU SIMD AVX instructions */
305 #define RTE_CRYPTODEV_FF_CPU_AVX2               (1ULL << 5)
306 /**< Utilises CPU SIMD AVX2 instructions */
307 #define RTE_CRYPTODEV_FF_CPU_AESNI              (1ULL << 6)
308 /**< Utilises CPU AES-NI instructions */
309 #define RTE_CRYPTODEV_FF_HW_ACCELERATED         (1ULL << 7)
310 /**< Operations are off-loaded to an external hardware accelerator */
311 #define RTE_CRYPTODEV_FF_CPU_AVX512             (1ULL << 8)
312 /**< Utilises CPU SIMD AVX512 instructions */
313 #define RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER    (1ULL << 9)
314 /**< Scatter-gather mbufs are supported */
315 #define RTE_CRYPTODEV_FF_CPU_NEON               (1ULL << 10)
316 /**< Utilises CPU NEON instructions */
317 #define RTE_CRYPTODEV_FF_CPU_ARM_CE             (1ULL << 11)
318 /**< Utilises ARM CPU Cryptographic Extensions */
319 #define RTE_CRYPTODEV_FF_SECURITY               (1ULL << 12)
320 /**< Support Security Protocol Processing */
321
322
323 /**
324  * Get the name of a crypto device feature flag
325  *
326  * @param       flag    The mask describing the flag.
327  *
328  * @return
329  *   The name of this flag, or NULL if it's not a valid feature flag.
330  */
331
332 extern const char *
333 rte_cryptodev_get_feature_name(uint64_t flag);
334
335 /**  Crypto device information */
336 struct rte_cryptodev_info {
337         const char *driver_name;                /**< Driver name. */
338         uint8_t driver_id;                      /**< Driver identifier */
339         struct rte_pci_device *pci_dev;         /**< PCI information. */
340
341         uint64_t feature_flags;
342         /**< Feature flags exposes HW/SW features for the given device */
343
344         const struct rte_cryptodev_capabilities *capabilities;
345         /**< Array of devices supported capabilities */
346
347         unsigned max_nb_queue_pairs;
348         /**< Maximum number of queues pairs supported by device. */
349
350         struct {
351                 unsigned max_nb_sessions;
352                 /**< Maximum number of sessions supported by device. */
353                 unsigned int max_nb_sessions_per_qp;
354                 /**< Maximum number of sessions per queue pair.
355                  * Default 0 for infinite sessions
356                  */
357         } sym;
358 };
359
360 #define RTE_CRYPTODEV_DETACHED  (0)
361 #define RTE_CRYPTODEV_ATTACHED  (1)
362
363 /** Definitions of Crypto device event types */
364 enum rte_cryptodev_event_type {
365         RTE_CRYPTODEV_EVENT_UNKNOWN,    /**< unknown event type */
366         RTE_CRYPTODEV_EVENT_ERROR,      /**< error interrupt event */
367         RTE_CRYPTODEV_EVENT_MAX         /**< max value of this enum */
368 };
369
370 /** Crypto device queue pair configuration structure. */
371 struct rte_cryptodev_qp_conf {
372         uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
373 };
374
375 /**
376  * Typedef for application callback function to be registered by application
377  * software for notification of device events
378  *
379  * @param       dev_id  Crypto device identifier
380  * @param       event   Crypto device event to register for notification of.
381  * @param       cb_arg  User specified parameter to be passed as to passed to
382  *                      users callback function.
383  */
384 typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
385                 enum rte_cryptodev_event_type event, void *cb_arg);
386
387
388 /** Crypto Device statistics */
389 struct rte_cryptodev_stats {
390         uint64_t enqueued_count;
391         /**< Count of all operations enqueued */
392         uint64_t dequeued_count;
393         /**< Count of all operations dequeued */
394
395         uint64_t enqueue_err_count;
396         /**< Total error count on operations enqueued */
397         uint64_t dequeue_err_count;
398         /**< Total error count on operations dequeued */
399 };
400
401 #define RTE_CRYPTODEV_NAME_MAX_LEN      (64)
402 /**< Max length of name of crypto PMD */
403
404 /**
405  * Get the device identifier for the named crypto device.
406  *
407  * @param       name    device name to select the device structure.
408  *
409  * @return
410  *   - Returns crypto device identifier on success.
411  *   - Return -1 on failure to find named crypto device.
412  */
413 extern int
414 rte_cryptodev_get_dev_id(const char *name);
415
416 /**
417  * Get the crypto device name given a device identifier.
418  *
419  * @param dev_id
420  *   The identifier of the device
421  *
422  * @return
423  *   - Returns crypto device name.
424  *   - Returns NULL if crypto device is not present.
425  */
426 extern const char *
427 rte_cryptodev_name_get(uint8_t dev_id);
428
429 /**
430  * Get the total number of crypto devices that have been successfully
431  * initialised.
432  *
433  * @return
434  *   - The total number of usable crypto devices.
435  */
436 extern uint8_t
437 rte_cryptodev_count(void);
438
439 /**
440  * Get number of crypto device defined type.
441  *
442  * @param       driver_id       driver identifier.
443  *
444  * @return
445  *   Returns number of crypto device.
446  */
447 extern uint8_t
448 rte_cryptodev_device_count_by_driver(uint8_t driver_id);
449
450 /**
451  * Get number and identifiers of attached crypto devices that
452  * use the same crypto driver.
453  *
454  * @param       driver_name     driver name.
455  * @param       devices         output devices identifiers.
456  * @param       nb_devices      maximal number of devices.
457  *
458  * @return
459  *   Returns number of attached crypto device.
460  */
461 uint8_t
462 rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
463                 uint8_t nb_devices);
464 /*
465  * Return the NUMA socket to which a device is connected
466  *
467  * @param dev_id
468  *   The identifier of the device
469  * @return
470  *   The NUMA socket id to which the device is connected or
471  *   a default of zero if the socket could not be determined.
472  *   -1 if returned is the dev_id value is out of range.
473  */
474 extern int
475 rte_cryptodev_socket_id(uint8_t dev_id);
476
477 /** Crypto device configuration structure */
478 struct rte_cryptodev_config {
479         int socket_id;                  /**< Socket to allocate resources on */
480         uint16_t nb_queue_pairs;
481         /**< Number of queue pairs to configure on device */
482 };
483
484 /**
485  * Configure a device.
486  *
487  * This function must be invoked first before any other function in the
488  * API. This function can also be re-invoked when a device is in the
489  * stopped state.
490  *
491  * @param       dev_id          The identifier of the device to configure.
492  * @param       config          The crypto device configuration structure.
493  *
494  * @return
495  *   - 0: Success, device configured.
496  *   - <0: Error code returned by the driver configuration function.
497  */
498 extern int
499 rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
500
501 /**
502  * Start an device.
503  *
504  * The device start step is the last one and consists of setting the configured
505  * offload features and in starting the transmit and the receive units of the
506  * device.
507  * On success, all basic functions exported by the API (link status,
508  * receive/transmit, and so on) can be invoked.
509  *
510  * @param dev_id
511  *   The identifier of the device.
512  * @return
513  *   - 0: Success, device started.
514  *   - <0: Error code of the driver device start function.
515  */
516 extern int
517 rte_cryptodev_start(uint8_t dev_id);
518
519 /**
520  * Stop an device. The device can be restarted with a call to
521  * rte_cryptodev_start()
522  *
523  * @param       dev_id          The identifier of the device.
524  */
525 extern void
526 rte_cryptodev_stop(uint8_t dev_id);
527
528 /**
529  * Close an device. The device cannot be restarted!
530  *
531  * @param       dev_id          The identifier of the device.
532  *
533  * @return
534  *  - 0 on successfully closing device
535  *  - <0 on failure to close device
536  */
537 extern int
538 rte_cryptodev_close(uint8_t dev_id);
539
540 /**
541  * Allocate and set up a receive queue pair for a device.
542  *
543  *
544  * @param       dev_id          The identifier of the device.
545  * @param       queue_pair_id   The index of the queue pairs to set up. The
546  *                              value must be in the range [0, nb_queue_pair
547  *                              - 1] previously supplied to
548  *                              rte_cryptodev_configure().
549  * @param       qp_conf         The pointer to the configuration data to be
550  *                              used for the queue pair. NULL value is
551  *                              allowed, in which case default configuration
552  *                              will be used.
553  * @param       socket_id       The *socket_id* argument is the socket
554  *                              identifier in case of NUMA. The value can be
555  *                              *SOCKET_ID_ANY* if there is no NUMA constraint
556  *                              for the DMA memory allocated for the receive
557  *                              queue pair.
558  * @param       session_pool    Pointer to device session mempool, used
559  *                              for session-less operations.
560  *
561  * @return
562  *   - 0: Success, queue pair correctly set up.
563  *   - <0: Queue pair configuration failed
564  */
565 extern int
566 rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
567                 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id,
568                 struct rte_mempool *session_pool);
569
570 /**
571  * @deprecated
572  * Start a specified queue pair of a device. It is used
573  * when deferred_start flag of the specified queue is true.
574  *
575  * @param       dev_id          The identifier of the device
576  * @param       queue_pair_id   The index of the queue pair to start. The value
577  *                              must be in the range [0, nb_queue_pair - 1]
578  *                              previously supplied to
579  *                              rte_crypto_dev_configure().
580  * @return
581  *   - 0: Success, the transmit queue is correctly set up.
582  *   - -EINVAL: The dev_id or the queue_id out of range.
583  *   - -ENOTSUP: The function not supported in PMD driver.
584  */
585 __rte_deprecated
586 extern int
587 rte_cryptodev_queue_pair_start(uint8_t dev_id, uint16_t queue_pair_id);
588
589 /**
590  * @deprecated
591  * Stop specified queue pair of a device
592  *
593  * @param       dev_id          The identifier of the device
594  * @param       queue_pair_id   The index of the queue pair to stop. The value
595  *                              must be in the range [0, nb_queue_pair - 1]
596  *                              previously supplied to
597  *                              rte_cryptodev_configure().
598  * @return
599  *   - 0: Success, the transmit queue is correctly set up.
600  *   - -EINVAL: The dev_id or the queue_id out of range.
601  *   - -ENOTSUP: The function not supported in PMD driver.
602  */
603 __rte_deprecated
604 extern int
605 rte_cryptodev_queue_pair_stop(uint8_t dev_id, uint16_t queue_pair_id);
606
607 /**
608  * Get the number of queue pairs on a specific crypto device
609  *
610  * @param       dev_id          Crypto device identifier.
611  * @return
612  *   - The number of configured queue pairs.
613  */
614 extern uint16_t
615 rte_cryptodev_queue_pair_count(uint8_t dev_id);
616
617
618 /**
619  * Retrieve the general I/O statistics of a device.
620  *
621  * @param       dev_id          The identifier of the device.
622  * @param       stats           A pointer to a structure of type
623  *                              *rte_cryptodev_stats* to be filled with the
624  *                              values of device counters.
625  * @return
626  *   - Zero if successful.
627  *   - Non-zero otherwise.
628  */
629 extern int
630 rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
631
632 /**
633  * Reset the general I/O statistics of a device.
634  *
635  * @param       dev_id          The identifier of the device.
636  */
637 extern void
638 rte_cryptodev_stats_reset(uint8_t dev_id);
639
640 /**
641  * Retrieve the contextual information of a device.
642  *
643  * @param       dev_id          The identifier of the device.
644  * @param       dev_info        A pointer to a structure of type
645  *                              *rte_cryptodev_info* to be filled with the
646  *                              contextual information of the device.
647  *
648  * @note The capabilities field of dev_info is set to point to the first
649  * element of an array of struct rte_cryptodev_capabilities. The element after
650  * the last valid element has it's op field set to
651  * RTE_CRYPTO_OP_TYPE_UNDEFINED.
652  */
653 extern void
654 rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
655
656
657 /**
658  * Register a callback function for specific device id.
659  *
660  * @param       dev_id          Device id.
661  * @param       event           Event interested.
662  * @param       cb_fn           User supplied callback function to be called.
663  * @param       cb_arg          Pointer to the parameters for the registered
664  *                              callback.
665  *
666  * @return
667  *  - On success, zero.
668  *  - On failure, a negative value.
669  */
670 extern int
671 rte_cryptodev_callback_register(uint8_t dev_id,
672                 enum rte_cryptodev_event_type event,
673                 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
674
675 /**
676  * Unregister a callback function for specific device id.
677  *
678  * @param       dev_id          The device identifier.
679  * @param       event           Event interested.
680  * @param       cb_fn           User supplied callback function to be called.
681  * @param       cb_arg          Pointer to the parameters for the registered
682  *                              callback.
683  *
684  * @return
685  *  - On success, zero.
686  *  - On failure, a negative value.
687  */
688 extern int
689 rte_cryptodev_callback_unregister(uint8_t dev_id,
690                 enum rte_cryptodev_event_type event,
691                 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
692
693
694 typedef uint16_t (*dequeue_pkt_burst_t)(void *qp,
695                 struct rte_crypto_op **ops,     uint16_t nb_ops);
696 /**< Dequeue processed packets from queue pair of a device. */
697
698 typedef uint16_t (*enqueue_pkt_burst_t)(void *qp,
699                 struct rte_crypto_op **ops,     uint16_t nb_ops);
700 /**< Enqueue packets for processing on queue pair of a device. */
701
702
703
704
705 struct rte_cryptodev_callback;
706
707 /** Structure to keep track of registered callbacks */
708 TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
709
710 /** The data structure associated with each crypto device. */
711 struct rte_cryptodev {
712         dequeue_pkt_burst_t dequeue_burst;
713         /**< Pointer to PMD receive function. */
714         enqueue_pkt_burst_t enqueue_burst;
715         /**< Pointer to PMD transmit function. */
716
717         struct rte_cryptodev_data *data;
718         /**< Pointer to device data */
719         struct rte_cryptodev_ops *dev_ops;
720         /**< Functions exported by PMD */
721         uint64_t feature_flags;
722         /**< Feature flags exposes HW/SW features for the given device */
723         struct rte_device *device;
724         /**< Backing device */
725
726         uint8_t driver_id;
727         /**< Crypto driver identifier*/
728
729         struct rte_cryptodev_cb_list link_intr_cbs;
730         /**< User application callback for interrupts if present */
731
732         void *security_ctx;
733         /**< Context for security ops */
734
735         __extension__
736         uint8_t attached : 1;
737         /**< Flag indicating the device is attached */
738 } __rte_cache_aligned;
739
740 void *
741 rte_cryptodev_get_sec_ctx(uint8_t dev_id);
742
743 /**
744  *
745  * The data part, with no function pointers, associated with each device.
746  *
747  * This structure is safe to place in shared memory to be common among
748  * different processes in a multi-process configuration.
749  */
750 struct rte_cryptodev_data {
751         uint8_t dev_id;
752         /**< Device ID for this instance */
753         uint8_t socket_id;
754         /**< Socket ID where memory is allocated */
755         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
756         /**< Unique identifier name */
757
758         __extension__
759         uint8_t dev_started : 1;
760         /**< Device state: STARTED(1)/STOPPED(0) */
761
762         struct rte_mempool *session_pool;
763         /**< Session memory pool */
764         void **queue_pairs;
765         /**< Array of pointers to queue pairs. */
766         uint16_t nb_queue_pairs;
767         /**< Number of device queue pairs. */
768
769         void *dev_private;
770         /**< PMD-specific private data */
771 } __rte_cache_aligned;
772
773 extern struct rte_cryptodev *rte_cryptodevs;
774 /**
775  *
776  * Dequeue a burst of processed crypto operations from a queue on the crypto
777  * device. The dequeued operation are stored in *rte_crypto_op* structures
778  * whose pointers are supplied in the *ops* array.
779  *
780  * The rte_cryptodev_dequeue_burst() function returns the number of ops
781  * actually dequeued, which is the number of *rte_crypto_op* data structures
782  * effectively supplied into the *ops* array.
783  *
784  * A return value equal to *nb_ops* indicates that the queue contained
785  * at least *nb_ops* operations, and this is likely to signify that other
786  * processed operations remain in the devices output queue. Applications
787  * implementing a "retrieve as many processed operations as possible" policy
788  * can check this specific case and keep invoking the
789  * rte_cryptodev_dequeue_burst() function until a value less than
790  * *nb_ops* is returned.
791  *
792  * The rte_cryptodev_dequeue_burst() function does not provide any error
793  * notification to avoid the corresponding overhead.
794  *
795  * @param       dev_id          The symmetric crypto device identifier
796  * @param       qp_id           The index of the queue pair from which to
797  *                              retrieve processed packets. The value must be
798  *                              in the range [0, nb_queue_pair - 1] previously
799  *                              supplied to rte_cryptodev_configure().
800  * @param       ops             The address of an array of pointers to
801  *                              *rte_crypto_op* structures that must be
802  *                              large enough to store *nb_ops* pointers in it.
803  * @param       nb_ops          The maximum number of operations to dequeue.
804  *
805  * @return
806  *   - The number of operations actually dequeued, which is the number
807  *   of pointers to *rte_crypto_op* structures effectively supplied to the
808  *   *ops* array.
809  */
810 static inline uint16_t
811 rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
812                 struct rte_crypto_op **ops, uint16_t nb_ops)
813 {
814         struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
815
816         nb_ops = (*dev->dequeue_burst)
817                         (dev->data->queue_pairs[qp_id], ops, nb_ops);
818
819         return nb_ops;
820 }
821
822 /**
823  * Enqueue a burst of operations for processing on a crypto device.
824  *
825  * The rte_cryptodev_enqueue_burst() function is invoked to place
826  * crypto operations on the queue *qp_id* of the device designated by
827  * its *dev_id*.
828  *
829  * The *nb_ops* parameter is the number of operations to process which are
830  * supplied in the *ops* array of *rte_crypto_op* structures.
831  *
832  * The rte_cryptodev_enqueue_burst() function returns the number of
833  * operations it actually enqueued for processing. A return value equal to
834  * *nb_ops* means that all packets have been enqueued.
835  *
836  * @param       dev_id          The identifier of the device.
837  * @param       qp_id           The index of the queue pair which packets are
838  *                              to be enqueued for processing. The value
839  *                              must be in the range [0, nb_queue_pairs - 1]
840  *                              previously supplied to
841  *                               *rte_cryptodev_configure*.
842  * @param       ops             The address of an array of *nb_ops* pointers
843  *                              to *rte_crypto_op* structures which contain
844  *                              the crypto operations to be processed.
845  * @param       nb_ops          The number of operations to process.
846  *
847  * @return
848  * The number of operations actually enqueued on the crypto device. The return
849  * value can be less than the value of the *nb_ops* parameter when the
850  * crypto devices queue is full or if invalid parameters are specified in
851  * a *rte_crypto_op*.
852  */
853 static inline uint16_t
854 rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
855                 struct rte_crypto_op **ops, uint16_t nb_ops)
856 {
857         struct rte_cryptodev *dev = &rte_cryptodevs[dev_id];
858
859         return (*dev->enqueue_burst)(
860                         dev->data->queue_pairs[qp_id], ops, nb_ops);
861 }
862
863
864 /** Cryptodev symmetric crypto session
865  * Each session is derived from a fixed xform chain. Therefore each session
866  * has a fixed algo, key, op-type, digest_len etc.
867  */
868 struct rte_cryptodev_sym_session {
869         __extension__ void *sess_private_data[0];
870         /**< Private session material */
871 };
872
873
874 /**
875  * Create symmetric crypto session header (generic with no private data)
876  *
877  * @param   mempool    Symmetric session mempool to allocate session
878  *                     objects from
879  * @return
880  *  - On success return pointer to sym-session
881  *  - On failure returns NULL
882  */
883 struct rte_cryptodev_sym_session *
884 rte_cryptodev_sym_session_create(struct rte_mempool *mempool);
885
886 /**
887  * Frees symmetric crypto session header, after checking that all
888  * the device private data has been freed, returning it
889  * to its original mempool.
890  *
891  * @param   sess     Session header to be freed.
892  *
893  * @return
894  *  - 0 if successful.
895  *  - -EINVAL if session is NULL.
896  *  - -EBUSY if not all device private data has been freed.
897  */
898 int
899 rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
900
901 /**
902  * Fill out private data for the device id, based on its device type.
903  *
904  * @param   dev_id   ID of device that we want the session to be used on
905  * @param   sess     Session where the private data will be attached to
906  * @param   xforms   Symmetric crypto transform operations to apply on flow
907  *                   processed with this session
908  * @param   mempool  Mempool where the private data is allocated.
909  *
910  * @return
911  *  - On success, zero.
912  *  - -EINVAL if input parameters are invalid.
913  *  - -ENOTSUP if crypto device does not support the crypto transform.
914  *  - -ENOMEM if the private session could not be allocated.
915  */
916 int
917 rte_cryptodev_sym_session_init(uint8_t dev_id,
918                         struct rte_cryptodev_sym_session *sess,
919                         struct rte_crypto_sym_xform *xforms,
920                         struct rte_mempool *mempool);
921
922 /**
923  * Frees private data for the device id, based on its device type,
924  * returning it to its mempool. It is the application's responsibility
925  * to ensure that private session data is not cleared while there are
926  * still in-flight operations using it.
927  *
928  * @param   dev_id   ID of device that uses the session.
929  * @param   sess     Session containing the reference to the private data
930  *
931  * @return
932  *  - 0 if successful.
933  *  - -EINVAL if device is invalid or session is NULL.
934  */
935 int
936 rte_cryptodev_sym_session_clear(uint8_t dev_id,
937                         struct rte_cryptodev_sym_session *sess);
938
939 /**
940  * @deprecated
941  * Get the size of the header session, for all registered drivers.
942  *
943  * @return
944  *   Size of the header session.
945  */
946 __rte_deprecated
947 unsigned int
948 rte_cryptodev_get_header_session_size(void);
949
950 /**
951  * @deprecated
952  * Get the size of the private session data for a device.
953  *
954  * @param       dev_id          The device identifier.
955  *
956  * @return
957  *   - Size of the private data, if successful
958  *   - 0 if device is invalid or does not have private session
959  */
960 __rte_deprecated
961 unsigned int
962 rte_cryptodev_get_private_session_size(uint8_t dev_id);
963
964 /**
965  * Get the size of the header session, for all registered drivers.
966  *
967  * @return
968  *   Size of the symmetric eader session.
969  */
970 unsigned int
971 rte_cryptodev_sym_get_header_session_size(void);
972
973 /**
974  * Get the size of the private symmetric session data
975  * for a device.
976  *
977  * @param       dev_id          The device identifier.
978  *
979  * @return
980  *   - Size of the private data, if successful
981  *   - 0 if device is invalid or does not have private
982  *   symmetric session
983  */
984 unsigned int
985 rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
986
987 /**
988  * @deprecated
989  * Attach queue pair with sym session.
990  *
991  * @param       dev_id          Device to which the session will be attached.
992  * @param       qp_id           Queue pair to which the session will be attached.
993  * @param       session         Session pointer previously allocated by
994  *                              *rte_cryptodev_sym_session_create*.
995  *
996  * @return
997  *  - On success, zero.
998  *  - On failure, a negative value.
999  */
1000 __rte_deprecated
1001 int
1002 rte_cryptodev_queue_pair_attach_sym_session(uint8_t dev_id, uint16_t qp_id,
1003                 struct rte_cryptodev_sym_session *session);
1004
1005 /**
1006  * @deprecated
1007  * Detach queue pair with sym session.
1008  *
1009  * @param       dev_id          Device to which the session is attached.
1010  * @param       qp_id           Queue pair to which the session is attached.
1011  * @param       session         Session pointer previously allocated by
1012  *                              *rte_cryptodev_sym_session_create*.
1013  *
1014  * @return
1015  *  - On success, zero.
1016  *  - On failure, a negative value.
1017  */
1018 __rte_deprecated
1019 int
1020 rte_cryptodev_queue_pair_detach_sym_session(uint8_t dev_id, uint16_t qp_id,
1021                 struct rte_cryptodev_sym_session *session);
1022
1023 /**
1024  * Provide driver identifier.
1025  *
1026  * @param name
1027  *   The pointer to a driver name.
1028  * @return
1029  *  The driver type identifier or -1 if no driver found
1030  */
1031 int rte_cryptodev_driver_id_get(const char *name);
1032
1033 /**
1034  * Provide driver name.
1035  *
1036  * @param driver_id
1037  *   The driver identifier.
1038  * @return
1039  *  The driver name or null if no driver found
1040  */
1041 const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
1042
1043 /**
1044  * Set private data for a session.
1045  *
1046  * @param       sess            Session pointer allocated by
1047  *                              *rte_cryptodev_sym_session_create*.
1048  * @param       data            Pointer to the private data.
1049  * @param       size            Size of the private data.
1050  *
1051  * @return
1052  *  - On success, zero.
1053  *  - On failure, a negative value.
1054  */
1055 int __rte_experimental
1056 rte_cryptodev_sym_session_set_private_data(
1057                                         struct rte_cryptodev_sym_session *sess,
1058                                         void *data,
1059                                         uint16_t size);
1060
1061 /**
1062  * Get private data of a session.
1063  *
1064  * @param       sess            Session pointer allocated by
1065  *                              *rte_cryptodev_sym_session_create*.
1066  *
1067  * @return
1068  *  - On success return pointer to private data.
1069  *  - On failure returns NULL.
1070  */
1071 void * __rte_experimental
1072 rte_cryptodev_sym_session_get_private_data(
1073                                         struct rte_cryptodev_sym_session *sess);
1074
1075 #ifdef __cplusplus
1076 }
1077 #endif
1078
1079 #endif /* _RTE_CRYPTODEV_H_ */