Skip to content

Commit 790d23e

Browse files
Dirk van der Merwedavem330
authored andcommitted
nfp: implement PCI driver shutdown callback
Device may be shutdown without the hardware being reinitialized, in which case we want to ensure we cleanup properly. This is especially important for kexec with traffic flowing. The shutdown procedures resembles the remove procedures, so we can reuse those common tasks. Signed-off-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 16848c8 commit 790d23e

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

drivers/net/ethernet/netronome/nfp/nfp_main.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ static int nfp_pcie_sriov_disable(struct pci_dev *pdev)
294294

295295
static int nfp_pcie_sriov_configure(struct pci_dev *pdev, int num_vfs)
296296
{
297+
if (!pci_get_drvdata(pdev))
298+
return -ENOENT;
299+
297300
if (num_vfs == 0)
298301
return nfp_pcie_sriov_disable(pdev);
299302
else
@@ -720,9 +723,13 @@ static int nfp_pci_probe(struct pci_dev *pdev,
720723
return err;
721724
}
722725

723-
static void nfp_pci_remove(struct pci_dev *pdev)
726+
static void __nfp_pci_shutdown(struct pci_dev *pdev, bool unload_fw)
724727
{
725-
struct nfp_pf *pf = pci_get_drvdata(pdev);
728+
struct nfp_pf *pf;
729+
730+
pf = pci_get_drvdata(pdev);
731+
if (!pf)
732+
return;
726733

727734
nfp_hwmon_unregister(pf);
728735

@@ -733,7 +740,7 @@ static void nfp_pci_remove(struct pci_dev *pdev)
733740
vfree(pf->dumpspec);
734741
kfree(pf->rtbl);
735742
nfp_mip_close(pf->mip);
736-
if (pf->fw_loaded)
743+
if (unload_fw && pf->fw_loaded)
737744
nfp_fw_unload(pf);
738745

739746
destroy_workqueue(pf->wq);
@@ -749,11 +756,22 @@ static void nfp_pci_remove(struct pci_dev *pdev)
749756
pci_disable_device(pdev);
750757
}
751758

759+
static void nfp_pci_remove(struct pci_dev *pdev)
760+
{
761+
__nfp_pci_shutdown(pdev, true);
762+
}
763+
764+
static void nfp_pci_shutdown(struct pci_dev *pdev)
765+
{
766+
__nfp_pci_shutdown(pdev, false);
767+
}
768+
752769
static struct pci_driver nfp_pci_driver = {
753770
.name = nfp_driver_name,
754771
.id_table = nfp_pci_device_ids,
755772
.probe = nfp_pci_probe,
756773
.remove = nfp_pci_remove,
774+
.shutdown = nfp_pci_shutdown,
757775
.sriov_configure = nfp_pcie_sriov_configure,
758776
};
759777

drivers/net/ethernet/netronome/nfp/nfp_netvf_main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,14 @@ static int nfp_netvf_pci_probe(struct pci_dev *pdev,
282282

283283
static void nfp_netvf_pci_remove(struct pci_dev *pdev)
284284
{
285-
struct nfp_net_vf *vf = pci_get_drvdata(pdev);
286-
struct nfp_net *nn = vf->nn;
285+
struct nfp_net_vf *vf;
286+
struct nfp_net *nn;
287+
288+
vf = pci_get_drvdata(pdev);
289+
if (!vf)
290+
return;
291+
292+
nn = vf->nn;
287293

288294
/* Note, the order is slightly different from above as we need
289295
* to keep the nn pointer around till we have freed everything.
@@ -317,4 +323,5 @@ struct pci_driver nfp_netvf_pci_driver = {
317323
.id_table = nfp_netvf_pci_device_ids,
318324
.probe = nfp_netvf_pci_probe,
319325
.remove = nfp_netvf_pci_remove,
326+
.shutdown = nfp_netvf_pci_remove,
320327
};

0 commit comments

Comments
 (0)