pds_core: delete VF dev on reset
authorShannon Nelson <shannon.nelson@amd.com>
Fri, 16 Feb 2024 22:29:51 +0000 (14:29 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 19 Feb 2024 10:29:07 +0000 (10:29 +0000)
When the VF is hit with a reset, remove the aux device in
the prepare for reset and try to restore it after the reset.
The userland mechanics will need to recover and rebuild whatever
uses the device afterwards.

Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/amd/pds_core/auxbus.c
drivers/net/ethernet/amd/pds_core/main.c

index 11c23a7f3172d39a200b85baad84c3cb3cc0db07..a3c79848a69aaaed3861e16355fcce393825efdc 100644 (file)
@@ -184,6 +184,9 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
        struct pds_auxiliary_dev *padev;
        int err = 0;
 
+       if (!cf)
+               return -ENODEV;
+
        mutex_lock(&pf->config_lock);
 
        padev = pf->vfs[cf->vf_id].padev;
@@ -202,14 +205,27 @@ int pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
 int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
 {
        struct pds_auxiliary_dev *padev;
-       enum pds_core_vif_types vt;
        char devname[PDS_DEVNAME_LEN];
+       enum pds_core_vif_types vt;
+       unsigned long mask;
        u16 vt_support;
        int client_id;
        int err = 0;
 
+       if (!cf)
+               return -ENODEV;
+
        mutex_lock(&pf->config_lock);
 
+       mask = BIT_ULL(PDSC_S_FW_DEAD) |
+              BIT_ULL(PDSC_S_STOPPING_DRIVER);
+       if (cf->state & mask) {
+               dev_err(pf->dev, "%s: can't add dev, VF client in bad state %#lx\n",
+                       __func__, cf->state);
+               err = -ENXIO;
+               goto out_unlock;
+       }
+
        /* We only support vDPA so far, so it is the only one to
         * be verified that it is available in the Core device and
         * enabled in the devlink param.  In the future this might
index e10451a5a89bb364b0c91b5e736a621bea0c9d01..82901a8473068eec1a1b9576265d9fb100e31990 100644 (file)
@@ -476,6 +476,14 @@ void pdsc_reset_prepare(struct pci_dev *pdev)
        pdsc_stop_health_thread(pdsc);
        pdsc_fw_down(pdsc);
 
+       if (pdev->is_virtfn) {
+               struct pdsc *pf;
+
+               pf = pdsc_get_pf_struct(pdsc->pdev);
+               if (!IS_ERR(pf))
+                       pdsc_auxbus_dev_del(pdsc, pf);
+       }
+
        pdsc_unmap_bars(pdsc);
        pci_release_regions(pdev);
        pci_disable_device(pdev);
@@ -511,6 +519,14 @@ void pdsc_reset_done(struct pci_dev *pdev)
 
        pdsc_fw_up(pdsc);
        pdsc_restart_health_thread(pdsc);
+
+       if (pdev->is_virtfn) {
+               struct pdsc *pf;
+
+               pf = pdsc_get_pf_struct(pdsc->pdev);
+               if (!IS_ERR(pf))
+                       pdsc_auxbus_dev_add(pdsc, pf);
+       }
 }
 
 static pci_ers_result_t pdsc_pci_error_detected(struct pci_dev *pdev,