1 // SPDX-License-Identifier: GPL-2.0-only
3 * CXL Error INJection support. Used by CXL core to inject
4 * protocol errors into CXL ports.
6 * Copyright (C) 2023 Advanced Micro Devices, Inc.
8 * Author: Ben Cheatham <benjamin.cheatham@amd.com>
10 #include <linux/seq_file.h>
11 #include <linux/pci.h>
14 #include "apei-internal.h"
16 /* Defined in einj-core.c */
17 extern bool einj_initialized
;
19 static struct { u32 mask
; const char *str
; } const einj_cxl_error_type_string
[] = {
20 { ACPI_EINJ_CXL_CACHE_CORRECTABLE
, "CXL.cache Protocol Correctable" },
21 { ACPI_EINJ_CXL_CACHE_UNCORRECTABLE
, "CXL.cache Protocol Uncorrectable non-fatal" },
22 { ACPI_EINJ_CXL_CACHE_FATAL
, "CXL.cache Protocol Uncorrectable fatal" },
23 { ACPI_EINJ_CXL_MEM_CORRECTABLE
, "CXL.mem Protocol Correctable" },
24 { ACPI_EINJ_CXL_MEM_UNCORRECTABLE
, "CXL.mem Protocol Uncorrectable non-fatal" },
25 { ACPI_EINJ_CXL_MEM_FATAL
, "CXL.mem Protocol Uncorrectable fatal" },
28 int einj_cxl_available_error_type_show(struct seq_file
*m
, void *v
)
31 u32 available_error_type
= 0;
33 rc
= einj_get_available_error_type(&available_error_type
);
37 for (int pos
= 0; pos
< ARRAY_SIZE(einj_cxl_error_type_string
); pos
++) {
38 cxl_err
= ACPI_EINJ_CXL_CACHE_CORRECTABLE
<< pos
;
40 if (available_error_type
& cxl_err
)
41 seq_printf(m
, "0x%08x\t%s\n",
42 einj_cxl_error_type_string
[pos
].mask
,
43 einj_cxl_error_type_string
[pos
].str
);
48 EXPORT_SYMBOL_NS_GPL(einj_cxl_available_error_type_show
, "CXL");
50 static int cxl_dport_get_sbdf(struct pci_dev
*dport_dev
, u64
*sbdf
)
53 struct pci_host_bridge
*bridge
;
56 pbus
= dport_dev
->bus
;
57 bridge
= pci_find_host_bridge(pbus
);
62 if (bridge
->domain_nr
!= PCI_DOMAIN_NR_NOT_SET
)
63 seg
= bridge
->domain_nr
;
66 *sbdf
= (seg
<< 24) | (bus
<< 16) | (dport_dev
->devfn
<< 8);
71 int einj_cxl_inject_rch_error(u64 rcrb
, u64 type
)
75 /* Only CXL error types can be specified */
76 if (!einj_is_cxl_error_type(type
))
79 rc
= einj_validate_error_type(type
);
83 return einj_cxl_rch_error_inject(type
, 0x2, rcrb
, GENMASK_ULL(63, 0),
86 EXPORT_SYMBOL_NS_GPL(einj_cxl_inject_rch_error
, "CXL");
88 int einj_cxl_inject_error(struct pci_dev
*dport
, u64 type
)
93 /* Only CXL error types can be specified */
94 if (!einj_is_cxl_error_type(type
))
97 rc
= einj_validate_error_type(type
);
101 rc
= cxl_dport_get_sbdf(dport
, ¶m4
);
105 return einj_error_inject(type
, 0x4, 0, 0, 0, param4
);
107 EXPORT_SYMBOL_NS_GPL(einj_cxl_inject_error
, "CXL");
109 bool einj_cxl_is_initialized(void)
111 return einj_initialized
;
113 EXPORT_SYMBOL_NS_GPL(einj_cxl_is_initialized
, "CXL");