xref: /linux/drivers/cxl/core/trace.h (revision f9c683386f5bc0364615138ce2b14be50848dbcf)
14a20bc3eSDan Williams // SPDX-License-Identifier: GPL-2.0
24a20bc3eSDan Williams /* Copyright(c) 2022 Intel Corporation. All rights reserved. */
34a20bc3eSDan Williams #undef TRACE_SYSTEM
44a20bc3eSDan Williams #define TRACE_SYSTEM cxl
54a20bc3eSDan Williams 
64a20bc3eSDan Williams #if !defined(_CXL_EVENTS_H) || defined(TRACE_HEADER_MULTI_READ)
74a20bc3eSDan Williams #define _CXL_EVENTS_H
84a20bc3eSDan Williams 
94a20bc3eSDan Williams #include <linux/tracepoint.h>
10ddf49d57SAlison Schofield #include <linux/pci.h>
116ebe28f9SIra Weiny #include <asm-generic/unaligned.h>
126ebe28f9SIra Weiny 
136ebe28f9SIra Weiny #include <cxl.h>
146ebe28f9SIra Weiny #include <cxlmem.h>
15ddf49d57SAlison Schofield #include "core.h"
164a20bc3eSDan Williams 
174a20bc3eSDan Williams #define CXL_RAS_UC_CACHE_DATA_PARITY	BIT(0)
184a20bc3eSDan Williams #define CXL_RAS_UC_CACHE_ADDR_PARITY	BIT(1)
194a20bc3eSDan Williams #define CXL_RAS_UC_CACHE_BE_PARITY	BIT(2)
204a20bc3eSDan Williams #define CXL_RAS_UC_CACHE_DATA_ECC	BIT(3)
214a20bc3eSDan Williams #define CXL_RAS_UC_MEM_DATA_PARITY	BIT(4)
224a20bc3eSDan Williams #define CXL_RAS_UC_MEM_ADDR_PARITY	BIT(5)
234a20bc3eSDan Williams #define CXL_RAS_UC_MEM_BE_PARITY	BIT(6)
244a20bc3eSDan Williams #define CXL_RAS_UC_MEM_DATA_ECC		BIT(7)
254a20bc3eSDan Williams #define CXL_RAS_UC_REINIT_THRESH	BIT(8)
264a20bc3eSDan Williams #define CXL_RAS_UC_RSVD_ENCODE		BIT(9)
274a20bc3eSDan Williams #define CXL_RAS_UC_POISON		BIT(10)
284a20bc3eSDan Williams #define CXL_RAS_UC_RECV_OVERFLOW	BIT(11)
294a20bc3eSDan Williams #define CXL_RAS_UC_INTERNAL_ERR		BIT(14)
304a20bc3eSDan Williams #define CXL_RAS_UC_IDE_TX_ERR		BIT(15)
314a20bc3eSDan Williams #define CXL_RAS_UC_IDE_RX_ERR		BIT(16)
324a20bc3eSDan Williams 
334a20bc3eSDan Williams #define show_uc_errs(status)	__print_flags(status, " | ",		  \
344a20bc3eSDan Williams 	{ CXL_RAS_UC_CACHE_DATA_PARITY, "Cache Data Parity Error" },	  \
354a20bc3eSDan Williams 	{ CXL_RAS_UC_CACHE_ADDR_PARITY, "Cache Address Parity Error" },	  \
364a20bc3eSDan Williams 	{ CXL_RAS_UC_CACHE_BE_PARITY, "Cache Byte Enable Parity Error" }, \
374a20bc3eSDan Williams 	{ CXL_RAS_UC_CACHE_DATA_ECC, "Cache Data ECC Error" },		  \
384a20bc3eSDan Williams 	{ CXL_RAS_UC_MEM_DATA_PARITY, "Memory Data Parity Error" },	  \
394a20bc3eSDan Williams 	{ CXL_RAS_UC_MEM_ADDR_PARITY, "Memory Address Parity Error" },	  \
404a20bc3eSDan Williams 	{ CXL_RAS_UC_MEM_BE_PARITY, "Memory Byte Enable Parity Error" },  \
414a20bc3eSDan Williams 	{ CXL_RAS_UC_MEM_DATA_ECC, "Memory Data ECC Error" },		  \
424a20bc3eSDan Williams 	{ CXL_RAS_UC_REINIT_THRESH, "REINIT Threshold Hit" },		  \
434a20bc3eSDan Williams 	{ CXL_RAS_UC_RSVD_ENCODE, "Received Unrecognized Encoding" },	  \
444a20bc3eSDan Williams 	{ CXL_RAS_UC_POISON, "Received Poison From Peer" },		  \
454a20bc3eSDan Williams 	{ CXL_RAS_UC_RECV_OVERFLOW, "Receiver Overflow" },		  \
464a20bc3eSDan Williams 	{ CXL_RAS_UC_INTERNAL_ERR, "Component Specific Error" },	  \
474a20bc3eSDan Williams 	{ CXL_RAS_UC_IDE_TX_ERR, "IDE Tx Error" },			  \
484a20bc3eSDan Williams 	{ CXL_RAS_UC_IDE_RX_ERR, "IDE Rx Error" }			  \
494a20bc3eSDan Williams )
504a20bc3eSDan Williams 
514a20bc3eSDan Williams TRACE_EVENT(cxl_aer_uncorrectable_error,
520c8393dcSIra Weiny 	TP_PROTO(const struct cxl_memdev *cxlmd, u32 status, u32 fe, u32 *hl),
530c8393dcSIra Weiny 	TP_ARGS(cxlmd, status, fe, hl),
544a20bc3eSDan Williams 	TP_STRUCT__entry(
550c8393dcSIra Weiny 		__string(memdev, dev_name(&cxlmd->dev))
56cd057017SIra Weiny 		__string(host, dev_name(cxlmd->dev.parent))
57279676c9SIra Weiny 		__field(u64, serial)
584a20bc3eSDan Williams 		__field(u32, status)
594a20bc3eSDan Williams 		__field(u32, first_error)
604a20bc3eSDan Williams 		__array(u32, header_log, CXL_HEADERLOG_SIZE_U32)
614a20bc3eSDan Williams 	),
624a20bc3eSDan Williams 	TP_fast_assign(
630c8393dcSIra Weiny 		__assign_str(memdev, dev_name(&cxlmd->dev));
64cd057017SIra Weiny 		__assign_str(host, dev_name(cxlmd->dev.parent));
65279676c9SIra Weiny 		__entry->serial = cxlmd->cxlds->serial;
664a20bc3eSDan Williams 		__entry->status = status;
674a20bc3eSDan Williams 		__entry->first_error = fe;
684a20bc3eSDan Williams 		/*
694a20bc3eSDan Williams 		 * Embed the 512B headerlog data for user app retrieval and
704a20bc3eSDan Williams 		 * parsing, but no need to print this in the trace buffer.
714a20bc3eSDan Williams 		 */
724a20bc3eSDan Williams 		memcpy(__entry->header_log, hl, CXL_HEADERLOG_SIZE);
734a20bc3eSDan Williams 	),
74279676c9SIra Weiny 	TP_printk("memdev=%s host=%s serial=%lld: status: '%s' first_error: '%s'",
75279676c9SIra Weiny 		  __get_str(memdev), __get_str(host), __entry->serial,
764a20bc3eSDan Williams 		  show_uc_errs(__entry->status),
774a20bc3eSDan Williams 		  show_uc_errs(__entry->first_error)
784a20bc3eSDan Williams 	)
794a20bc3eSDan Williams );
804a20bc3eSDan Williams 
814a20bc3eSDan Williams #define CXL_RAS_CE_CACHE_DATA_ECC	BIT(0)
824a20bc3eSDan Williams #define CXL_RAS_CE_MEM_DATA_ECC		BIT(1)
834a20bc3eSDan Williams #define CXL_RAS_CE_CRC_THRESH		BIT(2)
844a20bc3eSDan Williams #define CLX_RAS_CE_RETRY_THRESH		BIT(3)
854a20bc3eSDan Williams #define CXL_RAS_CE_CACHE_POISON		BIT(4)
864a20bc3eSDan Williams #define CXL_RAS_CE_MEM_POISON		BIT(5)
874a20bc3eSDan Williams #define CXL_RAS_CE_PHYS_LAYER_ERR	BIT(6)
884a20bc3eSDan Williams 
894a20bc3eSDan Williams #define show_ce_errs(status)	__print_flags(status, " | ",			\
904a20bc3eSDan Williams 	{ CXL_RAS_CE_CACHE_DATA_ECC, "Cache Data ECC Error" },			\
914a20bc3eSDan Williams 	{ CXL_RAS_CE_MEM_DATA_ECC, "Memory Data ECC Error" },			\
924a20bc3eSDan Williams 	{ CXL_RAS_CE_CRC_THRESH, "CRC Threshold Hit" },				\
934a20bc3eSDan Williams 	{ CLX_RAS_CE_RETRY_THRESH, "Retry Threshold" },				\
944a20bc3eSDan Williams 	{ CXL_RAS_CE_CACHE_POISON, "Received Cache Poison From Peer" },		\
954a20bc3eSDan Williams 	{ CXL_RAS_CE_MEM_POISON, "Received Memory Poison From Peer" },		\
964a20bc3eSDan Williams 	{ CXL_RAS_CE_PHYS_LAYER_ERR, "Received Error From Physical Layer" }	\
974a20bc3eSDan Williams )
984a20bc3eSDan Williams 
994a20bc3eSDan Williams TRACE_EVENT(cxl_aer_correctable_error,
1000c8393dcSIra Weiny 	TP_PROTO(const struct cxl_memdev *cxlmd, u32 status),
1010c8393dcSIra Weiny 	TP_ARGS(cxlmd, status),
1024a20bc3eSDan Williams 	TP_STRUCT__entry(
1030c8393dcSIra Weiny 		__string(memdev, dev_name(&cxlmd->dev))
104cd057017SIra Weiny 		__string(host, dev_name(cxlmd->dev.parent))
105279676c9SIra Weiny 		__field(u64, serial)
1064a20bc3eSDan Williams 		__field(u32, status)
1074a20bc3eSDan Williams 	),
1084a20bc3eSDan Williams 	TP_fast_assign(
1090c8393dcSIra Weiny 		__assign_str(memdev, dev_name(&cxlmd->dev));
110cd057017SIra Weiny 		__assign_str(host, dev_name(cxlmd->dev.parent));
111279676c9SIra Weiny 		__entry->serial = cxlmd->cxlds->serial;
1124a20bc3eSDan Williams 		__entry->status = status;
1134a20bc3eSDan Williams 	),
114279676c9SIra Weiny 	TP_printk("memdev=%s host=%s serial=%lld: status: '%s'",
115279676c9SIra Weiny 		  __get_str(memdev), __get_str(host), __entry->serial,
116cd057017SIra Weiny 		  show_ce_errs(__entry->status)
1174a20bc3eSDan Williams 	)
1184a20bc3eSDan Williams );
1194a20bc3eSDan Williams 
1206ebe28f9SIra Weiny #define cxl_event_log_type_str(type)				\
1216ebe28f9SIra Weiny 	__print_symbolic(type,					\
1226ebe28f9SIra Weiny 		{ CXL_EVENT_TYPE_INFO, "Informational" },	\
1236ebe28f9SIra Weiny 		{ CXL_EVENT_TYPE_WARN, "Warning" },		\
1246ebe28f9SIra Weiny 		{ CXL_EVENT_TYPE_FAIL, "Failure" },		\
1256ebe28f9SIra Weiny 		{ CXL_EVENT_TYPE_FATAL, "Fatal" })
1266ebe28f9SIra Weiny 
1276ebe28f9SIra Weiny TRACE_EVENT(cxl_overflow,
1286ebe28f9SIra Weiny 
1290c8393dcSIra Weiny 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
1306ebe28f9SIra Weiny 		 struct cxl_get_event_payload *payload),
1316ebe28f9SIra Weiny 
1320c8393dcSIra Weiny 	TP_ARGS(cxlmd, log, payload),
1336ebe28f9SIra Weiny 
1346ebe28f9SIra Weiny 	TP_STRUCT__entry(
1350c8393dcSIra Weiny 		__string(memdev, dev_name(&cxlmd->dev))
136cd057017SIra Weiny 		__string(host, dev_name(cxlmd->dev.parent))
1376ebe28f9SIra Weiny 		__field(int, log)
138279676c9SIra Weiny 		__field(u64, serial)
1396ebe28f9SIra Weiny 		__field(u64, first_ts)
1406ebe28f9SIra Weiny 		__field(u64, last_ts)
1416ebe28f9SIra Weiny 		__field(u16, count)
1426ebe28f9SIra Weiny 	),
1436ebe28f9SIra Weiny 
1446ebe28f9SIra Weiny 	TP_fast_assign(
1450c8393dcSIra Weiny 		__assign_str(memdev, dev_name(&cxlmd->dev));
146cd057017SIra Weiny 		__assign_str(host, dev_name(cxlmd->dev.parent));
147279676c9SIra Weiny 		__entry->serial = cxlmd->cxlds->serial;
1486ebe28f9SIra Weiny 		__entry->log = log;
1496ebe28f9SIra Weiny 		__entry->count = le16_to_cpu(payload->overflow_err_count);
1506ebe28f9SIra Weiny 		__entry->first_ts = le64_to_cpu(payload->first_overflow_timestamp);
1516ebe28f9SIra Weiny 		__entry->last_ts = le64_to_cpu(payload->last_overflow_timestamp);
1526ebe28f9SIra Weiny 	),
1536ebe28f9SIra Weiny 
154279676c9SIra Weiny 	TP_printk("memdev=%s host=%s serial=%lld: log=%s : %u records from %llu to %llu",
155279676c9SIra Weiny 		__get_str(memdev), __get_str(host), __entry->serial,
156cd057017SIra Weiny 		cxl_event_log_type_str(__entry->log), __entry->count,
157cd057017SIra Weiny 		__entry->first_ts, __entry->last_ts)
1586ebe28f9SIra Weiny 
1596ebe28f9SIra Weiny );
1606ebe28f9SIra Weiny 
1616ebe28f9SIra Weiny /*
1626ebe28f9SIra Weiny  * Common Event Record Format
1636ebe28f9SIra Weiny  * CXL 3.0 section 8.2.9.2.1; Table 8-42
1646ebe28f9SIra Weiny  */
1656ebe28f9SIra Weiny #define CXL_EVENT_RECORD_FLAG_PERMANENT		BIT(2)
1666ebe28f9SIra Weiny #define CXL_EVENT_RECORD_FLAG_MAINT_NEEDED	BIT(3)
1676ebe28f9SIra Weiny #define CXL_EVENT_RECORD_FLAG_PERF_DEGRADED	BIT(4)
1686ebe28f9SIra Weiny #define CXL_EVENT_RECORD_FLAG_HW_REPLACE	BIT(5)
1696ebe28f9SIra Weiny #define show_hdr_flags(flags)	__print_flags(flags, " | ",			   \
1706ebe28f9SIra Weiny 	{ CXL_EVENT_RECORD_FLAG_PERMANENT,	"PERMANENT_CONDITION"		}, \
1716ebe28f9SIra Weiny 	{ CXL_EVENT_RECORD_FLAG_MAINT_NEEDED,	"MAINTENANCE_NEEDED"		}, \
1726ebe28f9SIra Weiny 	{ CXL_EVENT_RECORD_FLAG_PERF_DEGRADED,	"PERFORMANCE_DEGRADED"		}, \
1736ebe28f9SIra Weiny 	{ CXL_EVENT_RECORD_FLAG_HW_REPLACE,	"HARDWARE_REPLACEMENT_NEEDED"	}  \
1746ebe28f9SIra Weiny )
1756ebe28f9SIra Weiny 
1766ebe28f9SIra Weiny /*
1776ebe28f9SIra Weiny  * Define macros for the common header of each CXL event.
1786ebe28f9SIra Weiny  *
1796ebe28f9SIra Weiny  * Tracepoints using these macros must do 3 things:
1806ebe28f9SIra Weiny  *
1816ebe28f9SIra Weiny  *	1) Add CXL_EVT_TP_entry to TP_STRUCT__entry
1826ebe28f9SIra Weiny  *	2) Use CXL_EVT_TP_fast_assign within TP_fast_assign;
1836ebe28f9SIra Weiny  *	   pass the dev, log, and CXL event header
184207a1f82SIra Weiny  *	   NOTE: The uuid must be assigned by the specific trace event
1856ebe28f9SIra Weiny  *	3) Use CXL_EVT_TP_printk() instead of TP_printk()
1866ebe28f9SIra Weiny  *
1876ebe28f9SIra Weiny  * See the generic_event tracepoint as an example.
1886ebe28f9SIra Weiny  */
1896ebe28f9SIra Weiny #define CXL_EVT_TP_entry					\
1900c8393dcSIra Weiny 	__string(memdev, dev_name(&cxlmd->dev))			\
191cd057017SIra Weiny 	__string(host, dev_name(cxlmd->dev.parent))		\
1926ebe28f9SIra Weiny 	__field(int, log)					\
1936ebe28f9SIra Weiny 	__field_struct(uuid_t, hdr_uuid)			\
194279676c9SIra Weiny 	__field(u64, serial)					\
1956ebe28f9SIra Weiny 	__field(u32, hdr_flags)					\
1966ebe28f9SIra Weiny 	__field(u16, hdr_handle)				\
1976ebe28f9SIra Weiny 	__field(u16, hdr_related_handle)			\
1986ebe28f9SIra Weiny 	__field(u64, hdr_timestamp)				\
1996ebe28f9SIra Weiny 	__field(u8, hdr_length)					\
2006ebe28f9SIra Weiny 	__field(u8, hdr_maint_op_class)
2016ebe28f9SIra Weiny 
202207a1f82SIra Weiny #define CXL_EVT_TP_fast_assign(cxlmd, l, hdr)					\
2030c8393dcSIra Weiny 	__assign_str(memdev, dev_name(&(cxlmd)->dev));				\
204cd057017SIra Weiny 	__assign_str(host, dev_name((cxlmd)->dev.parent));			\
2056ebe28f9SIra Weiny 	__entry->log = (l);							\
206279676c9SIra Weiny 	__entry->serial = (cxlmd)->cxlds->serial;				\
2076ebe28f9SIra Weiny 	__entry->hdr_length = (hdr).length;					\
2086ebe28f9SIra Weiny 	__entry->hdr_flags = get_unaligned_le24((hdr).flags);			\
2096ebe28f9SIra Weiny 	__entry->hdr_handle = le16_to_cpu((hdr).handle);			\
2106ebe28f9SIra Weiny 	__entry->hdr_related_handle = le16_to_cpu((hdr).related_handle);	\
2116ebe28f9SIra Weiny 	__entry->hdr_timestamp = le64_to_cpu((hdr).timestamp);			\
2126ebe28f9SIra Weiny 	__entry->hdr_maint_op_class = (hdr).maint_op_class
2136ebe28f9SIra Weiny 
2146ebe28f9SIra Weiny #define CXL_EVT_TP_printk(fmt, ...) \
215279676c9SIra Weiny 	TP_printk("memdev=%s host=%s serial=%lld log=%s : time=%llu uuid=%pUb "	\
216279676c9SIra Weiny 		"len=%d flags='%s' handle=%x related_handle=%x "		\
217279676c9SIra Weiny 		"maint_op_class=%u : " fmt,					\
218279676c9SIra Weiny 		__get_str(memdev), __get_str(host), __entry->serial,		\
219cd057017SIra Weiny 		cxl_event_log_type_str(__entry->log),				\
2206ebe28f9SIra Weiny 		__entry->hdr_timestamp, &__entry->hdr_uuid, __entry->hdr_length,\
2216ebe28f9SIra Weiny 		show_hdr_flags(__entry->hdr_flags), __entry->hdr_handle,	\
2226ebe28f9SIra Weiny 		__entry->hdr_related_handle, __entry->hdr_maint_op_class,	\
2236ebe28f9SIra Weiny 		##__VA_ARGS__)
2246ebe28f9SIra Weiny 
2256ebe28f9SIra Weiny TRACE_EVENT(cxl_generic_event,
2266ebe28f9SIra Weiny 
2270c8393dcSIra Weiny 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
228*f9c68338SIra Weiny 		 const uuid_t *uuid, struct cxl_event_generic *gen_rec),
2296ebe28f9SIra Weiny 
230*f9c68338SIra Weiny 	TP_ARGS(cxlmd, log, uuid, gen_rec),
2316ebe28f9SIra Weiny 
2326ebe28f9SIra Weiny 	TP_STRUCT__entry(
2336ebe28f9SIra Weiny 		CXL_EVT_TP_entry
2346ebe28f9SIra Weiny 		__array(u8, data, CXL_EVENT_RECORD_DATA_LENGTH)
2356ebe28f9SIra Weiny 	),
2366ebe28f9SIra Weiny 
2376ebe28f9SIra Weiny 	TP_fast_assign(
238*f9c68338SIra Weiny 		CXL_EVT_TP_fast_assign(cxlmd, log, gen_rec->hdr);
239207a1f82SIra Weiny 		memcpy(&__entry->hdr_uuid, uuid, sizeof(uuid_t));
240*f9c68338SIra Weiny 		memcpy(__entry->data, gen_rec->data, CXL_EVENT_RECORD_DATA_LENGTH);
2416ebe28f9SIra Weiny 	),
2426ebe28f9SIra Weiny 
2436ebe28f9SIra Weiny 	CXL_EVT_TP_printk("%s",
2446ebe28f9SIra Weiny 		__print_hex(__entry->data, CXL_EVENT_RECORD_DATA_LENGTH))
2456ebe28f9SIra Weiny );
2466ebe28f9SIra Weiny 
247d54a531aSIra Weiny /*
248d54a531aSIra Weiny  * Physical Address field masks
249d54a531aSIra Weiny  *
250d54a531aSIra Weiny  * General Media Event Record
251d54a531aSIra Weiny  * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
252d54a531aSIra Weiny  *
253d54a531aSIra Weiny  * DRAM Event Record
254d54a531aSIra Weiny  * CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
255d54a531aSIra Weiny  */
256d54a531aSIra Weiny #define CXL_DPA_FLAGS_MASK			0x3F
257d54a531aSIra Weiny #define CXL_DPA_MASK				(~CXL_DPA_FLAGS_MASK)
258d54a531aSIra Weiny 
259d54a531aSIra Weiny #define CXL_DPA_VOLATILE			BIT(0)
260d54a531aSIra Weiny #define CXL_DPA_NOT_REPAIRABLE			BIT(1)
261d54a531aSIra Weiny #define show_dpa_flags(flags)	__print_flags(flags, "|",		   \
262d54a531aSIra Weiny 	{ CXL_DPA_VOLATILE,			"VOLATILE"		}, \
263d54a531aSIra Weiny 	{ CXL_DPA_NOT_REPAIRABLE,		"NOT_REPAIRABLE"	}  \
264d54a531aSIra Weiny )
265d54a531aSIra Weiny 
266d54a531aSIra Weiny /*
267d54a531aSIra Weiny  * General Media Event Record - GMER
268d54a531aSIra Weiny  * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
269d54a531aSIra Weiny  */
270d54a531aSIra Weiny #define CXL_GMER_EVT_DESC_UNCORECTABLE_EVENT		BIT(0)
271d54a531aSIra Weiny #define CXL_GMER_EVT_DESC_THRESHOLD_EVENT		BIT(1)
272d54a531aSIra Weiny #define CXL_GMER_EVT_DESC_POISON_LIST_OVERFLOW		BIT(2)
273d54a531aSIra Weiny #define show_event_desc_flags(flags)	__print_flags(flags, "|",		   \
274d54a531aSIra Weiny 	{ CXL_GMER_EVT_DESC_UNCORECTABLE_EVENT,		"UNCORRECTABLE_EVENT"	}, \
275d54a531aSIra Weiny 	{ CXL_GMER_EVT_DESC_THRESHOLD_EVENT,		"THRESHOLD_EVENT"	}, \
276d54a531aSIra Weiny 	{ CXL_GMER_EVT_DESC_POISON_LIST_OVERFLOW,	"POISON_LIST_OVERFLOW"	}  \
277d54a531aSIra Weiny )
278d54a531aSIra Weiny 
279d54a531aSIra Weiny #define CXL_GMER_MEM_EVT_TYPE_ECC_ERROR			0x00
280d54a531aSIra Weiny #define CXL_GMER_MEM_EVT_TYPE_INV_ADDR			0x01
281d54a531aSIra Weiny #define CXL_GMER_MEM_EVT_TYPE_DATA_PATH_ERROR		0x02
282d54a531aSIra Weiny #define show_mem_event_type(type)	__print_symbolic(type,			\
283d54a531aSIra Weiny 	{ CXL_GMER_MEM_EVT_TYPE_ECC_ERROR,		"ECC Error" },		\
284d54a531aSIra Weiny 	{ CXL_GMER_MEM_EVT_TYPE_INV_ADDR,		"Invalid Address" },	\
285d54a531aSIra Weiny 	{ CXL_GMER_MEM_EVT_TYPE_DATA_PATH_ERROR,	"Data Path Error" }	\
286d54a531aSIra Weiny )
287d54a531aSIra Weiny 
288d54a531aSIra Weiny #define CXL_GMER_TRANS_UNKNOWN				0x00
289d54a531aSIra Weiny #define CXL_GMER_TRANS_HOST_READ			0x01
290d54a531aSIra Weiny #define CXL_GMER_TRANS_HOST_WRITE			0x02
291d54a531aSIra Weiny #define CXL_GMER_TRANS_HOST_SCAN_MEDIA			0x03
292d54a531aSIra Weiny #define CXL_GMER_TRANS_HOST_INJECT_POISON		0x04
293d54a531aSIra Weiny #define CXL_GMER_TRANS_INTERNAL_MEDIA_SCRUB		0x05
294d54a531aSIra Weiny #define CXL_GMER_TRANS_INTERNAL_MEDIA_MANAGEMENT	0x06
295d54a531aSIra Weiny #define show_trans_type(type)	__print_symbolic(type,					\
296d54a531aSIra Weiny 	{ CXL_GMER_TRANS_UNKNOWN,			"Unknown" },			\
297d54a531aSIra Weiny 	{ CXL_GMER_TRANS_HOST_READ,			"Host Read" },			\
298d54a531aSIra Weiny 	{ CXL_GMER_TRANS_HOST_WRITE,			"Host Write" },			\
299d54a531aSIra Weiny 	{ CXL_GMER_TRANS_HOST_SCAN_MEDIA,		"Host Scan Media" },		\
300d54a531aSIra Weiny 	{ CXL_GMER_TRANS_HOST_INJECT_POISON,		"Host Inject Poison" },		\
301d54a531aSIra Weiny 	{ CXL_GMER_TRANS_INTERNAL_MEDIA_SCRUB,		"Internal Media Scrub" },	\
302d54a531aSIra Weiny 	{ CXL_GMER_TRANS_INTERNAL_MEDIA_MANAGEMENT,	"Internal Media Management" }	\
303d54a531aSIra Weiny )
304d54a531aSIra Weiny 
305d54a531aSIra Weiny #define CXL_GMER_VALID_CHANNEL				BIT(0)
306d54a531aSIra Weiny #define CXL_GMER_VALID_RANK				BIT(1)
307d54a531aSIra Weiny #define CXL_GMER_VALID_DEVICE				BIT(2)
308d54a531aSIra Weiny #define CXL_GMER_VALID_COMPONENT			BIT(3)
309d54a531aSIra Weiny #define show_valid_flags(flags)	__print_flags(flags, "|",		   \
310d54a531aSIra Weiny 	{ CXL_GMER_VALID_CHANNEL,			"CHANNEL"	}, \
311d54a531aSIra Weiny 	{ CXL_GMER_VALID_RANK,				"RANK"		}, \
312d54a531aSIra Weiny 	{ CXL_GMER_VALID_DEVICE,			"DEVICE"	}, \
313d54a531aSIra Weiny 	{ CXL_GMER_VALID_COMPONENT,			"COMPONENT"	}  \
314d54a531aSIra Weiny )
315d54a531aSIra Weiny 
316d54a531aSIra Weiny TRACE_EVENT(cxl_general_media,
317d54a531aSIra Weiny 
3180c8393dcSIra Weiny 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
319207a1f82SIra Weiny 		 struct cxl_event_gen_media *rec),
320d54a531aSIra Weiny 
321207a1f82SIra Weiny 	TP_ARGS(cxlmd, log, rec),
322d54a531aSIra Weiny 
323d54a531aSIra Weiny 	TP_STRUCT__entry(
324d54a531aSIra Weiny 		CXL_EVT_TP_entry
325d54a531aSIra Weiny 		/* General Media */
326d54a531aSIra Weiny 		__field(u64, dpa)
327d54a531aSIra Weiny 		__field(u8, descriptor)
328d54a531aSIra Weiny 		__field(u8, type)
329d54a531aSIra Weiny 		__field(u8, transaction_type)
330d54a531aSIra Weiny 		__field(u8, channel)
331d54a531aSIra Weiny 		__field(u32, device)
332d54a531aSIra Weiny 		__array(u8, comp_id, CXL_EVENT_GEN_MED_COMP_ID_SIZE)
333d54a531aSIra Weiny 		__field(u16, validity_flags)
334d54a531aSIra Weiny 		/* Following are out of order to pack trace record */
335d54a531aSIra Weiny 		__field(u8, rank)
336d54a531aSIra Weiny 		__field(u8, dpa_flags)
337d54a531aSIra Weiny 	),
338d54a531aSIra Weiny 
339d54a531aSIra Weiny 	TP_fast_assign(
340207a1f82SIra Weiny 		CXL_EVT_TP_fast_assign(cxlmd, log, rec->hdr);
341207a1f82SIra Weiny 		memcpy(&__entry->hdr_uuid, &CXL_EVENT_GEN_MEDIA_UUID, sizeof(uuid_t));
342d54a531aSIra Weiny 
343d54a531aSIra Weiny 		/* General Media */
344d54a531aSIra Weiny 		__entry->dpa = le64_to_cpu(rec->phys_addr);
345d54a531aSIra Weiny 		__entry->dpa_flags = __entry->dpa & CXL_DPA_FLAGS_MASK;
346d54a531aSIra Weiny 		/* Mask after flags have been parsed */
347d54a531aSIra Weiny 		__entry->dpa &= CXL_DPA_MASK;
348d54a531aSIra Weiny 		__entry->descriptor = rec->descriptor;
349d54a531aSIra Weiny 		__entry->type = rec->type;
350d54a531aSIra Weiny 		__entry->transaction_type = rec->transaction_type;
351d54a531aSIra Weiny 		__entry->channel = rec->channel;
352d54a531aSIra Weiny 		__entry->rank = rec->rank;
353d54a531aSIra Weiny 		__entry->device = get_unaligned_le24(rec->device);
354d54a531aSIra Weiny 		memcpy(__entry->comp_id, &rec->component_id,
355d54a531aSIra Weiny 			CXL_EVENT_GEN_MED_COMP_ID_SIZE);
356d54a531aSIra Weiny 		__entry->validity_flags = get_unaligned_le16(&rec->validity_flags);
357d54a531aSIra Weiny 	),
358d54a531aSIra Weiny 
359d54a531aSIra Weiny 	CXL_EVT_TP_printk("dpa=%llx dpa_flags='%s' " \
360d54a531aSIra Weiny 		"descriptor='%s' type='%s' transaction_type='%s' channel=%u rank=%u " \
361d54a531aSIra Weiny 		"device=%x comp_id=%s validity_flags='%s'",
362d54a531aSIra Weiny 		__entry->dpa, show_dpa_flags(__entry->dpa_flags),
363d54a531aSIra Weiny 		show_event_desc_flags(__entry->descriptor),
364d54a531aSIra Weiny 		show_mem_event_type(__entry->type),
365d54a531aSIra Weiny 		show_trans_type(__entry->transaction_type),
366d54a531aSIra Weiny 		__entry->channel, __entry->rank, __entry->device,
367d54a531aSIra Weiny 		__print_hex(__entry->comp_id, CXL_EVENT_GEN_MED_COMP_ID_SIZE),
368d54a531aSIra Weiny 		show_valid_flags(__entry->validity_flags)
369d54a531aSIra Weiny 	)
370d54a531aSIra Weiny );
371d54a531aSIra Weiny 
3722d6c1e6dSIra Weiny /*
3732d6c1e6dSIra Weiny  * DRAM Event Record - DER
3742d6c1e6dSIra Weiny  *
3752d6c1e6dSIra Weiny  * CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
3762d6c1e6dSIra Weiny  */
3772d6c1e6dSIra Weiny /*
3782d6c1e6dSIra Weiny  * DRAM Event Record defines many fields the same as the General Media Event
3792d6c1e6dSIra Weiny  * Record.  Reuse those definitions as appropriate.
3802d6c1e6dSIra Weiny  */
3812d6c1e6dSIra Weiny #define CXL_DER_VALID_CHANNEL				BIT(0)
3822d6c1e6dSIra Weiny #define CXL_DER_VALID_RANK				BIT(1)
3832d6c1e6dSIra Weiny #define CXL_DER_VALID_NIBBLE				BIT(2)
3842d6c1e6dSIra Weiny #define CXL_DER_VALID_BANK_GROUP			BIT(3)
3852d6c1e6dSIra Weiny #define CXL_DER_VALID_BANK				BIT(4)
3862d6c1e6dSIra Weiny #define CXL_DER_VALID_ROW				BIT(5)
3872d6c1e6dSIra Weiny #define CXL_DER_VALID_COLUMN				BIT(6)
3882d6c1e6dSIra Weiny #define CXL_DER_VALID_CORRECTION_MASK			BIT(7)
3892d6c1e6dSIra Weiny #define show_dram_valid_flags(flags)	__print_flags(flags, "|",			   \
3902d6c1e6dSIra Weiny 	{ CXL_DER_VALID_CHANNEL,			"CHANNEL"		}, \
3912d6c1e6dSIra Weiny 	{ CXL_DER_VALID_RANK,				"RANK"			}, \
3922d6c1e6dSIra Weiny 	{ CXL_DER_VALID_NIBBLE,				"NIBBLE"		}, \
3932d6c1e6dSIra Weiny 	{ CXL_DER_VALID_BANK_GROUP,			"BANK GROUP"		}, \
3942d6c1e6dSIra Weiny 	{ CXL_DER_VALID_BANK,				"BANK"			}, \
3952d6c1e6dSIra Weiny 	{ CXL_DER_VALID_ROW,				"ROW"			}, \
3962d6c1e6dSIra Weiny 	{ CXL_DER_VALID_COLUMN,				"COLUMN"		}, \
3972d6c1e6dSIra Weiny 	{ CXL_DER_VALID_CORRECTION_MASK,		"CORRECTION MASK"	}  \
3982d6c1e6dSIra Weiny )
3992d6c1e6dSIra Weiny 
4002d6c1e6dSIra Weiny TRACE_EVENT(cxl_dram,
4012d6c1e6dSIra Weiny 
4020c8393dcSIra Weiny 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
403207a1f82SIra Weiny 		 struct cxl_event_dram *rec),
4042d6c1e6dSIra Weiny 
405207a1f82SIra Weiny 	TP_ARGS(cxlmd, log, rec),
4062d6c1e6dSIra Weiny 
4072d6c1e6dSIra Weiny 	TP_STRUCT__entry(
4082d6c1e6dSIra Weiny 		CXL_EVT_TP_entry
4092d6c1e6dSIra Weiny 		/* DRAM */
4102d6c1e6dSIra Weiny 		__field(u64, dpa)
4112d6c1e6dSIra Weiny 		__field(u8, descriptor)
4122d6c1e6dSIra Weiny 		__field(u8, type)
4132d6c1e6dSIra Weiny 		__field(u8, transaction_type)
4142d6c1e6dSIra Weiny 		__field(u8, channel)
4152d6c1e6dSIra Weiny 		__field(u16, validity_flags)
4162d6c1e6dSIra Weiny 		__field(u16, column)	/* Out of order to pack trace record */
4172d6c1e6dSIra Weiny 		__field(u32, nibble_mask)
4182d6c1e6dSIra Weiny 		__field(u32, row)
4192d6c1e6dSIra Weiny 		__array(u8, cor_mask, CXL_EVENT_DER_CORRECTION_MASK_SIZE)
4202d6c1e6dSIra Weiny 		__field(u8, rank)	/* Out of order to pack trace record */
4212d6c1e6dSIra Weiny 		__field(u8, bank_group)	/* Out of order to pack trace record */
4222d6c1e6dSIra Weiny 		__field(u8, bank)	/* Out of order to pack trace record */
4232d6c1e6dSIra Weiny 		__field(u8, dpa_flags)	/* Out of order to pack trace record */
4242d6c1e6dSIra Weiny 	),
4252d6c1e6dSIra Weiny 
4262d6c1e6dSIra Weiny 	TP_fast_assign(
427207a1f82SIra Weiny 		CXL_EVT_TP_fast_assign(cxlmd, log, rec->hdr);
428207a1f82SIra Weiny 		memcpy(&__entry->hdr_uuid, &CXL_EVENT_DRAM_UUID, sizeof(uuid_t));
4292d6c1e6dSIra Weiny 
4302d6c1e6dSIra Weiny 		/* DRAM */
4312d6c1e6dSIra Weiny 		__entry->dpa = le64_to_cpu(rec->phys_addr);
4322d6c1e6dSIra Weiny 		__entry->dpa_flags = __entry->dpa & CXL_DPA_FLAGS_MASK;
4332d6c1e6dSIra Weiny 		__entry->dpa &= CXL_DPA_MASK;
4342d6c1e6dSIra Weiny 		__entry->descriptor = rec->descriptor;
4352d6c1e6dSIra Weiny 		__entry->type = rec->type;
4362d6c1e6dSIra Weiny 		__entry->transaction_type = rec->transaction_type;
4372d6c1e6dSIra Weiny 		__entry->validity_flags = get_unaligned_le16(rec->validity_flags);
4382d6c1e6dSIra Weiny 		__entry->channel = rec->channel;
4392d6c1e6dSIra Weiny 		__entry->rank = rec->rank;
4402d6c1e6dSIra Weiny 		__entry->nibble_mask = get_unaligned_le24(rec->nibble_mask);
4412d6c1e6dSIra Weiny 		__entry->bank_group = rec->bank_group;
4422d6c1e6dSIra Weiny 		__entry->bank = rec->bank;
4432d6c1e6dSIra Weiny 		__entry->row = get_unaligned_le24(rec->row);
4442d6c1e6dSIra Weiny 		__entry->column = get_unaligned_le16(rec->column);
4452d6c1e6dSIra Weiny 		memcpy(__entry->cor_mask, &rec->correction_mask,
4462d6c1e6dSIra Weiny 			CXL_EVENT_DER_CORRECTION_MASK_SIZE);
4472d6c1e6dSIra Weiny 	),
4482d6c1e6dSIra Weiny 
4492d6c1e6dSIra Weiny 	CXL_EVT_TP_printk("dpa=%llx dpa_flags='%s' descriptor='%s' type='%s' " \
4502d6c1e6dSIra Weiny 		"transaction_type='%s' channel=%u rank=%u nibble_mask=%x " \
4512d6c1e6dSIra Weiny 		"bank_group=%u bank=%u row=%u column=%u cor_mask=%s " \
4522d6c1e6dSIra Weiny 		"validity_flags='%s'",
4532d6c1e6dSIra Weiny 		__entry->dpa, show_dpa_flags(__entry->dpa_flags),
4542d6c1e6dSIra Weiny 		show_event_desc_flags(__entry->descriptor),
4552d6c1e6dSIra Weiny 		show_mem_event_type(__entry->type),
4562d6c1e6dSIra Weiny 		show_trans_type(__entry->transaction_type),
4572d6c1e6dSIra Weiny 		__entry->channel, __entry->rank, __entry->nibble_mask,
4582d6c1e6dSIra Weiny 		__entry->bank_group, __entry->bank,
4592d6c1e6dSIra Weiny 		__entry->row, __entry->column,
4602d6c1e6dSIra Weiny 		__print_hex(__entry->cor_mask, CXL_EVENT_DER_CORRECTION_MASK_SIZE),
4612d6c1e6dSIra Weiny 		show_dram_valid_flags(__entry->validity_flags)
4622d6c1e6dSIra Weiny 	)
4632d6c1e6dSIra Weiny );
4642d6c1e6dSIra Weiny 
46595b49479SIra Weiny /*
46695b49479SIra Weiny  * Memory Module Event Record - MMER
46795b49479SIra Weiny  *
46895b49479SIra Weiny  * CXL res 3.0 section 8.2.9.2.1.3; Table 8-45
46995b49479SIra Weiny  */
47095b49479SIra Weiny #define CXL_MMER_HEALTH_STATUS_CHANGE		0x00
47195b49479SIra Weiny #define CXL_MMER_MEDIA_STATUS_CHANGE		0x01
47295b49479SIra Weiny #define CXL_MMER_LIFE_USED_CHANGE		0x02
47395b49479SIra Weiny #define CXL_MMER_TEMP_CHANGE			0x03
47495b49479SIra Weiny #define CXL_MMER_DATA_PATH_ERROR		0x04
47595b49479SIra Weiny #define CXL_MMER_LSA_ERROR			0x05
47695b49479SIra Weiny #define show_dev_evt_type(type)	__print_symbolic(type,			   \
47795b49479SIra Weiny 	{ CXL_MMER_HEALTH_STATUS_CHANGE,	"Health Status Change"	}, \
47895b49479SIra Weiny 	{ CXL_MMER_MEDIA_STATUS_CHANGE,		"Media Status Change"	}, \
47995b49479SIra Weiny 	{ CXL_MMER_LIFE_USED_CHANGE,		"Life Used Change"	}, \
48095b49479SIra Weiny 	{ CXL_MMER_TEMP_CHANGE,			"Temperature Change"	}, \
48195b49479SIra Weiny 	{ CXL_MMER_DATA_PATH_ERROR,		"Data Path Error"	}, \
48295b49479SIra Weiny 	{ CXL_MMER_LSA_ERROR,			"LSA Error"		}  \
48395b49479SIra Weiny )
48495b49479SIra Weiny 
48595b49479SIra Weiny /*
48695b49479SIra Weiny  * Device Health Information - DHI
48795b49479SIra Weiny  *
48895b49479SIra Weiny  * CXL res 3.0 section 8.2.9.8.3.1; Table 8-100
48995b49479SIra Weiny  */
49095b49479SIra Weiny #define CXL_DHI_HS_MAINTENANCE_NEEDED				BIT(0)
49195b49479SIra Weiny #define CXL_DHI_HS_PERFORMANCE_DEGRADED				BIT(1)
49295b49479SIra Weiny #define CXL_DHI_HS_HW_REPLACEMENT_NEEDED			BIT(2)
49395b49479SIra Weiny #define show_health_status_flags(flags)	__print_flags(flags, "|",	   \
49495b49479SIra Weiny 	{ CXL_DHI_HS_MAINTENANCE_NEEDED,	"MAINTENANCE_NEEDED"	}, \
49595b49479SIra Weiny 	{ CXL_DHI_HS_PERFORMANCE_DEGRADED,	"PERFORMANCE_DEGRADED"	}, \
49695b49479SIra Weiny 	{ CXL_DHI_HS_HW_REPLACEMENT_NEEDED,	"REPLACEMENT_NEEDED"	}  \
49795b49479SIra Weiny )
49895b49479SIra Weiny 
49995b49479SIra Weiny #define CXL_DHI_MS_NORMAL							0x00
50095b49479SIra Weiny #define CXL_DHI_MS_NOT_READY							0x01
50195b49479SIra Weiny #define CXL_DHI_MS_WRITE_PERSISTENCY_LOST					0x02
50295b49479SIra Weiny #define CXL_DHI_MS_ALL_DATA_LOST						0x03
50395b49479SIra Weiny #define CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_EVENT_POWER_LOSS			0x04
50495b49479SIra Weiny #define CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_EVENT_SHUTDOWN			0x05
50595b49479SIra Weiny #define CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_IMMINENT				0x06
50695b49479SIra Weiny #define CXL_DHI_MS_WRITE_ALL_DATA_LOSS_EVENT_POWER_LOSS				0x07
50795b49479SIra Weiny #define CXL_DHI_MS_WRITE_ALL_DATA_LOSS_EVENT_SHUTDOWN				0x08
50895b49479SIra Weiny #define CXL_DHI_MS_WRITE_ALL_DATA_LOSS_IMMINENT					0x09
50995b49479SIra Weiny #define show_media_status(ms)	__print_symbolic(ms,			   \
51095b49479SIra Weiny 	{ CXL_DHI_MS_NORMAL,						   \
51195b49479SIra Weiny 		"Normal"						}, \
51295b49479SIra Weiny 	{ CXL_DHI_MS_NOT_READY,						   \
51395b49479SIra Weiny 		"Not Ready"						}, \
51495b49479SIra Weiny 	{ CXL_DHI_MS_WRITE_PERSISTENCY_LOST,				   \
51595b49479SIra Weiny 		"Write Persistency Lost"				}, \
51695b49479SIra Weiny 	{ CXL_DHI_MS_ALL_DATA_LOST,					   \
51795b49479SIra Weiny 		"All Data Lost"						}, \
51895b49479SIra Weiny 	{ CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_EVENT_POWER_LOSS,		   \
51995b49479SIra Weiny 		"Write Persistency Loss in the Event of Power Loss"	}, \
52095b49479SIra Weiny 	{ CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_EVENT_SHUTDOWN,		   \
52195b49479SIra Weiny 		"Write Persistency Loss in Event of Shutdown"		}, \
52295b49479SIra Weiny 	{ CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_IMMINENT,			   \
52395b49479SIra Weiny 		"Write Persistency Loss Imminent"			}, \
52495b49479SIra Weiny 	{ CXL_DHI_MS_WRITE_ALL_DATA_LOSS_EVENT_POWER_LOSS,		   \
52595b49479SIra Weiny 		"All Data Loss in Event of Power Loss"			}, \
52695b49479SIra Weiny 	{ CXL_DHI_MS_WRITE_ALL_DATA_LOSS_EVENT_SHUTDOWN,		   \
52795b49479SIra Weiny 		"All Data loss in the Event of Shutdown"		}, \
52895b49479SIra Weiny 	{ CXL_DHI_MS_WRITE_ALL_DATA_LOSS_IMMINENT,			   \
52995b49479SIra Weiny 		"All Data Loss Imminent"				}  \
53095b49479SIra Weiny )
53195b49479SIra Weiny 
53295b49479SIra Weiny #define CXL_DHI_AS_NORMAL		0x0
53395b49479SIra Weiny #define CXL_DHI_AS_WARNING		0x1
53495b49479SIra Weiny #define CXL_DHI_AS_CRITICAL		0x2
53595b49479SIra Weiny #define show_two_bit_status(as) __print_symbolic(as,	   \
53695b49479SIra Weiny 	{ CXL_DHI_AS_NORMAL,		"Normal"	}, \
53795b49479SIra Weiny 	{ CXL_DHI_AS_WARNING,		"Warning"	}, \
53895b49479SIra Weiny 	{ CXL_DHI_AS_CRITICAL,		"Critical"	}  \
53995b49479SIra Weiny )
54095b49479SIra Weiny #define show_one_bit_status(as) __print_symbolic(as,	   \
54195b49479SIra Weiny 	{ CXL_DHI_AS_NORMAL,		"Normal"	}, \
54295b49479SIra Weiny 	{ CXL_DHI_AS_WARNING,		"Warning"	}  \
54395b49479SIra Weiny )
54495b49479SIra Weiny 
54595b49479SIra Weiny #define CXL_DHI_AS_LIFE_USED(as)			(as & 0x3)
54695b49479SIra Weiny #define CXL_DHI_AS_DEV_TEMP(as)				((as & 0xC) >> 2)
54795b49479SIra Weiny #define CXL_DHI_AS_COR_VOL_ERR_CNT(as)			((as & 0x10) >> 4)
54895b49479SIra Weiny #define CXL_DHI_AS_COR_PER_ERR_CNT(as)			((as & 0x20) >> 5)
54995b49479SIra Weiny 
55095b49479SIra Weiny TRACE_EVENT(cxl_memory_module,
55195b49479SIra Weiny 
5520c8393dcSIra Weiny 	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
553207a1f82SIra Weiny 		 struct cxl_event_mem_module *rec),
55495b49479SIra Weiny 
555207a1f82SIra Weiny 	TP_ARGS(cxlmd, log, rec),
55695b49479SIra Weiny 
55795b49479SIra Weiny 	TP_STRUCT__entry(
55895b49479SIra Weiny 		CXL_EVT_TP_entry
55995b49479SIra Weiny 
56095b49479SIra Weiny 		/* Memory Module Event */
56195b49479SIra Weiny 		__field(u8, event_type)
56295b49479SIra Weiny 
56395b49479SIra Weiny 		/* Device Health Info */
56495b49479SIra Weiny 		__field(u8, health_status)
56595b49479SIra Weiny 		__field(u8, media_status)
56695b49479SIra Weiny 		__field(u8, life_used)
56795b49479SIra Weiny 		__field(u32, dirty_shutdown_cnt)
56895b49479SIra Weiny 		__field(u32, cor_vol_err_cnt)
56995b49479SIra Weiny 		__field(u32, cor_per_err_cnt)
57095b49479SIra Weiny 		__field(s16, device_temp)
57195b49479SIra Weiny 		__field(u8, add_status)
57295b49479SIra Weiny 	),
57395b49479SIra Weiny 
57495b49479SIra Weiny 	TP_fast_assign(
575207a1f82SIra Weiny 		CXL_EVT_TP_fast_assign(cxlmd, log, rec->hdr);
576207a1f82SIra Weiny 		memcpy(&__entry->hdr_uuid, &CXL_EVENT_MEM_MODULE_UUID, sizeof(uuid_t));
57795b49479SIra Weiny 
57895b49479SIra Weiny 		/* Memory Module Event */
57995b49479SIra Weiny 		__entry->event_type = rec->event_type;
58095b49479SIra Weiny 
58195b49479SIra Weiny 		/* Device Health Info */
58295b49479SIra Weiny 		__entry->health_status = rec->info.health_status;
58395b49479SIra Weiny 		__entry->media_status = rec->info.media_status;
58495b49479SIra Weiny 		__entry->life_used = rec->info.life_used;
58595b49479SIra Weiny 		__entry->dirty_shutdown_cnt = get_unaligned_le32(rec->info.dirty_shutdown_cnt);
58695b49479SIra Weiny 		__entry->cor_vol_err_cnt = get_unaligned_le32(rec->info.cor_vol_err_cnt);
58795b49479SIra Weiny 		__entry->cor_per_err_cnt = get_unaligned_le32(rec->info.cor_per_err_cnt);
58895b49479SIra Weiny 		__entry->device_temp = get_unaligned_le16(rec->info.device_temp);
58995b49479SIra Weiny 		__entry->add_status = rec->info.add_status;
59095b49479SIra Weiny 	),
59195b49479SIra Weiny 
59295b49479SIra Weiny 	CXL_EVT_TP_printk("event_type='%s' health_status='%s' media_status='%s' " \
59395b49479SIra Weiny 		"as_life_used=%s as_dev_temp=%s as_cor_vol_err_cnt=%s " \
59495b49479SIra Weiny 		"as_cor_per_err_cnt=%s life_used=%u device_temp=%d " \
59595b49479SIra Weiny 		"dirty_shutdown_cnt=%u cor_vol_err_cnt=%u cor_per_err_cnt=%u",
59695b49479SIra Weiny 		show_dev_evt_type(__entry->event_type),
59795b49479SIra Weiny 		show_health_status_flags(__entry->health_status),
59895b49479SIra Weiny 		show_media_status(__entry->media_status),
59995b49479SIra Weiny 		show_two_bit_status(CXL_DHI_AS_LIFE_USED(__entry->add_status)),
60095b49479SIra Weiny 		show_two_bit_status(CXL_DHI_AS_DEV_TEMP(__entry->add_status)),
60195b49479SIra Weiny 		show_one_bit_status(CXL_DHI_AS_COR_VOL_ERR_CNT(__entry->add_status)),
60295b49479SIra Weiny 		show_one_bit_status(CXL_DHI_AS_COR_PER_ERR_CNT(__entry->add_status)),
60395b49479SIra Weiny 		__entry->life_used, __entry->device_temp,
60495b49479SIra Weiny 		__entry->dirty_shutdown_cnt, __entry->cor_vol_err_cnt,
60595b49479SIra Weiny 		__entry->cor_per_err_cnt
60695b49479SIra Weiny 	)
60795b49479SIra Weiny );
60895b49479SIra Weiny 
609ddf49d57SAlison Schofield #define show_poison_trace_type(type)			\
610ddf49d57SAlison Schofield 	__print_symbolic(type,				\
61198b69265SAlison Schofield 	{ CXL_POISON_TRACE_LIST,	"List"   },	\
61298b69265SAlison Schofield 	{ CXL_POISON_TRACE_INJECT,	"Inject" },	\
61398b69265SAlison Schofield 	{ CXL_POISON_TRACE_CLEAR,	"Clear"  })
614ddf49d57SAlison Schofield 
615ddf49d57SAlison Schofield #define __show_poison_source(source)                          \
616ddf49d57SAlison Schofield 	__print_symbolic(source,                              \
617ddf49d57SAlison Schofield 		{ CXL_POISON_SOURCE_UNKNOWN,   "Unknown"  },  \
618ddf49d57SAlison Schofield 		{ CXL_POISON_SOURCE_EXTERNAL,  "External" },  \
619ddf49d57SAlison Schofield 		{ CXL_POISON_SOURCE_INTERNAL,  "Internal" },  \
620ddf49d57SAlison Schofield 		{ CXL_POISON_SOURCE_INJECTED,  "Injected" },  \
621ddf49d57SAlison Schofield 		{ CXL_POISON_SOURCE_VENDOR,    "Vendor"   })
622ddf49d57SAlison Schofield 
623ddf49d57SAlison Schofield #define show_poison_source(source)			     \
624ddf49d57SAlison Schofield 	(((source > CXL_POISON_SOURCE_INJECTED) &&	     \
625ddf49d57SAlison Schofield 	 (source != CXL_POISON_SOURCE_VENDOR)) ? "Reserved"  \
626ddf49d57SAlison Schofield 	 : __show_poison_source(source))
627ddf49d57SAlison Schofield 
628ddf49d57SAlison Schofield #define show_poison_flags(flags)                             \
629ddf49d57SAlison Schofield 	__print_flags(flags, "|",                            \
630ddf49d57SAlison Schofield 		{ CXL_POISON_FLAG_MORE,      "More"     },   \
631ddf49d57SAlison Schofield 		{ CXL_POISON_FLAG_OVERFLOW,  "Overflow"  },  \
632ddf49d57SAlison Schofield 		{ CXL_POISON_FLAG_SCANNING,  "Scanning"  })
633ddf49d57SAlison Schofield 
634ddf49d57SAlison Schofield #define __cxl_poison_addr(record)					\
635ddf49d57SAlison Schofield 	(le64_to_cpu(record->address))
636ddf49d57SAlison Schofield #define cxl_poison_record_dpa(record)					\
637ddf49d57SAlison Schofield 	(__cxl_poison_addr(record) & CXL_POISON_START_MASK)
638ddf49d57SAlison Schofield #define cxl_poison_record_source(record)				\
639ddf49d57SAlison Schofield 	(__cxl_poison_addr(record)  & CXL_POISON_SOURCE_MASK)
640ddf49d57SAlison Schofield #define cxl_poison_record_dpa_length(record)				\
641ddf49d57SAlison Schofield 	(le32_to_cpu(record->length) * CXL_POISON_LEN_MULT)
642ddf49d57SAlison Schofield #define cxl_poison_overflow(flags, time)				\
643ddf49d57SAlison Schofield 	(flags & CXL_POISON_FLAG_OVERFLOW ? le64_to_cpu(time) : 0)
644ddf49d57SAlison Schofield 
64528a3ae4fSAlison Schofield u64 cxl_trace_hpa(struct cxl_region *cxlr, struct cxl_memdev *memdev, u64 dpa);
64628a3ae4fSAlison Schofield 
647ddf49d57SAlison Schofield TRACE_EVENT(cxl_poison,
648ddf49d57SAlison Schofield 
649ddf49d57SAlison Schofield 	TP_PROTO(struct cxl_memdev *cxlmd, struct cxl_region *region,
650ddf49d57SAlison Schofield 		 const struct cxl_poison_record *record, u8 flags,
651ddf49d57SAlison Schofield 		 __le64 overflow_ts, enum cxl_poison_trace_type trace_type),
652ddf49d57SAlison Schofield 
653ddf49d57SAlison Schofield 	TP_ARGS(cxlmd, region, record, flags, overflow_ts, trace_type),
654ddf49d57SAlison Schofield 
655ddf49d57SAlison Schofield 	TP_STRUCT__entry(
656ddf49d57SAlison Schofield 		__string(memdev, dev_name(&cxlmd->dev))
657ddf49d57SAlison Schofield 		__string(host, dev_name(cxlmd->dev.parent))
658ddf49d57SAlison Schofield 		__field(u64, serial)
659ddf49d57SAlison Schofield 		__field(u8, trace_type)
660ddf49d57SAlison Schofield 		__string(region, region)
661ddf49d57SAlison Schofield 		__field(u64, overflow_ts)
66228a3ae4fSAlison Schofield 		__field(u64, hpa)
663ddf49d57SAlison Schofield 		__field(u64, dpa)
664ddf49d57SAlison Schofield 		__field(u32, dpa_length)
665ddf49d57SAlison Schofield 		__array(char, uuid, 16)
666ddf49d57SAlison Schofield 		__field(u8, source)
667ddf49d57SAlison Schofield 		__field(u8, flags)
668ddf49d57SAlison Schofield 	    ),
669ddf49d57SAlison Schofield 
670ddf49d57SAlison Schofield 	TP_fast_assign(
671ddf49d57SAlison Schofield 		__assign_str(memdev, dev_name(&cxlmd->dev));
672ddf49d57SAlison Schofield 		__assign_str(host, dev_name(cxlmd->dev.parent));
673ddf49d57SAlison Schofield 		__entry->serial = cxlmd->cxlds->serial;
674ddf49d57SAlison Schofield 		__entry->overflow_ts = cxl_poison_overflow(flags, overflow_ts);
675ddf49d57SAlison Schofield 		__entry->dpa = cxl_poison_record_dpa(record);
676ddf49d57SAlison Schofield 		__entry->dpa_length = cxl_poison_record_dpa_length(record);
677ddf49d57SAlison Schofield 		__entry->source = cxl_poison_record_source(record);
678ddf49d57SAlison Schofield 		__entry->trace_type = trace_type;
679ddf49d57SAlison Schofield 		__entry->flags = flags;
680ddf49d57SAlison Schofield 		if (region) {
681ddf49d57SAlison Schofield 			__assign_str(region, dev_name(&region->dev));
682ddf49d57SAlison Schofield 			memcpy(__entry->uuid, &region->params.uuid, 16);
68328a3ae4fSAlison Schofield 			__entry->hpa = cxl_trace_hpa(region, cxlmd,
68428a3ae4fSAlison Schofield 						     __entry->dpa);
685ddf49d57SAlison Schofield 		} else {
686ddf49d57SAlison Schofield 			__assign_str(region, "");
687ddf49d57SAlison Schofield 			memset(__entry->uuid, 0, 16);
68828a3ae4fSAlison Schofield 			__entry->hpa = ULLONG_MAX;
689ddf49d57SAlison Schofield 		}
690ddf49d57SAlison Schofield 	    ),
691ddf49d57SAlison Schofield 
692ddf49d57SAlison Schofield 	TP_printk("memdev=%s host=%s serial=%lld trace_type=%s region=%s "  \
69328a3ae4fSAlison Schofield 		"region_uuid=%pU hpa=0x%llx dpa=0x%llx dpa_length=0x%x "    \
69428a3ae4fSAlison Schofield 		"source=%s flags=%s overflow_time=%llu",
695ddf49d57SAlison Schofield 		__get_str(memdev),
696ddf49d57SAlison Schofield 		__get_str(host),
697ddf49d57SAlison Schofield 		__entry->serial,
698ddf49d57SAlison Schofield 		show_poison_trace_type(__entry->trace_type),
699ddf49d57SAlison Schofield 		__get_str(region),
700ddf49d57SAlison Schofield 		__entry->uuid,
70128a3ae4fSAlison Schofield 		__entry->hpa,
702ddf49d57SAlison Schofield 		__entry->dpa,
703ddf49d57SAlison Schofield 		__entry->dpa_length,
704ddf49d57SAlison Schofield 		show_poison_source(__entry->source),
705ddf49d57SAlison Schofield 		show_poison_flags(__entry->flags),
706ddf49d57SAlison Schofield 		__entry->overflow_ts
707ddf49d57SAlison Schofield 	)
708ddf49d57SAlison Schofield );
709ddf49d57SAlison Schofield 
7104a20bc3eSDan Williams #endif /* _CXL_EVENTS_H */
7114a20bc3eSDan Williams 
7124a20bc3eSDan Williams #define TRACE_INCLUDE_FILE trace
7134a20bc3eSDan Williams #include <trace/define_trace.h>
714