00ce14e3527baac53135c6ed028ad7999a2e484a
[dpdk.git] / examples / ipsec-secgw / event_helper.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2020 Marvell International Ltd.
3  */
4 #ifndef _EVENT_HELPER_H_
5 #define _EVENT_HELPER_H_
6
7 #include <rte_log.h>
8
9 #define RTE_LOGTYPE_EH  RTE_LOGTYPE_USER4
10
11 #define EH_LOG_ERR(...) \
12         RTE_LOG(ERR, EH, \
13                 RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
14                         __func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__ ,)))
15
16 /* Max event devices supported */
17 #define EVENT_MODE_MAX_EVENT_DEVS RTE_EVENT_MAX_DEVS
18
19 /* Max Rx adapters supported */
20 #define EVENT_MODE_MAX_RX_ADAPTERS RTE_EVENT_MAX_DEVS
21
22 /* Max Rx adapter connections */
23 #define EVENT_MODE_MAX_CONNECTIONS_PER_ADAPTER 16
24
25 /* Max event queues supported per event device */
26 #define EVENT_MODE_MAX_EVENT_QUEUES_PER_DEV RTE_EVENT_MAX_QUEUES_PER_DEV
27
28 /* Max event-lcore links */
29 #define EVENT_MODE_MAX_LCORE_LINKS \
30         (EVENT_MODE_MAX_EVENT_DEVS * EVENT_MODE_MAX_EVENT_QUEUES_PER_DEV)
31
32 /**
33  * Packet transfer mode of the application
34  */
35 enum eh_pkt_transfer_mode {
36         EH_PKT_TRANSFER_MODE_POLL = 0,
37         EH_PKT_TRANSFER_MODE_EVENT,
38 };
39
40 /* Event dev params */
41 struct eventdev_params {
42         uint8_t eventdev_id;
43         uint8_t nb_eventqueue;
44         uint8_t nb_eventport;
45         uint8_t ev_queue_mode;
46 };
47
48 /**
49  * Event-lcore link configuration
50  */
51 struct eh_event_link_info {
52         uint8_t eventdev_id;
53                 /**< Event device ID */
54         uint8_t event_port_id;
55                 /**< Event port ID */
56         uint8_t eventq_id;
57                 /**< Event queue to be linked to the port */
58         uint8_t lcore_id;
59                 /**< Lcore to be polling on this port */
60 };
61
62 /* Rx adapter connection info */
63 struct rx_adapter_connection_info {
64         uint8_t ethdev_id;
65         uint8_t eventq_id;
66         int32_t ethdev_rx_qid;
67 };
68
69 /* Rx adapter conf */
70 struct rx_adapter_conf {
71         int32_t eventdev_id;
72         int32_t adapter_id;
73         uint32_t rx_core_id;
74         uint8_t nb_connections;
75         struct rx_adapter_connection_info
76                         conn[EVENT_MODE_MAX_CONNECTIONS_PER_ADAPTER];
77 };
78
79 /* Eventmode conf data */
80 struct eventmode_conf {
81         int nb_eventdev;
82                 /**< No of event devs */
83         struct eventdev_params eventdev_config[EVENT_MODE_MAX_EVENT_DEVS];
84                 /**< Per event dev conf */
85         uint8_t nb_rx_adapter;
86                 /**< No of Rx adapters */
87         struct rx_adapter_conf rx_adapter[EVENT_MODE_MAX_RX_ADAPTERS];
88                 /**< Rx adapter conf */
89         uint8_t nb_link;
90                 /**< No of links */
91         struct eh_event_link_info
92                 link[EVENT_MODE_MAX_LCORE_LINKS];
93                 /**< Per link conf */
94         struct rte_bitmap *eth_core_mask;
95                 /**< Core mask of cores to be used for software Rx and Tx */
96         uint32_t eth_portmask;
97                 /**< Mask of the eth ports to be used */
98         union {
99                 RTE_STD_C11
100                 struct {
101                         uint64_t sched_type                     : 2;
102                 /**< Schedule type */
103                         uint64_t all_ev_queue_to_ev_port        : 1;
104                 /**<
105                  * When enabled, all event queues need to be mapped to
106                  * each event port
107                  */
108                 };
109                 uint64_t u64;
110         } ext_params;
111                 /**< 64 bit field to specify extended params */
112 };
113
114 /**
115  * Event helper configuration
116  */
117 struct eh_conf {
118         enum eh_pkt_transfer_mode mode;
119                 /**< Packet transfer mode of the application */
120         uint32_t eth_portmask;
121                 /**<
122                  * Mask of the eth ports to be used. This portmask would be
123                  * checked while initializing devices using helper routines.
124                  */
125         void *mode_params;
126                 /**< Mode specific parameters */
127 };
128
129 /**
130  * Initialize event mode devices
131  *
132  * Application can call this function to get the event devices, eth devices
133  * and eth rx & tx adapters initialized according to the default config or
134  * config populated using the command line args.
135  *
136  * Application is expected to initialize the eth devices and then the event
137  * mode helper subsystem will stop & start eth devices according to its
138  * requirement. Call to this function should be done after the eth devices
139  * are successfully initialized.
140  *
141  * @param conf
142  *   Event helper configuration
143  * @return
144  *  - 0 on success.
145  *  - (<0) on failure.
146  */
147 int32_t
148 eh_devs_init(struct eh_conf *conf);
149
150 /**
151  * Release event mode devices
152  *
153  * Application can call this function to release event devices,
154  * eth rx & tx adapters according to the config.
155  *
156  * Call to this function should be done before application stops
157  * and closes eth devices. This function will not close and stop
158  * eth devices.
159  *
160  * @param conf
161  *   Event helper configuration
162  * @return
163  *  - 0 on success.
164  *  - (<0) on failure.
165  */
166 int32_t
167 eh_devs_uninit(struct eh_conf *conf);
168
169 #endif /* _EVENT_HELPER_H_ */