Skip to content

Commit 2eca426

Browse files
committed
Merge branch 'hns3-fixes'
Guangbin Huang says: ==================== net: hns3: add some fixes for -net This series adds some fixes for the HNS3 ethernet driver. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents b50d3b4 + ad0ecae commit 2eca426

5 files changed

Lines changed: 107 additions & 17 deletions

File tree

drivers/net/ethernet/hisilicon/hns3/hnae3.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ struct hnae3_ae_dev {
537537
* Get 1588 rx hwstamp
538538
* get_ts_info
539539
* Get phc info
540+
* clean_vf_config
541+
* Clean residual vf info after disable sriov
540542
*/
541543
struct hnae3_ae_ops {
542544
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
@@ -730,6 +732,7 @@ struct hnae3_ae_ops {
730732
struct ethtool_ts_info *info);
731733
int (*get_link_diagnosis_info)(struct hnae3_handle *handle,
732734
u32 *status_code);
735+
void (*clean_vf_config)(struct hnae3_ae_dev *ae_dev, int num_vfs);
733736
};
734737

735738
struct hnae3_dcb_ops {

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,46 +1028,56 @@ static bool hns3_can_use_tx_sgl(struct hns3_enet_ring *ring,
10281028

10291029
static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)
10301030
{
1031+
u32 alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size;
10311032
struct hns3_tx_spare *tx_spare;
10321033
struct page *page;
1033-
u32 alloc_size;
10341034
dma_addr_t dma;
10351035
int order;
10361036

1037-
alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size;
10381037
if (!alloc_size)
10391038
return;
10401039

10411040
order = get_order(alloc_size);
1041+
if (order >= MAX_ORDER) {
1042+
if (net_ratelimit())
1043+
dev_warn(ring_to_dev(ring), "failed to allocate tx spare buffer, exceed to max order\n");
1044+
return;
1045+
}
1046+
10421047
tx_spare = devm_kzalloc(ring_to_dev(ring), sizeof(*tx_spare),
10431048
GFP_KERNEL);
10441049
if (!tx_spare) {
10451050
/* The driver still work without the tx spare buffer */
10461051
dev_warn(ring_to_dev(ring), "failed to allocate hns3_tx_spare\n");
1047-
return;
1052+
goto devm_kzalloc_error;
10481053
}
10491054

10501055
page = alloc_pages_node(dev_to_node(ring_to_dev(ring)),
10511056
GFP_KERNEL, order);
10521057
if (!page) {
10531058
dev_warn(ring_to_dev(ring), "failed to allocate tx spare pages\n");
1054-
devm_kfree(ring_to_dev(ring), tx_spare);
1055-
return;
1059+
goto alloc_pages_error;
10561060
}
10571061

10581062
dma = dma_map_page(ring_to_dev(ring), page, 0,
10591063
PAGE_SIZE << order, DMA_TO_DEVICE);
10601064
if (dma_mapping_error(ring_to_dev(ring), dma)) {
10611065
dev_warn(ring_to_dev(ring), "failed to map pages for tx spare\n");
1062-
put_page(page);
1063-
devm_kfree(ring_to_dev(ring), tx_spare);
1064-
return;
1066+
goto dma_mapping_error;
10651067
}
10661068

10671069
tx_spare->dma = dma;
10681070
tx_spare->buf = page_address(page);
10691071
tx_spare->len = PAGE_SIZE << order;
10701072
ring->tx_spare = tx_spare;
1073+
return;
1074+
1075+
dma_mapping_error:
1076+
put_page(page);
1077+
alloc_pages_error:
1078+
devm_kfree(ring_to_dev(ring), tx_spare);
1079+
devm_kzalloc_error:
1080+
ring->tqp->handle->kinfo.tx_spare_buf_size = 0;
10711081
}
10721082

10731083
/* Use hns3_tx_spare_space() to make sure there is enough buffer
@@ -3050,6 +3060,21 @@ static int hns3_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
30503060
return ret;
30513061
}
30523062

3063+
/**
3064+
* hns3_clean_vf_config
3065+
* @pdev: pointer to a pci_dev structure
3066+
* @num_vfs: number of VFs allocated
3067+
*
3068+
* Clean residual vf config after disable sriov
3069+
**/
3070+
static void hns3_clean_vf_config(struct pci_dev *pdev, int num_vfs)
3071+
{
3072+
struct hnae3_ae_dev *ae_dev = pci_get_drvdata(pdev);
3073+
3074+
if (ae_dev->ops->clean_vf_config)
3075+
ae_dev->ops->clean_vf_config(ae_dev, num_vfs);
3076+
}
3077+
30533078
/* hns3_remove - Device removal routine
30543079
* @pdev: PCI device information struct
30553080
*/
@@ -3088,7 +3113,10 @@ static int hns3_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
30883113
else
30893114
return num_vfs;
30903115
} else if (!pci_vfs_assigned(pdev)) {
3116+
int num_vfs_pre = pci_num_vf(pdev);
3117+
30913118
pci_disable_sriov(pdev);
3119+
hns3_clean_vf_config(pdev, num_vfs_pre);
30923120
} else {
30933121
dev_warn(&pdev->dev,
30943122
"Unable to free VFs because some are assigned to VMs.\n");

drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ static void hns3_get_ringparam(struct net_device *netdev,
653653
struct hnae3_handle *h = priv->ae_handle;
654654
int rx_queue_index = h->kinfo.num_tqps;
655655

656-
if (hns3_nic_resetting(netdev)) {
657-
netdev_err(netdev, "dev resetting!");
656+
if (hns3_nic_resetting(netdev) || !priv->ring) {
657+
netdev_err(netdev, "failed to get ringparam value, due to dev resetting or uninited\n");
658658
return;
659659
}
660660

@@ -1074,8 +1074,14 @@ static int hns3_check_ringparam(struct net_device *ndev,
10741074
{
10751075
#define RX_BUF_LEN_2K 2048
10761076
#define RX_BUF_LEN_4K 4096
1077-
if (hns3_nic_resetting(ndev))
1077+
1078+
struct hns3_nic_priv *priv = netdev_priv(ndev);
1079+
1080+
if (hns3_nic_resetting(ndev) || !priv->ring) {
1081+
netdev_err(ndev, "failed to set ringparam value, due to dev resetting or uninited\n");
10781082
return -EBUSY;
1083+
}
1084+
10791085

10801086
if (param->rx_mini_pending || param->rx_jumbo_pending)
10811087
return -EINVAL;
@@ -1766,9 +1772,6 @@ static int hns3_set_tx_spare_buf_size(struct net_device *netdev,
17661772
struct hnae3_handle *h = priv->ae_handle;
17671773
int ret;
17681774

1769-
if (hns3_nic_resetting(netdev))
1770-
return -EBUSY;
1771-
17721775
h->kinfo.tx_spare_buf_size = data;
17731776

17741777
ret = hns3_reset_notify(h, HNAE3_DOWN_CLIENT);
@@ -1799,6 +1802,11 @@ static int hns3_set_tunable(struct net_device *netdev,
17991802
struct hnae3_handle *h = priv->ae_handle;
18001803
int i, ret = 0;
18011804

1805+
if (hns3_nic_resetting(netdev) || !priv->ring) {
1806+
netdev_err(netdev, "failed to set tunable value, dev resetting!");
1807+
return -EBUSY;
1808+
}
1809+
18021810
switch (tuna->id) {
18031811
case ETHTOOL_TX_COPYBREAK:
18041812
priv->tx_copybreak = *(u32 *)data;
@@ -1818,7 +1826,8 @@ static int hns3_set_tunable(struct net_device *netdev,
18181826
old_tx_spare_buf_size = h->kinfo.tx_spare_buf_size;
18191827
new_tx_spare_buf_size = *(u32 *)data;
18201828
ret = hns3_set_tx_spare_buf_size(netdev, new_tx_spare_buf_size);
1821-
if (ret) {
1829+
if (ret ||
1830+
(!priv->ring->tx_spare && new_tx_spare_buf_size != 0)) {
18221831
int ret1;
18231832

18241833
netdev_warn(netdev,

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12724,6 +12724,55 @@ static int hclge_get_link_diagnosis_info(struct hnae3_handle *handle,
1272412724
return 0;
1272512725
}
1272612726

12727+
/* After disable sriov, VF still has some config and info need clean,
12728+
* which configed by PF.
12729+
*/
12730+
static void hclge_clear_vport_vf_info(struct hclge_vport *vport, int vfid)
12731+
{
12732+
struct hclge_dev *hdev = vport->back;
12733+
struct hclge_vlan_info vlan_info;
12734+
int ret;
12735+
12736+
/* after disable sriov, clean VF rate configured by PF */
12737+
ret = hclge_tm_qs_shaper_cfg(vport, 0);
12738+
if (ret)
12739+
dev_err(&hdev->pdev->dev,
12740+
"failed to clean vf%d rate config, ret = %d\n",
12741+
vfid, ret);
12742+
12743+
vlan_info.vlan_tag = 0;
12744+
vlan_info.qos = 0;
12745+
vlan_info.vlan_proto = ETH_P_8021Q;
12746+
ret = hclge_update_port_base_vlan_cfg(vport,
12747+
HNAE3_PORT_BASE_VLAN_DISABLE,
12748+
&vlan_info);
12749+
if (ret)
12750+
dev_err(&hdev->pdev->dev,
12751+
"failed to clean vf%d port base vlan, ret = %d\n",
12752+
vfid, ret);
12753+
12754+
ret = hclge_set_vf_spoofchk_hw(hdev, vport->vport_id, false);
12755+
if (ret)
12756+
dev_err(&hdev->pdev->dev,
12757+
"failed to clean vf%d spoof config, ret = %d\n",
12758+
vfid, ret);
12759+
12760+
memset(&vport->vf_info, 0, sizeof(vport->vf_info));
12761+
}
12762+
12763+
static void hclge_clean_vport_config(struct hnae3_ae_dev *ae_dev, int num_vfs)
12764+
{
12765+
struct hclge_dev *hdev = ae_dev->priv;
12766+
struct hclge_vport *vport;
12767+
int i;
12768+
12769+
for (i = 0; i < num_vfs; i++) {
12770+
vport = &hdev->vport[i + HCLGE_VF_VPORT_START_NUM];
12771+
12772+
hclge_clear_vport_vf_info(vport, i);
12773+
}
12774+
}
12775+
1272712776
static const struct hnae3_ae_ops hclge_ops = {
1272812777
.init_ae_dev = hclge_init_ae_dev,
1272912778
.uninit_ae_dev = hclge_uninit_ae_dev,
@@ -12825,6 +12874,7 @@ static const struct hnae3_ae_ops hclge_ops = {
1282512874
.get_rx_hwts = hclge_ptp_get_rx_hwts,
1282612875
.get_ts_info = hclge_ptp_get_ts_info,
1282712876
.get_link_diagnosis_info = hclge_get_link_diagnosis_info,
12877+
.clean_vf_config = hclge_clean_vport_config,
1282812878
};
1282912879

1283012880
static struct hnae3_ae_algo ae_algo = {

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int hclge_mdio_write(struct mii_bus *bus, int phyid, int regnum,
4848
int ret;
4949

5050
if (test_bit(HCLGE_COMM_STATE_CMD_DISABLE, &hdev->hw.hw.comm_state))
51-
return 0;
51+
return -EBUSY;
5252

5353
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MDIO_CONFIG, false);
5454

@@ -86,7 +86,7 @@ static int hclge_mdio_read(struct mii_bus *bus, int phyid, int regnum)
8686
int ret;
8787

8888
if (test_bit(HCLGE_COMM_STATE_CMD_DISABLE, &hdev->hw.hw.comm_state))
89-
return 0;
89+
return -EBUSY;
9090

9191
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MDIO_CONFIG, true);
9292

0 commit comments

Comments
 (0)