pds_core: implement pci reset handlers
authorShannon Nelson <shannon.nelson@amd.com>
Thu, 14 Sep 2023 22:31:59 +0000 (15:31 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 5 Feb 2024 20:14:37 +0000 (20:14 +0000)
[ Upstream commit ffa55858330f267beec995fc4f68098c91311c64 ]

Implement the callbacks for a nice PCI reset.  These get called
when a user is nice enough to use the sysfs PCI reset entry, e.g.
    echo 1 > /sys/bus/pci/devices/0000:2b:00.0/reset

Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Stable-dep-of: 7e82a8745b95 ("pds_core: Prevent race issues involving the adminq")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/amd/pds_core/core.c
drivers/net/ethernet/amd/pds_core/core.h
drivers/net/ethernet/amd/pds_core/main.c

index dfb43ed..cc5e3d1 100644 (file)
@@ -514,7 +514,7 @@ void pdsc_stop(struct pdsc *pdsc)
                                           PDS_CORE_INTR_MASK_SET);
 }
 
-static void pdsc_fw_down(struct pdsc *pdsc)
+void pdsc_fw_down(struct pdsc *pdsc)
 {
        union pds_core_notifyq_comp reset_event = {
                .reset.ecode = cpu_to_le16(PDS_EVENT_RESET),
@@ -522,10 +522,13 @@ static void pdsc_fw_down(struct pdsc *pdsc)
        };
 
        if (test_and_set_bit(PDSC_S_FW_DEAD, &pdsc->state)) {
-               dev_err(pdsc->dev, "%s: already happening\n", __func__);
+               dev_warn(pdsc->dev, "%s: already happening\n", __func__);
                return;
        }
 
+       if (pdsc->pdev->is_virtfn)
+               return;
+
        /* Notify clients of fw_down */
        if (pdsc->fw_reporter)
                devlink_health_report(pdsc->fw_reporter, "FW down reported", pdsc);
@@ -535,7 +538,7 @@ static void pdsc_fw_down(struct pdsc *pdsc)
        pdsc_teardown(pdsc, PDSC_TEARDOWN_RECOVERY);
 }
 
-static void pdsc_fw_up(struct pdsc *pdsc)
+void pdsc_fw_up(struct pdsc *pdsc)
 {
        union pds_core_notifyq_comp reset_event = {
                .reset.ecode = cpu_to_le16(PDS_EVENT_RESET),
@@ -548,6 +551,11 @@ static void pdsc_fw_up(struct pdsc *pdsc)
                return;
        }
 
+       if (pdsc->pdev->is_virtfn) {
+               clear_bit(PDSC_S_FW_DEAD, &pdsc->state);
+               return;
+       }
+
        err = pdsc_setup(pdsc, PDSC_SETUP_RECOVERY);
        if (err)
                goto err_out;
index b1c1f10..860bce1 100644 (file)
@@ -309,4 +309,8 @@ irqreturn_t pdsc_adminq_isr(int irq, void *data);
 
 int pdsc_firmware_update(struct pdsc *pdsc, const struct firmware *fw,
                         struct netlink_ext_ack *extack);
+
+void pdsc_fw_down(struct pdsc *pdsc);
+void pdsc_fw_up(struct pdsc *pdsc);
+
 #endif /* _PDSC_H_ */
index 3a45bf4..4c7f982 100644 (file)
@@ -445,12 +445,62 @@ static void pdsc_remove(struct pci_dev *pdev)
        devlink_free(dl);
 }
 
+static void pdsc_reset_prepare(struct pci_dev *pdev)
+{
+       struct pdsc *pdsc = pci_get_drvdata(pdev);
+
+       pdsc_fw_down(pdsc);
+
+       pci_free_irq_vectors(pdev);
+       pdsc_unmap_bars(pdsc);
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+}
+
+static void pdsc_reset_done(struct pci_dev *pdev)
+{
+       struct pdsc *pdsc = pci_get_drvdata(pdev);
+       struct device *dev = pdsc->dev;
+       int err;
+
+       err = pci_enable_device(pdev);
+       if (err) {
+               dev_err(dev, "Cannot enable PCI device: %pe\n", ERR_PTR(err));
+               return;
+       }
+       pci_set_master(pdev);
+
+       if (!pdev->is_virtfn) {
+               pcie_print_link_status(pdsc->pdev);
+
+               err = pci_request_regions(pdsc->pdev, PDS_CORE_DRV_NAME);
+               if (err) {
+                       dev_err(pdsc->dev, "Cannot request PCI regions: %pe\n",
+                               ERR_PTR(err));
+                       return;
+               }
+
+               err = pdsc_map_bars(pdsc);
+               if (err)
+                       return;
+       }
+
+       pdsc_fw_up(pdsc);
+}
+
+static const struct pci_error_handlers pdsc_err_handler = {
+       /* FLR handling */
+       .reset_prepare      = pdsc_reset_prepare,
+       .reset_done         = pdsc_reset_done,
+};
+
 static struct pci_driver pdsc_driver = {
        .name = PDS_CORE_DRV_NAME,
        .id_table = pdsc_id_table,
        .probe = pdsc_probe,
        .remove = pdsc_remove,
        .sriov_configure = pdsc_sriov_configure,
+       .err_handler = &pdsc_err_handler,
 };
 
 void *pdsc_get_pf_struct(struct pci_dev *vf_pdev)