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