xref: /dpdk/examples/l2fwd-event/l2fwd_event_generic.c (revision 6cf329f9d8c2eb97c8f39becd514c14b25251ac1)
169de9488SSunil Kumar Kori /* SPDX-License-Identifier: BSD-3-Clause
269de9488SSunil Kumar Kori  * Copyright(C) 2019 Marvell International Ltd.
369de9488SSunil Kumar Kori  */
469de9488SSunil Kumar Kori 
569de9488SSunil Kumar Kori #include <stdbool.h>
669de9488SSunil Kumar Kori #include <getopt.h>
769de9488SSunil Kumar Kori 
869de9488SSunil Kumar Kori #include <rte_cycles.h>
969de9488SSunil Kumar Kori #include <rte_ethdev.h>
1069de9488SSunil Kumar Kori #include <rte_eventdev.h>
1169de9488SSunil Kumar Kori #include <rte_event_eth_rx_adapter.h>
1269de9488SSunil Kumar Kori #include <rte_event_eth_tx_adapter.h>
1369de9488SSunil Kumar Kori #include <rte_lcore.h>
1469de9488SSunil Kumar Kori #include <rte_spinlock.h>
1569de9488SSunil Kumar Kori 
1669de9488SSunil Kumar Kori #include "l2fwd_common.h"
1769de9488SSunil Kumar Kori #include "l2fwd_event.h"
1869de9488SSunil Kumar Kori 
196ab87600SSunil Kumar Kori static uint32_t
206ab87600SSunil Kumar Kori l2fwd_event_device_setup_generic(struct l2fwd_resources *rsrc)
216ab87600SSunil Kumar Kori {
226ab87600SSunil Kumar Kori 	struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
239a212dc0SConor Fogarty 	/* Configures event device as per below configuration. 8< */
246ab87600SSunil Kumar Kori 	struct rte_event_dev_config event_d_conf = {
256ab87600SSunil Kumar Kori 		.nb_events_limit  = 4096,
266ab87600SSunil Kumar Kori 		.nb_event_queue_flows = 1024,
276ab87600SSunil Kumar Kori 		.nb_event_port_dequeue_depth = 128,
286ab87600SSunil Kumar Kori 		.nb_event_port_enqueue_depth = 128
296ab87600SSunil Kumar Kori 	};
309a212dc0SConor Fogarty 	/* >8 End of configuration event device as per below configuration. */
316ab87600SSunil Kumar Kori 	struct rte_event_dev_info dev_info;
326ab87600SSunil Kumar Kori 	const uint8_t event_d_id = 0; /* Always use first event device only */
336ab87600SSunil Kumar Kori 	uint32_t event_queue_cfg = 0;
346ab87600SSunil Kumar Kori 	uint16_t ethdev_count = 0;
356ab87600SSunil Kumar Kori 	uint16_t num_workers = 0;
366ab87600SSunil Kumar Kori 	uint16_t port_id;
376ab87600SSunil Kumar Kori 	int ret;
386ab87600SSunil Kumar Kori 
396ab87600SSunil Kumar Kori 	RTE_ETH_FOREACH_DEV(port_id) {
406ab87600SSunil Kumar Kori 		if ((rsrc->enabled_port_mask & (1 << port_id)) == 0)
416ab87600SSunil Kumar Kori 			continue;
426ab87600SSunil Kumar Kori 		ethdev_count++;
436ab87600SSunil Kumar Kori 	}
446ab87600SSunil Kumar Kori 
457be78d02SJosh Soref 	/* Event device configuration */
466ab87600SSunil Kumar Kori 	rte_event_dev_info_get(event_d_id, &dev_info);
47345a22d5SPavan Nikhilesh 
48345a22d5SPavan Nikhilesh 	/* Enable implicit release */
49345a22d5SPavan Nikhilesh 	if (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_IMPLICIT_RELEASE_DISABLE)
50345a22d5SPavan Nikhilesh 		evt_rsrc->disable_implicit_release = 0;
516ab87600SSunil Kumar Kori 
526ab87600SSunil Kumar Kori 	if (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES)
536ab87600SSunil Kumar Kori 		event_queue_cfg |= RTE_EVENT_QUEUE_CFG_ALL_TYPES;
546ab87600SSunil Kumar Kori 
556ab87600SSunil Kumar Kori 	/* One queue for each ethdev port + one Tx adapter Single link queue. */
566ab87600SSunil Kumar Kori 	event_d_conf.nb_event_queues = ethdev_count + 1;
576ab87600SSunil Kumar Kori 	if (dev_info.max_event_queues < event_d_conf.nb_event_queues)
586ab87600SSunil Kumar Kori 		event_d_conf.nb_event_queues = dev_info.max_event_queues;
596ab87600SSunil Kumar Kori 
606ab87600SSunil Kumar Kori 	if (dev_info.max_num_events < event_d_conf.nb_events_limit)
616ab87600SSunil Kumar Kori 		event_d_conf.nb_events_limit = dev_info.max_num_events;
626ab87600SSunil Kumar Kori 
636ab87600SSunil Kumar Kori 	if (dev_info.max_event_queue_flows < event_d_conf.nb_event_queue_flows)
646ab87600SSunil Kumar Kori 		event_d_conf.nb_event_queue_flows =
656ab87600SSunil Kumar Kori 						dev_info.max_event_queue_flows;
666ab87600SSunil Kumar Kori 
676ab87600SSunil Kumar Kori 	if (dev_info.max_event_port_dequeue_depth <
686ab87600SSunil Kumar Kori 				event_d_conf.nb_event_port_dequeue_depth)
696ab87600SSunil Kumar Kori 		event_d_conf.nb_event_port_dequeue_depth =
706ab87600SSunil Kumar Kori 				dev_info.max_event_port_dequeue_depth;
716ab87600SSunil Kumar Kori 
726ab87600SSunil Kumar Kori 	if (dev_info.max_event_port_enqueue_depth <
736ab87600SSunil Kumar Kori 				event_d_conf.nb_event_port_enqueue_depth)
746ab87600SSunil Kumar Kori 		event_d_conf.nb_event_port_enqueue_depth =
756ab87600SSunil Kumar Kori 				dev_info.max_event_port_enqueue_depth;
766ab87600SSunil Kumar Kori 
77cb056611SStephen Hemminger 	/* Ignore Main core and service cores. */
78345a22d5SPavan Nikhilesh 	num_workers = rte_lcore_count() - 1 - rte_service_lcore_count();
796ab87600SSunil Kumar Kori 	if (dev_info.max_event_ports < num_workers)
806ab87600SSunil Kumar Kori 		num_workers = dev_info.max_event_ports;
816ab87600SSunil Kumar Kori 
826ab87600SSunil Kumar Kori 	event_d_conf.nb_event_ports = num_workers;
836ab87600SSunil Kumar Kori 	evt_rsrc->evp.nb_ports = num_workers;
846ab87600SSunil Kumar Kori 	evt_rsrc->evq.nb_queues = event_d_conf.nb_event_queues;
856ab87600SSunil Kumar Kori 
866ab87600SSunil Kumar Kori 	evt_rsrc->has_burst = !!(dev_info.event_dev_cap &
876ab87600SSunil Kumar Kori 				    RTE_EVENT_DEV_CAP_BURST_MODE);
886ab87600SSunil Kumar Kori 
89*6cf329f9SPavan Nikhilesh 	if (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_EVENT_PRESCHEDULE)
90*6cf329f9SPavan Nikhilesh 		event_d_conf.preschedule_type = RTE_EVENT_PRESCHEDULE;
91*6cf329f9SPavan Nikhilesh 
92*6cf329f9SPavan Nikhilesh 	if (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_EVENT_PRESCHEDULE_ADAPTIVE)
93*6cf329f9SPavan Nikhilesh 		event_d_conf.preschedule_type = RTE_EVENT_PRESCHEDULE_ADAPTIVE;
94*6cf329f9SPavan Nikhilesh 
956ab87600SSunil Kumar Kori 	ret = rte_event_dev_configure(event_d_id, &event_d_conf);
966ab87600SSunil Kumar Kori 	if (ret < 0)
976ab87600SSunil Kumar Kori 		rte_panic("Error in configuring event device\n");
986ab87600SSunil Kumar Kori 
996ab87600SSunil Kumar Kori 	evt_rsrc->event_d_id = event_d_id;
1006ab87600SSunil Kumar Kori 	return event_queue_cfg;
1016ab87600SSunil Kumar Kori }
1026ab87600SSunil Kumar Kori 
1033b5476dbSSunil Kumar Kori static void
1043b5476dbSSunil Kumar Kori l2fwd_event_port_setup_generic(struct l2fwd_resources *rsrc)
1053b5476dbSSunil Kumar Kori {
1063b5476dbSSunil Kumar Kori 	struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
1073b5476dbSSunil Kumar Kori 	uint8_t event_d_id = evt_rsrc->event_d_id;
1089a212dc0SConor Fogarty 	/* Event port initialization. 8< */
1093b5476dbSSunil Kumar Kori 	struct rte_event_port_conf event_p_conf = {
1103b5476dbSSunil Kumar Kori 		.dequeue_depth = 32,
1113b5476dbSSunil Kumar Kori 		.enqueue_depth = 32,
1123b5476dbSSunil Kumar Kori 		.new_event_threshold = 4096
1133b5476dbSSunil Kumar Kori 	};
1143b5476dbSSunil Kumar Kori 	struct rte_event_port_conf def_p_conf;
1153b5476dbSSunil Kumar Kori 	uint8_t event_p_id;
1163b5476dbSSunil Kumar Kori 	int32_t ret;
1173b5476dbSSunil Kumar Kori 
1183b5476dbSSunil Kumar Kori 	evt_rsrc->evp.event_p_id = (uint8_t *)malloc(sizeof(uint8_t) *
1193b5476dbSSunil Kumar Kori 					evt_rsrc->evp.nb_ports);
1203b5476dbSSunil Kumar Kori 	if (!evt_rsrc->evp.event_p_id)
1213b5476dbSSunil Kumar Kori 		rte_panic("No space is available\n");
1223b5476dbSSunil Kumar Kori 
1233b5476dbSSunil Kumar Kori 	memset(&def_p_conf, 0, sizeof(struct rte_event_port_conf));
1248cecdc7eSSunil Kumar Kori 	ret = rte_event_port_default_conf_get(event_d_id, 0, &def_p_conf);
1258cecdc7eSSunil Kumar Kori 	if (ret < 0)
1268cecdc7eSSunil Kumar Kori 		rte_panic("Error to get default configuration of event port\n");
1273b5476dbSSunil Kumar Kori 
1283b5476dbSSunil Kumar Kori 	if (def_p_conf.new_event_threshold < event_p_conf.new_event_threshold)
1293b5476dbSSunil Kumar Kori 		event_p_conf.new_event_threshold =
1303b5476dbSSunil Kumar Kori 			def_p_conf.new_event_threshold;
1313b5476dbSSunil Kumar Kori 
1323b5476dbSSunil Kumar Kori 	if (def_p_conf.dequeue_depth < event_p_conf.dequeue_depth)
1333b5476dbSSunil Kumar Kori 		event_p_conf.dequeue_depth = def_p_conf.dequeue_depth;
1343b5476dbSSunil Kumar Kori 
1353b5476dbSSunil Kumar Kori 	if (def_p_conf.enqueue_depth < event_p_conf.enqueue_depth)
1363b5476dbSSunil Kumar Kori 		event_p_conf.enqueue_depth = def_p_conf.enqueue_depth;
1373b5476dbSSunil Kumar Kori 
13875d11313STimothy McDaniel 	event_p_conf.event_port_cfg = 0;
13975d11313STimothy McDaniel 	if (evt_rsrc->disable_implicit_release)
14075d11313STimothy McDaniel 		event_p_conf.event_port_cfg |=
14175d11313STimothy McDaniel 			RTE_EVENT_PORT_CFG_DISABLE_IMPL_REL;
14275d11313STimothy McDaniel 
1433b5476dbSSunil Kumar Kori 	evt_rsrc->deq_depth = def_p_conf.dequeue_depth;
1443b5476dbSSunil Kumar Kori 
1453b5476dbSSunil Kumar Kori 	for (event_p_id = 0; event_p_id < evt_rsrc->evp.nb_ports;
1463b5476dbSSunil Kumar Kori 								event_p_id++) {
1473b5476dbSSunil Kumar Kori 		ret = rte_event_port_setup(event_d_id, event_p_id,
1483b5476dbSSunil Kumar Kori 					   &event_p_conf);
1493b5476dbSSunil Kumar Kori 		if (ret < 0)
1503b5476dbSSunil Kumar Kori 			rte_panic("Error in configuring event port %d\n",
1513b5476dbSSunil Kumar Kori 				  event_p_id);
1523b5476dbSSunil Kumar Kori 
1533b5476dbSSunil Kumar Kori 		ret = rte_event_port_link(event_d_id, event_p_id,
1543b5476dbSSunil Kumar Kori 					  evt_rsrc->evq.event_q_id,
1553b5476dbSSunil Kumar Kori 					  NULL,
1563b5476dbSSunil Kumar Kori 					  evt_rsrc->evq.nb_queues - 1);
1573b5476dbSSunil Kumar Kori 		if (ret != (evt_rsrc->evq.nb_queues - 1))
1583b5476dbSSunil Kumar Kori 			rte_panic("Error in linking event port %d to queues\n",
1593b5476dbSSunil Kumar Kori 				  event_p_id);
1603b5476dbSSunil Kumar Kori 		evt_rsrc->evp.event_p_id[event_p_id] = event_p_id;
1619a212dc0SConor Fogarty 		/* >8 End of event port initialization. */
1623b5476dbSSunil Kumar Kori 	}
1633b5476dbSSunil Kumar Kori 	/* init spinlock */
1643b5476dbSSunil Kumar Kori 	rte_spinlock_init(&evt_rsrc->evp.lock);
1653b5476dbSSunil Kumar Kori 
1663b5476dbSSunil Kumar Kori 	evt_rsrc->def_p_conf = event_p_conf;
1673b5476dbSSunil Kumar Kori }
1683b5476dbSSunil Kumar Kori 
1693b5476dbSSunil Kumar Kori static void
1703b5476dbSSunil Kumar Kori l2fwd_event_queue_setup_generic(struct l2fwd_resources *rsrc,
1713b5476dbSSunil Kumar Kori 			  uint32_t event_queue_cfg)
1723b5476dbSSunil Kumar Kori {
1733b5476dbSSunil Kumar Kori 	struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
1743b5476dbSSunil Kumar Kori 	uint8_t event_d_id = evt_rsrc->event_d_id;
1759a212dc0SConor Fogarty 	/* Event queue initialization. 8< */
1763b5476dbSSunil Kumar Kori 	struct rte_event_queue_conf event_q_conf = {
1773b5476dbSSunil Kumar Kori 		.nb_atomic_flows = 1024,
1783b5476dbSSunil Kumar Kori 		.nb_atomic_order_sequences = 1024,
1793b5476dbSSunil Kumar Kori 		.event_queue_cfg = event_queue_cfg,
1803b5476dbSSunil Kumar Kori 		.priority = RTE_EVENT_DEV_PRIORITY_NORMAL
1813b5476dbSSunil Kumar Kori 	};
1823b5476dbSSunil Kumar Kori 	struct rte_event_queue_conf def_q_conf;
1833b5476dbSSunil Kumar Kori 	uint8_t event_q_id;
1843b5476dbSSunil Kumar Kori 	int32_t ret;
1853b5476dbSSunil Kumar Kori 
1863b5476dbSSunil Kumar Kori 	event_q_conf.schedule_type = rsrc->sched_type;
1873b5476dbSSunil Kumar Kori 	evt_rsrc->evq.event_q_id = (uint8_t *)malloc(sizeof(uint8_t) *
1883b5476dbSSunil Kumar Kori 					evt_rsrc->evq.nb_queues);
1893b5476dbSSunil Kumar Kori 	if (!evt_rsrc->evq.event_q_id)
1903b5476dbSSunil Kumar Kori 		rte_panic("Memory allocation failure\n");
1913b5476dbSSunil Kumar Kori 
1928cecdc7eSSunil Kumar Kori 	ret = rte_event_queue_default_conf_get(event_d_id, 0, &def_q_conf);
1938cecdc7eSSunil Kumar Kori 	if (ret < 0)
1948cecdc7eSSunil Kumar Kori 		rte_panic("Error to get default config of event queue\n");
1959a212dc0SConor Fogarty 	/* >8 End of event queue initialization. */
1968cecdc7eSSunil Kumar Kori 
1973b5476dbSSunil Kumar Kori 	if (def_q_conf.nb_atomic_flows < event_q_conf.nb_atomic_flows)
1983b5476dbSSunil Kumar Kori 		event_q_conf.nb_atomic_flows = def_q_conf.nb_atomic_flows;
1993b5476dbSSunil Kumar Kori 
2003b5476dbSSunil Kumar Kori 	for (event_q_id = 0; event_q_id < (evt_rsrc->evq.nb_queues - 1);
2013b5476dbSSunil Kumar Kori 								event_q_id++) {
2023b5476dbSSunil Kumar Kori 		ret = rte_event_queue_setup(event_d_id, event_q_id,
2033b5476dbSSunil Kumar Kori 					    &event_q_conf);
2043b5476dbSSunil Kumar Kori 		if (ret < 0)
2053b5476dbSSunil Kumar Kori 			rte_panic("Error in configuring event queue\n");
2063b5476dbSSunil Kumar Kori 		evt_rsrc->evq.event_q_id[event_q_id] = event_q_id;
2073b5476dbSSunil Kumar Kori 	}
2083b5476dbSSunil Kumar Kori 
2093b5476dbSSunil Kumar Kori 	event_q_conf.event_queue_cfg |= RTE_EVENT_QUEUE_CFG_SINGLE_LINK;
2103b5476dbSSunil Kumar Kori 	event_q_conf.priority = RTE_EVENT_DEV_PRIORITY_HIGHEST,
2113b5476dbSSunil Kumar Kori 	ret = rte_event_queue_setup(event_d_id, event_q_id, &event_q_conf);
2123b5476dbSSunil Kumar Kori 	if (ret < 0)
2133b5476dbSSunil Kumar Kori 		rte_panic("Error in configuring event queue for Tx adapter\n");
2143b5476dbSSunil Kumar Kori 	evt_rsrc->evq.event_q_id[event_q_id] = event_q_id;
2153b5476dbSSunil Kumar Kori }
2163b5476dbSSunil Kumar Kori 
21750f05aa6SSunil Kumar Kori static void
21850f05aa6SSunil Kumar Kori l2fwd_rx_tx_adapter_setup_generic(struct l2fwd_resources *rsrc)
21950f05aa6SSunil Kumar Kori {
22050f05aa6SSunil Kumar Kori 	struct l2fwd_event_resources *evt_rsrc = rsrc->evt_rsrc;
221ab1488a3SDavid Marchand 	struct rte_event_eth_rx_adapter_queue_conf eth_q_conf;
22250f05aa6SSunil Kumar Kori 	uint8_t event_d_id = evt_rsrc->event_d_id;
22350f05aa6SSunil Kumar Kori 	uint8_t rx_adptr_id = 0;
22450f05aa6SSunil Kumar Kori 	uint8_t tx_adptr_id = 0;
22550f05aa6SSunil Kumar Kori 	uint8_t tx_port_id = 0;
22650f05aa6SSunil Kumar Kori 	uint16_t port_id;
22750f05aa6SSunil Kumar Kori 	uint32_t service_id;
22850f05aa6SSunil Kumar Kori 	int32_t ret, i = 0;
22950f05aa6SSunil Kumar Kori 
230ab1488a3SDavid Marchand 	memset(&eth_q_conf, 0, sizeof(eth_q_conf));
231ab1488a3SDavid Marchand 	eth_q_conf.ev.priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
232ab1488a3SDavid Marchand 
23350f05aa6SSunil Kumar Kori 	/* Rx adapter setup */
23450f05aa6SSunil Kumar Kori 	evt_rsrc->rx_adptr.nb_rx_adptr = 1;
23550f05aa6SSunil Kumar Kori 	evt_rsrc->rx_adptr.rx_adptr = (uint8_t *)malloc(sizeof(uint8_t) *
23650f05aa6SSunil Kumar Kori 					evt_rsrc->rx_adptr.nb_rx_adptr);
23750f05aa6SSunil Kumar Kori 	if (!evt_rsrc->rx_adptr.rx_adptr) {
23850f05aa6SSunil Kumar Kori 		free(evt_rsrc->evp.event_p_id);
23950f05aa6SSunil Kumar Kori 		free(evt_rsrc->evq.event_q_id);
24050f05aa6SSunil Kumar Kori 		rte_panic("Failed to allocate memery for Rx adapter\n");
24150f05aa6SSunil Kumar Kori 	}
24250f05aa6SSunil Kumar Kori 
24350f05aa6SSunil Kumar Kori 	ret = rte_event_eth_rx_adapter_create(rx_adptr_id, event_d_id,
24450f05aa6SSunil Kumar Kori 					      &evt_rsrc->def_p_conf);
24550f05aa6SSunil Kumar Kori 	if (ret)
24650f05aa6SSunil Kumar Kori 		rte_panic("Failed to create rx adapter\n");
24750f05aa6SSunil Kumar Kori 
24850f05aa6SSunil Kumar Kori 	/* Configure user requested sched type */
24950f05aa6SSunil Kumar Kori 	eth_q_conf.ev.sched_type = rsrc->sched_type;
25050f05aa6SSunil Kumar Kori 	RTE_ETH_FOREACH_DEV(port_id) {
25150f05aa6SSunil Kumar Kori 		if ((rsrc->enabled_port_mask & (1 << port_id)) == 0)
25250f05aa6SSunil Kumar Kori 			continue;
25350f05aa6SSunil Kumar Kori 		eth_q_conf.ev.queue_id = evt_rsrc->evq.event_q_id[i];
254796b07e9SShijith Thotton 		if (rsrc->evt_vec.enabled) {
255796b07e9SShijith Thotton 			uint32_t cap;
256796b07e9SShijith Thotton 
257796b07e9SShijith Thotton 			if (rte_event_eth_rx_adapter_caps_get(event_d_id,
258796b07e9SShijith Thotton 							      port_id, &cap))
259796b07e9SShijith Thotton 				rte_panic(
260796b07e9SShijith Thotton 					"Failed to get event rx adapter capability");
261796b07e9SShijith Thotton 
262796b07e9SShijith Thotton 			if (cap & RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR) {
263796b07e9SShijith Thotton 				eth_q_conf.vector_sz = rsrc->evt_vec.size;
264796b07e9SShijith Thotton 				eth_q_conf.vector_timeout_ns =
265796b07e9SShijith Thotton 					rsrc->evt_vec.timeout_ns;
266796b07e9SShijith Thotton 				eth_q_conf.vector_mp = rsrc->evt_vec_pool;
267796b07e9SShijith Thotton 				eth_q_conf.rx_queue_flags |=
268796b07e9SShijith Thotton 				RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR;
269796b07e9SShijith Thotton 			} else {
270796b07e9SShijith Thotton 				rte_panic(
271796b07e9SShijith Thotton 					"Rx adapter doesn't support event vector");
272796b07e9SShijith Thotton 			}
273796b07e9SShijith Thotton 		}
274796b07e9SShijith Thotton 
27550f05aa6SSunil Kumar Kori 		ret = rte_event_eth_rx_adapter_queue_add(rx_adptr_id, port_id,
27650f05aa6SSunil Kumar Kori 							 -1, &eth_q_conf);
27750f05aa6SSunil Kumar Kori 		if (ret)
27850f05aa6SSunil Kumar Kori 			rte_panic("Failed to add queues to Rx adapter\n");
27950f05aa6SSunil Kumar Kori 		if (i < evt_rsrc->evq.nb_queues)
28050f05aa6SSunil Kumar Kori 			i++;
28150f05aa6SSunil Kumar Kori 	}
28250f05aa6SSunil Kumar Kori 
28350f05aa6SSunil Kumar Kori 	ret = rte_event_eth_rx_adapter_service_id_get(rx_adptr_id, &service_id);
28450f05aa6SSunil Kumar Kori 	if (ret != -ESRCH && ret != 0)
28550f05aa6SSunil Kumar Kori 		rte_panic("Error getting the service ID for rx adptr\n");
28650f05aa6SSunil Kumar Kori 
28750f05aa6SSunil Kumar Kori 	rte_service_runstate_set(service_id, 1);
28850f05aa6SSunil Kumar Kori 	rte_service_set_runstate_mapped_check(service_id, 0);
28950f05aa6SSunil Kumar Kori 	evt_rsrc->rx_adptr.service_id = service_id;
29050f05aa6SSunil Kumar Kori 
29150f05aa6SSunil Kumar Kori 	ret = rte_event_eth_rx_adapter_start(rx_adptr_id);
29250f05aa6SSunil Kumar Kori 	if (ret)
29350f05aa6SSunil Kumar Kori 		rte_panic("Rx adapter[%d] start Failed\n", rx_adptr_id);
29450f05aa6SSunil Kumar Kori 
29550f05aa6SSunil Kumar Kori 	evt_rsrc->rx_adptr.rx_adptr[0] = rx_adptr_id;
29650f05aa6SSunil Kumar Kori 
29750f05aa6SSunil Kumar Kori 	/* Tx adapter setup */
29850f05aa6SSunil Kumar Kori 	evt_rsrc->tx_adptr.nb_tx_adptr = 1;
29950f05aa6SSunil Kumar Kori 	evt_rsrc->tx_adptr.tx_adptr = (uint8_t *)malloc(sizeof(uint8_t) *
30050f05aa6SSunil Kumar Kori 					evt_rsrc->tx_adptr.nb_tx_adptr);
30150f05aa6SSunil Kumar Kori 	if (!evt_rsrc->tx_adptr.tx_adptr) {
30250f05aa6SSunil Kumar Kori 		free(evt_rsrc->rx_adptr.rx_adptr);
30350f05aa6SSunil Kumar Kori 		free(evt_rsrc->evp.event_p_id);
30450f05aa6SSunil Kumar Kori 		free(evt_rsrc->evq.event_q_id);
30550f05aa6SSunil Kumar Kori 		rte_panic("Failed to allocate memery for Rx adapter\n");
30650f05aa6SSunil Kumar Kori 	}
30750f05aa6SSunil Kumar Kori 
30850f05aa6SSunil Kumar Kori 	ret = rte_event_eth_tx_adapter_create(tx_adptr_id, event_d_id,
30950f05aa6SSunil Kumar Kori 					      &evt_rsrc->def_p_conf);
31050f05aa6SSunil Kumar Kori 	if (ret)
31150f05aa6SSunil Kumar Kori 		rte_panic("Failed to create tx adapter\n");
31250f05aa6SSunil Kumar Kori 
31350f05aa6SSunil Kumar Kori 	RTE_ETH_FOREACH_DEV(port_id) {
31450f05aa6SSunil Kumar Kori 		if ((rsrc->enabled_port_mask & (1 << port_id)) == 0)
31550f05aa6SSunil Kumar Kori 			continue;
31650f05aa6SSunil Kumar Kori 		ret = rte_event_eth_tx_adapter_queue_add(tx_adptr_id, port_id,
31750f05aa6SSunil Kumar Kori 							 -1);
31850f05aa6SSunil Kumar Kori 		if (ret)
31950f05aa6SSunil Kumar Kori 			rte_panic("Failed to add queues to Tx adapter\n");
32050f05aa6SSunil Kumar Kori 	}
32150f05aa6SSunil Kumar Kori 
32250f05aa6SSunil Kumar Kori 	ret = rte_event_eth_tx_adapter_service_id_get(tx_adptr_id, &service_id);
32350f05aa6SSunil Kumar Kori 	if (ret != -ESRCH && ret != 0)
32450f05aa6SSunil Kumar Kori 		rte_panic("Failed to get Tx adapter service ID\n");
32550f05aa6SSunil Kumar Kori 
32650f05aa6SSunil Kumar Kori 	rte_service_runstate_set(service_id, 1);
32750f05aa6SSunil Kumar Kori 	rte_service_set_runstate_mapped_check(service_id, 0);
32850f05aa6SSunil Kumar Kori 	evt_rsrc->tx_adptr.service_id = service_id;
32950f05aa6SSunil Kumar Kori 
3309a212dc0SConor Fogarty 	/* Extra port created. 8< */
33150f05aa6SSunil Kumar Kori 	ret = rte_event_eth_tx_adapter_event_port_get(tx_adptr_id, &tx_port_id);
33250f05aa6SSunil Kumar Kori 	if (ret)
33350f05aa6SSunil Kumar Kori 		rte_panic("Failed to get Tx adapter port id: %d\n", ret);
33450f05aa6SSunil Kumar Kori 
33550f05aa6SSunil Kumar Kori 	ret = rte_event_port_link(event_d_id, tx_port_id,
33650f05aa6SSunil Kumar Kori 				  &evt_rsrc->evq.event_q_id[
33750f05aa6SSunil Kumar Kori 					evt_rsrc->evq.nb_queues - 1],
33850f05aa6SSunil Kumar Kori 				  NULL, 1);
33950f05aa6SSunil Kumar Kori 	if (ret != 1)
34050f05aa6SSunil Kumar Kori 		rte_panic("Unable to link Tx adapter port to Tx queue:err=%d\n",
34150f05aa6SSunil Kumar Kori 			 ret);
3429a212dc0SConor Fogarty 	/* >8 End of extra port created. */
34350f05aa6SSunil Kumar Kori 
34450f05aa6SSunil Kumar Kori 	ret = rte_event_eth_tx_adapter_start(tx_adptr_id);
34550f05aa6SSunil Kumar Kori 	if (ret)
34650f05aa6SSunil Kumar Kori 		rte_panic("Tx adapter[%d] start Failed\n", tx_adptr_id);
34750f05aa6SSunil Kumar Kori 
34850f05aa6SSunil Kumar Kori 	evt_rsrc->tx_adptr.tx_adptr[0] = tx_adptr_id;
34950f05aa6SSunil Kumar Kori }
35050f05aa6SSunil Kumar Kori 
35169de9488SSunil Kumar Kori void
35269de9488SSunil Kumar Kori l2fwd_event_set_generic_ops(struct event_setup_ops *ops)
35369de9488SSunil Kumar Kori {
3546ab87600SSunil Kumar Kori 	ops->event_device_setup = l2fwd_event_device_setup_generic;
3553b5476dbSSunil Kumar Kori 	ops->event_queue_setup = l2fwd_event_queue_setup_generic;
3563b5476dbSSunil Kumar Kori 	ops->event_port_setup = l2fwd_event_port_setup_generic;
35750f05aa6SSunil Kumar Kori 	ops->adapter_setup = l2fwd_rx_tx_adapter_setup_generic;
35869de9488SSunil Kumar Kori }
359