2019-10-07 11:08:04 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2021-10-26 13:14:30 +00:00
|
|
|
* Copyright(c) 2019-2021 Intel Corporation
|
2019-10-07 11:08:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <rte_malloc.h>
|
|
|
|
#include <rte_ethdev.h>
|
2021-10-26 13:14:30 +00:00
|
|
|
#include <rte_dmadev.h>
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
/* size of ring used for software copying between rx and tx. */
|
2021-10-26 13:14:30 +00:00
|
|
|
#define RTE_LOGTYPE_DMA RTE_LOGTYPE_USER1
|
2019-10-07 11:08:04 +00:00
|
|
|
#define MAX_PKT_BURST 32
|
|
|
|
#define MEMPOOL_CACHE_SIZE 512
|
|
|
|
#define MIN_POOL_SIZE 65536U
|
|
|
|
#define CMD_LINE_OPT_MAC_UPDATING "mac-updating"
|
|
|
|
#define CMD_LINE_OPT_NO_MAC_UPDATING "no-mac-updating"
|
|
|
|
#define CMD_LINE_OPT_PORTMASK "portmask"
|
|
|
|
#define CMD_LINE_OPT_NB_QUEUE "nb-queue"
|
|
|
|
#define CMD_LINE_OPT_COPY_TYPE "copy-type"
|
|
|
|
#define CMD_LINE_OPT_RING_SIZE "ring-size"
|
2021-10-26 13:14:26 +00:00
|
|
|
#define CMD_LINE_OPT_BATCH_SIZE "dma-batch-size"
|
2021-10-26 13:14:27 +00:00
|
|
|
#define CMD_LINE_OPT_FRAME_SIZE "max-frame-size"
|
2021-10-26 13:14:28 +00:00
|
|
|
#define CMD_LINE_OPT_STATS_INTERVAL "stats-interval"
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
/* configurable number of RX/TX ring descriptors */
|
|
|
|
#define RX_DEFAULT_RINGSIZE 1024
|
|
|
|
#define TX_DEFAULT_RINGSIZE 1024
|
|
|
|
|
|
|
|
/* max number of RX queues per port */
|
|
|
|
#define MAX_RX_QUEUES_COUNT 8
|
|
|
|
|
|
|
|
struct rxtx_port_config {
|
|
|
|
/* common config */
|
|
|
|
uint16_t rxtx_port;
|
|
|
|
uint16_t nb_queues;
|
|
|
|
/* for software copy mode */
|
|
|
|
struct rte_ring *rx_to_tx_ring;
|
2021-10-26 13:14:30 +00:00
|
|
|
/* for dmadev HW copy mode */
|
|
|
|
uint16_t dmadev_ids[MAX_RX_QUEUES_COUNT];
|
2019-10-07 11:08:04 +00:00
|
|
|
};
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Configuring ports and number of assigned lcores in struct. 8< */
|
2019-10-07 11:08:04 +00:00
|
|
|
struct rxtx_transmission_config {
|
|
|
|
struct rxtx_port_config ports[RTE_MAX_ETHPORTS];
|
|
|
|
uint16_t nb_ports;
|
|
|
|
uint16_t nb_lcores;
|
|
|
|
};
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of configuration of ports and number of assigned lcores. */
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2019-10-07 11:08:08 +00:00
|
|
|
/* per-port statistics struct */
|
2021-10-26 13:14:31 +00:00
|
|
|
struct dma_port_statistics {
|
2019-10-07 11:08:08 +00:00
|
|
|
uint64_t rx[RTE_MAX_ETHPORTS];
|
|
|
|
uint64_t tx[RTE_MAX_ETHPORTS];
|
|
|
|
uint64_t tx_dropped[RTE_MAX_ETHPORTS];
|
|
|
|
uint64_t copy_dropped[RTE_MAX_ETHPORTS];
|
|
|
|
};
|
2021-10-26 13:14:31 +00:00
|
|
|
struct dma_port_statistics port_statistics;
|
2019-10-07 11:08:08 +00:00
|
|
|
struct total_statistics {
|
|
|
|
uint64_t total_packets_dropped;
|
|
|
|
uint64_t total_packets_tx;
|
|
|
|
uint64_t total_packets_rx;
|
2021-10-26 13:14:30 +00:00
|
|
|
uint64_t total_submitted;
|
|
|
|
uint64_t total_completed;
|
|
|
|
uint64_t total_failed;
|
2019-10-07 11:08:08 +00:00
|
|
|
};
|
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
typedef enum copy_mode_t {
|
|
|
|
#define COPY_MODE_SW "sw"
|
|
|
|
COPY_MODE_SW_NUM,
|
2021-10-26 13:14:31 +00:00
|
|
|
#define COPY_MODE_DMA "hw"
|
|
|
|
COPY_MODE_DMA_NUM,
|
2019-10-07 11:08:04 +00:00
|
|
|
COPY_MODE_INVALID_NUM,
|
|
|
|
COPY_MODE_SIZE_NUM = COPY_MODE_INVALID_NUM
|
|
|
|
} copy_mode_t;
|
|
|
|
|
|
|
|
/* mask of enabled ports */
|
2021-10-26 13:14:31 +00:00
|
|
|
static uint32_t dma_enabled_port_mask;
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
/* number of RX queues per port */
|
|
|
|
static uint16_t nb_queues = 1;
|
|
|
|
|
|
|
|
/* MAC updating enabled by default. */
|
|
|
|
static int mac_updating = 1;
|
|
|
|
|
|
|
|
/* hardare copy mode enabled by default. */
|
2021-10-26 13:14:31 +00:00
|
|
|
static copy_mode_t copy_mode = COPY_MODE_DMA_NUM;
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
/* size of descriptor ring for hardware copy mode or
|
2019-10-07 11:08:04 +00:00
|
|
|
* rte_ring for software copy mode
|
|
|
|
*/
|
|
|
|
static unsigned short ring_size = 2048;
|
|
|
|
|
2021-10-26 13:14:28 +00:00
|
|
|
/* interval, in seconds, between stats prints */
|
|
|
|
static unsigned short stats_interval = 1;
|
2021-10-26 13:14:30 +00:00
|
|
|
/* global mbuf arrays for tracking DMA bufs */
|
|
|
|
#define MBUF_RING_SIZE 2048
|
|
|
|
#define MBUF_RING_MASK (MBUF_RING_SIZE - 1)
|
|
|
|
struct dma_bufs {
|
|
|
|
struct rte_mbuf *bufs[MBUF_RING_SIZE];
|
|
|
|
struct rte_mbuf *copies[MBUF_RING_SIZE];
|
|
|
|
uint16_t sent;
|
|
|
|
};
|
|
|
|
static struct dma_bufs dma_bufs[RTE_DMADEV_DEFAULT_MAX];
|
2021-10-26 13:14:28 +00:00
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
/* global transmission config */
|
|
|
|
struct rxtx_transmission_config cfg;
|
|
|
|
|
|
|
|
/* configurable number of RX/TX ring descriptors */
|
|
|
|
static uint16_t nb_rxd = RX_DEFAULT_RINGSIZE;
|
|
|
|
static uint16_t nb_txd = TX_DEFAULT_RINGSIZE;
|
|
|
|
|
|
|
|
static volatile bool force_quit;
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
static uint32_t dma_batch_sz = MAX_PKT_BURST;
|
2021-10-26 13:14:27 +00:00
|
|
|
static uint32_t max_frame_size = RTE_ETHER_MAX_LEN;
|
2021-10-26 13:14:26 +00:00
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
/* ethernet addresses of ports */
|
2021-10-26 13:14:31 +00:00
|
|
|
static struct rte_ether_addr dma_ports_eth_addr[RTE_MAX_ETHPORTS];
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
static struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS];
|
2021-10-26 13:14:31 +00:00
|
|
|
struct rte_mempool *dma_pktmbuf_pool;
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2019-10-07 11:08:08 +00:00
|
|
|
/* Print out statistics for one port. */
|
|
|
|
static void
|
|
|
|
print_port_stats(uint16_t port_id)
|
|
|
|
{
|
|
|
|
printf("\nStatistics for port %u ------------------------------"
|
|
|
|
"\nPackets sent: %34"PRIu64
|
|
|
|
"\nPackets received: %30"PRIu64
|
|
|
|
"\nPackets dropped on tx: %25"PRIu64
|
|
|
|
"\nPackets dropped on copy: %23"PRIu64,
|
|
|
|
port_id,
|
|
|
|
port_statistics.tx[port_id],
|
|
|
|
port_statistics.rx[port_id],
|
|
|
|
port_statistics.tx_dropped[port_id],
|
|
|
|
port_statistics.copy_dropped[port_id]);
|
|
|
|
}
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
/* Print out statistics for one dmadev device. */
|
2019-10-07 11:08:08 +00:00
|
|
|
static void
|
2021-10-26 13:14:30 +00:00
|
|
|
print_dmadev_stats(uint32_t dev_id, struct rte_dma_stats stats)
|
2019-10-07 11:08:08 +00:00
|
|
|
{
|
2021-10-26 13:14:30 +00:00
|
|
|
printf("\nDMA channel %u", dev_id);
|
|
|
|
printf("\n\t Total submitted ops: %"PRIu64"", stats.submitted);
|
|
|
|
printf("\n\t Total completed ops: %"PRIu64"", stats.completed);
|
|
|
|
printf("\n\t Total failed ops: %"PRIu64"", stats.errors);
|
2019-10-07 11:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_total_stats(struct total_statistics *ts)
|
|
|
|
{
|
|
|
|
printf("\nAggregate statistics ==============================="
|
2021-10-26 13:14:30 +00:00
|
|
|
"\nTotal packets Tx: %22"PRIu64" [pkt/s]"
|
|
|
|
"\nTotal packets Rx: %22"PRIu64" [pkt/s]"
|
|
|
|
"\nTotal packets dropped: %17"PRIu64" [pkt/s]",
|
2021-10-26 13:14:28 +00:00
|
|
|
ts->total_packets_tx / stats_interval,
|
|
|
|
ts->total_packets_rx / stats_interval,
|
|
|
|
ts->total_packets_dropped / stats_interval);
|
2019-10-07 11:08:08 +00:00
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
if (copy_mode == COPY_MODE_DMA_NUM) {
|
2021-10-26 13:14:30 +00:00
|
|
|
printf("\nTotal submitted ops: %19"PRIu64" [ops/s]"
|
|
|
|
"\nTotal completed ops: %19"PRIu64" [ops/s]"
|
|
|
|
"\nTotal failed ops: %22"PRIu64" [ops/s]",
|
|
|
|
ts->total_submitted / stats_interval,
|
|
|
|
ts->total_completed / stats_interval,
|
|
|
|
ts->total_failed / stats_interval);
|
2019-10-07 11:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n====================================================\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out statistics on packets dropped. */
|
|
|
|
static void
|
|
|
|
print_stats(char *prgname)
|
|
|
|
{
|
|
|
|
struct total_statistics ts, delta_ts;
|
2021-10-26 13:14:30 +00:00
|
|
|
struct rte_dma_stats stats = {0};
|
2019-10-07 11:08:08 +00:00
|
|
|
uint32_t i, port_id, dev_id;
|
2020-09-17 13:07:40 +00:00
|
|
|
char status_string[255]; /* to print at the top of the output */
|
2019-10-07 11:08:08 +00:00
|
|
|
int status_strlen;
|
|
|
|
|
|
|
|
const char clr[] = { 27, '[', '2', 'J', '\0' };
|
|
|
|
const char topLeft[] = { 27, '[', '1', ';', '1', 'H', '\0' };
|
|
|
|
|
|
|
|
status_strlen = snprintf(status_string, sizeof(status_string),
|
|
|
|
"%s, ", prgname);
|
|
|
|
status_strlen += snprintf(status_string + status_strlen,
|
|
|
|
sizeof(status_string) - status_strlen,
|
|
|
|
"Worker Threads = %d, ",
|
|
|
|
rte_lcore_count() > 2 ? 2 : 1);
|
|
|
|
status_strlen += snprintf(status_string + status_strlen,
|
|
|
|
sizeof(status_string) - status_strlen,
|
|
|
|
"Copy Mode = %s,\n", copy_mode == COPY_MODE_SW_NUM ?
|
2021-10-26 13:14:31 +00:00
|
|
|
COPY_MODE_SW : COPY_MODE_DMA);
|
2019-10-07 11:08:08 +00:00
|
|
|
status_strlen += snprintf(status_string + status_strlen,
|
|
|
|
sizeof(status_string) - status_strlen,
|
|
|
|
"Updating MAC = %s, ", mac_updating ?
|
|
|
|
"enabled" : "disabled");
|
|
|
|
status_strlen += snprintf(status_string + status_strlen,
|
|
|
|
sizeof(status_string) - status_strlen,
|
|
|
|
"Rx Queues = %d, ", nb_queues);
|
|
|
|
status_strlen += snprintf(status_string + status_strlen,
|
|
|
|
sizeof(status_string) - status_strlen,
|
2020-09-17 13:07:40 +00:00
|
|
|
"Ring Size = %d", ring_size);
|
2019-10-07 11:08:08 +00:00
|
|
|
|
|
|
|
memset(&ts, 0, sizeof(struct total_statistics));
|
|
|
|
|
|
|
|
while (!force_quit) {
|
2021-10-26 13:14:28 +00:00
|
|
|
/* Sleep for "stats_interval" seconds each round - init sleep allows reading
|
2019-10-07 11:08:08 +00:00
|
|
|
* messages from app startup.
|
|
|
|
*/
|
2021-10-26 13:14:28 +00:00
|
|
|
sleep(stats_interval);
|
2019-10-07 11:08:08 +00:00
|
|
|
|
|
|
|
/* Clear screen and move to top left */
|
|
|
|
printf("%s%s", clr, topLeft);
|
|
|
|
|
|
|
|
memset(&delta_ts, 0, sizeof(struct total_statistics));
|
|
|
|
|
2020-09-17 13:07:40 +00:00
|
|
|
printf("%s\n", status_string);
|
2019-10-07 11:08:08 +00:00
|
|
|
|
|
|
|
for (i = 0; i < cfg.nb_ports; i++) {
|
|
|
|
port_id = cfg.ports[i].rxtx_port;
|
|
|
|
print_port_stats(port_id);
|
|
|
|
|
|
|
|
delta_ts.total_packets_dropped +=
|
|
|
|
port_statistics.tx_dropped[port_id]
|
|
|
|
+ port_statistics.copy_dropped[port_id];
|
|
|
|
delta_ts.total_packets_tx +=
|
|
|
|
port_statistics.tx[port_id];
|
|
|
|
delta_ts.total_packets_rx +=
|
|
|
|
port_statistics.rx[port_id];
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
if (copy_mode == COPY_MODE_DMA_NUM) {
|
2019-10-07 11:08:08 +00:00
|
|
|
uint32_t j;
|
|
|
|
|
|
|
|
for (j = 0; j < cfg.ports[i].nb_queues; j++) {
|
2021-10-26 13:14:30 +00:00
|
|
|
dev_id = cfg.ports[i].dmadev_ids[j];
|
|
|
|
rte_dma_stats_get(dev_id, 0, &stats);
|
|
|
|
print_dmadev_stats(dev_id, stats);
|
2019-10-07 11:08:08 +00:00
|
|
|
|
2021-10-26 13:14:30 +00:00
|
|
|
delta_ts.total_submitted += stats.submitted;
|
|
|
|
delta_ts.total_completed += stats.completed;
|
|
|
|
delta_ts.total_failed += stats.errors;
|
2019-10-07 11:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delta_ts.total_packets_tx -= ts.total_packets_tx;
|
|
|
|
delta_ts.total_packets_rx -= ts.total_packets_rx;
|
|
|
|
delta_ts.total_packets_dropped -= ts.total_packets_dropped;
|
2021-10-26 13:14:30 +00:00
|
|
|
delta_ts.total_submitted -= ts.total_submitted;
|
|
|
|
delta_ts.total_completed -= ts.total_completed;
|
|
|
|
delta_ts.total_failed -= ts.total_failed;
|
2019-10-07 11:08:08 +00:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
print_total_stats(&delta_ts);
|
|
|
|
|
2020-04-28 13:27:41 +00:00
|
|
|
fflush(stdout);
|
|
|
|
|
2019-10-07 11:08:08 +00:00
|
|
|
ts.total_packets_tx += delta_ts.total_packets_tx;
|
|
|
|
ts.total_packets_rx += delta_ts.total_packets_rx;
|
|
|
|
ts.total_packets_dropped += delta_ts.total_packets_dropped;
|
2021-10-26 13:14:30 +00:00
|
|
|
ts.total_submitted += delta_ts.total_submitted;
|
|
|
|
ts.total_completed += delta_ts.total_completed;
|
|
|
|
ts.total_failed += delta_ts.total_failed;
|
2019-10-07 11:08:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 11:08:05 +00:00
|
|
|
static void
|
|
|
|
update_mac_addrs(struct rte_mbuf *m, uint32_t dest_portid)
|
|
|
|
{
|
|
|
|
struct rte_ether_hdr *eth;
|
|
|
|
void *tmp;
|
|
|
|
|
|
|
|
eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
|
|
|
|
|
|
|
|
/* 02:00:00:00:00:xx - overwriting 2 bytes of source address but
|
|
|
|
* it's acceptable cause it gets overwritten by rte_ether_addr_copy
|
|
|
|
*/
|
2021-10-07 22:07:49 +00:00
|
|
|
tmp = ð->dst_addr.addr_bytes[0];
|
2019-10-07 11:08:05 +00:00
|
|
|
*((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dest_portid << 40);
|
|
|
|
|
|
|
|
/* src addr */
|
2021-10-26 13:14:31 +00:00
|
|
|
rte_ether_addr_copy(&dma_ports_eth_addr[dest_portid], ð->src_addr);
|
2019-10-07 11:08:05 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Perform packet copy there is a user-defined function. 8< */
|
2019-10-07 11:08:05 +00:00
|
|
|
static inline void
|
2021-10-26 13:14:25 +00:00
|
|
|
pktmbuf_metadata_copy(const struct rte_mbuf *src, struct rte_mbuf *dst)
|
2019-10-07 11:08:05 +00:00
|
|
|
{
|
2021-10-26 13:14:25 +00:00
|
|
|
dst->data_off = src->data_off;
|
|
|
|
memcpy(&dst->rx_descriptor_fields1, &src->rx_descriptor_fields1,
|
|
|
|
offsetof(struct rte_mbuf, buf_len) -
|
|
|
|
offsetof(struct rte_mbuf, rx_descriptor_fields1));
|
|
|
|
}
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
/* Copy packet data */
|
|
|
|
static inline void
|
|
|
|
pktmbuf_sw_copy(struct rte_mbuf *src, struct rte_mbuf *dst)
|
|
|
|
{
|
2019-10-07 11:08:05 +00:00
|
|
|
rte_memcpy(rte_pktmbuf_mtod(dst, char *),
|
|
|
|
rte_pktmbuf_mtod(src, char *), src->data_len);
|
|
|
|
}
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of perform packet copy there is a user-defined function. */
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2019-10-07 11:08:06 +00:00
|
|
|
static uint32_t
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_enqueue_packets(struct rte_mbuf *pkts[], struct rte_mbuf *pkts_copy[],
|
2019-10-07 11:08:06 +00:00
|
|
|
uint32_t nb_rx, uint16_t dev_id)
|
|
|
|
{
|
2021-10-26 13:14:30 +00:00
|
|
|
struct dma_bufs *dma = &dma_bufs[dev_id];
|
2019-10-07 11:08:06 +00:00
|
|
|
int ret;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_rx; i++) {
|
|
|
|
/* Perform data copy */
|
2021-10-26 13:14:30 +00:00
|
|
|
ret = rte_dma_copy(dev_id, 0,
|
2021-10-26 13:14:25 +00:00
|
|
|
rte_pktmbuf_iova(pkts[i]),
|
|
|
|
rte_pktmbuf_iova(pkts_copy[i]),
|
2021-10-26 13:14:30 +00:00
|
|
|
rte_pktmbuf_data_len(pkts[i]), 0);
|
2019-10-07 11:08:06 +00:00
|
|
|
|
2021-10-26 13:14:30 +00:00
|
|
|
if (ret < 0)
|
2019-10-07 11:08:06 +00:00
|
|
|
break;
|
2021-10-26 13:14:30 +00:00
|
|
|
|
|
|
|
dma->bufs[ret & MBUF_RING_MASK] = pkts[i];
|
|
|
|
dma->copies[ret & MBUF_RING_MASK] = pkts_copy[i];
|
2019-10-07 11:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = i;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
static inline uint32_t
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_enqueue(struct rte_mbuf *pkts[], struct rte_mbuf *pkts_copy[],
|
2021-10-26 13:14:26 +00:00
|
|
|
uint32_t num, uint32_t step, uint16_t dev_id)
|
2021-10-26 13:14:25 +00:00
|
|
|
{
|
2021-10-26 13:14:26 +00:00
|
|
|
uint32_t i, k, m, n;
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
for (i = 0; i < num; i += m) {
|
|
|
|
|
|
|
|
m = RTE_MIN(step, num - i);
|
2021-10-26 13:14:31 +00:00
|
|
|
n = dma_enqueue_packets(pkts + i, pkts_copy + i, m, dev_id);
|
2021-10-26 13:14:26 +00:00
|
|
|
k += n;
|
|
|
|
if (n > 0)
|
2021-10-26 13:14:30 +00:00
|
|
|
rte_dma_submit(dev_id, 0);
|
2021-10-26 13:14:25 +00:00
|
|
|
|
2021-10-26 13:14:26 +00:00
|
|
|
/* don't try to enqueue more if HW queue is full */
|
|
|
|
if (n != m)
|
|
|
|
break;
|
|
|
|
}
|
2021-10-26 13:14:25 +00:00
|
|
|
|
2021-10-26 13:14:26 +00:00
|
|
|
return k;
|
2021-10-26 13:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_dequeue(struct rte_mbuf *src[], struct rte_mbuf *dst[], uint32_t num,
|
2021-10-26 13:14:25 +00:00
|
|
|
uint16_t dev_id)
|
|
|
|
{
|
2021-10-26 13:14:30 +00:00
|
|
|
struct dma_bufs *dma = &dma_bufs[dev_id];
|
|
|
|
uint16_t nb_dq, filled;
|
2021-10-26 13:14:31 +00:00
|
|
|
/* Dequeue the mbufs from DMA device. Since all memory
|
2021-10-26 13:14:25 +00:00
|
|
|
* is DPDK pinned memory and therefore all addresses should
|
|
|
|
* be valid, we don't check for copy errors
|
|
|
|
*/
|
2021-10-26 13:14:30 +00:00
|
|
|
nb_dq = rte_dma_completed(dev_id, 0, num, NULL, NULL);
|
|
|
|
|
|
|
|
/* Return early if no work to do */
|
|
|
|
if (unlikely(nb_dq == 0))
|
|
|
|
return nb_dq;
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
/* Populate pkts_copy with the copies bufs from dma->copies for tx */
|
2021-10-26 13:14:30 +00:00
|
|
|
for (filled = 0; filled < nb_dq; filled++) {
|
|
|
|
src[filled] = dma->bufs[(dma->sent + filled) & MBUF_RING_MASK];
|
|
|
|
dst[filled] = dma->copies[(dma->sent + filled) & MBUF_RING_MASK];
|
2021-10-26 13:14:25 +00:00
|
|
|
}
|
2021-10-26 13:14:30 +00:00
|
|
|
dma->sent += nb_dq;
|
|
|
|
|
|
|
|
return filled;
|
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
/* Receive packets on one port and enqueue to dmadev or rte_ring. 8< */
|
2019-10-07 11:08:05 +00:00
|
|
|
static void
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_rx_port(struct rxtx_port_config *rx_config)
|
2019-10-07 11:08:05 +00:00
|
|
|
{
|
2021-10-26 13:14:25 +00:00
|
|
|
int32_t ret;
|
2019-10-07 11:08:05 +00:00
|
|
|
uint32_t nb_rx, nb_enq, i, j;
|
|
|
|
struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
|
2021-10-26 13:14:25 +00:00
|
|
|
struct rte_mbuf *pkts_burst_copy[MAX_PKT_BURST];
|
2019-10-07 11:08:05 +00:00
|
|
|
|
|
|
|
for (i = 0; i < rx_config->nb_queues; i++) {
|
|
|
|
|
|
|
|
nb_rx = rte_eth_rx_burst(rx_config->rxtx_port, i,
|
|
|
|
pkts_burst, MAX_PKT_BURST);
|
|
|
|
|
|
|
|
if (nb_rx == 0)
|
|
|
|
continue;
|
|
|
|
|
2019-10-07 11:08:08 +00:00
|
|
|
port_statistics.rx[rx_config->rxtx_port] += nb_rx;
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
ret = rte_mempool_get_bulk(dma_pktmbuf_pool,
|
2021-10-26 13:14:25 +00:00
|
|
|
(void *)pkts_burst_copy, nb_rx);
|
|
|
|
|
|
|
|
if (unlikely(ret < 0))
|
|
|
|
rte_exit(EXIT_FAILURE,
|
|
|
|
"Unable to allocate memory.\n");
|
|
|
|
|
|
|
|
for (j = 0; j < nb_rx; j++)
|
|
|
|
pktmbuf_metadata_copy(pkts_burst[j],
|
|
|
|
pkts_burst_copy[j]);
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
if (copy_mode == COPY_MODE_DMA_NUM) {
|
2021-10-26 13:14:25 +00:00
|
|
|
/* enqueue packets for hardware copy */
|
2021-10-26 13:14:31 +00:00
|
|
|
nb_enq = dma_enqueue(pkts_burst, pkts_burst_copy,
|
|
|
|
nb_rx, dma_batch_sz, rx_config->dmadev_ids[i]);
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
/* free any not enqueued packets. */
|
2021-10-26 13:14:31 +00:00
|
|
|
rte_mempool_put_bulk(dma_pktmbuf_pool,
|
2021-10-26 13:14:25 +00:00
|
|
|
(void *)&pkts_burst[nb_enq],
|
|
|
|
nb_rx - nb_enq);
|
2021-10-26 13:14:31 +00:00
|
|
|
rte_mempool_put_bulk(dma_pktmbuf_pool,
|
2021-10-26 13:14:25 +00:00
|
|
|
(void *)&pkts_burst_copy[nb_enq],
|
|
|
|
nb_rx - nb_enq);
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
port_statistics.copy_dropped[rx_config->rxtx_port] +=
|
|
|
|
(nb_rx - nb_enq);
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
/* get completed copies */
|
2021-10-26 13:14:31 +00:00
|
|
|
nb_rx = dma_dequeue(pkts_burst, pkts_burst_copy,
|
2021-10-26 13:14:30 +00:00
|
|
|
MAX_PKT_BURST, rx_config->dmadev_ids[i]);
|
2021-10-26 13:14:25 +00:00
|
|
|
} else {
|
|
|
|
/* Perform packet software copy, free source packets */
|
2019-10-07 11:08:05 +00:00
|
|
|
for (j = 0; j < nb_rx; j++)
|
|
|
|
pktmbuf_sw_copy(pkts_burst[j],
|
|
|
|
pkts_burst_copy[j]);
|
2021-10-26 13:14:25 +00:00
|
|
|
}
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
rte_mempool_put_bulk(dma_pktmbuf_pool,
|
2021-10-26 13:14:25 +00:00
|
|
|
(void *)pkts_burst, nb_rx);
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
nb_enq = rte_ring_enqueue_burst(rx_config->rx_to_tx_ring,
|
|
|
|
(void *)pkts_burst_copy, nb_rx, NULL);
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
/* Free any not enqueued packets. */
|
2021-10-26 13:14:31 +00:00
|
|
|
rte_mempool_put_bulk(dma_pktmbuf_pool,
|
2021-10-26 13:14:25 +00:00
|
|
|
(void *)&pkts_burst_copy[nb_enq],
|
|
|
|
nb_rx - nb_enq);
|
2019-10-07 11:08:08 +00:00
|
|
|
|
|
|
|
port_statistics.copy_dropped[rx_config->rxtx_port] +=
|
|
|
|
(nb_rx - nb_enq);
|
2019-10-07 11:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-26 13:14:31 +00:00
|
|
|
/* >8 End of receive packets on one port and enqueue to dmadev or rte_ring. */
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
/* Transmit packets from dmadev/rte_ring for one port. 8< */
|
2019-10-07 11:08:05 +00:00
|
|
|
static void
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_tx_port(struct rxtx_port_config *tx_config)
|
2019-10-07 11:08:05 +00:00
|
|
|
{
|
2021-10-26 13:14:25 +00:00
|
|
|
uint32_t i, j, nb_dq, nb_tx;
|
|
|
|
struct rte_mbuf *mbufs[MAX_PKT_BURST];
|
2019-10-07 11:08:05 +00:00
|
|
|
|
|
|
|
for (i = 0; i < tx_config->nb_queues; i++) {
|
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
/* Dequeue the mbufs from rx_to_tx_ring. */
|
|
|
|
nb_dq = rte_ring_dequeue_burst(tx_config->rx_to_tx_ring,
|
|
|
|
(void *)mbufs, MAX_PKT_BURST, NULL);
|
|
|
|
if (nb_dq == 0)
|
|
|
|
continue;
|
2019-10-07 11:08:06 +00:00
|
|
|
|
2019-10-07 11:08:05 +00:00
|
|
|
/* Update macs if enabled */
|
|
|
|
if (mac_updating) {
|
|
|
|
for (j = 0; j < nb_dq; j++)
|
2021-10-26 13:14:25 +00:00
|
|
|
update_mac_addrs(mbufs[j],
|
2019-10-07 11:08:05 +00:00
|
|
|
tx_config->rxtx_port);
|
|
|
|
}
|
|
|
|
|
2021-10-26 13:14:25 +00:00
|
|
|
nb_tx = rte_eth_tx_burst(tx_config->rxtx_port, 0,
|
|
|
|
(void *)mbufs, nb_dq);
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2019-10-07 11:08:08 +00:00
|
|
|
port_statistics.tx[tx_config->rxtx_port] += nb_tx;
|
|
|
|
|
2019-10-07 11:08:05 +00:00
|
|
|
/* Free any unsent packets. */
|
|
|
|
if (unlikely(nb_tx < nb_dq))
|
2021-10-26 13:14:31 +00:00
|
|
|
rte_mempool_put_bulk(dma_pktmbuf_pool,
|
2021-10-26 13:14:25 +00:00
|
|
|
(void *)&mbufs[nb_tx], nb_dq - nb_tx);
|
2019-10-07 11:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-26 13:14:31 +00:00
|
|
|
/* >8 End of transmitting packets from dmadev. */
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
/* Main rx processing loop for dmadev. */
|
2019-10-07 11:08:07 +00:00
|
|
|
static void
|
|
|
|
rx_main_loop(void)
|
|
|
|
{
|
|
|
|
uint16_t i;
|
|
|
|
uint16_t nb_ports = cfg.nb_ports;
|
|
|
|
|
2021-10-26 13:14:30 +00:00
|
|
|
RTE_LOG(INFO, DMA, "Entering main rx loop for copy on lcore %u\n",
|
2019-10-07 11:08:07 +00:00
|
|
|
rte_lcore_id());
|
|
|
|
|
|
|
|
while (!force_quit)
|
|
|
|
for (i = 0; i < nb_ports; i++)
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_rx_port(&cfg.ports[i]);
|
2019-10-07 11:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Main tx processing loop for hardware copy. */
|
|
|
|
static void
|
|
|
|
tx_main_loop(void)
|
|
|
|
{
|
|
|
|
uint16_t i;
|
|
|
|
uint16_t nb_ports = cfg.nb_ports;
|
|
|
|
|
2021-10-26 13:14:30 +00:00
|
|
|
RTE_LOG(INFO, DMA, "Entering main tx loop for copy on lcore %u\n",
|
2019-10-07 11:08:07 +00:00
|
|
|
rte_lcore_id());
|
|
|
|
|
|
|
|
while (!force_quit)
|
|
|
|
for (i = 0; i < nb_ports; i++)
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_tx_port(&cfg.ports[i]);
|
2019-10-07 11:08:07 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 22:57:19 +00:00
|
|
|
/* Main rx and tx loop if only one worker lcore available */
|
2019-10-07 11:08:05 +00:00
|
|
|
static void
|
|
|
|
rxtx_main_loop(void)
|
|
|
|
{
|
|
|
|
uint16_t i;
|
|
|
|
uint16_t nb_ports = cfg.nb_ports;
|
|
|
|
|
2021-10-26 13:14:30 +00:00
|
|
|
RTE_LOG(INFO, DMA, "Entering main rx and tx loop for copy on"
|
2019-10-07 11:08:05 +00:00
|
|
|
" lcore %u\n", rte_lcore_id());
|
|
|
|
|
|
|
|
while (!force_quit)
|
|
|
|
for (i = 0; i < nb_ports; i++) {
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_rx_port(&cfg.ports[i]);
|
|
|
|
dma_tx_port(&cfg.ports[i]);
|
2019-10-07 11:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Start processing for each lcore. 8< */
|
2019-10-07 11:08:05 +00:00
|
|
|
static void start_forwarding_cores(void)
|
|
|
|
{
|
|
|
|
uint32_t lcore_id = rte_lcore_id();
|
|
|
|
|
2021-10-26 13:14:30 +00:00
|
|
|
RTE_LOG(INFO, DMA, "Entering %s on lcore %u\n",
|
2019-10-07 11:08:05 +00:00
|
|
|
__func__, rte_lcore_id());
|
|
|
|
|
2019-10-07 11:08:07 +00:00
|
|
|
if (cfg.nb_lcores == 1) {
|
|
|
|
lcore_id = rte_get_next_lcore(lcore_id, true, true);
|
|
|
|
rte_eal_remote_launch((lcore_function_t *)rxtx_main_loop,
|
|
|
|
NULL, lcore_id);
|
|
|
|
} else if (cfg.nb_lcores > 1) {
|
|
|
|
lcore_id = rte_get_next_lcore(lcore_id, true, true);
|
|
|
|
rte_eal_remote_launch((lcore_function_t *)rx_main_loop,
|
|
|
|
NULL, lcore_id);
|
|
|
|
|
|
|
|
lcore_id = rte_get_next_lcore(lcore_id, true, true);
|
|
|
|
rte_eal_remote_launch((lcore_function_t *)tx_main_loop, NULL,
|
|
|
|
lcore_id);
|
|
|
|
}
|
2019-10-07 11:08:05 +00:00
|
|
|
}
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of starting to processfor each lcore. */
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
/* Display usage */
|
|
|
|
static void
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_usage(const char *prgname)
|
2019-10-07 11:08:04 +00:00
|
|
|
{
|
|
|
|
printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n"
|
2021-10-26 13:14:26 +00:00
|
|
|
" -b --dma-batch-size: number of requests per DMA batch\n"
|
2021-10-26 13:14:27 +00:00
|
|
|
" -f --max-frame-size: max frame size\n"
|
2019-10-07 11:08:04 +00:00
|
|
|
" -p --portmask: hexadecimal bitmask of ports to configure\n"
|
|
|
|
" -q NQ: number of RX queues per port (default is 1)\n"
|
|
|
|
" --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)\n"
|
|
|
|
" When enabled:\n"
|
|
|
|
" - The source MAC address is replaced by the TX port MAC address\n"
|
|
|
|
" - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n"
|
|
|
|
" -c --copy-type CT: type of copy: sw|hw\n"
|
2021-10-26 13:14:31 +00:00
|
|
|
" -s --ring-size RS: size of dmadev descriptor ring for hardware copy mode or rte_ring for software copy mode\n"
|
2021-10-26 13:14:28 +00:00
|
|
|
" -i --stats-interval SI: interval, in seconds, between stats prints (default is 1)\n",
|
2019-10-07 11:08:04 +00:00
|
|
|
prgname);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_parse_portmask(const char *portmask)
|
2019-10-07 11:08:04 +00:00
|
|
|
{
|
|
|
|
char *end = NULL;
|
|
|
|
unsigned long pm;
|
|
|
|
|
|
|
|
/* Parse hexadecimal string */
|
|
|
|
pm = strtoul(portmask, &end, 16);
|
|
|
|
if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
|
2020-06-11 12:36:24 +00:00
|
|
|
return 0;
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
return pm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static copy_mode_t
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_parse_copy_mode(const char *copy_mode)
|
2019-10-07 11:08:04 +00:00
|
|
|
{
|
|
|
|
if (strcmp(copy_mode, COPY_MODE_SW) == 0)
|
|
|
|
return COPY_MODE_SW_NUM;
|
2021-10-26 13:14:31 +00:00
|
|
|
else if (strcmp(copy_mode, COPY_MODE_DMA) == 0)
|
|
|
|
return COPY_MODE_DMA_NUM;
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
return COPY_MODE_INVALID_NUM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse the argument given in the command line of the application */
|
|
|
|
static int
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_parse_args(int argc, char **argv, unsigned int nb_ports)
|
2019-10-07 11:08:04 +00:00
|
|
|
{
|
|
|
|
static const char short_options[] =
|
2021-10-26 13:14:26 +00:00
|
|
|
"b:" /* dma batch size */
|
|
|
|
"c:" /* copy type (sw|hw) */
|
2021-10-26 13:14:27 +00:00
|
|
|
"f:" /* max frame size */
|
2019-10-07 11:08:04 +00:00
|
|
|
"p:" /* portmask */
|
|
|
|
"q:" /* number of RX queues per port */
|
|
|
|
"s:" /* ring size */
|
2021-10-26 13:14:28 +00:00
|
|
|
"i:" /* interval, in seconds, between stats prints */
|
2019-10-07 11:08:04 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
static const struct option lgopts[] = {
|
|
|
|
{CMD_LINE_OPT_MAC_UPDATING, no_argument, &mac_updating, 1},
|
|
|
|
{CMD_LINE_OPT_NO_MAC_UPDATING, no_argument, &mac_updating, 0},
|
|
|
|
{CMD_LINE_OPT_PORTMASK, required_argument, NULL, 'p'},
|
|
|
|
{CMD_LINE_OPT_NB_QUEUE, required_argument, NULL, 'q'},
|
|
|
|
{CMD_LINE_OPT_COPY_TYPE, required_argument, NULL, 'c'},
|
|
|
|
{CMD_LINE_OPT_RING_SIZE, required_argument, NULL, 's'},
|
2021-10-26 13:14:26 +00:00
|
|
|
{CMD_LINE_OPT_BATCH_SIZE, required_argument, NULL, 'b'},
|
2021-10-26 13:14:27 +00:00
|
|
|
{CMD_LINE_OPT_FRAME_SIZE, required_argument, NULL, 'f'},
|
2021-10-26 13:14:28 +00:00
|
|
|
{CMD_LINE_OPT_STATS_INTERVAL, required_argument, NULL, 'i'},
|
2019-10-07 11:08:04 +00:00
|
|
|
{NULL, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
const unsigned int default_port_mask = (1 << nb_ports) - 1;
|
|
|
|
int opt, ret;
|
|
|
|
char **argvopt;
|
|
|
|
int option_index;
|
|
|
|
char *prgname = argv[0];
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_enabled_port_mask = default_port_mask;
|
2019-10-07 11:08:04 +00:00
|
|
|
argvopt = argv;
|
|
|
|
|
|
|
|
while ((opt = getopt_long(argc, argvopt, short_options,
|
|
|
|
lgopts, &option_index)) != EOF) {
|
|
|
|
|
|
|
|
switch (opt) {
|
2021-10-26 13:14:26 +00:00
|
|
|
case 'b':
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_batch_sz = atoi(optarg);
|
|
|
|
if (dma_batch_sz > MAX_PKT_BURST) {
|
2021-10-26 13:14:26 +00:00
|
|
|
printf("Invalid dma batch size, %s.\n", optarg);
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_usage(prgname);
|
2021-10-26 13:14:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
2021-10-26 13:14:27 +00:00
|
|
|
case 'f':
|
|
|
|
max_frame_size = atoi(optarg);
|
|
|
|
if (max_frame_size > RTE_ETHER_MAX_JUMBO_FRAME_LEN) {
|
|
|
|
printf("Invalid max frame size, %s.\n", optarg);
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_usage(prgname);
|
2021-10-26 13:14:27 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
/* portmask */
|
|
|
|
case 'p':
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_enabled_port_mask = dma_parse_portmask(optarg);
|
|
|
|
if (dma_enabled_port_mask & ~default_port_mask ||
|
|
|
|
dma_enabled_port_mask <= 0) {
|
2019-10-07 11:08:04 +00:00
|
|
|
printf("Invalid portmask, %s, suggest 0x%x\n",
|
|
|
|
optarg, default_port_mask);
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_usage(prgname);
|
2019-10-07 11:08:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q':
|
|
|
|
nb_queues = atoi(optarg);
|
|
|
|
if (nb_queues == 0 || nb_queues > MAX_RX_QUEUES_COUNT) {
|
|
|
|
printf("Invalid RX queues number %s. Max %u\n",
|
|
|
|
optarg, MAX_RX_QUEUES_COUNT);
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_usage(prgname);
|
2019-10-07 11:08:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
2021-10-26 13:14:31 +00:00
|
|
|
copy_mode = dma_parse_copy_mode(optarg);
|
2019-10-07 11:08:04 +00:00
|
|
|
if (copy_mode == COPY_MODE_INVALID_NUM) {
|
|
|
|
printf("Invalid copy type. Use: sw, hw\n");
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_usage(prgname);
|
2019-10-07 11:08:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
ring_size = atoi(optarg);
|
|
|
|
if (ring_size == 0) {
|
|
|
|
printf("Invalid ring size, %s.\n", optarg);
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_usage(prgname);
|
2019-10-07 11:08:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2021-10-26 13:14:30 +00:00
|
|
|
/* ring_size must be less-than or equal to MBUF_RING_SIZE
|
|
|
|
* to avoid overwriting bufs
|
|
|
|
*/
|
|
|
|
if (ring_size > MBUF_RING_SIZE) {
|
|
|
|
printf("Max ring_size is %d, setting ring_size to max",
|
|
|
|
MBUF_RING_SIZE);
|
|
|
|
ring_size = MBUF_RING_SIZE;
|
|
|
|
}
|
2019-10-07 11:08:04 +00:00
|
|
|
break;
|
|
|
|
|
2021-10-26 13:14:28 +00:00
|
|
|
case 'i':
|
|
|
|
stats_interval = atoi(optarg);
|
|
|
|
if (stats_interval == 0) {
|
|
|
|
printf("Invalid stats interval, setting to 1\n");
|
|
|
|
stats_interval = 1; /* set to default */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
/* long options */
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_usage(prgname);
|
2019-10-07 11:08:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("MAC updating %s\n", mac_updating ? "enabled" : "disabled");
|
|
|
|
if (optind >= 0)
|
|
|
|
argv[optind - 1] = prgname;
|
|
|
|
|
|
|
|
ret = optind - 1;
|
|
|
|
optind = 1; /* reset getopt lib */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check link status, return true if at least one port is up */
|
|
|
|
static int
|
|
|
|
check_link_status(uint32_t port_mask)
|
|
|
|
{
|
|
|
|
uint16_t portid;
|
|
|
|
struct rte_eth_link link;
|
2020-02-07 10:24:02 +00:00
|
|
|
int ret, link_status = 0;
|
2020-09-15 19:07:02 +00:00
|
|
|
char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
printf("\nChecking link status\n");
|
|
|
|
RTE_ETH_FOREACH_DEV(portid) {
|
|
|
|
if ((port_mask & (1 << portid)) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memset(&link, 0, sizeof(link));
|
2020-02-07 10:24:02 +00:00
|
|
|
ret = rte_eth_link_get(portid, &link);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("Port %u link get failed: err=%d\n",
|
|
|
|
portid, ret);
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
/* Print link status */
|
2020-09-15 19:07:02 +00:00
|
|
|
rte_eth_link_to_str(link_status_text,
|
|
|
|
sizeof(link_status_text), &link);
|
|
|
|
printf("Port %d %s\n", portid, link_status_text);
|
|
|
|
|
|
|
|
if (link.link_status)
|
2020-02-07 10:24:02 +00:00
|
|
|
link_status = 1;
|
2019-10-07 11:08:04 +00:00
|
|
|
}
|
2020-02-07 10:24:02 +00:00
|
|
|
return link_status;
|
2019-10-07 11:08:04 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Configuration of device. 8< */
|
2019-10-07 11:08:06 +00:00
|
|
|
static void
|
2021-10-26 13:14:31 +00:00
|
|
|
configure_dmadev_queue(uint32_t dev_id)
|
2019-10-07 11:08:06 +00:00
|
|
|
{
|
2021-10-26 13:14:30 +00:00
|
|
|
struct rte_dma_info info;
|
|
|
|
struct rte_dma_conf dev_config = { .nb_vchans = 1 };
|
|
|
|
struct rte_dma_vchan_conf qconf = {
|
|
|
|
.direction = RTE_DMA_DIR_MEM_TO_MEM,
|
|
|
|
.nb_desc = ring_size
|
2021-05-04 13:14:58 +00:00
|
|
|
};
|
2021-10-26 13:14:30 +00:00
|
|
|
uint16_t vchan = 0;
|
2019-10-07 11:08:06 +00:00
|
|
|
|
2021-10-26 13:14:30 +00:00
|
|
|
if (rte_dma_configure(dev_id, &dev_config) != 0)
|
|
|
|
rte_exit(EXIT_FAILURE, "Error with rte_dma_configure()\n");
|
|
|
|
|
|
|
|
if (rte_dma_vchan_setup(dev_id, vchan, &qconf) != 0) {
|
|
|
|
printf("Error with queue configuration\n");
|
|
|
|
rte_panic();
|
2019-10-07 11:08:06 +00:00
|
|
|
}
|
2021-10-26 13:14:30 +00:00
|
|
|
rte_dma_info_get(dev_id, &info);
|
|
|
|
if (info.nb_vchans != 1) {
|
|
|
|
printf("Error, no configured queues reported on device id %u\n", dev_id);
|
|
|
|
rte_panic();
|
2019-10-07 11:08:06 +00:00
|
|
|
}
|
2021-10-26 13:14:30 +00:00
|
|
|
if (rte_dma_start(dev_id) != 0)
|
|
|
|
rte_exit(EXIT_FAILURE, "Error with rte_dma_start()\n");
|
2019-10-07 11:08:06 +00:00
|
|
|
}
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of configuration of device. */
|
2019-10-07 11:08:06 +00:00
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
/* Using dmadev API functions. 8< */
|
2019-10-07 11:08:06 +00:00
|
|
|
static void
|
2021-10-26 13:14:31 +00:00
|
|
|
assign_dmadevs(void)
|
2019-10-07 11:08:06 +00:00
|
|
|
{
|
2021-10-26 13:14:31 +00:00
|
|
|
uint16_t nb_dmadev = 0;
|
|
|
|
int16_t dev_id = rte_dma_next_dev(0);
|
2019-10-07 11:08:06 +00:00
|
|
|
uint32_t i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < cfg.nb_ports; i++) {
|
|
|
|
for (j = 0; j < cfg.ports[i].nb_queues; j++) {
|
2021-10-26 13:14:31 +00:00
|
|
|
if (dev_id == -1)
|
2021-10-26 13:14:30 +00:00
|
|
|
goto end;
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
cfg.ports[i].dmadev_ids[j] = dev_id;
|
|
|
|
configure_dmadev_queue(cfg.ports[i].dmadev_ids[j]);
|
|
|
|
dev_id = rte_dma_next_dev(dev_id + 1);
|
|
|
|
++nb_dmadev;
|
2019-10-07 11:08:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end:
|
2021-10-26 13:14:31 +00:00
|
|
|
if (nb_dmadev < cfg.nb_ports * cfg.ports[0].nb_queues)
|
2019-10-07 11:08:06 +00:00
|
|
|
rte_exit(EXIT_FAILURE,
|
2021-10-26 13:14:31 +00:00
|
|
|
"Not enough dmadevs (%u) for all queues (%u).\n",
|
|
|
|
nb_dmadev, cfg.nb_ports * cfg.ports[0].nb_queues);
|
|
|
|
RTE_LOG(INFO, DMA, "Number of used dmadevs: %u.\n", nb_dmadev);
|
2019-10-07 11:08:06 +00:00
|
|
|
}
|
2021-10-26 13:14:31 +00:00
|
|
|
/* >8 End of using dmadev API functions. */
|
2019-10-07 11:08:06 +00:00
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Assign ring structures for packet exchanging. 8< */
|
2019-10-07 11:08:05 +00:00
|
|
|
static void
|
|
|
|
assign_rings(void)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < cfg.nb_ports; i++) {
|
|
|
|
char ring_name[RTE_RING_NAMESIZE];
|
|
|
|
|
|
|
|
snprintf(ring_name, sizeof(ring_name), "rx_to_tx_ring_%u", i);
|
|
|
|
/* Create ring for inter core communication */
|
|
|
|
cfg.ports[i].rx_to_tx_ring = rte_ring_create(
|
|
|
|
ring_name, ring_size,
|
|
|
|
rte_socket_id(), RING_F_SP_ENQ | RING_F_SC_DEQ);
|
|
|
|
|
|
|
|
if (cfg.ports[i].rx_to_tx_ring == NULL)
|
|
|
|
rte_exit(EXIT_FAILURE, "Ring create failed: %s\n",
|
|
|
|
rte_strerror(rte_errno));
|
|
|
|
}
|
|
|
|
}
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of assigning ring structures for packet exchanging. */
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
/*
|
|
|
|
* Initializes a given port using global settings and with the RX buffers
|
|
|
|
* coming from the mbuf_pool passed as a parameter.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
port_init(uint16_t portid, struct rte_mempool *mbuf_pool, uint16_t nb_queues)
|
|
|
|
{
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Configuring port to use RSS for multiple RX queues. 8< */
|
2019-10-07 11:08:04 +00:00
|
|
|
static const struct rte_eth_conf port_conf = {
|
|
|
|
.rxmode = {
|
2021-10-22 11:03:12 +00:00
|
|
|
.mq_mode = RTE_ETH_MQ_RX_RSS,
|
2019-10-07 11:08:04 +00:00
|
|
|
},
|
|
|
|
.rx_adv_conf = {
|
|
|
|
.rss_conf = {
|
|
|
|
.rss_key = NULL,
|
2021-10-22 11:03:12 +00:00
|
|
|
.rss_hf = RTE_ETH_RSS_PROTO_MASK,
|
2019-10-07 11:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of configuring port to use RSS for multiple RX queues. */
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
struct rte_eth_rxconf rxq_conf;
|
|
|
|
struct rte_eth_txconf txq_conf;
|
|
|
|
struct rte_eth_conf local_port_conf = port_conf;
|
|
|
|
struct rte_eth_dev_info dev_info;
|
|
|
|
int ret, i;
|
|
|
|
|
2021-10-26 13:14:27 +00:00
|
|
|
if (max_frame_size > local_port_conf.rxmode.mtu)
|
|
|
|
local_port_conf.rxmode.mtu = max_frame_size;
|
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
/* Skip ports that are not enabled */
|
2021-10-26 13:14:31 +00:00
|
|
|
if ((dma_enabled_port_mask & (1 << portid)) == 0) {
|
2019-10-07 11:08:04 +00:00
|
|
|
printf("Skipping disabled port %u\n", portid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init port */
|
|
|
|
printf("Initializing port %u... ", portid);
|
|
|
|
fflush(stdout);
|
2019-11-28 11:27:14 +00:00
|
|
|
ret = rte_eth_dev_info_get(portid, &dev_info);
|
|
|
|
if (ret < 0)
|
|
|
|
rte_exit(EXIT_FAILURE, "Cannot get device info: %s, port=%u\n",
|
|
|
|
rte_strerror(-ret), portid);
|
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
local_port_conf.rx_adv_conf.rss_conf.rss_hf &=
|
|
|
|
dev_info.flow_type_rss_offloads;
|
|
|
|
ret = rte_eth_dev_configure(portid, nb_queues, 1, &local_port_conf);
|
|
|
|
if (ret < 0)
|
|
|
|
rte_exit(EXIT_FAILURE, "Cannot configure device:"
|
|
|
|
" err=%d, port=%u\n", ret, portid);
|
|
|
|
|
|
|
|
ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
|
|
|
|
&nb_txd);
|
|
|
|
if (ret < 0)
|
|
|
|
rte_exit(EXIT_FAILURE,
|
|
|
|
"Cannot adjust number of descriptors: err=%d, port=%u\n",
|
|
|
|
ret, portid);
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
rte_eth_macaddr_get(portid, &dma_ports_eth_addr[portid]);
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
/* Init RX queues */
|
|
|
|
rxq_conf = dev_info.default_rxconf;
|
|
|
|
rxq_conf.offloads = local_port_conf.rxmode.offloads;
|
|
|
|
for (i = 0; i < nb_queues; i++) {
|
|
|
|
ret = rte_eth_rx_queue_setup(portid, i, nb_rxd,
|
|
|
|
rte_eth_dev_socket_id(portid), &rxq_conf,
|
|
|
|
mbuf_pool);
|
|
|
|
if (ret < 0)
|
|
|
|
rte_exit(EXIT_FAILURE,
|
|
|
|
"rte_eth_rx_queue_setup:err=%d,port=%u, queue_id=%u\n",
|
|
|
|
ret, portid, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init one TX queue on each port */
|
|
|
|
txq_conf = dev_info.default_txconf;
|
|
|
|
txq_conf.offloads = local_port_conf.txmode.offloads;
|
|
|
|
ret = rte_eth_tx_queue_setup(portid, 0, nb_txd,
|
|
|
|
rte_eth_dev_socket_id(portid),
|
|
|
|
&txq_conf);
|
|
|
|
if (ret < 0)
|
|
|
|
rte_exit(EXIT_FAILURE,
|
|
|
|
"rte_eth_tx_queue_setup:err=%d,port=%u\n",
|
|
|
|
ret, portid);
|
|
|
|
|
|
|
|
/* Initialize TX buffers */
|
|
|
|
tx_buffer[portid] = rte_zmalloc_socket("tx_buffer",
|
|
|
|
RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0,
|
|
|
|
rte_eth_dev_socket_id(portid));
|
|
|
|
if (tx_buffer[portid] == NULL)
|
|
|
|
rte_exit(EXIT_FAILURE,
|
|
|
|
"Cannot allocate buffer for tx on port %u\n",
|
|
|
|
portid);
|
|
|
|
|
|
|
|
rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST);
|
|
|
|
|
2019-10-07 11:08:08 +00:00
|
|
|
ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[portid],
|
|
|
|
rte_eth_tx_buffer_count_callback,
|
|
|
|
&port_statistics.tx_dropped[portid]);
|
|
|
|
if (ret < 0)
|
|
|
|
rte_exit(EXIT_FAILURE,
|
|
|
|
"Cannot set error callback for tx buffer on port %u\n",
|
|
|
|
portid);
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Start device. 8< */
|
2019-10-07 11:08:04 +00:00
|
|
|
ret = rte_eth_dev_start(portid);
|
|
|
|
if (ret < 0)
|
|
|
|
rte_exit(EXIT_FAILURE,
|
|
|
|
"rte_eth_dev_start:err=%d, port=%u\n",
|
|
|
|
ret, portid);
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of starting device. */
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* RX port is set in promiscuous mode. 8< */
|
2019-10-07 11:08:04 +00:00
|
|
|
rte_eth_promiscuous_enable(portid);
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of RX port is set in promiscuous mode. */
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2021-08-25 17:27:33 +00:00
|
|
|
printf("Port %u, MAC address: " RTE_ETHER_ADDR_PRT_FMT "\n\n",
|
2019-10-07 11:08:04 +00:00
|
|
|
portid,
|
2021-10-26 13:14:31 +00:00
|
|
|
RTE_ETHER_ADDR_BYTES(&dma_ports_eth_addr[portid]));
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
cfg.ports[cfg.nb_ports].rxtx_port = portid;
|
|
|
|
cfg.ports[cfg.nb_ports++].nb_queues = nb_queues;
|
|
|
|
}
|
|
|
|
|
2021-10-26 13:14:29 +00:00
|
|
|
/* Get a device dump for each device being used by the application */
|
|
|
|
static void
|
2021-10-26 13:14:31 +00:00
|
|
|
dmadev_dump(void)
|
2021-10-26 13:14:29 +00:00
|
|
|
{
|
|
|
|
uint32_t i, j;
|
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
if (copy_mode != COPY_MODE_DMA_NUM)
|
2021-10-26 13:14:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < cfg.nb_ports; i++)
|
|
|
|
for (j = 0; j < cfg.ports[i].nb_queues; j++)
|
2021-10-26 13:14:30 +00:00
|
|
|
rte_dma_dump(cfg.ports[i].dmadev_ids[j], stdout);
|
2021-10-26 13:14:29 +00:00
|
|
|
}
|
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
static void
|
|
|
|
signal_handler(int signum)
|
|
|
|
{
|
|
|
|
if (signum == SIGINT || signum == SIGTERM) {
|
|
|
|
printf("\n\nSignal %d received, preparing to exit...\n",
|
|
|
|
signum);
|
|
|
|
force_quit = true;
|
2021-10-26 13:14:29 +00:00
|
|
|
} else if (signum == SIGUSR1) {
|
2021-10-26 13:14:31 +00:00
|
|
|
dmadev_dump();
|
2019-10-07 11:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
uint16_t nb_ports, portid;
|
|
|
|
uint32_t i;
|
|
|
|
unsigned int nb_mbufs;
|
2021-10-26 13:14:27 +00:00
|
|
|
size_t sz;
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Init EAL. 8< */
|
2019-10-07 11:08:04 +00:00
|
|
|
ret = rte_eal_init(argc, argv);
|
|
|
|
if (ret < 0)
|
|
|
|
rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of init EAL. */
|
2019-10-07 11:08:04 +00:00
|
|
|
argc -= ret;
|
|
|
|
argv += ret;
|
|
|
|
|
|
|
|
force_quit = false;
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
signal(SIGTERM, signal_handler);
|
2021-10-26 13:14:29 +00:00
|
|
|
signal(SIGUSR1, signal_handler);
|
2019-10-07 11:08:04 +00:00
|
|
|
|
|
|
|
nb_ports = rte_eth_dev_count_avail();
|
|
|
|
if (nb_ports == 0)
|
|
|
|
rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
|
|
|
|
|
|
|
|
/* Parse application arguments (after the EAL ones) */
|
2021-10-26 13:14:31 +00:00
|
|
|
ret = dma_parse_args(argc, argv, nb_ports);
|
2019-10-07 11:08:04 +00:00
|
|
|
if (ret < 0)
|
2021-10-26 13:14:31 +00:00
|
|
|
rte_exit(EXIT_FAILURE, "Invalid DMA arguments\n");
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Allocates mempool to hold the mbufs. 8< */
|
2019-10-07 11:08:04 +00:00
|
|
|
nb_mbufs = RTE_MAX(nb_ports * (nb_queues * (nb_rxd + nb_txd +
|
2021-10-26 13:14:25 +00:00
|
|
|
4 * MAX_PKT_BURST + ring_size) + ring_size +
|
|
|
|
rte_lcore_count() * MEMPOOL_CACHE_SIZE),
|
2019-10-07 11:08:04 +00:00
|
|
|
MIN_POOL_SIZE);
|
|
|
|
|
|
|
|
/* Create the mbuf pool */
|
2021-10-26 13:14:27 +00:00
|
|
|
sz = max_frame_size + RTE_PKTMBUF_HEADROOM;
|
|
|
|
sz = RTE_MAX(sz, (size_t)RTE_MBUF_DEFAULT_BUF_SIZE);
|
2021-10-26 13:14:31 +00:00
|
|
|
dma_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", nb_mbufs,
|
2021-10-26 13:14:27 +00:00
|
|
|
MEMPOOL_CACHE_SIZE, 0, sz, rte_socket_id());
|
2021-10-26 13:14:31 +00:00
|
|
|
if (dma_pktmbuf_pool == NULL)
|
2019-10-07 11:08:04 +00:00
|
|
|
rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of allocates mempool to hold the mbufs. */
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Initialize each port. 8< */
|
2019-10-07 11:08:04 +00:00
|
|
|
cfg.nb_ports = 0;
|
|
|
|
RTE_ETH_FOREACH_DEV(portid)
|
2021-10-26 13:14:31 +00:00
|
|
|
port_init(portid, dma_pktmbuf_pool, nb_queues);
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of initializing each port. */
|
2019-10-07 11:08:04 +00:00
|
|
|
|
2019-10-07 11:08:08 +00:00
|
|
|
/* Initialize port xstats */
|
|
|
|
memset(&port_statistics, 0, sizeof(port_statistics));
|
|
|
|
|
2021-07-16 13:57:52 +00:00
|
|
|
/* Assigning each port resources. 8< */
|
2021-10-26 13:14:31 +00:00
|
|
|
while (!check_link_status(dma_enabled_port_mask) && !force_quit)
|
2019-10-07 11:08:04 +00:00
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
/* Check if there is enough lcores for all ports. */
|
|
|
|
cfg.nb_lcores = rte_lcore_count() - 1;
|
|
|
|
if (cfg.nb_lcores < 1)
|
|
|
|
rte_exit(EXIT_FAILURE,
|
2020-10-15 22:57:19 +00:00
|
|
|
"There should be at least one worker lcore.\n");
|
2019-10-07 11:08:05 +00:00
|
|
|
|
2021-10-26 13:14:31 +00:00
|
|
|
if (copy_mode == COPY_MODE_DMA_NUM)
|
|
|
|
assign_dmadevs();
|
2021-10-26 13:14:25 +00:00
|
|
|
|
|
|
|
assign_rings();
|
2021-07-16 13:57:52 +00:00
|
|
|
/* >8 End of assigning each port resources. */
|
2019-10-07 11:08:05 +00:00
|
|
|
|
|
|
|
start_forwarding_cores();
|
2020-10-15 22:57:19 +00:00
|
|
|
/* main core prints stats while other cores forward */
|
2019-10-07 11:08:08 +00:00
|
|
|
print_stats(argv[0]);
|
2019-10-07 11:08:05 +00:00
|
|
|
|
|
|
|
/* force_quit is true when we get here */
|
|
|
|
rte_eal_mp_wait_lcore();
|
|
|
|
|
2019-10-07 11:08:06 +00:00
|
|
|
uint32_t j;
|
2019-10-07 11:08:04 +00:00
|
|
|
for (i = 0; i < cfg.nb_ports; i++) {
|
|
|
|
printf("Closing port %d\n", cfg.ports[i].rxtx_port);
|
2020-10-15 13:30:38 +00:00
|
|
|
ret = rte_eth_dev_stop(cfg.ports[i].rxtx_port);
|
|
|
|
if (ret != 0)
|
2021-10-26 13:14:30 +00:00
|
|
|
RTE_LOG(ERR, DMA, "rte_eth_dev_stop: err=%s, port=%u\n",
|
2020-10-15 13:30:38 +00:00
|
|
|
rte_strerror(-ret), cfg.ports[i].rxtx_port);
|
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
rte_eth_dev_close(cfg.ports[i].rxtx_port);
|
2021-10-26 13:14:31 +00:00
|
|
|
if (copy_mode == COPY_MODE_DMA_NUM) {
|
2019-10-07 11:08:06 +00:00
|
|
|
for (j = 0; j < cfg.ports[i].nb_queues; j++) {
|
2021-10-26 13:14:31 +00:00
|
|
|
printf("Stopping dmadev %d\n",
|
2021-10-26 13:14:30 +00:00
|
|
|
cfg.ports[i].dmadev_ids[j]);
|
|
|
|
rte_dma_stop(cfg.ports[i].dmadev_ids[j]);
|
2019-10-07 11:08:06 +00:00
|
|
|
}
|
|
|
|
} else /* copy_mode == COPY_MODE_SW_NUM */
|
|
|
|
rte_ring_free(cfg.ports[i].rx_to_tx_ring);
|
2019-10-07 11:08:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 02:26:03 +00:00
|
|
|
/* clean up the EAL */
|
|
|
|
rte_eal_cleanup();
|
|
|
|
|
2019-10-07 11:08:04 +00:00
|
|
|
printf("Bye...\n");
|
|
|
|
return 0;
|
|
|
|
}
|