xref: /linux/drivers/gpu/drm/xe/xe_log.h (revision 7d1f84f1b94e79cb95d974ab3ec54cb3a4d64f5b)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2026 Intel Corporation
4  */
5 
6 #ifndef _XE_LOG_H_
7 #define _XE_LOG_H_
8 
9 #include <linux/cper.h>
10 #include <linux/err.h>
11 
12 #include "abi/xe_log_abi.h"
13 #include "abi/xe_sigid_abi.h"
14 #include "xe_any.h"
15 
16 struct pci_dev;
17 
18 __printf(8, 9)
19 void __xe_log_emit(struct pci_dev *pdev, int cper_sev, enum xe_sigid sigid,
20 		   u32 component, u32 location, const void *data, size_t len,
21 		   const char *fmt, ...);
22 
23 #define __xe_log_const_sev_to_level(sev) \
24 	(__builtin_constant_p(sev) ? (sev) == CPER_SEV_INFORMATIONAL ? KERN_INFO : KERN_ERR : NULL)
25 
26 #define __xe_log_emit_printk_index(level, fmt) \
27 	dev_printk_index_emit(level, "%s SIGID=%u %s" fmt);
28 
29 #define xe_log_emit(pdev, sev, sig, comp, loc, data, len, fmt, args...) do {		\
30 	__xe_log_emit_printk_index(__xe_log_const_sev_to_level(sev), fmt);		\
31 	__xe_log_emit((pdev), (sev), (sig), (comp), (loc), (data), (len), fmt, ##args); \
32 } while (0)
33 
34 #define xe_log_emit_fatal(pdev, sig, comp, loc, data, len, fmt, args...) \
35 	xe_log_emit((pdev), CPER_SEV_FATAL, (sig), (comp), (loc), \
36 		    (data), (len), fmt, ##args)
37 
38 #define xe_log_emit_recoverable(pdev, sig, comp, loc, data, len, fmt, args...) \
39 	xe_log_emit((pdev), CPER_SEV_RECOVERABLE, (sig), (comp), (loc), \
40 		    (data), (len), fmt, ##args)
41 
42 #define xe_log_emit_corrected(pdev, sig, comp, loc, data, len, fmt, args...) \
43 	xe_log_emit((pdev), CPER_SEV_CORRECTED, (sig), (comp), (loc), \
44 		    (data), (len), fmt, ##args)
45 
46 #define xe_log_emit_info(pdev, sig, comp, loc, data, len, fmt, args...) \
47 	xe_log_emit((pdev), CPER_SEV_INFORMATIONAL, (sig), (comp), (loc), \
48 		    (data), (len), fmt, ##args)
49 
50 #define xe_log_location_type(any)							\
51 	_Generic((any),									\
52 		 struct xe_gt * : XE_LOG_LOCATION_TYPE_GT,				\
53 		 const struct xe_gt * : XE_LOG_LOCATION_TYPE_GT,			\
54 		 struct xe_tile * : XE_LOG_LOCATION_TYPE_TILE,				\
55 		 const struct xe_tile * : XE_LOG_LOCATION_TYPE_TILE,			\
56 		 struct xe_device * : XE_LOG_LOCATION_TYPE_DEVICE,			\
57 		 const struct xe_device * : XE_LOG_LOCATION_TYPE_DEVICE,		\
58 		 struct pci_dev * : XE_LOG_LOCATION_TYPE_DEVICE,			\
59 		 struct device * : XE_LOG_LOCATION_TYPE_DEVICE)
60 
61 #define xe_log_location(any) \
62 	PREP_XE_LOG_LOCATION(xe_log_location_type(any), xe_any_id(any))
63 
64 /**
65  * xe_log_from() - Emit a structured SIGID log entry using @any pointer as location.
66  * @any: the &xe_device or &xe_tile or &xe_gt pointer this report relates to
67  * @cper_sev: CPER severity (CPER_SEV_FATAL, CPER_SEV_RECOVERABLE, ...)
68  * @sigid: signature identifier, see &enum xe_sigid
69  * @component: component identifer
70  * @data: pointer to the additional details, or ERR_PTR, or NULL if not applicable
71  * @len: length of the @data in bytes, or 0 if not applicable
72  * @fmt: printf-style format string
73  * @args: arguments for the @fmt format string
74  *
75  * The location used to emit SIGID entry will be based on the @any pointer type.
76  * See xe_log_emit() for more details.
77  */
78 #define xe_log_from(any, cper_sev, sigid, component, data, len, fmt, args...) do {	\
79 	typeof(any) ___any = (any);							\
80 	xe_log_emit(xe_any_to_pdev(___any), (cper_sev), (sigid), (component),		\
81 		    xe_log_location(___any), (data), (len), fmt, ##args);		\
82 } while (0)
83 
84 #define xe_log_from_fatal(any, sig, comp, data, len, fmt, args...) \
85 	xe_log_from((any), CPER_SEV_FATAL, (sig), (comp), \
86 		    (data), (len), fmt, ##args)
87 
88 #define xe_log_from_recoverable(any, sig, comp, data, len, fmt, args...) \
89 	xe_log_from((any), CPER_SEV_RECOVERABLE, (sig), (comp), \
90 		    (data), (len), fmt, ##args)
91 
92 #define xe_log_from_corrected(any, sig, comp, data, len, fmt, args...) \
93 	xe_log_from((any), CPER_SEV_CORRECTED, (sig), (comp), \
94 		    (data), (len), fmt, ##args)
95 
96 #define xe_log_from_info(any, sig, comp, data, len, fmt, args...) \
97 	xe_log_from((any), CPER_SEV_INFORMATIONAL, (sig), (comp), \
98 		    (data), (len), fmt, ##args)
99 
100 /**
101  * xe_log_comp() - Emit a structured SIGID log entry on the component behalf.
102  * @any: the &xe_device or &xe_tile or &xe_gt pointer this report relates to
103  * @cper_sev: CPER severity (CPER_SEV_FATAL, CPER_SEV_RECOVERABLE, ...)
104  * @TAG: the component tag to use
105  * @data: pointer to the additional details, or ERR_PTR, or NULL if not applicable
106  * @len: length of the @data in bytes, or 0 if not applicable
107  * @fmt: printf-style free text format string (not a stable interface)
108  * @args: arguments for the @fmt format string
109  *
110  * The SIGID will be determined from the component's @TAG.
111  * The component identifier will be determined from the component's @TAG.
112  * The location used to emit SIGID entry will be based on the @any pointer type.
113  */
114 #define xe_log_comp(any, cper_sev, TAG, data, len, fmt, args...) \
115 	xe_log_from((any), (cper_sev), (int)XE_LOG_COMPONENT_##TAG##_SIGID, \
116 		    XE_LOG_COMPONENT_##TAG, (data), (len), fmt, ##args)
117 
118 #define xe_log_comp_fatal(any, TAG, data, len, fmt, args...) \
119 	xe_log_comp((any), CPER_SEV_FATAL, TAG, (data), (len), fmt, ##args)
120 
121 #define xe_log_comp_recoverable(any, TAG, data, len, fmt, args...) \
122 	xe_log_comp((any), CPER_SEV_RECOVERABLE, TAG, (data), (len), fmt, ##args)
123 
124 #define xe_log_comp_corrected(any, TAG, data, len, fmt, args...) \
125 	xe_log_comp((any), CPER_SEV_CORRECTED, TAG, (data), (len), fmt, ##args)
126 
127 #define xe_log_comp_info(any, TAG, data, len, fmt, args...) \
128 	xe_log_comp((any), CPER_SEV_INFORMATIONAL, TAG, (data), (len), fmt, ##args)
129 
130 /**
131  * xe_log_err() - Emit a structured SIGID error log entry on the component behalf.
132  * @any: the &xe_device or &xe_tile or &xe_gt pointer this report relates to
133  * @TAG: the component tag to use
134  * @err: negative errno for the failing operation, or 0 if not applicable
135  * @fmt: printf-style free text format string (not a stable interface)
136  * @args: arguments for the @fmt format string
137  *
138  * The log entry will be emitted with @CPER_SEV_RECOVERABLE severity.
139  */
140 #define xe_log_err(any, TAG, err, fmt, args...) \
141 	xe_log_comp_recoverable((any), TAG, ERR_PTR(err), 0, fmt, ##args)
142 
143 /**
144  * xe_log_err_fatal() - Emit a structured SIGID error log entry on the component behalf.
145  * @any: the &xe_device or &xe_tile or &xe_gt pointer this report relates to
146  * @TAG: the component tag to use
147  * @err: negative errno for the failing operation, or 0 if not applicable
148  * @fmt: printf-style free text format string (not a stable interface)
149  * @args: arguments for the @fmt format string
150  *
151  * The log entry will be emitted with @CPER_SEV_FATAL severity.
152  */
153 #define xe_log_err_fatal(any, TAG, err, fmt, args...) \
154 	xe_log_comp_fatal((any), TAG, ERR_PTR(err), 0, fmt, ##args)
155 
156 /**
157  * xe_log_err_corrected() - Emit a structured SIGID error log entry on the component behalf.
158  * @any: the &xe_device or &xe_tile or &xe_gt pointer this report relates to
159  * @TAG: the component tag to use
160  * @err: negative errno for the failing operation, or 0 if not applicable
161  * @fmt: printf-style free text format string (not a stable interface)
162  * @args: arguments for the @fmt format string
163  *
164  * The log entry will be emitted with @CPER_SEV_CORRECTED severity.
165  */
166 #define xe_log_err_corrected(any, TAG, err, fmt, args...) \
167 	xe_log_comp_corrected((any), TAG, ERR_PTR(err), 0, fmt, ##args)
168 
169 /**
170  * xe_log_err_info() - Emit a structured SIGID error log entry on the component behalf.
171  * @any: the &xe_device or &xe_tile or &xe_gt pointer this report relates to
172  * @TAG: the component tag to use
173  * @err: negative errno for the failing operation, or 0 if not applicable
174  * @fmt: printf-style free text format string (not a stable interface)
175  * @args: arguments for the @fmt format string
176  *
177  * The log entry will be emitted with @CPER_SEV_INFORMATIONAL severity.
178  */
179 #define xe_log_err_info(any, TAG, err, fmt, args...) \
180 	xe_log_comp_info((any), TAG, ERR_PTR(err), 0, fmt, ##args)
181 
182 /**
183  * xe_log_info() - Emit a structured SIGID information log entry on the component behalf.
184  * @any: the &xe_device or &xe_tile or &xe_gt pointer this report relates to
185  * @TAG: the component tag to use
186  * @fmt: printf-style free text format string (not a stable interface)
187  * @args: arguments for the @fmt format string
188  *
189  * The log entry will be emitted with @CPER_SEV_INFORMATIONAL severity.
190  */
191 #define xe_log_info(any, TAG, fmt, args...) \
192 	xe_log_err_info((any), TAG, 0, fmt, ##args)
193 
194 #endif
195