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. */
66 /* use master core for command line ? */
67 uint8_t interactive = 0;
68 uint8_t auto_start = 0;
70 char cmdline_filename[PATH_MAX] = {0};
73 * NUMA support configuration.
74 * When set, the NUMA support attempts to dispatch the allocation of the
75 * RX and TX memory rings, and of the DMA memory buffers (mbufs) for the
76 * probed ports among the CPU sockets 0 and 1.
77 * Otherwise, all memory is allocated from CPU socket 0.
79 uint8_t numa_support = 1; /**< numa enabled by default */
82 * In UMA mode,all memory is allocated from socket 0 if --socket-num is
85 uint8_t socket_num = UMA_NO_CONFIG;
88 * Use ANONYMOUS mapped memory (might be not physically continuous) for mbufs.
93 * Record the Ethernet address of peer target ports to which packets are
95 * Must be instantiated with the ethernet addresses of peer traffic generator
98 struct ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
99 portid_t nb_peer_eth_addrs = 0;
102 * Probed Target Environment.
104 struct rte_port *ports; /**< For all probed ethernet ports. */
105 portid_t nb_ports; /**< Number of probed ethernet ports. */
106 struct fwd_lcore **fwd_lcores; /**< For all probed logical cores. */
107 lcoreid_t nb_lcores; /**< Number of probed logical cores. */
110 * Test Forwarding Configuration.
111 * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
112 * nb_fwd_ports <= nb_cfg_ports <= nb_ports
114 lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
115 lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
116 portid_t nb_cfg_ports; /**< Number of configured ports. */
117 portid_t nb_fwd_ports; /**< Number of forwarding ports. */
119 unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE]; /**< CPU ids configuration. */
120 portid_t fwd_ports_ids[RTE_MAX_ETHPORTS]; /**< Port ids configuration. */
122 struct fwd_stream **fwd_streams; /**< For each RX queue of each port. */
123 streamid_t nb_fwd_streams; /**< Is equal to (nb_ports * nb_rxq). */
126 * Forwarding engines.
128 struct fwd_engine * fwd_engines[] = {
137 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
139 &softnic_tm_bypass_engine,
141 #ifdef RTE_LIBRTE_IEEE1588
142 &ieee1588_fwd_engine,
147 struct fwd_config cur_fwd_config;
148 struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */
149 uint32_t retry_enabled;
150 uint32_t burst_tx_delay_time = BURST_TX_WAIT_US;
151 uint32_t burst_tx_retry_num = BURST_TX_RETRIES;
153 uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
154 uint32_t param_total_num_mbufs = 0; /**< number of mbufs in all pools - if
155 * specified on command-line. */
156 uint16_t stats_period; /**< Period to show statistics (disabled by default) */
159 * In container, it cannot terminate the process which running with 'stats-period'
160 * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
165 * Configuration of packet segments used by the "txonly" processing engine.
167 uint16_t tx_pkt_length = TXONLY_DEF_PACKET_LEN; /**< TXONLY packet length. */
168 uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT] = {
169 TXONLY_DEF_PACKET_LEN,
171 uint8_t tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */
173 enum tx_pkt_split tx_pkt_split = TX_PKT_SPLIT_OFF;
174 /**< Split policy for packets to TX. */
176 uint16_t nb_pkt_per_burst = DEF_PKT_BURST; /**< Number of packets per burst. */
177 uint16_t mb_mempool_cache = DEF_MBUF_CACHE; /**< Size of mbuf mempool cache. */
179 /* current configuration is in DCB or not,0 means it is not in DCB mode */
180 uint8_t dcb_config = 0;
182 /* Whether the dcb is in testing status */
183 uint8_t dcb_test = 0;
186 * Configurable number of RX/TX queues.
188 queueid_t nb_rxq = 1; /**< Number of RX queues per port. */
189 queueid_t nb_txq = 1; /**< Number of TX queues per port. */
192 * Configurable number of RX/TX ring descriptors.
194 #define RTE_TEST_RX_DESC_DEFAULT 128
195 #define RTE_TEST_TX_DESC_DEFAULT 512
196 uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; /**< Number of RX descriptors. */
197 uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; /**< Number of TX descriptors. */
199 #define RTE_PMD_PARAM_UNSET -1
201 * Configurable values of RX and TX ring threshold registers.
204 int8_t rx_pthresh = RTE_PMD_PARAM_UNSET;
205 int8_t rx_hthresh = RTE_PMD_PARAM_UNSET;
206 int8_t rx_wthresh = RTE_PMD_PARAM_UNSET;
208 int8_t tx_pthresh = RTE_PMD_PARAM_UNSET;
209 int8_t tx_hthresh = RTE_PMD_PARAM_UNSET;
210 int8_t tx_wthresh = RTE_PMD_PARAM_UNSET;
213 * Configurable value of RX free threshold.
215 int16_t rx_free_thresh = RTE_PMD_PARAM_UNSET;
218 * Configurable value of RX drop enable.
220 int8_t rx_drop_en = RTE_PMD_PARAM_UNSET;
223 * Configurable value of TX free threshold.
225 int16_t tx_free_thresh = RTE_PMD_PARAM_UNSET;
228 * Configurable value of TX RS bit threshold.
230 int16_t tx_rs_thresh = RTE_PMD_PARAM_UNSET;
233 * Configurable value of TX queue flags.
235 int32_t txq_flags = RTE_PMD_PARAM_UNSET;
238 * Receive Side Scaling (RSS) configuration.
240 uint64_t rss_hf = ETH_RSS_IP; /* RSS IP by default. */
243 * Port topology configuration
245 uint16_t port_topology = PORT_TOPOLOGY_PAIRED; /* Ports are paired by default */
248 * Avoids to flush all the RX streams before starts forwarding.
250 uint8_t no_flush_rx = 0; /* flush by default */
253 * Flow API isolated mode.
255 uint8_t flow_isolate_all;
258 * Avoids to check link status when starting/stopping a port.
260 uint8_t no_link_check = 0; /* check by default */
263 * Enable link status change notification
265 uint8_t lsc_interrupt = 1; /* enabled by default */
268 * Enable device removal notification.
270 uint8_t rmv_interrupt = 1; /* enabled by default */
273 * Display or mask ether events
274 * Default to all events except VF_MBOX
276 uint32_t event_print_mask = (UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN) |
277 (UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC) |
278 (UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE) |
279 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET) |
280 (UINT32_C(1) << RTE_ETH_EVENT_MACSEC) |
281 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV);
284 * NIC bypass mode configuration options.
287 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
288 /* The NIC bypass watchdog timeout. */
289 uint32_t bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
293 #ifdef RTE_LIBRTE_LATENCY_STATS
296 * Set when latency stats is enabled in the commandline
298 uint8_t latencystats_enabled;
301 * Lcore ID to serive latency statistics.
303 lcoreid_t latencystats_lcore_id = -1;
308 * Ethernet device configuration.
310 struct rte_eth_rxmode rx_mode = {
311 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
313 .header_split = 0, /**< Header Split disabled. */
314 .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
315 .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
316 .hw_vlan_strip = 1, /**< VLAN strip enabled. */
317 .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
318 .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */
319 .hw_strip_crc = 1, /**< CRC stripping by hardware enabled. */
320 .hw_timestamp = 0, /**< HW timestamp enabled. */
323 struct rte_fdir_conf fdir_conf = {
324 .mode = RTE_FDIR_MODE_NONE,
325 .pballoc = RTE_FDIR_PBALLOC_64K,
326 .status = RTE_FDIR_REPORT_STATUS,
328 .vlan_tci_mask = 0x0,
330 .src_ip = 0xFFFFFFFF,
331 .dst_ip = 0xFFFFFFFF,
334 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
335 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
337 .src_port_mask = 0xFFFF,
338 .dst_port_mask = 0xFFFF,
339 .mac_addr_byte_mask = 0xFF,
340 .tunnel_type_mask = 1,
341 .tunnel_id_mask = 0xFFFFFFFF,
346 volatile int test_done = 1; /* stop packet forwarding when set to 1. */
348 struct queue_stats_mappings tx_queue_stats_mappings_array[MAX_TX_QUEUE_STATS_MAPPINGS];
349 struct queue_stats_mappings rx_queue_stats_mappings_array[MAX_RX_QUEUE_STATS_MAPPINGS];
351 struct queue_stats_mappings *tx_queue_stats_mappings = tx_queue_stats_mappings_array;
352 struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_array;
354 uint16_t nb_tx_queue_stats_mappings = 0;
355 uint16_t nb_rx_queue_stats_mappings = 0;
358 * Display zero values by default for xstats
360 uint8_t xstats_hide_zero;
362 unsigned int num_sockets = 0;
363 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
365 #ifdef RTE_LIBRTE_BITRATE
366 /* Bitrate statistics */
367 struct rte_stats_bitrates *bitrate_data;
368 lcoreid_t bitrate_lcore_id;
369 uint8_t bitrate_enabled;
372 struct gro_status gro_ports[RTE_MAX_ETHPORTS];
373 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
375 /* Forward function declarations */
376 static void map_port_queue_stats_mapping_registers(portid_t pi,
377 struct rte_port *port);
378 static void check_all_ports_link_status(uint32_t port_mask);
379 static int eth_event_callback(portid_t port_id,
380 enum rte_eth_event_type type,
381 void *param, void *ret_param);
384 * Check if all the ports are started.
385 * If yes, return positive value. If not, return zero.
387 static int all_ports_started(void);
389 struct gso_status gso_ports[RTE_MAX_ETHPORTS];
390 uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
393 * Helper function to check if socket is already discovered.
394 * If yes, return positive value. If not, return zero.
397 new_socket_id(unsigned int socket_id)
401 for (i = 0; i < num_sockets; i++) {
402 if (socket_ids[i] == socket_id)
409 * Setup default configuration.
412 set_default_fwd_lcores_config(void)
416 unsigned int sock_num;
419 for (i = 0; i < RTE_MAX_LCORE; i++) {
420 sock_num = rte_lcore_to_socket_id(i);
421 if (new_socket_id(sock_num)) {
422 if (num_sockets >= RTE_MAX_NUMA_NODES) {
423 rte_exit(EXIT_FAILURE,
424 "Total sockets greater than %u\n",
427 socket_ids[num_sockets++] = sock_num;
429 if (!rte_lcore_is_enabled(i))
431 if (i == rte_get_master_lcore())
433 fwd_lcores_cpuids[nb_lc++] = i;
435 nb_lcores = (lcoreid_t) nb_lc;
436 nb_cfg_lcores = nb_lcores;
441 set_def_peer_eth_addrs(void)
445 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
446 peer_eth_addrs[i].addr_bytes[0] = ETHER_LOCAL_ADMIN_ADDR;
447 peer_eth_addrs[i].addr_bytes[5] = i;
452 set_default_fwd_ports_config(void)
457 RTE_ETH_FOREACH_DEV(pt_id)
458 fwd_ports_ids[i++] = pt_id;
460 nb_cfg_ports = nb_ports;
461 nb_fwd_ports = nb_ports;
465 set_def_fwd_config(void)
467 set_default_fwd_lcores_config();
468 set_def_peer_eth_addrs();
469 set_default_fwd_ports_config();
473 * Configuration initialisation done once at init time.
476 mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
477 unsigned int socket_id)
479 char pool_name[RTE_MEMPOOL_NAMESIZE];
480 struct rte_mempool *rte_mp = NULL;
483 mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
484 mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
487 "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
488 pool_name, nb_mbuf, mbuf_seg_size, socket_id);
491 rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf,
492 mb_size, (unsigned) mb_mempool_cache,
493 sizeof(struct rte_pktmbuf_pool_private),
498 if (rte_mempool_populate_anon(rte_mp) == 0) {
499 rte_mempool_free(rte_mp);
503 rte_pktmbuf_pool_init(rte_mp, NULL);
504 rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
506 /* wrapper to rte_mempool_create() */
507 rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
508 mb_mempool_cache, 0, mbuf_seg_size, socket_id);
512 if (rte_mp == NULL) {
513 rte_exit(EXIT_FAILURE,
514 "Creation of mbuf pool for socket %u failed: %s\n",
515 socket_id, rte_strerror(rte_errno));
516 } else if (verbose_level > 0) {
517 rte_mempool_dump(stdout, rte_mp);
522 * Check given socket id is valid or not with NUMA mode,
523 * if valid, return 0, else return -1
526 check_socket_id(const unsigned int socket_id)
528 static int warning_once = 0;
530 if (new_socket_id(socket_id)) {
531 if (!warning_once && numa_support)
532 printf("Warning: NUMA should be configured manually by"
533 " using --port-numa-config and"
534 " --ring-numa-config parameters along with"
546 struct rte_port *port;
547 struct rte_mempool *mbp;
548 unsigned int nb_mbuf_per_pool;
550 uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
551 struct rte_gro_param gro_param;
554 memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
557 memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
558 memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
559 memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
562 /* Configuration of logical cores. */
563 fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
564 sizeof(struct fwd_lcore *) * nb_lcores,
565 RTE_CACHE_LINE_SIZE);
566 if (fwd_lcores == NULL) {
567 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_lcore *)) "
568 "failed\n", nb_lcores);
570 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
571 fwd_lcores[lc_id] = rte_zmalloc("testpmd: struct fwd_lcore",
572 sizeof(struct fwd_lcore),
573 RTE_CACHE_LINE_SIZE);
574 if (fwd_lcores[lc_id] == NULL) {
575 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_lcore) "
578 fwd_lcores[lc_id]->cpuid_idx = lc_id;
581 RTE_ETH_FOREACH_DEV(pid) {
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 all_ports_stopped(void)
1376 struct rte_port *port;
1378 RTE_ETH_FOREACH_DEV(pi) {
1380 if ((port->port_status != RTE_PORT_STOPPED) &&
1381 (port->slave_flag == 0))
1389 port_is_started(portid_t port_id)
1391 if (port_id_is_invalid(port_id, ENABLED_WARN))
1394 if (ports[port_id].port_status != RTE_PORT_STARTED)
1401 port_is_closed(portid_t port_id)
1403 if (port_id_is_invalid(port_id, ENABLED_WARN))
1406 if (ports[port_id].port_status != RTE_PORT_CLOSED)
1413 start_port(portid_t pid)
1415 int diag, need_check_link_status = -1;
1418 struct rte_port *port;
1419 struct ether_addr mac_addr;
1420 enum rte_eth_event_type event_type;
1422 if (port_id_is_invalid(pid, ENABLED_WARN))
1427 RTE_ETH_FOREACH_DEV(pi) {
1428 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1431 need_check_link_status = 0;
1433 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STOPPED,
1434 RTE_PORT_HANDLING) == 0) {
1435 printf("Port %d is now not stopped\n", pi);
1439 if (port->need_reconfig > 0) {
1440 port->need_reconfig = 0;
1442 if (flow_isolate_all) {
1443 int ret = port_flow_isolate(pi, 1);
1445 printf("Failed to apply isolated"
1446 " mode on port %d\n", pi);
1451 printf("Configuring Port %d (socket %u)\n", pi,
1453 /* configure port */
1454 diag = rte_eth_dev_configure(pi, nb_rxq, nb_txq,
1457 if (rte_atomic16_cmpset(&(port->port_status),
1458 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1459 printf("Port %d can not be set back "
1460 "to stopped\n", pi);
1461 printf("Fail to configure port %d\n", pi);
1462 /* try to reconfigure port next time */
1463 port->need_reconfig = 1;
1467 if (port->need_reconfig_queues > 0) {
1468 port->need_reconfig_queues = 0;
1469 /* setup tx queues */
1470 for (qi = 0; qi < nb_txq; qi++) {
1471 if ((numa_support) &&
1472 (txring_numa[pi] != NUMA_NO_CONFIG))
1473 diag = rte_eth_tx_queue_setup(pi, qi,
1474 nb_txd,txring_numa[pi],
1477 diag = rte_eth_tx_queue_setup(pi, qi,
1478 nb_txd,port->socket_id,
1484 /* Fail to setup tx queue, return */
1485 if (rte_atomic16_cmpset(&(port->port_status),
1487 RTE_PORT_STOPPED) == 0)
1488 printf("Port %d can not be set back "
1489 "to stopped\n", pi);
1490 printf("Fail to configure port %d tx queues\n", pi);
1491 /* try to reconfigure queues next time */
1492 port->need_reconfig_queues = 1;
1495 /* setup rx queues */
1496 for (qi = 0; qi < nb_rxq; qi++) {
1497 if ((numa_support) &&
1498 (rxring_numa[pi] != NUMA_NO_CONFIG)) {
1499 struct rte_mempool * mp =
1500 mbuf_pool_find(rxring_numa[pi]);
1502 printf("Failed to setup RX queue:"
1503 "No mempool allocation"
1504 " on the socket %d\n",
1509 diag = rte_eth_rx_queue_setup(pi, qi,
1510 nb_rxd,rxring_numa[pi],
1511 &(port->rx_conf),mp);
1513 struct rte_mempool *mp =
1514 mbuf_pool_find(port->socket_id);
1516 printf("Failed to setup RX queue:"
1517 "No mempool allocation"
1518 " on the socket %d\n",
1522 diag = rte_eth_rx_queue_setup(pi, qi,
1523 nb_rxd,port->socket_id,
1524 &(port->rx_conf), mp);
1529 /* Fail to setup rx queue, return */
1530 if (rte_atomic16_cmpset(&(port->port_status),
1532 RTE_PORT_STOPPED) == 0)
1533 printf("Port %d can not be set back "
1534 "to stopped\n", pi);
1535 printf("Fail to configure port %d rx queues\n", pi);
1536 /* try to reconfigure queues next time */
1537 port->need_reconfig_queues = 1;
1542 for (event_type = RTE_ETH_EVENT_UNKNOWN;
1543 event_type < RTE_ETH_EVENT_MAX;
1545 diag = rte_eth_dev_callback_register(pi,
1550 printf("Failed to setup even callback for event %d\n",
1557 if (rte_eth_dev_start(pi) < 0) {
1558 printf("Fail to start port %d\n", pi);
1560 /* Fail to setup rx queue, return */
1561 if (rte_atomic16_cmpset(&(port->port_status),
1562 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1563 printf("Port %d can not be set back to "
1568 if (rte_atomic16_cmpset(&(port->port_status),
1569 RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0)
1570 printf("Port %d can not be set into started\n", pi);
1572 rte_eth_macaddr_get(pi, &mac_addr);
1573 printf("Port %d: %02X:%02X:%02X:%02X:%02X:%02X\n", pi,
1574 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
1575 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
1576 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5]);
1578 /* at least one port started, need checking link status */
1579 need_check_link_status = 1;
1582 if (need_check_link_status == 1 && !no_link_check)
1583 check_all_ports_link_status(RTE_PORT_ALL);
1584 else if (need_check_link_status == 0)
1585 printf("Please stop the ports first\n");
1592 stop_port(portid_t pid)
1595 struct rte_port *port;
1596 int need_check_link_status = 0;
1603 if (port_id_is_invalid(pid, ENABLED_WARN))
1606 printf("Stopping ports...\n");
1608 RTE_ETH_FOREACH_DEV(pi) {
1609 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1612 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1613 printf("Please remove port %d from forwarding configuration.\n", pi);
1617 if (port_is_bonding_slave(pi)) {
1618 printf("Please remove port %d from bonded device.\n", pi);
1623 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STARTED,
1624 RTE_PORT_HANDLING) == 0)
1627 rte_eth_dev_stop(pi);
1629 if (rte_atomic16_cmpset(&(port->port_status),
1630 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1631 printf("Port %d can not be set into stopped\n", pi);
1632 need_check_link_status = 1;
1634 if (need_check_link_status && !no_link_check)
1635 check_all_ports_link_status(RTE_PORT_ALL);
1641 close_port(portid_t pid)
1644 struct rte_port *port;
1646 if (port_id_is_invalid(pid, ENABLED_WARN))
1649 printf("Closing ports...\n");
1651 RTE_ETH_FOREACH_DEV(pi) {
1652 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1655 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1656 printf("Please remove port %d from forwarding configuration.\n", pi);
1660 if (port_is_bonding_slave(pi)) {
1661 printf("Please remove port %d from bonded device.\n", pi);
1666 if (rte_atomic16_cmpset(&(port->port_status),
1667 RTE_PORT_CLOSED, RTE_PORT_CLOSED) == 1) {
1668 printf("Port %d is already closed\n", pi);
1672 if (rte_atomic16_cmpset(&(port->port_status),
1673 RTE_PORT_STOPPED, RTE_PORT_HANDLING) == 0) {
1674 printf("Port %d is now not stopped\n", pi);
1678 if (port->flow_list)
1679 port_flow_flush(pi);
1680 rte_eth_dev_close(pi);
1682 if (rte_atomic16_cmpset(&(port->port_status),
1683 RTE_PORT_HANDLING, RTE_PORT_CLOSED) == 0)
1684 printf("Port %d cannot be set to closed\n", pi);
1691 reset_port(portid_t pid)
1695 struct rte_port *port;
1697 if (port_id_is_invalid(pid, ENABLED_WARN))
1700 printf("Resetting ports...\n");
1702 RTE_ETH_FOREACH_DEV(pi) {
1703 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1706 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1707 printf("Please remove port %d from forwarding "
1708 "configuration.\n", pi);
1712 if (port_is_bonding_slave(pi)) {
1713 printf("Please remove port %d from bonded device.\n",
1718 diag = rte_eth_dev_reset(pi);
1721 port->need_reconfig = 1;
1722 port->need_reconfig_queues = 1;
1724 printf("Failed to reset port %d. diag=%d\n", pi, diag);
1732 attach_port(char *identifier)
1735 unsigned int socket_id;
1737 printf("Attaching a new port...\n");
1739 if (identifier == NULL) {
1740 printf("Invalid parameters are specified\n");
1744 if (rte_eth_dev_attach(identifier, &pi))
1747 socket_id = (unsigned)rte_eth_dev_socket_id(pi);
1748 /* if socket_id is invalid, set to 0 */
1749 if (check_socket_id(socket_id) < 0)
1751 reconfig(pi, socket_id);
1752 rte_eth_promiscuous_enable(pi);
1754 nb_ports = rte_eth_dev_count();
1756 ports[pi].port_status = RTE_PORT_STOPPED;
1758 printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
1763 detach_port(portid_t port_id)
1765 char name[RTE_ETH_NAME_MAX_LEN];
1767 printf("Detaching a port...\n");
1769 if (!port_is_closed(port_id)) {
1770 printf("Please close port first\n");
1774 if (ports[port_id].flow_list)
1775 port_flow_flush(port_id);
1777 if (rte_eth_dev_detach(port_id, name)) {
1778 RTE_LOG(ERR, USER1, "Failed to detach port '%s'\n", name);
1782 nb_ports = rte_eth_dev_count();
1784 printf("Port '%s' is detached. Now total ports is %d\n",
1796 stop_packet_forwarding();
1798 if (ports != NULL) {
1800 RTE_ETH_FOREACH_DEV(pt_id) {
1801 printf("\nShutting down port %d...\n", pt_id);
1807 printf("\nBye...\n");
1810 typedef void (*cmd_func_t)(void);
1811 struct pmd_test_command {
1812 const char *cmd_name;
1813 cmd_func_t cmd_func;
1816 #define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
1818 /* Check the link status of all ports in up to 9s, and print them finally */
1820 check_all_ports_link_status(uint32_t port_mask)
1822 #define CHECK_INTERVAL 100 /* 100ms */
1823 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1825 uint8_t count, all_ports_up, print_flag = 0;
1826 struct rte_eth_link link;
1828 printf("Checking link statuses...\n");
1830 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1832 RTE_ETH_FOREACH_DEV(portid) {
1833 if ((port_mask & (1 << portid)) == 0)
1835 memset(&link, 0, sizeof(link));
1836 rte_eth_link_get_nowait(portid, &link);
1837 /* print link status if flag set */
1838 if (print_flag == 1) {
1839 if (link.link_status)
1841 "Port%d Link Up. speed %u Mbps- %s\n",
1842 portid, link.link_speed,
1843 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1844 ("full-duplex") : ("half-duplex\n"));
1846 printf("Port %d Link Down\n", portid);
1849 /* clear all_ports_up flag if any link down */
1850 if (link.link_status == ETH_LINK_DOWN) {
1855 /* after finally printing all link status, get out */
1856 if (print_flag == 1)
1859 if (all_ports_up == 0) {
1861 rte_delay_ms(CHECK_INTERVAL);
1864 /* set the print_flag if all ports up or timeout */
1865 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
1875 rmv_event_callback(void *arg)
1877 struct rte_eth_dev *dev;
1878 portid_t port_id = (intptr_t)arg;
1880 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1881 dev = &rte_eth_devices[port_id];
1884 close_port(port_id);
1885 printf("removing device %s\n", dev->device->name);
1886 if (rte_eal_dev_detach(dev->device))
1887 RTE_LOG(ERR, USER1, "Failed to detach device %s\n",
1891 /* This function is used by the interrupt thread */
1893 eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
1896 static const char * const event_desc[] = {
1897 [RTE_ETH_EVENT_UNKNOWN] = "Unknown",
1898 [RTE_ETH_EVENT_INTR_LSC] = "LSC",
1899 [RTE_ETH_EVENT_QUEUE_STATE] = "Queue state",
1900 [RTE_ETH_EVENT_INTR_RESET] = "Interrupt reset",
1901 [RTE_ETH_EVENT_VF_MBOX] = "VF Mbox",
1902 [RTE_ETH_EVENT_MACSEC] = "MACsec",
1903 [RTE_ETH_EVENT_INTR_RMV] = "device removal",
1904 [RTE_ETH_EVENT_MAX] = NULL,
1907 RTE_SET_USED(param);
1908 RTE_SET_USED(ret_param);
1910 if (type >= RTE_ETH_EVENT_MAX) {
1911 fprintf(stderr, "\nPort %" PRIu8 ": %s called upon invalid event %d\n",
1912 port_id, __func__, type);
1914 } else if (event_print_mask & (UINT32_C(1) << type)) {
1915 printf("\nPort %" PRIu8 ": %s event\n", port_id,
1921 case RTE_ETH_EVENT_INTR_RMV:
1922 if (rte_eal_alarm_set(100000,
1923 rmv_event_callback, (void *)(intptr_t)port_id))
1924 fprintf(stderr, "Could not set up deferred device removal\n");
1933 set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
1937 uint8_t mapping_found = 0;
1939 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1940 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1941 (tx_queue_stats_mappings[i].queue_id < nb_txq )) {
1942 diag = rte_eth_dev_set_tx_queue_stats_mapping(port_id,
1943 tx_queue_stats_mappings[i].queue_id,
1944 tx_queue_stats_mappings[i].stats_counter_id);
1951 port->tx_queue_stats_mapping_enabled = 1;
1956 set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
1960 uint8_t mapping_found = 0;
1962 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1963 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1964 (rx_queue_stats_mappings[i].queue_id < nb_rxq )) {
1965 diag = rte_eth_dev_set_rx_queue_stats_mapping(port_id,
1966 rx_queue_stats_mappings[i].queue_id,
1967 rx_queue_stats_mappings[i].stats_counter_id);
1974 port->rx_queue_stats_mapping_enabled = 1;
1979 map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
1983 diag = set_tx_queue_stats_mapping_registers(pi, port);
1985 if (diag == -ENOTSUP) {
1986 port->tx_queue_stats_mapping_enabled = 0;
1987 printf("TX queue stats mapping not supported port id=%d\n", pi);
1990 rte_exit(EXIT_FAILURE,
1991 "set_tx_queue_stats_mapping_registers "
1992 "failed for port id=%d diag=%d\n",
1996 diag = set_rx_queue_stats_mapping_registers(pi, port);
1998 if (diag == -ENOTSUP) {
1999 port->rx_queue_stats_mapping_enabled = 0;
2000 printf("RX queue stats mapping not supported port id=%d\n", pi);
2003 rte_exit(EXIT_FAILURE,
2004 "set_rx_queue_stats_mapping_registers "
2005 "failed for port id=%d diag=%d\n",
2011 rxtx_port_config(struct rte_port *port)
2013 port->rx_conf = port->dev_info.default_rxconf;
2014 port->tx_conf = port->dev_info.default_txconf;
2016 /* Check if any RX/TX parameters have been passed */
2017 if (rx_pthresh != RTE_PMD_PARAM_UNSET)
2018 port->rx_conf.rx_thresh.pthresh = rx_pthresh;
2020 if (rx_hthresh != RTE_PMD_PARAM_UNSET)
2021 port->rx_conf.rx_thresh.hthresh = rx_hthresh;
2023 if (rx_wthresh != RTE_PMD_PARAM_UNSET)
2024 port->rx_conf.rx_thresh.wthresh = rx_wthresh;
2026 if (rx_free_thresh != RTE_PMD_PARAM_UNSET)
2027 port->rx_conf.rx_free_thresh = rx_free_thresh;
2029 if (rx_drop_en != RTE_PMD_PARAM_UNSET)
2030 port->rx_conf.rx_drop_en = rx_drop_en;
2032 if (tx_pthresh != RTE_PMD_PARAM_UNSET)
2033 port->tx_conf.tx_thresh.pthresh = tx_pthresh;
2035 if (tx_hthresh != RTE_PMD_PARAM_UNSET)
2036 port->tx_conf.tx_thresh.hthresh = tx_hthresh;
2038 if (tx_wthresh != RTE_PMD_PARAM_UNSET)
2039 port->tx_conf.tx_thresh.wthresh = tx_wthresh;
2041 if (tx_rs_thresh != RTE_PMD_PARAM_UNSET)
2042 port->tx_conf.tx_rs_thresh = tx_rs_thresh;
2044 if (tx_free_thresh != RTE_PMD_PARAM_UNSET)
2045 port->tx_conf.tx_free_thresh = tx_free_thresh;
2047 if (txq_flags != RTE_PMD_PARAM_UNSET)
2048 port->tx_conf.txq_flags = txq_flags;
2052 init_port_config(void)
2055 struct rte_port *port;
2057 RTE_ETH_FOREACH_DEV(pid) {
2059 port->dev_conf.rxmode = rx_mode;
2060 port->dev_conf.fdir_conf = fdir_conf;
2062 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2063 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = rss_hf;
2065 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2066 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = 0;
2069 if (port->dcb_flag == 0) {
2070 if( port->dev_conf.rx_adv_conf.rss_conf.rss_hf != 0)
2071 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
2073 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
2076 rxtx_port_config(port);
2078 rte_eth_macaddr_get(pid, &port->eth_addr);
2080 map_port_queue_stats_mapping_registers(pid, port);
2081 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
2082 rte_pmd_ixgbe_bypass_init(pid);
2085 if (lsc_interrupt &&
2086 (rte_eth_devices[pid].data->dev_flags &
2087 RTE_ETH_DEV_INTR_LSC))
2088 port->dev_conf.intr_conf.lsc = 1;
2089 if (rmv_interrupt &&
2090 (rte_eth_devices[pid].data->dev_flags &
2091 RTE_ETH_DEV_INTR_RMV))
2092 port->dev_conf.intr_conf.rmv = 1;
2094 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
2095 /* Detect softnic port */
2096 if (!strcmp(port->dev_info.driver_name, "net_softnic")) {
2097 port->softnic_enable = 1;
2098 memset(&port->softport, 0, sizeof(struct softnic_port));
2100 if (!strcmp(cur_fwd_eng->fwd_mode_name, "tm"))
2101 port->softport.tm_flag = 1;
2107 void set_port_slave_flag(portid_t slave_pid)
2109 struct rte_port *port;
2111 port = &ports[slave_pid];
2112 port->slave_flag = 1;
2115 void clear_port_slave_flag(portid_t slave_pid)
2117 struct rte_port *port;
2119 port = &ports[slave_pid];
2120 port->slave_flag = 0;
2123 uint8_t port_is_bonding_slave(portid_t slave_pid)
2125 struct rte_port *port;
2127 port = &ports[slave_pid];
2128 return port->slave_flag;
2131 const uint16_t vlan_tags[] = {
2132 0, 1, 2, 3, 4, 5, 6, 7,
2133 8, 9, 10, 11, 12, 13, 14, 15,
2134 16, 17, 18, 19, 20, 21, 22, 23,
2135 24, 25, 26, 27, 28, 29, 30, 31
2139 get_eth_dcb_conf(struct rte_eth_conf *eth_conf,
2140 enum dcb_mode_enable dcb_mode,
2141 enum rte_eth_nb_tcs num_tcs,
2147 * Builds up the correct configuration for dcb+vt based on the vlan tags array
2148 * given above, and the number of traffic classes available for use.
2150 if (dcb_mode == DCB_VT_ENABLED) {
2151 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
2152 ð_conf->rx_adv_conf.vmdq_dcb_conf;
2153 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
2154 ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
2156 /* VMDQ+DCB RX and TX configurations */
2157 vmdq_rx_conf->enable_default_pool = 0;
2158 vmdq_rx_conf->default_pool = 0;
2159 vmdq_rx_conf->nb_queue_pools =
2160 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2161 vmdq_tx_conf->nb_queue_pools =
2162 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2164 vmdq_rx_conf->nb_pool_maps = vmdq_rx_conf->nb_queue_pools;
2165 for (i = 0; i < vmdq_rx_conf->nb_pool_maps; i++) {
2166 vmdq_rx_conf->pool_map[i].vlan_id = vlan_tags[i];
2167 vmdq_rx_conf->pool_map[i].pools =
2168 1 << (i % vmdq_rx_conf->nb_queue_pools);
2170 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2171 vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
2172 vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
2175 /* set DCB mode of RX and TX of multiple queues */
2176 eth_conf->rxmode.mq_mode = ETH_MQ_RX_VMDQ_DCB;
2177 eth_conf->txmode.mq_mode = ETH_MQ_TX_VMDQ_DCB;
2179 struct rte_eth_dcb_rx_conf *rx_conf =
2180 ð_conf->rx_adv_conf.dcb_rx_conf;
2181 struct rte_eth_dcb_tx_conf *tx_conf =
2182 ð_conf->tx_adv_conf.dcb_tx_conf;
2184 rx_conf->nb_tcs = num_tcs;
2185 tx_conf->nb_tcs = num_tcs;
2187 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2188 rx_conf->dcb_tc[i] = i % num_tcs;
2189 tx_conf->dcb_tc[i] = i % num_tcs;
2191 eth_conf->rxmode.mq_mode = ETH_MQ_RX_DCB_RSS;
2192 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf;
2193 eth_conf->txmode.mq_mode = ETH_MQ_TX_DCB;
2197 eth_conf->dcb_capability_en =
2198 ETH_DCB_PG_SUPPORT | ETH_DCB_PFC_SUPPORT;
2200 eth_conf->dcb_capability_en = ETH_DCB_PG_SUPPORT;
2206 init_port_dcb_config(portid_t pid,
2207 enum dcb_mode_enable dcb_mode,
2208 enum rte_eth_nb_tcs num_tcs,
2211 struct rte_eth_conf port_conf;
2212 struct rte_port *rte_port;
2216 rte_port = &ports[pid];
2218 memset(&port_conf, 0, sizeof(struct rte_eth_conf));
2219 /* Enter DCB configuration status */
2222 /*set configuration of DCB in vt mode and DCB in non-vt mode*/
2223 retval = get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en);
2226 port_conf.rxmode.hw_vlan_filter = 1;
2229 * Write the configuration into the device.
2230 * Set the numbers of RX & TX queues to 0, so
2231 * the RX & TX queues will not be setup.
2233 rte_eth_dev_configure(pid, 0, 0, &port_conf);
2235 rte_eth_dev_info_get(pid, &rte_port->dev_info);
2237 /* If dev_info.vmdq_pool_base is greater than 0,
2238 * the queue id of vmdq pools is started after pf queues.
2240 if (dcb_mode == DCB_VT_ENABLED &&
2241 rte_port->dev_info.vmdq_pool_base > 0) {
2242 printf("VMDQ_DCB multi-queue mode is nonsensical"
2243 " for port %d.", pid);
2247 /* Assume the ports in testpmd have the same dcb capability
2248 * and has the same number of rxq and txq in dcb mode
2250 if (dcb_mode == DCB_VT_ENABLED) {
2251 if (rte_port->dev_info.max_vfs > 0) {
2252 nb_rxq = rte_port->dev_info.nb_rx_queues;
2253 nb_txq = rte_port->dev_info.nb_tx_queues;
2255 nb_rxq = rte_port->dev_info.max_rx_queues;
2256 nb_txq = rte_port->dev_info.max_tx_queues;
2259 /*if vt is disabled, use all pf queues */
2260 if (rte_port->dev_info.vmdq_pool_base == 0) {
2261 nb_rxq = rte_port->dev_info.max_rx_queues;
2262 nb_txq = rte_port->dev_info.max_tx_queues;
2264 nb_rxq = (queueid_t)num_tcs;
2265 nb_txq = (queueid_t)num_tcs;
2269 rx_free_thresh = 64;
2271 memcpy(&rte_port->dev_conf, &port_conf, sizeof(struct rte_eth_conf));
2273 rxtx_port_config(rte_port);
2275 rte_port->dev_conf.rxmode.hw_vlan_filter = 1;
2276 for (i = 0; i < RTE_DIM(vlan_tags); i++)
2277 rx_vft_set(pid, vlan_tags[i], 1);
2279 rte_eth_macaddr_get(pid, &rte_port->eth_addr);
2280 map_port_queue_stats_mapping_registers(pid, rte_port);
2282 rte_port->dcb_flag = 1;
2290 /* Configuration of Ethernet ports. */
2291 ports = rte_zmalloc("testpmd: ports",
2292 sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
2293 RTE_CACHE_LINE_SIZE);
2294 if (ports == NULL) {
2295 rte_exit(EXIT_FAILURE,
2296 "rte_zmalloc(%d struct rte_port) failed\n",
2312 const char clr[] = { 27, '[', '2', 'J', '\0' };
2313 const char top_left[] = { 27, '[', '1', ';', '1', 'H', '\0' };
2315 /* Clear screen and move to top left */
2316 printf("%s%s", clr, top_left);
2318 printf("\nPort statistics ====================================");
2319 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
2320 nic_stats_display(fwd_ports_ids[i]);
2324 signal_handler(int signum)
2326 if (signum == SIGINT || signum == SIGTERM) {
2327 printf("\nSignal %d received, preparing to exit...\n",
2329 #ifdef RTE_LIBRTE_PDUMP
2330 /* uninitialize packet capture framework */
2333 #ifdef RTE_LIBRTE_LATENCY_STATS
2334 rte_latencystats_uninit();
2337 /* Set flag to indicate the force termination. */
2339 /* exit with the expected status */
2340 signal(signum, SIG_DFL);
2341 kill(getpid(), signum);
2346 main(int argc, char** argv)
2351 signal(SIGINT, signal_handler);
2352 signal(SIGTERM, signal_handler);
2354 diag = rte_eal_init(argc, argv);
2356 rte_panic("Cannot init EAL\n");
2358 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
2359 RTE_LOG(NOTICE, USER1, "mlockall() failed with error \"%s\"\n",
2363 #ifdef RTE_LIBRTE_PDUMP
2364 /* initialize packet capture framework */
2365 rte_pdump_init(NULL);
2368 nb_ports = (portid_t) rte_eth_dev_count();
2370 RTE_LOG(WARNING, EAL, "No probed ethernet devices\n");
2372 /* allocate port structures, and init them */
2375 set_def_fwd_config();
2377 rte_panic("Empty set of forwarding logical cores - check the "
2378 "core mask supplied in the command parameters\n");
2380 /* Bitrate/latency stats disabled by default */
2381 #ifdef RTE_LIBRTE_BITRATE
2382 bitrate_enabled = 0;
2384 #ifdef RTE_LIBRTE_LATENCY_STATS
2385 latencystats_enabled = 0;
2391 launch_args_parse(argc, argv);
2393 if (tx_first && interactive)
2394 rte_exit(EXIT_FAILURE, "--tx-first cannot be used on "
2395 "interactive mode.\n");
2397 if (tx_first && lsc_interrupt) {
2398 printf("Warning: lsc_interrupt needs to be off when "
2399 " using tx_first. Disabling.\n");
2403 if (!nb_rxq && !nb_txq)
2404 printf("Warning: Either rx or tx queues should be non-zero\n");
2406 if (nb_rxq > 1 && nb_rxq > nb_txq)
2407 printf("Warning: nb_rxq=%d enables RSS configuration, "
2408 "but nb_txq=%d will prevent to fully test it.\n",
2412 if (start_port(RTE_PORT_ALL) != 0)
2413 rte_exit(EXIT_FAILURE, "Start ports failed\n");
2415 /* set all ports to promiscuous mode by default */
2416 RTE_ETH_FOREACH_DEV(port_id)
2417 rte_eth_promiscuous_enable(port_id);
2419 /* Init metrics library */
2420 rte_metrics_init(rte_socket_id());
2422 #ifdef RTE_LIBRTE_LATENCY_STATS
2423 if (latencystats_enabled != 0) {
2424 int ret = rte_latencystats_init(1, NULL);
2426 printf("Warning: latencystats init()"
2427 " returned error %d\n", ret);
2428 printf("Latencystats running on lcore %d\n",
2429 latencystats_lcore_id);
2433 /* Setup bitrate stats */
2434 #ifdef RTE_LIBRTE_BITRATE
2435 if (bitrate_enabled != 0) {
2436 bitrate_data = rte_stats_bitrate_create();
2437 if (bitrate_data == NULL)
2438 rte_exit(EXIT_FAILURE,
2439 "Could not allocate bitrate data.\n");
2440 rte_stats_bitrate_reg(bitrate_data);
2444 #ifdef RTE_LIBRTE_CMDLINE
2445 if (strlen(cmdline_filename) != 0)
2446 cmdline_read_from_file(cmdline_filename);
2448 if (interactive == 1) {
2450 printf("Start automatic packet forwarding\n");
2451 start_packet_forwarding(0);
2463 printf("No commandline core given, start packet forwarding\n");
2464 start_packet_forwarding(tx_first);
2465 if (stats_period != 0) {
2466 uint64_t prev_time = 0, cur_time, diff_time = 0;
2467 uint64_t timer_period;
2469 /* Convert to number of cycles */
2470 timer_period = stats_period * rte_get_timer_hz();
2472 while (f_quit == 0) {
2473 cur_time = rte_get_timer_cycles();
2474 diff_time += cur_time - prev_time;
2476 if (diff_time >= timer_period) {
2478 /* Reset the timer */
2481 /* Sleep to avoid unnecessary checks */
2482 prev_time = cur_time;
2487 printf("Press enter to exit\n");
2488 rc = read(0, &c, 1);