Skip to content

Commit 2ae8fbb

Browse files
skoralahbjorn-helgaas
authored andcommitted
PCI/DPC: Ignore Surprise Down error on hot removal
According to PCIe r6.0 sec 6.7.6 [1], async removal with DPC may result in surprise down error. This error is expected and is just a side-effect of async remove. Ignore surprise down error generated as a side-effect of async remove. Typically, this error is benign as the pciehp handler invoked by PDC or/and DLLSC alongside DPC, de-enumerates and brings down the device appropriately, but the error messages might confuse users. Get rid of these irritating log messages with a 1s delay while pciehp waits for DPC recovery. The implementation is as follows: On an async remove a DPC is triggered along with a Presence Detect State change and/or DLL State Change. Determine it's an async remove by checking for DPC Trigger Status in DPC Status Register and Surprise Down Error Status in AER Uncorrected Error Status to be non-zero. If true, treat the DPC event as a side-effect of async remove, clear the error status registers and continue with hot-plug tear down routines. If not, follow the existing routine to handle AER and DPC errors. Masking Surprise Down Errors was explored as an alternative approach, but discarded due to the odd behavior that masking only avoids the interrupt, but still records an error per PCIe r6.0, sec 6.2.3.2.2. That stale error would be reported the next time some error other than Surprise Down is handled. Dmesg before: pcieport 0000:00:01.4: DPC: containment event, status:0x1f01 source:0x0000 pcieport 0000:00:01.4: DPC: unmasked uncorrectable error detected pcieport 0000:00:01.4: PCIe Bus Error: severity=Uncorrected (Fatal), type=Transaction Layer, (Receiver ID) pcieport 0000:00:01.4: device [1022:14ab] error status/mask=00000020/04004000 pcieport 0000:00:01.4: [ 5] SDES (First) nvme nvme2: frozen state error detected, reset controller pcieport 0000:00:01.4: DPC: Data Link Layer Link Active not set in 1000 msec pcieport 0000:00:01.4: AER: subordinate device reset failed pcieport 0000:00:01.4: AER: device recovery failed pcieport 0000:00:01.4: pciehp: Slot(16): Link Down nvme2n1: detected capacity change from 1953525168 to 0 pci 0000:04:00.0: Removing from iommu group 49 Dmesg after: pcieport 0000:00:01.4: pciehp: Slot(16): Link Down nvme1n1: detected capacity change from 1953525168 to 0 pci 0000:04:00.0: Removing from iommu group 37 [1] PCI Express Base Specification Revision 6.0, Dec 16 2021. https://members.pcisig.com/wg/PCI-SIG/document/16609 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Smita Koralahalli <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Lukas Wunner <[email protected]> Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]>
1 parent 6568d82 commit 2ae8fbb

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

drivers/pci/pcie/dpc.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,70 @@ void dpc_process_error(struct pci_dev *pdev)
303303
}
304304
}
305305

306+
static void pci_clear_surpdn_errors(struct pci_dev *pdev)
307+
{
308+
if (pdev->dpc_rp_extensions)
309+
pci_write_config_dword(pdev, pdev->dpc_cap +
310+
PCI_EXP_DPC_RP_PIO_STATUS, ~0);
311+
312+
/*
313+
* In practice, Surprise Down errors have been observed to also set
314+
* error bits in the Status Register as well as the Fatal Error
315+
* Detected bit in the Device Status Register.
316+
*/
317+
pci_write_config_word(pdev, PCI_STATUS, 0xffff);
318+
319+
pcie_capability_write_word(pdev, PCI_EXP_DEVSTA, PCI_EXP_DEVSTA_FED);
320+
}
321+
322+
static void dpc_handle_surprise_removal(struct pci_dev *pdev)
323+
{
324+
if (!pcie_wait_for_link(pdev, false)) {
325+
pci_info(pdev, "Data Link Layer Link Active not cleared in 1000 msec\n");
326+
goto out;
327+
}
328+
329+
if (pdev->dpc_rp_extensions && dpc_wait_rp_inactive(pdev))
330+
goto out;
331+
332+
pci_aer_raw_clear_status(pdev);
333+
pci_clear_surpdn_errors(pdev);
334+
335+
pci_write_config_word(pdev, pdev->dpc_cap + PCI_EXP_DPC_STATUS,
336+
PCI_EXP_DPC_STATUS_TRIGGER);
337+
338+
out:
339+
clear_bit(PCI_DPC_RECOVERED, &pdev->priv_flags);
340+
wake_up_all(&dpc_completed_waitqueue);
341+
}
342+
343+
static bool dpc_is_surprise_removal(struct pci_dev *pdev)
344+
{
345+
u16 status;
346+
347+
if (!pdev->is_hotplug_bridge)
348+
return false;
349+
350+
if (pci_read_config_word(pdev, pdev->aer_cap + PCI_ERR_UNCOR_STATUS,
351+
&status))
352+
return false;
353+
354+
return status & PCI_ERR_UNC_SURPDN;
355+
}
356+
306357
static irqreturn_t dpc_handler(int irq, void *context)
307358
{
308359
struct pci_dev *pdev = context;
309360

361+
/*
362+
* According to PCIe r6.0 sec 6.7.6, errors are an expected side effect
363+
* of async removal and should be ignored by software.
364+
*/
365+
if (dpc_is_surprise_removal(pdev)) {
366+
dpc_handle_surprise_removal(pdev);
367+
return IRQ_HANDLED;
368+
}
369+
310370
dpc_process_error(pdev);
311371

312372
/* We configure DPC so it only triggers on ERR_FATAL */

0 commit comments

Comments
 (0)