1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
8 #include <rte_cycles.h>
9 #include <rte_ethdev.h>
10 #include <rte_eventdev.h>
11 #include <rte_event_eth_rx_adapter.h>
12 #include <rte_event_eth_tx_adapter.h>
13 #include <rte_lcore.h>
14 #include <rte_spinlock.h>
16 #include "l2fwd_common.h"
17 #include "l2fwd_event.h"
20 l2fwd_event_device_setup_generic(struct l2fwd_resources *rsrc)
22 struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
23 struct rte_event_dev_config event_d_conf = {
24 .nb_events_limit = 4096,
25 .nb_event_queue_flows = 1024,
26 .nb_event_port_dequeue_depth = 128,
27 .nb_event_port_enqueue_depth = 128
29 struct rte_event_dev_info dev_info;
30 const uint8_t event_d_id = 0; /* Always use first event device only */
31 uint32_t event_queue_cfg = 0;
32 uint16_t ethdev_count = 0;
33 uint16_t num_workers = 0;
37 RTE_ETH_FOREACH_DEV(port_id) {
38 if ((rsrc->enabled_port_mask & (1 << port_id)) == 0)
43 /* Event device configurtion */
44 rte_event_dev_info_get(event_d_id, &dev_info);
46 /* Enable implicit release */
47 if (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE)
48 evt_rsrc->disable_implicit_release = 0;
50 if (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES)
51 event_queue_cfg |= RTE_EVENT_QUEUE_CFG_ALL_TYPES;
53 /* One queue for each ethdev port + one Tx adapter Single link queue. */
54 event_d_conf.nb_event_queues = ethdev_count + 1;
55 if (dev_info.max_event_queues < event_d_conf.nb_event_queues)
56 event_d_conf.nb_event_queues = dev_info.max_event_queues;
58 if (dev_info.max_num_events < event_d_conf.nb_events_limit)
59 event_d_conf.nb_events_limit = dev_info.max_num_events;
61 if (dev_info.max_event_queue_flows < event_d_conf.nb_event_queue_flows)
62 event_d_conf.nb_event_queue_flows =
63 dev_info.max_event_queue_flows;
65 if (dev_info.max_event_port_dequeue_depth <
66 event_d_conf.nb_event_port_dequeue_depth)
67 event_d_conf.nb_event_port_dequeue_depth =
68 dev_info.max_event_port_dequeue_depth;
70 if (dev_info.max_event_port_enqueue_depth <
71 event_d_conf.nb_event_port_enqueue_depth)
72 event_d_conf.nb_event_port_enqueue_depth =
73 dev_info.max_event_port_enqueue_depth;
75 /* Ignore Master core and service cores. */
76 num_workers = rte_lcore_count() - 1 - rte_service_lcore_count();
77 if (dev_info.max_event_ports < num_workers)
78 num_workers = dev_info.max_event_ports;
80 event_d_conf.nb_event_ports = num_workers;
81 evt_rsrc->evp.nb_ports = num_workers;
82 evt_rsrc->evq.nb_queues = event_d_conf.nb_event_queues;
84 evt_rsrc->has_burst = !!(dev_info.event_dev_cap &
85 RTE_EVENT_DEV_CAP_BURST_MODE);
87 ret = rte_event_dev_configure(event_d_id, &event_d_conf);
89 rte_panic("Error in configuring event device\n");
91 evt_rsrc->event_d_id = event_d_id;
92 return event_queue_cfg;
96 l2fwd_event_port_setup_generic(struct l2fwd_resources *rsrc)
98 struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
99 uint8_t event_d_id = evt_rsrc->event_d_id;
100 struct rte_event_port_conf event_p_conf = {
103 .new_event_threshold = 4096
105 struct rte_event_port_conf def_p_conf;
109 evt_rsrc->evp.event_p_id = (uint8_t *)malloc(sizeof(uint8_t) *
110 evt_rsrc->evp.nb_ports);
111 if (!evt_rsrc->evp.event_p_id)
112 rte_panic("No space is available\n");
114 memset(&def_p_conf, 0, sizeof(struct rte_event_port_conf));
115 ret = rte_event_port_default_conf_get(event_d_id, 0, &def_p_conf);
117 rte_panic("Error to get default configuration of event port\n");
119 if (def_p_conf.new_event_threshold < event_p_conf.new_event_threshold)
120 event_p_conf.new_event_threshold =
121 def_p_conf.new_event_threshold;
123 if (def_p_conf.dequeue_depth < event_p_conf.dequeue_depth)
124 event_p_conf.dequeue_depth = def_p_conf.dequeue_depth;
126 if (def_p_conf.enqueue_depth < event_p_conf.enqueue_depth)
127 event_p_conf.enqueue_depth = def_p_conf.enqueue_depth;
129 event_p_conf.disable_implicit_release =
130 evt_rsrc->disable_implicit_release;
131 evt_rsrc->deq_depth = def_p_conf.dequeue_depth;
133 for (event_p_id = 0; event_p_id < evt_rsrc->evp.nb_ports;
135 ret = rte_event_port_setup(event_d_id, event_p_id,
138 rte_panic("Error in configuring event port %d\n",
141 ret = rte_event_port_link(event_d_id, event_p_id,
142 evt_rsrc->evq.event_q_id,
144 evt_rsrc->evq.nb_queues - 1);
145 if (ret != (evt_rsrc->evq.nb_queues - 1))
146 rte_panic("Error in linking event port %d to queues\n",
148 evt_rsrc->evp.event_p_id[event_p_id] = event_p_id;
151 rte_spinlock_init(&evt_rsrc->evp.lock);
153 evt_rsrc->def_p_conf = event_p_conf;
157 l2fwd_event_queue_setup_generic(struct l2fwd_resources *rsrc,
158 uint32_t event_queue_cfg)
160 struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
161 uint8_t event_d_id = evt_rsrc->event_d_id;
162 struct rte_event_queue_conf event_q_conf = {
163 .nb_atomic_flows = 1024,
164 .nb_atomic_order_sequences = 1024,
165 .event_queue_cfg = event_queue_cfg,
166 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL
168 struct rte_event_queue_conf def_q_conf;
172 event_q_conf.schedule_type = rsrc->sched_type;
173 evt_rsrc->evq.event_q_id = (uint8_t *)malloc(sizeof(uint8_t) *
174 evt_rsrc->evq.nb_queues);
175 if (!evt_rsrc->evq.event_q_id)
176 rte_panic("Memory allocation failure\n");
178 ret = rte_event_queue_default_conf_get(event_d_id, 0, &def_q_conf);
180 rte_panic("Error to get default config of event queue\n");
182 if (def_q_conf.nb_atomic_flows < event_q_conf.nb_atomic_flows)
183 event_q_conf.nb_atomic_flows = def_q_conf.nb_atomic_flows;
185 for (event_q_id = 0; event_q_id < (evt_rsrc->evq.nb_queues - 1);
187 ret = rte_event_queue_setup(event_d_id, event_q_id,
190 rte_panic("Error in configuring event queue\n");
191 evt_rsrc->evq.event_q_id[event_q_id] = event_q_id;
194 event_q_conf.event_queue_cfg |= RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
195 event_q_conf.priority = RTE_EVENT_DEV_PRIORITY_HIGHEST,
196 ret = rte_event_queue_setup(event_d_id, event_q_id, &event_q_conf);
198 rte_panic("Error in configuring event queue for Tx adapter\n");
199 evt_rsrc->evq.event_q_id[event_q_id] = event_q_id;
203 l2fwd_rx_tx_adapter_setup_generic(struct l2fwd_resources *rsrc)
205 struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
206 struct rte_event_eth_rx_adapter_queue_conf eth_q_conf;
207 uint8_t event_d_id = evt_rsrc->event_d_id;
208 uint8_t rx_adptr_id = 0;
209 uint8_t tx_adptr_id = 0;
210 uint8_t tx_port_id = 0;
215 memset(ð_q_conf, 0, sizeof(eth_q_conf));
216 eth_q_conf.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
218 /* Rx adapter setup */
219 evt_rsrc->rx_adptr.nb_rx_adptr = 1;
220 evt_rsrc->rx_adptr.rx_adptr = (uint8_t *)malloc(sizeof(uint8_t) *
221 evt_rsrc->rx_adptr.nb_rx_adptr);
222 if (!evt_rsrc->rx_adptr.rx_adptr) {
223 free(evt_rsrc->evp.event_p_id);
224 free(evt_rsrc->evq.event_q_id);
225 rte_panic("Failed to allocate memery for Rx adapter\n");
228 ret = rte_event_eth_rx_adapter_create(rx_adptr_id, event_d_id,
229 &evt_rsrc->def_p_conf);
231 rte_panic("Failed to create rx adapter\n");
233 /* Configure user requested sched type */
234 eth_q_conf.ev.sched_type = rsrc->sched_type;
235 RTE_ETH_FOREACH_DEV(port_id) {
236 if ((rsrc->enabled_port_mask & (1 << port_id)) == 0)
238 eth_q_conf.ev.queue_id = evt_rsrc->evq.event_q_id[i];
239 ret = rte_event_eth_rx_adapter_queue_add(rx_adptr_id, port_id,
242 rte_panic("Failed to add queues to Rx adapter\n");
243 if (i < evt_rsrc->evq.nb_queues)
247 ret = rte_event_eth_rx_adapter_service_id_get(rx_adptr_id, &service_id);
248 if (ret != -ESRCH && ret != 0)
249 rte_panic("Error getting the service ID for rx adptr\n");
251 rte_service_runstate_set(service_id, 1);
252 rte_service_set_runstate_mapped_check(service_id, 0);
253 evt_rsrc->rx_adptr.service_id = service_id;
255 ret = rte_event_eth_rx_adapter_start(rx_adptr_id);
257 rte_panic("Rx adapter[%d] start Failed\n", rx_adptr_id);
259 evt_rsrc->rx_adptr.rx_adptr[0] = rx_adptr_id;
261 /* Tx adapter setup */
262 evt_rsrc->tx_adptr.nb_tx_adptr = 1;
263 evt_rsrc->tx_adptr.tx_adptr = (uint8_t *)malloc(sizeof(uint8_t) *
264 evt_rsrc->tx_adptr.nb_tx_adptr);
265 if (!evt_rsrc->tx_adptr.tx_adptr) {
266 free(evt_rsrc->rx_adptr.rx_adptr);
267 free(evt_rsrc->evp.event_p_id);
268 free(evt_rsrc->evq.event_q_id);
269 rte_panic("Failed to allocate memery for Rx adapter\n");
272 ret = rte_event_eth_tx_adapter_create(tx_adptr_id, event_d_id,
273 &evt_rsrc->def_p_conf);
275 rte_panic("Failed to create tx adapter\n");
277 RTE_ETH_FOREACH_DEV(port_id) {
278 if ((rsrc->enabled_port_mask & (1 << port_id)) == 0)
280 ret = rte_event_eth_tx_adapter_queue_add(tx_adptr_id, port_id,
283 rte_panic("Failed to add queues to Tx adapter\n");
286 ret = rte_event_eth_tx_adapter_service_id_get(tx_adptr_id, &service_id);
287 if (ret != -ESRCH && ret != 0)
288 rte_panic("Failed to get Tx adapter service ID\n");
290 rte_service_runstate_set(service_id, 1);
291 rte_service_set_runstate_mapped_check(service_id, 0);
292 evt_rsrc->tx_adptr.service_id = service_id;
294 ret = rte_event_eth_tx_adapter_event_port_get(tx_adptr_id, &tx_port_id);
296 rte_panic("Failed to get Tx adapter port id: %d\n", ret);
298 ret = rte_event_port_link(event_d_id, tx_port_id,
299 &evt_rsrc->evq.event_q_id[
300 evt_rsrc->evq.nb_queues - 1],
303 rte_panic("Unable to link Tx adapter port to Tx queue:err=%d\n",
306 ret = rte_event_eth_tx_adapter_start(tx_adptr_id);
308 rte_panic("Tx adapter[%d] start Failed\n", tx_adptr_id);
310 evt_rsrc->tx_adptr.tx_adptr[0] = tx_adptr_id;
314 l2fwd_event_set_generic_ops(struct event_setup_ops *ops)
316 ops->event_device_setup = l2fwd_event_device_setup_generic;
317 ops->event_queue_setup = l2fwd_event_queue_setup_generic;
318 ops->event_port_setup = l2fwd_event_port_setup_generic;
319 ops->adapter_setup = l2fwd_rx_tx_adapter_setup_generic;