Skip to content

Commit b09803b

Browse files
Oza Pawandeepbjorn-helgaas
authored andcommitted
PCI/DPC: Use the generic pcie_do_fatal_recovery() path
Our goal is to handle ERR_FATAL errors similarly, whether they are reported via AER or via DPC. A previous commit changed AER so it handles ERR_FATAL by calling driver .remove() methods and resetting the Link. DPC already does that (although the Link reset is done automatically by hardware and happens before we call the driver .remove() methods). Restructure the DPC code so it calls the same pcie_do_fatal_recovery() interface used by AER. This makes it clearer that we want to use the same path. Implement the .reset_link() method used by pcie_do_fatal_recovery(). For DPC, the actual reset is done automatically by hardware, so we really only have to wait for the Link to be inactive, then release the Port from DPC. Signed-off-by: Oza Pawandeep <poza@codeaurora.org> [bhelgaas: changelog, DPC_FATAL is not a bitfield, can be sequential] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 0b91439 commit b09803b

2 files changed

Lines changed: 34 additions & 20 deletions

File tree

‎drivers/pci/pcie/dpc.c‎

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,30 @@ static void dpc_wait_link_inactive(struct dpc_dev *dpc)
7373
pcie_wait_for_link(pdev, false);
7474
}
7575

76-
static void dpc_work(struct work_struct *work)
76+
static pci_ers_result_t dpc_reset_link(struct pci_dev *pdev)
7777
{
78-
struct dpc_dev *dpc = container_of(work, struct dpc_dev, work);
79-
struct pci_dev *dev, *temp, *pdev = dpc->dev->port;
80-
struct pci_bus *parent = pdev->subordinate;
81-
u16 cap = dpc->cap_pos, ctl;
82-
83-
pci_lock_rescan_remove();
84-
list_for_each_entry_safe_reverse(dev, temp, &parent->devices,
85-
bus_list) {
86-
pci_dev_get(dev);
87-
pci_dev_set_disconnected(dev, NULL);
88-
if (pci_has_subordinate(dev))
89-
pci_walk_bus(dev->subordinate,
90-
pci_dev_set_disconnected, NULL);
91-
pci_stop_and_remove_bus_device(dev);
92-
pci_dev_put(dev);
93-
}
94-
pci_unlock_rescan_remove();
95-
78+
struct dpc_dev *dpc;
79+
struct pcie_device *pciedev;
80+
struct device *devdpc;
81+
u16 cap, ctl;
82+
83+
/*
84+
* DPC disables the Link automatically in hardware, so it has
85+
* already been reset by the time we get here.
86+
*/
87+
devdpc = pcie_port_find_device(pdev, PCIE_PORT_SERVICE_DPC);
88+
pciedev = to_pcie_device(devdpc);
89+
dpc = get_service_data(pciedev);
90+
cap = dpc->cap_pos;
91+
92+
/*
93+
* Wait until the Link is inactive, then clear DPC Trigger Status
94+
* to allow the Port to leave DPC.
95+
*/
9696
dpc_wait_link_inactive(dpc);
97+
9798
if (dpc->rp_extensions && dpc_wait_rp_inactive(dpc))
98-
return;
99+
return PCI_ERS_RESULT_DISCONNECT;
99100
if (dpc->rp_extensions && dpc->rp_pio_status) {
100101
pci_write_config_dword(pdev, cap + PCI_EXP_DPC_RP_PIO_STATUS,
101102
dpc->rp_pio_status);
@@ -108,6 +109,17 @@ static void dpc_work(struct work_struct *work)
108109
pci_read_config_word(pdev, cap + PCI_EXP_DPC_CTL, &ctl);
109110
pci_write_config_word(pdev, cap + PCI_EXP_DPC_CTL,
110111
ctl | PCI_EXP_DPC_CTL_INT_EN);
112+
113+
return PCI_ERS_RESULT_RECOVERED;
114+
}
115+
116+
static void dpc_work(struct work_struct *work)
117+
{
118+
struct dpc_dev *dpc = container_of(work, struct dpc_dev, work);
119+
struct pci_dev *pdev = dpc->dev->port;
120+
121+
/* We configure DPC so it only triggers on ERR_FATAL */
122+
pcie_do_fatal_recovery(pdev, PCIE_PORT_SERVICE_DPC);
111123
}
112124

113125
static void dpc_process_rp_pio_error(struct dpc_dev *dpc)
@@ -288,6 +300,7 @@ static struct pcie_port_service_driver dpcdriver = {
288300
.service = PCIE_PORT_SERVICE_DPC,
289301
.probe = dpc_probe,
290302
.remove = dpc_remove,
303+
.reset_link = dpc_reset_link,
291304
};
292305

293306
static int __init dpc_service_init(void)

‎include/linux/aer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define AER_NONFATAL 0
1515
#define AER_FATAL 1
1616
#define AER_CORRECTABLE 2
17+
#define DPC_FATAL 3
1718

1819
struct pci_dev;
1920

0 commit comments

Comments
 (0)