Skip to content

Commit ffa5585

Browse files
emuslndavem330
authored andcommitted
pds_core: implement pci reset handlers
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 <[email protected]> Reviewed-by: Brett Creeley <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d557c09 commit ffa5585

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

drivers/net/ethernet/amd/pds_core/core.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,18 +515,21 @@ void pdsc_stop(struct pdsc *pdsc)
515515
PDS_CORE_INTR_MASK_SET);
516516
}
517517

518-
static void pdsc_fw_down(struct pdsc *pdsc)
518+
void pdsc_fw_down(struct pdsc *pdsc)
519519
{
520520
union pds_core_notifyq_comp reset_event = {
521521
.reset.ecode = cpu_to_le16(PDS_EVENT_RESET),
522522
.reset.state = 0,
523523
};
524524

525525
if (test_and_set_bit(PDSC_S_FW_DEAD, &pdsc->state)) {
526-
dev_err(pdsc->dev, "%s: already happening\n", __func__);
526+
dev_warn(pdsc->dev, "%s: already happening\n", __func__);
527527
return;
528528
}
529529

530+
if (pdsc->pdev->is_virtfn)
531+
return;
532+
530533
/* Notify clients of fw_down */
531534
if (pdsc->fw_reporter)
532535
devlink_health_report(pdsc->fw_reporter, "FW down reported", pdsc);
@@ -536,7 +539,7 @@ static void pdsc_fw_down(struct pdsc *pdsc)
536539
pdsc_teardown(pdsc, PDSC_TEARDOWN_RECOVERY);
537540
}
538541

539-
static void pdsc_fw_up(struct pdsc *pdsc)
542+
void pdsc_fw_up(struct pdsc *pdsc)
540543
{
541544
union pds_core_notifyq_comp reset_event = {
542545
.reset.ecode = cpu_to_le16(PDS_EVENT_RESET),
@@ -549,6 +552,11 @@ static void pdsc_fw_up(struct pdsc *pdsc)
549552
return;
550553
}
551554

555+
if (pdsc->pdev->is_virtfn) {
556+
clear_bit(PDSC_S_FW_DEAD, &pdsc->state);
557+
return;
558+
}
559+
552560
err = pdsc_setup(pdsc, PDSC_SETUP_RECOVERY);
553561
if (err)
554562
goto err_out;

drivers/net/ethernet/amd/pds_core/core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,4 +309,8 @@ irqreturn_t pdsc_adminq_isr(int irq, void *data);
309309

310310
int pdsc_firmware_update(struct pdsc *pdsc, const struct firmware *fw,
311311
struct netlink_ext_ack *extack);
312+
313+
void pdsc_fw_down(struct pdsc *pdsc);
314+
void pdsc_fw_up(struct pdsc *pdsc);
315+
312316
#endif /* _PDSC_H_ */

drivers/net/ethernet/amd/pds_core/main.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,62 @@ static void pdsc_remove(struct pci_dev *pdev)
445445
devlink_free(dl);
446446
}
447447

448+
static void pdsc_reset_prepare(struct pci_dev *pdev)
449+
{
450+
struct pdsc *pdsc = pci_get_drvdata(pdev);
451+
452+
pdsc_fw_down(pdsc);
453+
454+
pci_free_irq_vectors(pdev);
455+
pdsc_unmap_bars(pdsc);
456+
pci_release_regions(pdev);
457+
pci_disable_device(pdev);
458+
}
459+
460+
static void pdsc_reset_done(struct pci_dev *pdev)
461+
{
462+
struct pdsc *pdsc = pci_get_drvdata(pdev);
463+
struct device *dev = pdsc->dev;
464+
int err;
465+
466+
err = pci_enable_device(pdev);
467+
if (err) {
468+
dev_err(dev, "Cannot enable PCI device: %pe\n", ERR_PTR(err));
469+
return;
470+
}
471+
pci_set_master(pdev);
472+
473+
if (!pdev->is_virtfn) {
474+
pcie_print_link_status(pdsc->pdev);
475+
476+
err = pci_request_regions(pdsc->pdev, PDS_CORE_DRV_NAME);
477+
if (err) {
478+
dev_err(pdsc->dev, "Cannot request PCI regions: %pe\n",
479+
ERR_PTR(err));
480+
return;
481+
}
482+
483+
err = pdsc_map_bars(pdsc);
484+
if (err)
485+
return;
486+
}
487+
488+
pdsc_fw_up(pdsc);
489+
}
490+
491+
static const struct pci_error_handlers pdsc_err_handler = {
492+
/* FLR handling */
493+
.reset_prepare = pdsc_reset_prepare,
494+
.reset_done = pdsc_reset_done,
495+
};
496+
448497
static struct pci_driver pdsc_driver = {
449498
.name = PDS_CORE_DRV_NAME,
450499
.id_table = pdsc_id_table,
451500
.probe = pdsc_probe,
452501
.remove = pdsc_remove,
453502
.sriov_configure = pdsc_sriov_configure,
503+
.err_handler = &pdsc_err_handler,
454504
};
455505

456506
void *pdsc_get_pf_struct(struct pci_dev *vf_pdev)

0 commit comments

Comments
 (0)