1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include "l2fwd_common.h"
8 l2fwd_event_init_ports(struct l2fwd_resources *rsrc)
10 uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
11 uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
12 struct rte_eth_conf port_conf = {
14 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
18 .mq_mode = ETH_MQ_TX_NONE,
21 uint16_t nb_ports_available = 0;
25 if (rsrc->event_mode) {
26 port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
27 port_conf.rx_adv_conf.rss_conf.rss_key = NULL;
28 port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP;
31 /* Initialise each port */
32 RTE_ETH_FOREACH_DEV(port_id) {
33 struct rte_eth_conf local_port_conf = port_conf;
34 struct rte_eth_dev_info dev_info;
35 struct rte_eth_rxconf rxq_conf;
36 struct rte_eth_txconf txq_conf;
38 /* skip ports that are not enabled */
39 if ((rsrc->enabled_port_mask & (1 << port_id)) == 0) {
40 printf("Skipping disabled port %u\n", port_id);
46 printf("Initializing port %u... ", port_id);
49 ret = rte_eth_dev_info_get(port_id, &dev_info);
51 rte_panic("Error during getting device (port %u) info: %s\n",
52 port_id, strerror(-ret));
53 local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
54 dev_info.flow_type_rss_offloads;
55 if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
56 port_conf.rx_adv_conf.rss_conf.rss_hf) {
57 printf("Port %u modified RSS hash function based on hardware support,"
58 "requested:%#"PRIx64" configured:%#"PRIx64"",
60 port_conf.rx_adv_conf.rss_conf.rss_hf,
61 local_port_conf.rx_adv_conf.rss_conf.rss_hf);
64 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
65 local_port_conf.txmode.offloads |=
66 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
67 /* Configure RX and TX queue. 8< */
68 ret = rte_eth_dev_configure(port_id, 1, 1, &local_port_conf);
70 rte_panic("Cannot configure device: err=%d, port=%u\n",
72 /* >8 End of configuration RX and TX queue. */
74 ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_id, &nb_rxd,
77 rte_panic("Cannot adjust number of descriptors: err=%d, port=%u\n",
80 rte_eth_macaddr_get(port_id, &rsrc->eth_addr[port_id]);
82 /* init one RX queue */
84 rxq_conf = dev_info.default_rxconf;
85 rxq_conf.offloads = local_port_conf.rxmode.offloads;
86 /* Using lcore to poll one or several ports. 8< */
87 ret = rte_eth_rx_queue_setup(port_id, 0, nb_rxd,
88 rte_eth_dev_socket_id(port_id),
92 rte_panic("rte_eth_rx_queue_setup:err=%d, port=%u\n",
95 /* >8 End of using lcore to poll one or several ports. */
97 /* Init one TX queue on each port. 8< */
99 txq_conf = dev_info.default_txconf;
100 txq_conf.offloads = local_port_conf.txmode.offloads;
101 ret = rte_eth_tx_queue_setup(port_id, 0, nb_txd,
102 rte_eth_dev_socket_id(port_id),
105 rte_panic("rte_eth_tx_queue_setup:err=%d, port=%u\n",
107 /* >8 End of init one TX queue on each port. */
109 rte_eth_promiscuous_enable(port_id);
111 printf("Port %u,MAC address: " RTE_ETHER_ADDR_PRT_FMT "\n\n",
113 RTE_ETHER_ADDR_BYTES(&rsrc->eth_addr[port_id]));
116 return nb_ports_available;