net/e1000: fix link status
[dpdk.git] / drivers / net / e1000 / igb_ethdev.c
index a9f6de5..a3e30db 100644 (file)
@@ -81,8 +81,8 @@ static void eth_igb_close(struct rte_eth_dev *dev);
 static int eth_igb_reset(struct rte_eth_dev *dev);
 static int  eth_igb_promiscuous_enable(struct rte_eth_dev *dev);
 static int  eth_igb_promiscuous_disable(struct rte_eth_dev *dev);
-static void eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
-static void eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
+static int  eth_igb_allmulticast_enable(struct rte_eth_dev *dev);
+static int  eth_igb_allmulticast_disable(struct rte_eth_dev *dev);
 static int  eth_igb_link_update(struct rte_eth_dev *dev,
                                int wait_to_complete);
 static int eth_igb_stats_get(struct rte_eth_dev *dev,
@@ -98,8 +98,8 @@ static int eth_igb_xstats_get_names(struct rte_eth_dev *dev,
 static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,
                struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
                unsigned int limit);
-static void eth_igb_stats_reset(struct rte_eth_dev *dev);
-static void eth_igb_xstats_reset(struct rte_eth_dev *dev);
+static int eth_igb_stats_reset(struct rte_eth_dev *dev);
+static int eth_igb_xstats_reset(struct rte_eth_dev *dev);
 static int eth_igb_fw_version_get(struct rte_eth_dev *dev,
                                   char *fw_version, size_t fw_size);
 static int eth_igb_infos_get(struct rte_eth_dev *dev,
@@ -158,8 +158,8 @@ static void igbvf_dev_stop(struct rte_eth_dev *dev);
 static void igbvf_dev_close(struct rte_eth_dev *dev);
 static int igbvf_promiscuous_enable(struct rte_eth_dev *dev);
 static int igbvf_promiscuous_disable(struct rte_eth_dev *dev);
-static void igbvf_allmulticast_enable(struct rte_eth_dev *dev);
-static void igbvf_allmulticast_disable(struct rte_eth_dev *dev);
+static int igbvf_allmulticast_enable(struct rte_eth_dev *dev);
+static int igbvf_allmulticast_disable(struct rte_eth_dev *dev);
 static int eth_igbvf_link_update(struct e1000_hw *hw);
 static int eth_igbvf_stats_get(struct rte_eth_dev *dev,
                                struct rte_eth_stats *rte_stats);
@@ -168,7 +168,7 @@ static int eth_igbvf_xstats_get(struct rte_eth_dev *dev,
 static int eth_igbvf_xstats_get_names(struct rte_eth_dev *dev,
                                      struct rte_eth_xstat_name *xstats_names,
                                      unsigned limit);
-static void eth_igbvf_stats_reset(struct rte_eth_dev *dev);
+static int eth_igbvf_stats_reset(struct rte_eth_dev *dev);
 static int igbvf_vlan_filter_set(struct rte_eth_dev *dev,
                uint16_t vlan_id, int on);
 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on);
@@ -843,6 +843,11 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
        rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
                        &eth_dev->data->mac_addrs[0]);
 
+       /* Pass the information to the rte_eth_dev_close() that it should also
+        * release the private port resources.
+        */
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
        /* initialize the vfta */
        memset(shadow_vfta, 0, sizeof(*shadow_vfta));
 
@@ -886,6 +891,8 @@ eth_igb_dev_init(struct rte_eth_dev *eth_dev)
        /* enable support intr */
        igb_intr_enable(eth_dev);
 
+       eth_igb_dev_set_link_down(eth_dev);
+
        /* initialize filter info */
        memset(filter_info, 0,
               sizeof(struct e1000_filter_info));
@@ -912,61 +919,12 @@ err_late:
 static int
 eth_igb_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-       struct rte_pci_device *pci_dev;
-       struct rte_intr_handle *intr_handle;
-       struct e1000_hw *hw;
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(eth_dev->data->dev_private);
-       struct e1000_filter_info *filter_info =
-               E1000_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
-
        PMD_INIT_FUNC_TRACE();
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return -EPERM;
 
-       hw = E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
-       pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-       intr_handle = &pci_dev->intr_handle;
-
-       if (adapter->stopped == 0)
-               eth_igb_close(eth_dev);
-
-       eth_dev->dev_ops = NULL;
-       eth_dev->rx_pkt_burst = NULL;
-       eth_dev->tx_pkt_burst = NULL;
-
-       /* Reset any pending lock */
-       igb_reset_swfw_lock(hw);
-
-       /* uninitialize PF if max_vfs not zero */
-       igb_pf_host_uninit(eth_dev);
-
-       /* disable uio intr before callback unregister */
-       rte_intr_disable(intr_handle);
-       rte_intr_callback_unregister(intr_handle,
-                                    eth_igb_interrupt_handler, eth_dev);
-
-       /* clear the SYN filter info */
-       filter_info->syn_info = 0;
-
-       /* clear the ethertype filters info */
-       filter_info->ethertype_mask = 0;
-       memset(filter_info->ethertype_filters, 0,
-               E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
-
-       /* clear the rss filter info */
-       memset(&filter_info->rss_info, 0,
-               sizeof(struct igb_rte_flow_rss_conf));
-
-       /* remove all ntuple filters of the device */
-       igb_ntuple_filter_uninit(eth_dev);
-
-       /* remove all flex filters of the device */
-       igb_flex_filter_uninit(eth_dev);
-
-       /* clear all the filters list */
-       igb_filterlist_flush(eth_dev);
+       eth_igb_close(eth_dev);
 
        return 0;
 }
@@ -1038,6 +996,11 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
                return -ENOMEM;
        }
 
+       /* Pass the information to the rte_eth_dev_close() that it should also
+        * release the private port resources.
+        */
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
        /* Generate a random MAC address, if none was assigned by PF. */
        if (rte_is_zero_ether_addr(perm_addr)) {
                rte_eth_random_addr(perm_addr->addr_bytes);
@@ -1077,27 +1040,12 @@ eth_igbvf_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_igbvf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(eth_dev->data->dev_private);
-       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-
        PMD_INIT_FUNC_TRACE();
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return -EPERM;
 
-       if (adapter->stopped == 0)
-               igbvf_dev_close(eth_dev);
-
-       eth_dev->dev_ops = NULL;
-       eth_dev->rx_pkt_burst = NULL;
-       eth_dev->tx_pkt_burst = NULL;
-
-       /* disable uio intr before callback unregister */
-       rte_intr_disable(&pci_dev->intr_handle);
-       rte_intr_callback_unregister(&pci_dev->intr_handle,
-                                    eth_igbvf_interrupt_handler,
-                                    (void *)eth_dev);
+       igbvf_dev_close(eth_dev);
 
        return 0;
 }
@@ -1236,6 +1184,9 @@ eth_igb_configure(struct rte_eth_dev *dev)
 
        PMD_INIT_FUNC_TRACE();
 
+       if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
+               dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
+
        /* multipe queue mode checking */
        ret  = igb_check_mq_mode(dev);
        if (ret != 0) {
@@ -1506,6 +1457,11 @@ eth_igb_stop(struct rte_eth_dev *dev)
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        struct rte_eth_link link;
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct e1000_adapter *adapter =
+               E1000_DEV_PRIVATE(dev->data->dev_private);
+
+       if (adapter->stopped)
+               return;
 
        eth_igb_rxtx_control(dev, false);
 
@@ -1517,8 +1473,9 @@ eth_igb_stop(struct rte_eth_dev *dev)
        igb_pf_reset_hw(hw);
        E1000_WRITE_REG(hw, E1000_WUC, 0);
 
-       /* Set bit for Go Link disconnect */
-       if (hw->mac.type >= e1000_82580) {
+       /* Set bit for Go Link disconnect if PHY reset is not blocked */
+       if (hw->mac.type >= e1000_82580 &&
+           (e1000_check_reset_block(hw) != E1000_BLK_PHY_RESET)) {
                uint32_t phpm_reg;
 
                phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
@@ -1547,6 +1504,8 @@ eth_igb_stop(struct rte_eth_dev *dev)
                rte_free(intr_handle->intr_vec);
                intr_handle->intr_vec = NULL;
        }
+
+       adapter->stopped = true;
 }
 
 static int
@@ -1579,21 +1538,21 @@ static void
 eth_igb_close(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(dev->data->dev_private);
        struct rte_eth_link link;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct e1000_filter_info *filter_info =
+               E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
 
        eth_igb_stop(dev);
-       adapter->stopped = 1;
 
        e1000_phy_hw_reset(hw);
        igb_release_manageability(hw);
        igb_hw_control_release(hw);
 
-       /* Clear bit for Go Link disconnect */
-       if (hw->mac.type >= e1000_82580) {
+       /* Clear bit for Go Link disconnect if PHY reset is not blocked */
+       if (hw->mac.type >= e1000_82580 &&
+           (e1000_check_reset_block(hw) != E1000_BLK_PHY_RESET)) {
                uint32_t phpm_reg;
 
                phpm_reg = E1000_READ_REG(hw, E1000_82580_PHY_POWER_MGMT);
@@ -1610,6 +1569,40 @@ eth_igb_close(struct rte_eth_dev *dev)
 
        memset(&link, 0, sizeof(link));
        rte_eth_linkstatus_set(dev, &link);
+
+       dev->dev_ops = NULL;
+       dev->rx_pkt_burst = NULL;
+       dev->tx_pkt_burst = NULL;
+
+       /* Reset any pending lock */
+       igb_reset_swfw_lock(hw);
+
+       /* uninitialize PF if max_vfs not zero */
+       igb_pf_host_uninit(dev);
+
+       rte_intr_callback_unregister(intr_handle,
+                                    eth_igb_interrupt_handler, dev);
+
+       /* clear the SYN filter info */
+       filter_info->syn_info = 0;
+
+       /* clear the ethertype filters info */
+       filter_info->ethertype_mask = 0;
+       memset(filter_info->ethertype_filters, 0,
+               E1000_MAX_ETQF_FILTERS * sizeof(struct igb_ethertype_filter));
+
+       /* clear the rss filter info */
+       memset(&filter_info->rss_info, 0,
+               sizeof(struct igb_rte_flow_rss_conf));
+
+       /* remove all ntuple filters of the device */
+       igb_ntuple_filter_uninit(dev);
+
+       /* remove all flex filters of the device */
+       igb_flex_filter_uninit(dev);
+
+       /* clear all the filters list */
+       igb_filterlist_flush(dev);
 }
 
 /*
@@ -1870,7 +1863,7 @@ eth_igb_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
        return 0;
 }
 
-static void
+static int
 eth_igb_stats_reset(struct rte_eth_dev *dev)
 {
        struct e1000_hw_stats *hw_stats =
@@ -1881,9 +1874,11 @@ eth_igb_stats_reset(struct rte_eth_dev *dev)
 
        /* Reset software totals */
        memset(hw_stats, 0, sizeof(*hw_stats));
+
+       return 0;
 }
 
-static void
+static int
 eth_igb_xstats_reset(struct rte_eth_dev *dev)
 {
        struct e1000_hw_stats *stats =
@@ -1894,6 +1889,8 @@ eth_igb_xstats_reset(struct rte_eth_dev *dev)
 
        /* Reset software totals */
        memset(stats, 0, sizeof(*stats));
+
+       return 0;
 }
 
 static int eth_igb_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
@@ -2127,7 +2124,7 @@ eth_igbvf_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
        return 0;
 }
 
-static void
+static int
 eth_igbvf_stats_reset(struct rte_eth_dev *dev)
 {
        struct e1000_vf_stats *hw_stats = (struct e1000_vf_stats*)
@@ -2139,6 +2136,8 @@ eth_igbvf_stats_reset(struct rte_eth_dev *dev)
        /* reset HW current stats*/
        memset(&hw_stats->gprc, 0, sizeof(*hw_stats) -
               offsetof(struct e1000_vf_stats, gprc));
+
+       return 0;
 }
 
 static int
@@ -2551,7 +2550,7 @@ eth_igb_promiscuous_disable(struct rte_eth_dev *dev)
        return 0;
 }
 
-static void
+static int
 eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw =
@@ -2561,9 +2560,11 @@ eth_igb_allmulticast_enable(struct rte_eth_dev *dev)
        rctl = E1000_READ_REG(hw, E1000_RCTL);
        rctl |= E1000_RCTL_MPE;
        E1000_WRITE_REG(hw, E1000_RCTL, rctl);
+
+       return 0;
 }
 
-static void
+static int
 eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw =
@@ -2571,10 +2572,12 @@ eth_igb_allmulticast_disable(struct rte_eth_dev *dev)
        uint32_t rctl;
 
        if (dev->data->promiscuous == 1)
-               return; /* must remain in all_multicast mode */
+               return 0; /* must remain in all_multicast mode */
        rctl = E1000_READ_REG(hw, E1000_RCTL);
        rctl &= (~E1000_RCTL_MPE);
        E1000_WRITE_REG(hw, E1000_RCTL, rctl);
+
+       return 0;
 }
 
 static int
@@ -3259,6 +3262,9 @@ igbvf_dev_configure(struct rte_eth_dev *dev)
        PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
                     dev->data->port_id);
 
+       if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
+               dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
+
        /*
         * VF has no ability to enable/disable HW CRC
         * Keep the persistent behavior the same as Host PF
@@ -3344,6 +3350,11 @@ igbvf_dev_stop(struct rte_eth_dev *dev)
 {
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+       struct e1000_adapter *adapter =
+               E1000_DEV_PRIVATE(dev->data->dev_private);
+
+       if (adapter->stopped)
+               return;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -3366,22 +3377,23 @@ igbvf_dev_stop(struct rte_eth_dev *dev)
                rte_free(intr_handle->intr_vec);
                intr_handle->intr_vec = NULL;
        }
+
+       adapter->stopped = true;
 }
 
 static void
 igbvf_dev_close(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(dev->data->dev_private);
        struct rte_ether_addr addr;
+       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 
        PMD_INIT_FUNC_TRACE();
 
        e1000_reset_hw(hw);
 
        igbvf_dev_stop(dev);
-       adapter->stopped = 1;
+
        igb_dev_free_queues(dev);
 
        /**
@@ -3392,6 +3404,14 @@ igbvf_dev_close(struct rte_eth_dev *dev)
 
        memset(&addr, 0, sizeof(addr));
        igbvf_default_mac_addr_set(dev, &addr);
+
+       dev->dev_ops = NULL;
+       dev->rx_pkt_burst = NULL;
+       dev->tx_pkt_burst = NULL;
+
+       rte_intr_callback_unregister(&pci_dev->intr_handle,
+                                    eth_igbvf_interrupt_handler,
+                                    (void *)dev);
 }
 
 static int
@@ -3419,7 +3439,7 @@ igbvf_promiscuous_disable(struct rte_eth_dev *dev)
        return 0;
 }
 
-static void
+static int
 igbvf_allmulticast_enable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -3427,9 +3447,11 @@ igbvf_allmulticast_enable(struct rte_eth_dev *dev)
        /* In promiscuous mode multicast promisc already set */
        if (dev->data->promiscuous == 0)
                e1000_promisc_set_vf(hw, e1000_promisc_multicast);
+
+       return 0;
 }
 
-static void
+static int
 igbvf_allmulticast_disable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -3437,6 +3459,8 @@ igbvf_allmulticast_disable(struct rte_eth_dev *dev)
        /* In promiscuous mode leave multicast promisc enabled */
        if (dev->data->promiscuous == 0)
                e1000_promisc_set_vf(hw, e1000_promisc_disabled);
+
+       return 0;
 }
 
 static int igbvf_set_vfta(struct e1000_hw *hw, uint16_t vid, bool on)