Skip to contentSkip to conversation

cxl: Remove ifdef blocks of CONFIG_PCIEAER_CXL from core/pci.c

PATCH Superseded Dave Jiang 2 participants 3 messages Jul 25, 2025 – Jul 29, 2025 CXL

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Dave Jiang

author maintainer
#0 lore raw

PATCH v3 1/1 cxl: Remove ifdef blocks of CONFIG_PCIEAER_CXL from core/pci.c

Create new config CONFIG_CXL_RAS and put all CXL RAS items behind the config. The config will depend on CPER or PCIE AER to build. Move the related RAS code from core/pci.c to core/ras.c.

---
v3:
- Gate everything behind CONFIG_CXL_RAS and move to core/ras.c (Dan)
- Move the PCI AER handlers to ras.c as well. (Terry)

---
 drivers/cxl/Kconfig       |   4 +
 drivers/cxl/core/Makefile |   2 +-
 drivers/cxl/core/core.h   |   9 ++
 drivers/cxl/core/pci.c    | 319 --------------------------------------
 drivers/cxl/core/ras.c    | 313 +++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxl.h         |   8 -
 drivers/cxl/cxlpci.h      |  16 ++
 tools/testing/cxl/Kbuild  |   1 +
 8 files changed, 344 insertions(+), 328 deletions(-)
drivers/cxl/Kconfig +4 -0
index 48b7314afdb8..6a3895440163 100644
@@ -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 || PCIEAER_CXL
+
 endif
drivers/cxl/core/Makefile +1 -1
index 79e2ef81fde8..1c652e575aaa 100644
@@ -14,10 +14,10 @@ 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-y += acpi.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
drivers/cxl/core/core.h +9 -0
index 29b61828a847..ff1a478e690f 100644
@@ -136,4 +136,13 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,
 		    u16 *return_code);
 #endif
 
+#ifdef CONFIG_CXL_RAS
+void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds);
+#else
+static inline void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds) {}
+#endif
+
+void __cxl_handle_cor_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base);
+bool __cxl_handle_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base);
+
 #endif /* __CXL_CORE_H__ */
drivers/cxl/core/pci.c +0 -319

331 lines not on this page · raw message

drivers/cxl/core/ras.c +313 -0

323 lines not on this page · raw message

drivers/cxl/cxl.h +0 -8
index f68a9414da26..ddf0ee46b116 100644
@@ -760,14 +760,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);
drivers/cxl/cxlpci.h +16 -0
index 54e219b0049e..9063134c85d9 100644
@@ -132,7 +132,23 @@ struct cxl_dev_state;
 int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
 			struct cxl_endpoint_dvsec_info *info);
 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_NO_AER_DRIVER;
+}
+
+static inline void cxl_dport_init_ras_reporting(struct cxl_dport *dport,
+						struct device *host) { }
+#endif
+
 #endif /* __CXL_PCI_H__ */
tools/testing/cxl/Kbuild +1 -0
index 31a2d73c963f..4cc8099bbcd2 100644
@@ -68,6 +68,7 @@ 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

base-commit: 6e130ce1dfd47a1ef953d0be127934760aecb769

Signature · 1 line
2.50.1
#1 lore raw
Quoted 29 lines · Dave Jiang

Create new config CONFIG_CXL_RAS and put all CXL RAS items behind the config. The config will depend on CPER or PCIE AER to build. Move the related RAS code from core/pci.c to core/ras.c.

---
v3:
- Gate everything behind CONFIG_CXL_RAS and move to core/ras.c (Dan)
- Move the PCI AER handlers to ras.c as well. (Terry)

---
 drivers/cxl/Kconfig       |   4 +
 drivers/cxl/core/Makefile |   2 +-
 drivers/cxl/core/core.h   |   9 ++
 drivers/cxl/core/pci.c    | 319 --------------------------------------
 drivers/cxl/core/ras.c    | 313 +++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxl.h         |   8 -
 drivers/cxl/cxlpci.h      |  16 ++
 tools/testing/cxl/Kbuild  |   1 +
 8 files changed, 344 insertions(+), 328 deletions(-)
drivers/cxl/Kconfig +0 -0
index 48b7314afdb8..6a3895440163 100644

drivers/cxl/Kconfig config CXL_MCE · line 238

Quoted 6 lines
drivers/cxl/Kconfig +3 -0
@@ -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 || PCIEAER_CXL

No need for "|| PCIEAER" because PCIEAER_CXL has "depends on PCIEAER".

Quoted 24 lines
drivers/cxl/Kconfig +1 -0
+
 endif
drivers/cxl/core/Makefile +1 -1
index 79e2ef81fde8..1c652e575aaa 100644
@@ -14,10 +14,10 @@ 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-y += acpi.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
drivers/cxl/core/core.h +0 -0
index 29b61828a847..ff1a478e690f 100644
@@ -136,4 +136,13 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,
 		    u16 *return_code);

drivers/cxl/core/core.h int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, · line 146

Quoted 10 lines
drivers/cxl/core/core.h +8 -0
 #endif
 
+#ifdef CONFIG_CXL_RAS
+void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds);
+#else
+static inline void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds) {}
+#endif
+
+void __cxl_handle_cor_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base);
+bool __cxl_handle_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base);

No need for any of this, all of these functions can now be marked static. Now, it does mean that some of these need to be reordered in the file before their first use, but with this patch already doing code movement might as well move the code to the right order in the file and skip the need to do forward declarations.

[..]

Quoted 11 lines
drivers/cxl/cxlpci.h +2 -0
index 54e219b0049e..9063134c85d9 100644
@@ -132,7 +132,23 @@ struct cxl_dev_state;
 int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
 			struct cxl_endpoint_dvsec_info *info);
 void read_cdat_data(struct cxl_port *port);
+
+#ifdef CONFIG_CXL_RAS
 void cxl_cor_error_detected(struct pci_dev *pdev);

drivers/cxl/cxlpci.h struct cxl_dev_state; · line 147

Quoted 10 lines
drivers/cxl/cxlpci.h +8 -0
 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_NO_AER_DRIVER;

I would have expected PCI_ERS_RESULT_NONE. Not that it matters much. The only way this is possible is if AER is turned off, and if AER is turned off, this will never be called.

author maintainer
#2 lore raw
Quoted 33 lines · On 7/25/25 1:26 PM, [email protected] wrote:
Quoted 32 lines · Dave Jiang

Create new config CONFIG_CXL_RAS and put all CXL RAS items behind the config. The config will depend on CPER or PCIE AER to build. Move the related RAS code from core/pci.c to core/ras.c.

---
v3:
- Gate everything behind CONFIG_CXL_RAS and move to core/ras.c (Dan)
- Move the PCI AER handlers to ras.c as well. (Terry)

---
 drivers/cxl/Kconfig       |   4 +
 drivers/cxl/core/Makefile |   2 +-
 drivers/cxl/core/core.h   |   9 ++
 drivers/cxl/core/pci.c    | 319 --------------------------------------
 drivers/cxl/core/ras.c    | 313 +++++++++++++++++++++++++++++++++++++
 drivers/cxl/cxl.h         |   8 -
 drivers/cxl/cxlpci.h      |  16 ++
 tools/testing/cxl/Kbuild  |   1 +
 8 files changed, 344 insertions(+), 328 deletions(-)
drivers/cxl/Kconfig +0 -0
index 48b7314afdb8..6a3895440163 100644
@@ -233,4 +233,8 @@ config CXL_MCE
 	def_bool y
 	depends on X86_MCE && MEMORY_FAILURE
 
Quoted 5 lines

drivers/cxl/Kconfig config CXL_MCE · line 238

Quoted 3 lines
drivers/cxl/Kconfig +3 -0
+config CXL_RAS
+	def_bool y
+	depends on ACPI_APEI_GHES || PCIEAER || PCIEAER_CXL

No need for "|| PCIEAER" because PCIEAER_CXL has "depends on PCIEAER".

ok

Quoted 27 lines
Quoted 27 lines
drivers/cxl/Kconfig +1 -0
+
 endif
drivers/cxl/core/Makefile +1 -1
index 79e2ef81fde8..1c652e575aaa 100644
@@ -14,10 +14,10 @@ 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-y += acpi.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
drivers/cxl/core/core.h +0 -0
index 29b61828a847..ff1a478e690f 100644
@@ -136,4 +136,13 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid,
 		    u16 *return_code);
 #endif
 
Quoted 14 lines

drivers/cxl/core/core.h int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, · line 146

Quoted 8 lines
drivers/cxl/core/core.h +8 -0
+#ifdef CONFIG_CXL_RAS
+void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds);
+#else
+static inline void cxl_handle_rdport_errors(struct cxl_dev_state *cxlds) {}
+#endif
+
+void __cxl_handle_cor_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base);
+bool __cxl_handle_ras(struct cxl_dev_state *cxlds, void __iomem *ras_base);

No need for any of this, all of these functions can now be marked static. Now, it does mean that some of these need to be reordered in the file before their first use, but with this patch already doing code movement might as well move the code to the right order in the file and skip the need to do forward declarations.

ok I'll move those around.

Quoted 19 lines

[..]

Quoted 17 lines
drivers/cxl/cxlpci.h +6 -0
index 54e219b0049e..9063134c85d9 100644
@@ -132,7 +132,23 @@ struct cxl_dev_state;
 int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
 			struct cxl_endpoint_dvsec_info *info);
 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) { }
+
Quoted 8 lines

drivers/cxl/cxlpci.h struct cxl_dev_state; · line 147

Quoted 4 lines
drivers/cxl/cxlpci.h +4 -0
+static inline pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
+						  pci_channel_state_t state)
+{
+	return PCI_ERS_RESULT_NO_AER_DRIVER;

I would have expected PCI_ERS_RESULT_NONE. Not that it matters much. The only way this is possible is if AER is turned off, and if AER is turned off, this will never be called.

Just figure that if it gets called (not that it will), it would be reasonable to return no driver since the driver is disabled.