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_interrupts.h>
43 #include <rte_ether.h>
44 #include <rte_ethdev.h>
46 #include <rte_string_fns.h>
47 #ifdef RTE_LIBRTE_IXGBE_PMD
48 #include <rte_pmd_ixgbe.h>
50 #ifdef RTE_LIBRTE_PDUMP
51 #include <rte_pdump.h>
54 #include <rte_metrics.h>
55 #ifdef RTE_LIBRTE_BITRATE
56 #include <rte_bitrate.h>
58 #ifdef RTE_LIBRTE_LATENCY_STATS
59 #include <rte_latencystats.h>
64 uint16_t verbose_level = 0; /**< Silent by default. */
65 int testpmd_logtype; /**< Log type for testpmd logs */
67 /* use master core for command line ? */
68 uint8_t interactive = 0;
69 uint8_t auto_start = 0;
71 char cmdline_filename[PATH_MAX] = {0};
74 * NUMA support configuration.
75 * When set, the NUMA support attempts to dispatch the allocation of the
76 * RX and TX memory rings, and of the DMA memory buffers (mbufs) for the
77 * probed ports among the CPU sockets 0 and 1.
78 * Otherwise, all memory is allocated from CPU socket 0.
80 uint8_t numa_support = 1; /**< numa enabled by default */
83 * In UMA mode,all memory is allocated from socket 0 if --socket-num is
86 uint8_t socket_num = UMA_NO_CONFIG;
89 * Use ANONYMOUS mapped memory (might be not physically continuous) for mbufs.
94 * Record the Ethernet address of peer target ports to which packets are
96 * Must be instantiated with the ethernet addresses of peer traffic generator
99 struct ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
100 portid_t nb_peer_eth_addrs = 0;
103 * Probed Target Environment.
105 struct rte_port *ports; /**< For all probed ethernet ports. */
106 portid_t nb_ports; /**< Number of probed ethernet ports. */
107 struct fwd_lcore **fwd_lcores; /**< For all probed logical cores. */
108 lcoreid_t nb_lcores; /**< Number of probed logical cores. */
111 * Test Forwarding Configuration.
112 * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
113 * nb_fwd_ports <= nb_cfg_ports <= nb_ports
115 lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
116 lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
117 portid_t nb_cfg_ports; /**< Number of configured ports. */
118 portid_t nb_fwd_ports; /**< Number of forwarding ports. */
120 unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE]; /**< CPU ids configuration. */
121 portid_t fwd_ports_ids[RTE_MAX_ETHPORTS]; /**< Port ids configuration. */
123 struct fwd_stream **fwd_streams; /**< For each RX queue of each port. */
124 streamid_t nb_fwd_streams; /**< Is equal to (nb_ports * nb_rxq). */
127 * Forwarding engines.
129 struct fwd_engine * fwd_engines[] = {
138 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
140 &softnic_tm_bypass_engine,
142 #ifdef RTE_LIBRTE_IEEE1588
143 &ieee1588_fwd_engine,
148 struct fwd_config cur_fwd_config;
149 struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */
150 uint32_t retry_enabled;
151 uint32_t burst_tx_delay_time = BURST_TX_WAIT_US;
152 uint32_t burst_tx_retry_num = BURST_TX_RETRIES;
154 uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
155 uint32_t param_total_num_mbufs = 0; /**< number of mbufs in all pools - if
156 * specified on command-line. */
157 uint16_t stats_period; /**< Period to show statistics (disabled by default) */
160 * In container, it cannot terminate the process which running with 'stats-period'
161 * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
166 * Configuration of packet segments used by the "txonly" processing engine.
168 uint16_t tx_pkt_length = TXONLY_DEF_PACKET_LEN; /**< TXONLY packet length. */
169 uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT] = {
170 TXONLY_DEF_PACKET_LEN,
172 uint8_t tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */
174 enum tx_pkt_split tx_pkt_split = TX_PKT_SPLIT_OFF;
175 /**< Split policy for packets to TX. */
177 uint16_t nb_pkt_per_burst = DEF_PKT_BURST; /**< Number of packets per burst. */
178 uint16_t mb_mempool_cache = DEF_MBUF_CACHE; /**< Size of mbuf mempool cache. */
180 /* current configuration is in DCB or not,0 means it is not in DCB mode */
181 uint8_t dcb_config = 0;
183 /* Whether the dcb is in testing status */
184 uint8_t dcb_test = 0;
187 * Configurable number of RX/TX queues.
189 queueid_t nb_rxq = 1; /**< Number of RX queues per port. */
190 queueid_t nb_txq = 1; /**< Number of TX queues per port. */
193 * Configurable number of RX/TX ring descriptors.
195 #define RTE_TEST_RX_DESC_DEFAULT 128
196 #define RTE_TEST_TX_DESC_DEFAULT 512
197 uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; /**< Number of RX descriptors. */
198 uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; /**< Number of TX descriptors. */
200 #define RTE_PMD_PARAM_UNSET -1
202 * Configurable values of RX and TX ring threshold registers.
205 int8_t rx_pthresh = RTE_PMD_PARAM_UNSET;
206 int8_t rx_hthresh = RTE_PMD_PARAM_UNSET;
207 int8_t rx_wthresh = RTE_PMD_PARAM_UNSET;
209 int8_t tx_pthresh = RTE_PMD_PARAM_UNSET;
210 int8_t tx_hthresh = RTE_PMD_PARAM_UNSET;
211 int8_t tx_wthresh = RTE_PMD_PARAM_UNSET;
214 * Configurable value of RX free threshold.
216 int16_t rx_free_thresh = RTE_PMD_PARAM_UNSET;
219 * Configurable value of RX drop enable.
221 int8_t rx_drop_en = RTE_PMD_PARAM_UNSET;
224 * Configurable value of TX free threshold.
226 int16_t tx_free_thresh = RTE_PMD_PARAM_UNSET;
229 * Configurable value of TX RS bit threshold.
231 int16_t tx_rs_thresh = RTE_PMD_PARAM_UNSET;
234 * Configurable value of TX queue flags.
236 int32_t txq_flags = RTE_PMD_PARAM_UNSET;
239 * Receive Side Scaling (RSS) configuration.
241 uint64_t rss_hf = ETH_RSS_IP; /* RSS IP by default. */
244 * Port topology configuration
246 uint16_t port_topology = PORT_TOPOLOGY_PAIRED; /* Ports are paired by default */
249 * Avoids to flush all the RX streams before starts forwarding.
251 uint8_t no_flush_rx = 0; /* flush by default */
254 * Flow API isolated mode.
256 uint8_t flow_isolate_all;
259 * Avoids to check link status when starting/stopping a port.
261 uint8_t no_link_check = 0; /* check by default */
264 * Enable link status change notification
266 uint8_t lsc_interrupt = 1; /* enabled by default */
269 * Enable device removal notification.
271 uint8_t rmv_interrupt = 1; /* enabled by default */
274 * Display or mask ether events
275 * Default to all events except VF_MBOX
277 uint32_t event_print_mask = (UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN) |
278 (UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC) |
279 (UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE) |
280 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET) |
281 (UINT32_C(1) << RTE_ETH_EVENT_MACSEC) |
282 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV);
285 * NIC bypass mode configuration options.
288 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
289 /* The NIC bypass watchdog timeout. */
290 uint32_t bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
294 #ifdef RTE_LIBRTE_LATENCY_STATS
297 * Set when latency stats is enabled in the commandline
299 uint8_t latencystats_enabled;
302 * Lcore ID to serive latency statistics.
304 lcoreid_t latencystats_lcore_id = -1;
309 * Ethernet device configuration.
311 struct rte_eth_rxmode rx_mode = {
312 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
313 .offloads = (DEV_RX_OFFLOAD_VLAN_FILTER |
314 DEV_RX_OFFLOAD_VLAN_STRIP |
315 DEV_RX_OFFLOAD_CRC_STRIP),
316 .ignore_offload_bitfield = 1,
319 struct rte_eth_txmode tx_mode;
321 struct rte_fdir_conf fdir_conf = {
322 .mode = RTE_FDIR_MODE_NONE,
323 .pballoc = RTE_FDIR_PBALLOC_64K,
324 .status = RTE_FDIR_REPORT_STATUS,
326 .vlan_tci_mask = 0x0,
328 .src_ip = 0xFFFFFFFF,
329 .dst_ip = 0xFFFFFFFF,
332 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
333 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
335 .src_port_mask = 0xFFFF,
336 .dst_port_mask = 0xFFFF,
337 .mac_addr_byte_mask = 0xFF,
338 .tunnel_type_mask = 1,
339 .tunnel_id_mask = 0xFFFFFFFF,
344 volatile int test_done = 1; /* stop packet forwarding when set to 1. */
346 struct queue_stats_mappings tx_queue_stats_mappings_array[MAX_TX_QUEUE_STATS_MAPPINGS];
347 struct queue_stats_mappings rx_queue_stats_mappings_array[MAX_RX_QUEUE_STATS_MAPPINGS];
349 struct queue_stats_mappings *tx_queue_stats_mappings = tx_queue_stats_mappings_array;
350 struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_array;
352 uint16_t nb_tx_queue_stats_mappings = 0;
353 uint16_t nb_rx_queue_stats_mappings = 0;
356 * Display zero values by default for xstats
358 uint8_t xstats_hide_zero;
360 unsigned int num_sockets = 0;
361 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
363 #ifdef RTE_LIBRTE_BITRATE
364 /* Bitrate statistics */
365 struct rte_stats_bitrates *bitrate_data;
366 lcoreid_t bitrate_lcore_id;
367 uint8_t bitrate_enabled;
370 struct gro_status gro_ports[RTE_MAX_ETHPORTS];
371 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
373 /* Forward function declarations */
374 static void map_port_queue_stats_mapping_registers(portid_t pi,
375 struct rte_port *port);
376 static void check_all_ports_link_status(uint32_t port_mask);
377 static int eth_event_callback(portid_t port_id,
378 enum rte_eth_event_type type,
379 void *param, void *ret_param);
382 * Check if all the ports are started.
383 * If yes, return positive value. If not, return zero.
385 static int all_ports_started(void);
387 struct gso_status gso_ports[RTE_MAX_ETHPORTS];
388 uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
391 * Helper function to check if socket is already discovered.
392 * If yes, return positive value. If not, return zero.
395 new_socket_id(unsigned int socket_id)
399 for (i = 0; i < num_sockets; i++) {
400 if (socket_ids[i] == socket_id)
407 * Setup default configuration.
410 set_default_fwd_lcores_config(void)
414 unsigned int sock_num;
417 for (i = 0; i < RTE_MAX_LCORE; i++) {
418 sock_num = rte_lcore_to_socket_id(i);
419 if (new_socket_id(sock_num)) {
420 if (num_sockets >= RTE_MAX_NUMA_NODES) {
421 rte_exit(EXIT_FAILURE,
422 "Total sockets greater than %u\n",
425 socket_ids[num_sockets++] = sock_num;
427 if (!rte_lcore_is_enabled(i))
429 if (i == rte_get_master_lcore())
431 fwd_lcores_cpuids[nb_lc++] = i;
433 nb_lcores = (lcoreid_t) nb_lc;
434 nb_cfg_lcores = nb_lcores;
439 set_def_peer_eth_addrs(void)
443 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
444 peer_eth_addrs[i].addr_bytes[0] = ETHER_LOCAL_ADMIN_ADDR;
445 peer_eth_addrs[i].addr_bytes[5] = i;
450 set_default_fwd_ports_config(void)
455 RTE_ETH_FOREACH_DEV(pt_id)
456 fwd_ports_ids[i++] = pt_id;
458 nb_cfg_ports = nb_ports;
459 nb_fwd_ports = nb_ports;
463 set_def_fwd_config(void)
465 set_default_fwd_lcores_config();
466 set_def_peer_eth_addrs();
467 set_default_fwd_ports_config();
471 * Configuration initialisation done once at init time.
474 mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
475 unsigned int socket_id)
477 char pool_name[RTE_MEMPOOL_NAMESIZE];
478 struct rte_mempool *rte_mp = NULL;
481 mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
482 mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
485 "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
486 pool_name, nb_mbuf, mbuf_seg_size, socket_id);
489 rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf,
490 mb_size, (unsigned) mb_mempool_cache,
491 sizeof(struct rte_pktmbuf_pool_private),
496 if (rte_mempool_populate_anon(rte_mp) == 0) {
497 rte_mempool_free(rte_mp);
501 rte_pktmbuf_pool_init(rte_mp, NULL);
502 rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
504 /* wrapper to rte_mempool_create() */
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"
544 struct rte_port *port;
545 struct rte_mempool *mbp;
546 unsigned int nb_mbuf_per_pool;
548 uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
549 struct rte_gro_param gro_param;
552 memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
555 memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
556 memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
557 memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
560 /* Configuration of logical cores. */
561 fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
562 sizeof(struct fwd_lcore *) * nb_lcores,
563 RTE_CACHE_LINE_SIZE);
564 if (fwd_lcores == NULL) {
565 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_lcore *)) "
566 "failed\n", nb_lcores);
568 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
569 fwd_lcores[lc_id] = rte_zmalloc("testpmd: struct fwd_lcore",
570 sizeof(struct fwd_lcore),
571 RTE_CACHE_LINE_SIZE);
572 if (fwd_lcores[lc_id] == NULL) {
573 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_lcore) "
576 fwd_lcores[lc_id]->cpuid_idx = lc_id;
579 RTE_ETH_FOREACH_DEV(pid) {
581 /* Apply default Tx configuration for all ports */
582 port->dev_conf.txmode = tx_mode;
583 rte_eth_dev_info_get(pid, &port->dev_info);
586 if (port_numa[pid] != NUMA_NO_CONFIG)
587 port_per_socket[port_numa[pid]]++;
589 uint32_t socket_id = rte_eth_dev_socket_id(pid);
591 /* if socket_id is invalid, set to 0 */
592 if (check_socket_id(socket_id) < 0)
594 port_per_socket[socket_id]++;
598 /* set flag to initialize port/queue */
599 port->need_reconfig = 1;
600 port->need_reconfig_queues = 1;
604 * Create pools of mbuf.
605 * If NUMA support is disabled, create a single pool of mbuf in
606 * socket 0 memory by default.
607 * Otherwise, create a pool of mbuf in the memory of sockets 0 and 1.
609 * Use the maximum value of nb_rxd and nb_txd here, then nb_rxd and
610 * nb_txd can be configured at run time.
612 if (param_total_num_mbufs)
613 nb_mbuf_per_pool = param_total_num_mbufs;
615 nb_mbuf_per_pool = RTE_TEST_RX_DESC_MAX +
616 (nb_lcores * mb_mempool_cache) +
617 RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
618 nb_mbuf_per_pool *= RTE_MAX_ETHPORTS;
624 for (i = 0; i < num_sockets; i++)
625 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
628 if (socket_num == UMA_NO_CONFIG)
629 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 0);
631 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
637 gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
638 DEV_TX_OFFLOAD_GRE_TNL_TSO;
640 * Records which Mbuf pool to use by each logical core, if needed.
642 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
643 mbp = mbuf_pool_find(
644 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]));
647 mbp = mbuf_pool_find(0);
648 fwd_lcores[lc_id]->mbp = mbp;
649 /* initialize GSO context */
650 fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
651 fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
652 fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
653 fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
655 fwd_lcores[lc_id]->gso_ctx.flag = 0;
658 /* Configuration of packet forwarding streams. */
659 if (init_fwd_streams() < 0)
660 rte_exit(EXIT_FAILURE, "FAIL from init_fwd_streams()\n");
664 /* create a gro context for each lcore */
665 gro_param.gro_types = RTE_GRO_TCP_IPV4;
666 gro_param.max_flow_num = GRO_MAX_FLUSH_CYCLES;
667 gro_param.max_item_per_flow = MAX_PKT_BURST;
668 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
669 gro_param.socket_id = rte_lcore_to_socket_id(
670 fwd_lcores_cpuids[lc_id]);
671 fwd_lcores[lc_id]->gro_ctx = rte_gro_ctx_create(&gro_param);
672 if (fwd_lcores[lc_id]->gro_ctx == NULL) {
673 rte_exit(EXIT_FAILURE,
674 "rte_gro_ctx_create() failed\n");
681 reconfig(portid_t new_port_id, unsigned socket_id)
683 struct rte_port *port;
685 /* Reconfiguration of Ethernet ports. */
686 port = &ports[new_port_id];
687 rte_eth_dev_info_get(new_port_id, &port->dev_info);
689 /* set flag to initialize port/queue */
690 port->need_reconfig = 1;
691 port->need_reconfig_queues = 1;
692 port->socket_id = socket_id;
699 init_fwd_streams(void)
702 struct rte_port *port;
703 streamid_t sm_id, nb_fwd_streams_new;
706 /* set socket id according to numa or not */
707 RTE_ETH_FOREACH_DEV(pid) {
709 if (nb_rxq > port->dev_info.max_rx_queues) {
710 printf("Fail: nb_rxq(%d) is greater than "
711 "max_rx_queues(%d)\n", nb_rxq,
712 port->dev_info.max_rx_queues);
715 if (nb_txq > port->dev_info.max_tx_queues) {
716 printf("Fail: nb_txq(%d) is greater than "
717 "max_tx_queues(%d)\n", nb_txq,
718 port->dev_info.max_tx_queues);
722 if (port_numa[pid] != NUMA_NO_CONFIG)
723 port->socket_id = port_numa[pid];
725 port->socket_id = rte_eth_dev_socket_id(pid);
727 /* if socket_id is invalid, set to 0 */
728 if (check_socket_id(port->socket_id) < 0)
733 if (socket_num == UMA_NO_CONFIG)
736 port->socket_id = socket_num;
740 q = RTE_MAX(nb_rxq, nb_txq);
742 printf("Fail: Cannot allocate fwd streams as number of queues is 0\n");
745 nb_fwd_streams_new = (streamid_t)(nb_ports * q);
746 if (nb_fwd_streams_new == nb_fwd_streams)
749 if (fwd_streams != NULL) {
750 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
751 if (fwd_streams[sm_id] == NULL)
753 rte_free(fwd_streams[sm_id]);
754 fwd_streams[sm_id] = NULL;
756 rte_free(fwd_streams);
761 nb_fwd_streams = nb_fwd_streams_new;
762 fwd_streams = rte_zmalloc("testpmd: fwd_streams",
763 sizeof(struct fwd_stream *) * nb_fwd_streams, RTE_CACHE_LINE_SIZE);
764 if (fwd_streams == NULL)
765 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_stream *)) "
766 "failed\n", nb_fwd_streams);
768 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
769 fwd_streams[sm_id] = rte_zmalloc("testpmd: struct fwd_stream",
770 sizeof(struct fwd_stream), RTE_CACHE_LINE_SIZE);
771 if (fwd_streams[sm_id] == NULL)
772 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_stream)"
779 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
781 pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs)
783 unsigned int total_burst;
784 unsigned int nb_burst;
785 unsigned int burst_stats[3];
786 uint16_t pktnb_stats[3];
788 int burst_percent[3];
791 * First compute the total number of packet bursts and the
792 * two highest numbers of bursts of the same number of packets.
795 burst_stats[0] = burst_stats[1] = burst_stats[2] = 0;
796 pktnb_stats[0] = pktnb_stats[1] = pktnb_stats[2] = 0;
797 for (nb_pkt = 0; nb_pkt < MAX_PKT_BURST; nb_pkt++) {
798 nb_burst = pbs->pkt_burst_spread[nb_pkt];
801 total_burst += nb_burst;
802 if (nb_burst > burst_stats[0]) {
803 burst_stats[1] = burst_stats[0];
804 pktnb_stats[1] = pktnb_stats[0];
805 burst_stats[0] = nb_burst;
806 pktnb_stats[0] = nb_pkt;
809 if (total_burst == 0)
811 burst_percent[0] = (burst_stats[0] * 100) / total_burst;
812 printf(" %s-bursts : %u [%d%% of %d pkts", rx_tx, total_burst,
813 burst_percent[0], (int) pktnb_stats[0]);
814 if (burst_stats[0] == total_burst) {
818 if (burst_stats[0] + burst_stats[1] == total_burst) {
819 printf(" + %d%% of %d pkts]\n",
820 100 - burst_percent[0], pktnb_stats[1]);
823 burst_percent[1] = (burst_stats[1] * 100) / total_burst;
824 burst_percent[2] = 100 - (burst_percent[0] + burst_percent[1]);
825 if ((burst_percent[1] == 0) || (burst_percent[2] == 0)) {
826 printf(" + %d%% of others]\n", 100 - burst_percent[0]);
829 printf(" + %d%% of %d pkts + %d%% of others]\n",
830 burst_percent[1], (int) pktnb_stats[1], burst_percent[2]);
832 #endif /* RTE_TEST_PMD_RECORD_BURST_STATS */
835 fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
837 struct rte_port *port;
840 static const char *fwd_stats_border = "----------------------";
842 port = &ports[port_id];
843 printf("\n %s Forward statistics for port %-2d %s\n",
844 fwd_stats_border, port_id, fwd_stats_border);
846 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
847 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
849 stats->ipackets, stats->imissed,
850 (uint64_t) (stats->ipackets + stats->imissed));
852 if (cur_fwd_eng == &csum_fwd_engine)
853 printf(" Bad-ipcsum: %-14"PRIu64" Bad-l4csum: %-14"PRIu64" \n",
854 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
855 if ((stats->ierrors + stats->rx_nombuf) > 0) {
856 printf(" RX-error: %-"PRIu64"\n", stats->ierrors);
857 printf(" RX-nombufs: %-14"PRIu64"\n", stats->rx_nombuf);
860 printf(" TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
862 stats->opackets, port->tx_dropped,
863 (uint64_t) (stats->opackets + port->tx_dropped));
866 printf(" RX-packets: %14"PRIu64" RX-dropped:%14"PRIu64" RX-total:"
868 stats->ipackets, stats->imissed,
869 (uint64_t) (stats->ipackets + stats->imissed));
871 if (cur_fwd_eng == &csum_fwd_engine)
872 printf(" Bad-ipcsum:%14"PRIu64" Bad-l4csum:%14"PRIu64"\n",
873 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
874 if ((stats->ierrors + stats->rx_nombuf) > 0) {
875 printf(" RX-error:%"PRIu64"\n", stats->ierrors);
876 printf(" RX-nombufs: %14"PRIu64"\n",
880 printf(" TX-packets: %14"PRIu64" TX-dropped:%14"PRIu64" TX-total:"
882 stats->opackets, port->tx_dropped,
883 (uint64_t) (stats->opackets + port->tx_dropped));
886 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
888 pkt_burst_stats_display("RX",
889 &port->rx_stream->rx_burst_stats);
891 pkt_burst_stats_display("TX",
892 &port->tx_stream->tx_burst_stats);
895 if (port->rx_queue_stats_mapping_enabled) {
897 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
898 printf(" Stats reg %2d RX-packets:%14"PRIu64
899 " RX-errors:%14"PRIu64
900 " RX-bytes:%14"PRIu64"\n",
901 i, stats->q_ipackets[i], stats->q_errors[i], stats->q_ibytes[i]);
905 if (port->tx_queue_stats_mapping_enabled) {
906 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
907 printf(" Stats reg %2d TX-packets:%14"PRIu64
908 " TX-bytes:%14"PRIu64"\n",
909 i, stats->q_opackets[i], stats->q_obytes[i]);
913 printf(" %s--------------------------------%s\n",
914 fwd_stats_border, fwd_stats_border);
918 fwd_stream_stats_display(streamid_t stream_id)
920 struct fwd_stream *fs;
921 static const char *fwd_top_stats_border = "-------";
923 fs = fwd_streams[stream_id];
924 if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
925 (fs->fwd_dropped == 0))
927 printf("\n %s Forward Stats for RX Port=%2d/Queue=%2d -> "
928 "TX Port=%2d/Queue=%2d %s\n",
929 fwd_top_stats_border, fs->rx_port, fs->rx_queue,
930 fs->tx_port, fs->tx_queue, fwd_top_stats_border);
931 printf(" RX-packets: %-14u TX-packets: %-14u TX-dropped: %-14u",
932 fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
934 /* if checksum mode */
935 if (cur_fwd_eng == &csum_fwd_engine) {
936 printf(" RX- bad IP checksum: %-14u Rx- bad L4 checksum: "
937 "%-14u\n", fs->rx_bad_ip_csum, fs->rx_bad_l4_csum);
940 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
941 pkt_burst_stats_display("RX", &fs->rx_burst_stats);
942 pkt_burst_stats_display("TX", &fs->tx_burst_stats);
947 flush_fwd_rx_queues(void)
949 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
956 uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
957 uint64_t timer_period;
959 /* convert to number of cycles */
960 timer_period = rte_get_timer_hz(); /* 1 second timeout */
962 for (j = 0; j < 2; j++) {
963 for (rxp = 0; rxp < cur_fwd_config.nb_fwd_ports; rxp++) {
964 for (rxq = 0; rxq < nb_rxq; rxq++) {
965 port_id = fwd_ports_ids[rxp];
967 * testpmd can stuck in the below do while loop
968 * if rte_eth_rx_burst() always returns nonzero
969 * packets. So timer is added to exit this loop
970 * after 1sec timer expiry.
972 prev_tsc = rte_rdtsc();
974 nb_rx = rte_eth_rx_burst(port_id, rxq,
975 pkts_burst, MAX_PKT_BURST);
976 for (i = 0; i < nb_rx; i++)
977 rte_pktmbuf_free(pkts_burst[i]);
979 cur_tsc = rte_rdtsc();
980 diff_tsc = cur_tsc - prev_tsc;
981 timer_tsc += diff_tsc;
982 } while ((nb_rx > 0) &&
983 (timer_tsc < timer_period));
987 rte_delay_ms(10); /* wait 10 milli-seconds before retrying */
992 run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
994 struct fwd_stream **fsm;
997 #ifdef RTE_LIBRTE_BITRATE
998 uint64_t tics_per_1sec;
1000 uint64_t tics_current;
1001 uint8_t idx_port, cnt_ports;
1003 cnt_ports = rte_eth_dev_count();
1004 tics_datum = rte_rdtsc();
1005 tics_per_1sec = rte_get_timer_hz();
1007 fsm = &fwd_streams[fc->stream_idx];
1008 nb_fs = fc->stream_nb;
1010 for (sm_id = 0; sm_id < nb_fs; sm_id++)
1011 (*pkt_fwd)(fsm[sm_id]);
1012 #ifdef RTE_LIBRTE_BITRATE
1013 if (bitrate_enabled != 0 &&
1014 bitrate_lcore_id == rte_lcore_id()) {
1015 tics_current = rte_rdtsc();
1016 if (tics_current - tics_datum >= tics_per_1sec) {
1017 /* Periodic bitrate calculation */
1019 idx_port < cnt_ports;
1021 rte_stats_bitrate_calc(bitrate_data,
1023 tics_datum = tics_current;
1027 #ifdef RTE_LIBRTE_LATENCY_STATS
1028 if (latencystats_enabled != 0 &&
1029 latencystats_lcore_id == rte_lcore_id())
1030 rte_latencystats_update();
1033 } while (! fc->stopped);
1037 start_pkt_forward_on_core(void *fwd_arg)
1039 run_pkt_fwd_on_lcore((struct fwd_lcore *) fwd_arg,
1040 cur_fwd_config.fwd_eng->packet_fwd);
1045 * Run the TXONLY packet forwarding engine to send a single burst of packets.
1046 * Used to start communication flows in network loopback test configurations.
1049 run_one_txonly_burst_on_core(void *fwd_arg)
1051 struct fwd_lcore *fwd_lc;
1052 struct fwd_lcore tmp_lcore;
1054 fwd_lc = (struct fwd_lcore *) fwd_arg;
1055 tmp_lcore = *fwd_lc;
1056 tmp_lcore.stopped = 1;
1057 run_pkt_fwd_on_lcore(&tmp_lcore, tx_only_engine.packet_fwd);
1062 * Launch packet forwarding:
1063 * - Setup per-port forwarding context.
1064 * - launch logical cores with their forwarding configuration.
1067 launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
1069 port_fwd_begin_t port_fwd_begin;
1074 port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
1075 if (port_fwd_begin != NULL) {
1076 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1077 (*port_fwd_begin)(fwd_ports_ids[i]);
1079 for (i = 0; i < cur_fwd_config.nb_fwd_lcores; i++) {
1080 lc_id = fwd_lcores_cpuids[i];
1081 if ((interactive == 0) || (lc_id != rte_lcore_id())) {
1082 fwd_lcores[i]->stopped = 0;
1083 diag = rte_eal_remote_launch(pkt_fwd_on_lcore,
1084 fwd_lcores[i], lc_id);
1086 printf("launch lcore %u failed - diag=%d\n",
1093 * Launch packet forwarding configuration.
1096 start_packet_forwarding(int with_tx_first)
1098 port_fwd_begin_t port_fwd_begin;
1099 port_fwd_end_t port_fwd_end;
1100 struct rte_port *port;
1105 if (strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") == 0 && !nb_rxq)
1106 rte_exit(EXIT_FAILURE, "rxq are 0, cannot use rxonly fwd mode\n");
1108 if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 && !nb_txq)
1109 rte_exit(EXIT_FAILURE, "txq are 0, cannot use txonly fwd mode\n");
1111 if ((strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") != 0 &&
1112 strcmp(cur_fwd_eng->fwd_mode_name, "txonly") != 0) &&
1113 (!nb_rxq || !nb_txq))
1114 rte_exit(EXIT_FAILURE,
1115 "Either rxq or txq are 0, cannot use %s fwd mode\n",
1116 cur_fwd_eng->fwd_mode_name);
1118 if (all_ports_started() == 0) {
1119 printf("Not all ports were started\n");
1122 if (test_done == 0) {
1123 printf("Packet forwarding already started\n");
1127 if (init_fwd_streams() < 0) {
1128 printf("Fail from init_fwd_streams()\n");
1133 for (i = 0; i < nb_fwd_ports; i++) {
1134 pt_id = fwd_ports_ids[i];
1135 port = &ports[pt_id];
1136 if (!port->dcb_flag) {
1137 printf("In DCB mode, all forwarding ports must "
1138 "be configured in this mode.\n");
1142 if (nb_fwd_lcores == 1) {
1143 printf("In DCB mode,the nb forwarding cores "
1144 "should be larger than 1.\n");
1151 flush_fwd_rx_queues();
1154 pkt_fwd_config_display(&cur_fwd_config);
1155 rxtx_config_display();
1157 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1158 pt_id = fwd_ports_ids[i];
1159 port = &ports[pt_id];
1160 rte_eth_stats_get(pt_id, &port->stats);
1161 port->tx_dropped = 0;
1163 map_port_queue_stats_mapping_registers(pt_id, port);
1165 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1166 fwd_streams[sm_id]->rx_packets = 0;
1167 fwd_streams[sm_id]->tx_packets = 0;
1168 fwd_streams[sm_id]->fwd_dropped = 0;
1169 fwd_streams[sm_id]->rx_bad_ip_csum = 0;
1170 fwd_streams[sm_id]->rx_bad_l4_csum = 0;
1172 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1173 memset(&fwd_streams[sm_id]->rx_burst_stats, 0,
1174 sizeof(fwd_streams[sm_id]->rx_burst_stats));
1175 memset(&fwd_streams[sm_id]->tx_burst_stats, 0,
1176 sizeof(fwd_streams[sm_id]->tx_burst_stats));
1178 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1179 fwd_streams[sm_id]->core_cycles = 0;
1182 if (with_tx_first) {
1183 port_fwd_begin = tx_only_engine.port_fwd_begin;
1184 if (port_fwd_begin != NULL) {
1185 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1186 (*port_fwd_begin)(fwd_ports_ids[i]);
1188 while (with_tx_first--) {
1189 launch_packet_forwarding(
1190 run_one_txonly_burst_on_core);
1191 rte_eal_mp_wait_lcore();
1193 port_fwd_end = tx_only_engine.port_fwd_end;
1194 if (port_fwd_end != NULL) {
1195 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1196 (*port_fwd_end)(fwd_ports_ids[i]);
1199 launch_packet_forwarding(start_pkt_forward_on_core);
1203 stop_packet_forwarding(void)
1205 struct rte_eth_stats stats;
1206 struct rte_port *port;
1207 port_fwd_end_t port_fwd_end;
1212 uint64_t total_recv;
1213 uint64_t total_xmit;
1214 uint64_t total_rx_dropped;
1215 uint64_t total_tx_dropped;
1216 uint64_t total_rx_nombuf;
1217 uint64_t tx_dropped;
1218 uint64_t rx_bad_ip_csum;
1219 uint64_t rx_bad_l4_csum;
1220 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1221 uint64_t fwd_cycles;
1224 static const char *acc_stats_border = "+++++++++++++++";
1227 printf("Packet forwarding not started\n");
1230 printf("Telling cores to stop...");
1231 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++)
1232 fwd_lcores[lc_id]->stopped = 1;
1233 printf("\nWaiting for lcores to finish...\n");
1234 rte_eal_mp_wait_lcore();
1235 port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end;
1236 if (port_fwd_end != NULL) {
1237 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1238 pt_id = fwd_ports_ids[i];
1239 (*port_fwd_end)(pt_id);
1242 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1245 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1246 if (cur_fwd_config.nb_fwd_streams >
1247 cur_fwd_config.nb_fwd_ports) {
1248 fwd_stream_stats_display(sm_id);
1249 ports[fwd_streams[sm_id]->tx_port].tx_stream = NULL;
1250 ports[fwd_streams[sm_id]->rx_port].rx_stream = NULL;
1252 ports[fwd_streams[sm_id]->tx_port].tx_stream =
1254 ports[fwd_streams[sm_id]->rx_port].rx_stream =
1257 tx_dropped = ports[fwd_streams[sm_id]->tx_port].tx_dropped;
1258 tx_dropped = (uint64_t) (tx_dropped +
1259 fwd_streams[sm_id]->fwd_dropped);
1260 ports[fwd_streams[sm_id]->tx_port].tx_dropped = tx_dropped;
1263 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum;
1264 rx_bad_ip_csum = (uint64_t) (rx_bad_ip_csum +
1265 fwd_streams[sm_id]->rx_bad_ip_csum);
1266 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum =
1270 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum;
1271 rx_bad_l4_csum = (uint64_t) (rx_bad_l4_csum +
1272 fwd_streams[sm_id]->rx_bad_l4_csum);
1273 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum =
1276 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1277 fwd_cycles = (uint64_t) (fwd_cycles +
1278 fwd_streams[sm_id]->core_cycles);
1283 total_rx_dropped = 0;
1284 total_tx_dropped = 0;
1285 total_rx_nombuf = 0;
1286 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1287 pt_id = fwd_ports_ids[i];
1289 port = &ports[pt_id];
1290 rte_eth_stats_get(pt_id, &stats);
1291 stats.ipackets -= port->stats.ipackets;
1292 port->stats.ipackets = 0;
1293 stats.opackets -= port->stats.opackets;
1294 port->stats.opackets = 0;
1295 stats.ibytes -= port->stats.ibytes;
1296 port->stats.ibytes = 0;
1297 stats.obytes -= port->stats.obytes;
1298 port->stats.obytes = 0;
1299 stats.imissed -= port->stats.imissed;
1300 port->stats.imissed = 0;
1301 stats.oerrors -= port->stats.oerrors;
1302 port->stats.oerrors = 0;
1303 stats.rx_nombuf -= port->stats.rx_nombuf;
1304 port->stats.rx_nombuf = 0;
1306 total_recv += stats.ipackets;
1307 total_xmit += stats.opackets;
1308 total_rx_dropped += stats.imissed;
1309 total_tx_dropped += port->tx_dropped;
1310 total_rx_nombuf += stats.rx_nombuf;
1312 fwd_port_stats_display(pt_id, &stats);
1315 printf("\n %s Accumulated forward statistics for all ports"
1317 acc_stats_border, acc_stats_border);
1318 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
1320 " TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
1322 total_recv, total_rx_dropped, total_recv + total_rx_dropped,
1323 total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
1324 if (total_rx_nombuf > 0)
1325 printf(" RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
1326 printf(" %s++++++++++++++++++++++++++++++++++++++++++++++"
1328 acc_stats_border, acc_stats_border);
1329 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1331 printf("\n CPU cycles/packet=%u (total cycles="
1332 "%"PRIu64" / total RX packets=%"PRIu64")\n",
1333 (unsigned int)(fwd_cycles / total_recv),
1334 fwd_cycles, total_recv);
1336 printf("\nDone.\n");
1341 dev_set_link_up(portid_t pid)
1343 if (rte_eth_dev_set_link_up(pid) < 0)
1344 printf("\nSet link up fail.\n");
1348 dev_set_link_down(portid_t pid)
1350 if (rte_eth_dev_set_link_down(pid) < 0)
1351 printf("\nSet link down fail.\n");
1355 all_ports_started(void)
1358 struct rte_port *port;
1360 RTE_ETH_FOREACH_DEV(pi) {
1362 /* Check if there is a port which is not started */
1363 if ((port->port_status != RTE_PORT_STARTED) &&
1364 (port->slave_flag == 0))
1368 /* No port is not started */
1373 port_is_stopped(portid_t port_id)
1375 struct rte_port *port = &ports[port_id];
1377 if ((port->port_status != RTE_PORT_STOPPED) &&
1378 (port->slave_flag == 0))
1384 all_ports_stopped(void)
1388 RTE_ETH_FOREACH_DEV(pi) {
1389 if (!port_is_stopped(pi))
1397 port_is_started(portid_t port_id)
1399 if (port_id_is_invalid(port_id, ENABLED_WARN))
1402 if (ports[port_id].port_status != RTE_PORT_STARTED)
1409 port_is_closed(portid_t port_id)
1411 if (port_id_is_invalid(port_id, ENABLED_WARN))
1414 if (ports[port_id].port_status != RTE_PORT_CLOSED)
1421 start_port(portid_t pid)
1423 int diag, need_check_link_status = -1;
1426 struct rte_port *port;
1427 struct ether_addr mac_addr;
1428 enum rte_eth_event_type event_type;
1430 if (port_id_is_invalid(pid, ENABLED_WARN))
1435 RTE_ETH_FOREACH_DEV(pi) {
1436 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1439 need_check_link_status = 0;
1441 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STOPPED,
1442 RTE_PORT_HANDLING) == 0) {
1443 printf("Port %d is now not stopped\n", pi);
1447 if (port->need_reconfig > 0) {
1448 port->need_reconfig = 0;
1450 if (flow_isolate_all) {
1451 int ret = port_flow_isolate(pi, 1);
1453 printf("Failed to apply isolated"
1454 " mode on port %d\n", pi);
1459 printf("Configuring Port %d (socket %u)\n", pi,
1461 /* configure port */
1462 diag = rte_eth_dev_configure(pi, nb_rxq, nb_txq,
1465 if (rte_atomic16_cmpset(&(port->port_status),
1466 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1467 printf("Port %d can not be set back "
1468 "to stopped\n", pi);
1469 printf("Fail to configure port %d\n", pi);
1470 /* try to reconfigure port next time */
1471 port->need_reconfig = 1;
1475 if (port->need_reconfig_queues > 0) {
1476 port->need_reconfig_queues = 0;
1477 port->tx_conf.txq_flags = ETH_TXQ_FLAGS_IGNORE;
1478 /* Apply Tx offloads configuration */
1479 port->tx_conf.offloads = port->dev_conf.txmode.offloads;
1480 /* setup tx queues */
1481 for (qi = 0; qi < nb_txq; qi++) {
1482 if ((numa_support) &&
1483 (txring_numa[pi] != NUMA_NO_CONFIG))
1484 diag = rte_eth_tx_queue_setup(pi, qi,
1485 nb_txd,txring_numa[pi],
1488 diag = rte_eth_tx_queue_setup(pi, qi,
1489 nb_txd,port->socket_id,
1495 /* Fail to setup tx queue, return */
1496 if (rte_atomic16_cmpset(&(port->port_status),
1498 RTE_PORT_STOPPED) == 0)
1499 printf("Port %d can not be set back "
1500 "to stopped\n", pi);
1501 printf("Fail to configure port %d tx queues\n", pi);
1502 /* try to reconfigure queues next time */
1503 port->need_reconfig_queues = 1;
1506 /* Apply Rx offloads configuration */
1507 port->rx_conf.offloads = port->dev_conf.rxmode.offloads;
1508 /* setup rx queues */
1509 for (qi = 0; qi < nb_rxq; qi++) {
1510 if ((numa_support) &&
1511 (rxring_numa[pi] != NUMA_NO_CONFIG)) {
1512 struct rte_mempool * mp =
1513 mbuf_pool_find(rxring_numa[pi]);
1515 printf("Failed to setup RX queue:"
1516 "No mempool allocation"
1517 " on the socket %d\n",
1522 diag = rte_eth_rx_queue_setup(pi, qi,
1523 nb_rxd,rxring_numa[pi],
1524 &(port->rx_conf),mp);
1526 struct rte_mempool *mp =
1527 mbuf_pool_find(port->socket_id);
1529 printf("Failed to setup RX queue:"
1530 "No mempool allocation"
1531 " on the socket %d\n",
1535 diag = rte_eth_rx_queue_setup(pi, qi,
1536 nb_rxd,port->socket_id,
1537 &(port->rx_conf), mp);
1542 /* Fail to setup rx queue, return */
1543 if (rte_atomic16_cmpset(&(port->port_status),
1545 RTE_PORT_STOPPED) == 0)
1546 printf("Port %d can not be set back "
1547 "to stopped\n", pi);
1548 printf("Fail to configure port %d rx queues\n", pi);
1549 /* try to reconfigure queues next time */
1550 port->need_reconfig_queues = 1;
1555 for (event_type = RTE_ETH_EVENT_UNKNOWN;
1556 event_type < RTE_ETH_EVENT_MAX;
1558 diag = rte_eth_dev_callback_register(pi,
1563 printf("Failed to setup even callback for event %d\n",
1570 if (rte_eth_dev_start(pi) < 0) {
1571 printf("Fail to start port %d\n", pi);
1573 /* Fail to setup rx queue, return */
1574 if (rte_atomic16_cmpset(&(port->port_status),
1575 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1576 printf("Port %d can not be set back to "
1581 if (rte_atomic16_cmpset(&(port->port_status),
1582 RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0)
1583 printf("Port %d can not be set into started\n", pi);
1585 rte_eth_macaddr_get(pi, &mac_addr);
1586 printf("Port %d: %02X:%02X:%02X:%02X:%02X:%02X\n", pi,
1587 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
1588 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
1589 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5]);
1591 /* at least one port started, need checking link status */
1592 need_check_link_status = 1;
1595 if (need_check_link_status == 1 && !no_link_check)
1596 check_all_ports_link_status(RTE_PORT_ALL);
1597 else if (need_check_link_status == 0)
1598 printf("Please stop the ports first\n");
1605 stop_port(portid_t pid)
1608 struct rte_port *port;
1609 int need_check_link_status = 0;
1616 if (port_id_is_invalid(pid, ENABLED_WARN))
1619 printf("Stopping ports...\n");
1621 RTE_ETH_FOREACH_DEV(pi) {
1622 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1625 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1626 printf("Please remove port %d from forwarding configuration.\n", pi);
1630 if (port_is_bonding_slave(pi)) {
1631 printf("Please remove port %d from bonded device.\n", pi);
1636 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STARTED,
1637 RTE_PORT_HANDLING) == 0)
1640 rte_eth_dev_stop(pi);
1642 if (rte_atomic16_cmpset(&(port->port_status),
1643 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1644 printf("Port %d can not be set into stopped\n", pi);
1645 need_check_link_status = 1;
1647 if (need_check_link_status && !no_link_check)
1648 check_all_ports_link_status(RTE_PORT_ALL);
1654 close_port(portid_t pid)
1657 struct rte_port *port;
1659 if (port_id_is_invalid(pid, ENABLED_WARN))
1662 printf("Closing ports...\n");
1664 RTE_ETH_FOREACH_DEV(pi) {
1665 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1668 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1669 printf("Please remove port %d from forwarding configuration.\n", pi);
1673 if (port_is_bonding_slave(pi)) {
1674 printf("Please remove port %d from bonded device.\n", pi);
1679 if (rte_atomic16_cmpset(&(port->port_status),
1680 RTE_PORT_CLOSED, RTE_PORT_CLOSED) == 1) {
1681 printf("Port %d is already closed\n", pi);
1685 if (rte_atomic16_cmpset(&(port->port_status),
1686 RTE_PORT_STOPPED, RTE_PORT_HANDLING) == 0) {
1687 printf("Port %d is now not stopped\n", pi);
1691 if (port->flow_list)
1692 port_flow_flush(pi);
1693 rte_eth_dev_close(pi);
1695 if (rte_atomic16_cmpset(&(port->port_status),
1696 RTE_PORT_HANDLING, RTE_PORT_CLOSED) == 0)
1697 printf("Port %d cannot be set to closed\n", pi);
1704 reset_port(portid_t pid)
1708 struct rte_port *port;
1710 if (port_id_is_invalid(pid, ENABLED_WARN))
1713 printf("Resetting ports...\n");
1715 RTE_ETH_FOREACH_DEV(pi) {
1716 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1719 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1720 printf("Please remove port %d from forwarding "
1721 "configuration.\n", pi);
1725 if (port_is_bonding_slave(pi)) {
1726 printf("Please remove port %d from bonded device.\n",
1731 diag = rte_eth_dev_reset(pi);
1734 port->need_reconfig = 1;
1735 port->need_reconfig_queues = 1;
1737 printf("Failed to reset port %d. diag=%d\n", pi, diag);
1745 attach_port(char *identifier)
1748 unsigned int socket_id;
1750 printf("Attaching a new port...\n");
1752 if (identifier == NULL) {
1753 printf("Invalid parameters are specified\n");
1757 if (rte_eth_dev_attach(identifier, &pi))
1760 socket_id = (unsigned)rte_eth_dev_socket_id(pi);
1761 /* if socket_id is invalid, set to 0 */
1762 if (check_socket_id(socket_id) < 0)
1764 reconfig(pi, socket_id);
1765 rte_eth_promiscuous_enable(pi);
1767 nb_ports = rte_eth_dev_count();
1769 ports[pi].port_status = RTE_PORT_STOPPED;
1771 printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
1776 detach_port(portid_t port_id)
1778 char name[RTE_ETH_NAME_MAX_LEN];
1780 printf("Detaching a port...\n");
1782 if (!port_is_closed(port_id)) {
1783 printf("Please close port first\n");
1787 if (ports[port_id].flow_list)
1788 port_flow_flush(port_id);
1790 if (rte_eth_dev_detach(port_id, name)) {
1791 TESTPMD_LOG(ERR, "Failed to detach port '%s'\n", name);
1795 nb_ports = rte_eth_dev_count();
1797 printf("Port '%s' is detached. Now total ports is %d\n",
1809 stop_packet_forwarding();
1811 if (ports != NULL) {
1813 RTE_ETH_FOREACH_DEV(pt_id) {
1814 printf("\nShutting down port %d...\n", pt_id);
1820 printf("\nBye...\n");
1823 typedef void (*cmd_func_t)(void);
1824 struct pmd_test_command {
1825 const char *cmd_name;
1826 cmd_func_t cmd_func;
1829 #define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
1831 /* Check the link status of all ports in up to 9s, and print them finally */
1833 check_all_ports_link_status(uint32_t port_mask)
1835 #define CHECK_INTERVAL 100 /* 100ms */
1836 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1838 uint8_t count, all_ports_up, print_flag = 0;
1839 struct rte_eth_link link;
1841 printf("Checking link statuses...\n");
1843 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1845 RTE_ETH_FOREACH_DEV(portid) {
1846 if ((port_mask & (1 << portid)) == 0)
1848 memset(&link, 0, sizeof(link));
1849 rte_eth_link_get_nowait(portid, &link);
1850 /* print link status if flag set */
1851 if (print_flag == 1) {
1852 if (link.link_status)
1854 "Port%d Link Up. speed %u Mbps- %s\n",
1855 portid, link.link_speed,
1856 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1857 ("full-duplex") : ("half-duplex\n"));
1859 printf("Port %d Link Down\n", portid);
1862 /* clear all_ports_up flag if any link down */
1863 if (link.link_status == ETH_LINK_DOWN) {
1868 /* after finally printing all link status, get out */
1869 if (print_flag == 1)
1872 if (all_ports_up == 0) {
1874 rte_delay_ms(CHECK_INTERVAL);
1877 /* set the print_flag if all ports up or timeout */
1878 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
1888 rmv_event_callback(void *arg)
1890 struct rte_eth_dev *dev;
1891 portid_t port_id = (intptr_t)arg;
1893 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1894 dev = &rte_eth_devices[port_id];
1897 close_port(port_id);
1898 printf("removing device %s\n", dev->device->name);
1899 if (rte_eal_dev_detach(dev->device))
1900 TESTPMD_LOG(ERR, "Failed to detach device %s\n",
1904 /* This function is used by the interrupt thread */
1906 eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
1909 static const char * const event_desc[] = {
1910 [RTE_ETH_EVENT_UNKNOWN] = "Unknown",
1911 [RTE_ETH_EVENT_INTR_LSC] = "LSC",
1912 [RTE_ETH_EVENT_QUEUE_STATE] = "Queue state",
1913 [RTE_ETH_EVENT_INTR_RESET] = "Interrupt reset",
1914 [RTE_ETH_EVENT_VF_MBOX] = "VF Mbox",
1915 [RTE_ETH_EVENT_MACSEC] = "MACsec",
1916 [RTE_ETH_EVENT_INTR_RMV] = "device removal",
1917 [RTE_ETH_EVENT_MAX] = NULL,
1920 RTE_SET_USED(param);
1921 RTE_SET_USED(ret_param);
1923 if (type >= RTE_ETH_EVENT_MAX) {
1924 fprintf(stderr, "\nPort %" PRIu8 ": %s called upon invalid event %d\n",
1925 port_id, __func__, type);
1927 } else if (event_print_mask & (UINT32_C(1) << type)) {
1928 printf("\nPort %" PRIu8 ": %s event\n", port_id,
1934 case RTE_ETH_EVENT_INTR_RMV:
1935 if (rte_eal_alarm_set(100000,
1936 rmv_event_callback, (void *)(intptr_t)port_id))
1937 fprintf(stderr, "Could not set up deferred device removal\n");
1946 set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
1950 uint8_t mapping_found = 0;
1952 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1953 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1954 (tx_queue_stats_mappings[i].queue_id < nb_txq )) {
1955 diag = rte_eth_dev_set_tx_queue_stats_mapping(port_id,
1956 tx_queue_stats_mappings[i].queue_id,
1957 tx_queue_stats_mappings[i].stats_counter_id);
1964 port->tx_queue_stats_mapping_enabled = 1;
1969 set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
1973 uint8_t mapping_found = 0;
1975 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1976 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1977 (rx_queue_stats_mappings[i].queue_id < nb_rxq )) {
1978 diag = rte_eth_dev_set_rx_queue_stats_mapping(port_id,
1979 rx_queue_stats_mappings[i].queue_id,
1980 rx_queue_stats_mappings[i].stats_counter_id);
1987 port->rx_queue_stats_mapping_enabled = 1;
1992 map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
1996 diag = set_tx_queue_stats_mapping_registers(pi, port);
1998 if (diag == -ENOTSUP) {
1999 port->tx_queue_stats_mapping_enabled = 0;
2000 printf("TX queue stats mapping not supported port id=%d\n", pi);
2003 rte_exit(EXIT_FAILURE,
2004 "set_tx_queue_stats_mapping_registers "
2005 "failed for port id=%d diag=%d\n",
2009 diag = set_rx_queue_stats_mapping_registers(pi, port);
2011 if (diag == -ENOTSUP) {
2012 port->rx_queue_stats_mapping_enabled = 0;
2013 printf("RX queue stats mapping not supported port id=%d\n", pi);
2016 rte_exit(EXIT_FAILURE,
2017 "set_rx_queue_stats_mapping_registers "
2018 "failed for port id=%d diag=%d\n",
2024 rxtx_port_config(struct rte_port *port)
2026 port->rx_conf = port->dev_info.default_rxconf;
2027 port->tx_conf = port->dev_info.default_txconf;
2029 /* Check if any RX/TX parameters have been passed */
2030 if (rx_pthresh != RTE_PMD_PARAM_UNSET)
2031 port->rx_conf.rx_thresh.pthresh = rx_pthresh;
2033 if (rx_hthresh != RTE_PMD_PARAM_UNSET)
2034 port->rx_conf.rx_thresh.hthresh = rx_hthresh;
2036 if (rx_wthresh != RTE_PMD_PARAM_UNSET)
2037 port->rx_conf.rx_thresh.wthresh = rx_wthresh;
2039 if (rx_free_thresh != RTE_PMD_PARAM_UNSET)
2040 port->rx_conf.rx_free_thresh = rx_free_thresh;
2042 if (rx_drop_en != RTE_PMD_PARAM_UNSET)
2043 port->rx_conf.rx_drop_en = rx_drop_en;
2045 if (tx_pthresh != RTE_PMD_PARAM_UNSET)
2046 port->tx_conf.tx_thresh.pthresh = tx_pthresh;
2048 if (tx_hthresh != RTE_PMD_PARAM_UNSET)
2049 port->tx_conf.tx_thresh.hthresh = tx_hthresh;
2051 if (tx_wthresh != RTE_PMD_PARAM_UNSET)
2052 port->tx_conf.tx_thresh.wthresh = tx_wthresh;
2054 if (tx_rs_thresh != RTE_PMD_PARAM_UNSET)
2055 port->tx_conf.tx_rs_thresh = tx_rs_thresh;
2057 if (tx_free_thresh != RTE_PMD_PARAM_UNSET)
2058 port->tx_conf.tx_free_thresh = tx_free_thresh;
2060 if (txq_flags != RTE_PMD_PARAM_UNSET)
2061 port->tx_conf.txq_flags = txq_flags;
2065 init_port_config(void)
2068 struct rte_port *port;
2070 RTE_ETH_FOREACH_DEV(pid) {
2072 port->dev_conf.rxmode = rx_mode;
2073 port->dev_conf.fdir_conf = fdir_conf;
2075 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2076 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = rss_hf;
2078 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2079 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = 0;
2082 if (port->dcb_flag == 0) {
2083 if( port->dev_conf.rx_adv_conf.rss_conf.rss_hf != 0)
2084 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
2086 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
2089 rxtx_port_config(port);
2091 rte_eth_macaddr_get(pid, &port->eth_addr);
2093 map_port_queue_stats_mapping_registers(pid, port);
2094 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
2095 rte_pmd_ixgbe_bypass_init(pid);
2098 if (lsc_interrupt &&
2099 (rte_eth_devices[pid].data->dev_flags &
2100 RTE_ETH_DEV_INTR_LSC))
2101 port->dev_conf.intr_conf.lsc = 1;
2102 if (rmv_interrupt &&
2103 (rte_eth_devices[pid].data->dev_flags &
2104 RTE_ETH_DEV_INTR_RMV))
2105 port->dev_conf.intr_conf.rmv = 1;
2107 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
2108 /* Detect softnic port */
2109 if (!strcmp(port->dev_info.driver_name, "net_softnic")) {
2110 port->softnic_enable = 1;
2111 memset(&port->softport, 0, sizeof(struct softnic_port));
2113 if (!strcmp(cur_fwd_eng->fwd_mode_name, "tm"))
2114 port->softport.tm_flag = 1;
2120 void set_port_slave_flag(portid_t slave_pid)
2122 struct rte_port *port;
2124 port = &ports[slave_pid];
2125 port->slave_flag = 1;
2128 void clear_port_slave_flag(portid_t slave_pid)
2130 struct rte_port *port;
2132 port = &ports[slave_pid];
2133 port->slave_flag = 0;
2136 uint8_t port_is_bonding_slave(portid_t slave_pid)
2138 struct rte_port *port;
2140 port = &ports[slave_pid];
2141 return port->slave_flag;
2144 const uint16_t vlan_tags[] = {
2145 0, 1, 2, 3, 4, 5, 6, 7,
2146 8, 9, 10, 11, 12, 13, 14, 15,
2147 16, 17, 18, 19, 20, 21, 22, 23,
2148 24, 25, 26, 27, 28, 29, 30, 31
2152 get_eth_dcb_conf(struct rte_eth_conf *eth_conf,
2153 enum dcb_mode_enable dcb_mode,
2154 enum rte_eth_nb_tcs num_tcs,
2160 * Builds up the correct configuration for dcb+vt based on the vlan tags array
2161 * given above, and the number of traffic classes available for use.
2163 if (dcb_mode == DCB_VT_ENABLED) {
2164 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
2165 ð_conf->rx_adv_conf.vmdq_dcb_conf;
2166 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
2167 ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
2169 /* VMDQ+DCB RX and TX configurations */
2170 vmdq_rx_conf->enable_default_pool = 0;
2171 vmdq_rx_conf->default_pool = 0;
2172 vmdq_rx_conf->nb_queue_pools =
2173 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2174 vmdq_tx_conf->nb_queue_pools =
2175 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2177 vmdq_rx_conf->nb_pool_maps = vmdq_rx_conf->nb_queue_pools;
2178 for (i = 0; i < vmdq_rx_conf->nb_pool_maps; i++) {
2179 vmdq_rx_conf->pool_map[i].vlan_id = vlan_tags[i];
2180 vmdq_rx_conf->pool_map[i].pools =
2181 1 << (i % vmdq_rx_conf->nb_queue_pools);
2183 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2184 vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
2185 vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
2188 /* set DCB mode of RX and TX of multiple queues */
2189 eth_conf->rxmode.mq_mode = ETH_MQ_RX_VMDQ_DCB;
2190 eth_conf->txmode.mq_mode = ETH_MQ_TX_VMDQ_DCB;
2192 struct rte_eth_dcb_rx_conf *rx_conf =
2193 ð_conf->rx_adv_conf.dcb_rx_conf;
2194 struct rte_eth_dcb_tx_conf *tx_conf =
2195 ð_conf->tx_adv_conf.dcb_tx_conf;
2197 rx_conf->nb_tcs = num_tcs;
2198 tx_conf->nb_tcs = num_tcs;
2200 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2201 rx_conf->dcb_tc[i] = i % num_tcs;
2202 tx_conf->dcb_tc[i] = i % num_tcs;
2204 eth_conf->rxmode.mq_mode = ETH_MQ_RX_DCB_RSS;
2205 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf;
2206 eth_conf->txmode.mq_mode = ETH_MQ_TX_DCB;
2210 eth_conf->dcb_capability_en =
2211 ETH_DCB_PG_SUPPORT | ETH_DCB_PFC_SUPPORT;
2213 eth_conf->dcb_capability_en = ETH_DCB_PG_SUPPORT;
2219 init_port_dcb_config(portid_t pid,
2220 enum dcb_mode_enable dcb_mode,
2221 enum rte_eth_nb_tcs num_tcs,
2224 struct rte_eth_conf port_conf;
2225 struct rte_port *rte_port;
2229 rte_port = &ports[pid];
2231 memset(&port_conf, 0, sizeof(struct rte_eth_conf));
2232 /* Enter DCB configuration status */
2235 /*set configuration of DCB in vt mode and DCB in non-vt mode*/
2236 retval = get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en);
2239 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2242 * Write the configuration into the device.
2243 * Set the numbers of RX & TX queues to 0, so
2244 * the RX & TX queues will not be setup.
2246 rte_eth_dev_configure(pid, 0, 0, &port_conf);
2248 rte_eth_dev_info_get(pid, &rte_port->dev_info);
2250 /* If dev_info.vmdq_pool_base is greater than 0,
2251 * the queue id of vmdq pools is started after pf queues.
2253 if (dcb_mode == DCB_VT_ENABLED &&
2254 rte_port->dev_info.vmdq_pool_base > 0) {
2255 printf("VMDQ_DCB multi-queue mode is nonsensical"
2256 " for port %d.", pid);
2260 /* Assume the ports in testpmd have the same dcb capability
2261 * and has the same number of rxq and txq in dcb mode
2263 if (dcb_mode == DCB_VT_ENABLED) {
2264 if (rte_port->dev_info.max_vfs > 0) {
2265 nb_rxq = rte_port->dev_info.nb_rx_queues;
2266 nb_txq = rte_port->dev_info.nb_tx_queues;
2268 nb_rxq = rte_port->dev_info.max_rx_queues;
2269 nb_txq = rte_port->dev_info.max_tx_queues;
2272 /*if vt is disabled, use all pf queues */
2273 if (rte_port->dev_info.vmdq_pool_base == 0) {
2274 nb_rxq = rte_port->dev_info.max_rx_queues;
2275 nb_txq = rte_port->dev_info.max_tx_queues;
2277 nb_rxq = (queueid_t)num_tcs;
2278 nb_txq = (queueid_t)num_tcs;
2282 rx_free_thresh = 64;
2284 memcpy(&rte_port->dev_conf, &port_conf, sizeof(struct rte_eth_conf));
2286 rxtx_port_config(rte_port);
2288 rte_port->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2289 for (i = 0; i < RTE_DIM(vlan_tags); i++)
2290 rx_vft_set(pid, vlan_tags[i], 1);
2292 rte_eth_macaddr_get(pid, &rte_port->eth_addr);
2293 map_port_queue_stats_mapping_registers(pid, rte_port);
2295 rte_port->dcb_flag = 1;
2303 /* Configuration of Ethernet ports. */
2304 ports = rte_zmalloc("testpmd: ports",
2305 sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
2306 RTE_CACHE_LINE_SIZE);
2307 if (ports == NULL) {
2308 rte_exit(EXIT_FAILURE,
2309 "rte_zmalloc(%d struct rte_port) failed\n",
2325 const char clr[] = { 27, '[', '2', 'J', '\0' };
2326 const char top_left[] = { 27, '[', '1', ';', '1', 'H', '\0' };
2328 /* Clear screen and move to top left */
2329 printf("%s%s", clr, top_left);
2331 printf("\nPort statistics ====================================");
2332 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
2333 nic_stats_display(fwd_ports_ids[i]);
2337 signal_handler(int signum)
2339 if (signum == SIGINT || signum == SIGTERM) {
2340 printf("\nSignal %d received, preparing to exit...\n",
2342 #ifdef RTE_LIBRTE_PDUMP
2343 /* uninitialize packet capture framework */
2346 #ifdef RTE_LIBRTE_LATENCY_STATS
2347 rte_latencystats_uninit();
2350 /* Set flag to indicate the force termination. */
2352 /* exit with the expected status */
2353 signal(signum, SIG_DFL);
2354 kill(getpid(), signum);
2359 main(int argc, char** argv)
2364 signal(SIGINT, signal_handler);
2365 signal(SIGTERM, signal_handler);
2367 diag = rte_eal_init(argc, argv);
2369 rte_panic("Cannot init EAL\n");
2371 testpmd_logtype = rte_log_register("testpmd");
2372 if (testpmd_logtype < 0)
2373 rte_panic("Cannot register log type");
2374 rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
2376 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
2377 TESTPMD_LOG(NOTICE, "mlockall() failed with error \"%s\"\n",
2381 #ifdef RTE_LIBRTE_PDUMP
2382 /* initialize packet capture framework */
2383 rte_pdump_init(NULL);
2386 nb_ports = (portid_t) rte_eth_dev_count();
2388 TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
2390 /* allocate port structures, and init them */
2393 set_def_fwd_config();
2395 rte_panic("Empty set of forwarding logical cores - check the "
2396 "core mask supplied in the command parameters\n");
2398 /* Bitrate/latency stats disabled by default */
2399 #ifdef RTE_LIBRTE_BITRATE
2400 bitrate_enabled = 0;
2402 #ifdef RTE_LIBRTE_LATENCY_STATS
2403 latencystats_enabled = 0;
2409 launch_args_parse(argc, argv);
2411 if (tx_first && interactive)
2412 rte_exit(EXIT_FAILURE, "--tx-first cannot be used on "
2413 "interactive mode.\n");
2415 if (tx_first && lsc_interrupt) {
2416 printf("Warning: lsc_interrupt needs to be off when "
2417 " using tx_first. Disabling.\n");
2421 if (!nb_rxq && !nb_txq)
2422 printf("Warning: Either rx or tx queues should be non-zero\n");
2424 if (nb_rxq > 1 && nb_rxq > nb_txq)
2425 printf("Warning: nb_rxq=%d enables RSS configuration, "
2426 "but nb_txq=%d will prevent to fully test it.\n",
2430 if (start_port(RTE_PORT_ALL) != 0)
2431 rte_exit(EXIT_FAILURE, "Start ports failed\n");
2433 /* set all ports to promiscuous mode by default */
2434 RTE_ETH_FOREACH_DEV(port_id)
2435 rte_eth_promiscuous_enable(port_id);
2437 /* Init metrics library */
2438 rte_metrics_init(rte_socket_id());
2440 #ifdef RTE_LIBRTE_LATENCY_STATS
2441 if (latencystats_enabled != 0) {
2442 int ret = rte_latencystats_init(1, NULL);
2444 printf("Warning: latencystats init()"
2445 " returned error %d\n", ret);
2446 printf("Latencystats running on lcore %d\n",
2447 latencystats_lcore_id);
2451 /* Setup bitrate stats */
2452 #ifdef RTE_LIBRTE_BITRATE
2453 if (bitrate_enabled != 0) {
2454 bitrate_data = rte_stats_bitrate_create();
2455 if (bitrate_data == NULL)
2456 rte_exit(EXIT_FAILURE,
2457 "Could not allocate bitrate data.\n");
2458 rte_stats_bitrate_reg(bitrate_data);
2462 #ifdef RTE_LIBRTE_CMDLINE
2463 if (strlen(cmdline_filename) != 0)
2464 cmdline_read_from_file(cmdline_filename);
2466 if (interactive == 1) {
2468 printf("Start automatic packet forwarding\n");
2469 start_packet_forwarding(0);
2481 printf("No commandline core given, start packet forwarding\n");
2482 start_packet_forwarding(tx_first);
2483 if (stats_period != 0) {
2484 uint64_t prev_time = 0, cur_time, diff_time = 0;
2485 uint64_t timer_period;
2487 /* Convert to number of cycles */
2488 timer_period = stats_period * rte_get_timer_hz();
2490 while (f_quit == 0) {
2491 cur_time = rte_get_timer_cycles();
2492 diff_time += cur_time - prev_time;
2494 if (diff_time >= timer_period) {
2496 /* Reset the timer */
2499 /* Sleep to avoid unnecessary checks */
2500 prev_time = cur_time;
2505 printf("Press enter to exit\n");
2506 rc = read(0, &c, 1);