Skip to content

Commit dc97f63

Browse files
weiny2djbw
authored andcommitted
cxl/pci: Register for and process CPER events
If the firmware has configured CXL event support to be firmware first the OS can process those events through CPER records. The CXL layer has unique DPA to HPA knowledge and standard event trace parsing in place. CPER records contain Bus, Device, Function information which can be used to identify the PCI device which is sending the event. Change the PCI driver registration to include registration of a CXL CPER callback to process events through the trace subsystem. Use new scoped based management to simplify the handling of the PCI device object. Tested-by: Smita-Koralahalli <Smita.KoralahalliChannabasappa@amd.com> Reviewed-by: Smita-Koralahalli <Smita.KoralahalliChannabasappa@amd.com> Link: https://lore.kernel.org/r/20231220-cxl-cper-v5-9-1bb8a4ca2c7a@intel.com Signed-off-by: Ira Weiny <ira.weiny@intel.com> [djbw: use new pci_dev guard, flip init order] Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent ced085e commit dc97f63

4 files changed

Lines changed: 90 additions & 13 deletions

File tree

drivers/cxl/core/mbox.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -836,21 +836,37 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds)
836836
}
837837
EXPORT_SYMBOL_NS_GPL(cxl_enumerate_cmds, CXL);
838838

839-
static void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
840-
enum cxl_event_log_type type,
841-
struct cxl_event_record_raw *record)
839+
void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
840+
enum cxl_event_log_type type,
841+
enum cxl_event_type event_type,
842+
const uuid_t *uuid, union cxl_event *evt)
842843
{
843-
union cxl_event *evt = &record->event;
844-
uuid_t *id = &record->id;
845-
846-
if (uuid_equal(id, &CXL_EVENT_GEN_MEDIA_UUID))
844+
if (event_type == CXL_CPER_EVENT_GEN_MEDIA)
847845
trace_cxl_general_media(cxlmd, type, &evt->gen_media);
848-
else if (uuid_equal(id, &CXL_EVENT_DRAM_UUID))
846+
else if (event_type == CXL_CPER_EVENT_DRAM)
849847
trace_cxl_dram(cxlmd, type, &evt->dram);
850-
else if (uuid_equal(id, &CXL_EVENT_MEM_MODULE_UUID))
848+
else if (event_type == CXL_CPER_EVENT_MEM_MODULE)
851849
trace_cxl_memory_module(cxlmd, type, &evt->mem_module);
852850
else
853-
trace_cxl_generic_event(cxlmd, type, id, &evt->generic);
851+
trace_cxl_generic_event(cxlmd, type, uuid, &evt->generic);
852+
}
853+
EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, CXL);
854+
855+
static void __cxl_event_trace_record(const struct cxl_memdev *cxlmd,
856+
enum cxl_event_log_type type,
857+
struct cxl_event_record_raw *record)
858+
{
859+
enum cxl_event_type ev_type = CXL_CPER_EVENT_GENERIC;
860+
const uuid_t *uuid = &record->id;
861+
862+
if (uuid_equal(uuid, &CXL_EVENT_GEN_MEDIA_UUID))
863+
ev_type = CXL_CPER_EVENT_GEN_MEDIA;
864+
else if (uuid_equal(uuid, &CXL_EVENT_DRAM_UUID))
865+
ev_type = CXL_CPER_EVENT_DRAM;
866+
else if (uuid_equal(uuid, &CXL_EVENT_MEM_MODULE_UUID))
867+
ev_type = CXL_CPER_EVENT_MEM_MODULE;
868+
869+
cxl_event_trace_record(cxlmd, type, ev_type, uuid, &record->event);
854870
}
855871

856872
static int cxl_clear_event_record(struct cxl_memdev_state *mds,
@@ -961,8 +977,8 @@ static void cxl_mem_get_records_log(struct cxl_memdev_state *mds,
961977
break;
962978

963979
for (i = 0; i < nr_rec; i++)
964-
cxl_event_trace_record(cxlmd, type,
965-
&payload->records[i]);
980+
__cxl_event_trace_record(cxlmd, type,
981+
&payload->records[i]);
966982

967983
if (payload->flags & CXL_GET_EVENT_FLAG_OVERFLOW)
968984
trace_cxl_overflow(cxlmd, type, payload);

drivers/cxl/cxlmem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ void set_exclusive_cxl_commands(struct cxl_memdev_state *mds,
802802
void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds,
803803
unsigned long *cmds);
804804
void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status);
805+
void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
806+
enum cxl_event_log_type type,
807+
enum cxl_event_type event_type,
808+
const uuid_t *uuid, union cxl_event *evt);
805809
int cxl_set_timestamp(struct cxl_memdev_state *mds);
806810
int cxl_poison_state_init(struct cxl_memdev_state *mds);
807811
int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,

drivers/cxl/pci.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/* Copyright(c) 2020 Intel Corporation. All rights reserved. */
3+
#include <asm-generic/unaligned.h>
34
#include <linux/io-64-nonatomic-lo-hi.h>
45
#include <linux/moduleparam.h>
56
#include <linux/module.h>
@@ -969,6 +970,61 @@ static struct pci_driver cxl_pci_driver = {
969970
},
970971
};
971972

973+
#define CXL_EVENT_HDR_FLAGS_REC_SEVERITY GENMASK(1, 0)
974+
static void cxl_cper_event_call(enum cxl_event_type ev_type,
975+
struct cxl_cper_event_rec *rec)
976+
{
977+
struct cper_cxl_event_devid *device_id = &rec->hdr.device_id;
978+
struct pci_dev *pdev __free(pci_dev_put) = NULL;
979+
enum cxl_event_log_type log_type;
980+
struct cxl_dev_state *cxlds;
981+
unsigned int devfn;
982+
u32 hdr_flags;
983+
984+
devfn = PCI_DEVFN(device_id->device_num, device_id->func_num);
985+
pdev = pci_get_domain_bus_and_slot(device_id->segment_num,
986+
device_id->bus_num, devfn);
987+
if (!pdev)
988+
return;
989+
990+
guard(pci_dev)(pdev);
991+
if (pdev->driver != &cxl_pci_driver)
992+
return;
993+
994+
cxlds = pci_get_drvdata(pdev);
995+
if (!cxlds)
996+
return;
997+
998+
/* Fabricate a log type */
999+
hdr_flags = get_unaligned_le24(rec->event.generic.hdr.flags);
1000+
log_type = FIELD_GET(CXL_EVENT_HDR_FLAGS_REC_SEVERITY, hdr_flags);
1001+
1002+
cxl_event_trace_record(cxlds->cxlmd, log_type, ev_type,
1003+
&uuid_null, &rec->event);
1004+
}
1005+
1006+
static int __init cxl_pci_driver_init(void)
1007+
{
1008+
int rc;
1009+
1010+
rc = cxl_cper_register_callback(cxl_cper_event_call);
1011+
if (rc)
1012+
return rc;
1013+
1014+
rc = pci_register_driver(&cxl_pci_driver);
1015+
if (rc)
1016+
cxl_cper_unregister_callback(cxl_cper_event_call);
1017+
1018+
return rc;
1019+
}
1020+
1021+
static void __exit cxl_pci_driver_exit(void)
1022+
{
1023+
pci_unregister_driver(&cxl_pci_driver);
1024+
cxl_cper_unregister_callback(cxl_cper_event_call);
1025+
}
1026+
1027+
module_init(cxl_pci_driver_init);
1028+
module_exit(cxl_pci_driver_exit);
9721029
MODULE_LICENSE("GPL v2");
973-
module_pci_driver(cxl_pci_driver);
9741030
MODULE_IMPORT_NS(CXL);

include/linux/cxl-event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct cxl_event_record_raw {
108108
} __packed;
109109

110110
enum cxl_event_type {
111+
CXL_CPER_EVENT_GENERIC,
111112
CXL_CPER_EVENT_GEN_MEDIA,
112113
CXL_CPER_EVENT_DRAM,
113114
CXL_CPER_EVENT_MEM_MODULE,

0 commit comments

Comments
 (0)