Skip to content

Commit f9c6833

Browse files
weiny2djbw
authored andcommitted
cxl/events: Create a CXL event union
The CXL CPER and event log records share everything but a UUID/GUID in their structures. Define a cxl_event union without the UUID/GUID to be shared between the CPER and event log record formats. Adjust the code to use this union. Signed-off-by: Ira Weiny <ira.weiny@intel.com> Link: https://lore.kernel.org/r/20231220-cxl-cper-v5-6-1bb8a4ca2c7a@intel.com 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 6eade11 commit f9c6833

4 files changed

Lines changed: 52 additions & 42 deletions

File tree

drivers/cxl/core/mbox.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -840,26 +840,17 @@ static void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
840840
enum cxl_event_log_type type,
841841
struct cxl_event_record_raw *record)
842842
{
843+
union cxl_event *evt = &record->event;
843844
uuid_t *id = &record->id;
844845

845-
if (uuid_equal(id, &CXL_EVENT_GEN_MEDIA_UUID)) {
846-
struct cxl_event_gen_media *rec =
847-
(struct cxl_event_gen_media *)record;
848-
849-
trace_cxl_general_media(cxlmd, type, rec);
850-
} else if (uuid_equal(id, &CXL_EVENT_DRAM_UUID)) {
851-
struct cxl_event_dram *rec = (struct cxl_event_dram *)record;
852-
853-
trace_cxl_dram(cxlmd, type, rec);
854-
} else if (uuid_equal(id, &CXL_EVENT_MEM_MODULE_UUID)) {
855-
struct cxl_event_mem_module *rec =
856-
(struct cxl_event_mem_module *)record;
857-
858-
trace_cxl_memory_module(cxlmd, type, rec);
859-
} else {
860-
/* For unknown record types print just the header */
861-
trace_cxl_generic_event(cxlmd, type, id, record);
862-
}
846+
if (uuid_equal(id, &CXL_EVENT_GEN_MEDIA_UUID))
847+
trace_cxl_general_media(cxlmd, type, &evt->gen_media);
848+
else if (uuid_equal(id, &CXL_EVENT_DRAM_UUID))
849+
trace_cxl_dram(cxlmd, type, &evt->dram);
850+
else if (uuid_equal(id, &CXL_EVENT_MEM_MODULE_UUID))
851+
trace_cxl_memory_module(cxlmd, type, &evt->mem_module);
852+
else
853+
trace_cxl_generic_event(cxlmd, type, id, &evt->generic);
863854
}
864855

865856
static int cxl_clear_event_record(struct cxl_memdev_state *mds,
@@ -902,7 +893,10 @@ static int cxl_clear_event_record(struct cxl_memdev_state *mds,
902893
*/
903894
i = 0;
904895
for (cnt = 0; cnt < total; cnt++) {
905-
payload->handles[i++] = get_pl->records[cnt].hdr.handle;
896+
struct cxl_event_record_raw *raw = &get_pl->records[cnt];
897+
struct cxl_event_generic *gen = &raw->event.generic;
898+
899+
payload->handles[i++] = gen->hdr.handle;
906900
dev_dbg(mds->cxlds.dev, "Event log '%d': Clearing %u\n", log,
907901
le16_to_cpu(payload->handles[i]));
908902

drivers/cxl/core/trace.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,19 @@ TRACE_EVENT(cxl_overflow,
225225
TRACE_EVENT(cxl_generic_event,
226226

227227
TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
228-
const uuid_t *uuid, struct cxl_event_record_raw *rec),
228+
const uuid_t *uuid, struct cxl_event_generic *gen_rec),
229229

230-
TP_ARGS(cxlmd, log, uuid, rec),
230+
TP_ARGS(cxlmd, log, uuid, gen_rec),
231231

232232
TP_STRUCT__entry(
233233
CXL_EVT_TP_entry
234234
__array(u8, data, CXL_EVENT_RECORD_DATA_LENGTH)
235235
),
236236

237237
TP_fast_assign(
238-
CXL_EVT_TP_fast_assign(cxlmd, log, rec->hdr);
238+
CXL_EVT_TP_fast_assign(cxlmd, log, gen_rec->hdr);
239239
memcpy(&__entry->hdr_uuid, uuid, sizeof(uuid_t));
240-
memcpy(__entry->data, &rec->data, CXL_EVENT_RECORD_DATA_LENGTH);
240+
memcpy(__entry->data, gen_rec->data, CXL_EVENT_RECORD_DATA_LENGTH);
241241
),
242242

243243
CXL_EVT_TP_printk("%s",

include/linux/cxl-event.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ struct cxl_event_record_hdr {
1717
u8 reserved[15];
1818
} __packed;
1919

20-
/*
21-
* Common Event Record Format
22-
* CXL rev 3.0 section 8.2.9.2.1; Table 8-42
23-
*/
2420
#define CXL_EVENT_RECORD_DATA_LENGTH 0x50
25-
struct cxl_event_record_raw {
26-
uuid_t id;
21+
struct cxl_event_generic {
2722
struct cxl_event_record_hdr hdr;
2823
u8 data[CXL_EVENT_RECORD_DATA_LENGTH];
2924
} __packed;
@@ -96,4 +91,20 @@ struct cxl_event_mem_module {
9691
u8 reserved[0x3d];
9792
} __packed;
9893

94+
union cxl_event {
95+
struct cxl_event_generic generic;
96+
struct cxl_event_gen_media gen_media;
97+
struct cxl_event_dram dram;
98+
struct cxl_event_mem_module mem_module;
99+
} __packed;
100+
101+
/*
102+
* Common Event Record Format; in event logs
103+
* CXL rev 3.0 section 8.2.9.2.1; Table 8-42
104+
*/
105+
struct cxl_event_record_raw {
106+
uuid_t id;
107+
union cxl_event event;
108+
} __packed;
109+
99110
#endif /* _LINUX_CXL_EVENT_H */

tools/testing/cxl/test/mem.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ static int mock_get_event(struct device *dev, struct cxl_mbox_cmd *cmd)
251251
for (i = 0; i < CXL_TEST_EVENT_CNT && !event_log_empty(log); i++) {
252252
memcpy(&pl->records[i], event_get_current(log),
253253
sizeof(pl->records[i]));
254-
pl->records[i].hdr.handle = event_get_cur_event_handle(log);
254+
pl->records[i].event.generic.hdr.handle =
255+
event_get_cur_event_handle(log);
255256
log->cur_idx++;
256257
}
257258

@@ -339,25 +340,29 @@ static void cxl_mock_event_trigger(struct device *dev)
339340
struct cxl_event_record_raw maint_needed = {
340341
.id = UUID_INIT(0xBA5EBA11, 0xABCD, 0xEFEB,
341342
0xa5, 0x5a, 0xa5, 0x5a, 0xa5, 0xa5, 0x5a, 0xa5),
342-
.hdr = {
343-
.length = sizeof(struct cxl_event_record_raw),
344-
.flags[0] = CXL_EVENT_RECORD_FLAG_MAINT_NEEDED,
345-
/* .handle = Set dynamically */
346-
.related_handle = cpu_to_le16(0xa5b6),
343+
.event.generic = {
344+
.hdr = {
345+
.length = sizeof(struct cxl_event_record_raw),
346+
.flags[0] = CXL_EVENT_RECORD_FLAG_MAINT_NEEDED,
347+
/* .handle = Set dynamically */
348+
.related_handle = cpu_to_le16(0xa5b6),
349+
},
350+
.data = { 0xDE, 0xAD, 0xBE, 0xEF },
347351
},
348-
.data = { 0xDE, 0xAD, 0xBE, 0xEF },
349352
};
350353

351354
struct cxl_event_record_raw hardware_replace = {
352355
.id = UUID_INIT(0xABCDEFEB, 0xBA11, 0xBA5E,
353356
0xa5, 0x5a, 0xa5, 0x5a, 0xa5, 0xa5, 0x5a, 0xa5),
354-
.hdr = {
355-
.length = sizeof(struct cxl_event_record_raw),
356-
.flags[0] = CXL_EVENT_RECORD_FLAG_HW_REPLACE,
357-
/* .handle = Set dynamically */
358-
.related_handle = cpu_to_le16(0xb6a5),
357+
.event.generic = {
358+
.hdr = {
359+
.length = sizeof(struct cxl_event_record_raw),
360+
.flags[0] = CXL_EVENT_RECORD_FLAG_HW_REPLACE,
361+
/* .handle = Set dynamically */
362+
.related_handle = cpu_to_le16(0xb6a5),
363+
},
364+
.data = { 0xDE, 0xAD, 0xBE, 0xEF },
359365
},
360-
.data = { 0xDE, 0xAD, 0xBE, 0xEF },
361366
};
362367

363368
struct cxl_test_gen_media {

0 commit comments

Comments
 (0)