1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
13 #include <sys/types.h>
17 #include <sys/queue.h>
24 #include <rte_common.h>
25 #include <rte_errno.h>
26 #include <rte_byteorder.h>
28 #include <rte_debug.h>
29 #include <rte_cycles.h>
30 #include <rte_memory.h>
31 #include <rte_memcpy.h>
32 #include <rte_launch.h>
34 #include <rte_alarm.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_atomic.h>
38 #include <rte_branch_prediction.h>
39 #include <rte_mempool.h>
40 #include <rte_malloc.h>
42 #include <rte_mbuf_pool_ops.h>
43 #include <rte_interrupts.h>
45 #include <rte_ether.h>
46 #include <rte_ethdev.h>
48 #include <rte_string_fns.h>
49 #ifdef RTE_LIBRTE_IXGBE_PMD
50 #include <rte_pmd_ixgbe.h>
52 #ifdef RTE_LIBRTE_PDUMP
53 #include <rte_pdump.h>
56 #include <rte_metrics.h>
57 #ifdef RTE_LIBRTE_BITRATE
58 #include <rte_bitrate.h>
60 #ifdef RTE_LIBRTE_LATENCY_STATS
61 #include <rte_latencystats.h>
66 uint16_t verbose_level = 0; /**< Silent by default. */
67 int testpmd_logtype; /**< Log type for testpmd logs */
69 /* use master core for command line ? */
70 uint8_t interactive = 0;
71 uint8_t auto_start = 0;
73 char cmdline_filename[PATH_MAX] = {0};
76 * NUMA support configuration.
77 * When set, the NUMA support attempts to dispatch the allocation of the
78 * RX and TX memory rings, and of the DMA memory buffers (mbufs) for the
79 * probed ports among the CPU sockets 0 and 1.
80 * Otherwise, all memory is allocated from CPU socket 0.
82 uint8_t numa_support = 1; /**< numa enabled by default */
85 * In UMA mode,all memory is allocated from socket 0 if --socket-num is
88 uint8_t socket_num = UMA_NO_CONFIG;
91 * Use ANONYMOUS mapped memory (might be not physically continuous) for mbufs.
96 * Store specified sockets on which memory pool to be used by ports
99 uint8_t port_numa[RTE_MAX_ETHPORTS];
102 * Store specified sockets on which RX ring to be used by ports
105 uint8_t rxring_numa[RTE_MAX_ETHPORTS];
108 * Store specified sockets on which TX ring to be used by ports
111 uint8_t txring_numa[RTE_MAX_ETHPORTS];
114 * Record the Ethernet address of peer target ports to which packets are
116 * Must be instantiated with the ethernet addresses of peer traffic generator
119 struct ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS];
120 portid_t nb_peer_eth_addrs = 0;
123 * Probed Target Environment.
125 struct rte_port *ports; /**< For all probed ethernet ports. */
126 portid_t nb_ports; /**< Number of probed ethernet ports. */
127 struct fwd_lcore **fwd_lcores; /**< For all probed logical cores. */
128 lcoreid_t nb_lcores; /**< Number of probed logical cores. */
131 * Test Forwarding Configuration.
132 * nb_fwd_lcores <= nb_cfg_lcores <= nb_lcores
133 * nb_fwd_ports <= nb_cfg_ports <= nb_ports
135 lcoreid_t nb_cfg_lcores; /**< Number of configured logical cores. */
136 lcoreid_t nb_fwd_lcores; /**< Number of forwarding logical cores. */
137 portid_t nb_cfg_ports; /**< Number of configured ports. */
138 portid_t nb_fwd_ports; /**< Number of forwarding ports. */
140 unsigned int fwd_lcores_cpuids[RTE_MAX_LCORE]; /**< CPU ids configuration. */
141 portid_t fwd_ports_ids[RTE_MAX_ETHPORTS]; /**< Port ids configuration. */
143 struct fwd_stream **fwd_streams; /**< For each RX queue of each port. */
144 streamid_t nb_fwd_streams; /**< Is equal to (nb_ports * nb_rxq). */
147 * Forwarding engines.
149 struct fwd_engine * fwd_engines[] = {
158 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
160 &softnic_tm_bypass_engine,
162 #ifdef RTE_LIBRTE_IEEE1588
163 &ieee1588_fwd_engine,
168 struct fwd_config cur_fwd_config;
169 struct fwd_engine *cur_fwd_eng = &io_fwd_engine; /**< IO mode by default. */
170 uint32_t retry_enabled;
171 uint32_t burst_tx_delay_time = BURST_TX_WAIT_US;
172 uint32_t burst_tx_retry_num = BURST_TX_RETRIES;
174 uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */
175 uint32_t param_total_num_mbufs = 0; /**< number of mbufs in all pools - if
176 * specified on command-line. */
177 uint16_t stats_period; /**< Period to show statistics (disabled by default) */
180 * In container, it cannot terminate the process which running with 'stats-period'
181 * option. Set flag to exit stats period loop after received SIGINT/SIGTERM.
186 * Configuration of packet segments used by the "txonly" processing engine.
188 uint16_t tx_pkt_length = TXONLY_DEF_PACKET_LEN; /**< TXONLY packet length. */
189 uint16_t tx_pkt_seg_lengths[RTE_MAX_SEGS_PER_PKT] = {
190 TXONLY_DEF_PACKET_LEN,
192 uint8_t tx_pkt_nb_segs = 1; /**< Number of segments in TXONLY packets */
194 enum tx_pkt_split tx_pkt_split = TX_PKT_SPLIT_OFF;
195 /**< Split policy for packets to TX. */
197 uint16_t nb_pkt_per_burst = DEF_PKT_BURST; /**< Number of packets per burst. */
198 uint16_t mb_mempool_cache = DEF_MBUF_CACHE; /**< Size of mbuf mempool cache. */
200 /* current configuration is in DCB or not,0 means it is not in DCB mode */
201 uint8_t dcb_config = 0;
203 /* Whether the dcb is in testing status */
204 uint8_t dcb_test = 0;
207 * Configurable number of RX/TX queues.
209 queueid_t nb_rxq = 1; /**< Number of RX queues per port. */
210 queueid_t nb_txq = 1; /**< Number of TX queues per port. */
213 * Configurable number of RX/TX ring descriptors.
214 * Defaults are supplied by drivers via ethdev.
216 #define RTE_TEST_RX_DESC_DEFAULT 0
217 #define RTE_TEST_TX_DESC_DEFAULT 0
218 uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; /**< Number of RX descriptors. */
219 uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; /**< Number of TX descriptors. */
221 #define RTE_PMD_PARAM_UNSET -1
223 * Configurable values of RX and TX ring threshold registers.
226 int8_t rx_pthresh = RTE_PMD_PARAM_UNSET;
227 int8_t rx_hthresh = RTE_PMD_PARAM_UNSET;
228 int8_t rx_wthresh = RTE_PMD_PARAM_UNSET;
230 int8_t tx_pthresh = RTE_PMD_PARAM_UNSET;
231 int8_t tx_hthresh = RTE_PMD_PARAM_UNSET;
232 int8_t tx_wthresh = RTE_PMD_PARAM_UNSET;
235 * Configurable value of RX free threshold.
237 int16_t rx_free_thresh = RTE_PMD_PARAM_UNSET;
240 * Configurable value of RX drop enable.
242 int8_t rx_drop_en = RTE_PMD_PARAM_UNSET;
245 * Configurable value of TX free threshold.
247 int16_t tx_free_thresh = RTE_PMD_PARAM_UNSET;
250 * Configurable value of TX RS bit threshold.
252 int16_t tx_rs_thresh = RTE_PMD_PARAM_UNSET;
255 * Receive Side Scaling (RSS) configuration.
257 uint64_t rss_hf = ETH_RSS_IP; /* RSS IP by default. */
260 * Port topology configuration
262 uint16_t port_topology = PORT_TOPOLOGY_PAIRED; /* Ports are paired by default */
265 * Avoids to flush all the RX streams before starts forwarding.
267 uint8_t no_flush_rx = 0; /* flush by default */
270 * Flow API isolated mode.
272 uint8_t flow_isolate_all;
275 * Avoids to check link status when starting/stopping a port.
277 uint8_t no_link_check = 0; /* check by default */
280 * Enable link status change notification
282 uint8_t lsc_interrupt = 1; /* enabled by default */
285 * Enable device removal notification.
287 uint8_t rmv_interrupt = 1; /* enabled by default */
289 uint8_t hot_plug = 0; /**< hotplug disabled by default. */
292 * Display or mask ether events
293 * Default to all events except VF_MBOX
295 uint32_t event_print_mask = (UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN) |
296 (UINT32_C(1) << RTE_ETH_EVENT_INTR_LSC) |
297 (UINT32_C(1) << RTE_ETH_EVENT_QUEUE_STATE) |
298 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RESET) |
299 (UINT32_C(1) << RTE_ETH_EVENT_IPSEC) |
300 (UINT32_C(1) << RTE_ETH_EVENT_MACSEC) |
301 (UINT32_C(1) << RTE_ETH_EVENT_INTR_RMV);
303 * Decide if all memory are locked for performance.
308 * NIC bypass mode configuration options.
311 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
312 /* The NIC bypass watchdog timeout. */
313 uint32_t bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
317 #ifdef RTE_LIBRTE_LATENCY_STATS
320 * Set when latency stats is enabled in the commandline
322 uint8_t latencystats_enabled;
325 * Lcore ID to serive latency statistics.
327 lcoreid_t latencystats_lcore_id = -1;
332 * Ethernet device configuration.
334 struct rte_eth_rxmode rx_mode = {
335 .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
336 .offloads = DEV_RX_OFFLOAD_CRC_STRIP,
337 .ignore_offload_bitfield = 1,
340 struct rte_eth_txmode tx_mode = {
341 .offloads = DEV_TX_OFFLOAD_MBUF_FAST_FREE,
344 struct rte_fdir_conf fdir_conf = {
345 .mode = RTE_FDIR_MODE_NONE,
346 .pballoc = RTE_FDIR_PBALLOC_64K,
347 .status = RTE_FDIR_REPORT_STATUS,
349 .vlan_tci_mask = 0x0,
351 .src_ip = 0xFFFFFFFF,
352 .dst_ip = 0xFFFFFFFF,
355 .src_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
356 .dst_ip = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF},
358 .src_port_mask = 0xFFFF,
359 .dst_port_mask = 0xFFFF,
360 .mac_addr_byte_mask = 0xFF,
361 .tunnel_type_mask = 1,
362 .tunnel_id_mask = 0xFFFFFFFF,
367 volatile int test_done = 1; /* stop packet forwarding when set to 1. */
369 struct queue_stats_mappings tx_queue_stats_mappings_array[MAX_TX_QUEUE_STATS_MAPPINGS];
370 struct queue_stats_mappings rx_queue_stats_mappings_array[MAX_RX_QUEUE_STATS_MAPPINGS];
372 struct queue_stats_mappings *tx_queue_stats_mappings = tx_queue_stats_mappings_array;
373 struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_array;
375 uint16_t nb_tx_queue_stats_mappings = 0;
376 uint16_t nb_rx_queue_stats_mappings = 0;
379 * Display zero values by default for xstats
381 uint8_t xstats_hide_zero;
383 unsigned int num_sockets = 0;
384 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
386 #ifdef RTE_LIBRTE_BITRATE
387 /* Bitrate statistics */
388 struct rte_stats_bitrates *bitrate_data;
389 lcoreid_t bitrate_lcore_id;
390 uint8_t bitrate_enabled;
393 struct gro_status gro_ports[RTE_MAX_ETHPORTS];
394 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
396 /* Forward function declarations */
397 static void map_port_queue_stats_mapping_registers(portid_t pi,
398 struct rte_port *port);
399 static void check_all_ports_link_status(uint32_t port_mask);
400 static int eth_event_callback(portid_t port_id,
401 enum rte_eth_event_type type,
402 void *param, void *ret_param);
403 static void eth_dev_event_callback(char *device_name,
404 enum rte_dev_event_type type,
406 static int eth_dev_event_callback_register(void);
407 static int eth_dev_event_callback_unregister(void);
411 * Check if all the ports are started.
412 * If yes, return positive value. If not, return zero.
414 static int all_ports_started(void);
416 struct gso_status gso_ports[RTE_MAX_ETHPORTS];
417 uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
420 * Helper function to check if socket is already discovered.
421 * If yes, return positive value. If not, return zero.
424 new_socket_id(unsigned int socket_id)
428 for (i = 0; i < num_sockets; i++) {
429 if (socket_ids[i] == socket_id)
436 * Setup default configuration.
439 set_default_fwd_lcores_config(void)
443 unsigned int sock_num;
446 for (i = 0; i < RTE_MAX_LCORE; i++) {
447 sock_num = rte_lcore_to_socket_id(i);
448 if (new_socket_id(sock_num)) {
449 if (num_sockets >= RTE_MAX_NUMA_NODES) {
450 rte_exit(EXIT_FAILURE,
451 "Total sockets greater than %u\n",
454 socket_ids[num_sockets++] = sock_num;
456 if (!rte_lcore_is_enabled(i))
458 if (i == rte_get_master_lcore())
460 fwd_lcores_cpuids[nb_lc++] = i;
462 nb_lcores = (lcoreid_t) nb_lc;
463 nb_cfg_lcores = nb_lcores;
468 set_def_peer_eth_addrs(void)
472 for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
473 peer_eth_addrs[i].addr_bytes[0] = ETHER_LOCAL_ADMIN_ADDR;
474 peer_eth_addrs[i].addr_bytes[5] = i;
479 set_default_fwd_ports_config(void)
484 RTE_ETH_FOREACH_DEV(pt_id)
485 fwd_ports_ids[i++] = pt_id;
487 nb_cfg_ports = nb_ports;
488 nb_fwd_ports = nb_ports;
492 set_def_fwd_config(void)
494 set_default_fwd_lcores_config();
495 set_def_peer_eth_addrs();
496 set_default_fwd_ports_config();
500 * Configuration initialisation done once at init time.
503 mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
504 unsigned int socket_id)
506 char pool_name[RTE_MEMPOOL_NAMESIZE];
507 struct rte_mempool *rte_mp = NULL;
510 mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
511 mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
514 "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
515 pool_name, nb_mbuf, mbuf_seg_size, socket_id);
518 rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf,
519 mb_size, (unsigned) mb_mempool_cache,
520 sizeof(struct rte_pktmbuf_pool_private),
525 if (rte_mempool_populate_anon(rte_mp) == 0) {
526 rte_mempool_free(rte_mp);
530 rte_pktmbuf_pool_init(rte_mp, NULL);
531 rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL);
533 /* wrapper to rte_mempool_create() */
534 TESTPMD_LOG(INFO, "preferred mempool ops selected: %s\n",
535 rte_mbuf_best_mempool_ops());
536 rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf,
537 mb_mempool_cache, 0, mbuf_seg_size, socket_id);
541 if (rte_mp == NULL) {
542 rte_exit(EXIT_FAILURE,
543 "Creation of mbuf pool for socket %u failed: %s\n",
544 socket_id, rte_strerror(rte_errno));
545 } else if (verbose_level > 0) {
546 rte_mempool_dump(stdout, rte_mp);
551 * Check given socket id is valid or not with NUMA mode,
552 * if valid, return 0, else return -1
555 check_socket_id(const unsigned int socket_id)
557 static int warning_once = 0;
559 if (new_socket_id(socket_id)) {
560 if (!warning_once && numa_support)
561 printf("Warning: NUMA should be configured manually by"
562 " using --port-numa-config and"
563 " --ring-numa-config parameters along with"
572 * Get the allowed maximum number of RX queues.
573 * *pid return the port id which has minimal value of
574 * max_rx_queues in all ports.
577 get_allowed_max_nb_rxq(portid_t *pid)
579 queueid_t allowed_max_rxq = MAX_QUEUE_ID;
581 struct rte_eth_dev_info dev_info;
583 RTE_ETH_FOREACH_DEV(pi) {
584 rte_eth_dev_info_get(pi, &dev_info);
585 if (dev_info.max_rx_queues < allowed_max_rxq) {
586 allowed_max_rxq = dev_info.max_rx_queues;
590 return allowed_max_rxq;
594 * Check input rxq is valid or not.
595 * If input rxq is not greater than any of maximum number
596 * of RX queues of all ports, it is valid.
597 * if valid, return 0, else return -1
600 check_nb_rxq(queueid_t rxq)
602 queueid_t allowed_max_rxq;
605 allowed_max_rxq = get_allowed_max_nb_rxq(&pid);
606 if (rxq > allowed_max_rxq) {
607 printf("Fail: input rxq (%u) can't be greater "
608 "than max_rx_queues (%u) of port %u\n",
618 * Get the allowed maximum number of TX queues.
619 * *pid return the port id which has minimal value of
620 * max_tx_queues in all ports.
623 get_allowed_max_nb_txq(portid_t *pid)
625 queueid_t allowed_max_txq = MAX_QUEUE_ID;
627 struct rte_eth_dev_info dev_info;
629 RTE_ETH_FOREACH_DEV(pi) {
630 rte_eth_dev_info_get(pi, &dev_info);
631 if (dev_info.max_tx_queues < allowed_max_txq) {
632 allowed_max_txq = dev_info.max_tx_queues;
636 return allowed_max_txq;
640 * Check input txq is valid or not.
641 * If input txq is not greater than any of maximum number
642 * of TX queues of all ports, it is valid.
643 * if valid, return 0, else return -1
646 check_nb_txq(queueid_t txq)
648 queueid_t allowed_max_txq;
651 allowed_max_txq = get_allowed_max_nb_txq(&pid);
652 if (txq > allowed_max_txq) {
653 printf("Fail: input txq (%u) can't be greater "
654 "than max_tx_queues (%u) of port %u\n",
667 struct rte_port *port;
668 struct rte_mempool *mbp;
669 unsigned int nb_mbuf_per_pool;
671 uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
672 struct rte_gro_param gro_param;
676 memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
679 memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
680 memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
681 memset(txring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
684 /* Configuration of logical cores. */
685 fwd_lcores = rte_zmalloc("testpmd: fwd_lcores",
686 sizeof(struct fwd_lcore *) * nb_lcores,
687 RTE_CACHE_LINE_SIZE);
688 if (fwd_lcores == NULL) {
689 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d (struct fwd_lcore *)) "
690 "failed\n", nb_lcores);
692 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
693 fwd_lcores[lc_id] = rte_zmalloc("testpmd: struct fwd_lcore",
694 sizeof(struct fwd_lcore),
695 RTE_CACHE_LINE_SIZE);
696 if (fwd_lcores[lc_id] == NULL) {
697 rte_exit(EXIT_FAILURE, "rte_zmalloc(struct fwd_lcore) "
700 fwd_lcores[lc_id]->cpuid_idx = lc_id;
703 RTE_ETH_FOREACH_DEV(pid) {
705 /* Apply default TxRx configuration for all ports */
706 port->dev_conf.txmode = tx_mode;
707 port->dev_conf.rxmode = rx_mode;
708 rte_eth_dev_info_get(pid, &port->dev_info);
710 if (!(port->dev_info.rx_offload_capa &
711 DEV_RX_OFFLOAD_CRC_STRIP))
712 port->dev_conf.rxmode.offloads &=
713 ~DEV_RX_OFFLOAD_CRC_STRIP;
714 if (!(port->dev_info.tx_offload_capa &
715 DEV_TX_OFFLOAD_MBUF_FAST_FREE))
716 port->dev_conf.txmode.offloads &=
717 ~DEV_TX_OFFLOAD_MBUF_FAST_FREE;
719 if (port_numa[pid] != NUMA_NO_CONFIG)
720 port_per_socket[port_numa[pid]]++;
722 uint32_t socket_id = rte_eth_dev_socket_id(pid);
724 /* if socket_id is invalid, set to 0 */
725 if (check_socket_id(socket_id) < 0)
727 port_per_socket[socket_id]++;
731 /* Apply Rx offloads configuration */
732 for (k = 0; k < port->dev_info.max_rx_queues; k++)
733 port->rx_conf[k].offloads =
734 port->dev_conf.rxmode.offloads;
735 /* Apply Tx offloads configuration */
736 for (k = 0; k < port->dev_info.max_tx_queues; k++)
737 port->tx_conf[k].offloads =
738 port->dev_conf.txmode.offloads;
740 /* set flag to initialize port/queue */
741 port->need_reconfig = 1;
742 port->need_reconfig_queues = 1;
746 * Create pools of mbuf.
747 * If NUMA support is disabled, create a single pool of mbuf in
748 * socket 0 memory by default.
749 * Otherwise, create a pool of mbuf in the memory of sockets 0 and 1.
751 * Use the maximum value of nb_rxd and nb_txd here, then nb_rxd and
752 * nb_txd can be configured at run time.
754 if (param_total_num_mbufs)
755 nb_mbuf_per_pool = param_total_num_mbufs;
757 nb_mbuf_per_pool = RTE_TEST_RX_DESC_MAX +
758 (nb_lcores * mb_mempool_cache) +
759 RTE_TEST_TX_DESC_MAX + MAX_PKT_BURST;
760 nb_mbuf_per_pool *= RTE_MAX_ETHPORTS;
766 for (i = 0; i < num_sockets; i++)
767 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
770 if (socket_num == UMA_NO_CONFIG)
771 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool, 0);
773 mbuf_pool_create(mbuf_data_size, nb_mbuf_per_pool,
779 gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
780 DEV_TX_OFFLOAD_GRE_TNL_TSO;
782 * Records which Mbuf pool to use by each logical core, if needed.
784 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
785 mbp = mbuf_pool_find(
786 rte_lcore_to_socket_id(fwd_lcores_cpuids[lc_id]));
789 mbp = mbuf_pool_find(0);
790 fwd_lcores[lc_id]->mbp = mbp;
791 /* initialize GSO context */
792 fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
793 fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
794 fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
795 fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
797 fwd_lcores[lc_id]->gso_ctx.flag = 0;
800 /* Configuration of packet forwarding streams. */
801 if (init_fwd_streams() < 0)
802 rte_exit(EXIT_FAILURE, "FAIL from init_fwd_streams()\n");
806 /* create a gro context for each lcore */
807 gro_param.gro_types = RTE_GRO_TCP_IPV4;
808 gro_param.max_flow_num = GRO_MAX_FLUSH_CYCLES;
809 gro_param.max_item_per_flow = MAX_PKT_BURST;
810 for (lc_id = 0; lc_id < nb_lcores; lc_id++) {
811 gro_param.socket_id = rte_lcore_to_socket_id(
812 fwd_lcores_cpuids[lc_id]);
813 fwd_lcores[lc_id]->gro_ctx = rte_gro_ctx_create(&gro_param);
814 if (fwd_lcores[lc_id]->gro_ctx == NULL) {
815 rte_exit(EXIT_FAILURE,
816 "rte_gro_ctx_create() failed\n");
823 reconfig(portid_t new_port_id, unsigned socket_id)
825 struct rte_port *port;
827 /* Reconfiguration of Ethernet ports. */
828 port = &ports[new_port_id];
829 rte_eth_dev_info_get(new_port_id, &port->dev_info);
831 /* set flag to initialize port/queue */
832 port->need_reconfig = 1;
833 port->need_reconfig_queues = 1;
834 port->socket_id = socket_id;
841 init_fwd_streams(void)
844 struct rte_port *port;
845 streamid_t sm_id, nb_fwd_streams_new;
848 /* set socket id according to numa or not */
849 RTE_ETH_FOREACH_DEV(pid) {
851 if (nb_rxq > port->dev_info.max_rx_queues) {
852 printf("Fail: nb_rxq(%d) is greater than "
853 "max_rx_queues(%d)\n", nb_rxq,
854 port->dev_info.max_rx_queues);
857 if (nb_txq > port->dev_info.max_tx_queues) {
858 printf("Fail: nb_txq(%d) is greater than "
859 "max_tx_queues(%d)\n", nb_txq,
860 port->dev_info.max_tx_queues);
864 if (port_numa[pid] != NUMA_NO_CONFIG)
865 port->socket_id = port_numa[pid];
867 port->socket_id = rte_eth_dev_socket_id(pid);
869 /* if socket_id is invalid, set to 0 */
870 if (check_socket_id(port->socket_id) < 0)
875 if (socket_num == UMA_NO_CONFIG)
878 port->socket_id = socket_num;
882 q = RTE_MAX(nb_rxq, nb_txq);
884 printf("Fail: Cannot allocate fwd streams as number of queues is 0\n");
887 nb_fwd_streams_new = (streamid_t)(nb_ports * q);
888 if (nb_fwd_streams_new == nb_fwd_streams)
891 if (fwd_streams != NULL) {
892 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
893 if (fwd_streams[sm_id] == NULL)
895 rte_free(fwd_streams[sm_id]);
896 fwd_streams[sm_id] = NULL;
898 rte_free(fwd_streams);
903 nb_fwd_streams = nb_fwd_streams_new;
904 if (nb_fwd_streams) {
905 fwd_streams = rte_zmalloc("testpmd: fwd_streams",
906 sizeof(struct fwd_stream *) * nb_fwd_streams,
907 RTE_CACHE_LINE_SIZE);
908 if (fwd_streams == NULL)
909 rte_exit(EXIT_FAILURE, "rte_zmalloc(%d"
910 " (struct fwd_stream *)) failed\n",
913 for (sm_id = 0; sm_id < nb_fwd_streams; sm_id++) {
914 fwd_streams[sm_id] = rte_zmalloc("testpmd:"
915 " struct fwd_stream", sizeof(struct fwd_stream),
916 RTE_CACHE_LINE_SIZE);
917 if (fwd_streams[sm_id] == NULL)
918 rte_exit(EXIT_FAILURE, "rte_zmalloc"
919 "(struct fwd_stream) failed\n");
926 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
928 pkt_burst_stats_display(const char *rx_tx, struct pkt_burst_stats *pbs)
930 unsigned int total_burst;
931 unsigned int nb_burst;
932 unsigned int burst_stats[3];
933 uint16_t pktnb_stats[3];
935 int burst_percent[3];
938 * First compute the total number of packet bursts and the
939 * two highest numbers of bursts of the same number of packets.
942 burst_stats[0] = burst_stats[1] = burst_stats[2] = 0;
943 pktnb_stats[0] = pktnb_stats[1] = pktnb_stats[2] = 0;
944 for (nb_pkt = 0; nb_pkt < MAX_PKT_BURST; nb_pkt++) {
945 nb_burst = pbs->pkt_burst_spread[nb_pkt];
948 total_burst += nb_burst;
949 if (nb_burst > burst_stats[0]) {
950 burst_stats[1] = burst_stats[0];
951 pktnb_stats[1] = pktnb_stats[0];
952 burst_stats[0] = nb_burst;
953 pktnb_stats[0] = nb_pkt;
956 if (total_burst == 0)
958 burst_percent[0] = (burst_stats[0] * 100) / total_burst;
959 printf(" %s-bursts : %u [%d%% of %d pkts", rx_tx, total_burst,
960 burst_percent[0], (int) pktnb_stats[0]);
961 if (burst_stats[0] == total_burst) {
965 if (burst_stats[0] + burst_stats[1] == total_burst) {
966 printf(" + %d%% of %d pkts]\n",
967 100 - burst_percent[0], pktnb_stats[1]);
970 burst_percent[1] = (burst_stats[1] * 100) / total_burst;
971 burst_percent[2] = 100 - (burst_percent[0] + burst_percent[1]);
972 if ((burst_percent[1] == 0) || (burst_percent[2] == 0)) {
973 printf(" + %d%% of others]\n", 100 - burst_percent[0]);
976 printf(" + %d%% of %d pkts + %d%% of others]\n",
977 burst_percent[1], (int) pktnb_stats[1], burst_percent[2]);
979 #endif /* RTE_TEST_PMD_RECORD_BURST_STATS */
982 fwd_port_stats_display(portid_t port_id, struct rte_eth_stats *stats)
984 struct rte_port *port;
987 static const char *fwd_stats_border = "----------------------";
989 port = &ports[port_id];
990 printf("\n %s Forward statistics for port %-2d %s\n",
991 fwd_stats_border, port_id, fwd_stats_border);
993 if ((!port->rx_queue_stats_mapping_enabled) && (!port->tx_queue_stats_mapping_enabled)) {
994 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
996 stats->ipackets, stats->imissed,
997 (uint64_t) (stats->ipackets + stats->imissed));
999 if (cur_fwd_eng == &csum_fwd_engine)
1000 printf(" Bad-ipcsum: %-14"PRIu64" Bad-l4csum: %-14"PRIu64" \n",
1001 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
1002 if ((stats->ierrors + stats->rx_nombuf) > 0) {
1003 printf(" RX-error: %-"PRIu64"\n", stats->ierrors);
1004 printf(" RX-nombufs: %-14"PRIu64"\n", stats->rx_nombuf);
1007 printf(" TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
1009 stats->opackets, port->tx_dropped,
1010 (uint64_t) (stats->opackets + port->tx_dropped));
1013 printf(" RX-packets: %14"PRIu64" RX-dropped:%14"PRIu64" RX-total:"
1015 stats->ipackets, stats->imissed,
1016 (uint64_t) (stats->ipackets + stats->imissed));
1018 if (cur_fwd_eng == &csum_fwd_engine)
1019 printf(" Bad-ipcsum:%14"PRIu64" Bad-l4csum:%14"PRIu64"\n",
1020 port->rx_bad_ip_csum, port->rx_bad_l4_csum);
1021 if ((stats->ierrors + stats->rx_nombuf) > 0) {
1022 printf(" RX-error:%"PRIu64"\n", stats->ierrors);
1023 printf(" RX-nombufs: %14"PRIu64"\n",
1027 printf(" TX-packets: %14"PRIu64" TX-dropped:%14"PRIu64" TX-total:"
1029 stats->opackets, port->tx_dropped,
1030 (uint64_t) (stats->opackets + port->tx_dropped));
1033 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1034 if (port->rx_stream)
1035 pkt_burst_stats_display("RX",
1036 &port->rx_stream->rx_burst_stats);
1037 if (port->tx_stream)
1038 pkt_burst_stats_display("TX",
1039 &port->tx_stream->tx_burst_stats);
1042 if (port->rx_queue_stats_mapping_enabled) {
1044 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
1045 printf(" Stats reg %2d RX-packets:%14"PRIu64
1046 " RX-errors:%14"PRIu64
1047 " RX-bytes:%14"PRIu64"\n",
1048 i, stats->q_ipackets[i], stats->q_errors[i], stats->q_ibytes[i]);
1052 if (port->tx_queue_stats_mapping_enabled) {
1053 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
1054 printf(" Stats reg %2d TX-packets:%14"PRIu64
1055 " TX-bytes:%14"PRIu64"\n",
1056 i, stats->q_opackets[i], stats->q_obytes[i]);
1060 printf(" %s--------------------------------%s\n",
1061 fwd_stats_border, fwd_stats_border);
1065 fwd_stream_stats_display(streamid_t stream_id)
1067 struct fwd_stream *fs;
1068 static const char *fwd_top_stats_border = "-------";
1070 fs = fwd_streams[stream_id];
1071 if ((fs->rx_packets == 0) && (fs->tx_packets == 0) &&
1072 (fs->fwd_dropped == 0))
1074 printf("\n %s Forward Stats for RX Port=%2d/Queue=%2d -> "
1075 "TX Port=%2d/Queue=%2d %s\n",
1076 fwd_top_stats_border, fs->rx_port, fs->rx_queue,
1077 fs->tx_port, fs->tx_queue, fwd_top_stats_border);
1078 printf(" RX-packets: %-14u TX-packets: %-14u TX-dropped: %-14u",
1079 fs->rx_packets, fs->tx_packets, fs->fwd_dropped);
1081 /* if checksum mode */
1082 if (cur_fwd_eng == &csum_fwd_engine) {
1083 printf(" RX- bad IP checksum: %-14u Rx- bad L4 checksum: "
1084 "%-14u\n", fs->rx_bad_ip_csum, fs->rx_bad_l4_csum);
1087 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1088 pkt_burst_stats_display("RX", &fs->rx_burst_stats);
1089 pkt_burst_stats_display("TX", &fs->tx_burst_stats);
1094 flush_fwd_rx_queues(void)
1096 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
1103 uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
1104 uint64_t timer_period;
1106 /* convert to number of cycles */
1107 timer_period = rte_get_timer_hz(); /* 1 second timeout */
1109 for (j = 0; j < 2; j++) {
1110 for (rxp = 0; rxp < cur_fwd_config.nb_fwd_ports; rxp++) {
1111 for (rxq = 0; rxq < nb_rxq; rxq++) {
1112 port_id = fwd_ports_ids[rxp];
1114 * testpmd can stuck in the below do while loop
1115 * if rte_eth_rx_burst() always returns nonzero
1116 * packets. So timer is added to exit this loop
1117 * after 1sec timer expiry.
1119 prev_tsc = rte_rdtsc();
1121 nb_rx = rte_eth_rx_burst(port_id, rxq,
1122 pkts_burst, MAX_PKT_BURST);
1123 for (i = 0; i < nb_rx; i++)
1124 rte_pktmbuf_free(pkts_burst[i]);
1126 cur_tsc = rte_rdtsc();
1127 diff_tsc = cur_tsc - prev_tsc;
1128 timer_tsc += diff_tsc;
1129 } while ((nb_rx > 0) &&
1130 (timer_tsc < timer_period));
1134 rte_delay_ms(10); /* wait 10 milli-seconds before retrying */
1139 run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
1141 struct fwd_stream **fsm;
1144 #ifdef RTE_LIBRTE_BITRATE
1145 uint64_t tics_per_1sec;
1146 uint64_t tics_datum;
1147 uint64_t tics_current;
1150 tics_datum = rte_rdtsc();
1151 tics_per_1sec = rte_get_timer_hz();
1153 fsm = &fwd_streams[fc->stream_idx];
1154 nb_fs = fc->stream_nb;
1156 for (sm_id = 0; sm_id < nb_fs; sm_id++)
1157 (*pkt_fwd)(fsm[sm_id]);
1158 #ifdef RTE_LIBRTE_BITRATE
1159 if (bitrate_enabled != 0 &&
1160 bitrate_lcore_id == rte_lcore_id()) {
1161 tics_current = rte_rdtsc();
1162 if (tics_current - tics_datum >= tics_per_1sec) {
1163 /* Periodic bitrate calculation */
1164 RTE_ETH_FOREACH_DEV(idx_port)
1165 rte_stats_bitrate_calc(bitrate_data,
1167 tics_datum = tics_current;
1171 #ifdef RTE_LIBRTE_LATENCY_STATS
1172 if (latencystats_enabled != 0 &&
1173 latencystats_lcore_id == rte_lcore_id())
1174 rte_latencystats_update();
1177 } while (! fc->stopped);
1181 start_pkt_forward_on_core(void *fwd_arg)
1183 run_pkt_fwd_on_lcore((struct fwd_lcore *) fwd_arg,
1184 cur_fwd_config.fwd_eng->packet_fwd);
1189 * Run the TXONLY packet forwarding engine to send a single burst of packets.
1190 * Used to start communication flows in network loopback test configurations.
1193 run_one_txonly_burst_on_core(void *fwd_arg)
1195 struct fwd_lcore *fwd_lc;
1196 struct fwd_lcore tmp_lcore;
1198 fwd_lc = (struct fwd_lcore *) fwd_arg;
1199 tmp_lcore = *fwd_lc;
1200 tmp_lcore.stopped = 1;
1201 run_pkt_fwd_on_lcore(&tmp_lcore, tx_only_engine.packet_fwd);
1206 * Launch packet forwarding:
1207 * - Setup per-port forwarding context.
1208 * - launch logical cores with their forwarding configuration.
1211 launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
1213 port_fwd_begin_t port_fwd_begin;
1218 port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
1219 if (port_fwd_begin != NULL) {
1220 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1221 (*port_fwd_begin)(fwd_ports_ids[i]);
1223 for (i = 0; i < cur_fwd_config.nb_fwd_lcores; i++) {
1224 lc_id = fwd_lcores_cpuids[i];
1225 if ((interactive == 0) || (lc_id != rte_lcore_id())) {
1226 fwd_lcores[i]->stopped = 0;
1227 diag = rte_eal_remote_launch(pkt_fwd_on_lcore,
1228 fwd_lcores[i], lc_id);
1230 printf("launch lcore %u failed - diag=%d\n",
1237 * Update the forward ports list.
1240 update_fwd_ports(portid_t new_pid)
1243 unsigned int new_nb_fwd_ports = 0;
1246 for (i = 0; i < nb_fwd_ports; ++i) {
1247 if (port_id_is_invalid(fwd_ports_ids[i], DISABLED_WARN))
1250 fwd_ports_ids[new_nb_fwd_ports++] = fwd_ports_ids[i];
1254 if (new_pid < RTE_MAX_ETHPORTS)
1255 fwd_ports_ids[new_nb_fwd_ports++] = new_pid;
1257 nb_fwd_ports = new_nb_fwd_ports;
1258 nb_cfg_ports = new_nb_fwd_ports;
1262 * Launch packet forwarding configuration.
1265 start_packet_forwarding(int with_tx_first)
1267 port_fwd_begin_t port_fwd_begin;
1268 port_fwd_end_t port_fwd_end;
1269 struct rte_port *port;
1274 if (strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") == 0 && !nb_rxq)
1275 rte_exit(EXIT_FAILURE, "rxq are 0, cannot use rxonly fwd mode\n");
1277 if (strcmp(cur_fwd_eng->fwd_mode_name, "txonly") == 0 && !nb_txq)
1278 rte_exit(EXIT_FAILURE, "txq are 0, cannot use txonly fwd mode\n");
1280 if ((strcmp(cur_fwd_eng->fwd_mode_name, "rxonly") != 0 &&
1281 strcmp(cur_fwd_eng->fwd_mode_name, "txonly") != 0) &&
1282 (!nb_rxq || !nb_txq))
1283 rte_exit(EXIT_FAILURE,
1284 "Either rxq or txq are 0, cannot use %s fwd mode\n",
1285 cur_fwd_eng->fwd_mode_name);
1287 if (all_ports_started() == 0) {
1288 printf("Not all ports were started\n");
1291 if (test_done == 0) {
1292 printf("Packet forwarding already started\n");
1298 for (i = 0; i < nb_fwd_ports; i++) {
1299 pt_id = fwd_ports_ids[i];
1300 port = &ports[pt_id];
1301 if (!port->dcb_flag) {
1302 printf("In DCB mode, all forwarding ports must "
1303 "be configured in this mode.\n");
1307 if (nb_fwd_lcores == 1) {
1308 printf("In DCB mode,the nb forwarding cores "
1309 "should be larger than 1.\n");
1318 flush_fwd_rx_queues();
1320 pkt_fwd_config_display(&cur_fwd_config);
1321 rxtx_config_display();
1323 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1324 pt_id = fwd_ports_ids[i];
1325 port = &ports[pt_id];
1326 rte_eth_stats_get(pt_id, &port->stats);
1327 port->tx_dropped = 0;
1329 map_port_queue_stats_mapping_registers(pt_id, port);
1331 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1332 fwd_streams[sm_id]->rx_packets = 0;
1333 fwd_streams[sm_id]->tx_packets = 0;
1334 fwd_streams[sm_id]->fwd_dropped = 0;
1335 fwd_streams[sm_id]->rx_bad_ip_csum = 0;
1336 fwd_streams[sm_id]->rx_bad_l4_csum = 0;
1338 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
1339 memset(&fwd_streams[sm_id]->rx_burst_stats, 0,
1340 sizeof(fwd_streams[sm_id]->rx_burst_stats));
1341 memset(&fwd_streams[sm_id]->tx_burst_stats, 0,
1342 sizeof(fwd_streams[sm_id]->tx_burst_stats));
1344 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1345 fwd_streams[sm_id]->core_cycles = 0;
1348 if (with_tx_first) {
1349 port_fwd_begin = tx_only_engine.port_fwd_begin;
1350 if (port_fwd_begin != NULL) {
1351 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1352 (*port_fwd_begin)(fwd_ports_ids[i]);
1354 while (with_tx_first--) {
1355 launch_packet_forwarding(
1356 run_one_txonly_burst_on_core);
1357 rte_eal_mp_wait_lcore();
1359 port_fwd_end = tx_only_engine.port_fwd_end;
1360 if (port_fwd_end != NULL) {
1361 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
1362 (*port_fwd_end)(fwd_ports_ids[i]);
1365 launch_packet_forwarding(start_pkt_forward_on_core);
1369 stop_packet_forwarding(void)
1371 struct rte_eth_stats stats;
1372 struct rte_port *port;
1373 port_fwd_end_t port_fwd_end;
1378 uint64_t total_recv;
1379 uint64_t total_xmit;
1380 uint64_t total_rx_dropped;
1381 uint64_t total_tx_dropped;
1382 uint64_t total_rx_nombuf;
1383 uint64_t tx_dropped;
1384 uint64_t rx_bad_ip_csum;
1385 uint64_t rx_bad_l4_csum;
1386 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1387 uint64_t fwd_cycles;
1390 static const char *acc_stats_border = "+++++++++++++++";
1393 printf("Packet forwarding not started\n");
1396 printf("Telling cores to stop...");
1397 for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++)
1398 fwd_lcores[lc_id]->stopped = 1;
1399 printf("\nWaiting for lcores to finish...\n");
1400 rte_eal_mp_wait_lcore();
1401 port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end;
1402 if (port_fwd_end != NULL) {
1403 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1404 pt_id = fwd_ports_ids[i];
1405 (*port_fwd_end)(pt_id);
1408 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1411 for (sm_id = 0; sm_id < cur_fwd_config.nb_fwd_streams; sm_id++) {
1412 if (cur_fwd_config.nb_fwd_streams >
1413 cur_fwd_config.nb_fwd_ports) {
1414 fwd_stream_stats_display(sm_id);
1415 ports[fwd_streams[sm_id]->tx_port].tx_stream = NULL;
1416 ports[fwd_streams[sm_id]->rx_port].rx_stream = NULL;
1418 ports[fwd_streams[sm_id]->tx_port].tx_stream =
1420 ports[fwd_streams[sm_id]->rx_port].rx_stream =
1423 tx_dropped = ports[fwd_streams[sm_id]->tx_port].tx_dropped;
1424 tx_dropped = (uint64_t) (tx_dropped +
1425 fwd_streams[sm_id]->fwd_dropped);
1426 ports[fwd_streams[sm_id]->tx_port].tx_dropped = tx_dropped;
1429 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum;
1430 rx_bad_ip_csum = (uint64_t) (rx_bad_ip_csum +
1431 fwd_streams[sm_id]->rx_bad_ip_csum);
1432 ports[fwd_streams[sm_id]->rx_port].rx_bad_ip_csum =
1436 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum;
1437 rx_bad_l4_csum = (uint64_t) (rx_bad_l4_csum +
1438 fwd_streams[sm_id]->rx_bad_l4_csum);
1439 ports[fwd_streams[sm_id]->rx_port].rx_bad_l4_csum =
1442 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1443 fwd_cycles = (uint64_t) (fwd_cycles +
1444 fwd_streams[sm_id]->core_cycles);
1449 total_rx_dropped = 0;
1450 total_tx_dropped = 0;
1451 total_rx_nombuf = 0;
1452 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
1453 pt_id = fwd_ports_ids[i];
1455 port = &ports[pt_id];
1456 rte_eth_stats_get(pt_id, &stats);
1457 stats.ipackets -= port->stats.ipackets;
1458 port->stats.ipackets = 0;
1459 stats.opackets -= port->stats.opackets;
1460 port->stats.opackets = 0;
1461 stats.ibytes -= port->stats.ibytes;
1462 port->stats.ibytes = 0;
1463 stats.obytes -= port->stats.obytes;
1464 port->stats.obytes = 0;
1465 stats.imissed -= port->stats.imissed;
1466 port->stats.imissed = 0;
1467 stats.oerrors -= port->stats.oerrors;
1468 port->stats.oerrors = 0;
1469 stats.rx_nombuf -= port->stats.rx_nombuf;
1470 port->stats.rx_nombuf = 0;
1472 total_recv += stats.ipackets;
1473 total_xmit += stats.opackets;
1474 total_rx_dropped += stats.imissed;
1475 total_tx_dropped += port->tx_dropped;
1476 total_rx_nombuf += stats.rx_nombuf;
1478 fwd_port_stats_display(pt_id, &stats);
1481 printf("\n %s Accumulated forward statistics for all ports"
1483 acc_stats_border, acc_stats_border);
1484 printf(" RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64"RX-total: "
1486 " TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64"TX-total: "
1488 total_recv, total_rx_dropped, total_recv + total_rx_dropped,
1489 total_xmit, total_tx_dropped, total_xmit + total_tx_dropped);
1490 if (total_rx_nombuf > 0)
1491 printf(" RX-nombufs: %-14"PRIu64"\n", total_rx_nombuf);
1492 printf(" %s++++++++++++++++++++++++++++++++++++++++++++++"
1494 acc_stats_border, acc_stats_border);
1495 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
1497 printf("\n CPU cycles/packet=%u (total cycles="
1498 "%"PRIu64" / total RX packets=%"PRIu64")\n",
1499 (unsigned int)(fwd_cycles / total_recv),
1500 fwd_cycles, total_recv);
1502 printf("\nDone.\n");
1507 dev_set_link_up(portid_t pid)
1509 if (rte_eth_dev_set_link_up(pid) < 0)
1510 printf("\nSet link up fail.\n");
1514 dev_set_link_down(portid_t pid)
1516 if (rte_eth_dev_set_link_down(pid) < 0)
1517 printf("\nSet link down fail.\n");
1521 all_ports_started(void)
1524 struct rte_port *port;
1526 RTE_ETH_FOREACH_DEV(pi) {
1528 /* Check if there is a port which is not started */
1529 if ((port->port_status != RTE_PORT_STARTED) &&
1530 (port->slave_flag == 0))
1534 /* No port is not started */
1539 port_is_stopped(portid_t port_id)
1541 struct rte_port *port = &ports[port_id];
1543 if ((port->port_status != RTE_PORT_STOPPED) &&
1544 (port->slave_flag == 0))
1550 all_ports_stopped(void)
1554 RTE_ETH_FOREACH_DEV(pi) {
1555 if (!port_is_stopped(pi))
1563 port_is_started(portid_t port_id)
1565 if (port_id_is_invalid(port_id, ENABLED_WARN))
1568 if (ports[port_id].port_status != RTE_PORT_STARTED)
1575 port_is_closed(portid_t port_id)
1577 if (port_id_is_invalid(port_id, ENABLED_WARN))
1580 if (ports[port_id].port_status != RTE_PORT_CLOSED)
1587 start_port(portid_t pid)
1589 int diag, need_check_link_status = -1;
1592 struct rte_port *port;
1593 struct ether_addr mac_addr;
1594 enum rte_eth_event_type event_type;
1596 if (port_id_is_invalid(pid, ENABLED_WARN))
1601 RTE_ETH_FOREACH_DEV(pi) {
1602 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1605 need_check_link_status = 0;
1607 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STOPPED,
1608 RTE_PORT_HANDLING) == 0) {
1609 printf("Port %d is now not stopped\n", pi);
1613 if (port->need_reconfig > 0) {
1614 port->need_reconfig = 0;
1616 if (flow_isolate_all) {
1617 int ret = port_flow_isolate(pi, 1);
1619 printf("Failed to apply isolated"
1620 " mode on port %d\n", pi);
1625 printf("Configuring Port %d (socket %u)\n", pi,
1627 /* configure port */
1628 diag = rte_eth_dev_configure(pi, nb_rxq, nb_txq,
1631 if (rte_atomic16_cmpset(&(port->port_status),
1632 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1633 printf("Port %d can not be set back "
1634 "to stopped\n", pi);
1635 printf("Fail to configure port %d\n", pi);
1636 /* try to reconfigure port next time */
1637 port->need_reconfig = 1;
1641 if (port->need_reconfig_queues > 0) {
1642 port->need_reconfig_queues = 0;
1643 /* setup tx queues */
1644 for (qi = 0; qi < nb_txq; qi++) {
1645 port->tx_conf[qi].txq_flags =
1646 ETH_TXQ_FLAGS_IGNORE;
1647 if ((numa_support) &&
1648 (txring_numa[pi] != NUMA_NO_CONFIG))
1649 diag = rte_eth_tx_queue_setup(pi, qi,
1650 port->nb_tx_desc[qi],
1652 &(port->tx_conf[qi]));
1654 diag = rte_eth_tx_queue_setup(pi, qi,
1655 port->nb_tx_desc[qi],
1657 &(port->tx_conf[qi]));
1662 /* Fail to setup tx queue, return */
1663 if (rte_atomic16_cmpset(&(port->port_status),
1665 RTE_PORT_STOPPED) == 0)
1666 printf("Port %d can not be set back "
1667 "to stopped\n", pi);
1668 printf("Fail to configure port %d tx queues\n",
1670 /* try to reconfigure queues next time */
1671 port->need_reconfig_queues = 1;
1674 for (qi = 0; qi < nb_rxq; qi++) {
1675 /* setup rx queues */
1676 if ((numa_support) &&
1677 (rxring_numa[pi] != NUMA_NO_CONFIG)) {
1678 struct rte_mempool * mp =
1679 mbuf_pool_find(rxring_numa[pi]);
1681 printf("Failed to setup RX queue:"
1682 "No mempool allocation"
1683 " on the socket %d\n",
1688 diag = rte_eth_rx_queue_setup(pi, qi,
1689 port->nb_rx_desc[pi],
1691 &(port->rx_conf[qi]),
1694 struct rte_mempool *mp =
1695 mbuf_pool_find(port->socket_id);
1697 printf("Failed to setup RX queue:"
1698 "No mempool allocation"
1699 " on the socket %d\n",
1703 diag = rte_eth_rx_queue_setup(pi, qi,
1704 port->nb_rx_desc[pi],
1706 &(port->rx_conf[qi]),
1712 /* Fail to setup rx queue, return */
1713 if (rte_atomic16_cmpset(&(port->port_status),
1715 RTE_PORT_STOPPED) == 0)
1716 printf("Port %d can not be set back "
1717 "to stopped\n", pi);
1718 printf("Fail to configure port %d rx queues\n",
1720 /* try to reconfigure queues next time */
1721 port->need_reconfig_queues = 1;
1727 if (rte_eth_dev_start(pi) < 0) {
1728 printf("Fail to start port %d\n", pi);
1730 /* Fail to setup rx queue, return */
1731 if (rte_atomic16_cmpset(&(port->port_status),
1732 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1733 printf("Port %d can not be set back to "
1738 if (rte_atomic16_cmpset(&(port->port_status),
1739 RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0)
1740 printf("Port %d can not be set into started\n", pi);
1742 rte_eth_macaddr_get(pi, &mac_addr);
1743 printf("Port %d: %02X:%02X:%02X:%02X:%02X:%02X\n", pi,
1744 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
1745 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
1746 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5]);
1748 /* at least one port started, need checking link status */
1749 need_check_link_status = 1;
1752 for (event_type = RTE_ETH_EVENT_UNKNOWN;
1753 event_type < RTE_ETH_EVENT_MAX;
1755 diag = rte_eth_dev_callback_register(RTE_ETH_ALL,
1760 printf("Failed to setup even callback for event %d\n",
1766 if (need_check_link_status == 1 && !no_link_check)
1767 check_all_ports_link_status(RTE_PORT_ALL);
1768 else if (need_check_link_status == 0)
1769 printf("Please stop the ports first\n");
1776 stop_port(portid_t pid)
1779 struct rte_port *port;
1780 int need_check_link_status = 0;
1787 if (port_id_is_invalid(pid, ENABLED_WARN))
1790 printf("Stopping ports...\n");
1792 RTE_ETH_FOREACH_DEV(pi) {
1793 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1796 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1797 printf("Please remove port %d from forwarding configuration.\n", pi);
1801 if (port_is_bonding_slave(pi)) {
1802 printf("Please remove port %d from bonded device.\n", pi);
1807 if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STARTED,
1808 RTE_PORT_HANDLING) == 0)
1811 rte_eth_dev_stop(pi);
1813 if (rte_atomic16_cmpset(&(port->port_status),
1814 RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
1815 printf("Port %d can not be set into stopped\n", pi);
1816 need_check_link_status = 1;
1818 if (need_check_link_status && !no_link_check)
1819 check_all_ports_link_status(RTE_PORT_ALL);
1825 close_port(portid_t pid)
1828 struct rte_port *port;
1830 if (port_id_is_invalid(pid, ENABLED_WARN))
1833 printf("Closing ports...\n");
1835 RTE_ETH_FOREACH_DEV(pi) {
1836 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1839 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1840 printf("Please remove port %d from forwarding configuration.\n", pi);
1844 if (port_is_bonding_slave(pi)) {
1845 printf("Please remove port %d from bonded device.\n", pi);
1850 if (rte_atomic16_cmpset(&(port->port_status),
1851 RTE_PORT_CLOSED, RTE_PORT_CLOSED) == 1) {
1852 printf("Port %d is already closed\n", pi);
1856 if (rte_atomic16_cmpset(&(port->port_status),
1857 RTE_PORT_STOPPED, RTE_PORT_HANDLING) == 0) {
1858 printf("Port %d is now not stopped\n", pi);
1862 if (port->flow_list)
1863 port_flow_flush(pi);
1864 rte_eth_dev_close(pi);
1866 if (rte_atomic16_cmpset(&(port->port_status),
1867 RTE_PORT_HANDLING, RTE_PORT_CLOSED) == 0)
1868 printf("Port %d cannot be set to closed\n", pi);
1875 reset_port(portid_t pid)
1879 struct rte_port *port;
1881 if (port_id_is_invalid(pid, ENABLED_WARN))
1884 printf("Resetting ports...\n");
1886 RTE_ETH_FOREACH_DEV(pi) {
1887 if (pid != pi && pid != (portid_t)RTE_PORT_ALL)
1890 if (port_is_forwarding(pi) != 0 && test_done == 0) {
1891 printf("Please remove port %d from forwarding "
1892 "configuration.\n", pi);
1896 if (port_is_bonding_slave(pi)) {
1897 printf("Please remove port %d from bonded device.\n",
1902 diag = rte_eth_dev_reset(pi);
1905 port->need_reconfig = 1;
1906 port->need_reconfig_queues = 1;
1908 printf("Failed to reset port %d. diag=%d\n", pi, diag);
1916 eth_dev_event_callback_register(void)
1920 /* register the device event callback */
1921 ret = rte_dev_event_callback_register(NULL,
1922 eth_dev_event_callback, NULL);
1924 printf("Failed to register device event callback\n");
1933 eth_dev_event_callback_unregister(void)
1937 /* unregister the device event callback */
1938 ret = rte_dev_event_callback_unregister(NULL,
1939 eth_dev_event_callback, NULL);
1941 printf("Failed to unregister device event callback\n");
1949 attach_port(char *identifier)
1952 unsigned int socket_id;
1954 printf("Attaching a new port...\n");
1956 if (identifier == NULL) {
1957 printf("Invalid parameters are specified\n");
1961 if (rte_eth_dev_attach(identifier, &pi))
1964 socket_id = (unsigned)rte_eth_dev_socket_id(pi);
1965 /* if socket_id is invalid, set to 0 */
1966 if (check_socket_id(socket_id) < 0)
1968 reconfig(pi, socket_id);
1969 rte_eth_promiscuous_enable(pi);
1971 nb_ports = rte_eth_dev_count_avail();
1973 ports[pi].port_status = RTE_PORT_STOPPED;
1975 update_fwd_ports(pi);
1977 printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
1982 detach_port(portid_t port_id)
1984 char name[RTE_ETH_NAME_MAX_LEN];
1986 printf("Detaching a port...\n");
1988 if (!port_is_closed(port_id)) {
1989 printf("Please close port first\n");
1993 if (ports[port_id].flow_list)
1994 port_flow_flush(port_id);
1996 if (rte_eth_dev_detach(port_id, name)) {
1997 TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
2001 nb_ports = rte_eth_dev_count_avail();
2003 update_fwd_ports(RTE_MAX_ETHPORTS);
2005 printf("Port %u is detached. Now total ports is %d\n",
2018 stop_packet_forwarding();
2020 if (ports != NULL) {
2022 RTE_ETH_FOREACH_DEV(pt_id) {
2023 printf("\nShutting down port %d...\n", pt_id);
2031 ret = rte_dev_event_monitor_stop();
2034 "fail to stop device event monitor.");
2036 ret = eth_dev_event_callback_unregister();
2039 "fail to unregister all event callbacks.");
2042 printf("\nBye...\n");
2045 typedef void (*cmd_func_t)(void);
2046 struct pmd_test_command {
2047 const char *cmd_name;
2048 cmd_func_t cmd_func;
2051 #define PMD_TEST_CMD_NB (sizeof(pmd_test_menu) / sizeof(pmd_test_menu[0]))
2053 /* Check the link status of all ports in up to 9s, and print them finally */
2055 check_all_ports_link_status(uint32_t port_mask)
2057 #define CHECK_INTERVAL 100 /* 100ms */
2058 #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
2060 uint8_t count, all_ports_up, print_flag = 0;
2061 struct rte_eth_link link;
2063 printf("Checking link statuses...\n");
2065 for (count = 0; count <= MAX_CHECK_TIME; count++) {
2067 RTE_ETH_FOREACH_DEV(portid) {
2068 if ((port_mask & (1 << portid)) == 0)
2070 memset(&link, 0, sizeof(link));
2071 rte_eth_link_get_nowait(portid, &link);
2072 /* print link status if flag set */
2073 if (print_flag == 1) {
2074 if (link.link_status)
2076 "Port%d Link Up. speed %u Mbps- %s\n",
2077 portid, link.link_speed,
2078 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
2079 ("full-duplex") : ("half-duplex\n"));
2081 printf("Port %d Link Down\n", portid);
2084 /* clear all_ports_up flag if any link down */
2085 if (link.link_status == ETH_LINK_DOWN) {
2090 /* after finally printing all link status, get out */
2091 if (print_flag == 1)
2094 if (all_ports_up == 0) {
2096 rte_delay_ms(CHECK_INTERVAL);
2099 /* set the print_flag if all ports up or timeout */
2100 if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
2110 rmv_event_callback(void *arg)
2112 int need_to_start = 0;
2113 int org_no_link_check = no_link_check;
2114 portid_t port_id = (intptr_t)arg;
2116 RTE_ETH_VALID_PORTID_OR_RET(port_id);
2118 if (!test_done && port_is_forwarding(port_id)) {
2120 stop_packet_forwarding();
2124 no_link_check = org_no_link_check;
2125 close_port(port_id);
2126 detach_port(port_id);
2128 start_packet_forwarding(0);
2131 /* This function is used by the interrupt thread */
2133 eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
2136 static const char * const event_desc[] = {
2137 [RTE_ETH_EVENT_UNKNOWN] = "Unknown",
2138 [RTE_ETH_EVENT_INTR_LSC] = "LSC",
2139 [RTE_ETH_EVENT_QUEUE_STATE] = "Queue state",
2140 [RTE_ETH_EVENT_INTR_RESET] = "Interrupt reset",
2141 [RTE_ETH_EVENT_VF_MBOX] = "VF Mbox",
2142 [RTE_ETH_EVENT_IPSEC] = "IPsec",
2143 [RTE_ETH_EVENT_MACSEC] = "MACsec",
2144 [RTE_ETH_EVENT_INTR_RMV] = "device removal",
2145 [RTE_ETH_EVENT_NEW] = "device probed",
2146 [RTE_ETH_EVENT_DESTROY] = "device released",
2147 [RTE_ETH_EVENT_MAX] = NULL,
2150 RTE_SET_USED(param);
2151 RTE_SET_USED(ret_param);
2153 if (type >= RTE_ETH_EVENT_MAX) {
2154 fprintf(stderr, "\nPort %" PRIu8 ": %s called upon invalid event %d\n",
2155 port_id, __func__, type);
2157 } else if (event_print_mask & (UINT32_C(1) << type)) {
2158 printf("\nPort %" PRIu8 ": %s event\n", port_id,
2163 if (port_id_is_invalid(port_id, DISABLED_WARN))
2167 case RTE_ETH_EVENT_INTR_RMV:
2168 if (rte_eal_alarm_set(100000,
2169 rmv_event_callback, (void *)(intptr_t)port_id))
2170 fprintf(stderr, "Could not set up deferred device removal\n");
2178 /* This function is used by the interrupt thread */
2180 eth_dev_event_callback(char *device_name, enum rte_dev_event_type type,
2181 __rte_unused void *arg)
2183 if (type >= RTE_DEV_EVENT_MAX) {
2184 fprintf(stderr, "%s called upon invalid event %d\n",
2190 case RTE_DEV_EVENT_REMOVE:
2191 RTE_LOG(ERR, EAL, "The device: %s has been removed!\n",
2193 /* TODO: After finish failure handle, begin to stop
2194 * packet forward, stop port, close port, detach port.
2197 case RTE_DEV_EVENT_ADD:
2198 RTE_LOG(ERR, EAL, "The device: %s has been added!\n",
2200 /* TODO: After finish kernel driver binding,
2201 * begin to attach port.
2210 set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
2214 uint8_t mapping_found = 0;
2216 for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
2217 if ((tx_queue_stats_mappings[i].port_id == port_id) &&
2218 (tx_queue_stats_mappings[i].queue_id < nb_txq )) {
2219 diag = rte_eth_dev_set_tx_queue_stats_mapping(port_id,
2220 tx_queue_stats_mappings[i].queue_id,
2221 tx_queue_stats_mappings[i].stats_counter_id);
2228 port->tx_queue_stats_mapping_enabled = 1;
2233 set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
2237 uint8_t mapping_found = 0;
2239 for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
2240 if ((rx_queue_stats_mappings[i].port_id == port_id) &&
2241 (rx_queue_stats_mappings[i].queue_id < nb_rxq )) {
2242 diag = rte_eth_dev_set_rx_queue_stats_mapping(port_id,
2243 rx_queue_stats_mappings[i].queue_id,
2244 rx_queue_stats_mappings[i].stats_counter_id);
2251 port->rx_queue_stats_mapping_enabled = 1;
2256 map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
2260 diag = set_tx_queue_stats_mapping_registers(pi, port);
2262 if (diag == -ENOTSUP) {
2263 port->tx_queue_stats_mapping_enabled = 0;
2264 printf("TX queue stats mapping not supported port id=%d\n", pi);
2267 rte_exit(EXIT_FAILURE,
2268 "set_tx_queue_stats_mapping_registers "
2269 "failed for port id=%d diag=%d\n",
2273 diag = set_rx_queue_stats_mapping_registers(pi, port);
2275 if (diag == -ENOTSUP) {
2276 port->rx_queue_stats_mapping_enabled = 0;
2277 printf("RX queue stats mapping not supported port id=%d\n", pi);
2280 rte_exit(EXIT_FAILURE,
2281 "set_rx_queue_stats_mapping_registers "
2282 "failed for port id=%d diag=%d\n",
2288 rxtx_port_config(struct rte_port *port)
2292 for (qid = 0; qid < nb_rxq; qid++) {
2293 port->rx_conf[qid] = port->dev_info.default_rxconf;
2295 /* Check if any Rx parameters have been passed */
2296 if (rx_pthresh != RTE_PMD_PARAM_UNSET)
2297 port->rx_conf[qid].rx_thresh.pthresh = rx_pthresh;
2299 if (rx_hthresh != RTE_PMD_PARAM_UNSET)
2300 port->rx_conf[qid].rx_thresh.hthresh = rx_hthresh;
2302 if (rx_wthresh != RTE_PMD_PARAM_UNSET)
2303 port->rx_conf[qid].rx_thresh.wthresh = rx_wthresh;
2305 if (rx_free_thresh != RTE_PMD_PARAM_UNSET)
2306 port->rx_conf[qid].rx_free_thresh = rx_free_thresh;
2308 if (rx_drop_en != RTE_PMD_PARAM_UNSET)
2309 port->rx_conf[qid].rx_drop_en = rx_drop_en;
2311 port->nb_rx_desc[qid] = nb_rxd;
2314 for (qid = 0; qid < nb_txq; qid++) {
2315 port->tx_conf[qid] = port->dev_info.default_txconf;
2317 /* Check if any Tx parameters have been passed */
2318 if (tx_pthresh != RTE_PMD_PARAM_UNSET)
2319 port->tx_conf[qid].tx_thresh.pthresh = tx_pthresh;
2321 if (tx_hthresh != RTE_PMD_PARAM_UNSET)
2322 port->tx_conf[qid].tx_thresh.hthresh = tx_hthresh;
2324 if (tx_wthresh != RTE_PMD_PARAM_UNSET)
2325 port->tx_conf[qid].tx_thresh.wthresh = tx_wthresh;
2327 if (tx_rs_thresh != RTE_PMD_PARAM_UNSET)
2328 port->tx_conf[qid].tx_rs_thresh = tx_rs_thresh;
2330 if (tx_free_thresh != RTE_PMD_PARAM_UNSET)
2331 port->tx_conf[qid].tx_free_thresh = tx_free_thresh;
2333 port->nb_tx_desc[qid] = nb_txd;
2338 init_port_config(void)
2341 struct rte_port *port;
2342 struct rte_eth_dev_info dev_info;
2344 RTE_ETH_FOREACH_DEV(pid) {
2346 port->dev_conf.fdir_conf = fdir_conf;
2348 rte_eth_dev_info_get(pid, &dev_info);
2349 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2350 port->dev_conf.rx_adv_conf.rss_conf.rss_hf =
2351 rss_hf & dev_info.flow_type_rss_offloads;
2353 port->dev_conf.rx_adv_conf.rss_conf.rss_key = NULL;
2354 port->dev_conf.rx_adv_conf.rss_conf.rss_hf = 0;
2357 if (port->dcb_flag == 0) {
2358 if( port->dev_conf.rx_adv_conf.rss_conf.rss_hf != 0)
2359 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
2361 port->dev_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
2364 rxtx_port_config(port);
2366 rte_eth_macaddr_get(pid, &port->eth_addr);
2368 map_port_queue_stats_mapping_registers(pid, port);
2369 #if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
2370 rte_pmd_ixgbe_bypass_init(pid);
2373 if (lsc_interrupt &&
2374 (rte_eth_devices[pid].data->dev_flags &
2375 RTE_ETH_DEV_INTR_LSC))
2376 port->dev_conf.intr_conf.lsc = 1;
2377 if (rmv_interrupt &&
2378 (rte_eth_devices[pid].data->dev_flags &
2379 RTE_ETH_DEV_INTR_RMV))
2380 port->dev_conf.intr_conf.rmv = 1;
2382 #if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED
2383 /* Detect softnic port */
2384 if (!strcmp(port->dev_info.driver_name, "net_softnic")) {
2385 port->softnic_enable = 1;
2386 memset(&port->softport, 0, sizeof(struct softnic_port));
2388 if (!strcmp(cur_fwd_eng->fwd_mode_name, "tm"))
2389 port->softport.tm_flag = 1;
2395 void set_port_slave_flag(portid_t slave_pid)
2397 struct rte_port *port;
2399 port = &ports[slave_pid];
2400 port->slave_flag = 1;
2403 void clear_port_slave_flag(portid_t slave_pid)
2405 struct rte_port *port;
2407 port = &ports[slave_pid];
2408 port->slave_flag = 0;
2411 uint8_t port_is_bonding_slave(portid_t slave_pid)
2413 struct rte_port *port;
2415 port = &ports[slave_pid];
2416 if ((rte_eth_devices[slave_pid].data->dev_flags &
2417 RTE_ETH_DEV_BONDED_SLAVE) || (port->slave_flag == 1))
2422 const uint16_t vlan_tags[] = {
2423 0, 1, 2, 3, 4, 5, 6, 7,
2424 8, 9, 10, 11, 12, 13, 14, 15,
2425 16, 17, 18, 19, 20, 21, 22, 23,
2426 24, 25, 26, 27, 28, 29, 30, 31
2430 get_eth_dcb_conf(struct rte_eth_conf *eth_conf,
2431 enum dcb_mode_enable dcb_mode,
2432 enum rte_eth_nb_tcs num_tcs,
2438 * Builds up the correct configuration for dcb+vt based on the vlan tags array
2439 * given above, and the number of traffic classes available for use.
2441 if (dcb_mode == DCB_VT_ENABLED) {
2442 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
2443 ð_conf->rx_adv_conf.vmdq_dcb_conf;
2444 struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
2445 ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
2447 /* VMDQ+DCB RX and TX configurations */
2448 vmdq_rx_conf->enable_default_pool = 0;
2449 vmdq_rx_conf->default_pool = 0;
2450 vmdq_rx_conf->nb_queue_pools =
2451 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2452 vmdq_tx_conf->nb_queue_pools =
2453 (num_tcs == ETH_4_TCS ? ETH_32_POOLS : ETH_16_POOLS);
2455 vmdq_rx_conf->nb_pool_maps = vmdq_rx_conf->nb_queue_pools;
2456 for (i = 0; i < vmdq_rx_conf->nb_pool_maps; i++) {
2457 vmdq_rx_conf->pool_map[i].vlan_id = vlan_tags[i];
2458 vmdq_rx_conf->pool_map[i].pools =
2459 1 << (i % vmdq_rx_conf->nb_queue_pools);
2461 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2462 vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
2463 vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
2466 /* set DCB mode of RX and TX of multiple queues */
2467 eth_conf->rxmode.mq_mode = ETH_MQ_RX_VMDQ_DCB;
2468 eth_conf->txmode.mq_mode = ETH_MQ_TX_VMDQ_DCB;
2470 struct rte_eth_dcb_rx_conf *rx_conf =
2471 ð_conf->rx_adv_conf.dcb_rx_conf;
2472 struct rte_eth_dcb_tx_conf *tx_conf =
2473 ð_conf->tx_adv_conf.dcb_tx_conf;
2475 rx_conf->nb_tcs = num_tcs;
2476 tx_conf->nb_tcs = num_tcs;
2478 for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
2479 rx_conf->dcb_tc[i] = i % num_tcs;
2480 tx_conf->dcb_tc[i] = i % num_tcs;
2482 eth_conf->rxmode.mq_mode = ETH_MQ_RX_DCB_RSS;
2483 eth_conf->rx_adv_conf.rss_conf.rss_hf = rss_hf;
2484 eth_conf->txmode.mq_mode = ETH_MQ_TX_DCB;
2488 eth_conf->dcb_capability_en =
2489 ETH_DCB_PG_SUPPORT | ETH_DCB_PFC_SUPPORT;
2491 eth_conf->dcb_capability_en = ETH_DCB_PG_SUPPORT;
2497 init_port_dcb_config(portid_t pid,
2498 enum dcb_mode_enable dcb_mode,
2499 enum rte_eth_nb_tcs num_tcs,
2502 struct rte_eth_conf port_conf;
2503 struct rte_port *rte_port;
2507 rte_port = &ports[pid];
2509 memset(&port_conf, 0, sizeof(struct rte_eth_conf));
2510 /* Enter DCB configuration status */
2513 port_conf.rxmode = rte_port->dev_conf.rxmode;
2514 port_conf.txmode = rte_port->dev_conf.txmode;
2516 /*set configuration of DCB in vt mode and DCB in non-vt mode*/
2517 retval = get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en);
2520 port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2522 /* re-configure the device . */
2523 rte_eth_dev_configure(pid, nb_rxq, nb_rxq, &port_conf);
2525 rte_eth_dev_info_get(pid, &rte_port->dev_info);
2527 /* If dev_info.vmdq_pool_base is greater than 0,
2528 * the queue id of vmdq pools is started after pf queues.
2530 if (dcb_mode == DCB_VT_ENABLED &&
2531 rte_port->dev_info.vmdq_pool_base > 0) {
2532 printf("VMDQ_DCB multi-queue mode is nonsensical"
2533 " for port %d.", pid);
2537 /* Assume the ports in testpmd have the same dcb capability
2538 * and has the same number of rxq and txq in dcb mode
2540 if (dcb_mode == DCB_VT_ENABLED) {
2541 if (rte_port->dev_info.max_vfs > 0) {
2542 nb_rxq = rte_port->dev_info.nb_rx_queues;
2543 nb_txq = rte_port->dev_info.nb_tx_queues;
2545 nb_rxq = rte_port->dev_info.max_rx_queues;
2546 nb_txq = rte_port->dev_info.max_tx_queues;
2549 /*if vt is disabled, use all pf queues */
2550 if (rte_port->dev_info.vmdq_pool_base == 0) {
2551 nb_rxq = rte_port->dev_info.max_rx_queues;
2552 nb_txq = rte_port->dev_info.max_tx_queues;
2554 nb_rxq = (queueid_t)num_tcs;
2555 nb_txq = (queueid_t)num_tcs;
2559 rx_free_thresh = 64;
2561 memcpy(&rte_port->dev_conf, &port_conf, sizeof(struct rte_eth_conf));
2563 rxtx_port_config(rte_port);
2565 rte_port->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
2566 for (i = 0; i < RTE_DIM(vlan_tags); i++)
2567 rx_vft_set(pid, vlan_tags[i], 1);
2569 rte_eth_macaddr_get(pid, &rte_port->eth_addr);
2570 map_port_queue_stats_mapping_registers(pid, rte_port);
2572 rte_port->dcb_flag = 1;
2580 /* Configuration of Ethernet ports. */
2581 ports = rte_zmalloc("testpmd: ports",
2582 sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
2583 RTE_CACHE_LINE_SIZE);
2584 if (ports == NULL) {
2585 rte_exit(EXIT_FAILURE,
2586 "rte_zmalloc(%d struct rte_port) failed\n",
2602 const char clr[] = { 27, '[', '2', 'J', '\0' };
2603 const char top_left[] = { 27, '[', '1', ';', '1', 'H', '\0' };
2605 /* Clear screen and move to top left */
2606 printf("%s%s", clr, top_left);
2608 printf("\nPort statistics ====================================");
2609 for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
2610 nic_stats_display(fwd_ports_ids[i]);
2614 signal_handler(int signum)
2616 if (signum == SIGINT || signum == SIGTERM) {
2617 printf("\nSignal %d received, preparing to exit...\n",
2619 #ifdef RTE_LIBRTE_PDUMP
2620 /* uninitialize packet capture framework */
2623 #ifdef RTE_LIBRTE_LATENCY_STATS
2624 rte_latencystats_uninit();
2627 /* Set flag to indicate the force termination. */
2629 /* exit with the expected status */
2630 signal(signum, SIG_DFL);
2631 kill(getpid(), signum);
2636 main(int argc, char** argv)
2642 signal(SIGINT, signal_handler);
2643 signal(SIGTERM, signal_handler);
2645 diag = rte_eal_init(argc, argv);
2647 rte_panic("Cannot init EAL\n");
2649 testpmd_logtype = rte_log_register("testpmd");
2650 if (testpmd_logtype < 0)
2651 rte_panic("Cannot register log type");
2652 rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
2654 #ifdef RTE_LIBRTE_PDUMP
2655 /* initialize packet capture framework */
2656 rte_pdump_init(NULL);
2659 nb_ports = (portid_t) rte_eth_dev_count_avail();
2661 TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
2663 /* allocate port structures, and init them */
2666 set_def_fwd_config();
2668 rte_panic("Empty set of forwarding logical cores - check the "
2669 "core mask supplied in the command parameters\n");
2671 /* Bitrate/latency stats disabled by default */
2672 #ifdef RTE_LIBRTE_BITRATE
2673 bitrate_enabled = 0;
2675 #ifdef RTE_LIBRTE_LATENCY_STATS
2676 latencystats_enabled = 0;
2679 /* on FreeBSD, mlockall() is disabled by default */
2680 #ifdef RTE_EXEC_ENV_BSDAPP
2689 launch_args_parse(argc, argv);
2691 if (do_mlockall && mlockall(MCL_CURRENT | MCL_FUTURE)) {
2692 TESTPMD_LOG(NOTICE, "mlockall() failed with error \"%s\"\n",
2696 if (tx_first && interactive)
2697 rte_exit(EXIT_FAILURE, "--tx-first cannot be used on "
2698 "interactive mode.\n");
2700 if (tx_first && lsc_interrupt) {
2701 printf("Warning: lsc_interrupt needs to be off when "
2702 " using tx_first. Disabling.\n");
2706 if (!nb_rxq && !nb_txq)
2707 printf("Warning: Either rx or tx queues should be non-zero\n");
2709 if (nb_rxq > 1 && nb_rxq > nb_txq)
2710 printf("Warning: nb_rxq=%d enables RSS configuration, "
2711 "but nb_txq=%d will prevent to fully test it.\n",
2717 /* enable hot plug monitoring */
2718 ret = rte_dev_event_monitor_start();
2723 eth_dev_event_callback_register();
2727 if (start_port(RTE_PORT_ALL) != 0)
2728 rte_exit(EXIT_FAILURE, "Start ports failed\n");
2730 /* set all ports to promiscuous mode by default */
2731 RTE_ETH_FOREACH_DEV(port_id)
2732 rte_eth_promiscuous_enable(port_id);
2734 /* Init metrics library */
2735 rte_metrics_init(rte_socket_id());
2737 #ifdef RTE_LIBRTE_LATENCY_STATS
2738 if (latencystats_enabled != 0) {
2739 int ret = rte_latencystats_init(1, NULL);
2741 printf("Warning: latencystats init()"
2742 " returned error %d\n", ret);
2743 printf("Latencystats running on lcore %d\n",
2744 latencystats_lcore_id);
2748 /* Setup bitrate stats */
2749 #ifdef RTE_LIBRTE_BITRATE
2750 if (bitrate_enabled != 0) {
2751 bitrate_data = rte_stats_bitrate_create();
2752 if (bitrate_data == NULL)
2753 rte_exit(EXIT_FAILURE,
2754 "Could not allocate bitrate data.\n");
2755 rte_stats_bitrate_reg(bitrate_data);
2759 #ifdef RTE_LIBRTE_CMDLINE
2760 if (strlen(cmdline_filename) != 0)
2761 cmdline_read_from_file(cmdline_filename);
2763 if (interactive == 1) {
2765 printf("Start automatic packet forwarding\n");
2766 start_packet_forwarding(0);
2778 printf("No commandline core given, start packet forwarding\n");
2779 start_packet_forwarding(tx_first);
2780 if (stats_period != 0) {
2781 uint64_t prev_time = 0, cur_time, diff_time = 0;
2782 uint64_t timer_period;
2784 /* Convert to number of cycles */
2785 timer_period = stats_period * rte_get_timer_hz();
2787 while (f_quit == 0) {
2788 cur_time = rte_get_timer_cycles();
2789 diff_time += cur_time - prev_time;
2791 if (diff_time >= timer_period) {
2793 /* Reset the timer */
2796 /* Sleep to avoid unnecessary checks */
2797 prev_time = cur_time;
2802 printf("Press enter to exit\n");
2803 rc = read(0, &c, 1);