On 3/13/24 12:58 AM, Dan Williams wrote: > Ben Cheatham wrote: >> Move CXL protocol error types from einj.c (now einj-core.c) to einj-cxl.c. >> einj-cxl.c implements the necessary handling for CXL protocol error >> injection and exposes an API for the CXL core to use said functionality, >> while also allowing the EINJ module to be built without CXL support. >> Because CXL error types targeting CXL 1.0/1.1 ports require special >> handling, only allow them to be injected through the new cxl debugfs >> interface (next commit) and return an error when attempting to inject >> through the legacy interface. >> >> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx> >> Signed-off-by: Ben Cheatham <Benjamin.Cheatham@xxxxxxx> >> --- >> MAINTAINERS | 1 + >> drivers/acpi/apei/Kconfig | 12 +++ >> drivers/acpi/apei/Makefile | 2 + >> drivers/acpi/apei/apei-internal.h | 18 ++++ >> drivers/acpi/apei/{einj.c => einj-core.c} | 77 ++++++++++---- >> drivers/acpi/apei/einj-cxl.c | 116 ++++++++++++++++++++++ >> include/linux/einj-cxl.h | 44 ++++++++ >> 7 files changed, 252 insertions(+), 18 deletions(-) >> rename drivers/acpi/apei/{einj.c => einj-core.c} (93%) >> create mode 100644 drivers/acpi/apei/einj-cxl.c >> create mode 100644 include/linux/einj-cxl.h >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> index 2ecaaec6a6bf..90cf8403dd17 100644 >> --- a/MAINTAINERS >> +++ b/MAINTAINERS >> @@ -5289,6 +5289,7 @@ M: Dan Williams <dan.j.williams@xxxxxxxxx> >> L: linux-cxl@xxxxxxxxxxxxxxx >> S: Maintained >> F: drivers/cxl/ >> +F: include/linux/cxl-einj.h >> F: include/linux/cxl-event.h >> F: include/uapi/linux/cxl_mem.h >> F: tools/testing/cxl/ >> diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig >> index 6b18f8bc7be3..f01afa2805be 100644 >> --- a/drivers/acpi/apei/Kconfig >> +++ b/drivers/acpi/apei/Kconfig >> @@ -60,6 +60,18 @@ config ACPI_APEI_EINJ >> mainly used for debugging and testing the other parts of >> APEI and some other RAS features. >> >> +config ACPI_APEI_EINJ_CXL >> + bool "CXL Error INJection Support" >> + default ACPI_APEI_EINJ >> + depends on ACPI_APEI_EINJ && CXL_BUS <= ACPI_APEI_EINJ >> + help >> + Support for CXL protocol Error INJection through debugfs/cxl. >> + Availability and which errors are supported is dependent on >> + the host platform. Look to ACPI v6.5 section 18.6.4 and kernel >> + EINJ documentation for more information. >> + >> + If unsure say 'n' >> + >> config ACPI_APEI_ERST_DEBUG >> tristate "APEI Error Record Serialization Table (ERST) Debug Support" >> depends on ACPI_APEI >> diff --git a/drivers/acpi/apei/Makefile b/drivers/acpi/apei/Makefile >> index 4dfac2128737..2c474e6477e1 100644 >> --- a/drivers/acpi/apei/Makefile >> +++ b/drivers/acpi/apei/Makefile >> @@ -2,6 +2,8 @@ >> obj-$(CONFIG_ACPI_APEI) += apei.o >> obj-$(CONFIG_ACPI_APEI_GHES) += ghes.o >> obj-$(CONFIG_ACPI_APEI_EINJ) += einj.o >> +einj-y := einj-core.o >> +einj-$(CONFIG_ACPI_APEI_EINJ_CXL) += einj-cxl.o >> obj-$(CONFIG_ACPI_APEI_ERST_DEBUG) += erst-dbg.o >> >> apei-y := apei-base.o hest.o erst.o bert.o >> diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h >> index 67c2c3b959e1..cd2766c69d78 100644 >> --- a/drivers/acpi/apei/apei-internal.h >> +++ b/drivers/acpi/apei/apei-internal.h >> @@ -130,4 +130,22 @@ static inline u32 cper_estatus_len(struct acpi_hest_generic_status *estatus) >> } >> >> int apei_osc_setup(void); >> + >> +int einj_get_available_error_type(u32 *type); >> +int einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2, u64 param3, >> + u64 param4); >> +int einj_cxl_rch_error_inject(u32 type, u32 flags, u64 param1, u64 param2, >> + u64 param3, u64 param4); >> +bool einj_is_cxl_error_type(u64 type); >> +int einj_validate_error_type(u64 type); >> + >> +#ifndef ACPI_EINJ_CXL_CACHE_CORRECTABLE >> +#define ACPI_EINJ_CXL_CACHE_CORRECTABLE BIT(12) >> +#define ACPI_EINJ_CXL_CACHE_UNCORRECTABLE BIT(13) >> +#define ACPI_EINJ_CXL_CACHE_FATAL BIT(14) >> +#define ACPI_EINJ_CXL_MEM_CORRECTABLE BIT(15) >> +#define ACPI_EINJ_CXL_MEM_UNCORRECTABLE BIT(16) >> +#define ACPI_EINJ_CXL_MEM_FATAL BIT(17) >> +#endif >> + >> #endif >> diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj-core.c >> similarity index 93% >> rename from drivers/acpi/apei/einj.c >> rename to drivers/acpi/apei/einj-core.c >> index 937c69844dac..9affbe807ded 100644 >> --- a/drivers/acpi/apei/einj.c >> +++ b/drivers/acpi/apei/einj-core.c > [..] >> + /* >> + * Injections targeting a CXL 1.0/1.1 port have to be injected >> + * via the einj_cxl_rch_error_inject() path as that does the proper >> + * validation of the given RCRB base (MMIO) address. >> + */ >> + if (einj_is_cxl_error_type(type) && (flags & SETWA_FLAGS_MEM)) { >> + return -EINVAL; >> + } > > Checkpatch says: > > WARNING: braces {} are not necessary for single statement blocks > #170: FILE: drivers/acpi/apei/einj-core.c:578: > + if (einj_is_cxl_error_type(type) && (flags & SETWA_FLAGS_MEM)) { > + return -EINVAL; > + } > > > Fixed. That's interesting, I have checkpatch set to run on git commit so I should've seen that. I'll need to take another look at my setup.