net/bnxt: support 58818 chip family
[dpdk.git] / drivers / net / i40e / i40e_ethdev_vf.c
index 4d6510d..dc076ae 100644 (file)
@@ -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);
@@ -1575,6 +1599,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;
@@ -2176,7 +2201,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 +2215,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);
@@ -2207,7 +2232,9 @@ i40evf_dev_stop(struct rte_eth_dev *dev)
        i40evf_add_del_mc_addr_list(dev, vf->mc_addrs, vf->mc_addrs_num,
                                FALSE);
        hw->adapter_stopped = 1;
+       dev->data->dev_started = 0;
 
+       return 0;
 }
 
 static int
@@ -2389,6 +2416,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 +2429,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
@@ -2421,17 +2451,13 @@ i40evf_dev_close(struct rte_eth_dev *dev)
        i40e_shutdown_adminq(hw);
        i40evf_disable_irq0(hw);
 
-       dev->dev_ops = NULL;
-       dev->rx_pkt_burst = NULL;
-       dev->tx_pkt_burst = NULL;
-
        rte_free(vf->vf_res);
        vf->vf_res = NULL;
        rte_free(vf->aq_resp);
        vf->aq_resp = NULL;
 
        hw->adapter_closed = 1;
-       return 0;
+       return ret;
 }
 
 /*