1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
13 #include <sys/types.h>
17 #include <sys/queue.h>
24 #include <rte_common.h>
25 #include <rte_errno.h>
26 #include <rte_byteorder.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memcpy.h>
32 #include <rte_launch.h>
34 #include <rte_alarm.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_mempool.h>
40 #include <rte_malloc.h>
42 #include <rte_mbuf_pool_ops.h>
43 #include <rte_interrupts.h>
45 #include <rte_ether.h>
46 #include <rte_ethdev.h>
48 #include <rte_string_fns.h>
49 #ifdef RTE_LIBRTE_IXGBE_PMD
50 #include <rte_pmd_ixgbe.h>
52 #ifdef RTE_LIBRTE_PDUMP
53 #include <rte_pdump.h>
56 #include <rte_metrics.h>
57 #ifdef RTE_LIBRTE_BITRATE
58 #include <rte_bitrate.h>
60 #ifdef RTE_LIBRTE_LATENCY_STATS
61 #include <rte_latencystats.h>
67 /* FreeBSD may not have MAP_HUGETLB (in fact, it probably doesn't) */
68 #define HUGE_FLAG (0x40000)
70 #define HUGE_FLAG MAP_HUGETLB
73 #ifndef MAP_HUGE_SHIFT
74 /* older kernels (or FreeBSD) will not have this define */
75 #define HUGE_SHIFT (26)
77 #define HUGE_SHIFT MAP_HUGE_SHIFT
80 #define EXTMEM_HEAP_NAME "extmem"
81 #define EXTBUF_ZONE_SIZE RTE_PGSIZE_2M
83 uint16_t verbose_level = 0; /**< Silent by default. */
84 int testpmd_logtype; /**< Log type for testpmd logs */
86 /* use master core for command line ? */
87 uint8_t interactive = 0;
88 uint8_t auto_start = 0;
90 char cmdline_filename[PATH_MAX] = {0};
93 * NUMA support configuration.
94 * When set, the NUMA support attempts to dispatch the allocation of the
95 * RX and TX memory rings, and of the DMA memory buffers (mbufs) for the
96 * probed ports among the CPU sockets 0 and 1.
97 * Otherwise, all memory is allocated from CPU socket 0.
99 uint8_t numa_support = 1; /**< numa enabled by default */
102 * In UMA mode,all memory is allocated from socket 0 if --socket-num is
105 uint8_t socket_num = UMA_NO_CONFIG;
108 * Select mempool allocation type:
109 * - native: use regular DPDK memory
110 * - anon: use regular DPDK memory to create mempool, but populate using
111 * anonymous memory (may not be IOVA-contiguous)
112 * - xmem: use externally allocated hugepage memory
114 uint8_t mp_alloc_type = MP_ALLOC_NATIVE;
117 * Store specified sockets on which memory pool to be used by ports
120 uint8_t port_numa[RTE_MAX_ETHPORTS];
123 * Store specified sockets on which RX ring to be used by ports
126 uint8_t rxring_numa[RTE_MAX_ETHPORTS];
129 * Store specified sockets on which TX ring to be used by ports
132 uint8_t txring_numa[RTE_MAX_ETHPORTS];
135 * Record the Ethernet address of peer target ports to which packets are
137 * Must be instantiated with the ethernet addresses of peer traffic generator
140 struct rte_ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
141 portid_t nb_peer_eth_addrs = 0;
144 * Probed Target Environment.
146 struct rte_port *ports; /**< For all probed ethernet ports. */
147 portid_t nb_ports; /**< Number of probed ethernet ports. */
148 struct fwd_lcore **fwd_lcores; /**< For all probed logical cores. */
149 lcoreid_t nb_lcores; /**< Number of probed logical cores. */
151 portid_t ports_ids[RTE_MAX_ETHPORTS]; /**< Store all port ids. */
154 * Test Forwarding Configuration.
155 * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
156 * nb_fwd_ports <= nb_cfg_ports <= nb_ports
158 lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
159 lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
160 portid_t nb_cfg_ports; /**< Number of configured ports. */
161 portid_t nb_fwd_ports; /**< Number of forwarding ports. */
163 unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE]; /**< CPU ids configuration. */
164 portid_t fwd_ports_ids[RTE_MAX_ETHPORTS]; /**< Port ids configuration. */
166 struct fwd_stream **fwd_streams; /**< For each RX queue of each port. */
167 streamid_t nb_fwd_streams; /**< Is equal to (nb_ports * nb_rxq). */
170 * Forwarding engines.
172 struct fwd_engine * fwd_engines[] = {
182 #if defined RTE_LIBRTE_PMD_SOFTNIC
185 #ifdef RTE_LIBRTE_IEEE1588
186 &ieee1588_fwd_engine,
191 struct rte_mempool *mempools[RTE_MAX_NUMA_NODES];
192 uint16_t mempool_flags;
194 struct fwd_config cur_fwd_config;
195 struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */
196 uint32_t retry_enabled;
197 uint32_t burst_tx_delay_time = BURST_TX_WAIT_US;
198 uint32_t burst_tx_retry_num = BURST_TX_RETRIES;
200 uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
201 uint32_t param_total_num_mbufs = 0; /**< number of mbufs in all pools - if
202 * specified on command-line. */
203 uint16_t stats_period; /**< Period to show statistics (disabled by default) */
206 * In container, it cannot terminate the process which running with 'stats-period'
207 * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
212 * Configuration of packet segments used by the "txonly" processing engine.
214 uint16_t tx_pkt_length = TXONLY_DEF_PACKET_LEN; /**< TXONLY packet length. */
215 uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT] = {
216 TXONLY_DEF_PACKET_LEN,
218 uint8_t tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */
220 enum tx_pkt_split tx_pkt_split = TX_PKT_SPLIT_OFF;
221 /**< Split policy for packets to TX. */
223 uint8_t txonly_multi_flow;
224 /**< Whether multiple flows are generated in TXONLY mode. */
226 uint16_t nb_pkt_per_burst = DEF_PKT_BURST; /**< Number of packets per burst. */
227 uint16_t mb_mempool_cache = DEF_MBUF_CACHE; /**< Size of mbuf mempool cache. */
229 /* current configuration is in DCB or not,0 means it is not in DCB mode */
230 uint8_t dcb_config = 0;
232 /* Whether the dcb is in testing status */
233 uint8_t dcb_test = 0;
236 * Configurable number of RX/TX queues.
238 queueid_t nb_hairpinq; /**< Number of hairpin queues per port. */
239 queueid_t nb_rxq = 1; /**< Number of RX queues per port. */
240 queueid_t nb_txq = 1; /**< Number of TX queues per port. */
243 * Configurable number of RX/TX ring descriptors.
244 * Defaults are supplied by drivers via ethdev.
246 #define RTE_TEST_RX_DESC_DEFAULT 0
247 #define RTE_TEST_TX_DESC_DEFAULT 0
248 uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; /**< Number of RX descriptors. */
249 uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; /**< Number of TX descriptors. */
251 #define RTE_PMD_PARAM_UNSET -1
253 * Configurable values of RX and TX ring threshold registers.
256 int8_t rx_pthresh = RTE_PMD_PARAM_UNSET;
257 int8_t rx_hthresh = RTE_PMD_PARAM_UNSET;
258 int8_t rx_wthresh = RTE_PMD_PARAM_UNSET;
260 int8_t tx_pthresh = RTE_PMD_PARAM_UNSET;
261 int8_t tx_hthresh = RTE_PMD_PARAM_UNSET;
262 int8_t tx_wthresh = RTE_PMD_PARAM_UNSET;
265 * Configurable value of RX free threshold.
267 int16_t rx_free_thresh = RTE_PMD_PARAM_UNSET;
270 * Configurable value of RX drop enable.
272 int8_t rx_drop_en = RTE_PMD_PARAM_UNSET;
275 * Configurable value of TX free threshold.
277 int16_t tx_free_thresh = RTE_PMD_PARAM_UNSET;
280 * Configurable value of TX RS bit threshold.
282 int16_t tx_rs_thresh = RTE_PMD_PARAM_UNSET;
285 * Configurable value of buffered packets before sending.
287 uint16_t noisy_tx_sw_bufsz;
290 * Configurable value of packet buffer timeout.
292 uint16_t noisy_tx_sw_buf_flush_time;
295 * Configurable value for size of VNF internal memory area
296 * used for simulating noisy neighbour behaviour
298 uint64_t noisy_lkup_mem_sz;
301 * Configurable value of number of random writes done in
302 * VNF simulation memory area.
304 uint64_t noisy_lkup_num_writes;
307 * Configurable value of number of random reads done in
308 * VNF simulation memory area.
310 uint64_t noisy_lkup_num_reads;
313 * Configurable value of number of random reads/writes done in
314 * VNF simulation memory area.
316 uint64_t noisy_lkup_num_reads_writes;
319 * Receive Side Scaling (RSS) configuration.
321 uint64_t rss_hf = ETH_RSS_IP; /* RSS IP by default. */
324 * Port topology configuration
326 uint16_t port_topology = PORT_TOPOLOGY_PAIRED; /* Ports are paired by default */
329 * Avoids to flush all the RX streams before starts forwarding.
331 uint8_t no_flush_rx = 0; /* flush by default */
334 * Flow API isolated mode.
336 uint8_t flow_isolate_all;
339 * Avoids to check link status when starting/stopping a port.
341 uint8_t no_link_check = 0; /* check by default */
344 * Don't automatically start all ports in interactive mode.
346 uint8_t no_device_start = 0;
349 * Enable link status change notification
351 uint8_t lsc_interrupt = 1; /* enabled by default */
354 * Enable device removal notification.
356 uint8_t rmv_interrupt = 1; /* enabled by default */
358 uint8_t hot_plug = 0; /**< hotplug disabled by default. */
360 /* After attach, port setup is called on event or by iterator */
361 bool setup_on_probe_event = true;
363 /* Clear ptypes on port initialization. */
364 uint8_t clear_ptypes = true;
366 /* Pretty printing of ethdev events */
367 static const char * const eth_event_desc[] = {
368 [RTE_ETH_EVENT_UNKNOWN] = "unknown",
369 [RTE_ETH_EVENT_INTR_LSC] = "link state change",
370 [RTE_ETH_EVENT_QUEUE_STATE] = "queue state",
371 [RTE_ETH_EVENT_INTR_RESET] = "reset",
372 [RTE_ETH_EVENT_VF_MBOX] = "VF mbox",
373 [RTE_ETH_EVENT_IPSEC] = "IPsec",
374 [RTE_ETH_EVENT_MACSEC] = "MACsec",
375 [RTE_ETH_EVENT_INTR_RMV] = "device removal",
376 [RTE_ETH_EVENT_NEW] = "device probed",
377 [RTE_ETH_EVENT_DESTROY] = "device released",
378 [RTE_ETH_EVENT_MAX] = NULL,
382 * Display or mask ether events
383 * Default to all events except VF_MBOX
385 uint32_t event_print_mask = (UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN) |
386 (UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC) |
387 (UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE) |
388 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET) |
389 (UINT32_C(1) << RTE_ETH_EVENT_IPSEC) |
390 (UINT32_C(1) << RTE_ETH_EVENT_MACSEC) |
391 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV);
393 * Decide if all memory are locked for performance.
398 * NIC bypass mode configuration options.
401 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
402 /* The NIC bypass watchdog timeout. */
403 uint32_t bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
407 #ifdef RTE_LIBRTE_LATENCY_STATS
410 * Set when latency stats is enabled in the commandline
412 uint8_t latencystats_enabled;
415 * Lcore ID to serive latency statistics.
417 lcoreid_t latencystats_lcore_id = -1;
422 * Ethernet device configuration.
424 struct rte_eth_rxmode rx_mode = {
425 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
426 /**< Default maximum frame length. */
429 struct rte_eth_txmode tx_mode = {
430 .offloads = DEV_TX_OFFLOAD_MBUF_FAST_FREE,
433 struct rte_fdir_conf fdir_conf = {
434 .mode = RTE_FDIR_MODE_NONE,
435 .pballoc = RTE_FDIR_PBALLOC_64K,
436 .status = RTE_FDIR_REPORT_STATUS,
438 .vlan_tci_mask = 0xFFEF,
440 .src_ip = 0xFFFFFFFF,
441 .dst_ip = 0xFFFFFFFF,
444 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
445 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
447 .src_port_mask = 0xFFFF,
448 .dst_port_mask = 0xFFFF,
449 .mac_addr_byte_mask = 0xFF,
450 .tunnel_type_mask = 1,
451 .tunnel_id_mask = 0xFFFFFFFF,
456 volatile int test_done = 1; /* stop packet forwarding when set to 1. */
458 struct queue_stats_mappings tx_queue_stats_mappings_array[MAX_TX_QUEUE_STATS_MAPPINGS];
459 struct queue_stats_mappings rx_queue_stats_mappings_array[MAX_RX_QUEUE_STATS_MAPPINGS];
461 struct queue_stats_mappings *tx_queue_stats_mappings = tx_queue_stats_mappings_array;
462 struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_array;
464 uint16_t nb_tx_queue_stats_mappings = 0;
465 uint16_t nb_rx_queue_stats_mappings = 0;
468 * Display zero values by default for xstats
470 uint8_t xstats_hide_zero;
472 unsigned int num_sockets = 0;
473 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
475 #ifdef RTE_LIBRTE_BITRATE
476 /* Bitrate statistics */
477 struct rte_stats_bitrates *bitrate_data;
478 lcoreid_t bitrate_lcore_id;
479 uint8_t bitrate_enabled;
482 struct gro_status gro_ports[RTE_MAX_ETHPORTS];
483 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
485 /* Forward function declarations */
486 static void setup_attached_port(portid_t pi);
487 static void map_port_queue_stats_mapping_registers(portid_t pi,
488 struct rte_port *port);
489 static void check_all_ports_link_status(uint32_t port_mask);
490 static int eth_event_callback(portid_t port_id,
491 enum rte_eth_event_type type,
492 void *param, void *ret_param);
493 static void dev_event_callback(const char *device_name,
494 enum rte_dev_event_type type,
498 * Check if all the ports are started.
499 * If yes, return positive value. If not, return zero.
501 static int all_ports_started(void);
503 struct gso_status gso_ports[RTE_MAX_ETHPORTS];
504 uint16_t gso_max_segment_size = RTE_ETHER_MAX_LEN - RTE_ETHER_CRC_LEN;
506 /* Holds the registered mbuf dynamic flags names. */
507 char dynf_names[64][RTE_MBUF_DYN_NAMESIZE];
510 * Helper function to check if socket is already discovered.
511 * If yes, return positive value. If not, return zero.
514 new_socket_id(unsigned int socket_id)
518 for (i = 0; i < num_sockets; i++) {
519 if (socket_ids[i] == socket_id)
526 * Setup default configuration.
529 set_default_fwd_lcores_config(void)
533 unsigned int sock_num;
536 for (i = 0; i < RTE_MAX_LCORE; i++) {
537 if (!rte_lcore_is_enabled(i))
539 sock_num = rte_lcore_to_socket_id(i);
540 if (new_socket_id(sock_num)) {
541 if (num_sockets >= RTE_MAX_NUMA_NODES) {
542 rte_exit(EXIT_FAILURE,
543 "Total sockets greater than %u\n",
546 socket_ids[num_sockets++] = sock_num;
548 if (i == rte_get_master_lcore())
550 fwd_lcores_cpuids[nb_lc++] = i;
552 nb_lcores = (lcoreid_t) nb_lc;
553 nb_cfg_lcores = nb_lcores;
558 set_def_peer_eth_addrs(void)
562 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
563 peer_eth_addrs[i].addr_bytes[0] = RTE_ETHER_LOCAL_ADMIN_ADDR;
564 peer_eth_addrs[i].addr_bytes[5] = i;
569 set_default_fwd_ports_config(void)
574 RTE_ETH_FOREACH_DEV(pt_id) {
575 fwd_ports_ids[i++] = pt_id;
577 /* Update sockets info according to the attached device */
578 int socket_id = rte_eth_dev_socket_id(pt_id);
579 if (socket_id >= 0 && new_socket_id(socket_id)) {
580 if (num_sockets >= RTE_MAX_NUMA_NODES) {
581 rte_exit(EXIT_FAILURE,
582 "Total sockets greater than %u\n",
585 socket_ids[num_sockets++] = socket_id;
589 nb_cfg_ports = nb_ports;
590 nb_fwd_ports = nb_ports;
594 set_def_fwd_config(void)
596 set_default_fwd_lcores_config();
597 set_def_peer_eth_addrs();
598 set_default_fwd_ports_config();
601 /* extremely pessimistic estimation of memory required to create a mempool */
603 calc_mem_size(uint32_t nb_mbufs, uint32_t mbuf_sz, size_t pgsz, size_t *out)
605 unsigned int n_pages, mbuf_per_pg, leftover;
606 uint64_t total_mem, mbuf_mem, obj_sz;
608 /* there is no good way to predict how much space the mempool will
609 * occupy because it will allocate chunks on the fly, and some of those
610 * will come from default DPDK memory while some will come from our
611 * external memory, so just assume 128MB will be enough for everyone.
613 uint64_t hdr_mem = 128 << 20;
615 /* account for possible non-contiguousness */
616 obj_sz = rte_mempool_calc_obj_size(mbuf_sz, 0, NULL);
618 TESTPMD_LOG(ERR, "Object size is bigger than page size\n");
622 mbuf_per_pg = pgsz / obj_sz;
623 leftover = (nb_mbufs % mbuf_per_pg) > 0;
624 n_pages = (nb_mbufs / mbuf_per_pg) + leftover;
626 mbuf_mem = n_pages * pgsz;
628 total_mem = RTE_ALIGN(hdr_mem + mbuf_mem, pgsz);
630 if (total_mem > SIZE_MAX) {
631 TESTPMD_LOG(ERR, "Memory size too big\n");
634 *out = (size_t)total_mem;
640 pagesz_flags(uint64_t page_sz)
642 /* as per mmap() manpage, all page sizes are log2 of page size
643 * shifted by MAP_HUGE_SHIFT
645 int log2 = rte_log2_u64(page_sz);
647 return (log2 << HUGE_SHIFT);
651 alloc_mem(size_t memsz, size_t pgsz, bool huge)
656 /* allocate anonymous hugepages */
657 flags = MAP_ANONYMOUS | MAP_PRIVATE;
659 flags |= HUGE_FLAG | pagesz_flags(pgsz);
661 addr = mmap(NULL, memsz, PROT_READ | PROT_WRITE, flags, -1, 0);
662 if (addr == MAP_FAILED)
668 struct extmem_param {
672 rte_iova_t *iova_table;
673 unsigned int iova_table_len;
677 create_extmem(uint32_t nb_mbufs, uint32_t mbuf_sz, struct extmem_param *param,
680 uint64_t pgsizes[] = {RTE_PGSIZE_2M, RTE_PGSIZE_1G, /* x86_64, ARM */
681 RTE_PGSIZE_16M, RTE_PGSIZE_16G}; /* POWER */
682 unsigned int cur_page, n_pages, pgsz_idx;
683 size_t mem_sz, cur_pgsz;
684 rte_iova_t *iovas = NULL;
688 for (pgsz_idx = 0; pgsz_idx < RTE_DIM(pgsizes); pgsz_idx++) {
689 /* skip anything that is too big */
690 if (pgsizes[pgsz_idx] > SIZE_MAX)
693 cur_pgsz = pgsizes[pgsz_idx];
695 /* if we were told not to allocate hugepages, override */
697 cur_pgsz = sysconf(_SC_PAGESIZE);
699 ret = calc_mem_size(nb_mbufs, mbuf_sz, cur_pgsz, &mem_sz);
701 TESTPMD_LOG(ERR, "Cannot calculate memory size\n");
705 /* allocate our memory */
706 addr = alloc_mem(mem_sz, cur_pgsz, huge);
708 /* if we couldn't allocate memory with a specified page size,
709 * that doesn't mean we can't do it with other page sizes, so
715 /* store IOVA addresses for every page in this memory area */
716 n_pages = mem_sz / cur_pgsz;
718 iovas = malloc(sizeof(*iovas) * n_pages);
721 TESTPMD_LOG(ERR, "Cannot allocate memory for iova addresses\n");
724 /* lock memory if it's not huge pages */
728 /* populate IOVA addresses */
729 for (cur_page = 0; cur_page < n_pages; cur_page++) {
734 offset = cur_pgsz * cur_page;
735 cur = RTE_PTR_ADD(addr, offset);
737 /* touch the page before getting its IOVA */
738 *(volatile char *)cur = 0;
740 iova = rte_mem_virt2iova(cur);
742 iovas[cur_page] = iova;
747 /* if we couldn't allocate anything */
753 param->pgsz = cur_pgsz;
754 param->iova_table = iovas;
755 param->iova_table_len = n_pages;
762 munmap(addr, mem_sz);
768 setup_extmem(uint32_t nb_mbufs, uint32_t mbuf_sz, bool huge)
770 struct extmem_param param;
773 memset(¶m, 0, sizeof(param));
775 /* check if our heap exists */
776 socket_id = rte_malloc_heap_get_socket(EXTMEM_HEAP_NAME);
778 /* create our heap */
779 ret = rte_malloc_heap_create(EXTMEM_HEAP_NAME);
781 TESTPMD_LOG(ERR, "Cannot create heap\n");
786 ret = create_extmem(nb_mbufs, mbuf_sz, ¶m, huge);
788 TESTPMD_LOG(ERR, "Cannot create memory area\n");
792 /* we now have a valid memory area, so add it to heap */
793 ret = rte_malloc_heap_memory_add(EXTMEM_HEAP_NAME,
794 param.addr, param.len, param.iova_table,
795 param.iova_table_len, param.pgsz);
797 /* when using VFIO, memory is automatically mapped for DMA by EAL */
799 /* not needed any more */
800 free(param.iova_table);
803 TESTPMD_LOG(ERR, "Cannot add memory to heap\n");
804 munmap(param.addr, param.len);
810 TESTPMD_LOG(DEBUG, "Allocated %zuMB of external memory\n",
816 dma_unmap_cb(struct rte_mempool *mp __rte_unused, void *opaque __rte_unused,
817 struct rte_mempool_memhdr *memhdr, unsigned mem_idx __rte_unused)
822 RTE_ETH_FOREACH_DEV(pid) {
823 struct rte_eth_dev *dev =
824 &rte_eth_devices[pid];
826 ret = rte_dev_dma_unmap(dev->device, memhdr->addr, 0,
830 "unable to DMA unmap addr 0x%p "
832 memhdr->addr, dev->data->name);
835 ret = rte_extmem_unregister(memhdr->addr, memhdr->len);
838 "unable to un-register addr 0x%p\n", memhdr->addr);
843 dma_map_cb(struct rte_mempool *mp __rte_unused, void *opaque __rte_unused,
844 struct rte_mempool_memhdr *memhdr, unsigned mem_idx __rte_unused)
847 size_t page_size = sysconf(_SC_PAGESIZE);
850 ret = rte_extmem_register(memhdr->addr, memhdr->len, NULL, 0,
854 "unable to register addr 0x%p\n", memhdr->addr);
857 RTE_ETH_FOREACH_DEV(pid) {
858 struct rte_eth_dev *dev =
859 &rte_eth_devices[pid];
861 ret = rte_dev_dma_map(dev->device, memhdr->addr, 0,
865 "unable to DMA map addr 0x%p "
867 memhdr->addr, dev->data->name);
873 setup_extbuf(uint32_t nb_mbufs, uint16_t mbuf_sz, unsigned int socket_id,
874 char *pool_name, struct rte_pktmbuf_extmem **ext_mem)
876 struct rte_pktmbuf_extmem *xmem;
877 unsigned int ext_num, zone_num, elt_num;
880 elt_size = RTE_ALIGN_CEIL(mbuf_sz, RTE_CACHE_LINE_SIZE);
881 elt_num = EXTBUF_ZONE_SIZE / elt_size;
882 zone_num = (nb_mbufs + elt_num - 1) / elt_num;
884 xmem = malloc(sizeof(struct rte_pktmbuf_extmem) * zone_num);
886 TESTPMD_LOG(ERR, "Cannot allocate memory for "
887 "external buffer descriptors\n");
891 for (ext_num = 0; ext_num < zone_num; ext_num++) {
892 struct rte_pktmbuf_extmem *xseg = xmem + ext_num;
893 const struct rte_memzone *mz;
894 char mz_name[RTE_MEMZONE_NAMESIZE];
897 ret = snprintf(mz_name, sizeof(mz_name),
898 RTE_MEMPOOL_MZ_FORMAT "_xb_%u", pool_name, ext_num);
899 if (ret < 0 || ret >= (int)sizeof(mz_name)) {
900 errno = ENAMETOOLONG;
904 mz = rte_memzone_reserve_aligned(mz_name, EXTBUF_ZONE_SIZE,
906 RTE_MEMZONE_IOVA_CONTIG |
908 RTE_MEMZONE_SIZE_HINT_ONLY,
912 * The caller exits on external buffer creation
913 * error, so there is no need to free memzones.
919 xseg->buf_ptr = mz->addr;
920 xseg->buf_iova = mz->iova;
921 xseg->buf_len = EXTBUF_ZONE_SIZE;
922 xseg->elt_size = elt_size;
924 if (ext_num == 0 && xmem != NULL) {
933 * Configuration initialisation done once at init time.
935 static struct rte_mempool *
936 mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
937 unsigned int socket_id)
939 char pool_name[RTE_MEMPOOL_NAMESIZE];
940 struct rte_mempool *rte_mp = NULL;
943 mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
944 mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
947 "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
948 pool_name, nb_mbuf, mbuf_seg_size, socket_id);
950 switch (mp_alloc_type) {
951 case MP_ALLOC_NATIVE:
953 /* wrapper to rte_mempool_create() */
954 TESTPMD_LOG(INFO, "preferred mempool ops selected: %s\n",
955 rte_mbuf_best_mempool_ops());
956 rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
957 mb_mempool_cache, 0, mbuf_seg_size, socket_id);
962 rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf,
963 mb_size, (unsigned int) mb_mempool_cache,
964 sizeof(struct rte_pktmbuf_pool_private),
965 socket_id, mempool_flags);
969 if (rte_mempool_populate_anon(rte_mp) == 0) {
970 rte_mempool_free(rte_mp);
974 rte_pktmbuf_pool_init(rte_mp, NULL);
975 rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
976 rte_mempool_mem_iter(rte_mp, dma_map_cb, NULL);
980 case MP_ALLOC_XMEM_HUGE:
983 bool huge = mp_alloc_type == MP_ALLOC_XMEM_HUGE;
985 if (setup_extmem(nb_mbuf, mbuf_seg_size, huge) < 0)
986 rte_exit(EXIT_FAILURE, "Could not create external memory\n");
989 rte_malloc_heap_get_socket(EXTMEM_HEAP_NAME);
991 rte_exit(EXIT_FAILURE, "Could not get external memory socket ID\n");
993 TESTPMD_LOG(INFO, "preferred mempool ops selected: %s\n",
994 rte_mbuf_best_mempool_ops());
995 rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
996 mb_mempool_cache, 0, mbuf_seg_size,
1002 struct rte_pktmbuf_extmem *ext_mem;
1003 unsigned int ext_num;
1005 ext_num = setup_extbuf(nb_mbuf, mbuf_seg_size,
1006 socket_id, pool_name, &ext_mem);
1008 rte_exit(EXIT_FAILURE,
1009 "Can't create pinned data buffers\n");
1011 TESTPMD_LOG(INFO, "preferred mempool ops selected: %s\n",
1012 rte_mbuf_best_mempool_ops());
1013 rte_mp = rte_pktmbuf_pool_create_extbuf
1014 (pool_name, nb_mbuf, mb_mempool_cache,
1015 0, mbuf_seg_size, socket_id,
1022 rte_exit(EXIT_FAILURE, "Invalid mempool creation mode\n");
1027 if (rte_mp == NULL) {
1028 rte_exit(EXIT_FAILURE,
1029 "Creation of mbuf pool for socket %u failed: %s\n",
1030 socket_id, rte_strerror(rte_errno));
1031 } else if (verbose_level > 0) {
1032 rte_mempool_dump(stdout, rte_mp);
1038 * Check given socket id is valid or not with NUMA mode,
1039 * if valid, return 0, else return -1
1042 check_socket_id(const unsigned int socket_id)
1044 static int warning_once = 0;
1046 if (new_socket_id(socket_id)) {
1047 if (!warning_once && numa_support)
1048 printf("Warning: NUMA should be configured manually by"
1049 " using --port-numa-config and"
1050 " --ring-numa-config parameters along with"
1059 * Get the allowed maximum number of RX queues.
1060 * *pid return the port id which has minimal value of
1061 * max_rx_queues in all ports.
1064 get_allowed_max_nb_rxq(portid_t *pid)
1066 queueid_t allowed_max_rxq = RTE_MAX_QUEUES_PER_PORT;
1067 bool max_rxq_valid = false;
1069 struct rte_eth_dev_info dev_info;
1071 RTE_ETH_FOREACH_DEV(pi) {
1072 if (eth_dev_info_get_print_err(pi, &dev_info) != 0)
1075 max_rxq_valid = true;
1076 if (dev_info.max_rx_queues < allowed_max_rxq) {
1077 allowed_max_rxq = dev_info.max_rx_queues;
1081 return max_rxq_valid ? allowed_max_rxq : 0;
1085 * Check input rxq is valid or not.
1086 * If input rxq is not greater than any of maximum number
1087 * of RX queues of all ports, it is valid.
1088 * if valid, return 0, else return -1
1091 check_nb_rxq(queueid_t rxq)
1093 queueid_t allowed_max_rxq;
1096 allowed_max_rxq = get_allowed_max_nb_rxq(&pid);
1097 if (rxq > allowed_max_rxq) {
1098 printf("Fail: input rxq (%u) can't be greater "
1099 "than max_rx_queues (%u) of port %u\n",
1109 * Get the allowed maximum number of TX queues.
1110 * *pid return the port id which has minimal value of
1111 * max_tx_queues in all ports.
1114 get_allowed_max_nb_txq(portid_t *pid)
1116 queueid_t allowed_max_txq = RTE_MAX_QUEUES_PER_PORT;
1117 bool max_txq_valid = false;
1119 struct rte_eth_dev_info dev_info;
1121 RTE_ETH_FOREACH_DEV(pi) {
1122 if (eth_dev_info_get_print_err(pi, &dev_info) != 0)
1125 max_txq_valid = true;
1126 if (dev_info.max_tx_queues < allowed_max_txq) {
1127 allowed_max_txq = dev_info.max_tx_queues;
1131 return max_txq_valid ? allowed_max_txq : 0;
1135 * Check input txq is valid or not.
1136 * If input txq is not greater than any of maximum number
1137 * of TX queues of all ports, it is valid.
1138 * if valid, return 0, else return -1
1141 check_nb_txq(queueid_t txq)
1143 queueid_t allowed_max_txq;
1146 allowed_max_txq = get_allowed_max_nb_txq(&pid);
1147 if (txq > allowed_max_txq) {
1148 printf("Fail: input txq (%u) can't be greater "
1149 "than max_tx_queues (%u) of port %u\n",
1159 * Get the allowed maximum number of hairpin queues.
1160 * *pid return the port id which has minimal value of
1161 * max_hairpin_queues in all ports.
1164 get_allowed_max_nb_hairpinq(portid_t *pid)
1166 queueid_t allowed_max_hairpinq = RTE_MAX_QUEUES_PER_PORT;
1168 struct rte_eth_hairpin_cap cap;
1170 RTE_ETH_FOREACH_DEV(pi) {
1171 if (rte_eth_dev_hairpin_capability_get(pi, &cap) != 0) {
1175 if (cap.max_nb_queues < allowed_max_hairpinq) {
1176 allowed_max_hairpinq = cap.max_nb_queues;
1180 return allowed_max_hairpinq;
1184 * Check input hairpin is valid or not.
1185 * If input hairpin is not greater than any of maximum number
1186 * of hairpin queues of all ports, it is valid.
1187 * if valid, return 0, else return -1
1190 check_nb_hairpinq(queueid_t hairpinq)
1192 queueid_t allowed_max_hairpinq;
1195 allowed_max_hairpinq = get_allowed_max_nb_hairpinq(&pid);
1196 if (hairpinq > allowed_max_hairpinq) {
1197 printf("Fail: input hairpin (%u) can't be greater "
1198 "than max_hairpin_queues (%u) of port %u\n",
1199 hairpinq, allowed_max_hairpinq, pid);
1209 struct rte_port *port;
1210 struct rte_mempool *mbp;
1211 unsigned int nb_mbuf_per_pool;
1213 uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
1214 struct rte_gro_param gro_param;
1221 memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
1223 /* Configuration of logical cores. */
1224 fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
1225 sizeof(struct fwd_lcore *) * nb_lcores,
1226 RTE_CACHE_LINE_SIZE);
1227 if (fwd_lcores == NULL) {
1228 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_lcore *)) "
1229 "failed\n", nb_lcores);
1231 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
1232 fwd_lcores[lc_id] = rte_zmalloc("testpmd: struct fwd_lcore",
1233 sizeof(struct fwd_lcore),
1234 RTE_CACHE_LINE_SIZE);
1235 if (fwd_lcores[lc_id] == NULL) {
1236 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_lcore) "
1239 fwd_lcores[lc_id]->cpuid_idx = lc_id;
1242 RTE_ETH_FOREACH_DEV(pid) {
1244 /* Apply default TxRx configuration for all ports */
1245 port->dev_conf.txmode = tx_mode;
1246 port->dev_conf.rxmode = rx_mode;
1248 ret = eth_dev_info_get_print_err(pid, &port->dev_info);
1250 rte_exit(EXIT_FAILURE,
1251 "rte_eth_dev_info_get() failed\n");
1253 if (!(port->dev_info.tx_offload_capa &
1254 DEV_TX_OFFLOAD_MBUF_FAST_FREE))
1255 port->dev_conf.txmode.offloads &=
1256 ~DEV_TX_OFFLOAD_MBUF_FAST_FREE;
1258 if (port_numa[pid] != NUMA_NO_CONFIG)
1259 port_per_socket[port_numa[pid]]++;
1261 uint32_t socket_id = rte_eth_dev_socket_id(pid);
1264 * if socket_id is invalid,
1265 * set to the first available socket.
1267 if (check_socket_id(socket_id) < 0)
1268 socket_id = socket_ids[0];
1269 port_per_socket[socket_id]++;
1273 /* Apply Rx offloads configuration */
1274 for (k = 0; k < port->dev_info.max_rx_queues; k++)
1275 port->rx_conf[k].offloads =
1276 port->dev_conf.rxmode.offloads;
1277 /* Apply Tx offloads configuration */
1278 for (k = 0; k < port->dev_info.max_tx_queues; k++)
1279 port->tx_conf[k].offloads =
1280 port->dev_conf.txmode.offloads;
1282 /* set flag to initialize port/queue */
1283 port->need_reconfig = 1;
1284 port->need_reconfig_queues = 1;
1285 port->tx_metadata = 0;
1287 /* Check for maximum number of segments per MTU. Accordingly
1288 * update the mbuf data size.
1290 if (port->dev_info.rx_desc_lim.nb_mtu_seg_max != UINT16_MAX &&
1291 port->dev_info.rx_desc_lim.nb_mtu_seg_max != 0) {
1292 data_size = rx_mode.max_rx_pkt_len /
1293 port->dev_info.rx_desc_lim.nb_mtu_seg_max;
1295 if ((data_size + RTE_PKTMBUF_HEADROOM) >
1297 mbuf_data_size = data_size +
1298 RTE_PKTMBUF_HEADROOM;
1305 TESTPMD_LOG(WARNING, "Configured mbuf size %hu\n",
1309 * Create pools of mbuf.
1310 * If NUMA support is disabled, create a single pool of mbuf in
1311 * socket 0 memory by default.
1312 * Otherwise, create a pool of mbuf in the memory of sockets 0 and 1.
1314 * Use the maximum value of nb_rxd and nb_txd here, then nb_rxd and
1315 * nb_txd can be configured at run time.
1317 if (param_total_num_mbufs)
1318 nb_mbuf_per_pool = param_total_num_mbufs;
1320 nb_mbuf_per_pool = RTE_TEST_RX_DESC_MAX +
1321 (nb_lcores * mb_mempool_cache) +
1322 RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
1323 nb_mbuf_per_pool *= RTE_MAX_ETHPORTS;
1329 for (i = 0; i < num_sockets; i++)
1330 mempools[i] = mbuf_pool_create(mbuf_data_size,
1334 if (socket_num == UMA_NO_CONFIG)
1335 mempools[0] = mbuf_pool_create(mbuf_data_size,
1336 nb_mbuf_per_pool, 0);
1338 mempools[socket_num] = mbuf_pool_create
1346 gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
1347 DEV_TX_OFFLOAD_GRE_TNL_TSO | DEV_TX_OFFLOAD_UDP_TSO;
1349 * Records which Mbuf pool to use by each logical core, if needed.
1351 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
1352 mbp = mbuf_pool_find(
1353 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]));
1356 mbp = mbuf_pool_find(0);
1357 fwd_lcores[lc_id]->mbp = mbp;
1358 /* initialize GSO context */
1359 fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
1360 fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
1361 fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
1362 fwd_lcores[lc_id]->gso_ctx.gso_size = RTE_ETHER_MAX_LEN -
1364 fwd_lcores[lc_id]->gso_ctx.flag = 0;
1367 /* Configuration of packet forwarding streams. */
1368 if (init_fwd_streams() < 0)
1369 rte_exit(EXIT_FAILURE, "FAIL from init_fwd_streams()\n");
1373 /* create a gro context for each lcore */
1374 gro_param.gro_types = RTE_GRO_TCP_IPV4;
1375 gro_param.max_flow_num = GRO_MAX_FLUSH_CYCLES;
1376 gro_param.max_item_per_flow = MAX_PKT_BURST;
1377 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
1378 gro_param.socket_id = rte_lcore_to_socket_id(
1379 fwd_lcores_cpuids[lc_id]);
1380 fwd_lcores[lc_id]->gro_ctx = rte_gro_ctx_create(&gro_param);
1381 if (fwd_lcores[lc_id]->gro_ctx == NULL) {
1382 rte_exit(EXIT_FAILURE,
1383 "rte_gro_ctx_create() failed\n");
1387 #if defined RTE_LIBRTE_PMD_SOFTNIC
1388 if (strcmp(cur_fwd_eng->fwd_mode_name, "softnic") == 0) {
1389 RTE_ETH_FOREACH_DEV(pid) {
1391 const char *driver = port->dev_info.driver_name;
1393 if (strcmp(driver, "net_softnic") == 0)
1394 port->softport.fwd_lcore_arg = fwd_lcores;
1403 reconfig(portid_t new_port_id, unsigned socket_id)
1405 struct rte_port *port;
1408 /* Reconfiguration of Ethernet ports. */
1409 port = &ports[new_port_id];
1411 ret = eth_dev_info_get_print_err(new_port_id, &port->dev_info);
1415 /* set flag to initialize port/queue */
1416 port->need_reconfig = 1;
1417 port->need_reconfig_queues = 1;
1418 port->socket_id = socket_id;
1425 init_fwd_streams(void)
1428 struct rte_port *port;
1429 streamid_t sm_id, nb_fwd_streams_new;
1432 /* set socket id according to numa or not */
1433 RTE_ETH_FOREACH_DEV(pid) {
1435 if (nb_rxq > port->dev_info.max_rx_queues) {
1436 printf("Fail: nb_rxq(%d) is greater than "
1437 "max_rx_queues(%d)\n", nb_rxq,
1438 port->dev_info.max_rx_queues);
1441 if (nb_txq > port->dev_info.max_tx_queues) {
1442 printf("Fail: nb_txq(%d) is greater than "
1443 "max_tx_queues(%d)\n", nb_txq,
1444 port->dev_info.max_tx_queues);
1448 if (port_numa[pid] != NUMA_NO_CONFIG)
1449 port->socket_id = port_numa[pid];
1451 port->socket_id = rte_eth_dev_socket_id(pid);
1454 * if socket_id is invalid,
1455 * set to the first available socket.
1457 if (check_socket_id(port->socket_id) < 0)
1458 port->socket_id = socket_ids[0];
1462 if (socket_num == UMA_NO_CONFIG)
1463 port->socket_id = 0;
1465 port->socket_id = socket_num;
1469 q = RTE_MAX(nb_rxq, nb_txq);
1471 printf("Fail: Cannot allocate fwd streams as number of queues is 0\n");
1474 nb_fwd_streams_new = (streamid_t)(nb_ports * q);
1475 if (nb_fwd_streams_new == nb_fwd_streams)
1478 if (fwd_streams != NULL) {
1479 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
1480 if (fwd_streams[sm_id] == NULL)
1482 rte_free(fwd_streams[sm_id]);
1483 fwd_streams[sm_id] = NULL;
1485 rte_free(fwd_streams);
1490 nb_fwd_streams = nb_fwd_streams_new;
1491 if (nb_fwd_streams) {
1492 fwd_streams = rte_zmalloc("testpmd: fwd_streams",
1493 sizeof(struct fwd_stream *) * nb_fwd_streams,
1494 RTE_CACHE_LINE_SIZE);
1495 if (fwd_streams == NULL)
1496 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d"
1497 " (struct fwd_stream *)) failed\n",
1500 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
1501 fwd_streams[sm_id] = rte_zmalloc("testpmd:"
1502 " struct fwd_stream", sizeof(struct fwd_stream),
1503 RTE_CACHE_LINE_SIZE);
1504 if (fwd_streams[sm_id] == NULL)
1505 rte_exit(EXIT_FAILURE, "rte_zmalloc"
1506 "(struct fwd_stream) failed\n");
1513 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1515 pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs)
1517 unsigned int total_burst;
1518 unsigned int nb_burst;
1519 unsigned int burst_stats[3];
1520 uint16_t pktnb_stats[3];
1522 int burst_percent[3];
1525 * First compute the total number of packet bursts and the
1526 * two highest numbers of bursts of the same number of packets.
1529 burst_stats[0] = burst_stats[1] = burst_stats[2] = 0;
1530 pktnb_stats[0] = pktnb_stats[1] = pktnb_stats[2] = 0;
1531 for (nb_pkt = 0; nb_pkt < MAX_PKT_BURST; nb_pkt++) {
1532 nb_burst = pbs->pkt_burst_spread[nb_pkt];
1535 total_burst += nb_burst;
1536 if (nb_burst > burst_stats[0]) {
1537 burst_stats[1] = burst_stats[0];
1538 pktnb_stats[1] = pktnb_stats[0];
1539 burst_stats[0] = nb_burst;
1540 pktnb_stats[0] = nb_pkt;
1541 } else if (nb_burst > burst_stats[1]) {
1542 burst_stats[1] = nb_burst;
1543 pktnb_stats[1] = nb_pkt;
1546 if (total_burst == 0)
1548 burst_percent[0] = (burst_stats[0] * 100) / total_burst;
1549 printf(" %s-bursts : %u [%d%% of %d pkts", rx_tx, total_burst,
1550 burst_percent[0], (int) pktnb_stats[0]);
1551 if (burst_stats[0] == total_burst) {
1555 if (burst_stats[0] + burst_stats[1] == total_burst) {
1556 printf(" + %d%% of %d pkts]\n",
1557 100 - burst_percent[0], pktnb_stats[1]);
1560 burst_percent[1] = (burst_stats[1] * 100) / total_burst;
1561 burst_percent[2] = 100 - (burst_percent[0] + burst_percent[1]);
1562 if ((burst_percent[1] == 0) || (burst_percent[2] == 0)) {
1563 printf(" + %d%% of others]\n", 100 - burst_percent[0]);
1566 printf(" + %d%% of %d pkts + %d%% of others]\n",
1567 burst_percent[1], (int) pktnb_stats[1], burst_percent[2]);
1569 #endif /* RTE_TEST_PMD_RECORD_BURST_STATS */
1572 fwd_stream_stats_display(streamid_t stream_id)
1574 struct fwd_stream *fs;
1575 static const char *fwd_top_stats_border = "-------";
1577 fs = fwd_streams[stream_id];
1578 if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
1579 (fs->fwd_dropped == 0))
1581 printf("\n %s Forward Stats for RX Port=%2d/Queue=%2d -> "
1582 "TX Port=%2d/Queue=%2d %s\n",
1583 fwd_top_stats_border, fs->rx_port, fs->rx_queue,
1584 fs->tx_port, fs->tx_queue, fwd_top_stats_border);
1585 printf(" RX-packets: %-14"PRIu64" TX-packets: %-14"PRIu64
1586 " TX-dropped: %-14"PRIu64,
1587 fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
1589 /* if checksum mode */
1590 if (cur_fwd_eng == &csum_fwd_engine) {
1591 printf(" RX- bad IP checksum: %-14"PRIu64
1592 " Rx- bad L4 checksum: %-14"PRIu64
1593 " Rx- bad outer L4 checksum: %-14"PRIu64"\n",
1594 fs->rx_bad_ip_csum, fs->rx_bad_l4_csum,
1595 fs->rx_bad_outer_l4_csum);
1600 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1601 pkt_burst_stats_display("RX", &fs->rx_burst_stats);
1602 pkt_burst_stats_display("TX", &fs->tx_burst_stats);
1607 fwd_stats_display(void)
1609 static const char *fwd_stats_border = "----------------------";
1610 static const char *acc_stats_border = "+++++++++++++++";
1612 struct fwd_stream *rx_stream;
1613 struct fwd_stream *tx_stream;
1614 uint64_t tx_dropped;
1615 uint64_t rx_bad_ip_csum;
1616 uint64_t rx_bad_l4_csum;
1617 uint64_t rx_bad_outer_l4_csum;
1618 } ports_stats[RTE_MAX_ETHPORTS];
1619 uint64_t total_rx_dropped = 0;
1620 uint64_t total_tx_dropped = 0;
1621 uint64_t total_rx_nombuf = 0;
1622 struct rte_eth_stats stats;
1623 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1624 uint64_t fwd_cycles = 0;
1626 uint64_t total_recv = 0;
1627 uint64_t total_xmit = 0;
1628 struct rte_port *port;
1633 memset(ports_stats, 0, sizeof(ports_stats));
1635 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1636 struct fwd_stream *fs = fwd_streams[sm_id];
1638 if (cur_fwd_config.nb_fwd_streams >
1639 cur_fwd_config.nb_fwd_ports) {
1640 fwd_stream_stats_display(sm_id);
1642 ports_stats[fs->tx_port].tx_stream = fs;
1643 ports_stats[fs->rx_port].rx_stream = fs;
1646 ports_stats[fs->tx_port].tx_dropped += fs->fwd_dropped;
1648 ports_stats[fs->rx_port].rx_bad_ip_csum += fs->rx_bad_ip_csum;
1649 ports_stats[fs->rx_port].rx_bad_l4_csum += fs->rx_bad_l4_csum;
1650 ports_stats[fs->rx_port].rx_bad_outer_l4_csum +=
1651 fs->rx_bad_outer_l4_csum;
1653 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1654 fwd_cycles += fs->core_cycles;
1657 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1660 pt_id = fwd_ports_ids[i];
1661 port = &ports[pt_id];
1663 rte_eth_stats_get(pt_id, &stats);
1664 stats.ipackets -= port->stats.ipackets;
1665 stats.opackets -= port->stats.opackets;
1666 stats.ibytes -= port->stats.ibytes;
1667 stats.obytes -= port->stats.obytes;
1668 stats.imissed -= port->stats.imissed;
1669 stats.oerrors -= port->stats.oerrors;
1670 stats.rx_nombuf -= port->stats.rx_nombuf;
1672 total_recv += stats.ipackets;
1673 total_xmit += stats.opackets;
1674 total_rx_dropped += stats.imissed;
1675 total_tx_dropped += ports_stats[pt_id].tx_dropped;
1676 total_tx_dropped += stats.oerrors;
1677 total_rx_nombuf += stats.rx_nombuf;
1679 printf("\n %s Forward statistics for port %-2d %s\n",
1680 fwd_stats_border, pt_id, fwd_stats_border);
1682 if (!port->rx_queue_stats_mapping_enabled &&
1683 !port->tx_queue_stats_mapping_enabled) {
1684 printf(" RX-packets: %-14"PRIu64
1685 " RX-dropped: %-14"PRIu64
1686 "RX-total: %-"PRIu64"\n",
1687 stats.ipackets, stats.imissed,
1688 stats.ipackets + stats.imissed);
1690 if (cur_fwd_eng == &csum_fwd_engine)
1691 printf(" Bad-ipcsum: %-14"PRIu64
1692 " Bad-l4csum: %-14"PRIu64
1693 "Bad-outer-l4csum: %-14"PRIu64"\n",
1694 ports_stats[pt_id].rx_bad_ip_csum,
1695 ports_stats[pt_id].rx_bad_l4_csum,
1696 ports_stats[pt_id].rx_bad_outer_l4_csum);
1697 if (stats.ierrors + stats.rx_nombuf > 0) {
1698 printf(" RX-error: %-"PRIu64"\n",
1700 printf(" RX-nombufs: %-14"PRIu64"\n",
1704 printf(" TX-packets: %-14"PRIu64
1705 " TX-dropped: %-14"PRIu64
1706 "TX-total: %-"PRIu64"\n",
1707 stats.opackets, ports_stats[pt_id].tx_dropped,
1708 stats.opackets + ports_stats[pt_id].tx_dropped);
1710 printf(" RX-packets: %14"PRIu64
1711 " RX-dropped:%14"PRIu64
1712 " RX-total:%14"PRIu64"\n",
1713 stats.ipackets, stats.imissed,
1714 stats.ipackets + stats.imissed);
1716 if (cur_fwd_eng == &csum_fwd_engine)
1717 printf(" Bad-ipcsum:%14"PRIu64
1718 " Bad-l4csum:%14"PRIu64
1719 " Bad-outer-l4csum: %-14"PRIu64"\n",
1720 ports_stats[pt_id].rx_bad_ip_csum,
1721 ports_stats[pt_id].rx_bad_l4_csum,
1722 ports_stats[pt_id].rx_bad_outer_l4_csum);
1723 if ((stats.ierrors + stats.rx_nombuf) > 0) {
1724 printf(" RX-error:%"PRIu64"\n", stats.ierrors);
1725 printf(" RX-nombufs: %14"PRIu64"\n",
1729 printf(" TX-packets: %14"PRIu64
1730 " TX-dropped:%14"PRIu64
1731 " TX-total:%14"PRIu64"\n",
1732 stats.opackets, ports_stats[pt_id].tx_dropped,
1733 stats.opackets + ports_stats[pt_id].tx_dropped);
1736 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1737 if (ports_stats[pt_id].rx_stream)
1738 pkt_burst_stats_display("RX",
1739 &ports_stats[pt_id].rx_stream->rx_burst_stats);
1740 if (ports_stats[pt_id].tx_stream)
1741 pkt_burst_stats_display("TX",
1742 &ports_stats[pt_id].tx_stream->tx_burst_stats);
1745 if (port->rx_queue_stats_mapping_enabled) {
1747 for (j = 0; j < RTE_ETHDEV_QUEUE_STAT_CNTRS; j++) {
1748 printf(" Stats reg %2d RX-packets:%14"PRIu64
1749 " RX-errors:%14"PRIu64
1750 " RX-bytes:%14"PRIu64"\n",
1751 j, stats.q_ipackets[j],
1752 stats.q_errors[j], stats.q_ibytes[j]);
1756 if (port->tx_queue_stats_mapping_enabled) {
1757 for (j = 0; j < RTE_ETHDEV_QUEUE_STAT_CNTRS; j++) {
1758 printf(" Stats reg %2d TX-packets:%14"PRIu64
1761 j, stats.q_opackets[j],
1766 printf(" %s--------------------------------%s\n",
1767 fwd_stats_border, fwd_stats_border);
1770 printf("\n %s Accumulated forward statistics for all ports"
1772 acc_stats_border, acc_stats_border);
1773 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
1775 " TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
1777 total_recv, total_rx_dropped, total_recv + total_rx_dropped,
1778 total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
1779 if (total_rx_nombuf > 0)
1780 printf(" RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
1781 printf(" %s++++++++++++++++++++++++++++++++++++++++++++++"
1783 acc_stats_border, acc_stats_border);
1784 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1786 printf("\n CPU cycles/packet=%u (total cycles="
1787 "%"PRIu64" / total RX packets=%"PRIu64")\n",
1788 (unsigned int)(fwd_cycles / total_recv),
1789 fwd_cycles, total_recv);
1794 fwd_stats_reset(void)
1800 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1801 pt_id = fwd_ports_ids[i];
1802 rte_eth_stats_get(pt_id, &ports[pt_id].stats);
1804 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1805 struct fwd_stream *fs = fwd_streams[sm_id];
1809 fs->fwd_dropped = 0;
1810 fs->rx_bad_ip_csum = 0;
1811 fs->rx_bad_l4_csum = 0;
1812 fs->rx_bad_outer_l4_csum = 0;
1814 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1815 memset(&fs->rx_burst_stats, 0, sizeof(fs->rx_burst_stats));
1816 memset(&fs->tx_burst_stats, 0, sizeof(fs->tx_burst_stats));
1818 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1819 fs->core_cycles = 0;
1825 flush_fwd_rx_queues(void)
1827 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1834 uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
1835 uint64_t timer_period;
1837 /* convert to number of cycles */
1838 timer_period = rte_get_timer_hz(); /* 1 second timeout */
1840 for (j = 0; j < 2; j++) {
1841 for (rxp = 0; rxp < cur_fwd_config.nb_fwd_ports; rxp++) {
1842 for (rxq = 0; rxq < nb_rxq; rxq++) {
1843 port_id = fwd_ports_ids[rxp];
1845 * testpmd can stuck in the below do while loop
1846 * if rte_eth_rx_burst() always returns nonzero
1847 * packets. So timer is added to exit this loop
1848 * after 1sec timer expiry.
1850 prev_tsc = rte_rdtsc();
1852 nb_rx = rte_eth_rx_burst(port_id, rxq,
1853 pkts_burst, MAX_PKT_BURST);
1854 for (i = 0; i < nb_rx; i++)
1855 rte_pktmbuf_free(pkts_burst[i]);
1857 cur_tsc = rte_rdtsc();
1858 diff_tsc = cur_tsc - prev_tsc;
1859 timer_tsc += diff_tsc;
1860 } while ((nb_rx > 0) &&
1861 (timer_tsc < timer_period));
1865 rte_delay_ms(10); /* wait 10 milli-seconds before retrying */
1870 run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
1872 struct fwd_stream **fsm;
1875 #ifdef RTE_LIBRTE_BITRATE
1876 uint64_t tics_per_1sec;
1877 uint64_t tics_datum;
1878 uint64_t tics_current;
1879 uint16_t i, cnt_ports;
1881 cnt_ports = nb_ports;
1882 tics_datum = rte_rdtsc();
1883 tics_per_1sec = rte_get_timer_hz();
1885 fsm = &fwd_streams[fc->stream_idx];
1886 nb_fs = fc->stream_nb;
1888 for (sm_id = 0; sm_id < nb_fs; sm_id++)
1889 (*pkt_fwd)(fsm[sm_id]);
1890 #ifdef RTE_LIBRTE_BITRATE
1891 if (bitrate_enabled != 0 &&
1892 bitrate_lcore_id == rte_lcore_id()) {
1893 tics_current = rte_rdtsc();
1894 if (tics_current - tics_datum >= tics_per_1sec) {
1895 /* Periodic bitrate calculation */
1896 for (i = 0; i < cnt_ports; i++)
1897 rte_stats_bitrate_calc(bitrate_data,
1899 tics_datum = tics_current;
1903 #ifdef RTE_LIBRTE_LATENCY_STATS
1904 if (latencystats_enabled != 0 &&
1905 latencystats_lcore_id == rte_lcore_id())
1906 rte_latencystats_update();
1909 } while (! fc->stopped);
1913 start_pkt_forward_on_core(void *fwd_arg)
1915 run_pkt_fwd_on_lcore((struct fwd_lcore *) fwd_arg,
1916 cur_fwd_config.fwd_eng->packet_fwd);
1921 * Run the TXONLY packet forwarding engine to send a single burst of packets.
1922 * Used to start communication flows in network loopback test configurations.
1925 run_one_txonly_burst_on_core(void *fwd_arg)
1927 struct fwd_lcore *fwd_lc;
1928 struct fwd_lcore tmp_lcore;
1930 fwd_lc = (struct fwd_lcore *) fwd_arg;
1931 tmp_lcore = *fwd_lc;
1932 tmp_lcore.stopped = 1;
1933 run_pkt_fwd_on_lcore(&tmp_lcore, tx_only_engine.packet_fwd);
1938 * Launch packet forwarding:
1939 * - Setup per-port forwarding context.
1940 * - launch logical cores with their forwarding configuration.
1943 launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
1945 port_fwd_begin_t port_fwd_begin;
1950 port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
1951 if (port_fwd_begin != NULL) {
1952 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1953 (*port_fwd_begin)(fwd_ports_ids[i]);
1955 for (i = 0; i < cur_fwd_config.nb_fwd_lcores; i++) {
1956 lc_id = fwd_lcores_cpuids[i];
1957 if ((interactive == 0) || (lc_id != rte_lcore_id())) {
1958 fwd_lcores[i]->stopped = 0;
1959 diag = rte_eal_remote_launch(pkt_fwd_on_lcore,
1960 fwd_lcores[i], lc_id);
1962 printf("launch lcore %u failed - diag=%d\n",
1969 * Launch packet forwarding configuration.
1972 start_packet_forwarding(int with_tx_first)
1974 port_fwd_begin_t port_fwd_begin;
1975 port_fwd_end_t port_fwd_end;
1976 struct rte_port *port;
1980 if (strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") == 0 && !nb_rxq)
1981 rte_exit(EXIT_FAILURE, "rxq are 0, cannot use rxonly fwd mode\n");
1983 if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 && !nb_txq)
1984 rte_exit(EXIT_FAILURE, "txq are 0, cannot use txonly fwd mode\n");
1986 if ((strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") != 0 &&
1987 strcmp(cur_fwd_eng->fwd_mode_name, "txonly") != 0) &&
1988 (!nb_rxq || !nb_txq))
1989 rte_exit(EXIT_FAILURE,
1990 "Either rxq or txq are 0, cannot use %s fwd mode\n",
1991 cur_fwd_eng->fwd_mode_name);
1993 if (all_ports_started() == 0) {
1994 printf("Not all ports were started\n");
1997 if (test_done == 0) {
1998 printf("Packet forwarding already started\n");
2004 for (i = 0; i < nb_fwd_ports; i++) {
2005 pt_id = fwd_ports_ids[i];
2006 port = &ports[pt_id];
2007 if (!port->dcb_flag) {
2008 printf("In DCB mode, all forwarding ports must "
2009 "be configured in this mode.\n");
2013 if (nb_fwd_lcores == 1) {
2014 printf("In DCB mode,the nb forwarding cores "
2015 "should be larger than 1.\n");
2024 flush_fwd_rx_queues();
2026 pkt_fwd_config_display(&cur_fwd_config);
2027 rxtx_config_display();
2030 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2031 pt_id = fwd_ports_ids[i];
2032 port = &ports[pt_id];
2033 map_port_queue_stats_mapping_registers(pt_id, port);
2035 if (with_tx_first) {
2036 port_fwd_begin = tx_only_engine.port_fwd_begin;
2037 if (port_fwd_begin != NULL) {
2038 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
2039 (*port_fwd_begin)(fwd_ports_ids[i]);
2041 while (with_tx_first--) {
2042 launch_packet_forwarding(
2043 run_one_txonly_burst_on_core);
2044 rte_eal_mp_wait_lcore();
2046 port_fwd_end = tx_only_engine.port_fwd_end;
2047 if (port_fwd_end != NULL) {
2048 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
2049 (*port_fwd_end)(fwd_ports_ids[i]);
2052 launch_packet_forwarding(start_pkt_forward_on_core);
2056 stop_packet_forwarding(void)
2058 port_fwd_end_t port_fwd_end;
2064 printf("Packet forwarding not started\n");
2067 printf("Telling cores to stop...");
2068 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++)
2069 fwd_lcores[lc_id]->stopped = 1;
2070 printf("\nWaiting for lcores to finish...\n");
2071 rte_eal_mp_wait_lcore();
2072 port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end;
2073 if (port_fwd_end != NULL) {
2074 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
2075 pt_id = fwd_ports_ids[i];
2076 (*port_fwd_end)(pt_id);
2080 fwd_stats_display();
2082 printf("\nDone.\n");
2087 dev_set_link_up(portid_t pid)
2089 if (rte_eth_dev_set_link_up(pid) < 0)
2090 printf("\nSet link up fail.\n");
2094 dev_set_link_down(portid_t pid)
2096 if (rte_eth_dev_set_link_down(pid) < 0)
2097 printf("\nSet link down fail.\n");
2101 all_ports_started(void)
2104 struct rte_port *port;
2106 RTE_ETH_FOREACH_DEV(pi) {
2108 /* Check if there is a port which is not started */
2109 if ((port->port_status != RTE_PORT_STARTED) &&
2110 (port->slave_flag == 0))
2114 /* No port is not started */
2119 port_is_stopped(portid_t port_id)
2121 struct rte_port *port = &ports[port_id];
2123 if ((port->port_status != RTE_PORT_STOPPED) &&
2124 (port->slave_flag == 0))
2130 all_ports_stopped(void)
2134 RTE_ETH_FOREACH_DEV(pi) {
2135 if (!port_is_stopped(pi))
2143 port_is_started(portid_t port_id)
2145 if (port_id_is_invalid(port_id, ENABLED_WARN))
2148 if (ports[port_id].port_status != RTE_PORT_STARTED)
2154 /* Configure the Rx and Tx hairpin queues for the selected port. */
2156 setup_hairpin_queues(portid_t pi)
2159 struct rte_eth_hairpin_conf hairpin_conf = {
2164 struct rte_port *port = &ports[pi];
2166 for (qi = nb_txq, i = 0; qi < nb_hairpinq + nb_txq; qi++) {
2167 hairpin_conf.peers[0].port = pi;
2168 hairpin_conf.peers[0].queue = i + nb_rxq;
2169 diag = rte_eth_tx_hairpin_queue_setup
2170 (pi, qi, nb_txd, &hairpin_conf);
2175 /* Fail to setup rx queue, return */
2176 if (rte_atomic16_cmpset(&(port->port_status),
2178 RTE_PORT_STOPPED) == 0)
2179 printf("Port %d can not be set back "
2180 "to stopped\n", pi);
2181 printf("Fail to configure port %d hairpin "
2183 /* try to reconfigure queues next time */
2184 port->need_reconfig_queues = 1;
2187 for (qi = nb_rxq, i = 0; qi < nb_hairpinq + nb_rxq; qi++) {
2188 hairpin_conf.peers[0].port = pi;
2189 hairpin_conf.peers[0].queue = i + nb_txq;
2190 diag = rte_eth_rx_hairpin_queue_setup
2191 (pi, qi, nb_rxd, &hairpin_conf);
2196 /* Fail to setup rx queue, return */
2197 if (rte_atomic16_cmpset(&(port->port_status),
2199 RTE_PORT_STOPPED) == 0)
2200 printf("Port %d can not be set back "
2201 "to stopped\n", pi);
2202 printf("Fail to configure port %d hairpin "
2204 /* try to reconfigure queues next time */
2205 port->need_reconfig_queues = 1;
2212 start_port(portid_t pid)
2214 int diag, need_check_link_status = -1;
2217 struct rte_port *port;
2218 struct rte_ether_addr mac_addr;
2219 struct rte_eth_hairpin_cap cap;
2221 if (port_id_is_invalid(pid, ENABLED_WARN))
2226 RTE_ETH_FOREACH_DEV(pi) {
2227 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
2230 need_check_link_status = 0;
2232 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STOPPED,
2233 RTE_PORT_HANDLING) == 0) {
2234 printf("Port %d is now not stopped\n", pi);
2238 if (port->need_reconfig > 0) {
2239 port->need_reconfig = 0;
2241 if (flow_isolate_all) {
2242 int ret = port_flow_isolate(pi, 1);
2244 printf("Failed to apply isolated"
2245 " mode on port %d\n", pi);
2249 configure_rxtx_dump_callbacks(0);
2250 printf("Configuring Port %d (socket %u)\n", pi,
2252 if (nb_hairpinq > 0 &&
2253 rte_eth_dev_hairpin_capability_get(pi, &cap)) {
2254 printf("Port %d doesn't support hairpin "
2258 /* configure port */
2259 diag = rte_eth_dev_configure(pi, nb_rxq + nb_hairpinq,
2260 nb_txq + nb_hairpinq,
2263 if (rte_atomic16_cmpset(&(port->port_status),
2264 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
2265 printf("Port %d can not be set back "
2266 "to stopped\n", pi);
2267 printf("Fail to configure port %d\n", pi);
2268 /* try to reconfigure port next time */
2269 port->need_reconfig = 1;
2273 if (port->need_reconfig_queues > 0) {
2274 port->need_reconfig_queues = 0;
2275 /* setup tx queues */
2276 for (qi = 0; qi < nb_txq; qi++) {
2277 if ((numa_support) &&
2278 (txring_numa[pi] != NUMA_NO_CONFIG))
2279 diag = rte_eth_tx_queue_setup(pi, qi,
2280 port->nb_tx_desc[qi],
2282 &(port->tx_conf[qi]));
2284 diag = rte_eth_tx_queue_setup(pi, qi,
2285 port->nb_tx_desc[qi],
2287 &(port->tx_conf[qi]));
2292 /* Fail to setup tx queue, return */
2293 if (rte_atomic16_cmpset(&(port->port_status),
2295 RTE_PORT_STOPPED) == 0)
2296 printf("Port %d can not be set back "
2297 "to stopped\n", pi);
2298 printf("Fail to configure port %d tx queues\n",
2300 /* try to reconfigure queues next time */
2301 port->need_reconfig_queues = 1;
2304 for (qi = 0; qi < nb_rxq; qi++) {
2305 /* setup rx queues */
2306 if ((numa_support) &&
2307 (rxring_numa[pi] != NUMA_NO_CONFIG)) {
2308 struct rte_mempool * mp =
2309 mbuf_pool_find(rxring_numa[pi]);
2311 printf("Failed to setup RX queue:"
2312 "No mempool allocation"
2313 " on the socket %d\n",
2318 diag = rte_eth_rx_queue_setup(pi, qi,
2319 port->nb_rx_desc[qi],
2321 &(port->rx_conf[qi]),
2324 struct rte_mempool *mp =
2325 mbuf_pool_find(port->socket_id);
2327 printf("Failed to setup RX queue:"
2328 "No mempool allocation"
2329 " on the socket %d\n",
2333 diag = rte_eth_rx_queue_setup(pi, qi,
2334 port->nb_rx_desc[qi],
2336 &(port->rx_conf[qi]),
2342 /* Fail to setup rx queue, return */
2343 if (rte_atomic16_cmpset(&(port->port_status),
2345 RTE_PORT_STOPPED) == 0)
2346 printf("Port %d can not be set back "
2347 "to stopped\n", pi);
2348 printf("Fail to configure port %d rx queues\n",
2350 /* try to reconfigure queues next time */
2351 port->need_reconfig_queues = 1;
2354 /* setup hairpin queues */
2355 if (setup_hairpin_queues(pi) != 0)
2358 configure_rxtx_dump_callbacks(verbose_level);
2360 diag = rte_eth_dev_set_ptypes(pi, RTE_PTYPE_UNKNOWN,
2364 "Port %d: Failed to disable Ptype parsing\n",
2369 if (rte_eth_dev_start(pi) < 0) {
2370 printf("Fail to start port %d\n", pi);
2372 /* Fail to setup rx queue, return */
2373 if (rte_atomic16_cmpset(&(port->port_status),
2374 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
2375 printf("Port %d can not be set back to "
2380 if (rte_atomic16_cmpset(&(port->port_status),
2381 RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0)
2382 printf("Port %d can not be set into started\n", pi);
2384 if (eth_macaddr_get_print_err(pi, &mac_addr) == 0)
2385 printf("Port %d: %02X:%02X:%02X:%02X:%02X:%02X\n", pi,
2386 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
2387 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
2388 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5]);
2390 /* at least one port started, need checking link status */
2391 need_check_link_status = 1;
2394 if (need_check_link_status == 1 && !no_link_check)
2395 check_all_ports_link_status(RTE_PORT_ALL);
2396 else if (need_check_link_status == 0)
2397 printf("Please stop the ports first\n");
2404 stop_port(portid_t pid)
2407 struct rte_port *port;
2408 int need_check_link_status = 0;
2415 if (port_id_is_invalid(pid, ENABLED_WARN))
2418 printf("Stopping ports...\n");
2420 RTE_ETH_FOREACH_DEV(pi) {
2421 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
2424 if (port_is_forwarding(pi) != 0 && test_done == 0) {
2425 printf("Please remove port %d from forwarding configuration.\n", pi);
2429 if (port_is_bonding_slave(pi)) {
2430 printf("Please remove port %d from bonded device.\n", pi);
2435 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STARTED,
2436 RTE_PORT_HANDLING) == 0)
2439 rte_eth_dev_stop(pi);
2441 if (rte_atomic16_cmpset(&(port->port_status),
2442 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
2443 printf("Port %d can not be set into stopped\n", pi);
2444 need_check_link_status = 1;
2446 if (need_check_link_status && !no_link_check)
2447 check_all_ports_link_status(RTE_PORT_ALL);
2453 remove_invalid_ports_in(portid_t *array, portid_t *total)
2456 portid_t new_total = 0;
2458 for (i = 0; i < *total; i++)
2459 if (!port_id_is_invalid(array[i], DISABLED_WARN)) {
2460 array[new_total] = array[i];
2467 remove_invalid_ports(void)
2469 remove_invalid_ports_in(ports_ids, &nb_ports);
2470 remove_invalid_ports_in(fwd_ports_ids, &nb_fwd_ports);
2471 nb_cfg_ports = nb_fwd_ports;
2475 close_port(portid_t pid)
2478 struct rte_port *port;
2480 if (port_id_is_invalid(pid, ENABLED_WARN))
2483 printf("Closing ports...\n");
2485 RTE_ETH_FOREACH_DEV(pi) {
2486 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
2489 if (port_is_forwarding(pi) != 0 && test_done == 0) {
2490 printf("Please remove port %d from forwarding configuration.\n", pi);
2494 if (port_is_bonding_slave(pi)) {
2495 printf("Please remove port %d from bonded device.\n", pi);
2500 if (rte_atomic16_cmpset(&(port->port_status),
2501 RTE_PORT_CLOSED, RTE_PORT_CLOSED) == 1) {
2502 printf("Port %d is already closed\n", pi);
2506 if (rte_atomic16_cmpset(&(port->port_status),
2507 RTE_PORT_STOPPED, RTE_PORT_HANDLING) == 0) {
2508 printf("Port %d is now not stopped\n", pi);
2512 if (port->flow_list)
2513 port_flow_flush(pi);
2514 rte_eth_dev_close(pi);
2516 remove_invalid_ports();
2518 if (rte_atomic16_cmpset(&(port->port_status),
2519 RTE_PORT_HANDLING, RTE_PORT_CLOSED) == 0)
2520 printf("Port %d cannot be set to closed\n", pi);
2527 reset_port(portid_t pid)
2531 struct rte_port *port;
2533 if (port_id_is_invalid(pid, ENABLED_WARN))
2536 if ((pid == (portid_t)RTE_PORT_ALL && !all_ports_stopped()) ||
2537 (pid != (portid_t)RTE_PORT_ALL && !port_is_stopped(pid))) {
2538 printf("Can not reset port(s), please stop port(s) first.\n");
2542 printf("Resetting ports...\n");
2544 RTE_ETH_FOREACH_DEV(pi) {
2545 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
2548 if (port_is_forwarding(pi) != 0 && test_done == 0) {
2549 printf("Please remove port %d from forwarding "
2550 "configuration.\n", pi);
2554 if (port_is_bonding_slave(pi)) {
2555 printf("Please remove port %d from bonded device.\n",
2560 diag = rte_eth_dev_reset(pi);
2563 port->need_reconfig = 1;
2564 port->need_reconfig_queues = 1;
2566 printf("Failed to reset port %d. diag=%d\n", pi, diag);
2574 attach_port(char *identifier)
2577 struct rte_dev_iterator iterator;
2579 printf("Attaching a new port...\n");
2581 if (identifier == NULL) {
2582 printf("Invalid parameters are specified\n");
2586 if (rte_dev_probe(identifier) < 0) {
2587 TESTPMD_LOG(ERR, "Failed to attach port %s\n", identifier);
2591 /* first attach mode: event */
2592 if (setup_on_probe_event) {
2593 /* new ports are detected on RTE_ETH_EVENT_NEW event */
2594 for (pi = 0; pi < RTE_MAX_ETHPORTS; pi++)
2595 if (ports[pi].port_status == RTE_PORT_HANDLING &&
2596 ports[pi].need_setup != 0)
2597 setup_attached_port(pi);
2601 /* second attach mode: iterator */
2602 RTE_ETH_FOREACH_MATCHING_DEV(pi, identifier, &iterator) {
2603 /* setup ports matching the devargs used for probing */
2604 if (port_is_forwarding(pi))
2605 continue; /* port was already attached before */
2606 setup_attached_port(pi);
2611 setup_attached_port(portid_t pi)
2613 unsigned int socket_id;
2616 socket_id = (unsigned)rte_eth_dev_socket_id(pi);
2617 /* if socket_id is invalid, set to the first available socket. */
2618 if (check_socket_id(socket_id) < 0)
2619 socket_id = socket_ids[0];
2620 reconfig(pi, socket_id);
2621 ret = rte_eth_promiscuous_enable(pi);
2623 printf("Error during enabling promiscuous mode for port %u: %s - ignore\n",
2624 pi, rte_strerror(-ret));
2626 ports_ids[nb_ports++] = pi;
2627 fwd_ports_ids[nb_fwd_ports++] = pi;
2628 nb_cfg_ports = nb_fwd_ports;
2629 ports[pi].need_setup = 0;
2630 ports[pi].port_status = RTE_PORT_STOPPED;
2632 printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
2637 detach_port_device(portid_t port_id)
2639 struct rte_device *dev;
2642 printf("Removing a device...\n");
2644 if (port_id_is_invalid(port_id, ENABLED_WARN))
2647 dev = rte_eth_devices[port_id].device;
2649 printf("Device already removed\n");
2653 if (ports[port_id].port_status != RTE_PORT_CLOSED) {
2654 if (ports[port_id].port_status != RTE_PORT_STOPPED) {
2655 printf("Port not stopped\n");
2658 printf("Port was not closed\n");
2659 if (ports[port_id].flow_list)
2660 port_flow_flush(port_id);
2663 if (rte_dev_remove(dev) < 0) {
2664 TESTPMD_LOG(ERR, "Failed to detach device %s\n", dev->name);
2667 RTE_ETH_FOREACH_DEV_OF(sibling, dev) {
2668 /* reset mapping between old ports and removed device */
2669 rte_eth_devices[sibling].device = NULL;
2670 if (ports[sibling].port_status != RTE_PORT_CLOSED) {
2671 /* sibling ports are forced to be closed */
2672 ports[sibling].port_status = RTE_PORT_CLOSED;
2673 printf("Port %u is closed\n", sibling);
2677 remove_invalid_ports();
2679 printf("Device of port %u is detached\n", port_id);
2680 printf("Now total ports is %d\n", nb_ports);
2686 detach_device(char *identifier)
2688 struct rte_dev_iterator iterator;
2689 struct rte_devargs da;
2692 printf("Removing a device...\n");
2694 memset(&da, 0, sizeof(da));
2695 if (rte_devargs_parsef(&da, "%s", identifier)) {
2696 printf("cannot parse identifier\n");
2702 RTE_ETH_FOREACH_MATCHING_DEV(port_id, identifier, &iterator) {
2703 if (ports[port_id].port_status != RTE_PORT_CLOSED) {
2704 if (ports[port_id].port_status != RTE_PORT_STOPPED) {
2705 printf("Port %u not stopped\n", port_id);
2706 rte_eth_iterator_cleanup(&iterator);
2710 /* sibling ports are forced to be closed */
2711 if (ports[port_id].flow_list)
2712 port_flow_flush(port_id);
2713 ports[port_id].port_status = RTE_PORT_CLOSED;
2714 printf("Port %u is now closed\n", port_id);
2718 if (rte_eal_hotplug_remove(da.bus->name, da.name) != 0) {
2719 TESTPMD_LOG(ERR, "Failed to detach device %s(%s)\n",
2720 da.name, da.bus->name);
2724 remove_invalid_ports();
2726 printf("Device %s is detached\n", identifier);
2727 printf("Now total ports is %d\n", nb_ports);
2739 stop_packet_forwarding();
2741 for (i = 0 ; i < RTE_MAX_NUMA_NODES ; i++) {
2743 if (mp_alloc_type == MP_ALLOC_ANON)
2744 rte_mempool_mem_iter(mempools[i], dma_unmap_cb,
2748 if (ports != NULL) {
2750 RTE_ETH_FOREACH_DEV(pt_id) {
2751 printf("\nStopping port %d...\n", pt_id);
2755 RTE_ETH_FOREACH_DEV(pt_id) {
2756 printf("\nShutting down port %d...\n", pt_id);
2763 ret = rte_dev_event_monitor_stop();
2766 "fail to stop device event monitor.");
2770 ret = rte_dev_event_callback_unregister(NULL,
2771 dev_event_callback, NULL);
2774 "fail to unregister device event callback.\n");
2778 ret = rte_dev_hotplug_handle_disable();
2781 "fail to disable hotplug handling.\n");
2785 for (i = 0 ; i < RTE_MAX_NUMA_NODES ; i++) {
2787 rte_mempool_free(mempools[i]);
2790 printf("\nBye...\n");
2793 typedef void (*cmd_func_t)(void);
2794 struct pmd_test_command {
2795 const char *cmd_name;
2796 cmd_func_t cmd_func;
2799 #define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
2801 /* Check the link status of all ports in up to 9s, and print them finally */
2803 check_all_ports_link_status(uint32_t port_mask)
2805 #define CHECK_INTERVAL 100 /* 100ms */
2806 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
2808 uint8_t count, all_ports_up, print_flag = 0;
2809 struct rte_eth_link link;
2812 printf("Checking link statuses...\n");
2814 for (count = 0; count <= MAX_CHECK_TIME; count++) {
2816 RTE_ETH_FOREACH_DEV(portid) {
2817 if ((port_mask & (1 << portid)) == 0)
2819 memset(&link, 0, sizeof(link));
2820 ret = rte_eth_link_get_nowait(portid, &link);
2823 if (print_flag == 1)
2824 printf("Port %u link get failed: %s\n",
2825 portid, rte_strerror(-ret));
2828 /* print link status if flag set */
2829 if (print_flag == 1) {
2830 if (link.link_status)
2832 "Port%d Link Up. speed %u Mbps- %s\n",
2833 portid, link.link_speed,
2834 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
2835 ("full-duplex") : ("half-duplex\n"));
2837 printf("Port %d Link Down\n", portid);
2840 /* clear all_ports_up flag if any link down */
2841 if (link.link_status == ETH_LINK_DOWN) {
2846 /* after finally printing all link status, get out */
2847 if (print_flag == 1)
2850 if (all_ports_up == 0) {
2852 rte_delay_ms(CHECK_INTERVAL);
2855 /* set the print_flag if all ports up or timeout */
2856 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
2866 * This callback is for remove a port for a device. It has limitation because
2867 * it is not for multiple port removal for a device.
2868 * TODO: the device detach invoke will plan to be removed from user side to
2869 * eal. And convert all PMDs to free port resources on ether device closing.
2872 rmv_port_callback(void *arg)
2874 int need_to_start = 0;
2875 int org_no_link_check = no_link_check;
2876 portid_t port_id = (intptr_t)arg;
2878 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2880 if (!test_done && port_is_forwarding(port_id)) {
2882 stop_packet_forwarding();
2886 no_link_check = org_no_link_check;
2887 close_port(port_id);
2888 detach_port_device(port_id);
2890 start_packet_forwarding(0);
2893 /* This function is used by the interrupt thread */
2895 eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
2898 RTE_SET_USED(param);
2899 RTE_SET_USED(ret_param);
2901 if (type >= RTE_ETH_EVENT_MAX) {
2902 fprintf(stderr, "\nPort %" PRIu16 ": %s called upon invalid event %d\n",
2903 port_id, __func__, type);
2905 } else if (event_print_mask & (UINT32_C(1) << type)) {
2906 printf("\nPort %" PRIu16 ": %s event\n", port_id,
2907 eth_event_desc[type]);
2912 case RTE_ETH_EVENT_NEW:
2913 ports[port_id].need_setup = 1;
2914 ports[port_id].port_status = RTE_PORT_HANDLING;
2916 case RTE_ETH_EVENT_INTR_RMV:
2917 if (port_id_is_invalid(port_id, DISABLED_WARN))
2919 if (rte_eal_alarm_set(100000,
2920 rmv_port_callback, (void *)(intptr_t)port_id))
2921 fprintf(stderr, "Could not set up deferred device removal\n");
2930 register_eth_event_callback(void)
2933 enum rte_eth_event_type event;
2935 for (event = RTE_ETH_EVENT_UNKNOWN;
2936 event < RTE_ETH_EVENT_MAX; event++) {
2937 ret = rte_eth_dev_callback_register(RTE_ETH_ALL,
2942 TESTPMD_LOG(ERR, "Failed to register callback for "
2943 "%s event\n", eth_event_desc[event]);
2951 /* This function is used by the interrupt thread */
2953 dev_event_callback(const char *device_name, enum rte_dev_event_type type,
2954 __rte_unused void *arg)
2959 if (type >= RTE_DEV_EVENT_MAX) {
2960 fprintf(stderr, "%s called upon invalid event %d\n",
2966 case RTE_DEV_EVENT_REMOVE:
2967 RTE_LOG(DEBUG, EAL, "The device: %s has been removed!\n",
2969 ret = rte_eth_dev_get_port_by_name(device_name, &port_id);
2971 RTE_LOG(ERR, EAL, "can not get port by device %s!\n",
2976 * Because the user's callback is invoked in eal interrupt
2977 * callback, the interrupt callback need to be finished before
2978 * it can be unregistered when detaching device. So finish
2979 * callback soon and use a deferred removal to detach device
2980 * is need. It is a workaround, once the device detaching be
2981 * moved into the eal in the future, the deferred removal could
2984 if (rte_eal_alarm_set(100000,
2985 rmv_port_callback, (void *)(intptr_t)port_id))
2987 "Could not set up deferred device removal\n");
2989 case RTE_DEV_EVENT_ADD:
2990 RTE_LOG(ERR, EAL, "The device: %s has been added!\n",
2992 /* TODO: After finish kernel driver binding,
2993 * begin to attach port.
3002 set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
3006 uint8_t mapping_found = 0;
3008 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
3009 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
3010 (tx_queue_stats_mappings[i].queue_id < nb_txq )) {
3011 diag = rte_eth_dev_set_tx_queue_stats_mapping(port_id,
3012 tx_queue_stats_mappings[i].queue_id,
3013 tx_queue_stats_mappings[i].stats_counter_id);
3020 port->tx_queue_stats_mapping_enabled = 1;
3025 set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
3029 uint8_t mapping_found = 0;
3031 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
3032 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
3033 (rx_queue_stats_mappings[i].queue_id < nb_rxq )) {
3034 diag = rte_eth_dev_set_rx_queue_stats_mapping(port_id,
3035 rx_queue_stats_mappings[i].queue_id,
3036 rx_queue_stats_mappings[i].stats_counter_id);
3043 port->rx_queue_stats_mapping_enabled = 1;
3048 map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
3052 diag = set_tx_queue_stats_mapping_registers(pi, port);
3054 if (diag == -ENOTSUP) {
3055 port->tx_queue_stats_mapping_enabled = 0;
3056 printf("TX queue stats mapping not supported port id=%d\n", pi);
3059 rte_exit(EXIT_FAILURE,
3060 "set_tx_queue_stats_mapping_registers "
3061 "failed for port id=%d diag=%d\n",
3065 diag = set_rx_queue_stats_mapping_registers(pi, port);
3067 if (diag == -ENOTSUP) {
3068 port->rx_queue_stats_mapping_enabled = 0;
3069 printf("RX queue stats mapping not supported port id=%d\n", pi);
3072 rte_exit(EXIT_FAILURE,
3073 "set_rx_queue_stats_mapping_registers "
3074 "failed for port id=%d diag=%d\n",
3080 rxtx_port_config(struct rte_port *port)
3085 for (qid = 0; qid < nb_rxq; qid++) {
3086 offloads = port->rx_conf[qid].offloads;
3087 port->rx_conf[qid] = port->dev_info.default_rxconf;
3089 port->rx_conf[qid].offloads = offloads;
3091 /* Check if any Rx parameters have been passed */
3092 if (rx_pthresh != RTE_PMD_PARAM_UNSET)
3093 port->rx_conf[qid].rx_thresh.pthresh = rx_pthresh;
3095 if (rx_hthresh != RTE_PMD_PARAM_UNSET)
3096 port->rx_conf[qid].rx_thresh.hthresh = rx_hthresh;
3098 if (rx_wthresh != RTE_PMD_PARAM_UNSET)
3099 port->rx_conf[qid].rx_thresh.wthresh = rx_wthresh;
3101 if (rx_free_thresh != RTE_PMD_PARAM_UNSET)
3102 port->rx_conf[qid].rx_free_thresh = rx_free_thresh;
3104 if (rx_drop_en != RTE_PMD_PARAM_UNSET)
3105 port->rx_conf[qid].rx_drop_en = rx_drop_en;
3107 port->nb_rx_desc[qid] = nb_rxd;
3110 for (qid = 0; qid < nb_txq; qid++) {
3111 offloads = port->tx_conf[qid].offloads;
3112 port->tx_conf[qid] = port->dev_info.default_txconf;
3114 port->tx_conf[qid].offloads = offloads;
3116 /* Check if any Tx parameters have been passed */
3117 if (tx_pthresh != RTE_PMD_PARAM_UNSET)
3118 port->tx_conf[qid].tx_thresh.pthresh = tx_pthresh;
3120 if (tx_hthresh != RTE_PMD_PARAM_UNSET)
3121 port->tx_conf[qid].tx_thresh.hthresh = tx_hthresh;
3123 if (tx_wthresh != RTE_PMD_PARAM_UNSET)
3124 port->tx_conf[qid].tx_thresh.wthresh = tx_wthresh;
3126 if (tx_rs_thresh != RTE_PMD_PARAM_UNSET)
3127 port->tx_conf[qid].tx_rs_thresh = tx_rs_thresh;
3129 if (tx_free_thresh != RTE_PMD_PARAM_UNSET)
3130 port->tx_conf[qid].tx_free_thresh = tx_free_thresh;
3132 port->nb_tx_desc[qid] = nb_txd;
3137 init_port_config(void)
3140 struct rte_port *port;
3143 RTE_ETH_FOREACH_DEV(pid) {
3145 port->dev_conf.fdir_conf = fdir_conf;
3147 ret = eth_dev_info_get_print_err(pid, &port->dev_info);
3152 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
3153 port->dev_conf.rx_adv_conf.rss_conf.rss_hf =
3154 rss_hf & port->dev_info.flow_type_rss_offloads;
3156 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
3157 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = 0;
3160 if (port->dcb_flag == 0) {
3161 if( port->dev_conf.rx_adv_conf.rss_conf.rss_hf != 0)
3162 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
3164 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
3167 rxtx_port_config(port);
3169 ret = eth_macaddr_get_print_err(pid, &port->eth_addr);
3173 map_port_queue_stats_mapping_registers(pid, port);
3174 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
3175 rte_pmd_ixgbe_bypass_init(pid);
3178 if (lsc_interrupt &&
3179 (rte_eth_devices[pid].data->dev_flags &
3180 RTE_ETH_DEV_INTR_LSC))
3181 port->dev_conf.intr_conf.lsc = 1;
3182 if (rmv_interrupt &&
3183 (rte_eth_devices[pid].data->dev_flags &
3184 RTE_ETH_DEV_INTR_RMV))
3185 port->dev_conf.intr_conf.rmv = 1;
3189 void set_port_slave_flag(portid_t slave_pid)
3191 struct rte_port *port;
3193 port = &ports[slave_pid];
3194 port->slave_flag = 1;
3197 void clear_port_slave_flag(portid_t slave_pid)
3199 struct rte_port *port;
3201 port = &ports[slave_pid];
3202 port->slave_flag = 0;
3205 uint8_t port_is_bonding_slave(portid_t slave_pid)
3207 struct rte_port *port;
3209 port = &ports[slave_pid];
3210 if ((rte_eth_devices[slave_pid].data->dev_flags &
3211 RTE_ETH_DEV_BONDED_SLAVE) || (port->slave_flag == 1))
3216 const uint16_t vlan_tags[] = {
3217 0, 1, 2, 3, 4, 5, 6, 7,
3218 8, 9, 10, 11, 12, 13, 14, 15,
3219 16, 17, 18, 19, 20, 21, 22, 23,
3220 24, 25, 26, 27, 28, 29, 30, 31
3224 get_eth_dcb_conf(portid_t pid, struct rte_eth_conf *eth_conf,
3225 enum dcb_mode_enable dcb_mode,
3226 enum rte_eth_nb_tcs num_tcs,
3231 struct rte_eth_rss_conf rss_conf;
3234 * Builds up the correct configuration for dcb+vt based on the vlan tags array
3235 * given above, and the number of traffic classes available for use.
3237 if (dcb_mode == DCB_VT_ENABLED) {
3238 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
3239 ð_conf->rx_adv_conf.vmdq_dcb_conf;
3240 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
3241 ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
3243 /* VMDQ+DCB RX and TX configurations */
3244 vmdq_rx_conf->enable_default_pool = 0;
3245 vmdq_rx_conf->default_pool = 0;
3246 vmdq_rx_conf->nb_queue_pools =
3247 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
3248 vmdq_tx_conf->nb_queue_pools =
3249 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
3251 vmdq_rx_conf->nb_pool_maps = vmdq_rx_conf->nb_queue_pools;
3252 for (i = 0; i < vmdq_rx_conf->nb_pool_maps; i++) {
3253 vmdq_rx_conf->pool_map[i].vlan_id = vlan_tags[i];
3254 vmdq_rx_conf->pool_map[i].pools =
3255 1 << (i % vmdq_rx_conf->nb_queue_pools);
3257 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3258 vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
3259 vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
3262 /* set DCB mode of RX and TX of multiple queues */
3263 eth_conf->rxmode.mq_mode = ETH_MQ_RX_VMDQ_DCB;
3264 eth_conf->txmode.mq_mode = ETH_MQ_TX_VMDQ_DCB;
3266 struct rte_eth_dcb_rx_conf *rx_conf =
3267 ð_conf->rx_adv_conf.dcb_rx_conf;
3268 struct rte_eth_dcb_tx_conf *tx_conf =
3269 ð_conf->tx_adv_conf.dcb_tx_conf;
3271 rc = rte_eth_dev_rss_hash_conf_get(pid, &rss_conf);
3275 rx_conf->nb_tcs = num_tcs;
3276 tx_conf->nb_tcs = num_tcs;
3278 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
3279 rx_conf->dcb_tc[i] = i % num_tcs;
3280 tx_conf->dcb_tc[i] = i % num_tcs;
3283 eth_conf->rxmode.mq_mode = ETH_MQ_RX_DCB_RSS;
3284 eth_conf->rx_adv_conf.rss_conf = rss_conf;
3285 eth_conf->txmode.mq_mode = ETH_MQ_TX_DCB;
3289 eth_conf->dcb_capability_en =
3290 ETH_DCB_PG_SUPPORT | ETH_DCB_PFC_SUPPORT;
3292 eth_conf->dcb_capability_en = ETH_DCB_PG_SUPPORT;
3298 init_port_dcb_config(portid_t pid,
3299 enum dcb_mode_enable dcb_mode,
3300 enum rte_eth_nb_tcs num_tcs,
3303 struct rte_eth_conf port_conf;
3304 struct rte_port *rte_port;
3308 rte_port = &ports[pid];
3310 memset(&port_conf, 0, sizeof(struct rte_eth_conf));
3311 /* Enter DCB configuration status */
3314 port_conf.rxmode = rte_port->dev_conf.rxmode;
3315 port_conf.txmode = rte_port->dev_conf.txmode;
3317 /*set configuration of DCB in vt mode and DCB in non-vt mode*/
3318 retval = get_eth_dcb_conf(pid, &port_conf, dcb_mode, num_tcs, pfc_en);
3321 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3323 /* re-configure the device . */
3324 retval = rte_eth_dev_configure(pid, nb_rxq, nb_rxq, &port_conf);
3328 retval = eth_dev_info_get_print_err(pid, &rte_port->dev_info);
3332 /* If dev_info.vmdq_pool_base is greater than 0,
3333 * the queue id of vmdq pools is started after pf queues.
3335 if (dcb_mode == DCB_VT_ENABLED &&
3336 rte_port->dev_info.vmdq_pool_base > 0) {
3337 printf("VMDQ_DCB multi-queue mode is nonsensical"
3338 " for port %d.", pid);
3342 /* Assume the ports in testpmd have the same dcb capability
3343 * and has the same number of rxq and txq in dcb mode
3345 if (dcb_mode == DCB_VT_ENABLED) {
3346 if (rte_port->dev_info.max_vfs > 0) {
3347 nb_rxq = rte_port->dev_info.nb_rx_queues;
3348 nb_txq = rte_port->dev_info.nb_tx_queues;
3350 nb_rxq = rte_port->dev_info.max_rx_queues;
3351 nb_txq = rte_port->dev_info.max_tx_queues;
3354 /*if vt is disabled, use all pf queues */
3355 if (rte_port->dev_info.vmdq_pool_base == 0) {
3356 nb_rxq = rte_port->dev_info.max_rx_queues;
3357 nb_txq = rte_port->dev_info.max_tx_queues;
3359 nb_rxq = (queueid_t)num_tcs;
3360 nb_txq = (queueid_t)num_tcs;
3364 rx_free_thresh = 64;
3366 memcpy(&rte_port->dev_conf, &port_conf, sizeof(struct rte_eth_conf));
3368 rxtx_port_config(rte_port);
3370 rte_port->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
3371 for (i = 0; i < RTE_DIM(vlan_tags); i++)
3372 rx_vft_set(pid, vlan_tags[i], 1);
3374 retval = eth_macaddr_get_print_err(pid, &rte_port->eth_addr);
3378 map_port_queue_stats_mapping_registers(pid, rte_port);
3380 rte_port->dcb_flag = 1;
3388 /* Configuration of Ethernet ports. */
3389 ports = rte_zmalloc("testpmd: ports",
3390 sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
3391 RTE_CACHE_LINE_SIZE);
3392 if (ports == NULL) {
3393 rte_exit(EXIT_FAILURE,
3394 "rte_zmalloc(%d struct rte_port) failed\n",
3398 /* Initialize ports NUMA structures */
3399 memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
3400 memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
3401 memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
3415 const char clr[] = { 27, '[', '2', 'J', '\0' };
3416 const char top_left[] = { 27, '[', '1', ';', '1', 'H', '\0' };
3418 /* Clear screen and move to top left */
3419 printf("%s%s", clr, top_left);
3421 printf("\nPort statistics ====================================");
3422 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
3423 nic_stats_display(fwd_ports_ids[i]);
3429 signal_handler(int signum)
3431 if (signum == SIGINT || signum == SIGTERM) {
3432 printf("\nSignal %d received, preparing to exit...\n",
3434 #ifdef RTE_LIBRTE_PDUMP
3435 /* uninitialize packet capture framework */
3438 #ifdef RTE_LIBRTE_LATENCY_STATS
3439 if (latencystats_enabled != 0)
3440 rte_latencystats_uninit();
3443 /* Set flag to indicate the force termination. */
3445 /* exit with the expected status */
3446 signal(signum, SIG_DFL);
3447 kill(getpid(), signum);
3452 main(int argc, char** argv)
3459 signal(SIGINT, signal_handler);
3460 signal(SIGTERM, signal_handler);
3462 testpmd_logtype = rte_log_register("testpmd");
3463 if (testpmd_logtype < 0)
3464 rte_exit(EXIT_FAILURE, "Cannot register log type");
3465 rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
3467 diag = rte_eal_init(argc, argv);
3469 rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
3470 rte_strerror(rte_errno));
3472 if (rte_eal_process_type() == RTE_PROC_SECONDARY)
3473 rte_exit(EXIT_FAILURE,
3474 "Secondary process type not supported.\n");
3476 ret = register_eth_event_callback();
3478 rte_exit(EXIT_FAILURE, "Cannot register for ethdev events");
3480 #ifdef RTE_LIBRTE_PDUMP
3481 /* initialize packet capture framework */
3486 RTE_ETH_FOREACH_DEV(port_id) {
3487 ports_ids[count] = port_id;
3490 nb_ports = (portid_t) count;
3492 TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
3494 /* allocate port structures, and init them */
3497 set_def_fwd_config();
3499 rte_exit(EXIT_FAILURE, "No cores defined for forwarding\n"
3500 "Check the core mask argument\n");
3502 /* Bitrate/latency stats disabled by default */
3503 #ifdef RTE_LIBRTE_BITRATE
3504 bitrate_enabled = 0;
3506 #ifdef RTE_LIBRTE_LATENCY_STATS
3507 latencystats_enabled = 0;
3510 /* on FreeBSD, mlockall() is disabled by default */
3511 #ifdef RTE_EXEC_ENV_FREEBSD
3520 launch_args_parse(argc, argv);
3522 if (do_mlockall && mlockall(MCL_CURRENT | MCL_FUTURE)) {
3523 TESTPMD_LOG(NOTICE, "mlockall() failed with error \"%s\"\n",
3527 if (tx_first && interactive)
3528 rte_exit(EXIT_FAILURE, "--tx-first cannot be used on "
3529 "interactive mode.\n");
3531 if (tx_first && lsc_interrupt) {
3532 printf("Warning: lsc_interrupt needs to be off when "
3533 " using tx_first. Disabling.\n");
3537 if (!nb_rxq && !nb_txq)
3538 printf("Warning: Either rx or tx queues should be non-zero\n");
3540 if (nb_rxq > 1 && nb_rxq > nb_txq)
3541 printf("Warning: nb_rxq=%d enables RSS configuration, "
3542 "but nb_txq=%d will prevent to fully test it.\n",
3548 ret = rte_dev_hotplug_handle_enable();
3551 "fail to enable hotplug handling.");
3555 ret = rte_dev_event_monitor_start();
3558 "fail to start device event monitoring.");
3562 ret = rte_dev_event_callback_register(NULL,
3563 dev_event_callback, NULL);
3566 "fail to register device event callback\n");
3571 if (!no_device_start && start_port(RTE_PORT_ALL) != 0)
3572 rte_exit(EXIT_FAILURE, "Start ports failed\n");
3574 /* set all ports to promiscuous mode by default */
3575 RTE_ETH_FOREACH_DEV(port_id) {
3576 ret = rte_eth_promiscuous_enable(port_id);
3578 printf("Error during enabling promiscuous mode for port %u: %s - ignore\n",
3579 port_id, rte_strerror(-ret));
3582 /* Init metrics library */
3583 rte_metrics_init(rte_socket_id());
3585 #ifdef RTE_LIBRTE_LATENCY_STATS
3586 if (latencystats_enabled != 0) {
3587 int ret = rte_latencystats_init(1, NULL);
3589 printf("Warning: latencystats init()"
3590 " returned error %d\n", ret);
3591 printf("Latencystats running on lcore %d\n",
3592 latencystats_lcore_id);
3596 /* Setup bitrate stats */
3597 #ifdef RTE_LIBRTE_BITRATE
3598 if (bitrate_enabled != 0) {
3599 bitrate_data = rte_stats_bitrate_create();
3600 if (bitrate_data == NULL)
3601 rte_exit(EXIT_FAILURE,
3602 "Could not allocate bitrate data.\n");
3603 rte_stats_bitrate_reg(bitrate_data);
3607 #ifdef RTE_LIBRTE_CMDLINE
3608 if (strlen(cmdline_filename) != 0)
3609 cmdline_read_from_file(cmdline_filename);
3611 if (interactive == 1) {
3613 printf("Start automatic packet forwarding\n");
3614 start_packet_forwarding(0);
3626 printf("No commandline core given, start packet forwarding\n");
3627 start_packet_forwarding(tx_first);
3628 if (stats_period != 0) {
3629 uint64_t prev_time = 0, cur_time, diff_time = 0;
3630 uint64_t timer_period;
3632 /* Convert to number of cycles */
3633 timer_period = stats_period * rte_get_timer_hz();
3635 while (f_quit == 0) {
3636 cur_time = rte_get_timer_cycles();
3637 diff_time += cur_time - prev_time;
3639 if (diff_time >= timer_period) {
3641 /* Reset the timer */
3644 /* Sleep to avoid unnecessary checks */
3645 prev_time = cur_time;
3650 printf("Press enter to exit\n");
3651 rc = read(0, &c, 1);
3657 ret = rte_eal_cleanup();
3659 rte_exit(EXIT_FAILURE,
3660 "EAL cleanup failed: %s\n", strerror(-ret));
3662 return EXIT_SUCCESS;