Skip to content

Commit b07461a

Browse files
izumi777bjorn-helgaas
authored andcommitted
PCI/AER: Clear error status registers during enumeration and restore
AER errors might be recorded when powering-on devices. These errors can be ignored, so firmware usually clears them before the OS enumerates devices. However, firmware is not involved when devices are added via hotplug, so the OS may discover power-up errors that should be ignored. The same may happen when powering up devices when resuming after suspend. Clear the AER error status registers during enumeration and resume. [bhelgaas: changelog, remove repetitive comments] Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 6ff33f3 commit b07461a

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎drivers/pci/pci.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/pci_hotplug.h>
2828
#include <asm-generic/pci-bridge.h>
2929
#include <asm/setup.h>
30+
#include <linux/aer.h>
3031
#include "pci.h"
3132

3233
const char *pci_power_names[] = {
@@ -1099,6 +1100,8 @@ void pci_restore_state(struct pci_dev *dev)
10991100
pci_restore_ats_state(dev);
11001101
pci_restore_vc_state(dev);
11011102

1103+
pci_cleanup_aer_error_status_regs(dev);
1104+
11021105
pci_restore_config_space(dev);
11031106

11041107
pci_restore_pcix_state(dev);

‎drivers/pci/pcie/aer/aerdrv_core.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,34 @@ int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
7474
}
7575
EXPORT_SYMBOL_GPL(pci_cleanup_aer_uncorrect_error_status);
7676

77+
int pci_cleanup_aer_error_status_regs(struct pci_dev *dev)
78+
{
79+
int pos;
80+
u32 status;
81+
int port_type;
82+
83+
if (!pci_is_pcie(dev))
84+
return -ENODEV;
85+
86+
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
87+
if (!pos)
88+
return -EIO;
89+
90+
port_type = pci_pcie_type(dev);
91+
if (port_type == PCI_EXP_TYPE_ROOT_PORT) {
92+
pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &status);
93+
pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, status);
94+
}
95+
96+
pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status);
97+
pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, status);
98+
99+
pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
100+
pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
101+
102+
return 0;
103+
}
104+
77105
/**
78106
* add_error_device - list device to be handled
79107
* @e_info: pointer to error info

‎drivers/pci/probe.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/module.h>
1313
#include <linux/cpumask.h>
1414
#include <linux/pci-aspm.h>
15+
#include <linux/aer.h>
1516
#include <asm-generic/pci-bridge.h>
1617
#include "pci.h"
1718

@@ -1621,6 +1622,8 @@ static void pci_init_capabilities(struct pci_dev *dev)
16211622

16221623
/* Enable ACS P2P upstream forwarding */
16231624
pci_enable_acs(dev);
1625+
1626+
pci_cleanup_aer_error_status_regs(dev);
16241627
}
16251628

16261629
static void pci_set_msi_domain(struct pci_dev *dev)

‎include/linux/aer.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct aer_capability_regs {
4242
int pci_enable_pcie_error_reporting(struct pci_dev *dev);
4343
int pci_disable_pcie_error_reporting(struct pci_dev *dev);
4444
int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev);
45+
int pci_cleanup_aer_error_status_regs(struct pci_dev *dev);
4546
#else
4647
static inline int pci_enable_pcie_error_reporting(struct pci_dev *dev)
4748
{
@@ -55,6 +56,10 @@ static inline int pci_cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
5556
{
5657
return -EINVAL;
5758
}
59+
static inline int pci_cleanup_aer_error_status_regs(struct pci_dev *dev)
60+
{
61+
return -EINVAL;
62+
}
5863
#endif
5964

6065
void cper_print_aer(struct pci_dev *dev, int cper_severity,

0 commit comments

Comments
 (0)