metrics: fix variable declaration in header
[dpdk.git] / app / test-pmd / testpmd.c
index 00cffae..c256e71 100644 (file)
 #include <rte_ethdev.h>
 #include <rte_dev.h>
 #include <rte_string_fns.h>
-#ifdef RTE_LIBRTE_IXGBE_PMD
+#ifdef RTE_NET_IXGBE
 #include <rte_pmd_ixgbe.h>
 #endif
-#ifdef RTE_LIBRTE_PDUMP
+#ifdef RTE_LIB_PDUMP
 #include <rte_pdump.h>
 #endif
 #include <rte_flow.h>
 #include <rte_metrics.h>
-#ifdef RTE_LIBRTE_BITRATESTATS
+#ifdef RTE_LIB_BITRATESTATS
 #include <rte_bitrate.h>
 #endif
-#ifdef RTE_LIBRTE_LATENCY_STATS
+#ifdef RTE_LIB_LATENCYSTATS
 #include <rte_latencystats.h>
 #endif
 
@@ -83,7 +83,7 @@
 uint16_t verbose_level = 0; /**< Silent by default. */
 int testpmd_logtype; /**< Log type for testpmd logs */
 
-/* use master core for command line ? */
+/* use main core for command line ? */
 uint8_t interactive = 0;
 uint8_t auto_start = 0;
 uint8_t tx_first;
@@ -419,13 +419,13 @@ int do_mlockall = 0;
  * NIC bypass mode configuration options.
  */
 
-#if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
+#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
 /* The NIC bypass watchdog timeout. */
 uint32_t bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF;
 #endif
 
 
-#ifdef RTE_LIBRTE_LATENCY_STATS
+#ifdef RTE_LIB_LATENCYSTATS
 
 /*
  * Set when latency stats is enabled in the commandline
@@ -476,15 +476,6 @@ struct rte_fdir_conf fdir_conf = {
 
 volatile int test_done = 1; /* stop packet forwarding when set to 1. */
 
-struct queue_stats_mappings tx_queue_stats_mappings_array[MAX_TX_QUEUE_STATS_MAPPINGS];
-struct queue_stats_mappings rx_queue_stats_mappings_array[MAX_RX_QUEUE_STATS_MAPPINGS];
-
-struct queue_stats_mappings *tx_queue_stats_mappings = tx_queue_stats_mappings_array;
-struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_array;
-
-uint16_t nb_tx_queue_stats_mappings = 0;
-uint16_t nb_rx_queue_stats_mappings = 0;
-
 /*
  * Display zero values by default for xstats
  */
@@ -503,7 +494,7 @@ uint8_t record_burst_stats;
 unsigned int num_sockets = 0;
 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
 
-#ifdef RTE_LIBRTE_BITRATESTATS
+#ifdef RTE_LIB_BITRATESTATS
 /* Bitrate statistics */
 struct rte_stats_bitrates *bitrate_data;
 lcoreid_t bitrate_lcore_id;
@@ -520,8 +511,6 @@ enum rte_eth_rx_mq_mode rx_mq_mode = ETH_MQ_RX_VMDQ_DCB_RSS;
 
 /* Forward function declarations */
 static void setup_attached_port(portid_t pi);
-static void map_port_queue_stats_mapping_registers(portid_t pi,
-                                                  struct rte_port *port);
 static void check_all_ports_link_status(uint32_t port_mask);
 static int eth_event_callback(portid_t port_id,
                              enum rte_eth_event_type type,
@@ -581,7 +570,7 @@ set_default_fwd_lcores_config(void)
                        }
                        socket_ids[num_sockets++] = sock_num;
                }
-               if (i == rte_get_master_lcore())
+               if (i == rte_get_main_lcore())
                        continue;
                fwd_lcores_cpuids[nb_lc++] = i;
        }
@@ -1421,6 +1410,7 @@ init_config(void)
        struct rte_gro_param gro_param;
        uint32_t gso_types;
        uint16_t data_size;
+       uint16_t eth_overhead;
        bool warning = 0;
        int k;
        int ret;
@@ -1457,6 +1447,23 @@ init_config(void)
                        rte_exit(EXIT_FAILURE,
                                 "rte_eth_dev_info_get() failed\n");
 
+               /* Update the max_rx_pkt_len to have MTU as RTE_ETHER_MTU */
+               if (port->dev_info.max_mtu != UINT16_MAX &&
+                   port->dev_info.max_rx_pktlen > port->dev_info.max_mtu)
+                       eth_overhead = port->dev_info.max_rx_pktlen -
+                               port->dev_info.max_mtu;
+               else
+                       eth_overhead =
+                               RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
+
+               if (port->dev_conf.rxmode.max_rx_pkt_len <=
+                       (uint32_t)(RTE_ETHER_MTU + eth_overhead))
+                       port->dev_conf.rxmode.max_rx_pkt_len =
+                                       RTE_ETHER_MTU + eth_overhead;
+               else
+                       port->dev_conf.rxmode.offloads |=
+                                       DEV_RX_OFFLOAD_JUMBO_FRAME;
+
                if (!(port->dev_info.tx_offload_capa &
                      DEV_TX_OFFLOAD_MBUF_FAST_FREE))
                        port->dev_conf.txmode.offloads &=
@@ -1857,8 +1864,6 @@ fwd_stats_display(void)
                        fwd_cycles += fs->core_cycles;
        }
        for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
-               uint8_t j;
-
                pt_id = fwd_ports_ids[i];
                port = &ports[pt_id];
 
@@ -1881,88 +1886,34 @@ fwd_stats_display(void)
                printf("\n  %s Forward statistics for port %-2d %s\n",
                       fwd_stats_border, pt_id, fwd_stats_border);
 
-               if (!port->rx_queue_stats_mapping_enabled &&
-                   !port->tx_queue_stats_mapping_enabled) {
-                       printf("  RX-packets: %-14"PRIu64
-                              " RX-dropped: %-14"PRIu64
-                              "RX-total: %-"PRIu64"\n",
-                              stats.ipackets, stats.imissed,
-                              stats.ipackets + stats.imissed);
-
-                       if (cur_fwd_eng == &csum_fwd_engine)
-                               printf("  Bad-ipcsum: %-14"PRIu64
-                                      " Bad-l4csum: %-14"PRIu64
-                                      "Bad-outer-l4csum: %-14"PRIu64"\n",
-                                      ports_stats[pt_id].rx_bad_ip_csum,
-                                      ports_stats[pt_id].rx_bad_l4_csum,
-                                      ports_stats[pt_id].rx_bad_outer_l4_csum);
-                       if (stats.ierrors + stats.rx_nombuf > 0) {
-                               printf("  RX-error: %-"PRIu64"\n",
-                                      stats.ierrors);
-                               printf("  RX-nombufs: %-14"PRIu64"\n",
-                                      stats.rx_nombuf);
-                       }
-
-                       printf("  TX-packets: %-14"PRIu64
-                              " TX-dropped: %-14"PRIu64
-                              "TX-total: %-"PRIu64"\n",
-                              stats.opackets, ports_stats[pt_id].tx_dropped,
-                              stats.opackets + ports_stats[pt_id].tx_dropped);
-               } else {
-                       printf("  RX-packets:             %14"PRIu64
-                              "    RX-dropped:%14"PRIu64
-                              "    RX-total:%14"PRIu64"\n",
-                              stats.ipackets, stats.imissed,
-                              stats.ipackets + stats.imissed);
-
-                       if (cur_fwd_eng == &csum_fwd_engine)
-                               printf("  Bad-ipcsum:%14"PRIu64
-                                      "    Bad-l4csum:%14"PRIu64
-                                      "    Bad-outer-l4csum: %-14"PRIu64"\n",
-                                      ports_stats[pt_id].rx_bad_ip_csum,
-                                      ports_stats[pt_id].rx_bad_l4_csum,
-                                      ports_stats[pt_id].rx_bad_outer_l4_csum);
-                       if ((stats.ierrors + stats.rx_nombuf) > 0) {
-                               printf("  RX-error:%"PRIu64"\n", stats.ierrors);
-                               printf("  RX-nombufs:             %14"PRIu64"\n",
-                                      stats.rx_nombuf);
-                       }
+               printf("  RX-packets: %-14"PRIu64" RX-dropped: %-14"PRIu64
+                      "RX-total: %-"PRIu64"\n", stats.ipackets, stats.imissed,
+                      stats.ipackets + stats.imissed);
 
-                       printf("  TX-packets:             %14"PRIu64
-                              "    TX-dropped:%14"PRIu64
-                              "    TX-total:%14"PRIu64"\n",
-                              stats.opackets, ports_stats[pt_id].tx_dropped,
-                              stats.opackets + ports_stats[pt_id].tx_dropped);
+               if (cur_fwd_eng == &csum_fwd_engine)
+                       printf("  Bad-ipcsum: %-14"PRIu64
+                              " Bad-l4csum: %-14"PRIu64
+                              "Bad-outer-l4csum: %-14"PRIu64"\n",
+                              ports_stats[pt_id].rx_bad_ip_csum,
+                              ports_stats[pt_id].rx_bad_l4_csum,
+                              ports_stats[pt_id].rx_bad_outer_l4_csum);
+               if (stats.ierrors + stats.rx_nombuf > 0) {
+                       printf("  RX-error: %-"PRIu64"\n", stats.ierrors);
+                       printf("  RX-nombufs: %-14"PRIu64"\n", stats.rx_nombuf);
                }
 
+               printf("  TX-packets: %-14"PRIu64" TX-dropped: %-14"PRIu64
+                      "TX-total: %-"PRIu64"\n",
+                      stats.opackets, ports_stats[pt_id].tx_dropped,
+                      stats.opackets + ports_stats[pt_id].tx_dropped);
+
                if (record_burst_stats) {
                        if (ports_stats[pt_id].rx_stream)
                                pkt_burst_stats_display("RX",
                                        &ports_stats[pt_id].rx_stream->rx_burst_stats);
                        if (ports_stats[pt_id].tx_stream)
                                pkt_burst_stats_display("TX",
-                                       &ports_stats[pt_id].tx_stream->tx_burst_stats);
-               }
-
-               if (port->rx_queue_stats_mapping_enabled) {
-                       printf("\n");
-                       for (j = 0; j < RTE_ETHDEV_QUEUE_STAT_CNTRS; j++) {
-                               printf("  Stats reg %2d RX-packets:%14"PRIu64
-                                      "     RX-errors:%14"PRIu64
-                                      "    RX-bytes:%14"PRIu64"\n",
-                                      j, stats.q_ipackets[j],
-                                      stats.q_errors[j], stats.q_ibytes[j]);
-                       }
-                       printf("\n");
-               }
-               if (port->tx_queue_stats_mapping_enabled) {
-                       for (j = 0; j < RTE_ETHDEV_QUEUE_STAT_CNTRS; j++) {
-                               printf("  Stats reg %2d TX-packets:%14"PRIu64
-                                      "                                 TX-bytes:%14"
-                                      PRIu64"\n",
-                                      j, stats.q_opackets[j],
-                                      stats.q_obytes[j]);
-                       }
+                               &ports_stats[pt_id].tx_stream->tx_burst_stats);
                }
 
                printf("  %s--------------------------------%s\n",
@@ -2081,7 +2032,7 @@ run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
        struct fwd_stream **fsm;
        streamid_t nb_fs;
        streamid_t sm_id;
-#ifdef RTE_LIBRTE_BITRATESTATS
+#ifdef RTE_LIB_BITRATESTATS
        uint64_t tics_per_1sec;
        uint64_t tics_datum;
        uint64_t tics_current;
@@ -2096,7 +2047,7 @@ run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
        do {
                for (sm_id = 0; sm_id < nb_fs; sm_id++)
                        (*pkt_fwd)(fsm[sm_id]);
-#ifdef RTE_LIBRTE_BITRATESTATS
+#ifdef RTE_LIB_BITRATESTATS
                if (bitrate_enabled != 0 &&
                                bitrate_lcore_id == rte_lcore_id()) {
                        tics_current = rte_rdtsc();
@@ -2109,7 +2060,7 @@ run_pkt_fwd_on_lcore(struct fwd_lcore *fc, packet_fwd_t pkt_fwd)
                        }
                }
 #endif
-#ifdef RTE_LIBRTE_LATENCY_STATS
+#ifdef RTE_LIB_LATENCYSTATS
                if (latencystats_enabled != 0 &&
                                latencystats_lcore_id == rte_lcore_id())
                        rte_latencystats_update();
@@ -2236,11 +2187,6 @@ start_packet_forwarding(int with_tx_first)
        rxtx_config_display();
 
        fwd_stats_reset();
-       for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
-               pt_id = fwd_ports_ids[i];
-               port = &ports[pt_id];
-               map_port_queue_stats_mapping_registers(pt_id, port);
-       }
        if (with_tx_first) {
                port_fwd_begin = tx_only_engine.port_fwd_begin;
                if (port_fwd_begin != NULL) {
@@ -2806,7 +2752,12 @@ stop_port(portid_t pid)
                        }
                }
 
-               rte_eth_dev_stop(pi);
+               if (port->flow_list)
+                       port_flow_flush(pi);
+
+               if (rte_eth_dev_stop(pi) != 0)
+                       RTE_LOG(ERR, EAL, "rte_eth_dev_stop failed for port %u\n",
+                               pi);
 
                if (rte_atomic16_cmpset(&(port->port_status),
                        RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
@@ -3350,84 +3301,6 @@ dev_event_callback(const char *device_name, enum rte_dev_event_type type,
        }
 }
 
-static int
-set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
-{
-       uint16_t i;
-       int diag;
-       uint8_t mapping_found = 0;
-
-       for (i = 0; i < nb_tx_queue_stats_mappings; i++) {
-               if ((tx_queue_stats_mappings[i].port_id == port_id) &&
-                               (tx_queue_stats_mappings[i].queue_id < nb_txq )) {
-                       diag = rte_eth_dev_set_tx_queue_stats_mapping(port_id,
-                                       tx_queue_stats_mappings[i].queue_id,
-                                       tx_queue_stats_mappings[i].stats_counter_id);
-                       if (diag != 0)
-                               return diag;
-                       mapping_found = 1;
-               }
-       }
-       if (mapping_found)
-               port->tx_queue_stats_mapping_enabled = 1;
-       return 0;
-}
-
-static int
-set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
-{
-       uint16_t i;
-       int diag;
-       uint8_t mapping_found = 0;
-
-       for (i = 0; i < nb_rx_queue_stats_mappings; i++) {
-               if ((rx_queue_stats_mappings[i].port_id == port_id) &&
-                               (rx_queue_stats_mappings[i].queue_id < nb_rxq )) {
-                       diag = rte_eth_dev_set_rx_queue_stats_mapping(port_id,
-                                       rx_queue_stats_mappings[i].queue_id,
-                                       rx_queue_stats_mappings[i].stats_counter_id);
-                       if (diag != 0)
-                               return diag;
-                       mapping_found = 1;
-               }
-       }
-       if (mapping_found)
-               port->rx_queue_stats_mapping_enabled = 1;
-       return 0;
-}
-
-static void
-map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
-{
-       int diag = 0;
-
-       diag = set_tx_queue_stats_mapping_registers(pi, port);
-       if (diag != 0) {
-               if (diag == -ENOTSUP) {
-                       port->tx_queue_stats_mapping_enabled = 0;
-                       printf("TX queue stats mapping not supported port id=%d\n", pi);
-               }
-               else
-                       rte_exit(EXIT_FAILURE,
-                                       "set_tx_queue_stats_mapping_registers "
-                                       "failed for port id=%d diag=%d\n",
-                                       pi, diag);
-       }
-
-       diag = set_rx_queue_stats_mapping_registers(pi, port);
-       if (diag != 0) {
-               if (diag == -ENOTSUP) {
-                       port->rx_queue_stats_mapping_enabled = 0;
-                       printf("RX queue stats mapping not supported port id=%d\n", pi);
-               }
-               else
-                       rte_exit(EXIT_FAILURE,
-                                       "set_rx_queue_stats_mapping_registers "
-                                       "failed for port id=%d diag=%d\n",
-                                       pi, diag);
-       }
-}
-
 static void
 rxtx_port_config(struct rte_port *port)
 {
@@ -3524,8 +3397,7 @@ init_port_config(void)
                if (ret != 0)
                        return;
 
-               map_port_queue_stats_mapping_registers(pid, port);
-#if defined RTE_LIBRTE_IXGBE_PMD && defined RTE_LIBRTE_IXGBE_BYPASS
+#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS
                rte_pmd_ixgbe_bypass_init(pid);
 #endif
 
@@ -3735,8 +3607,6 @@ init_port_dcb_config(portid_t pid,
        if (retval != 0)
                return retval;
 
-       map_port_queue_stats_mapping_registers(pid, rte_port);
-
        rte_port->dcb_flag = 1;
 
        return 0;
@@ -3794,11 +3664,11 @@ signal_handler(int signum)
        if (signum == SIGINT || signum == SIGTERM) {
                printf("\nSignal %d received, preparing to exit...\n",
                                signum);
-#ifdef RTE_LIBRTE_PDUMP
+#ifdef RTE_LIB_PDUMP
                /* uninitialize packet capture framework */
                rte_pdump_uninit();
 #endif
-#ifdef RTE_LIBRTE_LATENCY_STATS
+#ifdef RTE_LIB_LATENCYSTATS
                if (latencystats_enabled != 0)
                        rte_latencystats_uninit();
 #endif
@@ -3840,7 +3710,7 @@ main(int argc, char** argv)
        if (ret != 0)
                rte_exit(EXIT_FAILURE, "Cannot register for ethdev events");
 
-#ifdef RTE_LIBRTE_PDUMP
+#ifdef RTE_LIB_PDUMP
        /* initialize packet capture framework */
        rte_pdump_init();
 #endif
@@ -3863,10 +3733,10 @@ main(int argc, char** argv)
                         "Check the core mask argument\n");
 
        /* Bitrate/latency stats disabled by default */
-#ifdef RTE_LIBRTE_BITRATESTATS
+#ifdef RTE_LIB_BITRATESTATS
        bitrate_enabled = 0;
 #endif
-#ifdef RTE_LIBRTE_LATENCY_STATS
+#ifdef RTE_LIB_LATENCYSTATS
        latencystats_enabled = 0;
 #endif
 
@@ -3945,7 +3815,7 @@ main(int argc, char** argv)
        /* Init metrics library */
        rte_metrics_init(rte_socket_id());
 
-#ifdef RTE_LIBRTE_LATENCY_STATS
+#ifdef RTE_LIB_LATENCYSTATS
        if (latencystats_enabled != 0) {
                int ret = rte_latencystats_init(1, NULL);
                if (ret)
@@ -3957,7 +3827,7 @@ main(int argc, char** argv)
 #endif
 
        /* Setup bitrate stats */
-#ifdef RTE_LIBRTE_BITRATESTATS
+#ifdef RTE_LIB_BITRATESTATS
        if (bitrate_enabled != 0) {
                bitrate_data = rte_stats_bitrate_create();
                if (bitrate_data == NULL)
@@ -3967,7 +3837,7 @@ main(int argc, char** argv)
        }
 #endif
 
-#ifdef RTE_LIBRTE_CMDLINE
+#ifdef RTE_LIB_CMDLINE
        if (strlen(cmdline_filename) != 0)
                cmdline_read_from_file(cmdline_filename);