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