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