examples/ipsec-secgw: add event config display
[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 Tx core can handle */
44 #define EVENT_MODE_MAX_ADAPTERS_PER_TX_CORE EVENT_MODE_MAX_TX_ADAPTERS
45
46 /**
47  * Packet transfer mode of the application
48  */
49 enum eh_pkt_transfer_mode {
50         EH_PKT_TRANSFER_MODE_POLL = 0,
51         EH_PKT_TRANSFER_MODE_EVENT,
52 };
53
54 /* Event dev params */
55 struct eventdev_params {
56         uint8_t eventdev_id;
57         uint8_t nb_eventqueue;
58         uint8_t nb_eventport;
59         uint8_t ev_queue_mode;
60 };
61
62 /**
63  * Event-lcore link configuration
64  */
65 struct eh_event_link_info {
66         uint8_t eventdev_id;
67                 /**< Event device ID */
68         uint8_t event_port_id;
69                 /**< Event port ID */
70         uint8_t eventq_id;
71                 /**< Event queue to be linked to the port */
72         uint8_t lcore_id;
73                 /**< Lcore to be polling on this port */
74 };
75
76 /* Rx adapter connection info */
77 struct rx_adapter_connection_info {
78         uint8_t ethdev_id;
79         uint8_t eventq_id;
80         int32_t ethdev_rx_qid;
81 };
82
83 /* Rx adapter conf */
84 struct rx_adapter_conf {
85         int32_t eventdev_id;
86         int32_t adapter_id;
87         uint32_t rx_core_id;
88         uint8_t nb_connections;
89         struct rx_adapter_connection_info
90                         conn[EVENT_MODE_MAX_CONNECTIONS_PER_ADAPTER];
91 };
92
93 /* Tx adapter connection info */
94 struct tx_adapter_connection_info {
95         uint8_t ethdev_id;
96         int32_t ethdev_tx_qid;
97 };
98
99 /* Tx adapter conf */
100 struct tx_adapter_conf {
101         int32_t eventdev_id;
102         int32_t adapter_id;
103         uint32_t tx_core_id;
104         uint8_t nb_connections;
105         struct tx_adapter_connection_info
106                         conn[EVENT_MODE_MAX_CONNECTIONS_PER_TX_ADAPTER];
107         uint8_t tx_ev_queue;
108 };
109
110 /* Eventmode conf data */
111 struct eventmode_conf {
112         int nb_eventdev;
113                 /**< No of event devs */
114         struct eventdev_params eventdev_config[EVENT_MODE_MAX_EVENT_DEVS];
115                 /**< Per event dev conf */
116         uint8_t nb_rx_adapter;
117                 /**< No of Rx adapters */
118         struct rx_adapter_conf rx_adapter[EVENT_MODE_MAX_RX_ADAPTERS];
119                 /**< Rx adapter conf */
120         uint8_t nb_tx_adapter;
121                 /**< No of Tx adapters */
122         struct tx_adapter_conf tx_adapter[EVENT_MODE_MAX_TX_ADAPTERS];
123                 /** Tx adapter conf */
124         uint8_t nb_link;
125                 /**< No of links */
126         struct eh_event_link_info
127                 link[EVENT_MODE_MAX_LCORE_LINKS];
128                 /**< Per link conf */
129         struct rte_bitmap *eth_core_mask;
130                 /**< Core mask of cores to be used for software Rx and Tx */
131         uint32_t eth_portmask;
132                 /**< Mask of the eth ports to be used */
133         union {
134                 RTE_STD_C11
135                 struct {
136                         uint64_t sched_type                     : 2;
137                 /**< Schedule type */
138                         uint64_t all_ev_queue_to_ev_port        : 1;
139                 /**<
140                  * When enabled, all event queues need to be mapped to
141                  * each event port
142                  */
143                 };
144                 uint64_t u64;
145         } ext_params;
146                 /**< 64 bit field to specify extended params */
147 };
148
149 /**
150  * Event helper configuration
151  */
152 struct eh_conf {
153         enum eh_pkt_transfer_mode mode;
154                 /**< Packet transfer mode of the application */
155         uint32_t eth_portmask;
156                 /**<
157                  * Mask of the eth ports to be used. This portmask would be
158                  * checked while initializing devices using helper routines.
159                  */
160         void *mode_params;
161                 /**< Mode specific parameters */
162 };
163
164 /**
165  * Initialize event mode devices
166  *
167  * Application can call this function to get the event devices, eth devices
168  * and eth rx & tx adapters initialized according to the default config or
169  * config populated using the command line args.
170  *
171  * Application is expected to initialize the eth devices and then the event
172  * mode helper subsystem will stop & start eth devices according to its
173  * requirement. Call to this function should be done after the eth devices
174  * are successfully initialized.
175  *
176  * @param conf
177  *   Event helper configuration
178  * @return
179  *  - 0 on success.
180  *  - (<0) on failure.
181  */
182 int32_t
183 eh_devs_init(struct eh_conf *conf);
184
185 /**
186  * Release event mode devices
187  *
188  * Application can call this function to release event devices,
189  * eth rx & tx adapters according to the config.
190  *
191  * Call to this function should be done before application stops
192  * and closes eth devices. This function will not close and stop
193  * eth devices.
194  *
195  * @param conf
196  *   Event helper configuration
197  * @return
198  *  - 0 on success.
199  *  - (<0) on failure.
200  */
201 int32_t
202 eh_devs_uninit(struct eh_conf *conf);
203
204 /**
205  * Get eventdev tx queue
206  *
207  * If the application uses event device which does not support internal port
208  * then it needs to submit the events to a Tx queue before final transmission.
209  * This Tx queue will be created internally by the eventmode helper subsystem,
210  * and application will need its queue ID when it runs the execution loop.
211  *
212  * @param mode_conf
213  *   Event helper configuration
214  * @param eventdev_id
215  *   Event device ID
216  * @return
217  *   Tx queue ID
218  */
219 uint8_t
220 eh_get_tx_queue(struct eh_conf *conf, uint8_t eventdev_id);
221
222 /**
223  * Display event mode configuration
224  *
225  * @param conf
226  *   Event helper configuration
227  */
228 void
229 eh_display_conf(struct eh_conf *conf);
230
231 #endif /* _EVENT_HELPER_H_ */