DPDK  18.05.1
rte_cryptodev_pmd.h
Go to the documentation of this file.
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_PMD_H_
33 #define _RTE_CRYPTODEV_PMD_H_
34 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #include <string.h>
48 
49 #include <rte_config.h>
50 #include <rte_dev.h>
51 #include <rte_malloc.h>
52 #include <rte_mbuf.h>
53 #include <rte_mempool.h>
54 #include <rte_log.h>
55 #include <rte_common.h>
56 
57 #include "rte_crypto.h"
58 #include "rte_cryptodev.h"
59 
60 
61 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS 8
62 #define RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_SESSIONS 2048
63 
64 #define RTE_CRYPTODEV_PMD_NAME_ARG ("name")
65 #define RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG ("max_nb_queue_pairs")
66 #define RTE_CRYPTODEV_PMD_MAX_NB_SESS_ARG ("max_nb_sessions")
67 #define RTE_CRYPTODEV_PMD_SOCKET_ID_ARG ("socket_id")
68 
69 
70 static const char * const cryptodev_pmd_valid_params[] = {
71  RTE_CRYPTODEV_PMD_NAME_ARG,
72  RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
73  RTE_CRYPTODEV_PMD_MAX_NB_SESS_ARG,
74  RTE_CRYPTODEV_PMD_SOCKET_ID_ARG
75 };
76 
81 struct rte_cryptodev_pmd_init_params {
82  char name[RTE_CRYPTODEV_NAME_MAX_LEN];
83  size_t private_data_size;
84  int socket_id;
85  unsigned int max_nb_queue_pairs;
86  unsigned int max_nb_sessions;
87 };
88 
91  struct rte_cryptodev *devs;
92  struct rte_cryptodev_data *data[RTE_CRYPTO_MAX_DEVS];
94  uint8_t nb_devs;
95  uint8_t max_devs;
96 };
97 
98 /* Cryptodev driver, containing the driver ID */
99 struct cryptodev_driver {
100  TAILQ_ENTRY(cryptodev_driver) next;
101  const struct rte_driver *driver;
102  uint8_t id;
103 };
104 
107 
117 struct rte_cryptodev *
118 rte_cryptodev_pmd_get_dev(uint8_t dev_id);
119 
128 struct rte_cryptodev *
129 rte_cryptodev_pmd_get_named_dev(const char *name);
130 
139 unsigned int
140 rte_cryptodev_pmd_is_valid_dev(uint8_t dev_id);
141 
145 extern struct rte_cryptodev *rte_cryptodevs;
146 
147 
162 typedef int (*cryptodev_configure_t)(struct rte_cryptodev *dev,
163  struct rte_cryptodev_config *config);
164 
172 typedef int (*cryptodev_start_t)(struct rte_cryptodev *dev);
173 
179 typedef void (*cryptodev_stop_t)(struct rte_cryptodev *dev);
180 
189 typedef int (*cryptodev_close_t)(struct rte_cryptodev *dev);
190 
191 
198 typedef void (*cryptodev_stats_get_t)(struct rte_cryptodev *dev,
199  struct rte_cryptodev_stats *stats);
200 
201 
207 typedef void (*cryptodev_stats_reset_t)(struct rte_cryptodev *dev);
208 
209 
215 typedef void (*cryptodev_info_get_t)(struct rte_cryptodev *dev,
216  struct rte_cryptodev_info *dev_info);
217 
226 typedef int (*cryptodev_queue_pair_start_t)(struct rte_cryptodev *dev,
227  uint16_t qp_id);
228 
237 typedef int (*cryptodev_queue_pair_stop_t)(struct rte_cryptodev *dev,
238  uint16_t qp_id);
239 
251 typedef int (*cryptodev_queue_pair_setup_t)(struct rte_cryptodev *dev,
252  uint16_t qp_id, const struct rte_cryptodev_qp_conf *qp_conf,
253  int socket_id, struct rte_mempool *session_pool);
254 
266  uint16_t qp_id);
267 
275 typedef uint32_t (*cryptodev_queue_pair_count_t)(struct rte_cryptodev *dev);
276 
290  struct rte_cryptodev *dev, unsigned nb_objs,
291  unsigned obj_cache_size, int socket_id);
292 
293 
304  struct rte_cryptodev *dev);
305 
321  struct rte_crypto_sym_xform *xform,
322  struct rte_cryptodev_sym_session *session,
323  struct rte_mempool *mp);
324 
331 typedef void (*cryptodev_sym_free_session_t)(struct rte_cryptodev *dev,
332  struct rte_cryptodev_sym_session *sess);
333 
343  struct rte_cryptodev *dev,
344  uint16_t qp_id,
345  void *session_private);
346 
356  struct rte_cryptodev *dev,
357  uint16_t qp_id,
358  void *session_private);
359 
395 };
396 
397 
409 struct rte_cryptodev *
410 rte_cryptodev_pmd_allocate(const char *name, int socket_id);
411 
422 extern int
424 
425 
443 int
444 rte_cryptodev_pmd_parse_input_args(
445  struct rte_cryptodev_pmd_init_params *params,
446  const char *args);
447 
462 struct rte_cryptodev *
463 rte_cryptodev_pmd_create(const char *name,
464  struct rte_device *device,
465  struct rte_cryptodev_pmd_init_params *params);
466 
479 int
480 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev);
481 
493  enum rte_cryptodev_event_type event);
494 
499 int
500 rte_cryptodev_pmd_create_dev_name(char *name, const char *dev_name_prefix);
501 
514 uint8_t rte_cryptodev_allocate_driver(struct cryptodev_driver *crypto_drv,
515  const struct rte_driver *drv);
516 
517 
518 #define RTE_PMD_REGISTER_CRYPTO_DRIVER(crypto_drv, drv, driver_id)\
519 RTE_INIT(init_ ##driver_id);\
520 static void init_ ##driver_id(void)\
521 {\
522  driver_id = rte_cryptodev_allocate_driver(&crypto_drv, &(drv));\
523 }
524 
525 static inline void *
526 get_session_private_data(const struct rte_cryptodev_sym_session *sess,
527  uint8_t driver_id) {
528  return sess->sess_private_data[driver_id];
529 }
530 
531 static inline void
532 set_session_private_data(struct rte_cryptodev_sym_session *sess,
533  uint8_t driver_id, void *private_data)
534 {
535  sess->sess_private_data[driver_id] = private_data;
536 }
537 
538 #ifdef __cplusplus
539 }
540 #endif
541 
542 #endif /* _RTE_CRYPTODEV_PMD_H_ */