162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/* Copyright(c) 2022 Intel Corporation. All rights reserved. */
362306a36Sopenharmony_ci#undef TRACE_SYSTEM
462306a36Sopenharmony_ci#define TRACE_SYSTEM cxl
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#if !defined(_CXL_EVENTS_H) || defined(TRACE_HEADER_MULTI_READ)
762306a36Sopenharmony_ci#define _CXL_EVENTS_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/tracepoint.h>
1062306a36Sopenharmony_ci#include <linux/pci.h>
1162306a36Sopenharmony_ci#include <asm-generic/unaligned.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <cxl.h>
1462306a36Sopenharmony_ci#include <cxlmem.h>
1562306a36Sopenharmony_ci#include "core.h"
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#define CXL_RAS_UC_CACHE_DATA_PARITY	BIT(0)
1862306a36Sopenharmony_ci#define CXL_RAS_UC_CACHE_ADDR_PARITY	BIT(1)
1962306a36Sopenharmony_ci#define CXL_RAS_UC_CACHE_BE_PARITY	BIT(2)
2062306a36Sopenharmony_ci#define CXL_RAS_UC_CACHE_DATA_ECC	BIT(3)
2162306a36Sopenharmony_ci#define CXL_RAS_UC_MEM_DATA_PARITY	BIT(4)
2262306a36Sopenharmony_ci#define CXL_RAS_UC_MEM_ADDR_PARITY	BIT(5)
2362306a36Sopenharmony_ci#define CXL_RAS_UC_MEM_BE_PARITY	BIT(6)
2462306a36Sopenharmony_ci#define CXL_RAS_UC_MEM_DATA_ECC		BIT(7)
2562306a36Sopenharmony_ci#define CXL_RAS_UC_REINIT_THRESH	BIT(8)
2662306a36Sopenharmony_ci#define CXL_RAS_UC_RSVD_ENCODE		BIT(9)
2762306a36Sopenharmony_ci#define CXL_RAS_UC_POISON		BIT(10)
2862306a36Sopenharmony_ci#define CXL_RAS_UC_RECV_OVERFLOW	BIT(11)
2962306a36Sopenharmony_ci#define CXL_RAS_UC_INTERNAL_ERR		BIT(14)
3062306a36Sopenharmony_ci#define CXL_RAS_UC_IDE_TX_ERR		BIT(15)
3162306a36Sopenharmony_ci#define CXL_RAS_UC_IDE_RX_ERR		BIT(16)
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define show_uc_errs(status)	__print_flags(status, " | ",		  \
3462306a36Sopenharmony_ci	{ CXL_RAS_UC_CACHE_DATA_PARITY, "Cache Data Parity Error" },	  \
3562306a36Sopenharmony_ci	{ CXL_RAS_UC_CACHE_ADDR_PARITY, "Cache Address Parity Error" },	  \
3662306a36Sopenharmony_ci	{ CXL_RAS_UC_CACHE_BE_PARITY, "Cache Byte Enable Parity Error" }, \
3762306a36Sopenharmony_ci	{ CXL_RAS_UC_CACHE_DATA_ECC, "Cache Data ECC Error" },		  \
3862306a36Sopenharmony_ci	{ CXL_RAS_UC_MEM_DATA_PARITY, "Memory Data Parity Error" },	  \
3962306a36Sopenharmony_ci	{ CXL_RAS_UC_MEM_ADDR_PARITY, "Memory Address Parity Error" },	  \
4062306a36Sopenharmony_ci	{ CXL_RAS_UC_MEM_BE_PARITY, "Memory Byte Enable Parity Error" },  \
4162306a36Sopenharmony_ci	{ CXL_RAS_UC_MEM_DATA_ECC, "Memory Data ECC Error" },		  \
4262306a36Sopenharmony_ci	{ CXL_RAS_UC_REINIT_THRESH, "REINIT Threshold Hit" },		  \
4362306a36Sopenharmony_ci	{ CXL_RAS_UC_RSVD_ENCODE, "Received Unrecognized Encoding" },	  \
4462306a36Sopenharmony_ci	{ CXL_RAS_UC_POISON, "Received Poison From Peer" },		  \
4562306a36Sopenharmony_ci	{ CXL_RAS_UC_RECV_OVERFLOW, "Receiver Overflow" },		  \
4662306a36Sopenharmony_ci	{ CXL_RAS_UC_INTERNAL_ERR, "Component Specific Error" },	  \
4762306a36Sopenharmony_ci	{ CXL_RAS_UC_IDE_TX_ERR, "IDE Tx Error" },			  \
4862306a36Sopenharmony_ci	{ CXL_RAS_UC_IDE_RX_ERR, "IDE Rx Error" }			  \
4962306a36Sopenharmony_ci)
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciTRACE_EVENT(cxl_aer_uncorrectable_error,
5262306a36Sopenharmony_ci	TP_PROTO(const struct cxl_memdev *cxlmd, u32 status, u32 fe, u32 *hl),
5362306a36Sopenharmony_ci	TP_ARGS(cxlmd, status, fe, hl),
5462306a36Sopenharmony_ci	TP_STRUCT__entry(
5562306a36Sopenharmony_ci		__string(memdev, dev_name(&cxlmd->dev))
5662306a36Sopenharmony_ci		__string(host, dev_name(cxlmd->dev.parent))
5762306a36Sopenharmony_ci		__field(u64, serial)
5862306a36Sopenharmony_ci		__field(u32, status)
5962306a36Sopenharmony_ci		__field(u32, first_error)
6062306a36Sopenharmony_ci		__array(u32, header_log, CXL_HEADERLOG_SIZE_U32)
6162306a36Sopenharmony_ci	),
6262306a36Sopenharmony_ci	TP_fast_assign(
6362306a36Sopenharmony_ci		__assign_str(memdev, dev_name(&cxlmd->dev));
6462306a36Sopenharmony_ci		__assign_str(host, dev_name(cxlmd->dev.parent));
6562306a36Sopenharmony_ci		__entry->serial = cxlmd->cxlds->serial;
6662306a36Sopenharmony_ci		__entry->status = status;
6762306a36Sopenharmony_ci		__entry->first_error = fe;
6862306a36Sopenharmony_ci		/*
6962306a36Sopenharmony_ci		 * Embed the 512B headerlog data for user app retrieval and
7062306a36Sopenharmony_ci		 * parsing, but no need to print this in the trace buffer.
7162306a36Sopenharmony_ci		 */
7262306a36Sopenharmony_ci		memcpy(__entry->header_log, hl, CXL_HEADERLOG_SIZE);
7362306a36Sopenharmony_ci	),
7462306a36Sopenharmony_ci	TP_printk("memdev=%s host=%s serial=%lld: status: '%s' first_error: '%s'",
7562306a36Sopenharmony_ci		  __get_str(memdev), __get_str(host), __entry->serial,
7662306a36Sopenharmony_ci		  show_uc_errs(__entry->status),
7762306a36Sopenharmony_ci		  show_uc_errs(__entry->first_error)
7862306a36Sopenharmony_ci	)
7962306a36Sopenharmony_ci);
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define CXL_RAS_CE_CACHE_DATA_ECC	BIT(0)
8262306a36Sopenharmony_ci#define CXL_RAS_CE_MEM_DATA_ECC		BIT(1)
8362306a36Sopenharmony_ci#define CXL_RAS_CE_CRC_THRESH		BIT(2)
8462306a36Sopenharmony_ci#define CLX_RAS_CE_RETRY_THRESH		BIT(3)
8562306a36Sopenharmony_ci#define CXL_RAS_CE_CACHE_POISON		BIT(4)
8662306a36Sopenharmony_ci#define CXL_RAS_CE_MEM_POISON		BIT(5)
8762306a36Sopenharmony_ci#define CXL_RAS_CE_PHYS_LAYER_ERR	BIT(6)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define show_ce_errs(status)	__print_flags(status, " | ",			\
9062306a36Sopenharmony_ci	{ CXL_RAS_CE_CACHE_DATA_ECC, "Cache Data ECC Error" },			\
9162306a36Sopenharmony_ci	{ CXL_RAS_CE_MEM_DATA_ECC, "Memory Data ECC Error" },			\
9262306a36Sopenharmony_ci	{ CXL_RAS_CE_CRC_THRESH, "CRC Threshold Hit" },				\
9362306a36Sopenharmony_ci	{ CLX_RAS_CE_RETRY_THRESH, "Retry Threshold" },				\
9462306a36Sopenharmony_ci	{ CXL_RAS_CE_CACHE_POISON, "Received Cache Poison From Peer" },		\
9562306a36Sopenharmony_ci	{ CXL_RAS_CE_MEM_POISON, "Received Memory Poison From Peer" },		\
9662306a36Sopenharmony_ci	{ CXL_RAS_CE_PHYS_LAYER_ERR, "Received Error From Physical Layer" }	\
9762306a36Sopenharmony_ci)
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ciTRACE_EVENT(cxl_aer_correctable_error,
10062306a36Sopenharmony_ci	TP_PROTO(const struct cxl_memdev *cxlmd, u32 status),
10162306a36Sopenharmony_ci	TP_ARGS(cxlmd, status),
10262306a36Sopenharmony_ci	TP_STRUCT__entry(
10362306a36Sopenharmony_ci		__string(memdev, dev_name(&cxlmd->dev))
10462306a36Sopenharmony_ci		__string(host, dev_name(cxlmd->dev.parent))
10562306a36Sopenharmony_ci		__field(u64, serial)
10662306a36Sopenharmony_ci		__field(u32, status)
10762306a36Sopenharmony_ci	),
10862306a36Sopenharmony_ci	TP_fast_assign(
10962306a36Sopenharmony_ci		__assign_str(memdev, dev_name(&cxlmd->dev));
11062306a36Sopenharmony_ci		__assign_str(host, dev_name(cxlmd->dev.parent));
11162306a36Sopenharmony_ci		__entry->serial = cxlmd->cxlds->serial;
11262306a36Sopenharmony_ci		__entry->status = status;
11362306a36Sopenharmony_ci	),
11462306a36Sopenharmony_ci	TP_printk("memdev=%s host=%s serial=%lld: status: '%s'",
11562306a36Sopenharmony_ci		  __get_str(memdev), __get_str(host), __entry->serial,
11662306a36Sopenharmony_ci		  show_ce_errs(__entry->status)
11762306a36Sopenharmony_ci	)
11862306a36Sopenharmony_ci);
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define cxl_event_log_type_str(type)				\
12162306a36Sopenharmony_ci	__print_symbolic(type,					\
12262306a36Sopenharmony_ci		{ CXL_EVENT_TYPE_INFO, "Informational" },	\
12362306a36Sopenharmony_ci		{ CXL_EVENT_TYPE_WARN, "Warning" },		\
12462306a36Sopenharmony_ci		{ CXL_EVENT_TYPE_FAIL, "Failure" },		\
12562306a36Sopenharmony_ci		{ CXL_EVENT_TYPE_FATAL, "Fatal" })
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ciTRACE_EVENT(cxl_overflow,
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
13062306a36Sopenharmony_ci		 struct cxl_get_event_payload *payload),
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci	TP_ARGS(cxlmd, log, payload),
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci	TP_STRUCT__entry(
13562306a36Sopenharmony_ci		__string(memdev, dev_name(&cxlmd->dev))
13662306a36Sopenharmony_ci		__string(host, dev_name(cxlmd->dev.parent))
13762306a36Sopenharmony_ci		__field(int, log)
13862306a36Sopenharmony_ci		__field(u64, serial)
13962306a36Sopenharmony_ci		__field(u64, first_ts)
14062306a36Sopenharmony_ci		__field(u64, last_ts)
14162306a36Sopenharmony_ci		__field(u16, count)
14262306a36Sopenharmony_ci	),
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci	TP_fast_assign(
14562306a36Sopenharmony_ci		__assign_str(memdev, dev_name(&cxlmd->dev));
14662306a36Sopenharmony_ci		__assign_str(host, dev_name(cxlmd->dev.parent));
14762306a36Sopenharmony_ci		__entry->serial = cxlmd->cxlds->serial;
14862306a36Sopenharmony_ci		__entry->log = log;
14962306a36Sopenharmony_ci		__entry->count = le16_to_cpu(payload->overflow_err_count);
15062306a36Sopenharmony_ci		__entry->first_ts = le64_to_cpu(payload->first_overflow_timestamp);
15162306a36Sopenharmony_ci		__entry->last_ts = le64_to_cpu(payload->last_overflow_timestamp);
15262306a36Sopenharmony_ci	),
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci	TP_printk("memdev=%s host=%s serial=%lld: log=%s : %u records from %llu to %llu",
15562306a36Sopenharmony_ci		__get_str(memdev), __get_str(host), __entry->serial,
15662306a36Sopenharmony_ci		cxl_event_log_type_str(__entry->log), __entry->count,
15762306a36Sopenharmony_ci		__entry->first_ts, __entry->last_ts)
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci);
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci/*
16262306a36Sopenharmony_ci * Common Event Record Format
16362306a36Sopenharmony_ci * CXL 3.0 section 8.2.9.2.1; Table 8-42
16462306a36Sopenharmony_ci */
16562306a36Sopenharmony_ci#define CXL_EVENT_RECORD_FLAG_PERMANENT		BIT(2)
16662306a36Sopenharmony_ci#define CXL_EVENT_RECORD_FLAG_MAINT_NEEDED	BIT(3)
16762306a36Sopenharmony_ci#define CXL_EVENT_RECORD_FLAG_PERF_DEGRADED	BIT(4)
16862306a36Sopenharmony_ci#define CXL_EVENT_RECORD_FLAG_HW_REPLACE	BIT(5)
16962306a36Sopenharmony_ci#define show_hdr_flags(flags)	__print_flags(flags, " | ",			   \
17062306a36Sopenharmony_ci	{ CXL_EVENT_RECORD_FLAG_PERMANENT,	"PERMANENT_CONDITION"		}, \
17162306a36Sopenharmony_ci	{ CXL_EVENT_RECORD_FLAG_MAINT_NEEDED,	"MAINTENANCE_NEEDED"		}, \
17262306a36Sopenharmony_ci	{ CXL_EVENT_RECORD_FLAG_PERF_DEGRADED,	"PERFORMANCE_DEGRADED"		}, \
17362306a36Sopenharmony_ci	{ CXL_EVENT_RECORD_FLAG_HW_REPLACE,	"HARDWARE_REPLACEMENT_NEEDED"	}  \
17462306a36Sopenharmony_ci)
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci/*
17762306a36Sopenharmony_ci * Define macros for the common header of each CXL event.
17862306a36Sopenharmony_ci *
17962306a36Sopenharmony_ci * Tracepoints using these macros must do 3 things:
18062306a36Sopenharmony_ci *
18162306a36Sopenharmony_ci *	1) Add CXL_EVT_TP_entry to TP_STRUCT__entry
18262306a36Sopenharmony_ci *	2) Use CXL_EVT_TP_fast_assign within TP_fast_assign;
18362306a36Sopenharmony_ci *	   pass the dev, log, and CXL event header
18462306a36Sopenharmony_ci *	3) Use CXL_EVT_TP_printk() instead of TP_printk()
18562306a36Sopenharmony_ci *
18662306a36Sopenharmony_ci * See the generic_event tracepoint as an example.
18762306a36Sopenharmony_ci */
18862306a36Sopenharmony_ci#define CXL_EVT_TP_entry					\
18962306a36Sopenharmony_ci	__string(memdev, dev_name(&cxlmd->dev))			\
19062306a36Sopenharmony_ci	__string(host, dev_name(cxlmd->dev.parent))		\
19162306a36Sopenharmony_ci	__field(int, log)					\
19262306a36Sopenharmony_ci	__field_struct(uuid_t, hdr_uuid)			\
19362306a36Sopenharmony_ci	__field(u64, serial)					\
19462306a36Sopenharmony_ci	__field(u32, hdr_flags)					\
19562306a36Sopenharmony_ci	__field(u16, hdr_handle)				\
19662306a36Sopenharmony_ci	__field(u16, hdr_related_handle)			\
19762306a36Sopenharmony_ci	__field(u64, hdr_timestamp)				\
19862306a36Sopenharmony_ci	__field(u8, hdr_length)					\
19962306a36Sopenharmony_ci	__field(u8, hdr_maint_op_class)
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci#define CXL_EVT_TP_fast_assign(cxlmd, l, hdr)					\
20262306a36Sopenharmony_ci	__assign_str(memdev, dev_name(&(cxlmd)->dev));				\
20362306a36Sopenharmony_ci	__assign_str(host, dev_name((cxlmd)->dev.parent));			\
20462306a36Sopenharmony_ci	__entry->log = (l);							\
20562306a36Sopenharmony_ci	__entry->serial = (cxlmd)->cxlds->serial;				\
20662306a36Sopenharmony_ci	memcpy(&__entry->hdr_uuid, &(hdr).id, sizeof(uuid_t));			\
20762306a36Sopenharmony_ci	__entry->hdr_length = (hdr).length;					\
20862306a36Sopenharmony_ci	__entry->hdr_flags = get_unaligned_le24((hdr).flags);			\
20962306a36Sopenharmony_ci	__entry->hdr_handle = le16_to_cpu((hdr).handle);			\
21062306a36Sopenharmony_ci	__entry->hdr_related_handle = le16_to_cpu((hdr).related_handle);	\
21162306a36Sopenharmony_ci	__entry->hdr_timestamp = le64_to_cpu((hdr).timestamp);			\
21262306a36Sopenharmony_ci	__entry->hdr_maint_op_class = (hdr).maint_op_class
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci#define CXL_EVT_TP_printk(fmt, ...) \
21562306a36Sopenharmony_ci	TP_printk("memdev=%s host=%s serial=%lld log=%s : time=%llu uuid=%pUb "	\
21662306a36Sopenharmony_ci		"len=%d flags='%s' handle=%x related_handle=%x "		\
21762306a36Sopenharmony_ci		"maint_op_class=%u : " fmt,					\
21862306a36Sopenharmony_ci		__get_str(memdev), __get_str(host), __entry->serial,		\
21962306a36Sopenharmony_ci		cxl_event_log_type_str(__entry->log),				\
22062306a36Sopenharmony_ci		__entry->hdr_timestamp, &__entry->hdr_uuid, __entry->hdr_length,\
22162306a36Sopenharmony_ci		show_hdr_flags(__entry->hdr_flags), __entry->hdr_handle,	\
22262306a36Sopenharmony_ci		__entry->hdr_related_handle, __entry->hdr_maint_op_class,	\
22362306a36Sopenharmony_ci		##__VA_ARGS__)
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ciTRACE_EVENT(cxl_generic_event,
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
22862306a36Sopenharmony_ci		 struct cxl_event_record_raw *rec),
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci	TP_ARGS(cxlmd, log, rec),
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci	TP_STRUCT__entry(
23362306a36Sopenharmony_ci		CXL_EVT_TP_entry
23462306a36Sopenharmony_ci		__array(u8, data, CXL_EVENT_RECORD_DATA_LENGTH)
23562306a36Sopenharmony_ci	),
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci	TP_fast_assign(
23862306a36Sopenharmony_ci		CXL_EVT_TP_fast_assign(cxlmd, log, rec->hdr);
23962306a36Sopenharmony_ci		memcpy(__entry->data, &rec->data, CXL_EVENT_RECORD_DATA_LENGTH);
24062306a36Sopenharmony_ci	),
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci	CXL_EVT_TP_printk("%s",
24362306a36Sopenharmony_ci		__print_hex(__entry->data, CXL_EVENT_RECORD_DATA_LENGTH))
24462306a36Sopenharmony_ci);
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ci/*
24762306a36Sopenharmony_ci * Physical Address field masks
24862306a36Sopenharmony_ci *
24962306a36Sopenharmony_ci * General Media Event Record
25062306a36Sopenharmony_ci * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
25162306a36Sopenharmony_ci *
25262306a36Sopenharmony_ci * DRAM Event Record
25362306a36Sopenharmony_ci * CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
25462306a36Sopenharmony_ci */
25562306a36Sopenharmony_ci#define CXL_DPA_FLAGS_MASK			0x3F
25662306a36Sopenharmony_ci#define CXL_DPA_MASK				(~CXL_DPA_FLAGS_MASK)
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci#define CXL_DPA_VOLATILE			BIT(0)
25962306a36Sopenharmony_ci#define CXL_DPA_NOT_REPAIRABLE			BIT(1)
26062306a36Sopenharmony_ci#define show_dpa_flags(flags)	__print_flags(flags, "|",		   \
26162306a36Sopenharmony_ci	{ CXL_DPA_VOLATILE,			"VOLATILE"		}, \
26262306a36Sopenharmony_ci	{ CXL_DPA_NOT_REPAIRABLE,		"NOT_REPAIRABLE"	}  \
26362306a36Sopenharmony_ci)
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci/*
26662306a36Sopenharmony_ci * General Media Event Record - GMER
26762306a36Sopenharmony_ci * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
26862306a36Sopenharmony_ci */
26962306a36Sopenharmony_ci#define CXL_GMER_EVT_DESC_UNCORECTABLE_EVENT		BIT(0)
27062306a36Sopenharmony_ci#define CXL_GMER_EVT_DESC_THRESHOLD_EVENT		BIT(1)
27162306a36Sopenharmony_ci#define CXL_GMER_EVT_DESC_POISON_LIST_OVERFLOW		BIT(2)
27262306a36Sopenharmony_ci#define show_event_desc_flags(flags)	__print_flags(flags, "|",		   \
27362306a36Sopenharmony_ci	{ CXL_GMER_EVT_DESC_UNCORECTABLE_EVENT,		"UNCORRECTABLE_EVENT"	}, \
27462306a36Sopenharmony_ci	{ CXL_GMER_EVT_DESC_THRESHOLD_EVENT,		"THRESHOLD_EVENT"	}, \
27562306a36Sopenharmony_ci	{ CXL_GMER_EVT_DESC_POISON_LIST_OVERFLOW,	"POISON_LIST_OVERFLOW"	}  \
27662306a36Sopenharmony_ci)
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci#define CXL_GMER_MEM_EVT_TYPE_ECC_ERROR			0x00
27962306a36Sopenharmony_ci#define CXL_GMER_MEM_EVT_TYPE_INV_ADDR			0x01
28062306a36Sopenharmony_ci#define CXL_GMER_MEM_EVT_TYPE_DATA_PATH_ERROR		0x02
28162306a36Sopenharmony_ci#define show_mem_event_type(type)	__print_symbolic(type,			\
28262306a36Sopenharmony_ci	{ CXL_GMER_MEM_EVT_TYPE_ECC_ERROR,		"ECC Error" },		\
28362306a36Sopenharmony_ci	{ CXL_GMER_MEM_EVT_TYPE_INV_ADDR,		"Invalid Address" },	\
28462306a36Sopenharmony_ci	{ CXL_GMER_MEM_EVT_TYPE_DATA_PATH_ERROR,	"Data Path Error" }	\
28562306a36Sopenharmony_ci)
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci#define CXL_GMER_TRANS_UNKNOWN				0x00
28862306a36Sopenharmony_ci#define CXL_GMER_TRANS_HOST_READ			0x01
28962306a36Sopenharmony_ci#define CXL_GMER_TRANS_HOST_WRITE			0x02
29062306a36Sopenharmony_ci#define CXL_GMER_TRANS_HOST_SCAN_MEDIA			0x03
29162306a36Sopenharmony_ci#define CXL_GMER_TRANS_HOST_INJECT_POISON		0x04
29262306a36Sopenharmony_ci#define CXL_GMER_TRANS_INTERNAL_MEDIA_SCRUB		0x05
29362306a36Sopenharmony_ci#define CXL_GMER_TRANS_INTERNAL_MEDIA_MANAGEMENT	0x06
29462306a36Sopenharmony_ci#define show_trans_type(type)	__print_symbolic(type,					\
29562306a36Sopenharmony_ci	{ CXL_GMER_TRANS_UNKNOWN,			"Unknown" },			\
29662306a36Sopenharmony_ci	{ CXL_GMER_TRANS_HOST_READ,			"Host Read" },			\
29762306a36Sopenharmony_ci	{ CXL_GMER_TRANS_HOST_WRITE,			"Host Write" },			\
29862306a36Sopenharmony_ci	{ CXL_GMER_TRANS_HOST_SCAN_MEDIA,		"Host Scan Media" },		\
29962306a36Sopenharmony_ci	{ CXL_GMER_TRANS_HOST_INJECT_POISON,		"Host Inject Poison" },		\
30062306a36Sopenharmony_ci	{ CXL_GMER_TRANS_INTERNAL_MEDIA_SCRUB,		"Internal Media Scrub" },	\
30162306a36Sopenharmony_ci	{ CXL_GMER_TRANS_INTERNAL_MEDIA_MANAGEMENT,	"Internal Media Management" }	\
30262306a36Sopenharmony_ci)
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci#define CXL_GMER_VALID_CHANNEL				BIT(0)
30562306a36Sopenharmony_ci#define CXL_GMER_VALID_RANK				BIT(1)
30662306a36Sopenharmony_ci#define CXL_GMER_VALID_DEVICE				BIT(2)
30762306a36Sopenharmony_ci#define CXL_GMER_VALID_COMPONENT			BIT(3)
30862306a36Sopenharmony_ci#define show_valid_flags(flags)	__print_flags(flags, "|",		   \
30962306a36Sopenharmony_ci	{ CXL_GMER_VALID_CHANNEL,			"CHANNEL"	}, \
31062306a36Sopenharmony_ci	{ CXL_GMER_VALID_RANK,				"RANK"		}, \
31162306a36Sopenharmony_ci	{ CXL_GMER_VALID_DEVICE,			"DEVICE"	}, \
31262306a36Sopenharmony_ci	{ CXL_GMER_VALID_COMPONENT,			"COMPONENT"	}  \
31362306a36Sopenharmony_ci)
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ciTRACE_EVENT(cxl_general_media,
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
31862306a36Sopenharmony_ci		 struct cxl_event_gen_media *rec),
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci	TP_ARGS(cxlmd, log, rec),
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ci	TP_STRUCT__entry(
32362306a36Sopenharmony_ci		CXL_EVT_TP_entry
32462306a36Sopenharmony_ci		/* General Media */
32562306a36Sopenharmony_ci		__field(u64, dpa)
32662306a36Sopenharmony_ci		__field(u8, descriptor)
32762306a36Sopenharmony_ci		__field(u8, type)
32862306a36Sopenharmony_ci		__field(u8, transaction_type)
32962306a36Sopenharmony_ci		__field(u8, channel)
33062306a36Sopenharmony_ci		__field(u32, device)
33162306a36Sopenharmony_ci		__array(u8, comp_id, CXL_EVENT_GEN_MED_COMP_ID_SIZE)
33262306a36Sopenharmony_ci		__field(u16, validity_flags)
33362306a36Sopenharmony_ci		/* Following are out of order to pack trace record */
33462306a36Sopenharmony_ci		__field(u8, rank)
33562306a36Sopenharmony_ci		__field(u8, dpa_flags)
33662306a36Sopenharmony_ci	),
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ci	TP_fast_assign(
33962306a36Sopenharmony_ci		CXL_EVT_TP_fast_assign(cxlmd, log, rec->hdr);
34062306a36Sopenharmony_ci
34162306a36Sopenharmony_ci		/* General Media */
34262306a36Sopenharmony_ci		__entry->dpa = le64_to_cpu(rec->phys_addr);
34362306a36Sopenharmony_ci		__entry->dpa_flags = __entry->dpa & CXL_DPA_FLAGS_MASK;
34462306a36Sopenharmony_ci		/* Mask after flags have been parsed */
34562306a36Sopenharmony_ci		__entry->dpa &= CXL_DPA_MASK;
34662306a36Sopenharmony_ci		__entry->descriptor = rec->descriptor;
34762306a36Sopenharmony_ci		__entry->type = rec->type;
34862306a36Sopenharmony_ci		__entry->transaction_type = rec->transaction_type;
34962306a36Sopenharmony_ci		__entry->channel = rec->channel;
35062306a36Sopenharmony_ci		__entry->rank = rec->rank;
35162306a36Sopenharmony_ci		__entry->device = get_unaligned_le24(rec->device);
35262306a36Sopenharmony_ci		memcpy(__entry->comp_id, &rec->component_id,
35362306a36Sopenharmony_ci			CXL_EVENT_GEN_MED_COMP_ID_SIZE);
35462306a36Sopenharmony_ci		__entry->validity_flags = get_unaligned_le16(&rec->validity_flags);
35562306a36Sopenharmony_ci	),
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci	CXL_EVT_TP_printk("dpa=%llx dpa_flags='%s' " \
35862306a36Sopenharmony_ci		"descriptor='%s' type='%s' transaction_type='%s' channel=%u rank=%u " \
35962306a36Sopenharmony_ci		"device=%x comp_id=%s validity_flags='%s'",
36062306a36Sopenharmony_ci		__entry->dpa, show_dpa_flags(__entry->dpa_flags),
36162306a36Sopenharmony_ci		show_event_desc_flags(__entry->descriptor),
36262306a36Sopenharmony_ci		show_mem_event_type(__entry->type),
36362306a36Sopenharmony_ci		show_trans_type(__entry->transaction_type),
36462306a36Sopenharmony_ci		__entry->channel, __entry->rank, __entry->device,
36562306a36Sopenharmony_ci		__print_hex(__entry->comp_id, CXL_EVENT_GEN_MED_COMP_ID_SIZE),
36662306a36Sopenharmony_ci		show_valid_flags(__entry->validity_flags)
36762306a36Sopenharmony_ci	)
36862306a36Sopenharmony_ci);
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ci/*
37162306a36Sopenharmony_ci * DRAM Event Record - DER
37262306a36Sopenharmony_ci *
37362306a36Sopenharmony_ci * CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
37462306a36Sopenharmony_ci */
37562306a36Sopenharmony_ci/*
37662306a36Sopenharmony_ci * DRAM Event Record defines many fields the same as the General Media Event
37762306a36Sopenharmony_ci * Record.  Reuse those definitions as appropriate.
37862306a36Sopenharmony_ci */
37962306a36Sopenharmony_ci#define CXL_DER_VALID_CHANNEL				BIT(0)
38062306a36Sopenharmony_ci#define CXL_DER_VALID_RANK				BIT(1)
38162306a36Sopenharmony_ci#define CXL_DER_VALID_NIBBLE				BIT(2)
38262306a36Sopenharmony_ci#define CXL_DER_VALID_BANK_GROUP			BIT(3)
38362306a36Sopenharmony_ci#define CXL_DER_VALID_BANK				BIT(4)
38462306a36Sopenharmony_ci#define CXL_DER_VALID_ROW				BIT(5)
38562306a36Sopenharmony_ci#define CXL_DER_VALID_COLUMN				BIT(6)
38662306a36Sopenharmony_ci#define CXL_DER_VALID_CORRECTION_MASK			BIT(7)
38762306a36Sopenharmony_ci#define show_dram_valid_flags(flags)	__print_flags(flags, "|",			   \
38862306a36Sopenharmony_ci	{ CXL_DER_VALID_CHANNEL,			"CHANNEL"		}, \
38962306a36Sopenharmony_ci	{ CXL_DER_VALID_RANK,				"RANK"			}, \
39062306a36Sopenharmony_ci	{ CXL_DER_VALID_NIBBLE,				"NIBBLE"		}, \
39162306a36Sopenharmony_ci	{ CXL_DER_VALID_BANK_GROUP,			"BANK GROUP"		}, \
39262306a36Sopenharmony_ci	{ CXL_DER_VALID_BANK,				"BANK"			}, \
39362306a36Sopenharmony_ci	{ CXL_DER_VALID_ROW,				"ROW"			}, \
39462306a36Sopenharmony_ci	{ CXL_DER_VALID_COLUMN,				"COLUMN"		}, \
39562306a36Sopenharmony_ci	{ CXL_DER_VALID_CORRECTION_MASK,		"CORRECTION MASK"	}  \
39662306a36Sopenharmony_ci)
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ciTRACE_EVENT(cxl_dram,
39962306a36Sopenharmony_ci
40062306a36Sopenharmony_ci	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
40162306a36Sopenharmony_ci		 struct cxl_event_dram *rec),
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci	TP_ARGS(cxlmd, log, rec),
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_ci	TP_STRUCT__entry(
40662306a36Sopenharmony_ci		CXL_EVT_TP_entry
40762306a36Sopenharmony_ci		/* DRAM */
40862306a36Sopenharmony_ci		__field(u64, dpa)
40962306a36Sopenharmony_ci		__field(u8, descriptor)
41062306a36Sopenharmony_ci		__field(u8, type)
41162306a36Sopenharmony_ci		__field(u8, transaction_type)
41262306a36Sopenharmony_ci		__field(u8, channel)
41362306a36Sopenharmony_ci		__field(u16, validity_flags)
41462306a36Sopenharmony_ci		__field(u16, column)	/* Out of order to pack trace record */
41562306a36Sopenharmony_ci		__field(u32, nibble_mask)
41662306a36Sopenharmony_ci		__field(u32, row)
41762306a36Sopenharmony_ci		__array(u8, cor_mask, CXL_EVENT_DER_CORRECTION_MASK_SIZE)
41862306a36Sopenharmony_ci		__field(u8, rank)	/* Out of order to pack trace record */
41962306a36Sopenharmony_ci		__field(u8, bank_group)	/* Out of order to pack trace record */
42062306a36Sopenharmony_ci		__field(u8, bank)	/* Out of order to pack trace record */
42162306a36Sopenharmony_ci		__field(u8, dpa_flags)	/* Out of order to pack trace record */
42262306a36Sopenharmony_ci	),
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_ci	TP_fast_assign(
42562306a36Sopenharmony_ci		CXL_EVT_TP_fast_assign(cxlmd, log, rec->hdr);
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci		/* DRAM */
42862306a36Sopenharmony_ci		__entry->dpa = le64_to_cpu(rec->phys_addr);
42962306a36Sopenharmony_ci		__entry->dpa_flags = __entry->dpa & CXL_DPA_FLAGS_MASK;
43062306a36Sopenharmony_ci		__entry->dpa &= CXL_DPA_MASK;
43162306a36Sopenharmony_ci		__entry->descriptor = rec->descriptor;
43262306a36Sopenharmony_ci		__entry->type = rec->type;
43362306a36Sopenharmony_ci		__entry->transaction_type = rec->transaction_type;
43462306a36Sopenharmony_ci		__entry->validity_flags = get_unaligned_le16(rec->validity_flags);
43562306a36Sopenharmony_ci		__entry->channel = rec->channel;
43662306a36Sopenharmony_ci		__entry->rank = rec->rank;
43762306a36Sopenharmony_ci		__entry->nibble_mask = get_unaligned_le24(rec->nibble_mask);
43862306a36Sopenharmony_ci		__entry->bank_group = rec->bank_group;
43962306a36Sopenharmony_ci		__entry->bank = rec->bank;
44062306a36Sopenharmony_ci		__entry->row = get_unaligned_le24(rec->row);
44162306a36Sopenharmony_ci		__entry->column = get_unaligned_le16(rec->column);
44262306a36Sopenharmony_ci		memcpy(__entry->cor_mask, &rec->correction_mask,
44362306a36Sopenharmony_ci			CXL_EVENT_DER_CORRECTION_MASK_SIZE);
44462306a36Sopenharmony_ci	),
44562306a36Sopenharmony_ci
44662306a36Sopenharmony_ci	CXL_EVT_TP_printk("dpa=%llx dpa_flags='%s' descriptor='%s' type='%s' " \
44762306a36Sopenharmony_ci		"transaction_type='%s' channel=%u rank=%u nibble_mask=%x " \
44862306a36Sopenharmony_ci		"bank_group=%u bank=%u row=%u column=%u cor_mask=%s " \
44962306a36Sopenharmony_ci		"validity_flags='%s'",
45062306a36Sopenharmony_ci		__entry->dpa, show_dpa_flags(__entry->dpa_flags),
45162306a36Sopenharmony_ci		show_event_desc_flags(__entry->descriptor),
45262306a36Sopenharmony_ci		show_mem_event_type(__entry->type),
45362306a36Sopenharmony_ci		show_trans_type(__entry->transaction_type),
45462306a36Sopenharmony_ci		__entry->channel, __entry->rank, __entry->nibble_mask,
45562306a36Sopenharmony_ci		__entry->bank_group, __entry->bank,
45662306a36Sopenharmony_ci		__entry->row, __entry->column,
45762306a36Sopenharmony_ci		__print_hex(__entry->cor_mask, CXL_EVENT_DER_CORRECTION_MASK_SIZE),
45862306a36Sopenharmony_ci		show_dram_valid_flags(__entry->validity_flags)
45962306a36Sopenharmony_ci	)
46062306a36Sopenharmony_ci);
46162306a36Sopenharmony_ci
46262306a36Sopenharmony_ci/*
46362306a36Sopenharmony_ci * Memory Module Event Record - MMER
46462306a36Sopenharmony_ci *
46562306a36Sopenharmony_ci * CXL res 3.0 section 8.2.9.2.1.3; Table 8-45
46662306a36Sopenharmony_ci */
46762306a36Sopenharmony_ci#define CXL_MMER_HEALTH_STATUS_CHANGE		0x00
46862306a36Sopenharmony_ci#define CXL_MMER_MEDIA_STATUS_CHANGE		0x01
46962306a36Sopenharmony_ci#define CXL_MMER_LIFE_USED_CHANGE		0x02
47062306a36Sopenharmony_ci#define CXL_MMER_TEMP_CHANGE			0x03
47162306a36Sopenharmony_ci#define CXL_MMER_DATA_PATH_ERROR		0x04
47262306a36Sopenharmony_ci#define CXL_MMER_LSA_ERROR			0x05
47362306a36Sopenharmony_ci#define show_dev_evt_type(type)	__print_symbolic(type,			   \
47462306a36Sopenharmony_ci	{ CXL_MMER_HEALTH_STATUS_CHANGE,	"Health Status Change"	}, \
47562306a36Sopenharmony_ci	{ CXL_MMER_MEDIA_STATUS_CHANGE,		"Media Status Change"	}, \
47662306a36Sopenharmony_ci	{ CXL_MMER_LIFE_USED_CHANGE,		"Life Used Change"	}, \
47762306a36Sopenharmony_ci	{ CXL_MMER_TEMP_CHANGE,			"Temperature Change"	}, \
47862306a36Sopenharmony_ci	{ CXL_MMER_DATA_PATH_ERROR,		"Data Path Error"	}, \
47962306a36Sopenharmony_ci	{ CXL_MMER_LSA_ERROR,			"LSA Error"		}  \
48062306a36Sopenharmony_ci)
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_ci/*
48362306a36Sopenharmony_ci * Device Health Information - DHI
48462306a36Sopenharmony_ci *
48562306a36Sopenharmony_ci * CXL res 3.0 section 8.2.9.8.3.1; Table 8-100
48662306a36Sopenharmony_ci */
48762306a36Sopenharmony_ci#define CXL_DHI_HS_MAINTENANCE_NEEDED				BIT(0)
48862306a36Sopenharmony_ci#define CXL_DHI_HS_PERFORMANCE_DEGRADED				BIT(1)
48962306a36Sopenharmony_ci#define CXL_DHI_HS_HW_REPLACEMENT_NEEDED			BIT(2)
49062306a36Sopenharmony_ci#define show_health_status_flags(flags)	__print_flags(flags, "|",	   \
49162306a36Sopenharmony_ci	{ CXL_DHI_HS_MAINTENANCE_NEEDED,	"MAINTENANCE_NEEDED"	}, \
49262306a36Sopenharmony_ci	{ CXL_DHI_HS_PERFORMANCE_DEGRADED,	"PERFORMANCE_DEGRADED"	}, \
49362306a36Sopenharmony_ci	{ CXL_DHI_HS_HW_REPLACEMENT_NEEDED,	"REPLACEMENT_NEEDED"	}  \
49462306a36Sopenharmony_ci)
49562306a36Sopenharmony_ci
49662306a36Sopenharmony_ci#define CXL_DHI_MS_NORMAL							0x00
49762306a36Sopenharmony_ci#define CXL_DHI_MS_NOT_READY							0x01
49862306a36Sopenharmony_ci#define CXL_DHI_MS_WRITE_PERSISTENCY_LOST					0x02
49962306a36Sopenharmony_ci#define CXL_DHI_MS_ALL_DATA_LOST						0x03
50062306a36Sopenharmony_ci#define CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_EVENT_POWER_LOSS			0x04
50162306a36Sopenharmony_ci#define CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_EVENT_SHUTDOWN			0x05
50262306a36Sopenharmony_ci#define CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_IMMINENT				0x06
50362306a36Sopenharmony_ci#define CXL_DHI_MS_WRITE_ALL_DATA_LOSS_EVENT_POWER_LOSS				0x07
50462306a36Sopenharmony_ci#define CXL_DHI_MS_WRITE_ALL_DATA_LOSS_EVENT_SHUTDOWN				0x08
50562306a36Sopenharmony_ci#define CXL_DHI_MS_WRITE_ALL_DATA_LOSS_IMMINENT					0x09
50662306a36Sopenharmony_ci#define show_media_status(ms)	__print_symbolic(ms,			   \
50762306a36Sopenharmony_ci	{ CXL_DHI_MS_NORMAL,						   \
50862306a36Sopenharmony_ci		"Normal"						}, \
50962306a36Sopenharmony_ci	{ CXL_DHI_MS_NOT_READY,						   \
51062306a36Sopenharmony_ci		"Not Ready"						}, \
51162306a36Sopenharmony_ci	{ CXL_DHI_MS_WRITE_PERSISTENCY_LOST,				   \
51262306a36Sopenharmony_ci		"Write Persistency Lost"				}, \
51362306a36Sopenharmony_ci	{ CXL_DHI_MS_ALL_DATA_LOST,					   \
51462306a36Sopenharmony_ci		"All Data Lost"						}, \
51562306a36Sopenharmony_ci	{ CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_EVENT_POWER_LOSS,		   \
51662306a36Sopenharmony_ci		"Write Persistency Loss in the Event of Power Loss"	}, \
51762306a36Sopenharmony_ci	{ CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_EVENT_SHUTDOWN,		   \
51862306a36Sopenharmony_ci		"Write Persistency Loss in Event of Shutdown"		}, \
51962306a36Sopenharmony_ci	{ CXL_DHI_MS_WRITE_PERSISTENCY_LOSS_IMMINENT,			   \
52062306a36Sopenharmony_ci		"Write Persistency Loss Imminent"			}, \
52162306a36Sopenharmony_ci	{ CXL_DHI_MS_WRITE_ALL_DATA_LOSS_EVENT_POWER_LOSS,		   \
52262306a36Sopenharmony_ci		"All Data Loss in Event of Power Loss"			}, \
52362306a36Sopenharmony_ci	{ CXL_DHI_MS_WRITE_ALL_DATA_LOSS_EVENT_SHUTDOWN,		   \
52462306a36Sopenharmony_ci		"All Data loss in the Event of Shutdown"		}, \
52562306a36Sopenharmony_ci	{ CXL_DHI_MS_WRITE_ALL_DATA_LOSS_IMMINENT,			   \
52662306a36Sopenharmony_ci		"All Data Loss Imminent"				}  \
52762306a36Sopenharmony_ci)
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_ci#define CXL_DHI_AS_NORMAL		0x0
53062306a36Sopenharmony_ci#define CXL_DHI_AS_WARNING		0x1
53162306a36Sopenharmony_ci#define CXL_DHI_AS_CRITICAL		0x2
53262306a36Sopenharmony_ci#define show_two_bit_status(as) __print_symbolic(as,	   \
53362306a36Sopenharmony_ci	{ CXL_DHI_AS_NORMAL,		"Normal"	}, \
53462306a36Sopenharmony_ci	{ CXL_DHI_AS_WARNING,		"Warning"	}, \
53562306a36Sopenharmony_ci	{ CXL_DHI_AS_CRITICAL,		"Critical"	}  \
53662306a36Sopenharmony_ci)
53762306a36Sopenharmony_ci#define show_one_bit_status(as) __print_symbolic(as,	   \
53862306a36Sopenharmony_ci	{ CXL_DHI_AS_NORMAL,		"Normal"	}, \
53962306a36Sopenharmony_ci	{ CXL_DHI_AS_WARNING,		"Warning"	}  \
54062306a36Sopenharmony_ci)
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_ci#define CXL_DHI_AS_LIFE_USED(as)			(as & 0x3)
54362306a36Sopenharmony_ci#define CXL_DHI_AS_DEV_TEMP(as)				((as & 0xC) >> 2)
54462306a36Sopenharmony_ci#define CXL_DHI_AS_COR_VOL_ERR_CNT(as)			((as & 0x10) >> 4)
54562306a36Sopenharmony_ci#define CXL_DHI_AS_COR_PER_ERR_CNT(as)			((as & 0x20) >> 5)
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ciTRACE_EVENT(cxl_memory_module,
54862306a36Sopenharmony_ci
54962306a36Sopenharmony_ci	TP_PROTO(const struct cxl_memdev *cxlmd, enum cxl_event_log_type log,
55062306a36Sopenharmony_ci		 struct cxl_event_mem_module *rec),
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_ci	TP_ARGS(cxlmd, log, rec),
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci	TP_STRUCT__entry(
55562306a36Sopenharmony_ci		CXL_EVT_TP_entry
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ci		/* Memory Module Event */
55862306a36Sopenharmony_ci		__field(u8, event_type)
55962306a36Sopenharmony_ci
56062306a36Sopenharmony_ci		/* Device Health Info */
56162306a36Sopenharmony_ci		__field(u8, health_status)
56262306a36Sopenharmony_ci		__field(u8, media_status)
56362306a36Sopenharmony_ci		__field(u8, life_used)
56462306a36Sopenharmony_ci		__field(u32, dirty_shutdown_cnt)
56562306a36Sopenharmony_ci		__field(u32, cor_vol_err_cnt)
56662306a36Sopenharmony_ci		__field(u32, cor_per_err_cnt)
56762306a36Sopenharmony_ci		__field(s16, device_temp)
56862306a36Sopenharmony_ci		__field(u8, add_status)
56962306a36Sopenharmony_ci	),
57062306a36Sopenharmony_ci
57162306a36Sopenharmony_ci	TP_fast_assign(
57262306a36Sopenharmony_ci		CXL_EVT_TP_fast_assign(cxlmd, log, rec->hdr);
57362306a36Sopenharmony_ci
57462306a36Sopenharmony_ci		/* Memory Module Event */
57562306a36Sopenharmony_ci		__entry->event_type = rec->event_type;
57662306a36Sopenharmony_ci
57762306a36Sopenharmony_ci		/* Device Health Info */
57862306a36Sopenharmony_ci		__entry->health_status = rec->info.health_status;
57962306a36Sopenharmony_ci		__entry->media_status = rec->info.media_status;
58062306a36Sopenharmony_ci		__entry->life_used = rec->info.life_used;
58162306a36Sopenharmony_ci		__entry->dirty_shutdown_cnt = get_unaligned_le32(rec->info.dirty_shutdown_cnt);
58262306a36Sopenharmony_ci		__entry->cor_vol_err_cnt = get_unaligned_le32(rec->info.cor_vol_err_cnt);
58362306a36Sopenharmony_ci		__entry->cor_per_err_cnt = get_unaligned_le32(rec->info.cor_per_err_cnt);
58462306a36Sopenharmony_ci		__entry->device_temp = get_unaligned_le16(rec->info.device_temp);
58562306a36Sopenharmony_ci		__entry->add_status = rec->info.add_status;
58662306a36Sopenharmony_ci	),
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_ci	CXL_EVT_TP_printk("event_type='%s' health_status='%s' media_status='%s' " \
58962306a36Sopenharmony_ci		"as_life_used=%s as_dev_temp=%s as_cor_vol_err_cnt=%s " \
59062306a36Sopenharmony_ci		"as_cor_per_err_cnt=%s life_used=%u device_temp=%d " \
59162306a36Sopenharmony_ci		"dirty_shutdown_cnt=%u cor_vol_err_cnt=%u cor_per_err_cnt=%u",
59262306a36Sopenharmony_ci		show_dev_evt_type(__entry->event_type),
59362306a36Sopenharmony_ci		show_health_status_flags(__entry->health_status),
59462306a36Sopenharmony_ci		show_media_status(__entry->media_status),
59562306a36Sopenharmony_ci		show_two_bit_status(CXL_DHI_AS_LIFE_USED(__entry->add_status)),
59662306a36Sopenharmony_ci		show_two_bit_status(CXL_DHI_AS_DEV_TEMP(__entry->add_status)),
59762306a36Sopenharmony_ci		show_one_bit_status(CXL_DHI_AS_COR_VOL_ERR_CNT(__entry->add_status)),
59862306a36Sopenharmony_ci		show_one_bit_status(CXL_DHI_AS_COR_PER_ERR_CNT(__entry->add_status)),
59962306a36Sopenharmony_ci		__entry->life_used, __entry->device_temp,
60062306a36Sopenharmony_ci		__entry->dirty_shutdown_cnt, __entry->cor_vol_err_cnt,
60162306a36Sopenharmony_ci		__entry->cor_per_err_cnt
60262306a36Sopenharmony_ci	)
60362306a36Sopenharmony_ci);
60462306a36Sopenharmony_ci
60562306a36Sopenharmony_ci#define show_poison_trace_type(type)			\
60662306a36Sopenharmony_ci	__print_symbolic(type,				\
60762306a36Sopenharmony_ci	{ CXL_POISON_TRACE_LIST,	"List"   },	\
60862306a36Sopenharmony_ci	{ CXL_POISON_TRACE_INJECT,	"Inject" },	\
60962306a36Sopenharmony_ci	{ CXL_POISON_TRACE_CLEAR,	"Clear"  })
61062306a36Sopenharmony_ci
61162306a36Sopenharmony_ci#define __show_poison_source(source)                          \
61262306a36Sopenharmony_ci	__print_symbolic(source,                              \
61362306a36Sopenharmony_ci		{ CXL_POISON_SOURCE_UNKNOWN,   "Unknown"  },  \
61462306a36Sopenharmony_ci		{ CXL_POISON_SOURCE_EXTERNAL,  "External" },  \
61562306a36Sopenharmony_ci		{ CXL_POISON_SOURCE_INTERNAL,  "Internal" },  \
61662306a36Sopenharmony_ci		{ CXL_POISON_SOURCE_INJECTED,  "Injected" },  \
61762306a36Sopenharmony_ci		{ CXL_POISON_SOURCE_VENDOR,    "Vendor"   })
61862306a36Sopenharmony_ci
61962306a36Sopenharmony_ci#define show_poison_source(source)			     \
62062306a36Sopenharmony_ci	(((source > CXL_POISON_SOURCE_INJECTED) &&	     \
62162306a36Sopenharmony_ci	 (source != CXL_POISON_SOURCE_VENDOR)) ? "Reserved"  \
62262306a36Sopenharmony_ci	 : __show_poison_source(source))
62362306a36Sopenharmony_ci
62462306a36Sopenharmony_ci#define show_poison_flags(flags)                             \
62562306a36Sopenharmony_ci	__print_flags(flags, "|",                            \
62662306a36Sopenharmony_ci		{ CXL_POISON_FLAG_MORE,      "More"     },   \
62762306a36Sopenharmony_ci		{ CXL_POISON_FLAG_OVERFLOW,  "Overflow"  },  \
62862306a36Sopenharmony_ci		{ CXL_POISON_FLAG_SCANNING,  "Scanning"  })
62962306a36Sopenharmony_ci
63062306a36Sopenharmony_ci#define __cxl_poison_addr(record)					\
63162306a36Sopenharmony_ci	(le64_to_cpu(record->address))
63262306a36Sopenharmony_ci#define cxl_poison_record_dpa(record)					\
63362306a36Sopenharmony_ci	(__cxl_poison_addr(record) & CXL_POISON_START_MASK)
63462306a36Sopenharmony_ci#define cxl_poison_record_source(record)				\
63562306a36Sopenharmony_ci	(__cxl_poison_addr(record)  & CXL_POISON_SOURCE_MASK)
63662306a36Sopenharmony_ci#define cxl_poison_record_dpa_length(record)				\
63762306a36Sopenharmony_ci	(le32_to_cpu(record->length) * CXL_POISON_LEN_MULT)
63862306a36Sopenharmony_ci#define cxl_poison_overflow(flags, time)				\
63962306a36Sopenharmony_ci	(flags & CXL_POISON_FLAG_OVERFLOW ? le64_to_cpu(time) : 0)
64062306a36Sopenharmony_ci
64162306a36Sopenharmony_ciu64 cxl_trace_hpa(struct cxl_region *cxlr, struct cxl_memdev *memdev, u64 dpa);
64262306a36Sopenharmony_ci
64362306a36Sopenharmony_ciTRACE_EVENT(cxl_poison,
64462306a36Sopenharmony_ci
64562306a36Sopenharmony_ci	TP_PROTO(struct cxl_memdev *cxlmd, struct cxl_region *region,
64662306a36Sopenharmony_ci		 const struct cxl_poison_record *record, u8 flags,
64762306a36Sopenharmony_ci		 __le64 overflow_ts, enum cxl_poison_trace_type trace_type),
64862306a36Sopenharmony_ci
64962306a36Sopenharmony_ci	TP_ARGS(cxlmd, region, record, flags, overflow_ts, trace_type),
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_ci	TP_STRUCT__entry(
65262306a36Sopenharmony_ci		__string(memdev, dev_name(&cxlmd->dev))
65362306a36Sopenharmony_ci		__string(host, dev_name(cxlmd->dev.parent))
65462306a36Sopenharmony_ci		__field(u64, serial)
65562306a36Sopenharmony_ci		__field(u8, trace_type)
65662306a36Sopenharmony_ci		__string(region, region)
65762306a36Sopenharmony_ci		__field(u64, overflow_ts)
65862306a36Sopenharmony_ci		__field(u64, hpa)
65962306a36Sopenharmony_ci		__field(u64, dpa)
66062306a36Sopenharmony_ci		__field(u32, dpa_length)
66162306a36Sopenharmony_ci		__array(char, uuid, 16)
66262306a36Sopenharmony_ci		__field(u8, source)
66362306a36Sopenharmony_ci		__field(u8, flags)
66462306a36Sopenharmony_ci	    ),
66562306a36Sopenharmony_ci
66662306a36Sopenharmony_ci	TP_fast_assign(
66762306a36Sopenharmony_ci		__assign_str(memdev, dev_name(&cxlmd->dev));
66862306a36Sopenharmony_ci		__assign_str(host, dev_name(cxlmd->dev.parent));
66962306a36Sopenharmony_ci		__entry->serial = cxlmd->cxlds->serial;
67062306a36Sopenharmony_ci		__entry->overflow_ts = cxl_poison_overflow(flags, overflow_ts);
67162306a36Sopenharmony_ci		__entry->dpa = cxl_poison_record_dpa(record);
67262306a36Sopenharmony_ci		__entry->dpa_length = cxl_poison_record_dpa_length(record);
67362306a36Sopenharmony_ci		__entry->source = cxl_poison_record_source(record);
67462306a36Sopenharmony_ci		__entry->trace_type = trace_type;
67562306a36Sopenharmony_ci		__entry->flags = flags;
67662306a36Sopenharmony_ci		if (region) {
67762306a36Sopenharmony_ci			__assign_str(region, dev_name(&region->dev));
67862306a36Sopenharmony_ci			memcpy(__entry->uuid, &region->params.uuid, 16);
67962306a36Sopenharmony_ci			__entry->hpa = cxl_trace_hpa(region, cxlmd,
68062306a36Sopenharmony_ci						     __entry->dpa);
68162306a36Sopenharmony_ci		} else {
68262306a36Sopenharmony_ci			__assign_str(region, "");
68362306a36Sopenharmony_ci			memset(__entry->uuid, 0, 16);
68462306a36Sopenharmony_ci			__entry->hpa = ULLONG_MAX;
68562306a36Sopenharmony_ci		}
68662306a36Sopenharmony_ci	    ),
68762306a36Sopenharmony_ci
68862306a36Sopenharmony_ci	TP_printk("memdev=%s host=%s serial=%lld trace_type=%s region=%s "  \
68962306a36Sopenharmony_ci		"region_uuid=%pU hpa=0x%llx dpa=0x%llx dpa_length=0x%x "    \
69062306a36Sopenharmony_ci		"source=%s flags=%s overflow_time=%llu",
69162306a36Sopenharmony_ci		__get_str(memdev),
69262306a36Sopenharmony_ci		__get_str(host),
69362306a36Sopenharmony_ci		__entry->serial,
69462306a36Sopenharmony_ci		show_poison_trace_type(__entry->trace_type),
69562306a36Sopenharmony_ci		__get_str(region),
69662306a36Sopenharmony_ci		__entry->uuid,
69762306a36Sopenharmony_ci		__entry->hpa,
69862306a36Sopenharmony_ci		__entry->dpa,
69962306a36Sopenharmony_ci		__entry->dpa_length,
70062306a36Sopenharmony_ci		show_poison_source(__entry->source),
70162306a36Sopenharmony_ci		show_poison_flags(__entry->flags),
70262306a36Sopenharmony_ci		__entry->overflow_ts
70362306a36Sopenharmony_ci	)
70462306a36Sopenharmony_ci);
70562306a36Sopenharmony_ci
70662306a36Sopenharmony_ci#endif /* _CXL_EVENTS_H */
70762306a36Sopenharmony_ci
70862306a36Sopenharmony_ci#define TRACE_INCLUDE_FILE trace
70962306a36Sopenharmony_ci#include <trace/define_trace.h>
710