DPDK 22.11.5
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 = RX_DESC_DEFAULT;
uint16_t nb_txd = TX_DESC_DEFAULT;
struct rte_eth_conf port_conf = {
.txmode = {
},
};
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 = RTE_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 |=
/* Configure RX and TX queue. 8< */
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);
/* >8 End of configuration RX and TX queue. */
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;
/* Using lcore to poll one or several ports. 8< */
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);
/* >8 End of using lcore to poll one or several ports. */
/* Init one TX queue on each port. 8< */
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);
/* >8 End of init one TX queue on each port. */
printf("Port %u,MAC address: " RTE_ETHER_ADDR_PRT_FMT "\n\n",
port_id,
RTE_ETHER_ADDR_BYTES(&rsrc->eth_addr[port_id]));
}
return nb_ports_available;
}
static void
l2fwd_event_vector_array_free(struct rte_event events[], uint16_t num)
{
uint16_t i;
for (i = 0; i < num; i++) {
&events[i].vec->mbufs[events[i].vec->elem_offset],
events[i].vec->nb_elem);
events[i].vec);
}
}
static void
l2fwd_event_port_flush(uint8_t event_d_id __rte_unused, struct rte_event ev,
void *args __rte_unused)
{
l2fwd_event_vector_array_free(&ev, 1);
else
}
void
l2fwd_event_worker_cleanup(uint8_t event_d_id, uint8_t port_id,
struct rte_event events[], uint16_t nb_enq,
uint16_t nb_deq, uint8_t is_vector)
{
int i;
if (nb_deq) {
if (is_vector)
l2fwd_event_vector_array_free(events + nb_enq,
nb_deq - nb_enq);
else
for (i = nb_enq; i < nb_deq; i++)
rte_pktmbuf_free(events[i].mbuf);
for (i = 0; i < nb_deq; i++)
events[i].op = RTE_EVENT_OP_RELEASE;
rte_event_enqueue_burst(event_d_id, port_id, events, nb_deq);
}
rte_event_port_quiesce(event_d_id, port_id, l2fwd_event_port_flush,
NULL);
}
#define __rte_unused
Definition: rte_common.h:120
#define rte_panic(...)
Definition: rte_debug.h:43
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)
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)
#define RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
Definition: rte_ethdev.h:1561
@ RTE_ETH_MQ_TX_NONE
Definition: rte_ethdev.h:401
@ RTE_ETH_MQ_RX_RSS
Definition: rte_ethdev.h:379
int rte_eth_promiscuous_enable(uint16_t port_id)
int rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
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)
int rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
int rte_eth_dev_socket_id(uint16_t port_id)
int rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id, uint16_t *nb_rx_desc, uint16_t *nb_tx_desc)
#define RTE_ETH_FOREACH_DEV(p)
Definition: rte_ethdev.h:2086
#define RTE_ETHER_ADDR_PRT_FMT
Definition: rte_ether.h:241
#define RTE_ETHER_ADDR_BYTES(mac_addrs)
Definition: rte_ether.h:245
#define RTE_EVENT_TYPE_VECTOR
#define RTE_EVENT_OP_RELEASE
__rte_experimental void rte_event_port_quiesce(uint8_t dev_id, uint8_t port_id, rte_eventdev_port_flush_t release_cb, void *args)
static uint16_t rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id, const struct rte_event ev[], uint16_t nb_events)
static void rte_pktmbuf_free(struct rte_mbuf *m)
Definition: rte_mbuf.h:1410
void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count)
static struct rte_mempool * rte_mempool_from_obj(void *obj)
Definition: rte_mempool.h:382
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1477
struct rte_eth_txmode txmode
Definition: rte_ethdev.h:1463
struct rte_eth_rxmode rxmode
Definition: rte_ethdev.h:1462
struct rte_eth_rss_conf rss_conf
Definition: rte_ethdev.h:1470
struct rte_eth_conf::@115 rx_adv_conf
struct rte_eth_txconf default_txconf
Definition: rte_ethdev.h:1750
struct rte_eth_rxconf default_rxconf
Definition: rte_ethdev.h:1749
uint64_t flow_type_rss_offloads
Definition: rte_ethdev.h:1748
uint64_t tx_offload_capa
Definition: rte_ethdev.h:1739
uint8_t * rss_key
Definition: rte_ethdev.h:464
uint64_t rss_hf
Definition: rte_ethdev.h:466
uint64_t offloads
Definition: rte_ethdev.h:1095
uint64_t offloads
Definition: rte_ethdev.h:421
enum rte_eth_rx_mq_mode mq_mode
Definition: rte_ethdev.h:412
uint64_t offloads
Definition: rte_ethdev.h:1146
uint64_t offloads
Definition: rte_ethdev.h:968
enum rte_eth_tx_mq_mode mq_mode
Definition: rte_ethdev.h:962
uint32_t event_type
struct rte_mbuf * mbuf