DPDK  19.11.1
examples/l2fwd-event/l2fwd_common.c
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(C) 2019 Marvell International Ltd.
*/
#include "l2fwd_common.h"
int
l2fwd_event_init_ports(struct l2fwd_resources *rsrc)
{
uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
struct rte_eth_conf port_conf = {
.rxmode = {
.split_hdr_size = 0,
},
.txmode = {
.mq_mode = ETH_MQ_TX_NONE,
},
};
uint16_t nb_ports_available = 0;
uint16_t port_id;
int ret;
if (rsrc->event_mode) {
port_conf.rx_adv_conf.rss_conf.rss_key = NULL;
port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_IP;
}
/* Initialise each port */
struct rte_eth_conf local_port_conf = port_conf;
struct rte_eth_dev_info dev_info;
struct rte_eth_rxconf rxq_conf;
struct rte_eth_txconf txq_conf;
/* skip ports that are not enabled */
if ((rsrc->enabled_port_mask & (1 << port_id)) == 0) {
printf("Skipping disabled port %u\n", port_id);
continue;
}
nb_ports_available++;
/* init port */
printf("Initializing port %u... ", port_id);
fflush(stdout);
ret = rte_eth_dev_info_get(port_id, &dev_info);
if (ret != 0)
rte_panic("Error during getting device (port %u) info: %s\n",
port_id, strerror(-ret));
local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
if (local_port_conf.rx_adv_conf.rss_conf.rss_hf !=
printf("Port %u modified RSS hash function based on hardware support,"
"requested:%#"PRIx64" configured:%#"PRIx64"",
port_id,
local_port_conf.rx_adv_conf.rss_conf.rss_hf);
}
local_port_conf.txmode.offloads |=
ret = rte_eth_dev_configure(port_id, 1, 1, &local_port_conf);
if (ret < 0)
rte_panic("Cannot configure device: err=%d, port=%u\n",
ret, port_id);
ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_id, &nb_rxd,
&nb_txd);
if (ret < 0)
rte_panic("Cannot adjust number of descriptors: err=%d, port=%u\n",
ret, port_id);
rte_eth_macaddr_get(port_id, &rsrc->eth_addr[port_id]);
/* init one RX queue */
fflush(stdout);
rxq_conf = dev_info.default_rxconf;
rxq_conf.offloads = local_port_conf.rxmode.offloads;
ret = rte_eth_rx_queue_setup(port_id, 0, nb_rxd,
&rxq_conf,
rsrc->pktmbuf_pool);
if (ret < 0)
rte_panic("rte_eth_rx_queue_setup:err=%d, port=%u\n",
ret, port_id);
/* init one TX queue on each port */
fflush(stdout);
txq_conf = dev_info.default_txconf;
txq_conf.offloads = local_port_conf.txmode.offloads;
ret = rte_eth_tx_queue_setup(port_id, 0, nb_txd,
&txq_conf);
if (ret < 0)
rte_panic("rte_eth_tx_queue_setup:err=%d, port=%u\n",
ret, port_id);
printf("Port %u,MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
port_id,
rsrc->eth_addr[port_id].addr_bytes[0],
rsrc->eth_addr[port_id].addr_bytes[1],
rsrc->eth_addr[port_id].addr_bytes[2],
rsrc->eth_addr[port_id].addr_bytes[3],
rsrc->eth_addr[port_id].addr_bytes[4],
rsrc->eth_addr[port_id].addr_bytes[5]);
}
return nb_ports_available;
}
rte_eth_dev_adjust_nb_rx_tx_desc
int rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id, uint16_t *nb_rx_desc, uint16_t *nb_tx_desc)
rte_eth_rxconf
Definition: rte_ethdev.h:818
ETH_MQ_TX_NONE
@ ETH_MQ_TX_NONE
Definition: rte_ethdev.h:378
rte_eth_tx_queue_setup
int rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id, uint16_t nb_tx_desc, unsigned int socket_id, const struct rte_eth_txconf *tx_conf)
rte_eth_txconf
Definition: rte_ethdev.h:837
rte_eth_dev_configure
int rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_queue, uint16_t nb_tx_queue, const struct rte_eth_conf *eth_conf)
rte_eth_rxmode::max_rx_pkt_len
uint32_t max_rx_pkt_len
Definition: rte_ethdev.h:397
rte_eth_conf::rxmode
struct rte_eth_rxmode rxmode
Definition: rte_ethdev.h:1053
rte_eth_rxmode::mq_mode
enum rte_eth_rx_mq_mode mq_mode
Definition: rte_ethdev.h:396
rte_eth_conf::rx_adv_conf
struct rte_eth_conf::@137 rx_adv_conf
rte_eth_dev_info_get
int rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
rte_eth_promiscuous_enable
int rte_eth_promiscuous_enable(uint16_t port_id)
rte_eth_macaddr_get
int rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
DEV_TX_OFFLOAD_MBUF_FAST_FREE
#define DEV_TX_OFFLOAD_MBUF_FAST_FREE
Definition: rte_ethdev.h:1143
rte_eth_txconf::offloads
uint64_t offloads
Definition: rte_ethdev.h:849
rte_eth_rss_conf::rss_hf
uint64_t rss_hf
Definition: rte_ethdev.h:451
rte_eth_rxconf::offloads
uint64_t offloads
Definition: rte_ethdev.h:828
rte_eth_txmode::offloads
uint64_t offloads
Definition: rte_ethdev.h:799
rte_panic
#define rte_panic(...)
Definition: rte_debug.h:50
rte_eth_rxmode::offloads
uint64_t offloads
Definition: rte_ethdev.h:406
rte_eth_dev_info::flow_type_rss_offloads
uint64_t flow_type_rss_offloads
Definition: rte_ethdev.h:1257
rte_eth_rx_queue_setup
int rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id, uint16_t nb_rx_desc, unsigned int socket_id, const struct rte_eth_rxconf *rx_conf, struct rte_mempool *mb_pool)
rte_eth_conf::rss_conf
struct rte_eth_rss_conf rss_conf
Definition: rte_ethdev.h:1061
rte_eth_dev_info::default_rxconf
struct rte_eth_rxconf default_rxconf
Definition: rte_ethdev.h:1258
rte_eth_conf::txmode
struct rte_eth_txmode txmode
Definition: rte_ethdev.h:1054
rte_eth_rss_conf::rss_key
uint8_t * rss_key
Definition: rte_ethdev.h:449
rte_eth_dev_info::default_txconf
struct rte_eth_txconf default_txconf
Definition: rte_ethdev.h:1259
rte_eth_dev_info::tx_offload_capa
uint64_t tx_offload_capa
Definition: rte_ethdev.h:1247
rte_eth_dev_info
Definition: rte_ethdev.h:1226
RTE_ETH_FOREACH_DEV
#define RTE_ETH_FOREACH_DEV(p)
Definition: rte_ethdev.h:1546
rte_eth_conf
Definition: rte_ethdev.h:1045
rte_eth_dev_socket_id
int rte_eth_dev_socket_id(uint16_t port_id)
ETH_MQ_RX_RSS
@ ETH_MQ_RX_RSS
Definition: rte_ethdev.h:349
RTE_ETHER_MAX_LEN
#define RTE_ETHER_MAX_LEN
Definition: rte_ether.h:33