xref: /dpdk/examples/ipsec-secgw/event_helper.h (revision 4b978938168b219346775ff877ac31649a36cba7)
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 	int tx_queue_id;
92 	int ev_cpt_queue_id;
93 };
94 
95 /**
96  * Event-lcore link configuration
97  */
98 struct eh_event_link_info {
99 	uint8_t eventdev_id;
100 		/**< Event device ID */
101 	uint8_t event_port_id;
102 		/**< Event port ID */
103 	uint8_t eventq_id;
104 		/**< Event queue to be linked to the port */
105 	uint32_t lcore_id;
106 		/**< Lcore to be polling on this port */
107 };
108 
109 /* Rx adapter connection info */
110 struct rx_adapter_connection_info {
111 	uint8_t ethdev_id;
112 	uint8_t eventq_id;
113 	int32_t ethdev_rx_qid;
114 };
115 
116 /* Rx adapter conf */
117 struct rx_adapter_conf {
118 	int32_t eventdev_id;
119 	int32_t adapter_id;
120 	uint32_t rx_core_id;
121 	uint8_t nb_connections;
122 	struct rx_adapter_connection_info
123 			conn[EVENT_MODE_MAX_CONNECTIONS_PER_ADAPTER];
124 };
125 
126 /* Tx adapter connection info */
127 struct tx_adapter_connection_info {
128 	uint8_t ethdev_id;
129 	int32_t ethdev_tx_qid;
130 };
131 
132 /* Tx adapter conf */
133 struct tx_adapter_conf {
134 	int32_t eventdev_id;
135 	int32_t adapter_id;
136 	uint32_t tx_core_id;
137 	uint8_t nb_connections;
138 	struct tx_adapter_connection_info
139 			conn[EVENT_MODE_MAX_CONNECTIONS_PER_TX_ADAPTER];
140 	uint8_t tx_ev_queue;
141 };
142 
143 /* Eventmode conf data */
144 struct eventmode_conf {
145 	int nb_eventdev;
146 		/**< No of event devs */
147 	struct eventdev_params eventdev_config[EVENT_MODE_MAX_EVENT_DEVS];
148 		/**< Per event dev conf */
149 	uint8_t nb_rx_adapter;
150 		/**< No of Rx adapters */
151 	struct rx_adapter_conf rx_adapter[EVENT_MODE_MAX_RX_ADAPTERS];
152 		/**< Rx adapter conf */
153 	uint8_t nb_tx_adapter;
154 		/**< No of Tx adapters */
155 	struct tx_adapter_conf tx_adapter[EVENT_MODE_MAX_TX_ADAPTERS];
156 		/** Tx adapter conf */
157 	uint8_t nb_link;
158 		/**< No of links */
159 	struct eh_event_link_info
160 		link[EVENT_MODE_MAX_LCORE_LINKS];
161 		/**< Per link conf */
162 	struct rte_bitmap *eth_core_mask;
163 		/**< Core mask of cores to be used for software Rx and Tx */
164 	uint32_t eth_portmask;
165 		/**< Mask of the eth ports to be used */
166 	union {
167 		struct {
168 			uint64_t sched_type			: 2;
169 		/**< Schedule type */
170 			uint64_t all_ev_queue_to_ev_port	: 1;
171 		/**<
172 		 * When enabled, all event queues need to be mapped to
173 		 * each event port
174 		 */
175 			uint64_t event_vector                   : 1;
176 		/**<
177 		 * Enable event vector, when enabled application can
178 		 * receive vector of events.
179 		 */
180 			uint64_t vector_size                    : 16;
181 		};
182 		uint64_t u64;
183 	} ext_params;
184 		/**< 64 bit field to specify extended params */
185 	uint64_t vector_tmo_ns;
186 		/**< Max vector timeout in nanoseconds */
187 	uint64_t vector_pool_sz;
188 		/**< Vector pool size */
189 	bool enable_event_crypto_adapter;
190 		/**< Enables event crypto adapter related configuration */
191 };
192 
193 /**
194  * Event helper configuration
195  */
196 struct eh_conf {
197 	enum eh_pkt_transfer_mode mode;
198 		/**< Packet transfer mode of the application */
199 	uint32_t eth_portmask;
200 		/**<
201 		 * Mask of the eth ports to be used. This portmask would be
202 		 * checked while initializing devices using helper routines.
203 		 */
204 	void *mode_params;
205 		/**< Mode specific parameters */
206 
207 		/** Application specific params */
208 	enum eh_ipsec_mode_types ipsec_mode;
209 		/**< Mode of ipsec run */
210 };
211 
212 /* Workers registered by the application */
213 struct eh_app_worker_params {
214 	union {
215 		struct {
216 			uint64_t burst : 1;
217 			/**< Specify status of rx type burst */
218 			uint64_t tx_internal_port : 1;
219 			/**< Specify whether tx internal port is available */
220 			uint64_t ipsec_mode : 1;
221 			/**< Specify ipsec processing level */
222 		};
223 		uint64_t u64;
224 	} cap;
225 			/**< Capabilities of this worker */
226 	void (*worker_thread)(struct eh_event_link_info *links,
227 			uint8_t nb_links);
228 			/**< Worker thread */
229 };
230 
231 /**
232  * Allocate memory for event helper configuration and initialize
233  * it with default values.
234  *
235  * @return
236  * - pointer to event helper configuration structure on success.
237  * - NULL on failure.
238  */
239 struct eh_conf *
240 eh_conf_init(void);
241 
242 /**
243  * Uninitialize event helper configuration and release its memory
244 . *
245  * @param conf
246  *   Event helper configuration
247  */
248 void
249 eh_conf_uninit(struct eh_conf *conf);
250 
251 /**
252  * Initialize event mode devices
253  *
254  * Application can call this function to get the event devices, eth devices
255  * and eth rx & tx adapters initialized according to the default config or
256  * config populated using the command line args.
257  *
258  * Application is expected to initialize the eth devices and then the event
259  * mode helper subsystem will stop & start eth devices according to its
260  * requirement. Call to this function should be done after the eth devices
261  * are successfully initialized.
262  *
263  * @param conf
264  *   Event helper configuration
265  * @return
266  *  - 0 on success.
267  *  - (<0) on failure.
268  */
269 int32_t
270 eh_devs_init(struct eh_conf *conf);
271 
272 /**
273  * Release event mode devices
274  *
275  * Application can call this function to release event devices,
276  * eth rx & tx adapters according to the config.
277  *
278  * Call to this function should be done before application stops
279  * and closes eth devices. This function will not close and stop
280  * eth devices.
281  *
282  * @param conf
283  *   Event helper configuration
284  * @return
285  *  - 0 on success.
286  *  - (<0) on failure.
287  */
288 int32_t
289 eh_devs_uninit(struct eh_conf *conf);
290 
291 /**
292  * Get eventdev tx queue
293  *
294  * If the application uses event device which does not support internal port
295  * then it needs to submit the events to a Tx queue before final transmission.
296  * This Tx queue will be created internally by the eventmode helper subsystem,
297  * and application will need its queue ID when it runs the execution loop.
298  *
299  * @param mode_conf
300  *   Event helper configuration
301  * @param eventdev_id
302  *   Event device ID
303  * @return
304  *   Tx queue ID
305  */
306 uint8_t
307 eh_get_tx_queue(struct eh_conf *conf, uint8_t eventdev_id);
308 
309 /**
310  * Display event mode configuration
311  *
312  * @param conf
313  *   Event helper configuration
314  */
315 void
316 eh_display_conf(struct eh_conf *conf);
317 
318 
319 /**
320  * Launch eventmode worker
321  *
322  * The application can request the eventmode helper subsystem to launch the
323  * worker based on the capabilities of event device and the options selected
324  * while initializing the eventmode.
325  *
326  * @param conf
327  *   Event helper configuration
328  * @param app_wrkr
329  *   List of all the workers registered by application, along with its
330  *   capabilities
331  * @param nb_wrkr_param
332  *   Number of workers passed by the application
333  *
334  */
335 void
336 eh_launch_worker(struct eh_conf *conf, struct eh_app_worker_params *app_wrkr,
337 		uint8_t nb_wrkr_param);
338 
339 #endif /* _EVENT_HELPER_H_ */
340