app/testpmd: check if CRC strip offload supported
[dpdk.git] / app / test-pmd / testpmd.c
index 40880ec..1344016 100644 (file)
@@ -671,6 +671,7 @@ init_config(void)
        uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
        struct rte_gro_param gro_param;
        uint32_t gso_types;
+       int k;
 
        memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -705,6 +706,11 @@ init_config(void)
                port->dev_conf.txmode = tx_mode;
                port->dev_conf.rxmode = rx_mode;
                rte_eth_dev_info_get(pid, &port->dev_info);
+
+               if (!(port->dev_info.rx_offload_capa &
+                                       DEV_RX_OFFLOAD_CRC_STRIP))
+                       port->dev_conf.rxmode.offloads &=
+                               ~DEV_RX_OFFLOAD_CRC_STRIP;
                if (!(port->dev_info.tx_offload_capa &
                      DEV_TX_OFFLOAD_MBUF_FAST_FREE))
                        port->dev_conf.txmode.offloads &=
@@ -722,6 +728,15 @@ init_config(void)
                        }
                }
 
+               /* Apply Rx offloads configuration */
+               for (k = 0; k < port->dev_info.max_rx_queues; k++)
+                       port->rx_conf[k].offloads =
+                               port->dev_conf.rxmode.offloads;
+               /* Apply Tx offloads configuration */
+               for (k = 0; k < port->dev_info.max_tx_queues; k++)
+                       port->tx_conf[k].offloads =
+                               port->dev_conf.txmode.offloads;
+
                /* set flag to initialize port/queue */
                port->need_reconfig = 1;
                port->need_reconfig_queues = 1;
@@ -1218,6 +1233,31 @@ launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
        }
 }
 
+/*
+ * Update the forward ports list.
+ */
+void
+update_fwd_ports(portid_t new_pid)
+{
+       unsigned int i;
+       unsigned int new_nb_fwd_ports = 0;
+       int move = 0;
+
+       for (i = 0; i < nb_fwd_ports; ++i) {
+               if (port_id_is_invalid(fwd_ports_ids[i], DISABLED_WARN))
+                       move = 1;
+               else if (move)
+                       fwd_ports_ids[new_nb_fwd_ports++] = fwd_ports_ids[i];
+               else
+                       new_nb_fwd_ports++;
+       }
+       if (new_pid < RTE_MAX_ETHPORTS)
+               fwd_ports_ids[new_nb_fwd_ports++] = new_pid;
+
+       nb_fwd_ports = new_nb_fwd_ports;
+       nb_cfg_ports = new_nb_fwd_ports;
+}
+
 /*
  * Launch packet forwarding configuration.
  */
@@ -1604,9 +1644,6 @@ start_port(portid_t pid)
                        for (qi = 0; qi < nb_txq; qi++) {
                                port->tx_conf[qi].txq_flags =
                                        ETH_TXQ_FLAGS_IGNORE;
-                               /* Apply Tx offloads configuration */
-                               port->tx_conf[qi].offloads =
-                                       port->dev_conf.txmode.offloads;
                                if ((numa_support) &&
                                        (txring_numa[pi] != NUMA_NO_CONFIG))
                                        diag = rte_eth_tx_queue_setup(pi, qi,
@@ -1635,9 +1672,6 @@ start_port(portid_t pid)
                                return -1;
                        }
                        for (qi = 0; qi < nb_rxq; qi++) {
-                               /* Apply Rx offloads configuration */
-                               port->rx_conf[qi].offloads =
-                                       port->dev_conf.rxmode.offloads;
                                /* setup rx queues */
                                if ((numa_support) &&
                                        (rxring_numa[pi] != NUMA_NO_CONFIG)) {
@@ -1938,6 +1972,8 @@ attach_port(char *identifier)
 
        ports[pi].port_status = RTE_PORT_STOPPED;
 
+       update_fwd_ports(pi);
+
        printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);
        printf("Done\n");
 }
@@ -1958,14 +1994,16 @@ detach_port(portid_t port_id)
                port_flow_flush(port_id);
 
        if (rte_eth_dev_detach(port_id, name)) {
-               TESTPMD_LOG(ERR, "Failed to detach port '%s'\n", name);
+               TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id);
                return;
        }
 
        nb_ports = rte_eth_dev_count_avail();
 
-       printf("Port '%s' is detached. Now total ports is %d\n",
-                       name, nb_ports);
+       update_fwd_ports(RTE_MAX_ETHPORTS);
+
+       printf("Port %u is detached. Now total ports is %d\n",
+                       port_id, nb_ports);
        printf("Done\n");
        return;
 }
@@ -2071,18 +2109,23 @@ check_all_ports_link_status(uint32_t port_mask)
 static void
 rmv_event_callback(void *arg)
 {
-       struct rte_eth_dev *dev;
+       int need_to_start = 0;
+       int org_no_link_check = no_link_check;
        portid_t port_id = (intptr_t)arg;
 
        RTE_ETH_VALID_PORTID_OR_RET(port_id);
-       dev = &rte_eth_devices[port_id];
 
+       if (!test_done && port_is_forwarding(port_id)) {
+               need_to_start = 1;
+               stop_packet_forwarding();
+       }
+       no_link_check = 1;
        stop_port(port_id);
+       no_link_check = org_no_link_check;
        close_port(port_id);
-       printf("removing device %s\n", dev->device->name);
-       if (rte_eal_dev_detach(dev->device))
-               TESTPMD_LOG(ERR, "Failed to detach device %s\n",
-                       dev->device->name);
+       detach_port(port_id);
+       if (need_to_start)
+               start_packet_forwarding(0);
 }
 
 /* This function is used by the interrupt thread */
@@ -2476,12 +2519,8 @@ init_port_dcb_config(portid_t pid,
                return retval;
        port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_FILTER;
 
-       /**
-        * Write the configuration into the device.
-        * Set the numbers of RX & TX queues to 0, so
-        * the RX & TX queues will not be setup.
-        */
-       rte_eth_dev_configure(pid, 0, 0, &port_conf);
+       /* re-configure the device . */
+       rte_eth_dev_configure(pid, nb_rxq, nb_rxq, &port_conf);
 
        rte_eth_dev_info_get(pid, &rte_port->dev_info);
 
@@ -2612,6 +2651,23 @@ main(int argc, char** argv)
                rte_panic("Cannot register log type");
        rte_log_set_level(testpmd_logtype, RTE_LOG_DEBUG);
 
+#ifdef RTE_LIBRTE_PDUMP
+       /* initialize packet capture framework */
+       rte_pdump_init(NULL);
+#endif
+
+       nb_ports = (portid_t) rte_eth_dev_count_avail();
+       if (nb_ports == 0)
+               TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
+
+       /* allocate port structures, and init them */
+       init_port();
+
+       set_def_fwd_config();
+       if (nb_lcores == 0)
+               rte_panic("Empty set of forwarding logical cores - check the "
+                         "core mask supplied in the command parameters\n");
+
        /* Bitrate/latency stats disabled by default */
 #ifdef RTE_LIBRTE_BITRATE
        bitrate_enabled = 0;
@@ -2637,23 +2693,6 @@ main(int argc, char** argv)
                        strerror(errno));
        }
 
-#ifdef RTE_LIBRTE_PDUMP
-       /* initialize packet capture framework */
-       rte_pdump_init(NULL);
-#endif
-
-       nb_ports = (portid_t) rte_eth_dev_count_avail();
-       if (nb_ports == 0)
-               TESTPMD_LOG(WARNING, "No probed ethernet devices\n");
-
-       /* allocate port structures, and init them */
-       init_port();
-
-       set_def_fwd_config();
-       if (nb_lcores == 0)
-               rte_panic("Empty set of forwarding logical cores - check the "
-                         "core mask supplied in the command parameters\n");
-
        if (tx_first && interactive)
                rte_exit(EXIT_FAILURE, "--tx-first cannot be used on "
                                "interactive mode.\n");