Skip to content

Commit 862d969

Browse files
Huazhong Tandavem330
authored andcommitted
net: hns3: do VF's pci re-initialization while PF doing FLR
While doing PF FLR, VF's PCIe configuration space will be cleared, so the pci and vector of VF should be re-initialized in the VF's reset process while PF doing FLR. Also, this patch fixes some memory not freed problem when pci re-initialization is done during reset process. Signed-off-by: Huazhong Tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6b9a97e commit 862d969

File tree

3 files changed

+74
-8
lines changed

3 files changed

+74
-8
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,20 +3848,30 @@ static int hns3_reset_notify_init_enet(struct hnae3_handle *handle)
38483848
/* Carrier off reporting is important to ethtool even BEFORE open */
38493849
netif_carrier_off(netdev);
38503850

3851+
ret = hns3_nic_alloc_vector_data(priv);
3852+
if (ret)
3853+
return ret;
3854+
38513855
hns3_restore_coal(priv);
38523856

38533857
ret = hns3_nic_init_vector_data(priv);
38543858
if (ret)
3855-
return ret;
3859+
goto err_dealloc_vector;
38563860

38573861
ret = hns3_init_all_ring(priv);
3858-
if (ret) {
3859-
hns3_nic_uninit_vector_data(priv);
3860-
priv->ring_data = NULL;
3861-
}
3862+
if (ret)
3863+
goto err_uninit_vector;
38623864

38633865
set_bit(HNS3_NIC_STATE_INITED, &priv->state);
38643866

3867+
return ret;
3868+
3869+
err_uninit_vector:
3870+
hns3_nic_uninit_vector_data(priv);
3871+
priv->ring_data = NULL;
3872+
err_dealloc_vector:
3873+
hns3_nic_dealloc_vector_data(priv);
3874+
38653875
return ret;
38663876
}
38673877

@@ -3886,6 +3896,10 @@ static int hns3_reset_notify_uninit_enet(struct hnae3_handle *handle)
38863896

38873897
hns3_store_coal(priv);
38883898

3899+
ret = hns3_nic_dealloc_vector_data(priv);
3900+
if (ret)
3901+
netdev_err(netdev, "dealloc vector error\n");
3902+
38893903
ret = hns3_uninit_all_ring(priv);
38903904
if (ret)
38913905
netdev_err(netdev, "uninit ring error\n");

drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,7 @@ static int hclgevf_init_msi(struct hclgevf_dev *hdev)
17661766
hdev->vector_irq = devm_kcalloc(&pdev->dev, hdev->num_msi,
17671767
sizeof(int), GFP_KERNEL);
17681768
if (!hdev->vector_irq) {
1769+
devm_kfree(&pdev->dev, hdev->vector_status);
17691770
pci_free_irq_vectors(pdev);
17701771
return -ENOMEM;
17711772
}
@@ -1777,6 +1778,8 @@ static void hclgevf_uninit_msi(struct hclgevf_dev *hdev)
17771778
{
17781779
struct pci_dev *pdev = hdev->pdev;
17791780

1781+
devm_kfree(&pdev->dev, hdev->vector_status);
1782+
devm_kfree(&pdev->dev, hdev->vector_irq);
17801783
pci_free_irq_vectors(pdev);
17811784
}
17821785

@@ -2001,11 +2004,52 @@ static int hclgevf_query_vf_resource(struct hclgevf_dev *hdev)
20012004
return 0;
20022005
}
20032006

2007+
static int hclgevf_pci_reset(struct hclgevf_dev *hdev)
2008+
{
2009+
struct pci_dev *pdev = hdev->pdev;
2010+
int ret = 0;
2011+
2012+
if (hdev->reset_type == HNAE3_VF_FULL_RESET &&
2013+
test_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state)) {
2014+
hclgevf_misc_irq_uninit(hdev);
2015+
hclgevf_uninit_msi(hdev);
2016+
clear_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state);
2017+
}
2018+
2019+
if (!test_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state)) {
2020+
pci_set_master(pdev);
2021+
ret = hclgevf_init_msi(hdev);
2022+
if (ret) {
2023+
dev_err(&pdev->dev,
2024+
"failed(%d) to init MSI/MSI-X\n", ret);
2025+
return ret;
2026+
}
2027+
2028+
ret = hclgevf_misc_irq_init(hdev);
2029+
if (ret) {
2030+
hclgevf_uninit_msi(hdev);
2031+
dev_err(&pdev->dev, "failed(%d) to init Misc IRQ(vector0)\n",
2032+
ret);
2033+
return ret;
2034+
}
2035+
2036+
set_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state);
2037+
}
2038+
2039+
return ret;
2040+
}
2041+
20042042
static int hclgevf_reset_hdev(struct hclgevf_dev *hdev)
20052043
{
20062044
struct pci_dev *pdev = hdev->pdev;
20072045
int ret;
20082046

2047+
ret = hclgevf_pci_reset(hdev);
2048+
if (ret) {
2049+
dev_err(&pdev->dev, "pci reset failed %d\n", ret);
2050+
return ret;
2051+
}
2052+
20092053
ret = hclgevf_cmd_init(hdev);
20102054
if (ret) {
20112055
dev_err(&pdev->dev, "cmd failed %d\n", ret);
@@ -2076,6 +2120,8 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
20762120
goto err_misc_irq_init;
20772121
}
20782122

2123+
set_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state);
2124+
20792125
ret = hclgevf_configure(hdev);
20802126
if (ret) {
20812127
dev_err(&pdev->dev, "failed(%d) to fetch configuration\n", ret);
@@ -2123,16 +2169,21 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
21232169
hclgevf_cmd_uninit(hdev);
21242170
err_cmd_queue_init:
21252171
hclgevf_pci_uninit(hdev);
2172+
clear_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state);
21262173
return ret;
21272174
}
21282175

21292176
static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev)
21302177
{
21312178
hclgevf_state_uninit(hdev);
2132-
hclgevf_misc_irq_uninit(hdev);
2179+
2180+
if (test_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state)) {
2181+
hclgevf_misc_irq_uninit(hdev);
2182+
hclgevf_uninit_msi(hdev);
2183+
hclgevf_pci_uninit(hdev);
2184+
}
2185+
21332186
hclgevf_cmd_uninit(hdev);
2134-
hclgevf_uninit_msi(hdev);
2135-
hclgevf_pci_uninit(hdev);
21362187
}
21372188

21382189
static int hclgevf_init_ae_dev(struct hnae3_ae_dev *ae_dev)

drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum hclgevf_states {
7373
/* device states */
7474
HCLGEVF_STATE_DOWN,
7575
HCLGEVF_STATE_DISABLED,
76+
HCLGEVF_STATE_IRQ_INITED,
7677
/* task states */
7778
HCLGEVF_STATE_SERVICE_SCHED,
7879
HCLGEVF_STATE_RST_SERVICE_SCHED,

0 commit comments

Comments
 (0)