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_fdir_conf fdir_conf = {
320 .mode = RTE_FDIR_MODE_NONE,
321 .pballoc = RTE_FDIR_PBALLOC_64K,
322 .status = RTE_FDIR_REPORT_STATUS,
324 .vlan_tci_mask = 0x0,
326 .src_ip = 0xFFFFFFFF,
327 .dst_ip = 0xFFFFFFFF,
330 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
331 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
333 .src_port_mask = 0xFFFF,
334 .dst_port_mask = 0xFFFF,
335 .mac_addr_byte_mask = 0xFF,
336 .tunnel_type_mask = 1,
337 .tunnel_id_mask = 0xFFFFFFFF,
342 volatile int test_done = 1; /* stop packet forwarding when set to 1. */
344 struct queue_stats_mappings tx_queue_stats_mappings_array[MAX_TX_QUEUE_STATS_MAPPINGS];
345 struct queue_stats_mappings rx_queue_stats_mappings_array[MAX_RX_QUEUE_STATS_MAPPINGS];
347 struct queue_stats_mappings *tx_queue_stats_mappings = tx_queue_stats_mappings_array;
348 struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_array;
350 uint16_t nb_tx_queue_stats_mappings = 0;
351 uint16_t nb_rx_queue_stats_mappings = 0;
354 * Display zero values by default for xstats
356 uint8_t xstats_hide_zero;
358 unsigned int num_sockets = 0;
359 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
361 #ifdef RTE_LIBRTE_BITRATE
362 /* Bitrate statistics */
363 struct rte_stats_bitrates *bitrate_data;
364 lcoreid_t bitrate_lcore_id;
365 uint8_t bitrate_enabled;
368 struct gro_status gro_ports[RTE_MAX_ETHPORTS];
369 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
371 /* Forward function declarations */
372 static void map_port_queue_stats_mapping_registers(portid_t pi,
373 struct rte_port *port);
374 static void check_all_ports_link_status(uint32_t port_mask);
375 static int eth_event_callback(portid_t port_id,
376 enum rte_eth_event_type type,
377 void *param, void *ret_param);
380 * Check if all the ports are started.
381 * If yes, return positive value. If not, return zero.
383 static int all_ports_started(void);
385 struct gso_status gso_ports[RTE_MAX_ETHPORTS];
386 uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
389 * Helper function to check if socket is already discovered.
390 * If yes, return positive value. If not, return zero.
393 new_socket_id(unsigned int socket_id)
397 for (i = 0; i < num_sockets; i++) {
398 if (socket_ids[i] == socket_id)
405 * Setup default configuration.
408 set_default_fwd_lcores_config(void)
412 unsigned int sock_num;
415 for (i = 0; i < RTE_MAX_LCORE; i++) {
416 sock_num = rte_lcore_to_socket_id(i);
417 if (new_socket_id(sock_num)) {
418 if (num_sockets >= RTE_MAX_NUMA_NODES) {
419 rte_exit(EXIT_FAILURE,
420 "Total sockets greater than %u\n",
423 socket_ids[num_sockets++] = sock_num;
425 if (!rte_lcore_is_enabled(i))
427 if (i == rte_get_master_lcore())
429 fwd_lcores_cpuids[nb_lc++] = i;
431 nb_lcores = (lcoreid_t) nb_lc;
432 nb_cfg_lcores = nb_lcores;
437 set_def_peer_eth_addrs(void)
441 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
442 peer_eth_addrs[i].addr_bytes[0] = ETHER_LOCAL_ADMIN_ADDR;
443 peer_eth_addrs[i].addr_bytes[5] = i;
448 set_default_fwd_ports_config(void)
453 RTE_ETH_FOREACH_DEV(pt_id)
454 fwd_ports_ids[i++] = pt_id;
456 nb_cfg_ports = nb_ports;
457 nb_fwd_ports = nb_ports;
461 set_def_fwd_config(void)
463 set_default_fwd_lcores_config();
464 set_def_peer_eth_addrs();
465 set_default_fwd_ports_config();
469 * Configuration initialisation done once at init time.
472 mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
473 unsigned int socket_id)
475 char pool_name[RTE_MEMPOOL_NAMESIZE];
476 struct rte_mempool *rte_mp = NULL;
479 mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
480 mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
483 "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
484 pool_name, nb_mbuf, mbuf_seg_size, socket_id);
487 rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf,
488 mb_size, (unsigned) mb_mempool_cache,
489 sizeof(struct rte_pktmbuf_pool_private),
494 if (rte_mempool_populate_anon(rte_mp) == 0) {
495 rte_mempool_free(rte_mp);
499 rte_pktmbuf_pool_init(rte_mp, NULL);
500 rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
502 /* wrapper to rte_mempool_create() */
503 rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
504 mb_mempool_cache, 0, mbuf_seg_size, socket_id);
508 if (rte_mp == NULL) {
509 rte_exit(EXIT_FAILURE,
510 "Creation of mbuf pool for socket %u failed: %s\n",
511 socket_id, rte_strerror(rte_errno));
512 } else if (verbose_level > 0) {
513 rte_mempool_dump(stdout, rte_mp);
518 * Check given socket id is valid or not with NUMA mode,
519 * if valid, return 0, else return -1
522 check_socket_id(const unsigned int socket_id)
524 static int warning_once = 0;
526 if (new_socket_id(socket_id)) {
527 if (!warning_once && numa_support)
528 printf("Warning: NUMA should be configured manually by"
529 " using --port-numa-config and"
530 " --ring-numa-config parameters along with"
542 struct rte_port *port;
543 struct rte_mempool *mbp;
544 unsigned int nb_mbuf_per_pool;
546 uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
547 struct rte_gro_param gro_param;
550 memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
553 memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
554 memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
555 memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
558 /* Configuration of logical cores. */
559 fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
560 sizeof(struct fwd_lcore *) * nb_lcores,
561 RTE_CACHE_LINE_SIZE);
562 if (fwd_lcores == NULL) {
563 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_lcore *)) "
564 "failed\n", nb_lcores);
566 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
567 fwd_lcores[lc_id] = rte_zmalloc("testpmd: struct fwd_lcore",
568 sizeof(struct fwd_lcore),
569 RTE_CACHE_LINE_SIZE);
570 if (fwd_lcores[lc_id] == NULL) {
571 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_lcore) "
574 fwd_lcores[lc_id]->cpuid_idx = lc_id;
577 RTE_ETH_FOREACH_DEV(pid) {
579 rte_eth_dev_info_get(pid, &port->dev_info);
582 if (port_numa[pid] != NUMA_NO_CONFIG)
583 port_per_socket[port_numa[pid]]++;
585 uint32_t socket_id = rte_eth_dev_socket_id(pid);
587 /* if socket_id is invalid, set to 0 */
588 if (check_socket_id(socket_id) < 0)
590 port_per_socket[socket_id]++;
594 /* set flag to initialize port/queue */
595 port->need_reconfig = 1;
596 port->need_reconfig_queues = 1;
600 * Create pools of mbuf.
601 * If NUMA support is disabled, create a single pool of mbuf in
602 * socket 0 memory by default.
603 * Otherwise, create a pool of mbuf in the memory of sockets 0 and 1.
605 * Use the maximum value of nb_rxd and nb_txd here, then nb_rxd and
606 * nb_txd can be configured at run time.
608 if (param_total_num_mbufs)
609 nb_mbuf_per_pool = param_total_num_mbufs;
611 nb_mbuf_per_pool = RTE_TEST_RX_DESC_MAX +
612 (nb_lcores * mb_mempool_cache) +
613 RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
614 nb_mbuf_per_pool *= RTE_MAX_ETHPORTS;
620 for (i = 0; i < num_sockets; i++)
621 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
624 if (socket_num == UMA_NO_CONFIG)
625 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 0);
627 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
633 gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
634 DEV_TX_OFFLOAD_GRE_TNL_TSO;
636 * Records which Mbuf pool to use by each logical core, if needed.
638 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
639 mbp = mbuf_pool_find(
640 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]));
643 mbp = mbuf_pool_find(0);
644 fwd_lcores[lc_id]->mbp = mbp;
645 /* initialize GSO context */
646 fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
647 fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
648 fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
649 fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
651 fwd_lcores[lc_id]->gso_ctx.flag = 0;
654 /* Configuration of packet forwarding streams. */
655 if (init_fwd_streams() < 0)
656 rte_exit(EXIT_FAILURE, "FAIL from init_fwd_streams()\n");
660 /* create a gro context for each lcore */
661 gro_param.gro_types = RTE_GRO_TCP_IPV4;
662 gro_param.max_flow_num = GRO_MAX_FLUSH_CYCLES;
663 gro_param.max_item_per_flow = MAX_PKT_BURST;
664 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
665 gro_param.socket_id = rte_lcore_to_socket_id(
666 fwd_lcores_cpuids[lc_id]);
667 fwd_lcores[lc_id]->gro_ctx = rte_gro_ctx_create(&gro_param);
668 if (fwd_lcores[lc_id]->gro_ctx == NULL) {
669 rte_exit(EXIT_FAILURE,
670 "rte_gro_ctx_create() failed\n");
677 reconfig(portid_t new_port_id, unsigned socket_id)
679 struct rte_port *port;
681 /* Reconfiguration of Ethernet ports. */
682 port = &ports[new_port_id];
683 rte_eth_dev_info_get(new_port_id, &port->dev_info);
685 /* set flag to initialize port/queue */
686 port->need_reconfig = 1;
687 port->need_reconfig_queues = 1;
688 port->socket_id = socket_id;
695 init_fwd_streams(void)
698 struct rte_port *port;
699 streamid_t sm_id, nb_fwd_streams_new;
702 /* set socket id according to numa or not */
703 RTE_ETH_FOREACH_DEV(pid) {
705 if (nb_rxq > port->dev_info.max_rx_queues) {
706 printf("Fail: nb_rxq(%d) is greater than "
707 "max_rx_queues(%d)\n", nb_rxq,
708 port->dev_info.max_rx_queues);
711 if (nb_txq > port->dev_info.max_tx_queues) {
712 printf("Fail: nb_txq(%d) is greater than "
713 "max_tx_queues(%d)\n", nb_txq,
714 port->dev_info.max_tx_queues);
718 if (port_numa[pid] != NUMA_NO_CONFIG)
719 port->socket_id = port_numa[pid];
721 port->socket_id = rte_eth_dev_socket_id(pid);
723 /* if socket_id is invalid, set to 0 */
724 if (check_socket_id(port->socket_id) < 0)
729 if (socket_num == UMA_NO_CONFIG)
732 port->socket_id = socket_num;
736 q = RTE_MAX(nb_rxq, nb_txq);
738 printf("Fail: Cannot allocate fwd streams as number of queues is 0\n");
741 nb_fwd_streams_new = (streamid_t)(nb_ports * q);
742 if (nb_fwd_streams_new == nb_fwd_streams)
745 if (fwd_streams != NULL) {
746 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
747 if (fwd_streams[sm_id] == NULL)
749 rte_free(fwd_streams[sm_id]);
750 fwd_streams[sm_id] = NULL;
752 rte_free(fwd_streams);
757 nb_fwd_streams = nb_fwd_streams_new;
758 fwd_streams = rte_zmalloc("testpmd: fwd_streams",
759 sizeof(struct fwd_stream *) * nb_fwd_streams, RTE_CACHE_LINE_SIZE);
760 if (fwd_streams == NULL)
761 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_stream *)) "
762 "failed\n", nb_fwd_streams);
764 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
765 fwd_streams[sm_id] = rte_zmalloc("testpmd: struct fwd_stream",
766 sizeof(struct fwd_stream), RTE_CACHE_LINE_SIZE);
767 if (fwd_streams[sm_id] == NULL)
768 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_stream)"
775 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
777 pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs)
779 unsigned int total_burst;
780 unsigned int nb_burst;
781 unsigned int burst_stats[3];
782 uint16_t pktnb_stats[3];
784 int burst_percent[3];
787 * First compute the total number of packet bursts and the
788 * two highest numbers of bursts of the same number of packets.
791 burst_stats[0] = burst_stats[1] = burst_stats[2] = 0;
792 pktnb_stats[0] = pktnb_stats[1] = pktnb_stats[2] = 0;
793 for (nb_pkt = 0; nb_pkt < MAX_PKT_BURST; nb_pkt++) {
794 nb_burst = pbs->pkt_burst_spread[nb_pkt];
797 total_burst += nb_burst;
798 if (nb_burst > burst_stats[0]) {
799 burst_stats[1] = burst_stats[0];
800 pktnb_stats[1] = pktnb_stats[0];
801 burst_stats[0] = nb_burst;
802 pktnb_stats[0] = nb_pkt;
805 if (total_burst == 0)
807 burst_percent[0] = (burst_stats[0] * 100) / total_burst;
808 printf(" %s-bursts : %u [%d%% of %d pkts", rx_tx, total_burst,
809 burst_percent[0], (int) pktnb_stats[0]);
810 if (burst_stats[0] == total_burst) {
814 if (burst_stats[0] + burst_stats[1] == total_burst) {
815 printf(" + %d%% of %d pkts]\n",
816 100 - burst_percent[0], pktnb_stats[1]);
819 burst_percent[1] = (burst_stats[1] * 100) / total_burst;
820 burst_percent[2] = 100 - (burst_percent[0] + burst_percent[1]);
821 if ((burst_percent[1] == 0) || (burst_percent[2] == 0)) {
822 printf(" + %d%% of others]\n", 100 - burst_percent[0]);
825 printf(" + %d%% of %d pkts + %d%% of others]\n",
826 burst_percent[1], (int) pktnb_stats[1], burst_percent[2]);
828 #endif /* RTE_TEST_PMD_RECORD_BURST_STATS */
831 fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
833 struct rte_port *port;
836 static const char *fwd_stats_border = "----------------------";
838 port = &ports[port_id];
839 printf("\n %s Forward statistics for port %-2d %s\n",
840 fwd_stats_border, port_id, fwd_stats_border);
842 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
843 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
845 stats->ipackets, stats->imissed,
846 (uint64_t) (stats->ipackets + stats->imissed));
848 if (cur_fwd_eng == &csum_fwd_engine)
849 printf(" Bad-ipcsum: %-14"PRIu64" Bad-l4csum: %-14"PRIu64" \n",
850 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
851 if ((stats->ierrors + stats->rx_nombuf) > 0) {
852 printf(" RX-error: %-"PRIu64"\n", stats->ierrors);
853 printf(" RX-nombufs: %-14"PRIu64"\n", stats->rx_nombuf);
856 printf(" TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
858 stats->opackets, port->tx_dropped,
859 (uint64_t) (stats->opackets + port->tx_dropped));
862 printf(" RX-packets: %14"PRIu64" RX-dropped:%14"PRIu64" RX-total:"
864 stats->ipackets, stats->imissed,
865 (uint64_t) (stats->ipackets + stats->imissed));
867 if (cur_fwd_eng == &csum_fwd_engine)
868 printf(" Bad-ipcsum:%14"PRIu64" Bad-l4csum:%14"PRIu64"\n",
869 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
870 if ((stats->ierrors + stats->rx_nombuf) > 0) {
871 printf(" RX-error:%"PRIu64"\n", stats->ierrors);
872 printf(" RX-nombufs: %14"PRIu64"\n",
876 printf(" TX-packets: %14"PRIu64" TX-dropped:%14"PRIu64" TX-total:"
878 stats->opackets, port->tx_dropped,
879 (uint64_t) (stats->opackets + port->tx_dropped));
882 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
884 pkt_burst_stats_display("RX",
885 &port->rx_stream->rx_burst_stats);
887 pkt_burst_stats_display("TX",
888 &port->tx_stream->tx_burst_stats);
891 if (port->rx_queue_stats_mapping_enabled) {
893 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
894 printf(" Stats reg %2d RX-packets:%14"PRIu64
895 " RX-errors:%14"PRIu64
896 " RX-bytes:%14"PRIu64"\n",
897 i, stats->q_ipackets[i], stats->q_errors[i], stats->q_ibytes[i]);
901 if (port->tx_queue_stats_mapping_enabled) {
902 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
903 printf(" Stats reg %2d TX-packets:%14"PRIu64
904 " TX-bytes:%14"PRIu64"\n",
905 i, stats->q_opackets[i], stats->q_obytes[i]);
909 printf(" %s--------------------------------%s\n",
910 fwd_stats_border, fwd_stats_border);
914 fwd_stream_stats_display(streamid_t stream_id)
916 struct fwd_stream *fs;
917 static const char *fwd_top_stats_border = "-------";
919 fs = fwd_streams[stream_id];
920 if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
921 (fs->fwd_dropped == 0))
923 printf("\n %s Forward Stats for RX Port=%2d/Queue=%2d -> "
924 "TX Port=%2d/Queue=%2d %s\n",
925 fwd_top_stats_border, fs->rx_port, fs->rx_queue,
926 fs->tx_port, fs->tx_queue, fwd_top_stats_border);
927 printf(" RX-packets: %-14u TX-packets: %-14u TX-dropped: %-14u",
928 fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
930 /* if checksum mode */
931 if (cur_fwd_eng == &csum_fwd_engine) {
932 printf(" RX- bad IP checksum: %-14u Rx- bad L4 checksum: "
933 "%-14u\n", fs->rx_bad_ip_csum, fs->rx_bad_l4_csum);
936 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
937 pkt_burst_stats_display("RX", &fs->rx_burst_stats);
938 pkt_burst_stats_display("TX", &fs->tx_burst_stats);
943 flush_fwd_rx_queues(void)
945 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
952 uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
953 uint64_t timer_period;
955 /* convert to number of cycles */
956 timer_period = rte_get_timer_hz(); /* 1 second timeout */
958 for (j = 0; j < 2; j++) {
959 for (rxp = 0; rxp < cur_fwd_config.nb_fwd_ports; rxp++) {
960 for (rxq = 0; rxq < nb_rxq; rxq++) {
961 port_id = fwd_ports_ids[rxp];
963 * testpmd can stuck in the below do while loop
964 * if rte_eth_rx_burst() always returns nonzero
965 * packets. So timer is added to exit this loop
966 * after 1sec timer expiry.
968 prev_tsc = rte_rdtsc();
970 nb_rx = rte_eth_rx_burst(port_id, rxq,
971 pkts_burst, MAX_PKT_BURST);
972 for (i = 0; i < nb_rx; i++)
973 rte_pktmbuf_free(pkts_burst[i]);
975 cur_tsc = rte_rdtsc();
976 diff_tsc = cur_tsc - prev_tsc;
977 timer_tsc += diff_tsc;
978 } while ((nb_rx > 0) &&
979 (timer_tsc < timer_period));
983 rte_delay_ms(10); /* wait 10 milli-seconds before retrying */
988 run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
990 struct fwd_stream **fsm;
993 #ifdef RTE_LIBRTE_BITRATE
994 uint64_t tics_per_1sec;
996 uint64_t tics_current;
997 uint8_t idx_port, cnt_ports;
999 cnt_ports = rte_eth_dev_count();
1000 tics_datum = rte_rdtsc();
1001 tics_per_1sec = rte_get_timer_hz();
1003 fsm = &fwd_streams[fc->stream_idx];
1004 nb_fs = fc->stream_nb;
1006 for (sm_id = 0; sm_id < nb_fs; sm_id++)
1007 (*pkt_fwd)(fsm[sm_id]);
1008 #ifdef RTE_LIBRTE_BITRATE
1009 if (bitrate_enabled != 0 &&
1010 bitrate_lcore_id == rte_lcore_id()) {
1011 tics_current = rte_rdtsc();
1012 if (tics_current - tics_datum >= tics_per_1sec) {
1013 /* Periodic bitrate calculation */
1015 idx_port < cnt_ports;
1017 rte_stats_bitrate_calc(bitrate_data,
1019 tics_datum = tics_current;
1023 #ifdef RTE_LIBRTE_LATENCY_STATS
1024 if (latencystats_enabled != 0 &&
1025 latencystats_lcore_id == rte_lcore_id())
1026 rte_latencystats_update();
1029 } while (! fc->stopped);
1033 start_pkt_forward_on_core(void *fwd_arg)
1035 run_pkt_fwd_on_lcore((struct fwd_lcore *) fwd_arg,
1036 cur_fwd_config.fwd_eng->packet_fwd);
1041 * Run the TXONLY packet forwarding engine to send a single burst of packets.
1042 * Used to start communication flows in network loopback test configurations.
1045 run_one_txonly_burst_on_core(void *fwd_arg)
1047 struct fwd_lcore *fwd_lc;
1048 struct fwd_lcore tmp_lcore;
1050 fwd_lc = (struct fwd_lcore *) fwd_arg;
1051 tmp_lcore = *fwd_lc;
1052 tmp_lcore.stopped = 1;
1053 run_pkt_fwd_on_lcore(&tmp_lcore, tx_only_engine.packet_fwd);
1058 * Launch packet forwarding:
1059 * - Setup per-port forwarding context.
1060 * - launch logical cores with their forwarding configuration.
1063 launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
1065 port_fwd_begin_t port_fwd_begin;
1070 port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
1071 if (port_fwd_begin != NULL) {
1072 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1073 (*port_fwd_begin)(fwd_ports_ids[i]);
1075 for (i = 0; i < cur_fwd_config.nb_fwd_lcores; i++) {
1076 lc_id = fwd_lcores_cpuids[i];
1077 if ((interactive == 0) || (lc_id != rte_lcore_id())) {
1078 fwd_lcores[i]->stopped = 0;
1079 diag = rte_eal_remote_launch(pkt_fwd_on_lcore,
1080 fwd_lcores[i], lc_id);
1082 printf("launch lcore %u failed - diag=%d\n",
1089 * Launch packet forwarding configuration.
1092 start_packet_forwarding(int with_tx_first)
1094 port_fwd_begin_t port_fwd_begin;
1095 port_fwd_end_t port_fwd_end;
1096 struct rte_port *port;
1101 if (strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") == 0 && !nb_rxq)
1102 rte_exit(EXIT_FAILURE, "rxq are 0, cannot use rxonly fwd mode\n");
1104 if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 && !nb_txq)
1105 rte_exit(EXIT_FAILURE, "txq are 0, cannot use txonly fwd mode\n");
1107 if ((strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") != 0 &&
1108 strcmp(cur_fwd_eng->fwd_mode_name, "txonly") != 0) &&
1109 (!nb_rxq || !nb_txq))
1110 rte_exit(EXIT_FAILURE,
1111 "Either rxq or txq are 0, cannot use %s fwd mode\n",
1112 cur_fwd_eng->fwd_mode_name);
1114 if (all_ports_started() == 0) {
1115 printf("Not all ports were started\n");
1118 if (test_done == 0) {
1119 printf("Packet forwarding already started\n");
1123 if (init_fwd_streams() < 0) {
1124 printf("Fail from init_fwd_streams()\n");
1129 for (i = 0; i < nb_fwd_ports; i++) {
1130 pt_id = fwd_ports_ids[i];
1131 port = &ports[pt_id];
1132 if (!port->dcb_flag) {
1133 printf("In DCB mode, all forwarding ports must "
1134 "be configured in this mode.\n");
1138 if (nb_fwd_lcores == 1) {
1139 printf("In DCB mode,the nb forwarding cores "
1140 "should be larger than 1.\n");
1147 flush_fwd_rx_queues();
1150 pkt_fwd_config_display(&cur_fwd_config);
1151 rxtx_config_display();
1153 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1154 pt_id = fwd_ports_ids[i];
1155 port = &ports[pt_id];
1156 rte_eth_stats_get(pt_id, &port->stats);
1157 port->tx_dropped = 0;
1159 map_port_queue_stats_mapping_registers(pt_id, port);
1161 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1162 fwd_streams[sm_id]->rx_packets = 0;
1163 fwd_streams[sm_id]->tx_packets = 0;
1164 fwd_streams[sm_id]->fwd_dropped = 0;
1165 fwd_streams[sm_id]->rx_bad_ip_csum = 0;
1166 fwd_streams[sm_id]->rx_bad_l4_csum = 0;
1168 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1169 memset(&fwd_streams[sm_id]->rx_burst_stats, 0,
1170 sizeof(fwd_streams[sm_id]->rx_burst_stats));
1171 memset(&fwd_streams[sm_id]->tx_burst_stats, 0,
1172 sizeof(fwd_streams[sm_id]->tx_burst_stats));
1174 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1175 fwd_streams[sm_id]->core_cycles = 0;
1178 if (with_tx_first) {
1179 port_fwd_begin = tx_only_engine.port_fwd_begin;
1180 if (port_fwd_begin != NULL) {
1181 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1182 (*port_fwd_begin)(fwd_ports_ids[i]);
1184 while (with_tx_first--) {
1185 launch_packet_forwarding(
1186 run_one_txonly_burst_on_core);
1187 rte_eal_mp_wait_lcore();
1189 port_fwd_end = tx_only_engine.port_fwd_end;
1190 if (port_fwd_end != NULL) {
1191 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1192 (*port_fwd_end)(fwd_ports_ids[i]);
1195 launch_packet_forwarding(start_pkt_forward_on_core);
1199 stop_packet_forwarding(void)
1201 struct rte_eth_stats stats;
1202 struct rte_port *port;
1203 port_fwd_end_t port_fwd_end;
1208 uint64_t total_recv;
1209 uint64_t total_xmit;
1210 uint64_t total_rx_dropped;
1211 uint64_t total_tx_dropped;
1212 uint64_t total_rx_nombuf;
1213 uint64_t tx_dropped;
1214 uint64_t rx_bad_ip_csum;
1215 uint64_t rx_bad_l4_csum;
1216 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1217 uint64_t fwd_cycles;
1220 static const char *acc_stats_border = "+++++++++++++++";
1223 printf("Packet forwarding not started\n");
1226 printf("Telling cores to stop...");
1227 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++)
1228 fwd_lcores[lc_id]->stopped = 1;
1229 printf("\nWaiting for lcores to finish...\n");
1230 rte_eal_mp_wait_lcore();
1231 port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end;
1232 if (port_fwd_end != NULL) {
1233 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1234 pt_id = fwd_ports_ids[i];
1235 (*port_fwd_end)(pt_id);
1238 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1241 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1242 if (cur_fwd_config.nb_fwd_streams >
1243 cur_fwd_config.nb_fwd_ports) {
1244 fwd_stream_stats_display(sm_id);
1245 ports[fwd_streams[sm_id]->tx_port].tx_stream = NULL;
1246 ports[fwd_streams[sm_id]->rx_port].rx_stream = NULL;
1248 ports[fwd_streams[sm_id]->tx_port].tx_stream =
1250 ports[fwd_streams[sm_id]->rx_port].rx_stream =
1253 tx_dropped = ports[fwd_streams[sm_id]->tx_port].tx_dropped;
1254 tx_dropped = (uint64_t) (tx_dropped +
1255 fwd_streams[sm_id]->fwd_dropped);
1256 ports[fwd_streams[sm_id]->tx_port].tx_dropped = tx_dropped;
1259 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum;
1260 rx_bad_ip_csum = (uint64_t) (rx_bad_ip_csum +
1261 fwd_streams[sm_id]->rx_bad_ip_csum);
1262 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum =
1266 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum;
1267 rx_bad_l4_csum = (uint64_t) (rx_bad_l4_csum +
1268 fwd_streams[sm_id]->rx_bad_l4_csum);
1269 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum =
1272 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1273 fwd_cycles = (uint64_t) (fwd_cycles +
1274 fwd_streams[sm_id]->core_cycles);
1279 total_rx_dropped = 0;
1280 total_tx_dropped = 0;
1281 total_rx_nombuf = 0;
1282 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1283 pt_id = fwd_ports_ids[i];
1285 port = &ports[pt_id];
1286 rte_eth_stats_get(pt_id, &stats);
1287 stats.ipackets -= port->stats.ipackets;
1288 port->stats.ipackets = 0;
1289 stats.opackets -= port->stats.opackets;
1290 port->stats.opackets = 0;
1291 stats.ibytes -= port->stats.ibytes;
1292 port->stats.ibytes = 0;
1293 stats.obytes -= port->stats.obytes;
1294 port->stats.obytes = 0;
1295 stats.imissed -= port->stats.imissed;
1296 port->stats.imissed = 0;
1297 stats.oerrors -= port->stats.oerrors;
1298 port->stats.oerrors = 0;
1299 stats.rx_nombuf -= port->stats.rx_nombuf;
1300 port->stats.rx_nombuf = 0;
1302 total_recv += stats.ipackets;
1303 total_xmit += stats.opackets;
1304 total_rx_dropped += stats.imissed;
1305 total_tx_dropped += port->tx_dropped;
1306 total_rx_nombuf += stats.rx_nombuf;
1308 fwd_port_stats_display(pt_id, &stats);
1311 printf("\n %s Accumulated forward statistics for all ports"
1313 acc_stats_border, acc_stats_border);
1314 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
1316 " TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
1318 total_recv, total_rx_dropped, total_recv + total_rx_dropped,
1319 total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
1320 if (total_rx_nombuf > 0)
1321 printf(" RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
1322 printf(" %s++++++++++++++++++++++++++++++++++++++++++++++"
1324 acc_stats_border, acc_stats_border);
1325 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1327 printf("\n CPU cycles/packet=%u (total cycles="
1328 "%"PRIu64" / total RX packets=%"PRIu64")\n",
1329 (unsigned int)(fwd_cycles / total_recv),
1330 fwd_cycles, total_recv);
1332 printf("\nDone.\n");
1337 dev_set_link_up(portid_t pid)
1339 if (rte_eth_dev_set_link_up(pid) < 0)
1340 printf("\nSet link up fail.\n");
1344 dev_set_link_down(portid_t pid)
1346 if (rte_eth_dev_set_link_down(pid) < 0)
1347 printf("\nSet link down fail.\n");
1351 all_ports_started(void)
1354 struct rte_port *port;
1356 RTE_ETH_FOREACH_DEV(pi) {
1358 /* Check if there is a port which is not started */
1359 if ((port->port_status != RTE_PORT_STARTED) &&
1360 (port->slave_flag == 0))
1364 /* No port is not started */
1369 port_is_stopped(portid_t port_id)
1371 struct rte_port *port = &ports[port_id];
1373 if ((port->port_status != RTE_PORT_STOPPED) &&
1374 (port->slave_flag == 0))
1380 all_ports_stopped(void)
1384 RTE_ETH_FOREACH_DEV(pi) {
1385 if (!port_is_stopped(pi))
1393 port_is_started(portid_t port_id)
1395 if (port_id_is_invalid(port_id, ENABLED_WARN))
1398 if (ports[port_id].port_status != RTE_PORT_STARTED)
1405 port_is_closed(portid_t port_id)
1407 if (port_id_is_invalid(port_id, ENABLED_WARN))
1410 if (ports[port_id].port_status != RTE_PORT_CLOSED)
1417 start_port(portid_t pid)
1419 int diag, need_check_link_status = -1;
1422 struct rte_port *port;
1423 struct ether_addr mac_addr;
1424 enum rte_eth_event_type event_type;
1426 if (port_id_is_invalid(pid, ENABLED_WARN))
1431 RTE_ETH_FOREACH_DEV(pi) {
1432 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1435 need_check_link_status = 0;
1437 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STOPPED,
1438 RTE_PORT_HANDLING) == 0) {
1439 printf("Port %d is now not stopped\n", pi);
1443 if (port->need_reconfig > 0) {
1444 port->need_reconfig = 0;
1446 if (flow_isolate_all) {
1447 int ret = port_flow_isolate(pi, 1);
1449 printf("Failed to apply isolated"
1450 " mode on port %d\n", pi);
1455 printf("Configuring Port %d (socket %u)\n", pi,
1457 /* configure port */
1458 diag = rte_eth_dev_configure(pi, nb_rxq, nb_txq,
1461 if (rte_atomic16_cmpset(&(port->port_status),
1462 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1463 printf("Port %d can not be set back "
1464 "to stopped\n", pi);
1465 printf("Fail to configure port %d\n", pi);
1466 /* try to reconfigure port next time */
1467 port->need_reconfig = 1;
1471 if (port->need_reconfig_queues > 0) {
1472 port->need_reconfig_queues = 0;
1473 /* setup tx queues */
1474 for (qi = 0; qi < nb_txq; qi++) {
1475 if ((numa_support) &&
1476 (txring_numa[pi] != NUMA_NO_CONFIG))
1477 diag = rte_eth_tx_queue_setup(pi, qi,
1478 nb_txd,txring_numa[pi],
1481 diag = rte_eth_tx_queue_setup(pi, qi,
1482 nb_txd,port->socket_id,
1488 /* Fail to setup tx queue, return */
1489 if (rte_atomic16_cmpset(&(port->port_status),
1491 RTE_PORT_STOPPED) == 0)
1492 printf("Port %d can not be set back "
1493 "to stopped\n", pi);
1494 printf("Fail to configure port %d tx queues\n", pi);
1495 /* try to reconfigure queues next time */
1496 port->need_reconfig_queues = 1;
1499 /* Apply Rx offloads configuration */
1500 port->rx_conf.offloads = port->dev_conf.rxmode.offloads;
1501 /* setup rx queues */
1502 for (qi = 0; qi < nb_rxq; qi++) {
1503 if ((numa_support) &&
1504 (rxring_numa[pi] != NUMA_NO_CONFIG)) {
1505 struct rte_mempool * mp =
1506 mbuf_pool_find(rxring_numa[pi]);
1508 printf("Failed to setup RX queue:"
1509 "No mempool allocation"
1510 " on the socket %d\n",
1515 diag = rte_eth_rx_queue_setup(pi, qi,
1516 nb_rxd,rxring_numa[pi],
1517 &(port->rx_conf),mp);
1519 struct rte_mempool *mp =
1520 mbuf_pool_find(port->socket_id);
1522 printf("Failed to setup RX queue:"
1523 "No mempool allocation"
1524 " on the socket %d\n",
1528 diag = rte_eth_rx_queue_setup(pi, qi,
1529 nb_rxd,port->socket_id,
1530 &(port->rx_conf), mp);
1535 /* Fail to setup rx queue, return */
1536 if (rte_atomic16_cmpset(&(port->port_status),
1538 RTE_PORT_STOPPED) == 0)
1539 printf("Port %d can not be set back "
1540 "to stopped\n", pi);
1541 printf("Fail to configure port %d rx queues\n", pi);
1542 /* try to reconfigure queues next time */
1543 port->need_reconfig_queues = 1;
1548 for (event_type = RTE_ETH_EVENT_UNKNOWN;
1549 event_type < RTE_ETH_EVENT_MAX;
1551 diag = rte_eth_dev_callback_register(pi,
1556 printf("Failed to setup even callback for event %d\n",
1563 if (rte_eth_dev_start(pi) < 0) {
1564 printf("Fail to start port %d\n", pi);
1566 /* Fail to setup rx queue, return */
1567 if (rte_atomic16_cmpset(&(port->port_status),
1568 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1569 printf("Port %d can not be set back to "
1574 if (rte_atomic16_cmpset(&(port->port_status),
1575 RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0)
1576 printf("Port %d can not be set into started\n", pi);
1578 rte_eth_macaddr_get(pi, &mac_addr);
1579 printf("Port %d: %02X:%02X:%02X:%02X:%02X:%02X\n", pi,
1580 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
1581 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
1582 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5]);
1584 /* at least one port started, need checking link status */
1585 need_check_link_status = 1;
1588 if (need_check_link_status == 1 && !no_link_check)
1589 check_all_ports_link_status(RTE_PORT_ALL);
1590 else if (need_check_link_status == 0)
1591 printf("Please stop the ports first\n");
1598 stop_port(portid_t pid)
1601 struct rte_port *port;
1602 int need_check_link_status = 0;
1609 if (port_id_is_invalid(pid, ENABLED_WARN))
1612 printf("Stopping ports...\n");
1614 RTE_ETH_FOREACH_DEV(pi) {
1615 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1618 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1619 printf("Please remove port %d from forwarding configuration.\n", pi);
1623 if (port_is_bonding_slave(pi)) {
1624 printf("Please remove port %d from bonded device.\n", pi);
1629 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STARTED,
1630 RTE_PORT_HANDLING) == 0)
1633 rte_eth_dev_stop(pi);
1635 if (rte_atomic16_cmpset(&(port->port_status),
1636 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1637 printf("Port %d can not be set into stopped\n", pi);
1638 need_check_link_status = 1;
1640 if (need_check_link_status && !no_link_check)
1641 check_all_ports_link_status(RTE_PORT_ALL);
1647 close_port(portid_t pid)
1650 struct rte_port *port;
1652 if (port_id_is_invalid(pid, ENABLED_WARN))
1655 printf("Closing ports...\n");
1657 RTE_ETH_FOREACH_DEV(pi) {
1658 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1661 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1662 printf("Please remove port %d from forwarding configuration.\n", pi);
1666 if (port_is_bonding_slave(pi)) {
1667 printf("Please remove port %d from bonded device.\n", pi);
1672 if (rte_atomic16_cmpset(&(port->port_status),
1673 RTE_PORT_CLOSED, RTE_PORT_CLOSED) == 1) {
1674 printf("Port %d is already closed\n", pi);
1678 if (rte_atomic16_cmpset(&(port->port_status),
1679 RTE_PORT_STOPPED, RTE_PORT_HANDLING) == 0) {
1680 printf("Port %d is now not stopped\n", pi);
1684 if (port->flow_list)
1685 port_flow_flush(pi);
1686 rte_eth_dev_close(pi);
1688 if (rte_atomic16_cmpset(&(port->port_status),
1689 RTE_PORT_HANDLING, RTE_PORT_CLOSED) == 0)
1690 printf("Port %d cannot be set to closed\n", pi);
1697 reset_port(portid_t pid)
1701 struct rte_port *port;
1703 if (port_id_is_invalid(pid, ENABLED_WARN))
1706 printf("Resetting ports...\n");
1708 RTE_ETH_FOREACH_DEV(pi) {
1709 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1712 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1713 printf("Please remove port %d from forwarding "
1714 "configuration.\n", pi);
1718 if (port_is_bonding_slave(pi)) {
1719 printf("Please remove port %d from bonded device.\n",
1724 diag = rte_eth_dev_reset(pi);
1727 port->need_reconfig = 1;
1728 port->need_reconfig_queues = 1;
1730 printf("Failed to reset port %d. diag=%d\n", pi, diag);
1738 attach_port(char *identifier)
1741 unsigned int socket_id;
1743 printf("Attaching a new port...\n");
1745 if (identifier == NULL) {
1746 printf("Invalid parameters are specified\n");
1750 if (rte_eth_dev_attach(identifier, &pi))
1753 socket_id = (unsigned)rte_eth_dev_socket_id(pi);
1754 /* if socket_id is invalid, set to 0 */
1755 if (check_socket_id(socket_id) < 0)
1757 reconfig(pi, socket_id);
1758 rte_eth_promiscuous_enable(pi);
1760 nb_ports = rte_eth_dev_count();
1762 ports[pi].port_status = RTE_PORT_STOPPED;
1764 printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
1769 detach_port(portid_t port_id)
1771 char name[RTE_ETH_NAME_MAX_LEN];
1773 printf("Detaching a port...\n");
1775 if (!port_is_closed(port_id)) {
1776 printf("Please close port first\n");
1780 if (ports[port_id].flow_list)
1781 port_flow_flush(port_id);
1783 if (rte_eth_dev_detach(port_id, name)) {
1784 TESTPMD_LOG(ERR, "Failed to detach port '%s'\n", name);
1788 nb_ports = rte_eth_dev_count();
1790 printf("Port '%s' is detached. Now total ports is %d\n",
1802 stop_packet_forwarding();
1804 if (ports != NULL) {
1806 RTE_ETH_FOREACH_DEV(pt_id) {
1807 printf("\nShutting down port %d...\n", pt_id);
1813 printf("\nBye...\n");
1816 typedef void (*cmd_func_t)(void);
1817 struct pmd_test_command {
1818 const char *cmd_name;
1819 cmd_func_t cmd_func;
1822 #define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
1824 /* Check the link status of all ports in up to 9s, and print them finally */
1826 check_all_ports_link_status(uint32_t port_mask)
1828 #define CHECK_INTERVAL 100 /* 100ms */
1829 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
1831 uint8_t count, all_ports_up, print_flag = 0;
1832 struct rte_eth_link link;
1834 printf("Checking link statuses...\n");
1836 for (count = 0; count <= MAX_CHECK_TIME; count++) {
1838 RTE_ETH_FOREACH_DEV(portid) {
1839 if ((port_mask & (1 << portid)) == 0)
1841 memset(&link, 0, sizeof(link));
1842 rte_eth_link_get_nowait(portid, &link);
1843 /* print link status if flag set */
1844 if (print_flag == 1) {
1845 if (link.link_status)
1847 "Port%d Link Up. speed %u Mbps- %s\n",
1848 portid, link.link_speed,
1849 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
1850 ("full-duplex") : ("half-duplex\n"));
1852 printf("Port %d Link Down\n", portid);
1855 /* clear all_ports_up flag if any link down */
1856 if (link.link_status == ETH_LINK_DOWN) {
1861 /* after finally printing all link status, get out */
1862 if (print_flag == 1)
1865 if (all_ports_up == 0) {
1867 rte_delay_ms(CHECK_INTERVAL);
1870 /* set the print_flag if all ports up or timeout */
1871 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
1881 rmv_event_callback(void *arg)
1883 struct rte_eth_dev *dev;
1884 portid_t port_id = (intptr_t)arg;
1886 RTE_ETH_VALID_PORTID_OR_RET(port_id);
1887 dev = &rte_eth_devices[port_id];
1890 close_port(port_id);
1891 printf("removing device %s\n", dev->device->name);
1892 if (rte_eal_dev_detach(dev->device))
1893 TESTPMD_LOG(ERR, "Failed to detach device %s\n",
1897 /* This function is used by the interrupt thread */
1899 eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
1902 static const char * const event_desc[] = {
1903 [RTE_ETH_EVENT_UNKNOWN] = "Unknown",
1904 [RTE_ETH_EVENT_INTR_LSC] = "LSC",
1905 [RTE_ETH_EVENT_QUEUE_STATE] = "Queue state",
1906 [RTE_ETH_EVENT_INTR_RESET] = "Interrupt reset",
1907 [RTE_ETH_EVENT_VF_MBOX] = "VF Mbox",
1908 [RTE_ETH_EVENT_MACSEC] = "MACsec",
1909 [RTE_ETH_EVENT_INTR_RMV] = "device removal",
1910 [RTE_ETH_EVENT_MAX] = NULL,
1913 RTE_SET_USED(param);
1914 RTE_SET_USED(ret_param);
1916 if (type >= RTE_ETH_EVENT_MAX) {
1917 fprintf(stderr, "\nPort %" PRIu8 ": %s called upon invalid event %d\n",
1918 port_id, __func__, type);
1920 } else if (event_print_mask & (UINT32_C(1) << type)) {
1921 printf("\nPort %" PRIu8 ": %s event\n", port_id,
1927 case RTE_ETH_EVENT_INTR_RMV:
1928 if (rte_eal_alarm_set(100000,
1929 rmv_event_callback, (void *)(intptr_t)port_id))
1930 fprintf(stderr, "Could not set up deferred device removal\n");
1939 set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
1943 uint8_t mapping_found = 0;
1945 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
1946 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
1947 (tx_queue_stats_mappings[i].queue_id < nb_txq )) {
1948 diag = rte_eth_dev_set_tx_queue_stats_mapping(port_id,
1949 tx_queue_stats_mappings[i].queue_id,
1950 tx_queue_stats_mappings[i].stats_counter_id);
1957 port->tx_queue_stats_mapping_enabled = 1;
1962 set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
1966 uint8_t mapping_found = 0;
1968 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
1969 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
1970 (rx_queue_stats_mappings[i].queue_id < nb_rxq )) {
1971 diag = rte_eth_dev_set_rx_queue_stats_mapping(port_id,
1972 rx_queue_stats_mappings[i].queue_id,
1973 rx_queue_stats_mappings[i].stats_counter_id);
1980 port->rx_queue_stats_mapping_enabled = 1;
1985 map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
1989 diag = set_tx_queue_stats_mapping_registers(pi, port);
1991 if (diag == -ENOTSUP) {
1992 port->tx_queue_stats_mapping_enabled = 0;
1993 printf("TX queue stats mapping not supported port id=%d\n", pi);
1996 rte_exit(EXIT_FAILURE,
1997 "set_tx_queue_stats_mapping_registers "
1998 "failed for port id=%d diag=%d\n",
2002 diag = set_rx_queue_stats_mapping_registers(pi, port);
2004 if (diag == -ENOTSUP) {
2005 port->rx_queue_stats_mapping_enabled = 0;
2006 printf("RX queue stats mapping not supported port id=%d\n", pi);
2009 rte_exit(EXIT_FAILURE,
2010 "set_rx_queue_stats_mapping_registers "
2011 "failed for port id=%d diag=%d\n",
2017 rxtx_port_config(struct rte_port *port)
2019 port->rx_conf = port->dev_info.default_rxconf;
2020 port->tx_conf = port->dev_info.default_txconf;
2022 /* Check if any RX/TX parameters have been passed */
2023 if (rx_pthresh != RTE_PMD_PARAM_UNSET)
2024 port->rx_conf.rx_thresh.pthresh = rx_pthresh;
2026 if (rx_hthresh != RTE_PMD_PARAM_UNSET)
2027 port->rx_conf.rx_thresh.hthresh = rx_hthresh;
2029 if (rx_wthresh != RTE_PMD_PARAM_UNSET)
2030 port->rx_conf.rx_thresh.wthresh = rx_wthresh;
2032 if (rx_free_thresh != RTE_PMD_PARAM_UNSET)
2033 port->rx_conf.rx_free_thresh = rx_free_thresh;
2035 if (rx_drop_en != RTE_PMD_PARAM_UNSET)
2036 port->rx_conf.rx_drop_en = rx_drop_en;
2038 if (tx_pthresh != RTE_PMD_PARAM_UNSET)
2039 port->tx_conf.tx_thresh.pthresh = tx_pthresh;
2041 if (tx_hthresh != RTE_PMD_PARAM_UNSET)
2042 port->tx_conf.tx_thresh.hthresh = tx_hthresh;
2044 if (tx_wthresh != RTE_PMD_PARAM_UNSET)
2045 port->tx_conf.tx_thresh.wthresh = tx_wthresh;
2047 if (tx_rs_thresh != RTE_PMD_PARAM_UNSET)
2048 port->tx_conf.tx_rs_thresh = tx_rs_thresh;
2050 if (tx_free_thresh != RTE_PMD_PARAM_UNSET)
2051 port->tx_conf.tx_free_thresh = tx_free_thresh;
2053 if (txq_flags != RTE_PMD_PARAM_UNSET)
2054 port->tx_conf.txq_flags = txq_flags;
2058 init_port_config(void)
2061 struct rte_port *port;
2063 RTE_ETH_FOREACH_DEV(pid) {
2065 port->dev_conf.rxmode = rx_mode;
2066 port->dev_conf.fdir_conf = fdir_conf;
2068 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2069 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = rss_hf;
2071 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2072 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = 0;
2075 if (port->dcb_flag == 0) {
2076 if( port->dev_conf.rx_adv_conf.rss_conf.rss_hf != 0)
2077 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
2079 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
2082 rxtx_port_config(port);
2084 rte_eth_macaddr_get(pid, &port->eth_addr);
2086 map_port_queue_stats_mapping_registers(pid, port);
2087 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
2088 rte_pmd_ixgbe_bypass_init(pid);
2091 if (lsc_interrupt &&
2092 (rte_eth_devices[pid].data->dev_flags &
2093 RTE_ETH_DEV_INTR_LSC))
2094 port->dev_conf.intr_conf.lsc = 1;
2095 if (rmv_interrupt &&
2096 (rte_eth_devices[pid].data->dev_flags &
2097 RTE_ETH_DEV_INTR_RMV))
2098 port->dev_conf.intr_conf.rmv = 1;
2100 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
2101 /* Detect softnic port */
2102 if (!strcmp(port->dev_info.driver_name, "net_softnic")) {
2103 port->softnic_enable = 1;
2104 memset(&port->softport, 0, sizeof(struct softnic_port));
2106 if (!strcmp(cur_fwd_eng->fwd_mode_name, "tm"))
2107 port->softport.tm_flag = 1;
2113 void set_port_slave_flag(portid_t slave_pid)
2115 struct rte_port *port;
2117 port = &ports[slave_pid];
2118 port->slave_flag = 1;
2121 void clear_port_slave_flag(portid_t slave_pid)
2123 struct rte_port *port;
2125 port = &ports[slave_pid];
2126 port->slave_flag = 0;
2129 uint8_t port_is_bonding_slave(portid_t slave_pid)
2131 struct rte_port *port;
2133 port = &ports[slave_pid];
2134 return port->slave_flag;
2137 const uint16_t vlan_tags[] = {
2138 0, 1, 2, 3, 4, 5, 6, 7,
2139 8, 9, 10, 11, 12, 13, 14, 15,
2140 16, 17, 18, 19, 20, 21, 22, 23,
2141 24, 25, 26, 27, 28, 29, 30, 31
2145 get_eth_dcb_conf(struct rte_eth_conf *eth_conf,
2146 enum dcb_mode_enable dcb_mode,
2147 enum rte_eth_nb_tcs num_tcs,
2153 * Builds up the correct configuration for dcb+vt based on the vlan tags array
2154 * given above, and the number of traffic classes available for use.
2156 if (dcb_mode == DCB_VT_ENABLED) {
2157 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
2158 ð_conf->rx_adv_conf.vmdq_dcb_conf;
2159 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
2160 ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
2162 /* VMDQ+DCB RX and TX configurations */
2163 vmdq_rx_conf->enable_default_pool = 0;
2164 vmdq_rx_conf->default_pool = 0;
2165 vmdq_rx_conf->nb_queue_pools =
2166 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2167 vmdq_tx_conf->nb_queue_pools =
2168 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2170 vmdq_rx_conf->nb_pool_maps = vmdq_rx_conf->nb_queue_pools;
2171 for (i = 0; i < vmdq_rx_conf->nb_pool_maps; i++) {
2172 vmdq_rx_conf->pool_map[i].vlan_id = vlan_tags[i];
2173 vmdq_rx_conf->pool_map[i].pools =
2174 1 << (i % vmdq_rx_conf->nb_queue_pools);
2176 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2177 vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
2178 vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
2181 /* set DCB mode of RX and TX of multiple queues */
2182 eth_conf->rxmode.mq_mode = ETH_MQ_RX_VMDQ_DCB;
2183 eth_conf->txmode.mq_mode = ETH_MQ_TX_VMDQ_DCB;
2185 struct rte_eth_dcb_rx_conf *rx_conf =
2186 ð_conf->rx_adv_conf.dcb_rx_conf;
2187 struct rte_eth_dcb_tx_conf *tx_conf =
2188 ð_conf->tx_adv_conf.dcb_tx_conf;
2190 rx_conf->nb_tcs = num_tcs;
2191 tx_conf->nb_tcs = num_tcs;
2193 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2194 rx_conf->dcb_tc[i] = i % num_tcs;
2195 tx_conf->dcb_tc[i] = i % num_tcs;
2197 eth_conf->rxmode.mq_mode = ETH_MQ_RX_DCB_RSS;
2198 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf;
2199 eth_conf->txmode.mq_mode = ETH_MQ_TX_DCB;
2203 eth_conf->dcb_capability_en =
2204 ETH_DCB_PG_SUPPORT | ETH_DCB_PFC_SUPPORT;
2206 eth_conf->dcb_capability_en = ETH_DCB_PG_SUPPORT;
2212 init_port_dcb_config(portid_t pid,
2213 enum dcb_mode_enable dcb_mode,
2214 enum rte_eth_nb_tcs num_tcs,
2217 struct rte_eth_conf port_conf;
2218 struct rte_port *rte_port;
2222 rte_port = &ports[pid];
2224 memset(&port_conf, 0, sizeof(struct rte_eth_conf));
2225 /* Enter DCB configuration status */
2228 /*set configuration of DCB in vt mode and DCB in non-vt mode*/
2229 retval = get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en);
2232 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2235 * Write the configuration into the device.
2236 * Set the numbers of RX & TX queues to 0, so
2237 * the RX & TX queues will not be setup.
2239 rte_eth_dev_configure(pid, 0, 0, &port_conf);
2241 rte_eth_dev_info_get(pid, &rte_port->dev_info);
2243 /* If dev_info.vmdq_pool_base is greater than 0,
2244 * the queue id of vmdq pools is started after pf queues.
2246 if (dcb_mode == DCB_VT_ENABLED &&
2247 rte_port->dev_info.vmdq_pool_base > 0) {
2248 printf("VMDQ_DCB multi-queue mode is nonsensical"
2249 " for port %d.", pid);
2253 /* Assume the ports in testpmd have the same dcb capability
2254 * and has the same number of rxq and txq in dcb mode
2256 if (dcb_mode == DCB_VT_ENABLED) {
2257 if (rte_port->dev_info.max_vfs > 0) {
2258 nb_rxq = rte_port->dev_info.nb_rx_queues;
2259 nb_txq = rte_port->dev_info.nb_tx_queues;
2261 nb_rxq = rte_port->dev_info.max_rx_queues;
2262 nb_txq = rte_port->dev_info.max_tx_queues;
2265 /*if vt is disabled, use all pf queues */
2266 if (rte_port->dev_info.vmdq_pool_base == 0) {
2267 nb_rxq = rte_port->dev_info.max_rx_queues;
2268 nb_txq = rte_port->dev_info.max_tx_queues;
2270 nb_rxq = (queueid_t)num_tcs;
2271 nb_txq = (queueid_t)num_tcs;
2275 rx_free_thresh = 64;
2277 memcpy(&rte_port->dev_conf, &port_conf, sizeof(struct rte_eth_conf));
2279 rxtx_port_config(rte_port);
2281 rte_port->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2282 for (i = 0; i < RTE_DIM(vlan_tags); i++)
2283 rx_vft_set(pid, vlan_tags[i], 1);
2285 rte_eth_macaddr_get(pid, &rte_port->eth_addr);
2286 map_port_queue_stats_mapping_registers(pid, rte_port);
2288 rte_port->dcb_flag = 1;
2296 /* Configuration of Ethernet ports. */
2297 ports = rte_zmalloc("testpmd: ports",
2298 sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
2299 RTE_CACHE_LINE_SIZE);
2300 if (ports == NULL) {
2301 rte_exit(EXIT_FAILURE,
2302 "rte_zmalloc(%d struct rte_port) failed\n",
2318 const char clr[] = { 27, '[', '2', 'J', '\0' };
2319 const char top_left[] = { 27, '[', '1', ';', '1', 'H', '\0' };
2321 /* Clear screen and move to top left */
2322 printf("%s%s", clr, top_left);
2324 printf("\nPort statistics ====================================");
2325 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
2326 nic_stats_display(fwd_ports_ids[i]);
2330 signal_handler(int signum)
2332 if (signum == SIGINT || signum == SIGTERM) {
2333 printf("\nSignal %d received, preparing to exit...\n",
2335 #ifdef RTE_LIBRTE_PDUMP
2336 /* uninitialize packet capture framework */
2339 #ifdef RTE_LIBRTE_LATENCY_STATS
2340 rte_latencystats_uninit();
2343 /* Set flag to indicate the force termination. */
2345 /* exit with the expected status */
2346 signal(signum, SIG_DFL);
2347 kill(getpid(), signum);
2352 main(int argc, char** argv)
2357 signal(SIGINT, signal_handler);
2358 signal(SIGTERM, signal_handler);
2360 diag = rte_eal_init(argc, argv);
2362 rte_panic("Cannot init EAL\n");
2364 testpmd_logtype = rte_log_register("testpmd");
2365 if (testpmd_logtype < 0)
2366 rte_panic("Cannot register log type");
2367 rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
2369 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
2370 TESTPMD_LOG(NOTICE, "mlockall() failed with error \"%s\"\n",
2374 #ifdef RTE_LIBRTE_PDUMP
2375 /* initialize packet capture framework */
2376 rte_pdump_init(NULL);
2379 nb_ports = (portid_t) rte_eth_dev_count();
2381 TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
2383 /* allocate port structures, and init them */
2386 set_def_fwd_config();
2388 rte_panic("Empty set of forwarding logical cores - check the "
2389 "core mask supplied in the command parameters\n");
2391 /* Bitrate/latency stats disabled by default */
2392 #ifdef RTE_LIBRTE_BITRATE
2393 bitrate_enabled = 0;
2395 #ifdef RTE_LIBRTE_LATENCY_STATS
2396 latencystats_enabled = 0;
2402 launch_args_parse(argc, argv);
2404 if (tx_first && interactive)
2405 rte_exit(EXIT_FAILURE, "--tx-first cannot be used on "
2406 "interactive mode.\n");
2408 if (tx_first && lsc_interrupt) {
2409 printf("Warning: lsc_interrupt needs to be off when "
2410 " using tx_first. Disabling.\n");
2414 if (!nb_rxq && !nb_txq)
2415 printf("Warning: Either rx or tx queues should be non-zero\n");
2417 if (nb_rxq > 1 && nb_rxq > nb_txq)
2418 printf("Warning: nb_rxq=%d enables RSS configuration, "
2419 "but nb_txq=%d will prevent to fully test it.\n",
2423 if (start_port(RTE_PORT_ALL) != 0)
2424 rte_exit(EXIT_FAILURE, "Start ports failed\n");
2426 /* set all ports to promiscuous mode by default */
2427 RTE_ETH_FOREACH_DEV(port_id)
2428 rte_eth_promiscuous_enable(port_id);
2430 /* Init metrics library */
2431 rte_metrics_init(rte_socket_id());
2433 #ifdef RTE_LIBRTE_LATENCY_STATS
2434 if (latencystats_enabled != 0) {
2435 int ret = rte_latencystats_init(1, NULL);
2437 printf("Warning: latencystats init()"
2438 " returned error %d\n", ret);
2439 printf("Latencystats running on lcore %d\n",
2440 latencystats_lcore_id);
2444 /* Setup bitrate stats */
2445 #ifdef RTE_LIBRTE_BITRATE
2446 if (bitrate_enabled != 0) {
2447 bitrate_data = rte_stats_bitrate_create();
2448 if (bitrate_data == NULL)
2449 rte_exit(EXIT_FAILURE,
2450 "Could not allocate bitrate data.\n");
2451 rte_stats_bitrate_reg(bitrate_data);
2455 #ifdef RTE_LIBRTE_CMDLINE
2456 if (strlen(cmdline_filename) != 0)
2457 cmdline_read_from_file(cmdline_filename);
2459 if (interactive == 1) {
2461 printf("Start automatic packet forwarding\n");
2462 start_packet_forwarding(0);
2474 printf("No commandline core given, start packet forwarding\n");
2475 start_packet_forwarding(tx_first);
2476 if (stats_period != 0) {
2477 uint64_t prev_time = 0, cur_time, diff_time = 0;
2478 uint64_t timer_period;
2480 /* Convert to number of cycles */
2481 timer_period = stats_period * rte_get_timer_hz();
2483 while (f_quit == 0) {
2484 cur_time = rte_get_timer_cycles();
2485 diff_time += cur_time - prev_time;
2487 if (diff_time >= timer_period) {
2489 /* Reset the timer */
2492 /* Sleep to avoid unnecessary checks */
2493 prev_time = cur_time;
2498 printf("Press enter to exit\n");
2499 rc = read(0, &c, 1);