1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (C) 2020 Marvell International Ltd.
4 #include <rte_bitmap.h>
5 #include <rte_ethdev.h>
6 #include <rte_eventdev.h>
7 #include <rte_event_eth_rx_adapter.h>
8 #include <rte_event_eth_tx_adapter.h>
9 #include <rte_malloc.h>
12 #include "event_helper.h"
14 static volatile bool eth_core_running;
17 eh_get_enabled_cores(struct rte_bitmap *eth_core_mask)
21 RTE_LCORE_FOREACH(i) {
22 /* Check if this core is enabled in core mask*/
23 if (rte_bitmap_get(eth_core_mask, i)) {
24 /* Found enabled core */
31 static inline unsigned int
32 eh_get_next_eth_core(struct eventmode_conf *em_conf)
34 static unsigned int prev_core = -1;
35 unsigned int next_core;
38 * Make sure we have at least one eth core running, else the following
39 * logic would lead to an infinite loop.
41 if (eh_get_enabled_cores(em_conf->eth_core_mask) == 0) {
42 EH_LOG_ERR("No enabled eth core found");
46 /* Only some cores are marked as eth cores, skip others */
48 /* Get the next core */
49 next_core = rte_get_next_lcore(prev_core, 0, 1);
51 /* Check if we have reached max lcores */
52 if (next_core == RTE_MAX_LCORE)
55 /* Update prev_core */
56 prev_core = next_core;
57 } while (!(rte_bitmap_get(em_conf->eth_core_mask, next_core)));
62 static inline unsigned int
63 eh_get_next_active_core(struct eventmode_conf *em_conf, unsigned int prev_core)
65 unsigned int next_core;
67 /* Get next active core skipping cores reserved as eth cores */
69 /* Get the next core */
70 next_core = rte_get_next_lcore(prev_core, 0, 0);
72 /* Check if we have reached max lcores */
73 if (next_core == RTE_MAX_LCORE)
76 prev_core = next_core;
77 } while (rte_bitmap_get(em_conf->eth_core_mask, next_core));
82 static struct eventdev_params *
83 eh_get_eventdev_params(struct eventmode_conf *em_conf, uint8_t eventdev_id)
87 for (i = 0; i < em_conf->nb_eventdev; i++) {
88 if (em_conf->eventdev_config[i].eventdev_id == eventdev_id)
93 if (i == em_conf->nb_eventdev)
96 return &(em_conf->eventdev_config[i]);
100 eh_dev_has_rx_internal_port(uint8_t eventdev_id)
105 RTE_ETH_FOREACH_DEV(j) {
108 ret = rte_event_eth_rx_adapter_caps_get(eventdev_id, j, &caps);
112 if (!(caps & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT))
119 eh_dev_has_tx_internal_port(uint8_t eventdev_id)
124 RTE_ETH_FOREACH_DEV(j) {
127 ret = rte_event_eth_tx_adapter_caps_get(eventdev_id, j, &caps);
131 if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
138 eh_dev_has_burst_mode(uint8_t dev_id)
140 struct rte_event_dev_info dev_info;
142 rte_event_dev_info_get(dev_id, &dev_info);
143 return (dev_info.event_dev_cap & RTE_EVENT_DEV_CAP_BURST_MODE) ?
148 eh_set_default_conf_eventdev(struct eventmode_conf *em_conf)
150 int lcore_count, nb_eventdev, nb_eth_dev, ret;
151 struct eventdev_params *eventdev_config;
152 struct rte_event_dev_info dev_info;
154 /* Get the number of event devices */
155 nb_eventdev = rte_event_dev_count();
156 if (nb_eventdev == 0) {
157 EH_LOG_ERR("No event devices detected");
161 if (nb_eventdev != 1) {
162 EH_LOG_ERR("Event mode does not support multiple event devices. "
163 "Please provide only one event device.");
167 /* Get the number of eth devs */
168 nb_eth_dev = rte_eth_dev_count_avail();
169 if (nb_eth_dev == 0) {
170 EH_LOG_ERR("No eth devices detected");
174 /* Get the number of lcores */
175 lcore_count = rte_lcore_count();
177 /* Read event device info */
178 ret = rte_event_dev_info_get(0, &dev_info);
180 EH_LOG_ERR("Failed to read event device info %d", ret);
184 /* Check if enough ports are available */
185 if (dev_info.max_event_ports < 2) {
186 EH_LOG_ERR("Not enough event ports available");
190 /* Get the first event dev conf */
191 eventdev_config = &(em_conf->eventdev_config[0]);
193 /* Save number of queues & ports available */
194 eventdev_config->eventdev_id = 0;
195 eventdev_config->nb_eventqueue = dev_info.max_event_queues;
196 eventdev_config->nb_eventport = dev_info.max_event_ports;
197 eventdev_config->ev_queue_mode = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
199 /* Check if there are more queues than required */
200 if (eventdev_config->nb_eventqueue > nb_eth_dev + 1) {
201 /* One queue is reserved for Tx */
202 eventdev_config->nb_eventqueue = nb_eth_dev + 1;
205 /* Check if there are more ports than required */
206 if (eventdev_config->nb_eventport > lcore_count) {
207 /* One port per lcore is enough */
208 eventdev_config->nb_eventport = lcore_count;
211 /* Update the number of event devices */
212 em_conf->nb_eventdev++;
218 eh_do_capability_check(struct eventmode_conf *em_conf)
220 struct eventdev_params *eventdev_config;
221 int all_internal_ports = 1;
222 uint32_t eventdev_id;
225 for (i = 0; i < em_conf->nb_eventdev; i++) {
227 /* Get the event dev conf */
228 eventdev_config = &(em_conf->eventdev_config[i]);
229 eventdev_id = eventdev_config->eventdev_id;
231 /* Check if event device has internal port for Rx & Tx */
232 if (eh_dev_has_rx_internal_port(eventdev_id) &&
233 eh_dev_has_tx_internal_port(eventdev_id)) {
234 eventdev_config->all_internal_ports = 1;
236 all_internal_ports = 0;
241 * If Rx & Tx internal ports are supported by all event devices then
242 * eth cores won't be required. Override the eth core mask requested
243 * and decrement number of event queues by one as it won't be needed
246 if (all_internal_ports) {
247 rte_bitmap_reset(em_conf->eth_core_mask);
248 for (i = 0; i < em_conf->nb_eventdev; i++)
249 em_conf->eventdev_config[i].nb_eventqueue--;
254 eh_set_default_conf_link(struct eventmode_conf *em_conf)
256 struct eventdev_params *eventdev_config;
257 struct eh_event_link_info *link;
258 unsigned int lcore_id = -1;
262 * Create a 1:1 mapping from event ports to cores. If the number
263 * of event ports is lesser than the cores, some cores won't
264 * execute worker. If there are more event ports, then some ports
270 * The event queue-port mapping is done according to the link. Since
271 * we are falling back to the default link config, enabling
272 * "all_ev_queue_to_ev_port" mode flag. This will map all queues
275 em_conf->ext_params.all_ev_queue_to_ev_port = 1;
277 /* Get first event dev conf */
278 eventdev_config = &(em_conf->eventdev_config[0]);
280 /* Loop through the ports */
281 for (i = 0; i < eventdev_config->nb_eventport; i++) {
283 /* Get next active core id */
284 lcore_id = eh_get_next_active_core(em_conf,
287 if (lcore_id == RTE_MAX_LCORE) {
288 /* Reached max cores */
292 /* Save the current combination as one link */
295 link_index = em_conf->nb_link;
297 /* Get the corresponding link */
298 link = &(em_conf->link[link_index]);
301 link->eventdev_id = eventdev_config->eventdev_id;
302 link->event_port_id = i;
303 link->lcore_id = lcore_id;
306 * Don't set eventq_id as by default all queues
307 * need to be mapped to the port, which is controlled
308 * by the operating mode.
311 /* Update number of links */
319 eh_set_default_conf_rx_adapter(struct eventmode_conf *em_conf)
321 struct rx_adapter_connection_info *conn;
322 struct eventdev_params *eventdev_config;
323 struct rx_adapter_conf *adapter;
324 bool rx_internal_port = true;
325 bool single_ev_queue = false;
335 /* Create one adapter with eth queues mapped to event queue(s) */
337 if (em_conf->nb_eventdev == 0) {
338 EH_LOG_ERR("No event devs registered");
342 /* Get the number of eth devs */
343 nb_eth_dev = rte_eth_dev_count_avail();
345 /* Use the first event dev */
346 eventdev_config = &(em_conf->eventdev_config[0]);
348 /* Get eventdev ID */
349 eventdev_id = eventdev_config->eventdev_id;
352 /* Get adapter conf */
353 adapter = &(em_conf->rx_adapter[adapter_id]);
355 /* Set adapter conf */
356 adapter->eventdev_id = eventdev_id;
357 adapter->adapter_id = adapter_id;
360 * If event device does not have internal ports for passing
361 * packets then reserved one queue for Tx path
363 nb_eventqueue = eventdev_config->all_internal_ports ?
364 eventdev_config->nb_eventqueue :
365 eventdev_config->nb_eventqueue - 1;
368 * Map all queues of eth device (port) to an event queue. If there
369 * are more event queues than eth ports then create 1:1 mapping.
370 * Otherwise map all eth ports to a single event queue.
372 if (nb_eth_dev > nb_eventqueue)
373 single_ev_queue = true;
375 for (i = 0; i < nb_eth_dev; i++) {
377 /* Use only the ports enabled */
378 if ((em_conf->eth_portmask & (1 << i)) == 0)
381 /* Get the connection id */
382 conn_id = adapter->nb_connections;
384 /* Get the connection */
385 conn = &(adapter->conn[conn_id]);
387 /* Set mapping between eth ports & event queues*/
389 conn->eventq_id = single_ev_queue ? 0 : i;
391 /* Add all eth queues eth port to event queue */
392 conn->ethdev_rx_qid = -1;
394 /* Get Rx adapter capabilities */
395 ret = rte_event_eth_rx_adapter_caps_get(eventdev_id, i, &caps);
397 EH_LOG_ERR("Failed to get event device %d eth rx adapter"
398 " capabilities for port %d", eventdev_id, i);
401 if (!(caps & RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT))
402 rx_internal_port = false;
404 /* Update no of connections */
405 adapter->nb_connections++;
409 if (rx_internal_port) {
410 /* Rx core is not required */
411 adapter->rx_core_id = -1;
413 /* Rx core is required */
414 adapter->rx_core_id = eh_get_next_eth_core(em_conf);
417 /* We have setup one adapter */
418 em_conf->nb_rx_adapter = 1;
424 eh_set_default_conf_tx_adapter(struct eventmode_conf *em_conf)
426 struct tx_adapter_connection_info *conn;
427 struct eventdev_params *eventdev_config;
428 struct tx_adapter_conf *tx_adapter;
429 bool tx_internal_port = true;
439 * Create one Tx adapter with all eth queues mapped to event queues
443 if (em_conf->nb_eventdev == 0) {
444 EH_LOG_ERR("No event devs registered");
448 /* Get the number of eth devs */
449 nb_eth_dev = rte_eth_dev_count_avail();
451 /* Use the first event dev */
452 eventdev_config = &(em_conf->eventdev_config[0]);
454 /* Get eventdev ID */
455 eventdev_id = eventdev_config->eventdev_id;
458 /* Get adapter conf */
459 tx_adapter = &(em_conf->tx_adapter[adapter_id]);
461 /* Set adapter conf */
462 tx_adapter->eventdev_id = eventdev_id;
463 tx_adapter->adapter_id = adapter_id;
466 * Map all Tx queues of the eth device (port) to the event device.
469 /* Set defaults for connections */
472 * One eth device (port) is one connection. Map all Tx queues
473 * of the device to the Tx adapter.
476 for (i = 0; i < nb_eth_dev; i++) {
478 /* Use only the ports enabled */
479 if ((em_conf->eth_portmask & (1 << i)) == 0)
482 /* Get the connection id */
483 conn_id = tx_adapter->nb_connections;
485 /* Get the connection */
486 conn = &(tx_adapter->conn[conn_id]);
488 /* Add ethdev to connections */
491 /* Add all eth tx queues to adapter */
492 conn->ethdev_tx_qid = -1;
494 /* Get Tx adapter capabilities */
495 ret = rte_event_eth_tx_adapter_caps_get(eventdev_id, i, &caps);
497 EH_LOG_ERR("Failed to get event device %d eth tx adapter"
498 " capabilities for port %d", eventdev_id, i);
501 if (!(caps & RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT))
502 tx_internal_port = false;
504 /* Update no of connections */
505 tx_adapter->nb_connections++;
508 if (tx_internal_port) {
509 /* Tx core is not required */
510 tx_adapter->tx_core_id = -1;
512 /* Tx core is required */
513 tx_adapter->tx_core_id = eh_get_next_eth_core(em_conf);
516 * Use one event queue per adapter for submitting packets
517 * for Tx. Reserving the last queue available
519 /* Queue numbers start at 0 */
520 tx_adapter->tx_ev_queue = eventdev_config->nb_eventqueue - 1;
523 /* We have setup one adapter */
524 em_conf->nb_tx_adapter = 1;
529 eh_validate_conf(struct eventmode_conf *em_conf)
534 * Check if event devs are specified. Else probe the event devices
535 * and initialize the config with all ports & queues available
537 if (em_conf->nb_eventdev == 0) {
538 ret = eh_set_default_conf_eventdev(em_conf);
543 /* Perform capability check for the selected event devices */
544 eh_do_capability_check(em_conf);
547 * Check if links are specified. Else generate a default config for
548 * the event ports used.
550 if (em_conf->nb_link == 0) {
551 ret = eh_set_default_conf_link(em_conf);
557 * Check if rx adapters are specified. Else generate a default config
558 * with one rx adapter and all eth queues - event queue mapped.
560 if (em_conf->nb_rx_adapter == 0) {
561 ret = eh_set_default_conf_rx_adapter(em_conf);
567 * Check if tx adapters are specified. Else generate a default config
568 * with one tx adapter.
570 if (em_conf->nb_tx_adapter == 0) {
571 ret = eh_set_default_conf_tx_adapter(em_conf);
580 eh_initialize_eventdev(struct eventmode_conf *em_conf)
582 struct rte_event_queue_conf eventq_conf = {0};
583 struct rte_event_dev_info evdev_default_conf;
584 struct rte_event_dev_config eventdev_conf;
585 struct eventdev_params *eventdev_config;
586 int nb_eventdev = em_conf->nb_eventdev;
587 struct eh_event_link_info *link;
588 uint8_t *queue = NULL;
594 for (i = 0; i < nb_eventdev; i++) {
596 /* Get eventdev config */
597 eventdev_config = &(em_conf->eventdev_config[i]);
599 /* Get event dev ID */
600 eventdev_id = eventdev_config->eventdev_id;
602 /* Get the number of queues */
603 nb_eventqueue = eventdev_config->nb_eventqueue;
605 /* Reset the default conf */
606 memset(&evdev_default_conf, 0,
607 sizeof(struct rte_event_dev_info));
609 /* Get default conf of eventdev */
610 ret = rte_event_dev_info_get(eventdev_id, &evdev_default_conf);
613 "Error in getting event device info[devID:%d]",
618 memset(&eventdev_conf, 0, sizeof(struct rte_event_dev_config));
619 eventdev_conf.nb_events_limit =
620 evdev_default_conf.max_num_events;
621 eventdev_conf.nb_event_queues = nb_eventqueue;
622 eventdev_conf.nb_event_ports =
623 eventdev_config->nb_eventport;
624 eventdev_conf.nb_event_queue_flows =
625 evdev_default_conf.max_event_queue_flows;
626 eventdev_conf.nb_event_port_dequeue_depth =
627 evdev_default_conf.max_event_port_dequeue_depth;
628 eventdev_conf.nb_event_port_enqueue_depth =
629 evdev_default_conf.max_event_port_enqueue_depth;
631 /* Configure event device */
632 ret = rte_event_dev_configure(eventdev_id, &eventdev_conf);
634 EH_LOG_ERR("Error in configuring event device");
638 /* Configure event queues */
639 for (j = 0; j < nb_eventqueue; j++) {
641 memset(&eventq_conf, 0,
642 sizeof(struct rte_event_queue_conf));
644 /* Per event dev queues can be ATQ or SINGLE LINK */
645 eventq_conf.event_queue_cfg =
646 eventdev_config->ev_queue_mode;
648 * All queues need to be set with sched_type as
649 * schedule type for the application stage. One
650 * queue would be reserved for the final eth tx
651 * stage if event device does not have internal
652 * ports. This will be an atomic queue.
654 if (!eventdev_config->all_internal_ports &&
655 j == nb_eventqueue-1) {
656 eventq_conf.schedule_type =
657 RTE_SCHED_TYPE_ATOMIC;
659 eventq_conf.schedule_type =
660 em_conf->ext_params.sched_type;
663 /* Set max atomic flows to 1024 */
664 eventq_conf.nb_atomic_flows = 1024;
665 eventq_conf.nb_atomic_order_sequences = 1024;
667 /* Setup the queue */
668 ret = rte_event_queue_setup(eventdev_id, j,
671 EH_LOG_ERR("Failed to setup event queue %d",
677 /* Configure event ports */
678 for (j = 0; j < eventdev_config->nb_eventport; j++) {
679 ret = rte_event_port_setup(eventdev_id, j, NULL);
681 EH_LOG_ERR("Failed to setup event port %d",
688 /* Make event queue - event port link */
689 for (j = 0; j < em_conf->nb_link; j++) {
692 link = &(em_conf->link[j]);
694 /* Get event dev ID */
695 eventdev_id = link->eventdev_id;
698 * If "all_ev_queue_to_ev_port" params flag is selected, all
699 * queues need to be mapped to the port.
701 if (em_conf->ext_params.all_ev_queue_to_ev_port)
704 queue = &(link->eventq_id);
706 /* Link queue to port */
707 ret = rte_event_port_link(eventdev_id, link->event_port_id,
710 EH_LOG_ERR("Failed to link event port %d", ret);
715 /* Start event devices */
716 for (i = 0; i < nb_eventdev; i++) {
718 /* Get eventdev config */
719 eventdev_config = &(em_conf->eventdev_config[i]);
721 ret = rte_event_dev_start(eventdev_config->eventdev_id);
723 EH_LOG_ERR("Failed to start event device %d, %d",
732 eh_rx_adapter_configure(struct eventmode_conf *em_conf,
733 struct rx_adapter_conf *adapter)
735 struct rte_event_eth_rx_adapter_queue_conf queue_conf = {0};
736 struct rte_event_dev_info evdev_default_conf = {0};
737 struct rte_event_port_conf port_conf = {0};
738 struct rx_adapter_connection_info *conn;
744 /* Get event dev ID */
745 eventdev_id = adapter->eventdev_id;
747 /* Get default configuration of event dev */
748 ret = rte_event_dev_info_get(eventdev_id, &evdev_default_conf);
750 EH_LOG_ERR("Failed to get event dev info %d", ret);
754 /* Setup port conf */
755 port_conf.new_event_threshold = 1200;
756 port_conf.dequeue_depth =
757 evdev_default_conf.max_event_port_dequeue_depth;
758 port_conf.enqueue_depth =
759 evdev_default_conf.max_event_port_enqueue_depth;
761 /* Create Rx adapter */
762 ret = rte_event_eth_rx_adapter_create(adapter->adapter_id,
763 adapter->eventdev_id, &port_conf);
765 EH_LOG_ERR("Failed to create rx adapter %d", ret);
769 /* Setup various connections in the adapter */
770 for (j = 0; j < adapter->nb_connections; j++) {
772 conn = &(adapter->conn[j]);
774 /* Setup queue conf */
775 queue_conf.ev.queue_id = conn->eventq_id;
776 queue_conf.ev.sched_type = em_conf->ext_params.sched_type;
777 queue_conf.ev.event_type = RTE_EVENT_TYPE_ETHDEV;
779 /* Add queue to the adapter */
780 ret = rte_event_eth_rx_adapter_queue_add(adapter->adapter_id,
781 conn->ethdev_id, conn->ethdev_rx_qid,
784 EH_LOG_ERR("Failed to add eth queue to rx adapter %d",
790 /* Get the service ID used by rx adapter */
791 ret = rte_event_eth_rx_adapter_service_id_get(adapter->adapter_id,
793 if (ret != -ESRCH && ret < 0) {
794 EH_LOG_ERR("Failed to get service id used by rx adapter %d",
799 rte_service_set_runstate_mapped_check(service_id, 0);
802 ret = rte_event_eth_rx_adapter_start(adapter->adapter_id);
804 EH_LOG_ERR("Failed to start rx adapter %d", ret);
812 eh_initialize_rx_adapter(struct eventmode_conf *em_conf)
814 struct rx_adapter_conf *adapter;
817 /* Configure rx adapters */
818 for (i = 0; i < em_conf->nb_rx_adapter; i++) {
819 adapter = &(em_conf->rx_adapter[i]);
820 ret = eh_rx_adapter_configure(em_conf, adapter);
822 EH_LOG_ERR("Failed to configure rx adapter %d", ret);
830 eh_start_worker_eth_core(struct eventmode_conf *conf, uint32_t lcore_id)
832 uint32_t service_id[EVENT_MODE_MAX_ADAPTERS_PER_RX_CORE];
833 struct rx_adapter_conf *rx_adapter;
834 struct tx_adapter_conf *tx_adapter;
835 int service_count = 0;
840 EH_LOG_INFO("Entering eth_core processing on lcore %u", lcore_id);
843 * Parse adapter config to check which of all Rx adapters need
844 * to be handled by this core.
846 for (i = 0; i < conf->nb_rx_adapter; i++) {
847 /* Check if we have exceeded the max allowed */
848 if (service_count > EVENT_MODE_MAX_ADAPTERS_PER_RX_CORE) {
850 "Exceeded the max allowed adapters per rx core");
854 rx_adapter = &(conf->rx_adapter[i]);
855 if (rx_adapter->rx_core_id != lcore_id)
858 /* Adapter is handled by this core */
859 adapter_id = rx_adapter->adapter_id;
861 /* Get the service ID for the adapters */
862 ret = rte_event_eth_rx_adapter_service_id_get(adapter_id,
863 &(service_id[service_count]));
865 if (ret != -ESRCH && ret < 0) {
867 "Failed to get service id used by rx adapter");
871 /* Update service count */
876 * Parse adapter config to see which of all Tx adapters need
877 * to be handled by this core.
879 for (i = 0; i < conf->nb_tx_adapter; i++) {
880 /* Check if we have exceeded the max allowed */
881 if (service_count > EVENT_MODE_MAX_ADAPTERS_PER_TX_CORE) {
883 "Exceeded the max allowed adapters per tx core");
887 tx_adapter = &conf->tx_adapter[i];
888 if (tx_adapter->tx_core_id != lcore_id)
891 /* Adapter is handled by this core */
892 adapter_id = tx_adapter->adapter_id;
894 /* Get the service ID for the adapters */
895 ret = rte_event_eth_tx_adapter_service_id_get(adapter_id,
896 &(service_id[service_count]));
898 if (ret != -ESRCH && ret < 0) {
900 "Failed to get service id used by tx adapter");
904 /* Update service count */
908 eth_core_running = true;
910 while (eth_core_running) {
911 for (i = 0; i < service_count; i++) {
912 /* Initiate adapter service */
913 rte_service_run_iter_on_app_lcore(service_id[i], 0);
921 eh_stop_worker_eth_core(void)
923 if (eth_core_running) {
924 EH_LOG_INFO("Stopping eth cores");
925 eth_core_running = false;
930 static struct eh_app_worker_params *
931 eh_find_worker(uint32_t lcore_id, struct eh_conf *conf,
932 struct eh_app_worker_params *app_wrkrs, uint8_t nb_wrkr_param)
934 struct eh_app_worker_params curr_conf = { {{0} }, NULL};
935 struct eh_event_link_info *link = NULL;
936 struct eh_app_worker_params *tmp_wrkr;
937 struct eventmode_conf *em_conf;
941 /* Get eventmode config */
942 em_conf = conf->mode_params;
945 * Use event device from the first lcore-event link.
947 * Assumption: All lcore-event links tied to a core are using the
948 * same event device. In other words, one core would be polling on
949 * queues of a single event device only.
952 /* Get a link for this lcore */
953 for (i = 0; i < em_conf->nb_link; i++) {
954 link = &(em_conf->link[i]);
955 if (link->lcore_id == lcore_id)
960 EH_LOG_ERR("No valid link found for lcore %d", lcore_id);
964 /* Get event dev ID */
965 eventdev_id = link->eventdev_id;
967 /* Populate the curr_conf with the capabilities */
969 /* Check for Tx internal port */
970 if (eh_dev_has_tx_internal_port(eventdev_id))
971 curr_conf.cap.tx_internal_port = EH_TX_TYPE_INTERNAL_PORT;
973 curr_conf.cap.tx_internal_port = EH_TX_TYPE_NO_INTERNAL_PORT;
975 /* Check for burst mode */
976 if (eh_dev_has_burst_mode(eventdev_id))
977 curr_conf.cap.burst = EH_RX_TYPE_BURST;
979 curr_conf.cap.burst = EH_RX_TYPE_NON_BURST;
981 curr_conf.cap.ipsec_mode = conf->ipsec_mode;
983 /* Parse the passed list and see if we have matching capabilities */
985 /* Initialize the pointer used to traverse the list */
986 tmp_wrkr = app_wrkrs;
988 for (i = 0; i < nb_wrkr_param; i++, tmp_wrkr++) {
990 /* Skip this if capabilities are not matching */
991 if (tmp_wrkr->cap.u64 != curr_conf.cap.u64)
994 /* If the checks pass, we have a match */
1002 eh_verify_match_worker(struct eh_app_worker_params *match_wrkr)
1004 /* Verify registered worker */
1005 if (match_wrkr->worker_thread == NULL) {
1006 EH_LOG_ERR("No worker registered");
1015 eh_get_event_lcore_links(uint32_t lcore_id, struct eh_conf *conf,
1016 struct eh_event_link_info **links)
1018 struct eh_event_link_info *link_cache;
1019 struct eventmode_conf *em_conf = NULL;
1020 struct eh_event_link_info *link;
1021 uint8_t lcore_nb_link = 0;
1022 size_t single_link_size;
1027 if (conf == NULL || links == NULL) {
1028 EH_LOG_ERR("Invalid args");
1032 /* Get eventmode conf */
1033 em_conf = conf->mode_params;
1035 if (em_conf == NULL) {
1036 EH_LOG_ERR("Invalid event mode parameters");
1040 /* Get the number of links registered */
1041 for (i = 0; i < em_conf->nb_link; i++) {
1044 link = &(em_conf->link[i]);
1046 /* Check if we have link intended for this lcore */
1047 if (link->lcore_id == lcore_id) {
1049 /* Update the number of links for this core */
1055 /* Compute size of one entry to be copied */
1056 single_link_size = sizeof(struct eh_event_link_info);
1058 /* Compute size of the buffer required */
1059 cache_size = lcore_nb_link * sizeof(struct eh_event_link_info);
1061 /* Compute size of the buffer required */
1062 link_cache = calloc(1, cache_size);
1064 /* Get the number of links registered */
1065 for (i = 0; i < em_conf->nb_link; i++) {
1068 link = &(em_conf->link[i]);
1070 /* Check if we have link intended for this lcore */
1071 if (link->lcore_id == lcore_id) {
1073 /* Cache the link */
1074 memcpy(&link_cache[index], link, single_link_size);
1081 /* Update the links for application to use the cached links */
1082 *links = link_cache;
1084 /* Return the number of cached links */
1085 return lcore_nb_link;
1089 eh_tx_adapter_configure(struct eventmode_conf *em_conf,
1090 struct tx_adapter_conf *adapter)
1092 struct rte_event_dev_info evdev_default_conf = {0};
1093 struct rte_event_port_conf port_conf = {0};
1094 struct tx_adapter_connection_info *conn;
1095 struct eventdev_params *eventdev_config;
1096 uint8_t tx_port_id = 0;
1097 uint8_t eventdev_id;
1098 uint32_t service_id;
1101 /* Get event dev ID */
1102 eventdev_id = adapter->eventdev_id;
1104 /* Get event device conf */
1105 eventdev_config = eh_get_eventdev_params(em_conf, eventdev_id);
1107 /* Create Tx adapter */
1109 /* Get default configuration of event dev */
1110 ret = rte_event_dev_info_get(eventdev_id, &evdev_default_conf);
1112 EH_LOG_ERR("Failed to get event dev info %d", ret);
1116 /* Setup port conf */
1117 port_conf.new_event_threshold =
1118 evdev_default_conf.max_num_events;
1119 port_conf.dequeue_depth =
1120 evdev_default_conf.max_event_port_dequeue_depth;
1121 port_conf.enqueue_depth =
1122 evdev_default_conf.max_event_port_enqueue_depth;
1124 /* Create adapter */
1125 ret = rte_event_eth_tx_adapter_create(adapter->adapter_id,
1126 adapter->eventdev_id, &port_conf);
1128 EH_LOG_ERR("Failed to create tx adapter %d", ret);
1132 /* Setup various connections in the adapter */
1133 for (j = 0; j < adapter->nb_connections; j++) {
1135 /* Get connection */
1136 conn = &(adapter->conn[j]);
1138 /* Add queue to the adapter */
1139 ret = rte_event_eth_tx_adapter_queue_add(adapter->adapter_id,
1140 conn->ethdev_id, conn->ethdev_tx_qid);
1142 EH_LOG_ERR("Failed to add eth queue to tx adapter %d",
1149 * Check if Tx core is assigned. If Tx core is not assigned then
1150 * the adapter has internal port for submitting Tx packets and
1151 * Tx event queue & port setup is not required
1153 if (adapter->tx_core_id == (uint32_t) (-1)) {
1154 /* Internal port is present */
1155 goto skip_tx_queue_port_setup;
1158 /* Setup Tx queue & port */
1160 /* Get event port used by the adapter */
1161 ret = rte_event_eth_tx_adapter_event_port_get(
1162 adapter->adapter_id, &tx_port_id);
1164 EH_LOG_ERR("Failed to get tx adapter port id %d", ret);
1169 * Tx event queue is reserved for Tx adapter. Unlink this queue
1170 * from all other ports
1173 for (j = 0; j < eventdev_config->nb_eventport; j++) {
1174 rte_event_port_unlink(eventdev_id, j,
1175 &(adapter->tx_ev_queue), 1);
1178 /* Link Tx event queue to Tx port */
1179 ret = rte_event_port_link(eventdev_id, tx_port_id,
1180 &(adapter->tx_ev_queue), NULL, 1);
1182 EH_LOG_ERR("Failed to link event queue to port");
1186 /* Get the service ID used by Tx adapter */
1187 ret = rte_event_eth_tx_adapter_service_id_get(adapter->adapter_id,
1189 if (ret != -ESRCH && ret < 0) {
1190 EH_LOG_ERR("Failed to get service id used by tx adapter %d",
1195 rte_service_set_runstate_mapped_check(service_id, 0);
1197 skip_tx_queue_port_setup:
1199 ret = rte_event_eth_tx_adapter_start(adapter->adapter_id);
1201 EH_LOG_ERR("Failed to start tx adapter %d", ret);
1209 eh_initialize_tx_adapter(struct eventmode_conf *em_conf)
1211 struct tx_adapter_conf *adapter;
1214 /* Configure Tx adapters */
1215 for (i = 0; i < em_conf->nb_tx_adapter; i++) {
1216 adapter = &(em_conf->tx_adapter[i]);
1217 ret = eh_tx_adapter_configure(em_conf, adapter);
1219 EH_LOG_ERR("Failed to configure tx adapter %d", ret);
1227 eh_display_operating_mode(struct eventmode_conf *em_conf)
1229 char sched_types[][32] = {
1230 "RTE_SCHED_TYPE_ORDERED",
1231 "RTE_SCHED_TYPE_ATOMIC",
1232 "RTE_SCHED_TYPE_PARALLEL",
1234 EH_LOG_INFO("Operating mode:");
1236 EH_LOG_INFO("\tScheduling type: \t%s",
1237 sched_types[em_conf->ext_params.sched_type]);
1243 eh_display_event_dev_conf(struct eventmode_conf *em_conf)
1245 char queue_mode[][32] = {
1247 "ATQ (ALL TYPE QUEUE)",
1250 char print_buf[256] = { 0 };
1253 EH_LOG_INFO("Event Device Configuration:");
1255 for (i = 0; i < em_conf->nb_eventdev; i++) {
1257 "\tDev ID: %-2d \tQueues: %-2d \tPorts: %-2d",
1258 em_conf->eventdev_config[i].eventdev_id,
1259 em_conf->eventdev_config[i].nb_eventqueue,
1260 em_conf->eventdev_config[i].nb_eventport);
1261 sprintf(print_buf + strlen(print_buf),
1263 queue_mode[em_conf->eventdev_config[i].ev_queue_mode]);
1264 EH_LOG_INFO("%s", print_buf);
1270 eh_display_rx_adapter_conf(struct eventmode_conf *em_conf)
1272 int nb_rx_adapter = em_conf->nb_rx_adapter;
1273 struct rx_adapter_connection_info *conn;
1274 struct rx_adapter_conf *adapter;
1275 char print_buf[256] = { 0 };
1278 EH_LOG_INFO("Rx adapters configured: %d", nb_rx_adapter);
1280 for (i = 0; i < nb_rx_adapter; i++) {
1281 adapter = &(em_conf->rx_adapter[i]);
1283 "\tRx adaper ID: %-2d\tConnections: %-2d\tEvent dev ID: %-2d",
1284 adapter->adapter_id,
1285 adapter->nb_connections,
1286 adapter->eventdev_id);
1287 if (adapter->rx_core_id == (uint32_t)-1)
1288 sprintf(print_buf + strlen(print_buf),
1289 "\tRx core: %-2s", "[INTERNAL PORT]");
1290 else if (adapter->rx_core_id == RTE_MAX_LCORE)
1291 sprintf(print_buf + strlen(print_buf),
1292 "\tRx core: %-2s", "[NONE]");
1294 sprintf(print_buf + strlen(print_buf),
1295 "\tRx core: %-2d", adapter->rx_core_id);
1297 EH_LOG_INFO("%s", print_buf);
1299 for (j = 0; j < adapter->nb_connections; j++) {
1300 conn = &(adapter->conn[j]);
1303 "\t\tEthdev ID: %-2d", conn->ethdev_id);
1305 if (conn->ethdev_rx_qid == -1)
1306 sprintf(print_buf + strlen(print_buf),
1307 "\tEth rx queue: %-2s", "ALL");
1309 sprintf(print_buf + strlen(print_buf),
1310 "\tEth rx queue: %-2d",
1311 conn->ethdev_rx_qid);
1313 sprintf(print_buf + strlen(print_buf),
1314 "\tEvent queue: %-2d", conn->eventq_id);
1315 EH_LOG_INFO("%s", print_buf);
1322 eh_display_tx_adapter_conf(struct eventmode_conf *em_conf)
1324 int nb_tx_adapter = em_conf->nb_tx_adapter;
1325 struct tx_adapter_connection_info *conn;
1326 struct tx_adapter_conf *adapter;
1327 char print_buf[256] = { 0 };
1330 EH_LOG_INFO("Tx adapters configured: %d", nb_tx_adapter);
1332 for (i = 0; i < nb_tx_adapter; i++) {
1333 adapter = &(em_conf->tx_adapter[i]);
1335 "\tTx adapter ID: %-2d\tConnections: %-2d\tEvent dev ID: %-2d",
1336 adapter->adapter_id,
1337 adapter->nb_connections,
1338 adapter->eventdev_id);
1339 if (adapter->tx_core_id == (uint32_t)-1)
1340 sprintf(print_buf + strlen(print_buf),
1341 "\tTx core: %-2s", "[INTERNAL PORT]");
1342 else if (adapter->tx_core_id == RTE_MAX_LCORE)
1343 sprintf(print_buf + strlen(print_buf),
1344 "\tTx core: %-2s", "[NONE]");
1346 sprintf(print_buf + strlen(print_buf),
1347 "\tTx core: %-2d,\tInput event queue: %-2d",
1348 adapter->tx_core_id, adapter->tx_ev_queue);
1350 EH_LOG_INFO("%s", print_buf);
1352 for (j = 0; j < adapter->nb_connections; j++) {
1353 conn = &(adapter->conn[j]);
1356 "\t\tEthdev ID: %-2d", conn->ethdev_id);
1358 if (conn->ethdev_tx_qid == -1)
1359 sprintf(print_buf + strlen(print_buf),
1360 "\tEth tx queue: %-2s", "ALL");
1362 sprintf(print_buf + strlen(print_buf),
1363 "\tEth tx queue: %-2d",
1364 conn->ethdev_tx_qid);
1365 EH_LOG_INFO("%s", print_buf);
1372 eh_display_link_conf(struct eventmode_conf *em_conf)
1374 struct eh_event_link_info *link;
1375 char print_buf[256] = { 0 };
1378 EH_LOG_INFO("Links configured: %d", em_conf->nb_link);
1380 for (i = 0; i < em_conf->nb_link; i++) {
1381 link = &(em_conf->link[i]);
1384 "\tEvent dev ID: %-2d\tEvent port: %-2d",
1386 link->event_port_id);
1388 if (em_conf->ext_params.all_ev_queue_to_ev_port)
1389 sprintf(print_buf + strlen(print_buf),
1390 "Event queue: %-2s\t", "ALL");
1392 sprintf(print_buf + strlen(print_buf),
1393 "Event queue: %-2d\t", link->eventq_id);
1395 sprintf(print_buf + strlen(print_buf),
1396 "Lcore: %-2d", link->lcore_id);
1397 EH_LOG_INFO("%s", print_buf);
1405 struct eventmode_conf *em_conf = NULL;
1406 struct eh_conf *conf = NULL;
1407 unsigned int eth_core_id;
1408 void *bitmap = NULL;
1411 /* Allocate memory for config */
1412 conf = calloc(1, sizeof(struct eh_conf));
1414 EH_LOG_ERR("Failed to allocate memory for eventmode helper "
1419 /* Set default conf */
1421 /* Packet transfer mode: poll */
1422 conf->mode = EH_PKT_TRANSFER_MODE_POLL;
1423 conf->ipsec_mode = EH_IPSEC_MODE_TYPE_APP;
1425 /* Keep all ethernet ports enabled by default */
1426 conf->eth_portmask = -1;
1428 /* Allocate memory for event mode params */
1429 conf->mode_params = calloc(1, sizeof(struct eventmode_conf));
1430 if (conf->mode_params == NULL) {
1431 EH_LOG_ERR("Failed to allocate memory for event mode params");
1435 /* Get eventmode conf */
1436 em_conf = conf->mode_params;
1438 /* Allocate and initialize bitmap for eth cores */
1439 nb_bytes = rte_bitmap_get_memory_footprint(RTE_MAX_LCORE);
1441 EH_LOG_ERR("Failed to get bitmap footprint");
1445 bitmap = rte_zmalloc("event-helper-ethcore-bitmap", nb_bytes,
1446 RTE_CACHE_LINE_SIZE);
1448 EH_LOG_ERR("Failed to allocate memory for eth cores bitmap\n");
1452 em_conf->eth_core_mask = rte_bitmap_init(RTE_MAX_LCORE, bitmap,
1454 if (!em_conf->eth_core_mask) {
1455 EH_LOG_ERR("Failed to initialize bitmap");
1459 /* Set schedule type as not set */
1460 em_conf->ext_params.sched_type = SCHED_TYPE_NOT_SET;
1462 /* Set two cores as eth cores for Rx & Tx */
1464 /* Use first core other than master core as Rx core */
1465 eth_core_id = rte_get_next_lcore(0, /* curr core */
1466 1, /* skip master core */
1469 rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
1471 /* Use next core as Tx core */
1472 eth_core_id = rte_get_next_lcore(eth_core_id, /* curr core */
1473 1, /* skip master core */
1476 rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
1490 eh_conf_uninit(struct eh_conf *conf)
1492 struct eventmode_conf *em_conf = NULL;
1494 if (!conf || !conf->mode_params)
1497 /* Get eventmode conf */
1498 em_conf = conf->mode_params;
1500 /* Free evenmode configuration memory */
1501 rte_free(em_conf->eth_core_mask);
1507 eh_display_conf(struct eh_conf *conf)
1509 struct eventmode_conf *em_conf;
1512 EH_LOG_ERR("Invalid event helper configuration");
1516 if (conf->mode != EH_PKT_TRANSFER_MODE_EVENT)
1519 if (conf->mode_params == NULL) {
1520 EH_LOG_ERR("Invalid event mode parameters");
1524 /* Get eventmode conf */
1525 em_conf = (struct eventmode_conf *)(conf->mode_params);
1527 /* Display user exposed operating modes */
1528 eh_display_operating_mode(em_conf);
1530 /* Display event device conf */
1531 eh_display_event_dev_conf(em_conf);
1533 /* Display Rx adapter conf */
1534 eh_display_rx_adapter_conf(em_conf);
1536 /* Display Tx adapter conf */
1537 eh_display_tx_adapter_conf(em_conf);
1539 /* Display event-lcore link */
1540 eh_display_link_conf(em_conf);
1544 eh_devs_init(struct eh_conf *conf)
1546 struct eventmode_conf *em_conf;
1551 EH_LOG_ERR("Invalid event helper configuration");
1555 if (conf->mode != EH_PKT_TRANSFER_MODE_EVENT)
1558 if (conf->mode_params == NULL) {
1559 EH_LOG_ERR("Invalid event mode parameters");
1563 /* Get eventmode conf */
1564 em_conf = conf->mode_params;
1566 /* Eventmode conf would need eth portmask */
1567 em_conf->eth_portmask = conf->eth_portmask;
1569 /* Validate the requested config */
1570 ret = eh_validate_conf(em_conf);
1572 EH_LOG_ERR("Failed to validate the requested config %d", ret);
1576 /* Display the current configuration */
1577 eh_display_conf(conf);
1579 /* Stop eth devices before setting up adapter */
1580 RTE_ETH_FOREACH_DEV(port_id) {
1582 /* Use only the ports enabled */
1583 if ((conf->eth_portmask & (1 << port_id)) == 0)
1586 ret = rte_eth_dev_stop(port_id);
1588 EH_LOG_ERR("Failed to stop port %u, err: %d",
1594 /* Setup eventdev */
1595 ret = eh_initialize_eventdev(em_conf);
1597 EH_LOG_ERR("Failed to initialize event dev %d", ret);
1601 /* Setup Rx adapter */
1602 ret = eh_initialize_rx_adapter(em_conf);
1604 EH_LOG_ERR("Failed to initialize rx adapter %d", ret);
1608 /* Setup Tx adapter */
1609 ret = eh_initialize_tx_adapter(em_conf);
1611 EH_LOG_ERR("Failed to initialize tx adapter %d", ret);
1615 /* Start eth devices after setting up adapter */
1616 RTE_ETH_FOREACH_DEV(port_id) {
1618 /* Use only the ports enabled */
1619 if ((conf->eth_portmask & (1 << port_id)) == 0)
1622 ret = rte_eth_dev_start(port_id);
1624 EH_LOG_ERR("Failed to start eth dev %d, %d",
1634 eh_devs_uninit(struct eh_conf *conf)
1636 struct eventmode_conf *em_conf;
1641 EH_LOG_ERR("Invalid event helper configuration");
1645 if (conf->mode != EH_PKT_TRANSFER_MODE_EVENT)
1648 if (conf->mode_params == NULL) {
1649 EH_LOG_ERR("Invalid event mode parameters");
1653 /* Get eventmode conf */
1654 em_conf = conf->mode_params;
1656 /* Stop and release rx adapters */
1657 for (i = 0; i < em_conf->nb_rx_adapter; i++) {
1659 id = em_conf->rx_adapter[i].adapter_id;
1660 ret = rte_event_eth_rx_adapter_stop(id);
1662 EH_LOG_ERR("Failed to stop rx adapter %d", ret);
1666 for (j = 0; j < em_conf->rx_adapter[i].nb_connections; j++) {
1668 ret = rte_event_eth_rx_adapter_queue_del(id,
1669 em_conf->rx_adapter[i].conn[j].ethdev_id, -1);
1672 "Failed to remove rx adapter queues %d",
1678 ret = rte_event_eth_rx_adapter_free(id);
1680 EH_LOG_ERR("Failed to free rx adapter %d", ret);
1685 /* Stop and release event devices */
1686 for (i = 0; i < em_conf->nb_eventdev; i++) {
1688 id = em_conf->eventdev_config[i].eventdev_id;
1689 rte_event_dev_stop(id);
1691 ret = rte_event_dev_close(id);
1693 EH_LOG_ERR("Failed to close event dev %d, %d", id, ret);
1698 /* Stop and release tx adapters */
1699 for (i = 0; i < em_conf->nb_tx_adapter; i++) {
1701 id = em_conf->tx_adapter[i].adapter_id;
1702 ret = rte_event_eth_tx_adapter_stop(id);
1704 EH_LOG_ERR("Failed to stop tx adapter %d", ret);
1708 for (j = 0; j < em_conf->tx_adapter[i].nb_connections; j++) {
1710 ret = rte_event_eth_tx_adapter_queue_del(id,
1711 em_conf->tx_adapter[i].conn[j].ethdev_id, -1);
1714 "Failed to remove tx adapter queues %d",
1720 ret = rte_event_eth_tx_adapter_free(id);
1722 EH_LOG_ERR("Failed to free tx adapter %d", ret);
1731 eh_launch_worker(struct eh_conf *conf, struct eh_app_worker_params *app_wrkr,
1732 uint8_t nb_wrkr_param)
1734 struct eh_app_worker_params *match_wrkr;
1735 struct eh_event_link_info *links = NULL;
1736 struct eventmode_conf *em_conf;
1741 EH_LOG_ERR("Invalid event helper configuration");
1745 if (conf->mode_params == NULL) {
1746 EH_LOG_ERR("Invalid event mode parameters");
1750 /* Get eventmode conf */
1751 em_conf = conf->mode_params;
1754 lcore_id = rte_lcore_id();
1756 /* Check if this is eth core */
1757 if (rte_bitmap_get(em_conf->eth_core_mask, lcore_id)) {
1758 eh_start_worker_eth_core(em_conf, lcore_id);
1762 if (app_wrkr == NULL || nb_wrkr_param == 0) {
1763 EH_LOG_ERR("Invalid args");
1768 * This is a regular worker thread. The application registers
1769 * multiple workers with various capabilities. Run worker
1770 * based on the selected capabilities of the event
1771 * device configured.
1774 /* Get the first matching worker for the event device */
1775 match_wrkr = eh_find_worker(lcore_id, conf, app_wrkr, nb_wrkr_param);
1776 if (match_wrkr == NULL) {
1777 EH_LOG_ERR("Failed to match worker registered for lcore %d",
1779 goto clean_and_exit;
1782 /* Verify sanity of the matched worker */
1783 if (eh_verify_match_worker(match_wrkr) != 1) {
1784 EH_LOG_ERR("Failed to validate the matched worker");
1785 goto clean_and_exit;
1788 /* Get worker links */
1789 nb_links = eh_get_event_lcore_links(lcore_id, conf, &links);
1791 /* Launch the worker thread */
1792 match_wrkr->worker_thread(links, nb_links);
1794 /* Free links info memory */
1799 /* Flag eth_cores to stop, if started */
1800 eh_stop_worker_eth_core();
1804 eh_get_tx_queue(struct eh_conf *conf, uint8_t eventdev_id)
1806 struct eventdev_params *eventdev_config;
1807 struct eventmode_conf *em_conf;
1810 EH_LOG_ERR("Invalid event helper configuration");
1814 if (conf->mode_params == NULL) {
1815 EH_LOG_ERR("Invalid event mode parameters");
1819 /* Get eventmode conf */
1820 em_conf = conf->mode_params;
1822 /* Get event device conf */
1823 eventdev_config = eh_get_eventdev_params(em_conf, eventdev_id);
1825 if (eventdev_config == NULL) {
1826 EH_LOG_ERR("Failed to read eventdev config");
1831 * The last queue is reserved to be used as atomic queue for the
1832 * last stage (eth packet tx stage)
1834 return eventdev_config->nb_eventqueue - 1;