Skip to content

Commit 8039804

Browse files
benhartcheathamdjbw
authored andcommitted
cxl/core: Add CXL EINJ debugfs files
Export CXL helper functions in einj-cxl.c for getting/injecting available CXL protocol error types to sysfs under kernel/debug/cxl. The kernel/debug/cxl/einj_types file will print the available CXL protocol errors in the same format as the available_error_types file provided by the einj module. The kernel/debug/cxl/$dport_dev/einj_inject file is functionally the same as the error_type and error_inject files provided by the EINJ module, i.e.: writing an error type into $dport_dev/einj_inject will inject said error type into the CXL dport represented by $dport_dev. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Ben Cheatham <Benjamin.Cheatham@amd.com> Link: https://lore.kernel.org/r/20240311142508.31717-4-Benjamin.Cheatham@amd.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 12fb28e commit 8039804

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Documentation/ABI/testing/debugfs-cxl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,33 @@ Description:
3333
device cannot clear poison from the address, -ENXIO is returned.
3434
The clear_poison attribute is only visible for devices
3535
supporting the capability.
36+
37+
What: /sys/kernel/debug/cxl/einj_types
38+
Date: January, 2024
39+
KernelVersion: v6.9
40+
Contact: linux-cxl@vger.kernel.org
41+
Description:
42+
(RO) Prints the CXL protocol error types made available by
43+
the platform in the format "0x<error number> <error type>".
44+
The possible error types are (as of ACPI v6.5):
45+
0x1000 CXL.cache Protocol Correctable
46+
0x2000 CXL.cache Protocol Uncorrectable non-fatal
47+
0x4000 CXL.cache Protocol Uncorrectable fatal
48+
0x8000 CXL.mem Protocol Correctable
49+
0x10000 CXL.mem Protocol Uncorrectable non-fatal
50+
0x20000 CXL.mem Protocol Uncorrectable fatal
51+
52+
The <error number> can be written to einj_inject to inject
53+
<error type> into a chosen dport.
54+
55+
What: /sys/kernel/debug/cxl/$dport_dev/einj_inject
56+
Date: January, 2024
57+
KernelVersion: v6.9
58+
Contact: linux-cxl@vger.kernel.org
59+
Description:
60+
(WO) Writing an integer to this file injects the corresponding
61+
CXL protocol error into $dport_dev ($dport_dev will be a device
62+
name from /sys/bus/pci/devices). The integer to type mapping for
63+
injection can be found by reading from einj_types. If the dport
64+
was enumerated in RCH mode, a CXL 1.1 error is injected, otherwise
65+
a CXL 2.0 error is injected.

drivers/cxl/core/port.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/platform_device.h>
44
#include <linux/memregion.h>
55
#include <linux/workqueue.h>
6+
#include <linux/einj-cxl.h>
67
#include <linux/debugfs.h>
78
#include <linux/device.h>
89
#include <linux/module.h>
@@ -793,6 +794,40 @@ static int cxl_dport_setup_regs(struct device *host, struct cxl_dport *dport,
793794
return rc;
794795
}
795796

797+
DEFINE_SHOW_ATTRIBUTE(einj_cxl_available_error_type);
798+
799+
static int cxl_einj_inject(void *data, u64 type)
800+
{
801+
struct cxl_dport *dport = data;
802+
803+
if (dport->rch)
804+
return einj_cxl_inject_rch_error(dport->rcrb.base, type);
805+
806+
return einj_cxl_inject_error(to_pci_dev(dport->dport_dev), type);
807+
}
808+
DEFINE_DEBUGFS_ATTRIBUTE(cxl_einj_inject_fops, NULL, cxl_einj_inject,
809+
"0x%llx\n");
810+
811+
static void cxl_debugfs_create_dport_dir(struct cxl_dport *dport)
812+
{
813+
struct dentry *dir;
814+
815+
if (!einj_cxl_is_initialized())
816+
return;
817+
818+
/*
819+
* dport_dev needs to be a PCIe port for CXL 2.0+ ports because
820+
* EINJ expects a dport SBDF to be specified for 2.0 error injection.
821+
*/
822+
if (!dport->rch && !dev_is_pci(dport->dport_dev))
823+
return;
824+
825+
dir = cxl_debugfs_create_dir(dev_name(dport->dport_dev));
826+
827+
debugfs_create_file("einj_inject", 0200, dir, dport,
828+
&cxl_einj_inject_fops);
829+
}
830+
796831
static struct cxl_port *__devm_cxl_add_port(struct device *host,
797832
struct device *uport_dev,
798833
resource_size_t component_reg_phys,
@@ -1149,6 +1184,8 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,
11491184
if (dev_is_pci(dport_dev))
11501185
dport->link_latency = cxl_pci_get_latency(to_pci_dev(dport_dev));
11511186

1187+
cxl_debugfs_create_dport_dir(dport);
1188+
11521189
return dport;
11531190
}
11541191

@@ -2221,6 +2258,10 @@ static __init int cxl_core_init(void)
22212258

22222259
cxl_debugfs = debugfs_create_dir("cxl", NULL);
22232260

2261+
if (einj_cxl_is_initialized())
2262+
debugfs_create_file("einj_types", 0400, cxl_debugfs, NULL,
2263+
&einj_cxl_available_error_type_fops);
2264+
22242265
cxl_mbox_init();
22252266

22262267
rc = cxl_memdev_init();

0 commit comments

Comments
 (0)