Commit 814da63c authored by Huazhong Tan's avatar Huazhong Tan Committed by David S. Miller

net: hns3: use HNS3_NIC_STATE_INITED to indicate the initialization state of enet

Besides of module_init and module_exit, the process of reset will
also uninitialize and initialize the enet client. When reset process
fails with enet client uninitialized, the module_exit does not need
to uninitialize the enet client, otherwise it may cause double
uninitialization problem.

So we need the HNS3_NIC_STATE_INITED flag to indicate whether
the enet client is initialized.

Also HNS3_NIC_STATE_REINITING is previously unused, so change it to
HNS3_NIC_STATE_INITED.

Fixes: bb6b94a8 ("net: hns3: Add reset interface implementation in client")
Signed-off-by: default avatarHuazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7c588c74
...@@ -3397,6 +3397,8 @@ static int hns3_client_init(struct hnae3_handle *handle) ...@@ -3397,6 +3397,8 @@ static int hns3_client_init(struct hnae3_handle *handle)
/* MTU range: (ETH_MIN_MTU(kernel default) - 9706) */ /* MTU range: (ETH_MIN_MTU(kernel default) - 9706) */
netdev->max_mtu = HNS3_MAX_MTU - (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); netdev->max_mtu = HNS3_MAX_MTU - (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
set_bit(HNS3_NIC_STATE_INITED, &priv->state);
return ret; return ret;
out_reg_netdev_fail: out_reg_netdev_fail:
...@@ -3423,6 +3425,11 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset) ...@@ -3423,6 +3425,11 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset)
if (netdev->reg_state != NETREG_UNINITIALIZED) if (netdev->reg_state != NETREG_UNINITIALIZED)
unregister_netdev(netdev); unregister_netdev(netdev);
if (!test_and_clear_bit(HNS3_NIC_STATE_INITED, &priv->state)) {
netdev_warn(netdev, "already uninitialized\n");
goto out_netdev_free;
}
hns3_del_all_fd_rules(netdev, true); hns3_del_all_fd_rules(netdev, true);
hns3_force_clear_all_rx_ring(handle); hns3_force_clear_all_rx_ring(handle);
...@@ -3443,6 +3450,7 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset) ...@@ -3443,6 +3450,7 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset)
priv->ring_data = NULL; priv->ring_data = NULL;
out_netdev_free:
free_netdev(netdev); free_netdev(netdev);
} }
...@@ -3782,6 +3790,8 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle) ...@@ -3782,6 +3790,8 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle)
priv->ring_data = NULL; priv->ring_data = NULL;
} }
set_bit(HNS3_NIC_STATE_INITED, &priv->state);
return ret; return ret;
} }
...@@ -3792,6 +3802,11 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle) ...@@ -3792,6 +3802,11 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
struct hns3_nic_priv *priv = netdev_priv(netdev); struct hns3_nic_priv *priv = netdev_priv(netdev);
int ret; int ret;
if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state)) {
netdev_warn(netdev, "already uninitialized\n");
return 0;
}
hns3_force_clear_all_rx_ring(handle); hns3_force_clear_all_rx_ring(handle);
ret = hns3_nic_uninit_vector_data(priv); ret = hns3_nic_uninit_vector_data(priv);
...@@ -3815,6 +3830,8 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle) ...@@ -3815,6 +3830,8 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
hns3_del_all_fd_rules(netdev, false); hns3_del_all_fd_rules(netdev, false);
} }
clear_bit(HNS3_NIC_STATE_INITED, &priv->state);
return ret; return ret;
} }
......
...@@ -15,7 +15,7 @@ extern const char hns3_driver_version[]; ...@@ -15,7 +15,7 @@ extern const char hns3_driver_version[];
enum hns3_nic_state { enum hns3_nic_state {
HNS3_NIC_STATE_TESTING, HNS3_NIC_STATE_TESTING,
HNS3_NIC_STATE_RESETTING, HNS3_NIC_STATE_RESETTING,
HNS3_NIC_STATE_REINITING, HNS3_NIC_STATE_INITED,
HNS3_NIC_STATE_DOWN, HNS3_NIC_STATE_DOWN,
HNS3_NIC_STATE_DISABLED, HNS3_NIC_STATE_DISABLED,
HNS3_NIC_STATE_REMOVING, HNS3_NIC_STATE_REMOVING,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment