When firmware grants control of Advanced Error Reporting to the operating
system, that not only encompasses the AER capability, but also error
enable/status bits in the Device Control and Device Status registers
(PCI Firmware r3.3 table 4-6 bit 3).

PCIe devices without AER capability still support baseline capability
error reporting through these enable/status bits (PCIe r7.1 sec 6.2.1),
but the bits must not be modified unless AER control was granted.

pcie_aer_is_native() is unsuitable to check for control of AER-incapable
devices because it implicitly checks for presence of an AER capability.

Move that check to its callers (where needed) to allow using the function
for the imminent baseline capability error reporting.

Signed-off-by: Lukas Wunner <[email protected]>
---
Changes v1 -> v2:
  * Amend kernel-doc of pci_aer_unmask_internal_errors() (Sathya).
 
 drivers/pci/pcie/aer.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c
index 51cf2ff8c85a..9bb8e2127849 100644
--- a/drivers/pci/pcie/aer.c
+++ b/drivers/pci/pcie/aer.c
@@ -263,9 +263,6 @@ int pcie_aer_is_native(struct pci_dev *dev)
 {
        struct pci_host_bridge *host = pci_find_host_bridge(dev->bus);
 
-       if (!dev->aer_cap)
-               return 0;
-
        return host->native_aer;
 }
 EXPORT_SYMBOL_NS_GPL(pcie_aer_is_native, "CXL");
@@ -286,7 +283,7 @@ int pci_aer_clear_nonfatal_status(struct pci_dev *dev)
        int aer = dev->aer_cap;
        u32 status, sev;
 
-       if (!pcie_aer_is_native(dev))
+       if (!aer || !pcie_aer_is_native(dev))
                return -EIO;
 
        /* Clear status bits for ERR_NONFATAL errors only */
@@ -305,7 +302,7 @@ void pci_aer_clear_fatal_status(struct pci_dev *dev)
        int aer = dev->aer_cap;
        u32 status, sev;
 
-       if (!pcie_aer_is_native(dev))
+       if (!aer || !pcie_aer_is_native(dev))
                return;
 
        /* Clear status bits for ERR_FATAL errors only */
@@ -1288,7 +1285,7 @@ static bool find_source_device(struct pci_dev *parent,
  * Mask registers.
  *
  * Note: AER must be enabled and supported by the device which must be
- * checked in advance, e.g. with pcie_aer_is_native().
+ * checked in advance, e.g. with dev->aer_cap && pcie_aer_is_native(dev).
  */
 void pci_aer_unmask_internal_errors(struct pci_dev *dev)
 {
-- 
2.53.0


Reply via email to