net: hns3: add some fixes for -net
Subsystems (4)
cover net: hns3: add some fixes for -net
This series adds some fixes for the HNS3 ethernet driver.
Guangbin Huang (1):
net: hns3: fix phy can not link up when autoneg off and reset
Hao Chen (4):
net: hns3: fix ethtool tx copybreak buf size indicating not aligned
issue
net: hns3: add max order judgement for tx spare buffer
net: hns3: add netdev reset check for hns3_set_tunable()
net: hns3: add NULL pointer check for hns3_set/get_ringparam()
Peng Li (1):
net: hns3: clean residual vf config after disable sriov
drivers/net/ethernet/hisilicon/hns3/hnae3.h | 3 ++ .../net/ethernet/hisilicon/hns3/hns3_enet.c | 44 +++++++++++++--- .../ethernet/hisilicon/hns3/hns3_ethtool.c | 23 ++++++--- .../hisilicon/hns3/hns3pf/hclge_main.c | 50 +++++++++++++++++++ .../hisilicon/hns3/hns3pf/hclge_mdio.c | 4 +- 5 files changed, 107 insertions(+), 17 deletions(-)
Signature · 1 line
2.33.0
PATCH 1/6 net: hns3: fix ethtool tx copybreak buf size indicating not aligned issue
From: Hao Chen <[email protected]>
When use ethtoool set tx copybreak buf size to a large value which causes order exceeding 10 or memory is not enough, it causes allocating tx copybreak buffer failed and print "the active tx spare buf is 0, not enabled tx spare buffer", however, use --get-tunable parameter query tx copybreak buf size and it indicates setting value not 0.
So, it's necessary to change the print value from setting value to 0.
Set kinfo.tx_spare_buf_size to 0 when set tx copybreak buf size failed.
--- .../net/ethernet/hisilicon/hns3/hns3_enet.c | 20 +++++++++++-------- .../ethernet/hisilicon/hns3/hns3_ethtool.c | 3 ++- 2 files changed, 14 insertions(+), 9 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +12 -8
@@ -1028,13 +1028,12 @@ static bool hns3_can_use_tx_sgl(struct hns3_enet_ring *ring,static void hns3_init_tx_spare_buffer (struct hns3_enet_ring *ring) { +u32 alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size;struct hns3_tx_spare *tx_spare;struct page *page; -u32 alloc_size;dma_addr_t dma;int order; - alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size;if (!alloc_size)return ;
@@ -1044,30 +1043,35 @@ static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)if (!tx_spare) {/* The driver still work without the tx spare buffer */ dev_warn (ring_to_dev (ring),"failed to allocate hns3_tx_spare\n" ); -return ; + goto devm_kzalloc_error; } page =alloc_pages_node (dev_to_node (ring_to_dev (ring)),GFP_KERNEL , order);if (!page) {dev_warn (ring_to_dev (ring),"failed to allocate tx spare pages\n" ); -devm_kfree (ring_to_dev (ring), tx_spare); -return ; + goto alloc_pages_error; } dma =dma_map_page (ring_to_dev (ring), page,0 ,PAGE_SIZE << order,DMA_TO_DEVICE );if (dma_mapping_error (ring_to_dev (ring), dma)) {dev_warn (ring_to_dev (ring),"failed to map pages for tx spare\n" ); -put_page (page); -devm_kfree (ring_to_dev (ring), tx_spare); -return ; + goto dma_mapping_error; } tx_spare->dma = dma; tx_spare->buf =page_address (page); tx_spare->len =PAGE_SIZE << order; ring->tx_spare = tx_spare; +return ; + +dma_mapping_error: +put_page (page); +alloc_pages_error: +devm_kfree (ring_to_dev (ring), tx_spare); +devm_kzalloc_error: + ring->tqp->handle->kinfo.tx_spare_buf_size =0 ; }/* Use hns3_tx_spare_space() to make sure there is enough buffer
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +2 -1
@@ -1818,7 +1818,8 @@ static int hns3_set_tunable(struct net_device *netdev, old_tx_spare_buf_size = h->kinfo.tx_spare_buf_size; new_tx_spare_buf_size = *(u32 *)data; ret =hns3_set_tx_spare_buf_size (netdev, new_tx_spare_buf_size); -if (ret) { +if (ret || + (!priv->ring->tx_spare && new_tx_spare_buf_size !=0 )) {int ret1; netdev_warn(netdev,
Signature · 1 line
2.33.0
PATCH 2/6 net: hns3: add max order judgement for tx spare buffer
In reply to Guangbin HuangFrom: Hao Chen <[email protected]>
Add max order judgement for tx spare buffer to avoid triggering call trace, print related fail information instead, when user set tx spare buf size to a large value which causes order exceeding 10.
--- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +6 -0
@@ -1038,6 +1038,12 @@ static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)return ; order =get_order (alloc_size); +if (order >=MAX_ORDER ) { +if (net_ratelimit ()) +dev_warn (ring_to_dev (ring),"failed to allocate tx spare buffer, exceed to max order\n" ); +return ; + } + tx_spare =devm_kzalloc (ring_to_dev (ring),sizeof (*tx_spare),GFP_KERNEL );if (!tx_spare) {
Signature · 1 line
2.33.0
PATCH 3/6 net: hns3: clean residual vf config after disable sriov
In reply to Guangbin HuangFrom: Peng Li <[email protected]>
After disable sriov, VF still has some config and info need to be cleaned, which configured by PF. This patch clean the HW config and SW struct vport->vf_info.
--- drivers/net/ethernet/hisilicon/hns3/hnae3.h | 3 ++ .../net/ethernet/hisilicon/hns3/hns3_enet.c | 18 +++++++ .../hisilicon/hns3/hns3pf/hclge_main.c | 50 +++++++++++++++++++ 3 files changed, 71 insertions(+)
drivers/net/ethernet/hisilicon/hns3/hnae3.h +3 -0
@@ -537,6 +537,8 @@ struct hnae3_ae_dev {* Get 1588 rx hwstamp * get_ts_info * Get phc info +* clean_vf_config +* Clean residual vf info after disable sriov */ struct hnae3_ae_ops {int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
@@ -730,6 +732,7 @@ struct hnae3_ae_ops { struct ethtool_ts_info *info);int (*get_link_diagnosis_info)(struct hnae3_handle *handle,u32 *status_code); +void (*clean_vf_config)(struct hnae3_ae_dev *ae_dev,int num_vfs); };struct hnae3_dcb_ops {
drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +18 -0
@@ -3060,6 +3060,21 @@ static int hns3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return ret; } +/** +* hns3_clean_vf_config +* @pdev: pointer to a pci_dev structure +* @num_vfs: number of VFs allocated +* +* Clean residual vf config after disable sriov +**/ +static void hns3_clean_vf_config (struct pci_dev *pdev,int num_vfs) +{ +struct hnae3_ae_dev *ae_dev =pci_get_drvdata (pdev); + +if (ae_dev->ops->clean_vf_config) + ae_dev->ops->clean_vf_config (ae_dev, num_vfs); +} +/* hns3_remove - Device removal routine * @pdev: PCI device information struct */
@@ -3098,7 +3113,10 @@ static int hns3_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)else return num_vfs; }else if (!pci_vfs_assigned (pdev)) { +int num_vfs_pre =pci_num_vf (pdev); +pci_disable_sriov (pdev); +hns3_clean_vf_config (pdev, num_vfs_pre); }else {dev_warn (&pdev->dev,"Unable to free VFs because some are assigned to VMs.\n" );
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.33.0
PATCH 4/6 net: hns3: add netdev reset check for hns3_set_tunable()
In reply to Guangbin HuangFrom: Hao Chen <[email protected]>
When pci device reset failed, it does uninit operation and priv->ring is NULL, it causes accessing NULL pointer error.
Add netdev reset check for hns3_set_tunable() to fix it.
--- drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +5 -3
@@ -1766,9 +1766,6 @@ static int hns3_set_tx_spare_buf_size(struct net_device *netdev,struct hnae3_handle *h = priv->ae_handle;int ret; -if (hns3_nic_resetting (netdev)) -return -EBUSY ; - h->kinfo.tx_spare_buf_size = data; ret =hns3_reset_notify (h,HNAE3_DOWN_CLIENT );
@@ -1799,6 +1796,11 @@ static int hns3_set_tunable(struct net_device *netdev,struct hnae3_handle *h = priv->ae_handle;int i, ret =0 ; +if (hns3_nic_resetting (netdev) || !priv->ring) { +netdev_err (netdev,"failed to set tunable value, dev resetting!" ); +return -EBUSY ; + } +switch (tuna->id) {case ETHTOOL_TX_COPYBREAK : priv->tx_copybreak = *(u32 *)data;
Signature · 1 line
2.33.0
PATCH 5/6 net: hns3: add NULL pointer check for hns3_set/get_ringparam()
In reply to Guangbin HuangFrom: Hao Chen <[email protected]>
When pci devices init failed and haven't reinit, priv->ring is NULL and hns3_set/get_ringparam() will access priv->ring. it causes call trace.
So, add NULL pointer check for hns3_set/get_ringparam() to avoid this situation.
--- drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +9 -3
@@ -653,8 +653,8 @@ static void hns3_get_ringparam(struct net_device *netdev,struct hnae3_handle *h = priv->ae_handle;int rx_queue_index = h->kinfo.num_tqps; -if (hns3_nic_resetting (netdev)) { -netdev_err (netdev,"dev resetting!" ); +if (hns3_nic_resetting (netdev) || !priv->ring) { +netdev_err (netdev,"failed to get ringparam value, due to dev resetting or uninited\n" );return ; }
@@ -1074,8 +1074,14 @@ static int hns3_check_ringparam(struct net_device *ndev, {#define RX_BUF_LEN_2K 2048#define RX_BUF_LEN_4K 4096 -if (hns3_nic_resetting (ndev)) + +struct hns3_nic_priv *priv =netdev_priv (ndev); + +if (hns3_nic_resetting (ndev) || !priv->ring) { +netdev_err (ndev,"failed to set ringparam value, due to dev resetting or uninited\n" );return -EBUSY ; + } +if (param->rx_mini_pending || param->rx_jumbo_pending)return -EINVAL ;
Signature · 1 line
2.33.0
PATCH 6/6 net: hns3: fix phy can not link up when autoneg off and reset
In reply to Guangbin HuangCurrently, function hclge_mdio_read() will return 0 if during reset(the cmd state will be set to disable).
If use general phy driver, the phy_state_machine() will update phy speed every second in function genphy_read_status_fixed() when PHY is set to autoneg off, no matter of link down or link up.
If phy driver happens to read BMCR register during reset, phy speed will be updated to 10Mpbs as BMCR register value is 0. So it may call phy can not link up if previous speed is not 10Mpbs.
To fix this problem, function hclge_mdio_read() should return -EBUSY if the cmd state is disable. So does function hclge_mdio_write().
--- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c +2 -2
@@ -48,7 +48,7 @@ static int hclge_mdio_write(struct mii_bus *bus, int phyid, int regnum,int ret;if (test_bit (HCLGE_COMM_STATE_CMD_DISABLE , &hdev->hw.hw.comm_state)) -return 0 ; +return -EBUSY ;hclge_cmd_setup_basic_desc (&desc,HCLGE_OPC_MDIO_CONFIG , false);
@@ -86,7 +86,7 @@ static int hclge_mdio_read(struct mii_bus *bus, int phyid, int regnum)int ret;if (test_bit (HCLGE_COMM_STATE_CMD_DISABLE , &hdev->hw.hw.comm_state)) -return 0 ; +return -EBUSY ;hclge_cmd_setup_basic_desc (&desc,HCLGE_OPC_MDIO_CONFIG , true);
Signature · 1 line
2.33.0
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Quoted 5 lines · On Sat, 26 Mar 2022 17:50:59 +0800 you wrote:
This series adds some fixes for the HNS3 ethernet driver.
Guangbin Huang (1):
net: hns3: fix phy can not link up when autoneg off and reset
Quoted 8 lines
Hao Chen (4):
net: hns3: fix ethtool tx copybreak buf size indicating not aligned
issue
net: hns3: add max order judgement for tx spare buffer
net: hns3: add netdev reset check forhns3_set_tunable()
net: hns3: add NULL pointer check for hns3_set/get_ringparam()[...]
Here is the summary with links:
- [net,1/6] net: hns3: fix ethtool tx copybreak buf size indicating not aligned issue
https://git.kernel.org/netdev/net/c/877837211802 - [net,2/6] net: hns3: add max order judgement for tx spare buffer https://git.kernel.org/netdev/net/c/a89cbb16995b - [net,3/6] net: hns3: clean residual vf config after disable sriov https://git.kernel.org/netdev/net/c/671cb8cbb9c9 - [net,4/6] net: hns3: add netdev reset check for hns3_set_tunable() https://git.kernel.org/netdev/net/c/f5cd60169f98 - [net,5/6] net: hns3: add NULL pointer check for hns3_set/get_ringparam() https://git.kernel.org/netdev/net/c/4d07c5936c25
- [net,6/6] net: hns3: fix phy can not link up when autoneg off and reset
https://git.kernel.org/netdev/net/c/ad0ecaef6a2c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html