Merge tag 'cxl-for-6.7' of git://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl
[sfrench/cifs-2.6.git] / drivers / pci / pcie / aer.c
index 41076cb2956e6c939fbf8065e36419e841b2bc39..42a3bd35a3e118d8eb656d1d24b9f0fa0f4afaf7 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/kfifo.h>
 #include <linux/slab.h>
 #include <acpi/apei.h>
+#include <acpi/ghes.h>
 #include <ras/ras_event.h>
 
 #include "../pci.h"
@@ -1143,6 +1144,15 @@ static void aer_recover_work_func(struct work_struct *work)
                        continue;
                }
                pci_print_aer(pdev, entry.severity, entry.regs);
+               /*
+                * Memory for aer_capability_regs(entry.regs) is being allocated from the
+                * ghes_estatus_pool to protect it from overwriting when multiple sections
+                * are present in the error status. Thus free the same after processing
+                * the data.
+                */
+               ghes_estatus_pool_region_free((unsigned long)entry.regs,
+                                             sizeof(struct aer_capability_regs));
+
                if (entry.severity == AER_NONFATAL)
                        pcie_do_recovery(pdev, pci_channel_io_normal,
                                         aer_root_reset);
@@ -1360,6 +1370,28 @@ static irqreturn_t aer_irq(int irq, void *context)
        return IRQ_WAKE_THREAD;
 }
 
+static void aer_enable_irq(struct pci_dev *pdev)
+{
+       int aer = pdev->aer_cap;
+       u32 reg32;
+
+       /* Enable Root Port's interrupt in response to error messages */
+       pci_read_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, &reg32);
+       reg32 |= ROOT_PORT_INTR_ON_MESG_MASK;
+       pci_write_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, reg32);
+}
+
+static void aer_disable_irq(struct pci_dev *pdev)
+{
+       int aer = pdev->aer_cap;
+       u32 reg32;
+
+       /* Disable Root's interrupt in response to error messages */
+       pci_read_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, &reg32);
+       reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK;
+       pci_write_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, reg32);
+}
+
 /**
  * aer_enable_rootport - enable Root Port's interrupts when receiving messages
  * @rpc: pointer to a Root Port data structure
@@ -1389,10 +1421,7 @@ static void aer_enable_rootport(struct aer_rpc *rpc)
        pci_read_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS, &reg32);
        pci_write_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS, reg32);
 
-       /* Enable Root Port's interrupt in response to error messages */
-       pci_read_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, &reg32);
-       reg32 |= ROOT_PORT_INTR_ON_MESG_MASK;
-       pci_write_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, reg32);
+       aer_enable_irq(pdev);
 }
 
 /**
@@ -1407,10 +1436,7 @@ static void aer_disable_rootport(struct aer_rpc *rpc)
        int aer = pdev->aer_cap;
        u32 reg32;
 
-       /* Disable Root's interrupt in response to error messages */
-       pci_read_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, &reg32);
-       reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK;
-       pci_write_config_dword(pdev, aer + PCI_ERR_ROOT_COMMAND, reg32);
+       aer_disable_irq(pdev);
 
        /* Clear Root's error status reg */
        pci_read_config_dword(pdev, aer + PCI_ERR_ROOT_STATUS, &reg32);
@@ -1506,12 +1532,8 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
         */
        aer = root ? root->aer_cap : 0;
 
-       if ((host->native_aer || pcie_ports_native) && aer) {
-               /* Disable Root's interrupt in response to error messages */
-               pci_read_config_dword(root, aer + PCI_ERR_ROOT_COMMAND, &reg32);
-               reg32 &= ~ROOT_PORT_INTR_ON_MESG_MASK;
-               pci_write_config_dword(root, aer + PCI_ERR_ROOT_COMMAND, reg32);
-       }
+       if ((host->native_aer || pcie_ports_native) && aer)
+               aer_disable_irq(root);
 
        if (type == PCI_EXP_TYPE_RC_EC || type == PCI_EXP_TYPE_RC_END) {
                rc = pcie_reset_flr(dev, PCI_RESET_DO_RESET);
@@ -1530,10 +1552,7 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev)
                pci_read_config_dword(root, aer + PCI_ERR_ROOT_STATUS, &reg32);
                pci_write_config_dword(root, aer + PCI_ERR_ROOT_STATUS, reg32);
 
-               /* Enable Root Port's interrupt in response to error messages */
-               pci_read_config_dword(root, aer + PCI_ERR_ROOT_COMMAND, &reg32);
-               reg32 |= ROOT_PORT_INTR_ON_MESG_MASK;
-               pci_write_config_dword(root, aer + PCI_ERR_ROOT_COMMAND, reg32);
+               aer_enable_irq(root);
        }
 
        return rc ? PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_RECOVERED;