net/i40evf: fix packet loss for X722
[dpdk.git] / drivers / net / i40e / i40e_ethdev_vf.c
index 3dcd50c..0c9bd8d 100644 (file)
@@ -25,8 +25,8 @@
 #include <rte_eal.h>
 #include <rte_alarm.h>
 #include <rte_ether.h>
-#include <rte_ethdev_driver.h>
-#include <rte_ethdev_pci.h>
+#include <ethdev_driver.h>
+#include <ethdev_pci.h>
 #include <rte_malloc.h>
 #include <rte_dev.h>
 
@@ -74,7 +74,7 @@ enum i40evf_aq_result {
 
 static int i40evf_dev_configure(struct rte_eth_dev *dev);
 static int i40evf_dev_start(struct rte_eth_dev *dev);
-static void i40evf_dev_stop(struct rte_eth_dev *dev);
+static int i40evf_dev_stop(struct rte_eth_dev *dev);
 static int i40evf_dev_info_get(struct rte_eth_dev *dev,
                               struct rte_eth_dev_info *dev_info);
 static int i40evf_dev_link_update(struct rte_eth_dev *dev,
@@ -260,7 +260,7 @@ i40evf_read_pfmsg(struct rte_eth_dev *dev, struct i40evf_arq_msg_info *data)
                case VIRTCHNL_EVENT_RESET_IMPENDING:
                        vf->vf_reset = true;
                        vf->pend_msg |= PFMSG_RESET_IMPENDING;
-                       PMD_DRV_LOG(INFO, "vf is reseting");
+                       PMD_DRV_LOG(INFO, "VF is resetting");
                        break;
                case VIRTCHNL_EVENT_PF_DRIVER_CLOSE:
                        vf->dev_closed = true;
@@ -314,7 +314,7 @@ _atomic_set_cmd(struct i40e_vf *vf, enum virtchnl_ops ops)
 #define ASQ_DELAY_MS  10
 
 static int
-i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
+_i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
 {
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
@@ -405,6 +405,19 @@ i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
        return err | vf->cmd_retval;
 }
 
+static int
+i40evf_execute_vf_cmd(struct rte_eth_dev *dev, struct vf_cmd_info *args)
+{
+       struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+       int err;
+
+       while (!rte_spinlock_trylock(&vf->cmd_send_lock))
+               rte_delay_us_sleep(50);
+       err = _i40evf_execute_vf_cmd(dev, args);
+       rte_spinlock_unlock(&vf->cmd_send_lock);
+       return err;
+}
+
 /*
  * Check API version with sync wait until version read or fail from admin queue
  */
@@ -1065,8 +1078,18 @@ i40evf_add_vlan(struct rte_eth_dev *dev, uint16_t vlanid)
        args.out_buffer = vf->aq_resp;
        args.out_size = I40E_AQ_BUF_SZ;
        err = i40evf_execute_vf_cmd(dev, &args);
-       if (err)
+       if (err) {
                PMD_DRV_LOG(ERR, "fail to execute command OP_ADD_VLAN");
+               return err;
+       }
+       /**
+        * In linux kernel driver on receiving ADD_VLAN it enables
+        * VLAN_STRIP by default. So reconfigure the vlan_offload
+        * as it was done by the app earlier.
+        */
+       err = i40evf_vlan_offload_set(dev, ETH_VLAN_STRIP_MASK);
+       if (err)
+               PMD_DRV_LOG(ERR, "fail to set vlan_strip");
 
        return err;
 }
@@ -1246,6 +1269,7 @@ i40evf_init_vf(struct rte_eth_dev *dev)
 
        vf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
        vf->dev_data = dev->data;
+       rte_spinlock_init(&vf->cmd_send_lock);
        err = i40e_set_mac_type(hw);
        if (err) {
                PMD_INIT_LOG(ERR, "set_mac_type failed: %d", err);
@@ -1481,7 +1505,8 @@ i40evf_handle_aq_msg(struct rte_eth_dev *dev)
                                                       info.msg_len);
                        else {
                                /* read message and it's expected one */
-                               if (msg_opc == vf->pend_cmd) {
+                               if ((volatile uint32_t)msg_opc ==
+                                   vf->pend_cmd) {
                                        vf->cmd_retval = msg_ret;
                                        /* prevent compiler reordering */
                                        rte_compiler_barrier();
@@ -1575,6 +1600,7 @@ i40evf_dev_init(struct rte_eth_dev *eth_dev)
        }
        i40e_set_default_ptype_table(eth_dev);
        rte_eth_copy_pci_info(eth_dev, pci_dev);
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
 
        hw->vendor_id = pci_dev->id.vendor_id;
        hw->device_id = pci_dev->id.device_id;
@@ -1874,22 +1900,22 @@ i40evf_rxq_init(struct rte_eth_dev *dev, struct i40e_rx_queue *rxq)
         * Check if the jumbo frame and maximum packet length are set correctly
         */
        if (dev_data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
-               if (rxq->max_pkt_len <= RTE_ETHER_MAX_LEN ||
+               if (rxq->max_pkt_len <= I40E_ETH_MAX_LEN ||
                    rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
                        PMD_DRV_LOG(ERR, "maximum packet length must be "
                                "larger than %u and smaller than %u, as jumbo "
-                               "frame is enabled", (uint32_t)RTE_ETHER_MAX_LEN,
+                               "frame is enabled", (uint32_t)I40E_ETH_MAX_LEN,
                                        (uint32_t)I40E_FRAME_SIZE_MAX);
                        return I40E_ERR_CONFIG;
                }
        } else {
                if (rxq->max_pkt_len < RTE_ETHER_MIN_LEN ||
-                   rxq->max_pkt_len > RTE_ETHER_MAX_LEN) {
+                   rxq->max_pkt_len > I40E_ETH_MAX_LEN) {
                        PMD_DRV_LOG(ERR, "maximum packet length must be "
                                "larger than %u and smaller than %u, as jumbo "
                                "frame is disabled",
                                (uint32_t)RTE_ETHER_MIN_LEN,
-                               (uint32_t)RTE_ETHER_MAX_LEN);
+                               (uint32_t)I40E_ETH_MAX_LEN);
                        return I40E_ERR_CONFIG;
                }
        }
@@ -2176,7 +2202,7 @@ err_queue:
        return -1;
 }
 
-static void
+static int
 i40evf_dev_stop(struct rte_eth_dev *dev)
 {
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
@@ -2190,7 +2216,7 @@ i40evf_dev_stop(struct rte_eth_dev *dev)
                rte_intr_disable(intr_handle);
 
        if (hw->adapter_stopped == 1)
-               return;
+               return 0;
        i40evf_stop_queues(dev);
        i40evf_disable_queues_intr(dev);
        i40e_dev_clear_queues(dev);
@@ -2208,6 +2234,8 @@ i40evf_dev_stop(struct rte_eth_dev *dev)
                                FALSE);
        hw->adapter_stopped = 1;
        dev->data->dev_started = 0;
+
+       return 0;
 }
 
 static int
@@ -2389,6 +2417,7 @@ i40evf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
                stats->imissed = pstats->rx_discards;
                stats->oerrors = pstats->tx_errors + pstats->tx_discards;
                stats->ibytes = pstats->rx_bytes;
+               stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
                stats->obytes = pstats->tx_bytes;
        } else {
                PMD_DRV_LOG(ERR, "Get statistics failed");
@@ -2401,11 +2430,13 @@ i40evf_dev_close(struct rte_eth_dev *dev)
 {
        struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(dev->data->dev_private);
+       int ret;
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
-       i40evf_dev_stop(dev);
+       ret = i40evf_dev_stop(dev);
+
        i40e_dev_free_queues(dev);
        /*
         * disable promiscuous mode before reset vf
@@ -2427,7 +2458,7 @@ i40evf_dev_close(struct rte_eth_dev *dev)
        vf->aq_resp = NULL;
 
        hw->adapter_closed = 1;
-       return 0;
+       return ret;
 }
 
 /*
@@ -2715,7 +2746,7 @@ i40evf_config_rss(struct i40e_vf *vf)
                }
 
                for (i = 0; i < rss_lut_size; i++)
-                       lut_info[i] = i % vf->num_queue_pairs;
+                       lut_info[i] = i % num;
 
                ret = i40evf_set_rss_lut(&vf->vsi, lut_info,
                                         rss_lut_size);
@@ -2806,7 +2837,7 @@ i40evf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
                return -EBUSY;
        }
 
-       if (frame_size > RTE_ETHER_MAX_LEN)
+       if (frame_size > I40E_ETH_MAX_LEN)
                dev_data->dev_conf.rxmode.offloads |=
                        DEV_RX_OFFLOAD_JUMBO_FRAME;
        else