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