net: hns3: Mask the packet statistics query when NIC is down
authorJian Shen <shenjian15@huawei.com>
Fri, 5 Jan 2018 10:18:11 +0000 (18:18 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 Jan 2018 19:06:18 +0000 (14:06 -0500)
Update the HNS3_NIC_STATE_DOWN bit when NIC state changes.
When NIC is down, mask the packet statistics for querying
with ifconfig command. It's a common practice.

Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

index 79c5daa..a8e4406 100644 (file)
@@ -247,6 +247,8 @@ static int hns3_nic_net_up(struct net_device *netdev)
        if (ret)
                goto out_start_err;
 
+       clear_bit(HNS3_NIC_STATE_DOWN, &priv->state);
+
        return 0;
 
 out_start_err:
@@ -286,6 +288,9 @@ static void hns3_nic_net_down(struct net_device *netdev)
        const struct hnae3_ae_ops *ops;
        int i;
 
+       if (test_and_set_bit(HNS3_NIC_STATE_DOWN, &priv->state))
+               return;
+
        /* stop ae_dev */
        ops = priv->ae_handle->ae_algo->ops;
        if (ops->stop)
@@ -1135,6 +1140,9 @@ hns3_nic_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
        u64 tx_pkts = 0;
        u64 rx_pkts = 0;
 
+       if (test_bit(HNS3_NIC_STATE_DOWN, &priv->state))
+               return;
+
        handle->ae_algo->ops->update_stats(handle, &netdev->stats);
 
        for (idx = 0; idx < queue_num; idx++) {