]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cxl/pci: Remove CXL VH handling in CONFIG_PCIEAER_CXL conditional blocks from core...
authorDave Jiang <dave.jiang@intel.com>
Wed, 14 Jan 2026 18:20:28 +0000 (12:20 -0600)
committerDave Jiang <dave.jiang@intel.com>
Thu, 22 Jan 2026 21:58:03 +0000 (14:58 -0700)
Create new config CONFIG_CXL_RAS and put all CXL RAS items behind the
config. The config will depend on CPER and PCIE AER to build. Move the
related VH RAS code from core/pci.c to core/ras.c.

Restricted CXL host (RCH) RAS functions will be moved in a future patch.

Cc: Robert Richter <rrichter@amd.com>
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Co-developed-by: Terry Bowman <terry.bowman@amd.com>
Signed-off-by: Terry Bowman <terry.bowman@amd.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Link: https://patch.msgid.link/20260114182055.46029-8-terry.bowman@amd.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/Kconfig
drivers/cxl/core/Makefile
drivers/cxl/core/core.h
drivers/cxl/core/pci.c
drivers/cxl/core/ras.c
drivers/cxl/cxl.h
drivers/cxl/cxlpci.h
tools/testing/cxl/Kbuild

index 48b7314afdb88c66d13222af6e95102a31cc8a24..217888992c882a5a877f02a91c8d1f9749ea8953 100644 (file)
@@ -233,4 +233,8 @@ config CXL_MCE
        def_bool y
        depends on X86_MCE && MEMORY_FAILURE
 
+config CXL_RAS
+       def_bool y
+       depends on ACPI_APEI_GHES && PCIEAER && CXL_PCI
+
 endif
index 5ad8fef210b5c8a871ce06d9f13a0c0f7410cfdc..b2930cc54f8ba2a3082a0e439031a04977a04c12 100644 (file)
@@ -14,9 +14,9 @@ cxl_core-y += pci.o
 cxl_core-y += hdm.o
 cxl_core-y += pmu.o
 cxl_core-y += cdat.o
-cxl_core-y += ras.o
 cxl_core-$(CONFIG_TRACING) += trace.o
 cxl_core-$(CONFIG_CXL_REGION) += region.o
 cxl_core-$(CONFIG_CXL_MCE) += mce.o
 cxl_core-$(CONFIG_CXL_FEATURES) += features.o
 cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.o
+cxl_core-$(CONFIG_CXL_RAS) += ras.o
index 1fb66132b77771dcef41185141768ff43f086b0c..bc818de87ccccf18ae5e9dda084451fa74702d36 100644 (file)
@@ -144,8 +144,39 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c);
 int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
                                        struct access_coordinate *c);
 
+#ifdef CONFIG_CXL_RAS
 int cxl_ras_init(void);
 void cxl_ras_exit(void);
+bool cxl_handle_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base);
+void cxl_handle_cor_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base);
+#else
+static inline int cxl_ras_init(void)
+{
+       return 0;
+}
+
+static inline void cxl_ras_exit(void)
+{
+}
+
+static inline bool cxl_handle_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base)
+{
+       return false;
+}
+static inline void cxl_handle_cor_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base) { }
+#endif /* CONFIG_CXL_RAS */
+
+/* Restricted CXL Host specific RAS functions */
+#ifdef CONFIG_CXL_RAS
+void cxl_dport_map_rch_aer(struct cxl_dport *dport);
+void cxl_disable_rch_root_ints(struct cxl_dport *dport);
+void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds);
+#else
+static inline void cxl_dport_map_rch_aer(struct cxl_dport *dport) { }
+static inline void cxl_disable_rch_root_ints(struct cxl_dport *dport) { }
+static inline void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds) { }
+#endif /* CONFIG_CXL_RAS */
+
 int cxl_gpf_port_setup(struct cxl_dport *dport);
 
 struct cxl_hdm;
index 51bb0f372e40dd9c2430d753e63aeabb0e23926d..e132fff809792eccd71564a3a1827f6421c584bb 100644 (file)
@@ -632,81 +632,8 @@ err:
 }
 EXPORT_SYMBOL_NS_GPL(read_cdat_data, "CXL");
 
-static void cxl_handle_cor_ras(struct cxl_dev_state *cxlds,
-                              void __iomem *ras_base)
-{
-       void __iomem *addr;
-       u32 status;
-
-       if (!ras_base)
-               return;
-
-       addr = ras_base + CXL_RAS_CORRECTABLE_STATUS_OFFSET;
-       status = readl(addr);
-       if (status & CXL_RAS_CORRECTABLE_STATUS_MASK) {
-               writel(status & CXL_RAS_CORRECTABLE_STATUS_MASK, addr);
-               trace_cxl_aer_correctable_error(cxlds->cxlmd, status);
-       }
-}
-
-/* CXL spec rev3.0 8.2.4.16.1 */
-static void header_log_copy(void __iomem *ras_base, u32 *log)
-{
-       void __iomem *addr;
-       u32 *log_addr;
-       int i, log_u32_size = CXL_HEADERLOG_SIZE / sizeof(u32);
-
-       addr = ras_base + CXL_RAS_HEADER_LOG_OFFSET;
-       log_addr = log;
-
-       for (i = 0; i < log_u32_size; i++) {
-               *log_addr = readl(addr);
-               log_addr++;
-               addr += sizeof(u32);
-       }
-}
-
-/*
- * Log the state of the RAS status registers and prepare them to log the
- * next error status. Return 1 if reset needed.
- */
-static bool cxl_handle_ras(struct cxl_dev_state *cxlds,
-                          void __iomem *ras_base)
-{
-       u32 hl[CXL_HEADERLOG_SIZE_U32];
-       void __iomem *addr;
-       u32 status;
-       u32 fe;
-
-       if (!ras_base)
-               return false;
-
-       addr = ras_base + CXL_RAS_UNCORRECTABLE_STATUS_OFFSET;
-       status = readl(addr);
-       if (!(status & CXL_RAS_UNCORRECTABLE_STATUS_MASK))
-               return false;
-
-       /* If multiple errors, log header points to first error from ctrl reg */
-       if (hweight32(status) > 1) {
-               void __iomem *rcc_addr =
-                       ras_base + CXL_RAS_CAP_CONTROL_OFFSET;
-
-               fe = BIT(FIELD_GET(CXL_RAS_CAP_CONTROL_FE_MASK,
-                                  readl(rcc_addr)));
-       } else {
-               fe = status;
-       }
-
-       header_log_copy(ras_base, hl);
-       trace_cxl_aer_uncorrectable_error(cxlds->cxlmd, status, fe, hl);
-       writel(status & CXL_RAS_UNCORRECTABLE_STATUS_MASK, addr);
-
-       return true;
-}
-
-#ifdef CONFIG_PCIEAER_CXL
-
-static void cxl_dport_map_rch_aer(struct cxl_dport *dport)
+#ifdef CONFIG_CXL_RAS
+void cxl_dport_map_rch_aer(struct cxl_dport *dport)
 {
        resource_size_t aer_phys;
        struct device *host;
@@ -721,19 +648,7 @@ static void cxl_dport_map_rch_aer(struct cxl_dport *dport)
        }
 }
 
-static void cxl_dport_map_ras(struct cxl_dport *dport)
-{
-       struct cxl_register_map *map = &dport->reg_map;
-       struct device *dev = dport->dport_dev;
-
-       if (!map->component_map.ras.valid)
-               dev_dbg(dev, "RAS registers not found\n");
-       else if (cxl_map_component_regs(map, &dport->regs.component,
-                                       BIT(CXL_CM_CAP_CAP_ID_RAS)))
-               dev_dbg(dev, "Failed to map RAS capability.\n");
-}
-
-static void cxl_disable_rch_root_ints(struct cxl_dport *dport)
+void cxl_disable_rch_root_ints(struct cxl_dport *dport)
 {
        void __iomem *aer_base = dport->regs.dport_aer;
        u32 aer_cmd_mask, aer_cmd;
@@ -757,28 +672,6 @@ static void cxl_disable_rch_root_ints(struct cxl_dport *dport)
        writel(aer_cmd, aer_base + PCI_ERR_ROOT_COMMAND);
 }
 
-/**
- * cxl_dport_init_ras_reporting - Setup CXL RAS report on this dport
- * @dport: the cxl_dport that needs to be initialized
- * @host: host device for devm operations
- */
-void cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host)
-{
-       dport->reg_map.host = host;
-       cxl_dport_map_ras(dport);
-
-       if (dport->rch) {
-               struct pci_host_bridge *host_bridge = to_pci_host_bridge(dport->dport_dev);
-
-               if (!host_bridge->native_aer)
-                       return;
-
-               cxl_dport_map_rch_aer(dport);
-               cxl_disable_rch_root_ints(dport);
-       }
-}
-EXPORT_SYMBOL_NS_GPL(cxl_dport_init_ras_reporting, "CXL");
-
 /*
  * Copy the AER capability registers using 32 bit read accesses.
  * This is necessary because RCRB AER capability is MMIO mapped. Clear the
@@ -827,7 +720,7 @@ static bool cxl_rch_get_aer_severity(struct aer_capability_regs *aer_regs,
        return false;
 }
 
-static void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds)
+void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds)
 {
        struct pci_dev *pdev = to_pci_dev(cxlds->dev);
        struct aer_capability_regs aer_regs;
@@ -852,82 +745,8 @@ static void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds)
        else
                cxl_handle_ras(cxlds, dport->regs.ras);
 }
-
-#else
-static void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds) { }
 #endif
 
-void cxl_cor_error_detected(struct pci_dev *pdev)
-{
-       struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
-       struct device *dev = &cxlds->cxlmd->dev;
-
-       scoped_guard(device, dev) {
-               if (!dev->driver) {
-                       dev_warn(&pdev->dev,
-                                "%s: memdev disabled, abort error handling\n",
-                                dev_name(dev));
-                       return;
-               }
-
-               if (cxlds->rcd)
-                       cxl_handle_rdport_errors(cxlds);
-
-               cxl_handle_cor_ras(cxlds, cxlds->regs.ras);
-       }
-}
-EXPORT_SYMBOL_NS_GPL(cxl_cor_error_detected, "CXL");
-
-pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
-                                   pci_channel_state_t state)
-{
-       struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
-       struct cxl_memdev *cxlmd = cxlds->cxlmd;
-       struct device *dev = &cxlmd->dev;
-       bool ue;
-
-       scoped_guard(device, dev) {
-               if (!dev->driver) {
-                       dev_warn(&pdev->dev,
-                                "%s: memdev disabled, abort error handling\n",
-                                dev_name(dev));
-                       return PCI_ERS_RESULT_DISCONNECT;
-               }
-
-               if (cxlds->rcd)
-                       cxl_handle_rdport_errors(cxlds);
-               /*
-                * A frozen channel indicates an impending reset which is fatal to
-                * CXL.mem operation, and will likely crash the system. On the off
-                * chance the situation is recoverable dump the status of the RAS
-                * capability registers and bounce the active state of the memdev.
-                */
-               ue = cxl_handle_ras(cxlds, cxlds->regs.ras);
-       }
-
-
-       switch (state) {
-       case pci_channel_io_normal:
-               if (ue) {
-                       device_release_driver(dev);
-                       return PCI_ERS_RESULT_NEED_RESET;
-               }
-               return PCI_ERS_RESULT_CAN_RECOVER;
-       case pci_channel_io_frozen:
-               dev_warn(&pdev->dev,
-                        "%s: frozen state error detected, disable CXL.mem\n",
-                        dev_name(dev));
-               device_release_driver(dev);
-               return PCI_ERS_RESULT_NEED_RESET;
-       case pci_channel_io_perm_failure:
-               dev_warn(&pdev->dev,
-                        "failure state error detected, request disconnect\n");
-               return PCI_ERS_RESULT_DISCONNECT;
-       }
-       return PCI_ERS_RESULT_NEED_RESET;
-}
-EXPORT_SYMBOL_NS_GPL(cxl_error_detected, "CXL");
-
 static int cxl_flit_size(struct pci_dev *pdev)
 {
        if (cxl_pci_flit_256(pdev))
index 2731ba3a07993c5a8fecb0e4d76081afff7d432e..b933030b8e1e778647c12297d8735ba780a4efbc 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/aer.h>
 #include <cxl/event.h>
 #include <cxlmem.h>
+#include <cxlpci.h>
 #include "trace.h"
 
 static void cxl_cper_trace_corr_port_prot_err(struct pci_dev *pdev,
@@ -124,3 +125,178 @@ void cxl_ras_exit(void)
        cxl_cper_unregister_prot_err_work(&cxl_cper_prot_err_work);
        cancel_work_sync(&cxl_cper_prot_err_work);
 }
+
+static void cxl_dport_map_ras(struct cxl_dport *dport)
+{
+       struct cxl_register_map *map = &dport->reg_map;
+       struct device *dev = dport->dport_dev;
+
+       if (!map->component_map.ras.valid)
+               dev_dbg(dev, "RAS registers not found\n");
+       else if (cxl_map_component_regs(map, &dport->regs.component,
+                                       BIT(CXL_CM_CAP_CAP_ID_RAS)))
+               dev_dbg(dev, "Failed to map RAS capability.\n");
+}
+
+/**
+ * cxl_dport_init_ras_reporting - Setup CXL RAS report on this dport
+ * @dport: the cxl_dport that needs to be initialized
+ * @host: host device for devm operations
+ */
+void cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host)
+{
+       dport->reg_map.host = host;
+       cxl_dport_map_ras(dport);
+
+       if (dport->rch) {
+               struct pci_host_bridge *host_bridge = to_pci_host_bridge(dport->dport_dev);
+
+               if (!host_bridge->native_aer)
+                       return;
+
+               cxl_dport_map_rch_aer(dport);
+               cxl_disable_rch_root_ints(dport);
+       }
+}
+EXPORT_SYMBOL_NS_GPL(cxl_dport_init_ras_reporting, "CXL");
+
+void cxl_handle_cor_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base)
+{
+       void __iomem *addr;
+       u32 status;
+
+       if (!ras_base)
+               return;
+
+       addr = ras_base + CXL_RAS_CORRECTABLE_STATUS_OFFSET;
+       status = readl(addr);
+       if (status & CXL_RAS_CORRECTABLE_STATUS_MASK) {
+               writel(status & CXL_RAS_CORRECTABLE_STATUS_MASK, addr);
+               trace_cxl_aer_correctable_error(cxlds->cxlmd, status);
+       }
+}
+
+/* CXL spec rev3.0 8.2.4.16.1 */
+static void header_log_copy(void __iomem *ras_base, u32 *log)
+{
+       void __iomem *addr;
+       u32 *log_addr;
+       int i, log_u32_size = CXL_HEADERLOG_SIZE / sizeof(u32);
+
+       addr = ras_base + CXL_RAS_HEADER_LOG_OFFSET;
+       log_addr = log;
+
+       for (i = 0; i < log_u32_size; i++) {
+               *log_addr = readl(addr);
+               log_addr++;
+               addr += sizeof(u32);
+       }
+}
+
+/*
+ * Log the state of the RAS status registers and prepare them to log the
+ * next error status. Return 1 if reset needed.
+ */
+bool cxl_handle_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base)
+{
+       u32 hl[CXL_HEADERLOG_SIZE_U32];
+       void __iomem *addr;
+       u32 status;
+       u32 fe;
+
+       if (!ras_base)
+               return false;
+
+       addr = ras_base + CXL_RAS_UNCORRECTABLE_STATUS_OFFSET;
+       status = readl(addr);
+       if (!(status & CXL_RAS_UNCORRECTABLE_STATUS_MASK))
+               return false;
+
+       /* If multiple errors, log header points to first error from ctrl reg */
+       if (hweight32(status) > 1) {
+               void __iomem *rcc_addr =
+                       ras_base + CXL_RAS_CAP_CONTROL_OFFSET;
+
+               fe = BIT(FIELD_GET(CXL_RAS_CAP_CONTROL_FE_MASK,
+                                  readl(rcc_addr)));
+       } else {
+               fe = status;
+       }
+
+       header_log_copy(ras_base, hl);
+       trace_cxl_aer_uncorrectable_error(cxlds->cxlmd, status, fe, hl);
+       writel(status & CXL_RAS_UNCORRECTABLE_STATUS_MASK, addr);
+
+       return true;
+}
+
+void cxl_cor_error_detected(struct pci_dev *pdev)
+{
+       struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
+       struct device *dev = &cxlds->cxlmd->dev;
+
+       scoped_guard(device, dev) {
+               if (!dev->driver) {
+                       dev_warn(&pdev->dev,
+                                "%s: memdev disabled, abort error handling\n",
+                                dev_name(dev));
+                       return;
+               }
+
+               if (cxlds->rcd)
+                       cxl_handle_rdport_errors(cxlds);
+
+               cxl_handle_cor_ras(cxlds, cxlds->regs.ras);
+       }
+}
+EXPORT_SYMBOL_NS_GPL(cxl_cor_error_detected, "CXL");
+
+pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
+                                   pci_channel_state_t state)
+{
+       struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
+       struct cxl_memdev *cxlmd = cxlds->cxlmd;
+       struct device *dev = &cxlmd->dev;
+       bool ue;
+
+       scoped_guard(device, dev) {
+               if (!dev->driver) {
+                       dev_warn(&pdev->dev,
+                                "%s: memdev disabled, abort error handling\n",
+                                dev_name(dev));
+                       return PCI_ERS_RESULT_DISCONNECT;
+               }
+
+               if (cxlds->rcd)
+                       cxl_handle_rdport_errors(cxlds);
+               /*
+                * A frozen channel indicates an impending reset which is fatal to
+                * CXL.mem operation, and will likely crash the system. On the off
+                * chance the situation is recoverable dump the status of the RAS
+                * capability registers and bounce the active state of the memdev.
+                */
+               ue = cxl_handle_ras(cxlds, cxlds->regs.ras);
+       }
+
+
+       switch (state) {
+       case pci_channel_io_normal:
+               if (ue) {
+                       device_release_driver(dev);
+                       return PCI_ERS_RESULT_NEED_RESET;
+               }
+               return PCI_ERS_RESULT_CAN_RECOVER;
+       case pci_channel_io_frozen:
+               dev_warn(&pdev->dev,
+                        "%s: frozen state error detected, disable CXL.mem\n",
+                        dev_name(dev));
+               device_release_driver(dev);
+               return PCI_ERS_RESULT_NEED_RESET;
+       case pci_channel_io_perm_failure:
+               dev_warn(&pdev->dev,
+                        "failure state error detected, request disconnect\n");
+               return PCI_ERS_RESULT_DISCONNECT;
+       }
+       return PCI_ERS_RESULT_NEED_RESET;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_error_detected, "CXL");
index ba17fa86d249ebd097198f5e8cf053d48fde54b7..42a76a7a088f57cb557a94f989e7d8ca8e44a274 100644 (file)
@@ -803,14 +803,6 @@ struct cxl_dport *devm_cxl_add_rch_dport(struct cxl_port *port,
                                         struct device *dport_dev, int port_id,
                                         resource_size_t rcrb);
 
-#ifdef CONFIG_PCIEAER_CXL
-void cxl_setup_parent_dport(struct device *host, struct cxl_dport *dport);
-void cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host);
-#else
-static inline void cxl_dport_init_ras_reporting(struct cxl_dport *dport,
-                                               struct device *host) { }
-#endif
-
 struct cxl_decoder *to_cxl_decoder(struct device *dev);
 struct cxl_root_decoder *to_cxl_root_decoder(struct device *dev);
 struct cxl_switch_decoder *to_cxl_switch_decoder(struct device *dev);
index cdb7cf3dbcb4378d0aab4f94789eb72d37cfdc84..6f9c78886fd9a822cc0a8b905ac28933521e8c2e 100644 (file)
@@ -76,7 +76,23 @@ static inline bool cxl_pci_flit_256(struct pci_dev *pdev)
 
 struct cxl_dev_state;
 void read_cdat_data(struct cxl_port *port);
+
+#ifdef CONFIG_CXL_RAS
 void cxl_cor_error_detected(struct pci_dev *pdev);
 pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
                                    pci_channel_state_t state);
+void cxl_dport_init_ras_reporting(struct cxl_dport *dport, struct device *host);
+#else
+static inline void cxl_cor_error_detected(struct pci_dev *pdev) { }
+
+static inline pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
+                                                 pci_channel_state_t state)
+{
+       return PCI_ERS_RESULT_NONE;
+}
+
+static inline void cxl_dport_init_ras_reporting(struct cxl_dport *dport,
+                                               struct device *host) { }
+#endif
+
 #endif /* __CXL_PCI_H__ */
index 0e151d0572d1f6e69978a4d6b243085b50527d71..b7ea66382f3b1bfbb00b0d988eb96876c4f60a60 100644 (file)
@@ -57,12 +57,12 @@ cxl_core-y += $(CXL_CORE_SRC)/pci.o
 cxl_core-y += $(CXL_CORE_SRC)/hdm.o
 cxl_core-y += $(CXL_CORE_SRC)/pmu.o
 cxl_core-y += $(CXL_CORE_SRC)/cdat.o
-cxl_core-y += $(CXL_CORE_SRC)/ras.o
 cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o
 cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o
 cxl_core-$(CONFIG_CXL_MCE) += $(CXL_CORE_SRC)/mce.o
 cxl_core-$(CONFIG_CXL_FEATURES) += $(CXL_CORE_SRC)/features.o
 cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += $(CXL_CORE_SRC)/edac.o
+cxl_core-$(CONFIG_CXL_RAS) += $(CXL_CORE_SRC)/ras.o
 cxl_core-y += config_check.o
 cxl_core-y += cxl_core_test.o
 cxl_core-y += cxl_core_exports.o