app/testpmd: convert to new Rx offloads API
[dpdk.git] / app / test-pmd / testpmd.c
index f6398a0..686d9e4 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2017 Intel Corporation
  */
 
 #include <stdarg.h>
@@ -57,7 +28,6 @@
 #include <rte_cycles.h>
 #include <rte_memory.h>
 #include <rte_memcpy.h>
-#include <rte_memzone.h>
 #include <rte_launch.h>
 #include <rte_eal.h>
 #include <rte_alarm.h>
@@ -92,6 +62,7 @@
 #include "testpmd.h"
 
 uint16_t verbose_level = 0; /**< Silent by default. */
+int testpmd_logtype; /**< Log type for testpmd logs */
 
 /* use master core for command line ? */
 uint8_t interactive = 0;
@@ -339,15 +310,10 @@ lcoreid_t latencystats_lcore_id = -1;
  */
 struct rte_eth_rxmode rx_mode = {
        .max_rx_pkt_len = ETHER_MAX_LEN, /**< Default maximum frame length. */
-       .split_hdr_size = 0,
-       .header_split   = 0, /**< Header Split disabled. */
-       .hw_ip_checksum = 0, /**< IP checksum offload disabled. */
-       .hw_vlan_filter = 1, /**< VLAN filtering enabled. */
-       .hw_vlan_strip  = 1, /**< VLAN strip enabled. */
-       .hw_vlan_extend = 0, /**< Extended VLAN disabled. */
-       .jumbo_frame    = 0, /**< Jumbo Frame Support disabled. */
-       .hw_strip_crc   = 1, /**< CRC stripping by hardware enabled. */
-       .hw_timestamp   = 0, /**< HW timestamp enabled. */
+       .offloads = (DEV_RX_OFFLOAD_VLAN_FILTER |
+                    DEV_RX_OFFLOAD_VLAN_STRIP |
+                    DEV_RX_OFFLOAD_CRC_STRIP),
+       .ignore_offload_bitfield = 1,
 };
 
 struct rte_fdir_conf fdir_conf = {
@@ -384,6 +350,11 @@ struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_a
 uint16_t nb_tx_queue_stats_mappings = 0;
 uint16_t nb_rx_queue_stats_mappings = 0;
 
+/*
+ * Display zero values by default for xstats
+ */
+uint8_t xstats_hide_zero;
+
 unsigned int num_sockets = 0;
 unsigned int socket_ids[RTE_MAX_NUMA_NODES];
 
@@ -398,7 +369,8 @@ struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES;
 
 /* Forward function declarations */
-static void map_port_queue_stats_mapping_registers(uint8_t pi, struct rte_port *port);
+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,
@@ -507,7 +479,7 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
        mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
        mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name));
 
-       RTE_LOG(INFO, USER1,
+       TESTPMD_LOG(INFO,
                "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
                pool_name, nb_mbuf, mbuf_seg_size, socket_id);
 
@@ -1516,6 +1488,8 @@ start_port(portid_t pid)
                                port->need_reconfig_queues = 1;
                                return -1;
                        }
+                       /* Apply Rx offloads configuration */
+                       port->rx_conf.offloads = port->dev_conf.rxmode.offloads;
                        /* setup rx queues */
                        for (qi = 0; qi < nb_rxq; qi++) {
                                if ((numa_support) &&
@@ -1784,7 +1758,7 @@ attach_port(char *identifier)
 }
 
 void
-detach_port(uint8_t port_id)
+detach_port(portid_t port_id)
 {
        char name[RTE_ETH_NAME_MAX_LEN];
 
@@ -1799,7 +1773,7 @@ detach_port(uint8_t port_id)
                port_flow_flush(port_id);
 
        if (rte_eth_dev_detach(port_id, name)) {
-               RTE_LOG(ERR, USER1, "Failed to detach port '%s'\n", name);
+               TESTPMD_LOG(ERR, "Failed to detach port '%s'\n", name);
                return;
        }
 
@@ -1899,7 +1873,7 @@ static void
 rmv_event_callback(void *arg)
 {
        struct rte_eth_dev *dev;
-       uint8_t port_id = (intptr_t)arg;
+       portid_t port_id = (intptr_t)arg;
 
        RTE_ETH_VALID_PORTID_OR_RET(port_id);
        dev = &rte_eth_devices[port_id];
@@ -1908,7 +1882,7 @@ rmv_event_callback(void *arg)
        close_port(port_id);
        printf("removing device %s\n", dev->device->name);
        if (rte_eal_dev_detach(dev->device))
-               RTE_LOG(ERR, USER1, "Failed to detach device %s\n",
+               TESTPMD_LOG(ERR, "Failed to detach device %s\n",
                        dev->device->name);
 }
 
@@ -1954,7 +1928,7 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
 }
 
 static int
-set_tx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port)
+set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
 {
        uint16_t i;
        int diag;
@@ -1977,7 +1951,7 @@ set_tx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port)
 }
 
 static int
-set_rx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port)
+set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port)
 {
        uint16_t i;
        int diag;
@@ -2000,7 +1974,7 @@ set_rx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port)
 }
 
 static void
-map_port_queue_stats_mapping_registers(uint8_t pi, struct rte_port *port)
+map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port)
 {
        int diag = 0;
 
@@ -2192,8 +2166,8 @@ get_eth_dcb_conf(struct rte_eth_conf *eth_conf,
                                1 << (i % vmdq_rx_conf->nb_queue_pools);
                }
                for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) {
-                       vmdq_rx_conf->dcb_tc[i] = i;
-                       vmdq_tx_conf->dcb_tc[i] = i;
+                       vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
+                       vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
                }
 
                /* set DCB mode of RX and TX of multiple queues */
@@ -2247,7 +2221,7 @@ init_port_dcb_config(portid_t pid,
        retval = get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en);
        if (retval < 0)
                return retval;
-       port_conf.rxmode.hw_vlan_filter = 1;
+       port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
 
        /**
         * Write the configuration into the device.
@@ -2296,7 +2270,7 @@ init_port_dcb_config(portid_t pid,
 
        rxtx_port_config(rte_port);
        /* VLAN filter */
-       rte_port->dev_conf.rxmode.hw_vlan_filter = 1;
+       rte_port->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
        for (i = 0; i < RTE_DIM(vlan_tags); i++)
                rx_vft_set(pid, vlan_tags[i], 1);
 
@@ -2379,8 +2353,13 @@ main(int argc, char** argv)
        if (diag < 0)
                rte_panic("Cannot init EAL\n");
 
+       testpmd_logtype = rte_log_register("testpmd");
+       if (testpmd_logtype < 0)
+               rte_panic("Cannot register log type");
+       rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
+
        if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
-               RTE_LOG(NOTICE, USER1, "mlockall() failed with error \"%s\"\n",
+               TESTPMD_LOG(NOTICE, "mlockall() failed with error \"%s\"\n",
                        strerror(errno));
        }
 
@@ -2391,7 +2370,7 @@ main(int argc, char** argv)
 
        nb_ports = (portid_t) rte_eth_dev_count();
        if (nb_ports == 0)
-               RTE_LOG(WARNING, EAL, "No probed ethernet devices\n");
+               TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
 
        /* allocate port structures, and init them */
        init_port();