1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
13 #include <sys/types.h>
16 #include <sys/queue.h>
23 #include <rte_common.h>
24 #include <rte_errno.h>
25 #include <rte_byteorder.h>
27 #include <rte_debug.h>
28 #include <rte_cycles.h>
29 #include <rte_memory.h>
30 #include <rte_memcpy.h>
31 #include <rte_launch.h>
33 #include <rte_alarm.h>
34 #include <rte_per_lcore.h>
35 #include <rte_lcore.h>
36 #include <rte_atomic.h>
37 #include <rte_branch_prediction.h>
38 #include <rte_mempool.h>
39 #include <rte_malloc.h>
41 #include <rte_mbuf_pool_ops.h>
42 #include <rte_interrupts.h>
44 #include <rte_ether.h>
45 #include <rte_ethdev.h>
47 #include <rte_string_fns.h>
48 #ifdef RTE_LIBRTE_IXGBE_PMD
49 #include <rte_pmd_ixgbe.h>
51 #ifdef RTE_LIBRTE_PDUMP
52 #include <rte_pdump.h>
55 #include <rte_metrics.h>
56 #ifdef RTE_LIBRTE_BITRATE
57 #include <rte_bitrate.h>
59 #ifdef RTE_LIBRTE_LATENCY_STATS
60 #include <rte_latencystats.h>
65 uint16_t verbose_level = 0; /**< Silent by default. */
66 int testpmd_logtype; /**< Log type for testpmd logs */
68 /* use master core for command line ? */
69 uint8_t interactive = 0;
70 uint8_t auto_start = 0;
72 char cmdline_filename[PATH_MAX] = {0};
75 * NUMA support configuration.
76 * When set, the NUMA support attempts to dispatch the allocation of the
77 * RX and TX memory rings, and of the DMA memory buffers (mbufs) for the
78 * probed ports among the CPU sockets 0 and 1.
79 * Otherwise, all memory is allocated from CPU socket 0.
81 uint8_t numa_support = 1; /**< numa enabled by default */
84 * In UMA mode,all memory is allocated from socket 0 if --socket-num is
87 uint8_t socket_num = UMA_NO_CONFIG;
90 * Use ANONYMOUS mapped memory (might be not physically continuous) for mbufs.
95 * Record the Ethernet address of peer target ports to which packets are
97 * Must be instantiated with the ethernet addresses of peer traffic generator
100 struct ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
101 portid_t nb_peer_eth_addrs = 0;
104 * Probed Target Environment.
106 struct rte_port *ports; /**< For all probed ethernet ports. */
107 portid_t nb_ports; /**< Number of probed ethernet ports. */
108 struct fwd_lcore **fwd_lcores; /**< For all probed logical cores. */
109 lcoreid_t nb_lcores; /**< Number of probed logical cores. */
112 * Test Forwarding Configuration.
113 * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
114 * nb_fwd_ports <= nb_cfg_ports <= nb_ports
116 lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
117 lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
118 portid_t nb_cfg_ports; /**< Number of configured ports. */
119 portid_t nb_fwd_ports; /**< Number of forwarding ports. */
121 unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE]; /**< CPU ids configuration. */
122 portid_t fwd_ports_ids[RTE_MAX_ETHPORTS]; /**< Port ids configuration. */
124 struct fwd_stream **fwd_streams; /**< For each RX queue of each port. */
125 streamid_t nb_fwd_streams; /**< Is equal to (nb_ports * nb_rxq). */
128 * Forwarding engines.
130 struct fwd_engine * fwd_engines[] = {
139 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
141 &softnic_tm_bypass_engine,
143 #ifdef RTE_LIBRTE_IEEE1588
144 &ieee1588_fwd_engine,
149 struct fwd_config cur_fwd_config;
150 struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */
151 uint32_t retry_enabled;
152 uint32_t burst_tx_delay_time = BURST_TX_WAIT_US;
153 uint32_t burst_tx_retry_num = BURST_TX_RETRIES;
155 uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
156 uint32_t param_total_num_mbufs = 0; /**< number of mbufs in all pools - if
157 * specified on command-line. */
158 uint16_t stats_period; /**< Period to show statistics (disabled by default) */
161 * In container, it cannot terminate the process which running with 'stats-period'
162 * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
167 * Configuration of packet segments used by the "txonly" processing engine.
169 uint16_t tx_pkt_length = TXONLY_DEF_PACKET_LEN; /**< TXONLY packet length. */
170 uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT] = {
171 TXONLY_DEF_PACKET_LEN,
173 uint8_t tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */
175 enum tx_pkt_split tx_pkt_split = TX_PKT_SPLIT_OFF;
176 /**< Split policy for packets to TX. */
178 uint16_t nb_pkt_per_burst = DEF_PKT_BURST; /**< Number of packets per burst. */
179 uint16_t mb_mempool_cache = DEF_MBUF_CACHE; /**< Size of mbuf mempool cache. */
181 /* current configuration is in DCB or not,0 means it is not in DCB mode */
182 uint8_t dcb_config = 0;
184 /* Whether the dcb is in testing status */
185 uint8_t dcb_test = 0;
188 * Configurable number of RX/TX queues.
190 queueid_t nb_rxq = 1; /**< Number of RX queues per port. */
191 queueid_t nb_txq = 1; /**< Number of TX queues per port. */
194 * Configurable number of RX/TX ring descriptors.
196 #define RTE_TEST_RX_DESC_DEFAULT 128
197 #define RTE_TEST_TX_DESC_DEFAULT 512
198 uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; /**< Number of RX descriptors. */
199 uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; /**< Number of TX descriptors. */
201 #define RTE_PMD_PARAM_UNSET -1
203 * Configurable values of RX and TX ring threshold registers.
206 int8_t rx_pthresh = RTE_PMD_PARAM_UNSET;
207 int8_t rx_hthresh = RTE_PMD_PARAM_UNSET;
208 int8_t rx_wthresh = RTE_PMD_PARAM_UNSET;
210 int8_t tx_pthresh = RTE_PMD_PARAM_UNSET;
211 int8_t tx_hthresh = RTE_PMD_PARAM_UNSET;
212 int8_t tx_wthresh = RTE_PMD_PARAM_UNSET;
215 * Configurable value of RX free threshold.
217 int16_t rx_free_thresh = RTE_PMD_PARAM_UNSET;
220 * Configurable value of RX drop enable.
222 int8_t rx_drop_en = RTE_PMD_PARAM_UNSET;
225 * Configurable value of TX free threshold.
227 int16_t tx_free_thresh = RTE_PMD_PARAM_UNSET;
230 * Configurable value of TX RS bit threshold.
232 int16_t tx_rs_thresh = RTE_PMD_PARAM_UNSET;
235 * Receive Side Scaling (RSS) configuration.
237 uint64_t rss_hf = ETH_RSS_IP; /* RSS IP by default. */
240 * Port topology configuration
242 uint16_t port_topology = PORT_TOPOLOGY_PAIRED; /* Ports are paired by default */
245 * Avoids to flush all the RX streams before starts forwarding.
247 uint8_t no_flush_rx = 0; /* flush by default */
250 * Flow API isolated mode.
252 uint8_t flow_isolate_all;
255 * Avoids to check link status when starting/stopping a port.
257 uint8_t no_link_check = 0; /* check by default */
260 * Enable link status change notification
262 uint8_t lsc_interrupt = 1; /* enabled by default */
265 * Enable device removal notification.
267 uint8_t rmv_interrupt = 1; /* enabled by default */
270 * Display or mask ether events
271 * Default to all events except VF_MBOX
273 uint32_t event_print_mask = (UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN) |
274 (UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC) |
275 (UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE) |
276 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET) |
277 (UINT32_C(1) << RTE_ETH_EVENT_MACSEC) |
278 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV);
281 * NIC bypass mode configuration options.
284 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
285 /* The NIC bypass watchdog timeout. */
286 uint32_t bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
290 #ifdef RTE_LIBRTE_LATENCY_STATS
293 * Set when latency stats is enabled in the commandline
295 uint8_t latencystats_enabled;
298 * Lcore ID to serive latency statistics.
300 lcoreid_t latencystats_lcore_id = -1;
305 * Ethernet device configuration.
307 struct rte_eth_rxmode rx_mode = {
308 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
309 .offloads = (DEV_RX_OFFLOAD_VLAN_FILTER |
310 DEV_RX_OFFLOAD_VLAN_STRIP |
311 DEV_RX_OFFLOAD_CRC_STRIP),
312 .ignore_offload_bitfield = 1,
315 struct rte_eth_txmode tx_mode = {
316 .offloads = DEV_TX_OFFLOAD_MBUF_FAST_FREE,
319 struct rte_fdir_conf fdir_conf = {
320 .mode = RTE_FDIR_MODE_NONE,
321 .pballoc = RTE_FDIR_PBALLOC_64K,
322 .status = RTE_FDIR_REPORT_STATUS,
324 .vlan_tci_mask = 0x0,
326 .src_ip = 0xFFFFFFFF,
327 .dst_ip = 0xFFFFFFFF,
330 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
331 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
333 .src_port_mask = 0xFFFF,
334 .dst_port_mask = 0xFFFF,
335 .mac_addr_byte_mask = 0xFF,
336 .tunnel_type_mask = 1,
337 .tunnel_id_mask = 0xFFFFFFFF,
342 volatile int test_done = 1; /* stop packet forwarding when set to 1. */
344 struct queue_stats_mappings tx_queue_stats_mappings_array[MAX_TX_QUEUE_STATS_MAPPINGS];
345 struct queue_stats_mappings rx_queue_stats_mappings_array[MAX_RX_QUEUE_STATS_MAPPINGS];
347 struct queue_stats_mappings *tx_queue_stats_mappings = tx_queue_stats_mappings_array;
348 struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_array;
350 uint16_t nb_tx_queue_stats_mappings = 0;
351 uint16_t nb_rx_queue_stats_mappings = 0;
354 * Display zero values by default for xstats
356 uint8_t xstats_hide_zero;
358 unsigned int num_sockets = 0;
359 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
361 #ifdef RTE_LIBRTE_BITRATE
362 /* Bitrate statistics */
363 struct rte_stats_bitrates *bitrate_data;
364 lcoreid_t bitrate_lcore_id;
365 uint8_t bitrate_enabled;
368 struct gro_status gro_ports[RTE_MAX_ETHPORTS];
369 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
371 /* Forward function declarations */
372 static void map_port_queue_stats_mapping_registers(portid_t pi,
373 struct rte_port *port);
374 static void check_all_ports_link_status(uint32_t port_mask);
375 static int eth_event_callback(portid_t port_id,
376 enum rte_eth_event_type type,
377 void *param, void *ret_param);
380 * Check if all the ports are started.
381 * If yes, return positive value. If not, return zero.
383 static int all_ports_started(void);
385 struct gso_status gso_ports[RTE_MAX_ETHPORTS];
386 uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
389 * Helper function to check if socket is already discovered.
390 * If yes, return positive value. If not, return zero.
393 new_socket_id(unsigned int socket_id)
397 for (i = 0; i < num_sockets; i++) {
398 if (socket_ids[i] == socket_id)
405 * Setup default configuration.
408 set_default_fwd_lcores_config(void)
412 unsigned int sock_num;
415 for (i = 0; i < RTE_MAX_LCORE; i++) {
416 sock_num = rte_lcore_to_socket_id(i);
417 if (new_socket_id(sock_num)) {
418 if (num_sockets >= RTE_MAX_NUMA_NODES) {
419 rte_exit(EXIT_FAILURE,
420 "Total sockets greater than %u\n",
423 socket_ids[num_sockets++] = sock_num;
425 if (!rte_lcore_is_enabled(i))
427 if (i == rte_get_master_lcore())
429 fwd_lcores_cpuids[nb_lc++] = i;
431 nb_lcores = (lcoreid_t) nb_lc;
432 nb_cfg_lcores = nb_lcores;
437 set_def_peer_eth_addrs(void)
441 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
442 peer_eth_addrs[i].addr_bytes[0] = ETHER_LOCAL_ADMIN_ADDR;
443 peer_eth_addrs[i].addr_bytes[5] = i;
448 set_default_fwd_ports_config(void)
453 RTE_ETH_FOREACH_DEV(pt_id)
454 fwd_ports_ids[i++] = pt_id;
456 nb_cfg_ports = nb_ports;
457 nb_fwd_ports = nb_ports;
461 set_def_fwd_config(void)
463 set_default_fwd_lcores_config();
464 set_def_peer_eth_addrs();
465 set_default_fwd_ports_config();
469 * Configuration initialisation done once at init time.
472 mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
473 unsigned int socket_id)
475 char pool_name[RTE_MEMPOOL_NAMESIZE];
476 struct rte_mempool *rte_mp = NULL;
479 mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
480 mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
483 "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
484 pool_name, nb_mbuf, mbuf_seg_size, socket_id);
487 rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf,
488 mb_size, (unsigned) mb_mempool_cache,
489 sizeof(struct rte_pktmbuf_pool_private),
494 if (rte_mempool_populate_anon(rte_mp) == 0) {
495 rte_mempool_free(rte_mp);
499 rte_pktmbuf_pool_init(rte_mp, NULL);
500 rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
502 /* wrapper to rte_mempool_create() */
503 TESTPMD_LOG(INFO, "preferred mempool ops selected: %s\n",
504 rte_mbuf_best_mempool_ops());
505 rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
506 mb_mempool_cache, 0, mbuf_seg_size, socket_id);
510 if (rte_mp == NULL) {
511 rte_exit(EXIT_FAILURE,
512 "Creation of mbuf pool for socket %u failed: %s\n",
513 socket_id, rte_strerror(rte_errno));
514 } else if (verbose_level > 0) {
515 rte_mempool_dump(stdout, rte_mp);
520 * Check given socket id is valid or not with NUMA mode,
521 * if valid, return 0, else return -1
524 check_socket_id(const unsigned int socket_id)
526 static int warning_once = 0;
528 if (new_socket_id(socket_id)) {
529 if (!warning_once && numa_support)
530 printf("Warning: NUMA should be configured manually by"
531 " using --port-numa-config and"
532 " --ring-numa-config parameters along with"
541 * Get the allowed maximum number of RX queues.
542 * *pid return the port id which has minimal value of
543 * max_rx_queues in all ports.
546 get_allowed_max_nb_rxq(portid_t *pid)
548 queueid_t allowed_max_rxq = MAX_QUEUE_ID;
550 struct rte_eth_dev_info dev_info;
552 RTE_ETH_FOREACH_DEV(pi) {
553 rte_eth_dev_info_get(pi, &dev_info);
554 if (dev_info.max_rx_queues < allowed_max_rxq) {
555 allowed_max_rxq = dev_info.max_rx_queues;
559 return allowed_max_rxq;
563 * Check input rxq is valid or not.
564 * If input rxq is not greater than any of maximum number
565 * of RX queues of all ports, it is valid.
566 * if valid, return 0, else return -1
569 check_nb_rxq(queueid_t rxq)
571 queueid_t allowed_max_rxq;
574 allowed_max_rxq = get_allowed_max_nb_rxq(&pid);
575 if (rxq > allowed_max_rxq) {
576 printf("Fail: input rxq (%u) can't be greater "
577 "than max_rx_queues (%u) of port %u\n",
587 * Get the allowed maximum number of TX queues.
588 * *pid return the port id which has minimal value of
589 * max_tx_queues in all ports.
592 get_allowed_max_nb_txq(portid_t *pid)
594 queueid_t allowed_max_txq = MAX_QUEUE_ID;
596 struct rte_eth_dev_info dev_info;
598 RTE_ETH_FOREACH_DEV(pi) {
599 rte_eth_dev_info_get(pi, &dev_info);
600 if (dev_info.max_tx_queues < allowed_max_txq) {
601 allowed_max_txq = dev_info.max_tx_queues;
605 return allowed_max_txq;
609 * Check input txq is valid or not.
610 * If input txq is not greater than any of maximum number
611 * of TX queues of all ports, it is valid.
612 * if valid, return 0, else return -1
615 check_nb_txq(queueid_t txq)
617 queueid_t allowed_max_txq;
620 allowed_max_txq = get_allowed_max_nb_txq(&pid);
621 if (txq > allowed_max_txq) {
622 printf("Fail: input txq (%u) can't be greater "
623 "than max_tx_queues (%u) of port %u\n",
636 struct rte_port *port;
637 struct rte_mempool *mbp;
638 unsigned int nb_mbuf_per_pool;
640 uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
641 struct rte_gro_param gro_param;
644 memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
647 memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
648 memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
649 memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
652 /* Configuration of logical cores. */
653 fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
654 sizeof(struct fwd_lcore *) * nb_lcores,
655 RTE_CACHE_LINE_SIZE);
656 if (fwd_lcores == NULL) {
657 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_lcore *)) "
658 "failed\n", nb_lcores);
660 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
661 fwd_lcores[lc_id] = rte_zmalloc("testpmd: struct fwd_lcore",
662 sizeof(struct fwd_lcore),
663 RTE_CACHE_LINE_SIZE);
664 if (fwd_lcores[lc_id] == NULL) {
665 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_lcore) "
668 fwd_lcores[lc_id]->cpuid_idx = lc_id;
671 RTE_ETH_FOREACH_DEV(pid) {
673 /* Apply default Tx configuration for all ports */
674 port->dev_conf.txmode = tx_mode;
675 port->dev_conf.rxmode = rx_mode;
676 rte_eth_dev_info_get(pid, &port->dev_info);
677 if (!(port->dev_info.tx_offload_capa &
678 DEV_TX_OFFLOAD_MBUF_FAST_FREE))
679 port->dev_conf.txmode.offloads &=
680 ~DEV_TX_OFFLOAD_MBUF_FAST_FREE;
683 if (port_numa[pid] != NUMA_NO_CONFIG)
684 port_per_socket[port_numa[pid]]++;
686 uint32_t socket_id = rte_eth_dev_socket_id(pid);
688 /* if socket_id is invalid, set to 0 */
689 if (check_socket_id(socket_id) < 0)
691 port_per_socket[socket_id]++;
695 /* set flag to initialize port/queue */
696 port->need_reconfig = 1;
697 port->need_reconfig_queues = 1;
701 * Create pools of mbuf.
702 * If NUMA support is disabled, create a single pool of mbuf in
703 * socket 0 memory by default.
704 * Otherwise, create a pool of mbuf in the memory of sockets 0 and 1.
706 * Use the maximum value of nb_rxd and nb_txd here, then nb_rxd and
707 * nb_txd can be configured at run time.
709 if (param_total_num_mbufs)
710 nb_mbuf_per_pool = param_total_num_mbufs;
712 nb_mbuf_per_pool = RTE_TEST_RX_DESC_MAX +
713 (nb_lcores * mb_mempool_cache) +
714 RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
715 nb_mbuf_per_pool *= RTE_MAX_ETHPORTS;
721 for (i = 0; i < num_sockets; i++)
722 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
725 if (socket_num == UMA_NO_CONFIG)
726 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 0);
728 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
734 gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
735 DEV_TX_OFFLOAD_GRE_TNL_TSO;
737 * Records which Mbuf pool to use by each logical core, if needed.
739 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
740 mbp = mbuf_pool_find(
741 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]));
744 mbp = mbuf_pool_find(0);
745 fwd_lcores[lc_id]->mbp = mbp;
746 /* initialize GSO context */
747 fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
748 fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
749 fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
750 fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
752 fwd_lcores[lc_id]->gso_ctx.flag = 0;
755 /* Configuration of packet forwarding streams. */
756 if (init_fwd_streams() < 0)
757 rte_exit(EXIT_FAILURE, "FAIL from init_fwd_streams()\n");
761 /* create a gro context for each lcore */
762 gro_param.gro_types = RTE_GRO_TCP_IPV4;
763 gro_param.max_flow_num = GRO_MAX_FLUSH_CYCLES;
764 gro_param.max_item_per_flow = MAX_PKT_BURST;
765 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
766 gro_param.socket_id = rte_lcore_to_socket_id(
767 fwd_lcores_cpuids[lc_id]);
768 fwd_lcores[lc_id]->gro_ctx = rte_gro_ctx_create(&gro_param);
769 if (fwd_lcores[lc_id]->gro_ctx == NULL) {
770 rte_exit(EXIT_FAILURE,
771 "rte_gro_ctx_create() failed\n");
778 reconfig(portid_t new_port_id, unsigned socket_id)
780 struct rte_port *port;
782 /* Reconfiguration of Ethernet ports. */
783 port = &ports[new_port_id];
784 rte_eth_dev_info_get(new_port_id, &port->dev_info);
786 /* set flag to initialize port/queue */
787 port->need_reconfig = 1;
788 port->need_reconfig_queues = 1;
789 port->socket_id = socket_id;
796 init_fwd_streams(void)
799 struct rte_port *port;
800 streamid_t sm_id, nb_fwd_streams_new;
803 /* set socket id according to numa or not */
804 RTE_ETH_FOREACH_DEV(pid) {
806 if (nb_rxq > port->dev_info.max_rx_queues) {
807 printf("Fail: nb_rxq(%d) is greater than "
808 "max_rx_queues(%d)\n", nb_rxq,
809 port->dev_info.max_rx_queues);
812 if (nb_txq > port->dev_info.max_tx_queues) {
813 printf("Fail: nb_txq(%d) is greater than "
814 "max_tx_queues(%d)\n", nb_txq,
815 port->dev_info.max_tx_queues);
819 if (port_numa[pid] != NUMA_NO_CONFIG)
820 port->socket_id = port_numa[pid];
822 port->socket_id = rte_eth_dev_socket_id(pid);
824 /* if socket_id is invalid, set to 0 */
825 if (check_socket_id(port->socket_id) < 0)
830 if (socket_num == UMA_NO_CONFIG)
833 port->socket_id = socket_num;
837 q = RTE_MAX(nb_rxq, nb_txq);
839 printf("Fail: Cannot allocate fwd streams as number of queues is 0\n");
842 nb_fwd_streams_new = (streamid_t)(nb_ports * q);
843 if (nb_fwd_streams_new == nb_fwd_streams)
846 if (fwd_streams != NULL) {
847 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
848 if (fwd_streams[sm_id] == NULL)
850 rte_free(fwd_streams[sm_id]);
851 fwd_streams[sm_id] = NULL;
853 rte_free(fwd_streams);
858 nb_fwd_streams = nb_fwd_streams_new;
859 fwd_streams = rte_zmalloc("testpmd: fwd_streams",
860 sizeof(struct fwd_stream *) * nb_fwd_streams, RTE_CACHE_LINE_SIZE);
861 if (fwd_streams == NULL)
862 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_stream *)) "
863 "failed\n", nb_fwd_streams);
865 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
866 fwd_streams[sm_id] = rte_zmalloc("testpmd: struct fwd_stream",
867 sizeof(struct fwd_stream), RTE_CACHE_LINE_SIZE);
868 if (fwd_streams[sm_id] == NULL)
869 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_stream)"
876 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
878 pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs)
880 unsigned int total_burst;
881 unsigned int nb_burst;
882 unsigned int burst_stats[3];
883 uint16_t pktnb_stats[3];
885 int burst_percent[3];
888 * First compute the total number of packet bursts and the
889 * two highest numbers of bursts of the same number of packets.
892 burst_stats[0] = burst_stats[1] = burst_stats[2] = 0;
893 pktnb_stats[0] = pktnb_stats[1] = pktnb_stats[2] = 0;
894 for (nb_pkt = 0; nb_pkt < MAX_PKT_BURST; nb_pkt++) {
895 nb_burst = pbs->pkt_burst_spread[nb_pkt];
898 total_burst += nb_burst;
899 if (nb_burst > burst_stats[0]) {
900 burst_stats[1] = burst_stats[0];
901 pktnb_stats[1] = pktnb_stats[0];
902 burst_stats[0] = nb_burst;
903 pktnb_stats[0] = nb_pkt;
906 if (total_burst == 0)
908 burst_percent[0] = (burst_stats[0] * 100) / total_burst;
909 printf(" %s-bursts : %u [%d%% of %d pkts", rx_tx, total_burst,
910 burst_percent[0], (int) pktnb_stats[0]);
911 if (burst_stats[0] == total_burst) {
915 if (burst_stats[0] + burst_stats[1] == total_burst) {
916 printf(" + %d%% of %d pkts]\n",
917 100 - burst_percent[0], pktnb_stats[1]);
920 burst_percent[1] = (burst_stats[1] * 100) / total_burst;
921 burst_percent[2] = 100 - (burst_percent[0] + burst_percent[1]);
922 if ((burst_percent[1] == 0) || (burst_percent[2] == 0)) {
923 printf(" + %d%% of others]\n", 100 - burst_percent[0]);
926 printf(" + %d%% of %d pkts + %d%% of others]\n",
927 burst_percent[1], (int) pktnb_stats[1], burst_percent[2]);
929 #endif /* RTE_TEST_PMD_RECORD_BURST_STATS */
932 fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
934 struct rte_port *port;
937 static const char *fwd_stats_border = "----------------------";
939 port = &ports[port_id];
940 printf("\n %s Forward statistics for port %-2d %s\n",
941 fwd_stats_border, port_id, fwd_stats_border);
943 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
944 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
946 stats->ipackets, stats->imissed,
947 (uint64_t) (stats->ipackets + stats->imissed));
949 if (cur_fwd_eng == &csum_fwd_engine)
950 printf(" Bad-ipcsum: %-14"PRIu64" Bad-l4csum: %-14"PRIu64" \n",
951 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
952 if ((stats->ierrors + stats->rx_nombuf) > 0) {
953 printf(" RX-error: %-"PRIu64"\n", stats->ierrors);
954 printf(" RX-nombufs: %-14"PRIu64"\n", stats->rx_nombuf);
957 printf(" TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
959 stats->opackets, port->tx_dropped,
960 (uint64_t) (stats->opackets + port->tx_dropped));
963 printf(" RX-packets: %14"PRIu64" RX-dropped:%14"PRIu64" RX-total:"
965 stats->ipackets, stats->imissed,
966 (uint64_t) (stats->ipackets + stats->imissed));
968 if (cur_fwd_eng == &csum_fwd_engine)
969 printf(" Bad-ipcsum:%14"PRIu64" Bad-l4csum:%14"PRIu64"\n",
970 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
971 if ((stats->ierrors + stats->rx_nombuf) > 0) {
972 printf(" RX-error:%"PRIu64"\n", stats->ierrors);
973 printf(" RX-nombufs: %14"PRIu64"\n",
977 printf(" TX-packets: %14"PRIu64" TX-dropped:%14"PRIu64" TX-total:"
979 stats->opackets, port->tx_dropped,
980 (uint64_t) (stats->opackets + port->tx_dropped));
983 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
985 pkt_burst_stats_display("RX",
986 &port->rx_stream->rx_burst_stats);
988 pkt_burst_stats_display("TX",
989 &port->tx_stream->tx_burst_stats);
992 if (port->rx_queue_stats_mapping_enabled) {
994 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
995 printf(" Stats reg %2d RX-packets:%14"PRIu64
996 " RX-errors:%14"PRIu64
997 " RX-bytes:%14"PRIu64"\n",
998 i, stats->q_ipackets[i], stats->q_errors[i], stats->q_ibytes[i]);
1002 if (port->tx_queue_stats_mapping_enabled) {
1003 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
1004 printf(" Stats reg %2d TX-packets:%14"PRIu64
1005 " TX-bytes:%14"PRIu64"\n",
1006 i, stats->q_opackets[i], stats->q_obytes[i]);
1010 printf(" %s--------------------------------%s\n",
1011 fwd_stats_border, fwd_stats_border);
1015 fwd_stream_stats_display(streamid_t stream_id)
1017 struct fwd_stream *fs;
1018 static const char *fwd_top_stats_border = "-------";
1020 fs = fwd_streams[stream_id];
1021 if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
1022 (fs->fwd_dropped == 0))
1024 printf("\n %s Forward Stats for RX Port=%2d/Queue=%2d -> "
1025 "TX Port=%2d/Queue=%2d %s\n",
1026 fwd_top_stats_border, fs->rx_port, fs->rx_queue,
1027 fs->tx_port, fs->tx_queue, fwd_top_stats_border);
1028 printf(" RX-packets: %-14u TX-packets: %-14u TX-dropped: %-14u",
1029 fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
1031 /* if checksum mode */
1032 if (cur_fwd_eng == &csum_fwd_engine) {
1033 printf(" RX- bad IP checksum: %-14u Rx- bad L4 checksum: "
1034 "%-14u\n", fs->rx_bad_ip_csum, fs->rx_bad_l4_csum);
1037 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1038 pkt_burst_stats_display("RX", &fs->rx_burst_stats);
1039 pkt_burst_stats_display("TX", &fs->tx_burst_stats);
1044 flush_fwd_rx_queues(void)
1046 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1053 uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
1054 uint64_t timer_period;
1056 /* convert to number of cycles */
1057 timer_period = rte_get_timer_hz(); /* 1 second timeout */
1059 for (j = 0; j < 2; j++) {
1060 for (rxp = 0; rxp < cur_fwd_config.nb_fwd_ports; rxp++) {
1061 for (rxq = 0; rxq < nb_rxq; rxq++) {
1062 port_id = fwd_ports_ids[rxp];
1064 * testpmd can stuck in the below do while loop
1065 * if rte_eth_rx_burst() always returns nonzero
1066 * packets. So timer is added to exit this loop
1067 * after 1sec timer expiry.
1069 prev_tsc = rte_rdtsc();
1071 nb_rx = rte_eth_rx_burst(port_id, rxq,
1072 pkts_burst, MAX_PKT_BURST);
1073 for (i = 0; i < nb_rx; i++)
1074 rte_pktmbuf_free(pkts_burst[i]);
1076 cur_tsc = rte_rdtsc();
1077 diff_tsc = cur_tsc - prev_tsc;
1078 timer_tsc += diff_tsc;
1079 } while ((nb_rx > 0) &&
1080 (timer_tsc < timer_period));
1084 rte_delay_ms(10); /* wait 10 milli-seconds before retrying */
1089 run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
1091 struct fwd_stream **fsm;
1094 #ifdef RTE_LIBRTE_BITRATE
1095 uint64_t tics_per_1sec;
1096 uint64_t tics_datum;
1097 uint64_t tics_current;
1098 uint8_t idx_port, cnt_ports;
1100 cnt_ports = rte_eth_dev_count();
1101 tics_datum = rte_rdtsc();
1102 tics_per_1sec = rte_get_timer_hz();
1104 fsm = &fwd_streams[fc->stream_idx];
1105 nb_fs = fc->stream_nb;
1107 for (sm_id = 0; sm_id < nb_fs; sm_id++)
1108 (*pkt_fwd)(fsm[sm_id]);
1109 #ifdef RTE_LIBRTE_BITRATE
1110 if (bitrate_enabled != 0 &&
1111 bitrate_lcore_id == rte_lcore_id()) {
1112 tics_current = rte_rdtsc();
1113 if (tics_current - tics_datum >= tics_per_1sec) {
1114 /* Periodic bitrate calculation */
1116 idx_port < cnt_ports;
1118 rte_stats_bitrate_calc(bitrate_data,
1120 tics_datum = tics_current;
1124 #ifdef RTE_LIBRTE_LATENCY_STATS
1125 if (latencystats_enabled != 0 &&
1126 latencystats_lcore_id == rte_lcore_id())
1127 rte_latencystats_update();
1130 } while (! fc->stopped);
1134 start_pkt_forward_on_core(void *fwd_arg)
1136 run_pkt_fwd_on_lcore((struct fwd_lcore *) fwd_arg,
1137 cur_fwd_config.fwd_eng->packet_fwd);
1142 * Run the TXONLY packet forwarding engine to send a single burst of packets.
1143 * Used to start communication flows in network loopback test configurations.
1146 run_one_txonly_burst_on_core(void *fwd_arg)
1148 struct fwd_lcore *fwd_lc;
1149 struct fwd_lcore tmp_lcore;
1151 fwd_lc = (struct fwd_lcore *) fwd_arg;
1152 tmp_lcore = *fwd_lc;
1153 tmp_lcore.stopped = 1;
1154 run_pkt_fwd_on_lcore(&tmp_lcore, tx_only_engine.packet_fwd);
1159 * Launch packet forwarding:
1160 * - Setup per-port forwarding context.
1161 * - launch logical cores with their forwarding configuration.
1164 launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
1166 port_fwd_begin_t port_fwd_begin;
1171 port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
1172 if (port_fwd_begin != NULL) {
1173 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1174 (*port_fwd_begin)(fwd_ports_ids[i]);
1176 for (i = 0; i < cur_fwd_config.nb_fwd_lcores; i++) {
1177 lc_id = fwd_lcores_cpuids[i];
1178 if ((interactive == 0) || (lc_id != rte_lcore_id())) {
1179 fwd_lcores[i]->stopped = 0;
1180 diag = rte_eal_remote_launch(pkt_fwd_on_lcore,
1181 fwd_lcores[i], lc_id);
1183 printf("launch lcore %u failed - diag=%d\n",
1190 * Launch packet forwarding configuration.
1193 start_packet_forwarding(int with_tx_first)
1195 port_fwd_begin_t port_fwd_begin;
1196 port_fwd_end_t port_fwd_end;
1197 struct rte_port *port;
1202 if (strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") == 0 && !nb_rxq)
1203 rte_exit(EXIT_FAILURE, "rxq are 0, cannot use rxonly fwd mode\n");
1205 if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 && !nb_txq)
1206 rte_exit(EXIT_FAILURE, "txq are 0, cannot use txonly fwd mode\n");
1208 if ((strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") != 0 &&
1209 strcmp(cur_fwd_eng->fwd_mode_name, "txonly") != 0) &&
1210 (!nb_rxq || !nb_txq))
1211 rte_exit(EXIT_FAILURE,
1212 "Either rxq or txq are 0, cannot use %s fwd mode\n",
1213 cur_fwd_eng->fwd_mode_name);
1215 if (all_ports_started() == 0) {
1216 printf("Not all ports were started\n");
1219 if (test_done == 0) {
1220 printf("Packet forwarding already started\n");
1224 if (init_fwd_streams() < 0) {
1225 printf("Fail from init_fwd_streams()\n");
1230 for (i = 0; i < nb_fwd_ports; i++) {
1231 pt_id = fwd_ports_ids[i];
1232 port = &ports[pt_id];
1233 if (!port->dcb_flag) {
1234 printf("In DCB mode, all forwarding ports must "
1235 "be configured in this mode.\n");
1239 if (nb_fwd_lcores == 1) {
1240 printf("In DCB mode,the nb forwarding cores "
1241 "should be larger than 1.\n");
1248 flush_fwd_rx_queues();
1251 pkt_fwd_config_display(&cur_fwd_config);
1252 rxtx_config_display();
1254 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1255 pt_id = fwd_ports_ids[i];
1256 port = &ports[pt_id];
1257 rte_eth_stats_get(pt_id, &port->stats);
1258 port->tx_dropped = 0;
1260 map_port_queue_stats_mapping_registers(pt_id, port);
1262 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1263 fwd_streams[sm_id]->rx_packets = 0;
1264 fwd_streams[sm_id]->tx_packets = 0;
1265 fwd_streams[sm_id]->fwd_dropped = 0;
1266 fwd_streams[sm_id]->rx_bad_ip_csum = 0;
1267 fwd_streams[sm_id]->rx_bad_l4_csum = 0;
1269 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1270 memset(&fwd_streams[sm_id]->rx_burst_stats, 0,
1271 sizeof(fwd_streams[sm_id]->rx_burst_stats));
1272 memset(&fwd_streams[sm_id]->tx_burst_stats, 0,
1273 sizeof(fwd_streams[sm_id]->tx_burst_stats));
1275 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1276 fwd_streams[sm_id]->core_cycles = 0;
1279 if (with_tx_first) {
1280 port_fwd_begin = tx_only_engine.port_fwd_begin;
1281 if (port_fwd_begin != NULL) {
1282 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1283 (*port_fwd_begin)(fwd_ports_ids[i]);
1285 while (with_tx_first--) {
1286 launch_packet_forwarding(
1287 run_one_txonly_burst_on_core);
1288 rte_eal_mp_wait_lcore();
1290 port_fwd_end = tx_only_engine.port_fwd_end;
1291 if (port_fwd_end != NULL) {
1292 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1293 (*port_fwd_end)(fwd_ports_ids[i]);
1296 launch_packet_forwarding(start_pkt_forward_on_core);
1300 stop_packet_forwarding(void)
1302 struct rte_eth_stats stats;
1303 struct rte_port *port;
1304 port_fwd_end_t port_fwd_end;
1309 uint64_t total_recv;
1310 uint64_t total_xmit;
1311 uint64_t total_rx_dropped;
1312 uint64_t total_tx_dropped;
1313 uint64_t total_rx_nombuf;
1314 uint64_t tx_dropped;
1315 uint64_t rx_bad_ip_csum;
1316 uint64_t rx_bad_l4_csum;
1317 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1318 uint64_t fwd_cycles;
1321 static const char *acc_stats_border = "+++++++++++++++";
1324 printf("Packet forwarding not started\n");
1327 printf("Telling cores to stop...");
1328 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++)
1329 fwd_lcores[lc_id]->stopped = 1;
1330 printf("\nWaiting for lcores to finish...\n");
1331 rte_eal_mp_wait_lcore();
1332 port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end;
1333 if (port_fwd_end != NULL) {
1334 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1335 pt_id = fwd_ports_ids[i];
1336 (*port_fwd_end)(pt_id);
1339 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1342 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1343 if (cur_fwd_config.nb_fwd_streams >
1344 cur_fwd_config.nb_fwd_ports) {
1345 fwd_stream_stats_display(sm_id);
1346 ports[fwd_streams[sm_id]->tx_port].tx_stream = NULL;
1347 ports[fwd_streams[sm_id]->rx_port].rx_stream = NULL;
1349 ports[fwd_streams[sm_id]->tx_port].tx_stream =
1351 ports[fwd_streams[sm_id]->rx_port].rx_stream =
1354 tx_dropped = ports[fwd_streams[sm_id]->tx_port].tx_dropped;
1355 tx_dropped = (uint64_t) (tx_dropped +
1356 fwd_streams[sm_id]->fwd_dropped);
1357 ports[fwd_streams[sm_id]->tx_port].tx_dropped = tx_dropped;
1360 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum;
1361 rx_bad_ip_csum = (uint64_t) (rx_bad_ip_csum +
1362 fwd_streams[sm_id]->rx_bad_ip_csum);
1363 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum =
1367 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum;
1368 rx_bad_l4_csum = (uint64_t) (rx_bad_l4_csum +
1369 fwd_streams[sm_id]->rx_bad_l4_csum);
1370 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum =
1373 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1374 fwd_cycles = (uint64_t) (fwd_cycles +
1375 fwd_streams[sm_id]->core_cycles);
1380 total_rx_dropped = 0;
1381 total_tx_dropped = 0;
1382 total_rx_nombuf = 0;
1383 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1384 pt_id = fwd_ports_ids[i];
1386 port = &ports[pt_id];
1387 rte_eth_stats_get(pt_id, &stats);
1388 stats.ipackets -= port->stats.ipackets;
1389 port->stats.ipackets = 0;
1390 stats.opackets -= port->stats.opackets;
1391 port->stats.opackets = 0;
1392 stats.ibytes -= port->stats.ibytes;
1393 port->stats.ibytes = 0;
1394 stats.obytes -= port->stats.obytes;
1395 port->stats.obytes = 0;
1396 stats.imissed -= port->stats.imissed;
1397 port->stats.imissed = 0;
1398 stats.oerrors -= port->stats.oerrors;
1399 port->stats.oerrors = 0;
1400 stats.rx_nombuf -= port->stats.rx_nombuf;
1401 port->stats.rx_nombuf = 0;
1403 total_recv += stats.ipackets;
1404 total_xmit += stats.opackets;
1405 total_rx_dropped += stats.imissed;
1406 total_tx_dropped += port->tx_dropped;
1407 total_rx_nombuf += stats.rx_nombuf;
1409 fwd_port_stats_display(pt_id, &stats);
1412 printf("\n %s Accumulated forward statistics for all ports"
1414 acc_stats_border, acc_stats_border);
1415 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
1417 " TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
1419 total_recv, total_rx_dropped, total_recv + total_rx_dropped,
1420 total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
1421 if (total_rx_nombuf > 0)
1422 printf(" RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
1423 printf(" %s++++++++++++++++++++++++++++++++++++++++++++++"
1425 acc_stats_border, acc_stats_border);
1426 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1428 printf("\n CPU cycles/packet=%u (total cycles="
1429 "%"PRIu64" / total RX packets=%"PRIu64")\n",
1430 (unsigned int)(fwd_cycles / total_recv),
1431 fwd_cycles, total_recv);
1433 printf("\nDone.\n");
1438 dev_set_link_up(portid_t pid)
1440 if (rte_eth_dev_set_link_up(pid) < 0)
1441 printf("\nSet link up fail.\n");
1445 dev_set_link_down(portid_t pid)
1447 if (rte_eth_dev_set_link_down(pid) < 0)
1448 printf("\nSet link down fail.\n");
1452 all_ports_started(void)
1455 struct rte_port *port;
1457 RTE_ETH_FOREACH_DEV(pi) {
1459 /* Check if there is a port which is not started */
1460 if ((port->port_status != RTE_PORT_STARTED) &&
1461 (port->slave_flag == 0))
1465 /* No port is not started */
1470 port_is_stopped(portid_t port_id)
1472 struct rte_port *port = &ports[port_id];
1474 if ((port->port_status != RTE_PORT_STOPPED) &&
1475 (port->slave_flag == 0))
1481 all_ports_stopped(void)
1485 RTE_ETH_FOREACH_DEV(pi) {
1486 if (!port_is_stopped(pi))
1494 port_is_started(portid_t port_id)
1496 if (port_id_is_invalid(port_id, ENABLED_WARN))
1499 if (ports[port_id].port_status != RTE_PORT_STARTED)
1506 port_is_closed(portid_t port_id)
1508 if (port_id_is_invalid(port_id, ENABLED_WARN))
1511 if (ports[port_id].port_status != RTE_PORT_CLOSED)
1518 start_port(portid_t pid)
1520 int diag, need_check_link_status = -1;
1523 struct rte_port *port;
1524 struct ether_addr mac_addr;
1525 enum rte_eth_event_type event_type;
1527 if (port_id_is_invalid(pid, ENABLED_WARN))
1532 RTE_ETH_FOREACH_DEV(pi) {
1533 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1536 need_check_link_status = 0;
1538 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STOPPED,
1539 RTE_PORT_HANDLING) == 0) {
1540 printf("Port %d is now not stopped\n", pi);
1544 if (port->need_reconfig > 0) {
1545 port->need_reconfig = 0;
1547 if (flow_isolate_all) {
1548 int ret = port_flow_isolate(pi, 1);
1550 printf("Failed to apply isolated"
1551 " mode on port %d\n", pi);
1556 printf("Configuring Port %d (socket %u)\n", pi,
1558 /* configure port */
1559 diag = rte_eth_dev_configure(pi, nb_rxq, nb_txq,
1562 if (rte_atomic16_cmpset(&(port->port_status),
1563 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1564 printf("Port %d can not be set back "
1565 "to stopped\n", pi);
1566 printf("Fail to configure port %d\n", pi);
1567 /* try to reconfigure port next time */
1568 port->need_reconfig = 1;
1572 if (port->need_reconfig_queues > 0) {
1573 port->need_reconfig_queues = 0;
1574 port->tx_conf.txq_flags = ETH_TXQ_FLAGS_IGNORE;
1575 /* Apply Tx offloads configuration */
1576 port->tx_conf.offloads = port->dev_conf.txmode.offloads;
1577 /* setup tx queues */
1578 for (qi = 0; qi < nb_txq; qi++) {
1579 if ((numa_support) &&
1580 (txring_numa[pi] != NUMA_NO_CONFIG))
1581 diag = rte_eth_tx_queue_setup(pi, qi,
1582 nb_txd,txring_numa[pi],
1585 diag = rte_eth_tx_queue_setup(pi, qi,
1586 nb_txd,port->socket_id,
1592 /* Fail to setup tx queue, return */
1593 if (rte_atomic16_cmpset(&(port->port_status),
1595 RTE_PORT_STOPPED) == 0)
1596 printf("Port %d can not be set back "
1597 "to stopped\n", pi);
1598 printf("Fail to configure port %d tx queues\n", pi);
1599 /* try to reconfigure queues next time */
1600 port->need_reconfig_queues = 1;
1603 /* Apply Rx offloads configuration */
1604 port->rx_conf.offloads = port->dev_conf.rxmode.offloads;
1605 /* setup rx queues */
1606 for (qi = 0; qi < nb_rxq; qi++) {
1607 if ((numa_support) &&
1608 (rxring_numa[pi] != NUMA_NO_CONFIG)) {
1609 struct rte_mempool * mp =
1610 mbuf_pool_find(rxring_numa[pi]);
1612 printf("Failed to setup RX queue:"
1613 "No mempool allocation"
1614 " on the socket %d\n",
1619 diag = rte_eth_rx_queue_setup(pi, qi,
1620 nb_rxd,rxring_numa[pi],
1621 &(port->rx_conf),mp);
1623 struct rte_mempool *mp =
1624 mbuf_pool_find(port->socket_id);
1626 printf("Failed to setup RX queue:"
1627 "No mempool allocation"
1628 " on the socket %d\n",
1632 diag = rte_eth_rx_queue_setup(pi, qi,
1633 nb_rxd,port->socket_id,
1634 &(port->rx_conf), mp);
1639 /* Fail to setup rx queue, return */
1640 if (rte_atomic16_cmpset(&(port->port_status),
1642 RTE_PORT_STOPPED) == 0)
1643 printf("Port %d can not be set back "
1644 "to stopped\n", pi);
1645 printf("Fail to configure port %d rx queues\n", pi);
1646 /* try to reconfigure queues next time */
1647 port->need_reconfig_queues = 1;
1653 if (rte_eth_dev_start(pi) < 0) {
1654 printf("Fail to start port %d\n", pi);
1656 /* Fail to setup rx queue, return */
1657 if (rte_atomic16_cmpset(&(port->port_status),
1658 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1659 printf("Port %d can not be set back to "
1664 if (rte_atomic16_cmpset(&(port->port_status),
1665 RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0)
1666 printf("Port %d can not be set into started\n", pi);
1668 rte_eth_macaddr_get(pi, &mac_addr);
1669 printf("Port %d: %02X:%02X:%02X:%02X:%02X:%02X\n", pi,
1670 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
1671 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
1672 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5]);
1674 /* at least one port started, need checking link status */
1675 need_check_link_status = 1;
1678 for (event_type = RTE_ETH_EVENT_UNKNOWN;
1679 event_type < RTE_ETH_EVENT_MAX;
1681 diag = rte_eth_dev_callback_register(RTE_ETH_ALL,
1686 printf("Failed to setup even callback for event %d\n",
1692 if (need_check_link_status == 1 && !no_link_check)
1693 check_all_ports_link_status(RTE_PORT_ALL);
1694 else if (need_check_link_status == 0)
1695 printf("Please stop the ports first\n");
1702 stop_port(portid_t pid)
1705 struct rte_port *port;
1706 int need_check_link_status = 0;
1713 if (port_id_is_invalid(pid, ENABLED_WARN))
1716 printf("Stopping ports...\n");
1718 RTE_ETH_FOREACH_DEV(pi) {
1719 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1722 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1723 printf("Please remove port %d from forwarding configuration.\n", pi);
1727 if (port_is_bonding_slave(pi)) {
1728 printf("Please remove port %d from bonded device.\n", pi);
1733 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STARTED,
1734 RTE_PORT_HANDLING) == 0)
1737 rte_eth_dev_stop(pi);
1739 if (rte_atomic16_cmpset(&(port->port_status),
1740 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1741 printf("Port %d can not be set into stopped\n", pi);
1742 need_check_link_status = 1;
1744 if (need_check_link_status && !no_link_check)
1745 check_all_ports_link_status(RTE_PORT_ALL);
1751 close_port(portid_t pid)
1754 struct rte_port *port;
1756 if (port_id_is_invalid(pid, ENABLED_WARN))
1759 printf("Closing ports...\n");
1761 RTE_ETH_FOREACH_DEV(pi) {
1762 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1765 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1766 printf("Please remove port %d from forwarding configuration.\n", pi);
1770 if (port_is_bonding_slave(pi)) {
1771 printf("Please remove port %d from bonded device.\n", pi);
1776 if (rte_atomic16_cmpset(&(port->port_status),
1777 RTE_PORT_CLOSED, RTE_PORT_CLOSED) == 1) {
1778 printf("Port %d is already closed\n", pi);
1782 if (rte_atomic16_cmpset(&(port->port_status),
1783 RTE_PORT_STOPPED, RTE_PORT_HANDLING) == 0) {
1784 printf("Port %d is now not stopped\n", pi);
1788 if (port->flow_list)
1789 port_flow_flush(pi);
1790 rte_eth_dev_close(pi);
1792 if (rte_atomic16_cmpset(&(port->port_status),
1793 RTE_PORT_HANDLING, RTE_PORT_CLOSED) == 0)
1794 printf("Port %d cannot be set to closed\n", pi);
1801 reset_port(portid_t pid)
1805 struct rte_port *port;
1807 if (port_id_is_invalid(pid, ENABLED_WARN))
1810 printf("Resetting ports...\n");
1812 RTE_ETH_FOREACH_DEV(pi) {
1813 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1816 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1817 printf("Please remove port %d from forwarding "
1818 "configuration.\n", pi);
1822 if (port_is_bonding_slave(pi)) {
1823 printf("Please remove port %d from bonded device.\n",
1828 diag = rte_eth_dev_reset(pi);
1831 port->need_reconfig = 1;
1832 port->need_reconfig_queues = 1;
1834 printf("Failed to reset port %d. diag=%d\n", pi, diag);
1842 attach_port(char *identifier)
1845 unsigned int socket_id;
1847 printf("Attaching a new port...\n");
1849 if (identifier == NULL) {
1850 printf("Invalid parameters are specified\n");
1854 if (rte_eth_dev_attach(identifier, &pi))
1857 socket_id = (unsigned)rte_eth_dev_socket_id(pi);
1858 /* if socket_id is invalid, set to 0 */
1859 if (check_socket_id(socket_id) < 0)
1861 reconfig(pi, socket_id);
1862 rte_eth_promiscuous_enable(pi);
1864 nb_ports = rte_eth_dev_count();
1866 ports[pi].port_status = RTE_PORT_STOPPED;
1868 printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
1873 detach_port(portid_t port_id)
1875 char name[RTE_ETH_NAME_MAX_LEN];
1877 printf("Detaching a port...\n");
1879 if (!port_is_closed(port_id)) {
1880 printf("Please close port first\n");
1884 if (ports[port_id].flow_list)
1885 port_flow_flush(port_id);
1887 if (rte_eth_dev_detach(port_id, name)) {
1888 TESTPMD_LOG(ERR, "Failed to detach port '%s'\n", name);
1892 nb_ports = rte_eth_dev_count();
1894 printf("Port '%s' is detached. Now total ports is %d\n",
1906 stop_packet_forwarding();
1908 if (ports != NULL) {
1910 RTE_ETH_FOREACH_DEV(pt_id) {
1911 printf("\nShutting down port %d...\n", pt_id);
1917 printf("\nBye...\n");
1920 typedef void (*cmd_func_t)(void);
1921 struct pmd_test_command {
1922 const char *cmd_name;
1923 cmd_func_t cmd_func;
1926 #define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
1928 /* Check the link status of all ports in up to 9s, and print them finally */
1930 check_all_ports_link_status(uint32_t port_mask)
1932 #define CHECK_INTERVAL 100 /* 100ms */
1933 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1935 uint8_t count, all_ports_up, print_flag = 0;
1936 struct rte_eth_link link;
1938 printf("Checking link statuses...\n");
1940 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1942 RTE_ETH_FOREACH_DEV(portid) {
1943 if ((port_mask & (1 << portid)) == 0)
1945 memset(&link, 0, sizeof(link));
1946 rte_eth_link_get_nowait(portid, &link);
1947 /* print link status if flag set */
1948 if (print_flag == 1) {
1949 if (link.link_status)
1951 "Port%d Link Up. speed %u Mbps- %s\n",
1952 portid, link.link_speed,
1953 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1954 ("full-duplex") : ("half-duplex\n"));
1956 printf("Port %d Link Down\n", portid);
1959 /* clear all_ports_up flag if any link down */
1960 if (link.link_status == ETH_LINK_DOWN) {
1965 /* after finally printing all link status, get out */
1966 if (print_flag == 1)
1969 if (all_ports_up == 0) {
1971 rte_delay_ms(CHECK_INTERVAL);
1974 /* set the print_flag if all ports up or timeout */
1975 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
1985 rmv_event_callback(void *arg)
1987 struct rte_eth_dev *dev;
1988 portid_t port_id = (intptr_t)arg;
1990 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1991 dev = &rte_eth_devices[port_id];
1994 close_port(port_id);
1995 printf("removing device %s\n", dev->device->name);
1996 if (rte_eal_dev_detach(dev->device))
1997 TESTPMD_LOG(ERR, "Failed to detach device %s\n",
2001 /* This function is used by the interrupt thread */
2003 eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
2006 static const char * const event_desc[] = {
2007 [RTE_ETH_EVENT_UNKNOWN] = "Unknown",
2008 [RTE_ETH_EVENT_INTR_LSC] = "LSC",
2009 [RTE_ETH_EVENT_QUEUE_STATE] = "Queue state",
2010 [RTE_ETH_EVENT_INTR_RESET] = "Interrupt reset",
2011 [RTE_ETH_EVENT_VF_MBOX] = "VF Mbox",
2012 [RTE_ETH_EVENT_MACSEC] = "MACsec",
2013 [RTE_ETH_EVENT_INTR_RMV] = "device removal",
2014 [RTE_ETH_EVENT_NEW] = "device probed",
2015 [RTE_ETH_EVENT_DESTROY] = "device released",
2016 [RTE_ETH_EVENT_MAX] = NULL,
2019 RTE_SET_USED(param);
2020 RTE_SET_USED(ret_param);
2022 if (type >= RTE_ETH_EVENT_MAX) {
2023 fprintf(stderr, "\nPort %" PRIu8 ": %s called upon invalid event %d\n",
2024 port_id, __func__, type);
2026 } else if (event_print_mask & (UINT32_C(1) << type)) {
2027 printf("\nPort %" PRIu8 ": %s event\n", port_id,
2033 case RTE_ETH_EVENT_INTR_RMV:
2034 if (rte_eal_alarm_set(100000,
2035 rmv_event_callback, (void *)(intptr_t)port_id))
2036 fprintf(stderr, "Could not set up deferred device removal\n");
2045 set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
2049 uint8_t mapping_found = 0;
2051 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2052 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2053 (tx_queue_stats_mappings[i].queue_id < nb_txq )) {
2054 diag = rte_eth_dev_set_tx_queue_stats_mapping(port_id,
2055 tx_queue_stats_mappings[i].queue_id,
2056 tx_queue_stats_mappings[i].stats_counter_id);
2063 port->tx_queue_stats_mapping_enabled = 1;
2068 set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
2072 uint8_t mapping_found = 0;
2074 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2075 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2076 (rx_queue_stats_mappings[i].queue_id < nb_rxq )) {
2077 diag = rte_eth_dev_set_rx_queue_stats_mapping(port_id,
2078 rx_queue_stats_mappings[i].queue_id,
2079 rx_queue_stats_mappings[i].stats_counter_id);
2086 port->rx_queue_stats_mapping_enabled = 1;
2091 map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
2095 diag = set_tx_queue_stats_mapping_registers(pi, port);
2097 if (diag == -ENOTSUP) {
2098 port->tx_queue_stats_mapping_enabled = 0;
2099 printf("TX queue stats mapping not supported port id=%d\n", pi);
2102 rte_exit(EXIT_FAILURE,
2103 "set_tx_queue_stats_mapping_registers "
2104 "failed for port id=%d diag=%d\n",
2108 diag = set_rx_queue_stats_mapping_registers(pi, port);
2110 if (diag == -ENOTSUP) {
2111 port->rx_queue_stats_mapping_enabled = 0;
2112 printf("RX queue stats mapping not supported port id=%d\n", pi);
2115 rte_exit(EXIT_FAILURE,
2116 "set_rx_queue_stats_mapping_registers "
2117 "failed for port id=%d diag=%d\n",
2123 rxtx_port_config(struct rte_port *port)
2125 port->rx_conf = port->dev_info.default_rxconf;
2126 port->tx_conf = port->dev_info.default_txconf;
2128 /* Check if any RX/TX parameters have been passed */
2129 if (rx_pthresh != RTE_PMD_PARAM_UNSET)
2130 port->rx_conf.rx_thresh.pthresh = rx_pthresh;
2132 if (rx_hthresh != RTE_PMD_PARAM_UNSET)
2133 port->rx_conf.rx_thresh.hthresh = rx_hthresh;
2135 if (rx_wthresh != RTE_PMD_PARAM_UNSET)
2136 port->rx_conf.rx_thresh.wthresh = rx_wthresh;
2138 if (rx_free_thresh != RTE_PMD_PARAM_UNSET)
2139 port->rx_conf.rx_free_thresh = rx_free_thresh;
2141 if (rx_drop_en != RTE_PMD_PARAM_UNSET)
2142 port->rx_conf.rx_drop_en = rx_drop_en;
2144 if (tx_pthresh != RTE_PMD_PARAM_UNSET)
2145 port->tx_conf.tx_thresh.pthresh = tx_pthresh;
2147 if (tx_hthresh != RTE_PMD_PARAM_UNSET)
2148 port->tx_conf.tx_thresh.hthresh = tx_hthresh;
2150 if (tx_wthresh != RTE_PMD_PARAM_UNSET)
2151 port->tx_conf.tx_thresh.wthresh = tx_wthresh;
2153 if (tx_rs_thresh != RTE_PMD_PARAM_UNSET)
2154 port->tx_conf.tx_rs_thresh = tx_rs_thresh;
2156 if (tx_free_thresh != RTE_PMD_PARAM_UNSET)
2157 port->tx_conf.tx_free_thresh = tx_free_thresh;
2161 init_port_config(void)
2164 struct rte_port *port;
2166 RTE_ETH_FOREACH_DEV(pid) {
2168 port->dev_conf.fdir_conf = fdir_conf;
2170 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2171 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = rss_hf;
2173 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2174 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = 0;
2177 if (port->dcb_flag == 0) {
2178 if( port->dev_conf.rx_adv_conf.rss_conf.rss_hf != 0)
2179 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
2181 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
2184 rxtx_port_config(port);
2186 rte_eth_macaddr_get(pid, &port->eth_addr);
2188 map_port_queue_stats_mapping_registers(pid, port);
2189 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
2190 rte_pmd_ixgbe_bypass_init(pid);
2193 if (lsc_interrupt &&
2194 (rte_eth_devices[pid].data->dev_flags &
2195 RTE_ETH_DEV_INTR_LSC))
2196 port->dev_conf.intr_conf.lsc = 1;
2197 if (rmv_interrupt &&
2198 (rte_eth_devices[pid].data->dev_flags &
2199 RTE_ETH_DEV_INTR_RMV))
2200 port->dev_conf.intr_conf.rmv = 1;
2202 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
2203 /* Detect softnic port */
2204 if (!strcmp(port->dev_info.driver_name, "net_softnic")) {
2205 port->softnic_enable = 1;
2206 memset(&port->softport, 0, sizeof(struct softnic_port));
2208 if (!strcmp(cur_fwd_eng->fwd_mode_name, "tm"))
2209 port->softport.tm_flag = 1;
2215 void set_port_slave_flag(portid_t slave_pid)
2217 struct rte_port *port;
2219 port = &ports[slave_pid];
2220 port->slave_flag = 1;
2223 void clear_port_slave_flag(portid_t slave_pid)
2225 struct rte_port *port;
2227 port = &ports[slave_pid];
2228 port->slave_flag = 0;
2231 uint8_t port_is_bonding_slave(portid_t slave_pid)
2233 struct rte_port *port;
2235 port = &ports[slave_pid];
2236 return port->slave_flag;
2239 const uint16_t vlan_tags[] = {
2240 0, 1, 2, 3, 4, 5, 6, 7,
2241 8, 9, 10, 11, 12, 13, 14, 15,
2242 16, 17, 18, 19, 20, 21, 22, 23,
2243 24, 25, 26, 27, 28, 29, 30, 31
2247 get_eth_dcb_conf(struct rte_eth_conf *eth_conf,
2248 enum dcb_mode_enable dcb_mode,
2249 enum rte_eth_nb_tcs num_tcs,
2255 * Builds up the correct configuration for dcb+vt based on the vlan tags array
2256 * given above, and the number of traffic classes available for use.
2258 if (dcb_mode == DCB_VT_ENABLED) {
2259 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
2260 ð_conf->rx_adv_conf.vmdq_dcb_conf;
2261 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
2262 ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
2264 /* VMDQ+DCB RX and TX configurations */
2265 vmdq_rx_conf->enable_default_pool = 0;
2266 vmdq_rx_conf->default_pool = 0;
2267 vmdq_rx_conf->nb_queue_pools =
2268 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2269 vmdq_tx_conf->nb_queue_pools =
2270 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2272 vmdq_rx_conf->nb_pool_maps = vmdq_rx_conf->nb_queue_pools;
2273 for (i = 0; i < vmdq_rx_conf->nb_pool_maps; i++) {
2274 vmdq_rx_conf->pool_map[i].vlan_id = vlan_tags[i];
2275 vmdq_rx_conf->pool_map[i].pools =
2276 1 << (i % vmdq_rx_conf->nb_queue_pools);
2278 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2279 vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
2280 vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
2283 /* set DCB mode of RX and TX of multiple queues */
2284 eth_conf->rxmode.mq_mode = ETH_MQ_RX_VMDQ_DCB;
2285 eth_conf->txmode.mq_mode = ETH_MQ_TX_VMDQ_DCB;
2287 struct rte_eth_dcb_rx_conf *rx_conf =
2288 ð_conf->rx_adv_conf.dcb_rx_conf;
2289 struct rte_eth_dcb_tx_conf *tx_conf =
2290 ð_conf->tx_adv_conf.dcb_tx_conf;
2292 rx_conf->nb_tcs = num_tcs;
2293 tx_conf->nb_tcs = num_tcs;
2295 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2296 rx_conf->dcb_tc[i] = i % num_tcs;
2297 tx_conf->dcb_tc[i] = i % num_tcs;
2299 eth_conf->rxmode.mq_mode = ETH_MQ_RX_DCB_RSS;
2300 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf;
2301 eth_conf->txmode.mq_mode = ETH_MQ_TX_DCB;
2305 eth_conf->dcb_capability_en =
2306 ETH_DCB_PG_SUPPORT | ETH_DCB_PFC_SUPPORT;
2308 eth_conf->dcb_capability_en = ETH_DCB_PG_SUPPORT;
2314 init_port_dcb_config(portid_t pid,
2315 enum dcb_mode_enable dcb_mode,
2316 enum rte_eth_nb_tcs num_tcs,
2319 struct rte_eth_conf port_conf;
2320 struct rte_port *rte_port;
2324 rte_port = &ports[pid];
2326 memset(&port_conf, 0, sizeof(struct rte_eth_conf));
2327 /* Enter DCB configuration status */
2330 /*set configuration of DCB in vt mode and DCB in non-vt mode*/
2331 retval = get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en);
2334 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2337 * Write the configuration into the device.
2338 * Set the numbers of RX & TX queues to 0, so
2339 * the RX & TX queues will not be setup.
2341 rte_eth_dev_configure(pid, 0, 0, &port_conf);
2343 rte_eth_dev_info_get(pid, &rte_port->dev_info);
2345 /* If dev_info.vmdq_pool_base is greater than 0,
2346 * the queue id of vmdq pools is started after pf queues.
2348 if (dcb_mode == DCB_VT_ENABLED &&
2349 rte_port->dev_info.vmdq_pool_base > 0) {
2350 printf("VMDQ_DCB multi-queue mode is nonsensical"
2351 " for port %d.", pid);
2355 /* Assume the ports in testpmd have the same dcb capability
2356 * and has the same number of rxq and txq in dcb mode
2358 if (dcb_mode == DCB_VT_ENABLED) {
2359 if (rte_port->dev_info.max_vfs > 0) {
2360 nb_rxq = rte_port->dev_info.nb_rx_queues;
2361 nb_txq = rte_port->dev_info.nb_tx_queues;
2363 nb_rxq = rte_port->dev_info.max_rx_queues;
2364 nb_txq = rte_port->dev_info.max_tx_queues;
2367 /*if vt is disabled, use all pf queues */
2368 if (rte_port->dev_info.vmdq_pool_base == 0) {
2369 nb_rxq = rte_port->dev_info.max_rx_queues;
2370 nb_txq = rte_port->dev_info.max_tx_queues;
2372 nb_rxq = (queueid_t)num_tcs;
2373 nb_txq = (queueid_t)num_tcs;
2377 rx_free_thresh = 64;
2379 memcpy(&rte_port->dev_conf, &port_conf, sizeof(struct rte_eth_conf));
2381 rxtx_port_config(rte_port);
2383 rte_port->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2384 for (i = 0; i < RTE_DIM(vlan_tags); i++)
2385 rx_vft_set(pid, vlan_tags[i], 1);
2387 rte_eth_macaddr_get(pid, &rte_port->eth_addr);
2388 map_port_queue_stats_mapping_registers(pid, rte_port);
2390 rte_port->dcb_flag = 1;
2398 /* Configuration of Ethernet ports. */
2399 ports = rte_zmalloc("testpmd: ports",
2400 sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
2401 RTE_CACHE_LINE_SIZE);
2402 if (ports == NULL) {
2403 rte_exit(EXIT_FAILURE,
2404 "rte_zmalloc(%d struct rte_port) failed\n",
2420 const char clr[] = { 27, '[', '2', 'J', '\0' };
2421 const char top_left[] = { 27, '[', '1', ';', '1', 'H', '\0' };
2423 /* Clear screen and move to top left */
2424 printf("%s%s", clr, top_left);
2426 printf("\nPort statistics ====================================");
2427 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
2428 nic_stats_display(fwd_ports_ids[i]);
2432 signal_handler(int signum)
2434 if (signum == SIGINT || signum == SIGTERM) {
2435 printf("\nSignal %d received, preparing to exit...\n",
2437 #ifdef RTE_LIBRTE_PDUMP
2438 /* uninitialize packet capture framework */
2441 #ifdef RTE_LIBRTE_LATENCY_STATS
2442 rte_latencystats_uninit();
2445 /* Set flag to indicate the force termination. */
2447 /* exit with the expected status */
2448 signal(signum, SIG_DFL);
2449 kill(getpid(), signum);
2454 main(int argc, char** argv)
2459 signal(SIGINT, signal_handler);
2460 signal(SIGTERM, signal_handler);
2462 diag = rte_eal_init(argc, argv);
2464 rte_panic("Cannot init EAL\n");
2466 testpmd_logtype = rte_log_register("testpmd");
2467 if (testpmd_logtype < 0)
2468 rte_panic("Cannot register log type");
2469 rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
2471 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
2472 TESTPMD_LOG(NOTICE, "mlockall() failed with error \"%s\"\n",
2476 #ifdef RTE_LIBRTE_PDUMP
2477 /* initialize packet capture framework */
2478 rte_pdump_init(NULL);
2481 nb_ports = (portid_t) rte_eth_dev_count();
2483 TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
2485 /* allocate port structures, and init them */
2488 set_def_fwd_config();
2490 rte_panic("Empty set of forwarding logical cores - check the "
2491 "core mask supplied in the command parameters\n");
2493 /* Bitrate/latency stats disabled by default */
2494 #ifdef RTE_LIBRTE_BITRATE
2495 bitrate_enabled = 0;
2497 #ifdef RTE_LIBRTE_LATENCY_STATS
2498 latencystats_enabled = 0;
2504 launch_args_parse(argc, argv);
2506 if (tx_first && interactive)
2507 rte_exit(EXIT_FAILURE, "--tx-first cannot be used on "
2508 "interactive mode.\n");
2510 if (tx_first && lsc_interrupt) {
2511 printf("Warning: lsc_interrupt needs to be off when "
2512 " using tx_first. Disabling.\n");
2516 if (!nb_rxq && !nb_txq)
2517 printf("Warning: Either rx or tx queues should be non-zero\n");
2519 if (nb_rxq > 1 && nb_rxq > nb_txq)
2520 printf("Warning: nb_rxq=%d enables RSS configuration, "
2521 "but nb_txq=%d will prevent to fully test it.\n",
2525 if (start_port(RTE_PORT_ALL) != 0)
2526 rte_exit(EXIT_FAILURE, "Start ports failed\n");
2528 /* set all ports to promiscuous mode by default */
2529 RTE_ETH_FOREACH_DEV(port_id)
2530 rte_eth_promiscuous_enable(port_id);
2532 /* Init metrics library */
2533 rte_metrics_init(rte_socket_id());
2535 #ifdef RTE_LIBRTE_LATENCY_STATS
2536 if (latencystats_enabled != 0) {
2537 int ret = rte_latencystats_init(1, NULL);
2539 printf("Warning: latencystats init()"
2540 " returned error %d\n", ret);
2541 printf("Latencystats running on lcore %d\n",
2542 latencystats_lcore_id);
2546 /* Setup bitrate stats */
2547 #ifdef RTE_LIBRTE_BITRATE
2548 if (bitrate_enabled != 0) {
2549 bitrate_data = rte_stats_bitrate_create();
2550 if (bitrate_data == NULL)
2551 rte_exit(EXIT_FAILURE,
2552 "Could not allocate bitrate data.\n");
2553 rte_stats_bitrate_reg(bitrate_data);
2557 #ifdef RTE_LIBRTE_CMDLINE
2558 if (strlen(cmdline_filename) != 0)
2559 cmdline_read_from_file(cmdline_filename);
2561 if (interactive == 1) {
2563 printf("Start automatic packet forwarding\n");
2564 start_packet_forwarding(0);
2576 printf("No commandline core given, start packet forwarding\n");
2577 start_packet_forwarding(tx_first);
2578 if (stats_period != 0) {
2579 uint64_t prev_time = 0, cur_time, diff_time = 0;
2580 uint64_t timer_period;
2582 /* Convert to number of cycles */
2583 timer_period = stats_period * rte_get_timer_hz();
2585 while (f_quit == 0) {
2586 cur_time = rte_get_timer_cycles();
2587 diff_time += cur_time - prev_time;
2589 if (diff_time >= timer_period) {
2591 /* Reset the timer */
2594 /* Sleep to avoid unnecessary checks */
2595 prev_time = cur_time;
2600 printf("Press enter to exit\n");
2601 rc = read(0, &c, 1);