提交 0ccc85ed 编写于 作者: H Huazhong Tan 提交者: Xie XiuQi

net: hns3: unify ring clearing function

driver inclusion
category: bugfix
bugzilla: NA
CVE: NA

There are two function to clear ring buffer, which is a little
duplicated. So this patch combines them into one function, also
adds a new function to reset the TX queue.

Feature or Bugfix:Bugfix
Signed-off-by: NHuazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Nliweihang <liweihang@huawei.com>
Reviewed-by: Nlipeng <lipeng321@huawei.com>
Reviewed-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 f6d0c3aa
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#define hns3_set_field(origin, shift, val) ((origin) |= ((val) << (shift))) #define hns3_set_field(origin, shift, val) ((origin) |= ((val) << (shift)))
#define hns3_tx_bd_count(S) DIV_ROUND_UP(S, HNS3_MAX_BD_SIZE) #define hns3_tx_bd_count(S) DIV_ROUND_UP(S, HNS3_MAX_BD_SIZE)
static void hns3_clear_all_ring(struct hnae3_handle *h); static void hns3_clear_all_ring(struct hnae3_handle *h, bool force);
static void hns3_force_clear_all_ring(struct hnae3_handle *h);
static void hns3_remove_hw_addr(struct net_device *netdev); static void hns3_remove_hw_addr(struct net_device *netdev);
const char hns3_driver_name[] = "hns3"; const char hns3_driver_name[] = "hns3";
...@@ -473,6 +472,20 @@ static int hns3_nic_net_open(struct net_device *netdev) ...@@ -473,6 +472,20 @@ static int hns3_nic_net_open(struct net_device *netdev)
return 0; return 0;
} }
static void hns3_reset_tx_queue(struct hnae3_handle *h)
{
struct net_device *ndev = h->kinfo.netdev;
struct hns3_nic_priv *priv = netdev_priv(ndev);
struct netdev_queue *dev_queue;
u32 i;
for (i = 0; i < h->kinfo.num_tqps; i++) {
dev_queue = netdev_get_tx_queue(ndev,
priv->ring_data[i].queue_index);
netdev_tx_reset_queue(dev_queue);
}
}
static void hns3_nic_net_down(struct net_device *netdev) static void hns3_nic_net_down(struct net_device *netdev)
{ {
struct hns3_nic_priv *priv = netdev_priv(netdev); struct hns3_nic_priv *priv = netdev_priv(netdev);
...@@ -503,7 +516,9 @@ static void hns3_nic_net_down(struct net_device *netdev) ...@@ -503,7 +516,9 @@ static void hns3_nic_net_down(struct net_device *netdev)
* to disable the ring through firmware when downing the netdev. * to disable the ring through firmware when downing the netdev.
*/ */
if (!hns3_nic_resetting(netdev)) if (!hns3_nic_resetting(netdev))
hns3_clear_all_ring(priv->ae_handle); hns3_clear_all_ring(priv->ae_handle, false);
hns3_reset_tx_queue(priv->ae_handle);
} }
static int hns3_nic_net_stop(struct net_device *netdev) static int hns3_nic_net_stop(struct net_device *netdev)
...@@ -4003,7 +4018,7 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset) ...@@ -4003,7 +4018,7 @@ static void hns3_client_uninit(struct hnae3_handle *handle, bool reset)
hns3_del_all_fd_rules(netdev, true); hns3_del_all_fd_rules(netdev, true);
hns3_force_clear_all_ring(handle); hns3_clear_all_ring(handle, true);
hns3_nic_uninit_vector_data(priv); hns3_nic_uninit_vector_data(priv);
...@@ -4172,43 +4187,26 @@ static void hns3_force_clear_rx_ring(struct hns3_enet_ring *ring) ...@@ -4172,43 +4187,26 @@ static void hns3_force_clear_rx_ring(struct hns3_enet_ring *ring)
} }
} }
static void hns3_force_clear_all_ring(struct hnae3_handle *h) static void hns3_clear_all_ring(struct hnae3_handle *h, bool force)
{
struct net_device *ndev = h->kinfo.netdev;
struct hns3_nic_priv *priv = netdev_priv(ndev);
struct hns3_enet_ring *ring;
u32 i;
for (i = 0; i < h->kinfo.num_tqps; i++) {
ring = priv->ring_data[i].ring;
hns3_clear_tx_ring(ring);
ring = priv->ring_data[i + h->kinfo.num_tqps].ring;
hns3_force_clear_rx_ring(ring);
}
}
static void hns3_clear_all_ring(struct hnae3_handle *h)
{ {
struct net_device *ndev = h->kinfo.netdev; struct net_device *ndev = h->kinfo.netdev;
struct hns3_nic_priv *priv = netdev_priv(ndev); struct hns3_nic_priv *priv = netdev_priv(ndev);
u32 i; u32 i;
for (i = 0; i < h->kinfo.num_tqps; i++) { for (i = 0; i < h->kinfo.num_tqps; i++) {
struct netdev_queue *dev_queue;
struct hns3_enet_ring *ring; struct hns3_enet_ring *ring;
ring = priv->ring_data[i].ring; ring = priv->ring_data[i].ring;
hns3_clear_tx_ring(ring); hns3_clear_tx_ring(ring);
dev_queue = netdev_get_tx_queue(ndev,
priv->ring_data[i].queue_index);
netdev_tx_reset_queue(dev_queue);
ring = priv->ring_data[i + h->kinfo.num_tqps].ring; ring = priv->ring_data[i + h->kinfo.num_tqps].ring;
/* Continue to clear other rings even if clearing some /* Continue to clear other rings even if clearing some
* rings failed. * rings failed.
*/ */
hns3_clear_rx_ring(ring); if (force)
hns3_force_clear_rx_ring(ring);
else
hns3_clear_rx_ring(ring);
} }
} }
...@@ -4422,8 +4420,8 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle) ...@@ -4422,8 +4420,8 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
return 0; return 0;
} }
hns3_clear_all_ring(handle); hns3_clear_all_ring(handle, true);
hns3_force_clear_all_ring(handle); hns3_reset_tx_queue(priv->ae_handle);
hns3_nic_uninit_vector_data(priv); hns3_nic_uninit_vector_data(priv);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册