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