xref: /dpdk/examples/ipsec-secgw/event_helper.h (revision 48a39871)
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 #define EH_LOG_INFO(...) \
17 	RTE_LOG(INFO, EH, \
18 		RTE_FMT("%s() line %u: " RTE_FMT_HEAD(__VA_ARGS__ ,) "\n", \
19 			__func__, __LINE__, RTE_FMT_TAIL(__VA_ARGS__ ,)))
20 
21 /* Max event devices supported */
22 #define EVENT_MODE_MAX_EVENT_DEVS RTE_EVENT_MAX_DEVS
23 
24 /* Max Rx adapters supported */
25 #define EVENT_MODE_MAX_RX_ADAPTERS RTE_EVENT_MAX_DEVS
26 
27 /* Max Tx adapters supported */
28 #define EVENT_MODE_MAX_TX_ADAPTERS RTE_EVENT_MAX_DEVS
29 
30 /* Max Rx adapter connections */
31 #define EVENT_MODE_MAX_CONNECTIONS_PER_ADAPTER 16
32 
33 /* Max Tx adapter connections */
34 #define EVENT_MODE_MAX_CONNECTIONS_PER_TX_ADAPTER 16
35 
36 /* Max event queues supported per event device */
37 #define EVENT_MODE_MAX_EVENT_QUEUES_PER_DEV RTE_EVENT_MAX_QUEUES_PER_DEV
38 
39 /* Max event-lcore links */
40 #define EVENT_MODE_MAX_LCORE_LINKS \
41 	(EVENT_MODE_MAX_EVENT_DEVS * EVENT_MODE_MAX_EVENT_QUEUES_PER_DEV)
42 
43 /* Max adapters that one Rx core can handle */
44 #define EVENT_MODE_MAX_ADAPTERS_PER_RX_CORE EVENT_MODE_MAX_RX_ADAPTERS
45 
46 /* Max adapters that one Tx core can handle */
47 #define EVENT_MODE_MAX_ADAPTERS_PER_TX_CORE EVENT_MODE_MAX_TX_ADAPTERS
48 
49 /* Used to indicate that queue schedule type is not set */
50 #define SCHED_TYPE_NOT_SET	3
51 
52 /**
53  * Packet transfer mode of the application
54  */
55 enum eh_pkt_transfer_mode {
56 	EH_PKT_TRANSFER_MODE_POLL = 0,
57 	EH_PKT_TRANSFER_MODE_EVENT,
58 };
59 
60 /**
61  * Event mode packet rx types
62  */
63 enum eh_rx_types {
64 	EH_RX_TYPE_NON_BURST = 0,
65 	EH_RX_TYPE_BURST
66 };
67 
68 /**
69  * Event mode packet tx types
70  */
71 enum eh_tx_types {
72 	EH_TX_TYPE_INTERNAL_PORT = 0,
73 	EH_TX_TYPE_NO_INTERNAL_PORT
74 };
75 
76 /**
77  * Event mode ipsec mode types
78  */
79 enum eh_ipsec_mode_types {
80 	EH_IPSEC_MODE_TYPE_APP = 0,
81 	EH_IPSEC_MODE_TYPE_DRIVER
82 };
83 
84 /* Event dev params */
85 struct eventdev_params {
86 	uint8_t eventdev_id;
87 	uint8_t nb_eventqueue;
88 	uint8_t nb_eventport;
89 	uint8_t ev_queue_mode;
90 	uint8_t all_internal_ports;
91 };
92 
93 /**
94  * Event-lcore link configuration
95  */
96 struct eh_event_link_info {
97 	uint8_t eventdev_id;
98 		/**< Event device ID */
99 	uint8_t event_port_id;
100 		/**< Event port ID */
101 	uint8_t eventq_id;
102 		/**< Event queue to be linked to the port */
103 	uint8_t lcore_id;
104 		/**< Lcore to be polling on this port */
105 };
106 
107 /* Rx adapter connection info */
108 struct rx_adapter_connection_info {
109 	uint8_t ethdev_id;
110 	uint8_t eventq_id;
111 	int32_t ethdev_rx_qid;
112 };
113 
114 /* Rx adapter conf */
115 struct rx_adapter_conf {
116 	int32_t eventdev_id;
117 	int32_t adapter_id;
118 	uint32_t rx_core_id;
119 	uint8_t nb_connections;
120 	struct rx_adapter_connection_info
121 			conn[EVENT_MODE_MAX_CONNECTIONS_PER_ADAPTER];
122 };
123 
124 /* Tx adapter connection info */
125 struct tx_adapter_connection_info {
126 	uint8_t ethdev_id;
127 	int32_t ethdev_tx_qid;
128 };
129 
130 /* Tx adapter conf */
131 struct tx_adapter_conf {
132 	int32_t eventdev_id;
133 	int32_t adapter_id;
134 	uint32_t tx_core_id;
135 	uint8_t nb_connections;
136 	struct tx_adapter_connection_info
137 			conn[EVENT_MODE_MAX_CONNECTIONS_PER_TX_ADAPTER];
138 	uint8_t tx_ev_queue;
139 };
140 
141 /* Eventmode conf data */
142 struct eventmode_conf {
143 	int nb_eventdev;
144 		/**< No of event devs */
145 	struct eventdev_params eventdev_config[EVENT_MODE_MAX_EVENT_DEVS];
146 		/**< Per event dev conf */
147 	uint8_t nb_rx_adapter;
148 		/**< No of Rx adapters */
149 	struct rx_adapter_conf rx_adapter[EVENT_MODE_MAX_RX_ADAPTERS];
150 		/**< Rx adapter conf */
151 	uint8_t nb_tx_adapter;
152 		/**< No of Tx adapters */
153 	struct tx_adapter_conf tx_adapter[EVENT_MODE_MAX_TX_ADAPTERS];
154 		/** Tx adapter conf */
155 	uint8_t nb_link;
156 		/**< No of links */
157 	struct eh_event_link_info
158 		link[EVENT_MODE_MAX_LCORE_LINKS];
159 		/**< Per link conf */
160 	struct rte_bitmap *eth_core_mask;
161 		/**< Core mask of cores to be used for software Rx and Tx */
162 	uint32_t eth_portmask;
163 		/**< Mask of the eth ports to be used */
164 	union {
165 		RTE_STD_C11
166 		struct {
167 			uint64_t sched_type			: 2;
168 		/**< Schedule type */
169 			uint64_t all_ev_queue_to_ev_port	: 1;
170 		/**<
171 		 * When enabled, all event queues need to be mapped to
172 		 * each event port
173 		 */
174 			uint64_t event_vector                   : 1;
175 		/**<
176 		 * Enable event vector, when enabled application can
177 		 * receive vector of events.
178 		 */
179 			uint64_t vector_size                    : 16;
180 		};
181 		uint64_t u64;
182 	} ext_params;
183 		/**< 64 bit field to specify extended params */
184 	uint64_t vector_tmo_ns;
185 		/**< Max vector timeout in nanoseconds */
186 	uint64_t vector_pool_sz;
187 		/**< Vector pool size */
188 };
189 
190 /**
191  * Event helper configuration
192  */
193 struct eh_conf {
194 	enum eh_pkt_transfer_mode mode;
195 		/**< Packet transfer mode of the application */
196 	uint32_t eth_portmask;
197 		/**<
198 		 * Mask of the eth ports to be used. This portmask would be
199 		 * checked while initializing devices using helper routines.
200 		 */
201 	void *mode_params;
202 		/**< Mode specific parameters */
203 
204 		/** Application specific params */
205 	enum eh_ipsec_mode_types ipsec_mode;
206 		/**< Mode of ipsec run */
207 };
208 
209 /* Workers registered by the application */
210 struct eh_app_worker_params {
211 	union {
212 		RTE_STD_C11
213 		struct {
214 			uint64_t burst : 1;
215 			/**< Specify status of rx type burst */
216 			uint64_t tx_internal_port : 1;
217 			/**< Specify whether tx internal port is available */
218 			uint64_t ipsec_mode : 1;
219 			/**< Specify ipsec processing level */
220 		};
221 		uint64_t u64;
222 	} cap;
223 			/**< Capabilities of this worker */
224 	void (*worker_thread)(struct eh_event_link_info *links,
225 			uint8_t nb_links);
226 			/**< Worker thread */
227 };
228 
229 /**
230  * Allocate memory for event helper configuration and initialize
231  * it with default values.
232  *
233  * @return
234  * - pointer to event helper configuration structure on success.
235  * - NULL on failure.
236  */
237 struct eh_conf *
238 eh_conf_init(void);
239 
240 /**
241  * Uninitialize event helper configuration and release its memory
242 . *
243  * @param conf
244  *   Event helper configuration
245  */
246 void
247 eh_conf_uninit(struct eh_conf *conf);
248 
249 /**
250  * Initialize event mode devices
251  *
252  * Application can call this function to get the event devices, eth devices
253  * and eth rx & tx adapters initialized according to the default config or
254  * config populated using the command line args.
255  *
256  * Application is expected to initialize the eth devices and then the event
257  * mode helper subsystem will stop & start eth devices according to its
258  * requirement. Call to this function should be done after the eth devices
259  * are successfully initialized.
260  *
261  * @param conf
262  *   Event helper configuration
263  * @return
264  *  - 0 on success.
265  *  - (<0) on failure.
266  */
267 int32_t
268 eh_devs_init(struct eh_conf *conf);
269 
270 /**
271  * Release event mode devices
272  *
273  * Application can call this function to release event devices,
274  * eth rx & tx adapters according to the config.
275  *
276  * Call to this function should be done before application stops
277  * and closes eth devices. This function will not close and stop
278  * eth devices.
279  *
280  * @param conf
281  *   Event helper configuration
282  * @return
283  *  - 0 on success.
284  *  - (<0) on failure.
285  */
286 int32_t
287 eh_devs_uninit(struct eh_conf *conf);
288 
289 /**
290  * Get eventdev tx queue
291  *
292  * If the application uses event device which does not support internal port
293  * then it needs to submit the events to a Tx queue before final transmission.
294  * This Tx queue will be created internally by the eventmode helper subsystem,
295  * and application will need its queue ID when it runs the execution loop.
296  *
297  * @param mode_conf
298  *   Event helper configuration
299  * @param eventdev_id
300  *   Event device ID
301  * @return
302  *   Tx queue ID
303  */
304 uint8_t
305 eh_get_tx_queue(struct eh_conf *conf, uint8_t eventdev_id);
306 
307 /**
308  * Display event mode configuration
309  *
310  * @param conf
311  *   Event helper configuration
312  */
313 void
314 eh_display_conf(struct eh_conf *conf);
315 
316 
317 /**
318  * Launch eventmode worker
319  *
320  * The application can request the eventmode helper subsystem to launch the
321  * worker based on the capabilities of event device and the options selected
322  * while initializing the eventmode.
323  *
324  * @param conf
325  *   Event helper configuration
326  * @param app_wrkr
327  *   List of all the workers registered by application, along with its
328  *   capabilities
329  * @param nb_wrkr_param
330  *   Number of workers passed by the application
331  *
332  */
333 void
334 eh_launch_worker(struct eh_conf *conf, struct eh_app_worker_params *app_wrkr,
335 		uint8_t nb_wrkr_param);
336 
337 #endif /* _EVENT_HELPER_H_ */
338