c206415d07ebc1cd5b55964bc3984874f980ce0f
[dpdk.git] / examples / l2fwd-event / l2fwd_common.c
1 #include "l2fwd_common.h"
2
3 int
4 l2fwd_event_init_ports(struct l2fwd_resources *rsrc)
5 {
6         uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
7         uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
8         struct rte_eth_conf port_conf = {
9                 .rxmode = {
10                         .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
11                         .split_hdr_size = 0,
12                 },
13                 .txmode = {
14                         .mq_mode = ETH_MQ_TX_NONE,
15                 },
16         };
17         uint16_t nb_ports_available = 0;
18         uint16_t port_id;
19         int ret;
20
21         /* Initialise each port */
22         RTE_ETH_FOREACH_DEV(port_id) {
23                 struct rte_eth_conf local_port_conf = port_conf;
24                 struct rte_eth_dev_info dev_info;
25                 struct rte_eth_rxconf rxq_conf;
26                 struct rte_eth_txconf txq_conf;
27
28                 /* skip ports that are not enabled */
29                 if ((rsrc->enabled_port_mask & (1 << port_id)) == 0) {
30                         printf("Skipping disabled port %u\n", port_id);
31                         continue;
32                 }
33                 nb_ports_available++;
34
35                 /* init port */
36                 printf("Initializing port %u... ", port_id);
37                 fflush(stdout);
38                 rte_eth_dev_info_get(port_id, &dev_info);
39                 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
40                         local_port_conf.txmode.offloads |=
41                                 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
42                 ret = rte_eth_dev_configure(port_id, 1, 1, &local_port_conf);
43                 if (ret < 0)
44                         rte_panic("Cannot configure device: err=%d, port=%u\n",
45                                   ret, port_id);
46
47                 ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_id, &nb_rxd,
48                                                        &nb_txd);
49                 if (ret < 0)
50                         rte_panic("Cannot adjust number of descriptors: err=%d, port=%u\n",
51                                   ret, port_id);
52
53                 rte_eth_macaddr_get(port_id, &rsrc->eth_addr[port_id]);
54
55                 /* init one RX queue */
56                 fflush(stdout);
57                 rxq_conf = dev_info.default_rxconf;
58                 rxq_conf.offloads = local_port_conf.rxmode.offloads;
59                 ret = rte_eth_rx_queue_setup(port_id, 0, nb_rxd,
60                                              rte_eth_dev_socket_id(port_id),
61                                              &rxq_conf,
62                                              rsrc->pktmbuf_pool);
63                 if (ret < 0)
64                         rte_panic("rte_eth_rx_queue_setup:err=%d, port=%u\n",
65                                   ret, port_id);
66
67                 /* init one TX queue on each port */
68                 fflush(stdout);
69                 txq_conf = dev_info.default_txconf;
70                 txq_conf.offloads = local_port_conf.txmode.offloads;
71                 ret = rte_eth_tx_queue_setup(port_id, 0, nb_txd,
72                                 rte_eth_dev_socket_id(port_id),
73                                 &txq_conf);
74                 if (ret < 0)
75                         rte_panic("rte_eth_tx_queue_setup:err=%d, port=%u\n",
76                                   ret, port_id);
77
78                 rte_eth_promiscuous_enable(port_id);
79
80                 printf("Port %u,MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
81                         port_id,
82                         rsrc->eth_addr[port_id].addr_bytes[0],
83                         rsrc->eth_addr[port_id].addr_bytes[1],
84                         rsrc->eth_addr[port_id].addr_bytes[2],
85                         rsrc->eth_addr[port_id].addr_bytes[3],
86                         rsrc->eth_addr[port_id].addr_bytes[4],
87                         rsrc->eth_addr[port_id].addr_bytes[5]);
88         }
89
90         return nb_ports_available;
91 }