Commit a723fb8e authored by Jian Shen's avatar Jian Shen Committed by David S. Miller

net: hns3: refine for set ring parameters

Previously, when changing the ring parameters, we free the old
ring resources firstly, and then setup the new ring resources.
In some case of an memory allocation fail, there will be no
resources to use. This patch refines it by setup new ring
resources and free the old ring resources in order.

Also reduce the max ring BD number to 32760 according to UM.
Signed-off-by: default avatarJian Shen <shenjian15@huawei.com>
Reviewed-by: default avatarPeng Li <lipeng321@huawei.com>
Signed-off-by: default avatarHuazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3f0f3253
...@@ -3588,7 +3588,7 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring) ...@@ -3588,7 +3588,7 @@ static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
return ret; return ret;
} }
static void hns3_fini_ring(struct hns3_enet_ring *ring) void hns3_fini_ring(struct hns3_enet_ring *ring)
{ {
hns3_free_desc(ring); hns3_free_desc(ring);
devm_kfree(ring_to_dev(ring), ring->desc_cb); devm_kfree(ring_to_dev(ring), ring->desc_cb);
......
...@@ -75,7 +75,7 @@ enum hns3_nic_state { ...@@ -75,7 +75,7 @@ enum hns3_nic_state {
#define HNS3_TX_TIMEOUT (5 * HZ) #define HNS3_TX_TIMEOUT (5 * HZ)
#define HNS3_RING_NAME_LEN 16 #define HNS3_RING_NAME_LEN 16
#define HNS3_BUFFER_SIZE_2048 2048 #define HNS3_BUFFER_SIZE_2048 2048
#define HNS3_RING_MAX_PENDING 32768 #define HNS3_RING_MAX_PENDING 32760
#define HNS3_RING_MIN_PENDING 24 #define HNS3_RING_MIN_PENDING 24
#define HNS3_RING_BD_MULTIPLE 8 #define HNS3_RING_BD_MULTIPLE 8
/* max frame size of mac */ /* max frame size of mac */
...@@ -642,6 +642,7 @@ void hns3_clean_tx_ring(struct hns3_enet_ring *ring); ...@@ -642,6 +642,7 @@ void hns3_clean_tx_ring(struct hns3_enet_ring *ring);
int hns3_init_all_ring(struct hns3_nic_priv *priv); int hns3_init_all_ring(struct hns3_nic_priv *priv);
int hns3_uninit_all_ring(struct hns3_nic_priv *priv); int hns3_uninit_all_ring(struct hns3_nic_priv *priv);
int hns3_nic_reset_all_ring(struct hnae3_handle *h); int hns3_nic_reset_all_ring(struct hnae3_handle *h);
void hns3_fini_ring(struct hns3_enet_ring *ring);
netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev); netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev);
bool hns3_is_phys_func(struct pci_dev *pdev); bool hns3_is_phys_func(struct pci_dev *pdev);
int hns3_clean_rx_ring( int hns3_clean_rx_ring(
......
...@@ -867,8 +867,8 @@ static int hns3_get_rxnfc(struct net_device *netdev, ...@@ -867,8 +867,8 @@ static int hns3_get_rxnfc(struct net_device *netdev,
} }
} }
static int hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv, static void hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv,
u32 tx_desc_num, u32 rx_desc_num) u32 tx_desc_num, u32 rx_desc_num)
{ {
struct hnae3_handle *h = priv->ae_handle; struct hnae3_handle *h = priv->ae_handle;
int i; int i;
...@@ -881,21 +881,29 @@ static int hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv, ...@@ -881,21 +881,29 @@ static int hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv,
priv->ring_data[i + h->kinfo.num_tqps].ring->desc_num = priv->ring_data[i + h->kinfo.num_tqps].ring->desc_num =
rx_desc_num; rx_desc_num;
} }
return hns3_init_all_ring(priv);
} }
static int hns3_set_ringparam(struct net_device *ndev, static struct hns3_enet_ring *hns3_backup_ringparam(struct hns3_nic_priv *priv)
struct ethtool_ringparam *param)
{ {
struct hns3_nic_priv *priv = netdev_priv(ndev); struct hnae3_handle *handle = priv->ae_handle;
struct hnae3_handle *h = priv->ae_handle; struct hns3_enet_ring *tmp_rings;
bool if_running = netif_running(ndev); int i;
u32 old_tx_desc_num, new_tx_desc_num;
u32 old_rx_desc_num, new_rx_desc_num;
int queue_num = h->kinfo.num_tqps;
int ret;
tmp_rings = kcalloc(handle->kinfo.num_tqps * 2,
sizeof(struct hns3_enet_ring), GFP_KERNEL);
if (!tmp_rings)
return NULL;
for (i = 0; i < handle->kinfo.num_tqps * 2; i++)
memcpy(&tmp_rings[i], priv->ring_data[i].ring,
sizeof(struct hns3_enet_ring));
return tmp_rings;
}
static int hns3_check_ringparam(struct net_device *ndev,
struct ethtool_ringparam *param)
{
if (hns3_nic_resetting(ndev)) if (hns3_nic_resetting(ndev))
return -EBUSY; return -EBUSY;
...@@ -911,6 +919,25 @@ static int hns3_set_ringparam(struct net_device *ndev, ...@@ -911,6 +919,25 @@ static int hns3_set_ringparam(struct net_device *ndev,
return -EINVAL; return -EINVAL;
} }
return 0;
}
static int hns3_set_ringparam(struct net_device *ndev,
struct ethtool_ringparam *param)
{
struct hns3_nic_priv *priv = netdev_priv(ndev);
struct hnae3_handle *h = priv->ae_handle;
struct hns3_enet_ring *tmp_rings;
bool if_running = netif_running(ndev);
u32 old_tx_desc_num, new_tx_desc_num;
u32 old_rx_desc_num, new_rx_desc_num;
u16 queue_num = h->kinfo.num_tqps;
int ret, i;
ret = hns3_check_ringparam(ndev, param);
if (ret)
return ret;
/* Hardware requires that its descriptors must be multiple of eight */ /* Hardware requires that its descriptors must be multiple of eight */
new_tx_desc_num = ALIGN(param->tx_pending, HNS3_RING_BD_MULTIPLE); new_tx_desc_num = ALIGN(param->tx_pending, HNS3_RING_BD_MULTIPLE);
new_rx_desc_num = ALIGN(param->rx_pending, HNS3_RING_BD_MULTIPLE); new_rx_desc_num = ALIGN(param->rx_pending, HNS3_RING_BD_MULTIPLE);
...@@ -920,6 +947,13 @@ static int hns3_set_ringparam(struct net_device *ndev, ...@@ -920,6 +947,13 @@ static int hns3_set_ringparam(struct net_device *ndev,
old_rx_desc_num == new_rx_desc_num) old_rx_desc_num == new_rx_desc_num)
return 0; return 0;
tmp_rings = hns3_backup_ringparam(priv);
if (!tmp_rings) {
netdev_err(ndev,
"backup ring param failed by allocating memory fail\n");
return -ENOMEM;
}
netdev_info(ndev, netdev_info(ndev,
"Changing Tx/Rx ring depth from %d/%d to %d/%d\n", "Changing Tx/Rx ring depth from %d/%d to %d/%d\n",
old_tx_desc_num, old_rx_desc_num, old_tx_desc_num, old_rx_desc_num,
...@@ -928,22 +962,24 @@ static int hns3_set_ringparam(struct net_device *ndev, ...@@ -928,22 +962,24 @@ static int hns3_set_ringparam(struct net_device *ndev,
if (if_running) if (if_running)
ndev->netdev_ops->ndo_stop(ndev); ndev->netdev_ops->ndo_stop(ndev);
ret = hns3_uninit_all_ring(priv); hns3_change_all_ring_bd_num(priv, new_tx_desc_num, new_rx_desc_num);
if (ret) ret = hns3_init_all_ring(priv);
return ret;
ret = hns3_change_all_ring_bd_num(priv, new_tx_desc_num,
new_rx_desc_num);
if (ret) { if (ret) {
ret = hns3_change_all_ring_bd_num(priv, old_tx_desc_num, netdev_err(ndev, "Change bd num fail, revert to old value(%d)\n",
old_rx_desc_num); ret);
if (ret) {
netdev_err(ndev, hns3_change_all_ring_bd_num(priv, old_tx_desc_num,
"Revert to old bd num fail, ret=%d.\n", ret); old_rx_desc_num);
return ret; for (i = 0; i < h->kinfo.num_tqps * 2; i++)
} memcpy(priv->ring_data[i].ring, &tmp_rings[i],
sizeof(struct hns3_enet_ring));
} else {
for (i = 0; i < h->kinfo.num_tqps * 2; i++)
hns3_fini_ring(&tmp_rings[i]);
} }
kfree(tmp_rings);
if (if_running) if (if_running)
ret = ndev->netdev_ops->ndo_open(ndev); ret = ndev->netdev_ops->ndo_open(ndev);
......
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