net/e1000: fix link status update
[dpdk.git] / drivers / net / e1000 / em_ethdev.c
index fd44924..080cbe2 100644 (file)
@@ -35,16 +35,16 @@ static int eth_em_configure(struct rte_eth_dev *dev);
 static int eth_em_start(struct rte_eth_dev *dev);
 static void eth_em_stop(struct rte_eth_dev *dev);
 static void eth_em_close(struct rte_eth_dev *dev);
-static void eth_em_promiscuous_enable(struct rte_eth_dev *dev);
-static void eth_em_promiscuous_disable(struct rte_eth_dev *dev);
-static void eth_em_allmulticast_enable(struct rte_eth_dev *dev);
-static void eth_em_allmulticast_disable(struct rte_eth_dev *dev);
+static int eth_em_promiscuous_enable(struct rte_eth_dev *dev);
+static int eth_em_promiscuous_disable(struct rte_eth_dev *dev);
+static int eth_em_allmulticast_enable(struct rte_eth_dev *dev);
+static int eth_em_allmulticast_disable(struct rte_eth_dev *dev);
 static int eth_em_link_update(struct rte_eth_dev *dev,
                                int wait_to_complete);
 static int eth_em_stats_get(struct rte_eth_dev *dev,
                                struct rte_eth_stats *rte_stats);
-static void eth_em_stats_reset(struct rte_eth_dev *dev);
-static void eth_em_infos_get(struct rte_eth_dev *dev,
+static int eth_em_stats_reset(struct rte_eth_dev *dev);
+static int eth_em_infos_get(struct rte_eth_dev *dev,
                                struct rte_eth_dev_info *dev_info);
 static int eth_em_flow_ctrl_get(struct rte_eth_dev *dev,
                                struct rte_eth_fc_conf *fc_conf);
@@ -297,6 +297,11 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
        rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
                eth_dev->data->mac_addrs);
 
+       /* 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));
 
@@ -313,27 +318,12 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_em_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-       struct e1000_adapter *adapter =
-               E1000_DEV_PRIVATE(eth_dev->data->dev_private);
-       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
-
        PMD_INIT_FUNC_TRACE();
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return -EPERM;
 
-       if (adapter->stopped == 0)
-               eth_em_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(intr_handle);
-       rte_intr_callback_unregister(intr_handle,
-                                    eth_em_interrupt_handler, eth_dev);
+       eth_em_close(eth_dev);
 
        return 0;
 }
@@ -774,6 +764,8 @@ eth_em_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_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 
        eth_em_stop(dev);
        adapter->stopped = 1;
@@ -781,6 +773,15 @@ eth_em_close(struct rte_eth_dev *dev)
        e1000_phy_hw_reset(hw);
        em_release_manageability(hw);
        em_hw_control_release(hw);
+
+       dev->dev_ops = NULL;
+       dev->rx_pkt_burst = NULL;
+       dev->tx_pkt_burst = NULL;
+
+       /* disable uio intr before callback unregister */
+       rte_intr_disable(intr_handle);
+       rte_intr_callback_unregister(intr_handle,
+                                    eth_em_interrupt_handler, dev);
 }
 
 static int
@@ -984,7 +985,7 @@ eth_em_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
        return 0;
 }
 
-static void
+static int
 eth_em_stats_reset(struct rte_eth_dev *dev)
 {
        struct e1000_hw_stats *hw_stats =
@@ -995,6 +996,8 @@ eth_em_stats_reset(struct rte_eth_dev *dev)
 
        /* Reset software totals */
        memset(hw_stats, 0, sizeof(*hw_stats));
+
+       return 0;
 }
 
 static int
@@ -1048,7 +1051,7 @@ em_get_max_pktlen(struct rte_eth_dev *dev)
        }
 }
 
-static void
+static int
 eth_em_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
        struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -1107,6 +1110,8 @@ eth_em_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->default_txportconf.nb_queues = 1;
        dev_info->default_txportconf.ring_size = 256;
        dev_info->default_rxportconf.ring_size = 256;
+
+       return 0;
 }
 
 /* return 0 means link status changed, -1 means not changed */
@@ -1116,9 +1121,9 @@ eth_em_link_update(struct rte_eth_dev *dev, int wait_to_complete)
        struct e1000_hw *hw =
                E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
        struct rte_eth_link link;
-       int link_check, count;
+       int link_up, count;
 
-       link_check = 0;
+       link_up = 0;
        hw->mac.get_link_status = 1;
 
        /* possible wait-to-complete in up to 9 seconds */
@@ -1128,31 +1133,31 @@ eth_em_link_update(struct rte_eth_dev *dev, int wait_to_complete)
                case e1000_media_type_copper:
                        /* Do the work to read phy */
                        e1000_check_for_link(hw);
-                       link_check = !hw->mac.get_link_status;
+                       link_up = !hw->mac.get_link_status;
                        break;
 
                case e1000_media_type_fiber:
                        e1000_check_for_link(hw);
-                       link_check = (E1000_READ_REG(hw, E1000_STATUS) &
+                       link_up = (E1000_READ_REG(hw, E1000_STATUS) &
                                        E1000_STATUS_LU);
                        break;
 
                case e1000_media_type_internal_serdes:
                        e1000_check_for_link(hw);
-                       link_check = hw->mac.serdes_has_link;
+                       link_up = hw->mac.serdes_has_link;
                        break;
 
                default:
                        break;
                }
-               if (link_check || wait_to_complete == 0)
+               if (link_up || wait_to_complete == 0)
                        break;
                rte_delay_ms(EM_LINK_UPDATE_CHECK_INTERVAL);
        }
        memset(&link, 0, sizeof(link));
 
        /* Now we check if a transition has happened */
-       if (link_check && (link.link_status == ETH_LINK_DOWN)) {
+       if (link_up) {
                uint16_t duplex, speed;
                hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
                link.link_duplex = (duplex == FULL_DUPLEX) ?
@@ -1162,7 +1167,7 @@ eth_em_link_update(struct rte_eth_dev *dev, int wait_to_complete)
                link.link_status = ETH_LINK_UP;
                link.link_autoneg = !(dev->data->dev_conf.link_speeds &
                                ETH_LINK_SPEED_FIXED);
-       } else if (!link_check && (link.link_status == ETH_LINK_UP)) {
+       } else {
                link.link_speed = ETH_SPEED_NUM_NONE;
                link.link_duplex = ETH_LINK_HALF_DUPLEX;
                link.link_status = ETH_LINK_DOWN;
@@ -1261,7 +1266,7 @@ em_release_manageability(struct e1000_hw *hw)
        }
 }
 
-static void
+static int
 eth_em_promiscuous_enable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw =
@@ -1271,9 +1276,11 @@ eth_em_promiscuous_enable(struct rte_eth_dev *dev)
        rctl = E1000_READ_REG(hw, E1000_RCTL);
        rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
        E1000_WRITE_REG(hw, E1000_RCTL, rctl);
+
+       return 0;
 }
 
-static void
+static int
 eth_em_promiscuous_disable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw =
@@ -1287,9 +1294,11 @@ eth_em_promiscuous_disable(struct rte_eth_dev *dev)
        else
                rctl &= (~E1000_RCTL_MPE);
        E1000_WRITE_REG(hw, E1000_RCTL, rctl);
+
+       return 0;
 }
 
-static void
+static int
 eth_em_allmulticast_enable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw =
@@ -1299,9 +1308,11 @@ eth_em_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_em_allmulticast_disable(struct rte_eth_dev *dev)
 {
        struct e1000_hw *hw =
@@ -1309,10 +1320,12 @@ eth_em_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
@@ -1776,8 +1789,12 @@ eth_em_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        struct e1000_hw *hw;
        uint32_t frame_size;
        uint32_t rctl;
+       int ret;
+
+       ret = eth_em_infos_get(dev, &dev_info);
+       if (ret != 0)
+               return ret;
 
-       eth_em_infos_get(dev, &dev_info);
        frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
                VLAN_TAG_SIZE;