xref: /linux/drivers/ufs/core/ufs_trace.h (revision 566ab427f827b0256d3e8ce0235d088e6a9c28bd)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
4  */
5 
6 #undef TRACE_SYSTEM
7 #define TRACE_SYSTEM ufs
8 
9 #if !defined(_TRACE_UFS_H) || defined(TRACE_HEADER_MULTI_READ)
10 #define _TRACE_UFS_H
11 
12 #include <ufs/ufs.h>
13 #include <linux/tracepoint.h>
14 
15 #define str_opcode(opcode)						\
16 	__print_symbolic(opcode,					\
17 		{ WRITE_16,		"WRITE_16" },			\
18 		{ WRITE_10,		"WRITE_10" },			\
19 		{ READ_16,		"READ_16" },			\
20 		{ READ_10,		"READ_10" },			\
21 		{ SYNCHRONIZE_CACHE,	"SYNC" },			\
22 		{ UNMAP,		"UNMAP" })
23 
24 #define UFS_LINK_STATES						\
25 	EM(UIC_LINK_OFF_STATE,		"UIC_LINK_OFF_STATE")		\
26 	EM(UIC_LINK_ACTIVE_STATE,	"UIC_LINK_ACTIVE_STATE")	\
27 	EMe(UIC_LINK_HIBERN8_STATE,	"UIC_LINK_HIBERN8_STATE")
28 
29 #define UFS_PWR_MODES							\
30 	EM(UFS_ACTIVE_PWR_MODE,		"UFS_ACTIVE_PWR_MODE")		\
31 	EM(UFS_SLEEP_PWR_MODE,		"UFS_SLEEP_PWR_MODE")		\
32 	EM(UFS_POWERDOWN_PWR_MODE,	"UFS_POWERDOWN_PWR_MODE")	\
33 	EMe(UFS_DEEPSLEEP_PWR_MODE,	"UFS_DEEPSLEEP_PWR_MODE")
34 
35 #define UFSCHD_CLK_GATING_STATES				\
36 	EM(CLKS_OFF,			"CLKS_OFF")		\
37 	EM(CLKS_ON,			"CLKS_ON")		\
38 	EM(REQ_CLKS_OFF,		"REQ_CLKS_OFF")		\
39 	EMe(REQ_CLKS_ON,		"REQ_CLKS_ON")
40 
41 #define UFS_CMD_TRACE_STRINGS					\
42 	EM(UFS_CMD_SEND,	"send_req")			\
43 	EM(UFS_CMD_COMP,	"complete_rsp")			\
44 	EM(UFS_DEV_COMP,	"dev_complete")			\
45 	EM(UFS_QUERY_SEND,	"query_send")			\
46 	EM(UFS_QUERY_COMP,	"query_complete")		\
47 	EM(UFS_QUERY_ERR,	"query_complete_err")		\
48 	EM(UFS_TM_SEND,		"tm_send")			\
49 	EM(UFS_TM_COMP,		"tm_complete")			\
50 	EMe(UFS_TM_ERR,		"tm_complete_err")
51 
52 #define UFS_CMD_TRACE_TSF_TYPES					\
53 	EM(UFS_TSF_CDB,		"CDB")		                \
54 	EM(UFS_TSF_OSF,		"OSF")		                \
55 	EM(UFS_TSF_TM_INPUT,	"TM_INPUT")                     \
56 	EMe(UFS_TSF_TM_OUTPUT,	"TM_OUTPUT")
57 
58 /* Enums require being exported to userspace, for user tool parsing */
59 #undef EM
60 #undef EMe
61 #define EM(a, b)	TRACE_DEFINE_ENUM(a);
62 #define EMe(a, b)	TRACE_DEFINE_ENUM(a);
63 
64 UFS_LINK_STATES;
65 UFS_PWR_MODES;
66 UFSCHD_CLK_GATING_STATES;
67 UFS_CMD_TRACE_STRINGS
68 UFS_CMD_TRACE_TSF_TYPES
69 
70 /*
71  * Now redefine the EM() and EMe() macros to map the enums to the strings
72  * that will be printed in the output.
73  */
74 #undef EM
75 #undef EMe
76 #define EM(a, b)	{a, b},
77 #define EMe(a, b)	{a, b}
78 
79 #define show_ufs_cmd_trace_str(str_t)	\
80 				__print_symbolic(str_t, UFS_CMD_TRACE_STRINGS)
81 #define show_ufs_cmd_trace_tsf(tsf)	\
82 				__print_symbolic(tsf, UFS_CMD_TRACE_TSF_TYPES)
83 
84 TRACE_EVENT(ufshcd_clk_gating,
85 
86 	TP_PROTO(const char *dev_name, int state),
87 
88 	TP_ARGS(dev_name, state),
89 
90 	TP_STRUCT__entry(
91 		__string(dev_name, dev_name)
92 		__field(int, state)
93 	),
94 
95 	TP_fast_assign(
96 		__assign_str(dev_name);
97 		__entry->state = state;
98 	),
99 
100 	TP_printk("%s: gating state changed to %s",
101 		__get_str(dev_name),
102 		__print_symbolic(__entry->state, UFSCHD_CLK_GATING_STATES))
103 );
104 
105 TRACE_EVENT(ufshcd_clk_scaling,
106 
107 	TP_PROTO(const char *dev_name, const char *state, const char *clk,
108 		u32 prev_state, u32 curr_state),
109 
110 	TP_ARGS(dev_name, state, clk, prev_state, curr_state),
111 
112 	TP_STRUCT__entry(
113 		__string(dev_name, dev_name)
114 		__string(state, state)
115 		__string(clk, clk)
116 		__field(u32, prev_state)
117 		__field(u32, curr_state)
118 	),
119 
120 	TP_fast_assign(
121 		__assign_str(dev_name);
122 		__assign_str(state);
123 		__assign_str(clk);
124 		__entry->prev_state = prev_state;
125 		__entry->curr_state = curr_state;
126 	),
127 
128 	TP_printk("%s: %s %s from %u to %u Hz",
129 		__get_str(dev_name), __get_str(state), __get_str(clk),
130 		__entry->prev_state, __entry->curr_state)
131 );
132 
133 TRACE_EVENT(ufshcd_auto_bkops_state,
134 
135 	TP_PROTO(const char *dev_name, const char *state),
136 
137 	TP_ARGS(dev_name, state),
138 
139 	TP_STRUCT__entry(
140 		__string(dev_name, dev_name)
141 		__string(state, state)
142 	),
143 
144 	TP_fast_assign(
145 		__assign_str(dev_name);
146 		__assign_str(state);
147 	),
148 
149 	TP_printk("%s: auto bkops - %s",
150 		__get_str(dev_name), __get_str(state))
151 );
152 
153 DECLARE_EVENT_CLASS(ufshcd_profiling_template,
154 	TP_PROTO(const char *dev_name, const char *profile_info, s64 time_us,
155 		 int err),
156 
157 	TP_ARGS(dev_name, profile_info, time_us, err),
158 
159 	TP_STRUCT__entry(
160 		__string(dev_name, dev_name)
161 		__string(profile_info, profile_info)
162 		__field(s64, time_us)
163 		__field(int, err)
164 	),
165 
166 	TP_fast_assign(
167 		__assign_str(dev_name);
168 		__assign_str(profile_info);
169 		__entry->time_us = time_us;
170 		__entry->err = err;
171 	),
172 
173 	TP_printk("%s: %s: took %lld usecs, err %d",
174 		__get_str(dev_name), __get_str(profile_info),
175 		__entry->time_us, __entry->err)
176 );
177 
178 DEFINE_EVENT(ufshcd_profiling_template, ufshcd_profile_hibern8,
179 	TP_PROTO(const char *dev_name, const char *profile_info, s64 time_us,
180 		 int err),
181 	TP_ARGS(dev_name, profile_info, time_us, err));
182 
183 DEFINE_EVENT(ufshcd_profiling_template, ufshcd_profile_clk_gating,
184 	TP_PROTO(const char *dev_name, const char *profile_info, s64 time_us,
185 		 int err),
186 	TP_ARGS(dev_name, profile_info, time_us, err));
187 
188 DEFINE_EVENT(ufshcd_profiling_template, ufshcd_profile_clk_scaling,
189 	TP_PROTO(const char *dev_name, const char *profile_info, s64 time_us,
190 		 int err),
191 	TP_ARGS(dev_name, profile_info, time_us, err));
192 
193 DECLARE_EVENT_CLASS(ufshcd_template,
194 	TP_PROTO(const char *dev_name, int err, s64 usecs,
195 		 int dev_state, int link_state),
196 
197 	TP_ARGS(dev_name, err, usecs, dev_state, link_state),
198 
199 	TP_STRUCT__entry(
200 		__field(s64, usecs)
201 		__field(int, err)
202 		__string(dev_name, dev_name)
203 		__field(int, dev_state)
204 		__field(int, link_state)
205 	),
206 
207 	TP_fast_assign(
208 		__entry->usecs = usecs;
209 		__entry->err = err;
210 		__assign_str(dev_name);
211 		__entry->dev_state = dev_state;
212 		__entry->link_state = link_state;
213 	),
214 
215 	TP_printk(
216 		"%s: took %lld usecs, dev_state: %s, link_state: %s, err %d",
217 		__get_str(dev_name),
218 		__entry->usecs,
219 		__print_symbolic(__entry->dev_state, UFS_PWR_MODES),
220 		__print_symbolic(__entry->link_state, UFS_LINK_STATES),
221 		__entry->err
222 	)
223 );
224 
225 DEFINE_EVENT(ufshcd_template, ufshcd_system_suspend,
226 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
227 		      int dev_state, int link_state),
228 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
229 
230 DEFINE_EVENT(ufshcd_template, ufshcd_system_resume,
231 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
232 		      int dev_state, int link_state),
233 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
234 
235 DEFINE_EVENT(ufshcd_template, ufshcd_runtime_suspend,
236 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
237 		      int dev_state, int link_state),
238 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
239 
240 DEFINE_EVENT(ufshcd_template, ufshcd_runtime_resume,
241 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
242 		      int dev_state, int link_state),
243 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
244 
245 DEFINE_EVENT(ufshcd_template, ufshcd_init,
246 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
247 		      int dev_state, int link_state),
248 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
249 
250 DEFINE_EVENT(ufshcd_template, ufshcd_wl_suspend,
251 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
252 		      int dev_state, int link_state),
253 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
254 
255 DEFINE_EVENT(ufshcd_template, ufshcd_wl_resume,
256 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
257 		      int dev_state, int link_state),
258 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
259 
260 DEFINE_EVENT(ufshcd_template, ufshcd_wl_runtime_suspend,
261 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
262 		      int dev_state, int link_state),
263 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
264 
265 DEFINE_EVENT(ufshcd_template, ufshcd_wl_runtime_resume,
266 	     TP_PROTO(const char *dev_name, int err, s64 usecs,
267 		      int dev_state, int link_state),
268 	     TP_ARGS(dev_name, err, usecs, dev_state, link_state));
269 
270 TRACE_EVENT(ufshcd_command,
271 	TP_PROTO(struct scsi_device *sdev, enum ufs_trace_str_t str_t,
272 		 unsigned int tag, u32 doorbell, u32 hwq_id, int transfer_len,
273 		 u32 intr, u64 lba, u8 opcode, u8 group_id),
274 
275 	TP_ARGS(sdev, str_t, tag, doorbell, hwq_id, transfer_len, intr, lba,
276 		opcode, group_id),
277 
278 	TP_STRUCT__entry(
279 		__field(struct scsi_device *, sdev)
280 		__field(enum ufs_trace_str_t, str_t)
281 		__field(unsigned int, tag)
282 		__field(u32, doorbell)
283 		__field(u32, hwq_id)
284 		__field(u32, intr)
285 		__field(u64, lba)
286 		__field(int, transfer_len)
287 		__field(u8, opcode)
288 		__field(u8, group_id)
289 	),
290 
291 	TP_fast_assign(
292 		__entry->sdev = sdev;
293 		__entry->str_t = str_t;
294 		__entry->tag = tag;
295 		__entry->doorbell = doorbell;
296 		__entry->hwq_id = hwq_id;
297 		__entry->intr = intr;
298 		__entry->lba = lba;
299 		__entry->transfer_len = transfer_len;
300 		__entry->opcode = opcode;
301 		__entry->group_id = group_id;
302 	),
303 
304 	TP_printk(
305 		"%s: %s: tag: %u, DB: 0x%x, size: %d, IS: %u, LBA: %llu, opcode: 0x%x (%s), group_id: 0x%x, hwq_id: %d",
306 		show_ufs_cmd_trace_str(__entry->str_t),
307 		dev_name(&__entry->sdev->sdev_dev), __entry->tag,
308 		__entry->doorbell, __entry->transfer_len, __entry->intr,
309 		__entry->lba, (u32)__entry->opcode, str_opcode(__entry->opcode),
310 		(u32)__entry->group_id, __entry->hwq_id
311 	)
312 );
313 
314 TRACE_EVENT(ufshcd_uic_command,
315 	TP_PROTO(const char *dev_name, enum ufs_trace_str_t str_t, u32 cmd,
316 		 u32 arg1, u32 arg2, u32 arg3),
317 
318 	TP_ARGS(dev_name, str_t, cmd, arg1, arg2, arg3),
319 
320 	TP_STRUCT__entry(
321 		__string(dev_name, dev_name)
322 		__field(enum ufs_trace_str_t, str_t)
323 		__field(u32, cmd)
324 		__field(u32, arg1)
325 		__field(u32, arg2)
326 		__field(u32, arg3)
327 	),
328 
329 	TP_fast_assign(
330 		__assign_str(dev_name);
331 		__entry->str_t = str_t;
332 		__entry->cmd = cmd;
333 		__entry->arg1 = arg1;
334 		__entry->arg2 = arg2;
335 		__entry->arg3 = arg3;
336 	),
337 
338 	TP_printk(
339 		"%s: %s: cmd: 0x%x, arg1: 0x%x, arg2: 0x%x, arg3: 0x%x",
340 		show_ufs_cmd_trace_str(__entry->str_t), __get_str(dev_name),
341 		__entry->cmd, __entry->arg1, __entry->arg2, __entry->arg3
342 	)
343 );
344 
345 TRACE_EVENT(ufshcd_upiu,
346 	TP_PROTO(const char *dev_name, enum ufs_trace_str_t str_t, void *hdr,
347 		 void *tsf, enum ufs_trace_tsf_t tsf_t),
348 
349 	TP_ARGS(dev_name, str_t, hdr, tsf, tsf_t),
350 
351 	TP_STRUCT__entry(
352 		__string(dev_name, dev_name)
353 		__field(enum ufs_trace_str_t, str_t)
354 		__array(unsigned char, hdr, 12)
355 		__array(unsigned char, tsf, 16)
356 		__field(enum ufs_trace_tsf_t, tsf_t)
357 	),
358 
359 	TP_fast_assign(
360 		__assign_str(dev_name);
361 		__entry->str_t = str_t;
362 		memcpy(__entry->hdr, hdr, sizeof(__entry->hdr));
363 		memcpy(__entry->tsf, tsf, sizeof(__entry->tsf));
364 		__entry->tsf_t = tsf_t;
365 	),
366 
367 	TP_printk(
368 		"%s: %s: HDR:%s, %s:%s",
369 		show_ufs_cmd_trace_str(__entry->str_t), __get_str(dev_name),
370 		__print_hex(__entry->hdr, sizeof(__entry->hdr)),
371 		show_ufs_cmd_trace_tsf(__entry->tsf_t),
372 		__print_hex(__entry->tsf, sizeof(__entry->tsf))
373 	)
374 );
375 
376 TRACE_EVENT(ufshcd_exception_event,
377 
378 	TP_PROTO(const char *dev_name, u16 status),
379 
380 	TP_ARGS(dev_name, status),
381 
382 	TP_STRUCT__entry(
383 		__string(dev_name, dev_name)
384 		__field(u16, status)
385 	),
386 
387 	TP_fast_assign(
388 		__assign_str(dev_name);
389 		__entry->status = status;
390 	),
391 
392 	TP_printk("%s: status 0x%x",
393 		__get_str(dev_name), __entry->status
394 	)
395 );
396 
397 #endif /* if !defined(_TRACE_UFS_H) || defined(TRACE_HEADER_MULTI_READ) */
398 
399 #undef TRACE_INCLUDE_PATH
400 #define TRACE_INCLUDE_PATH ../../drivers/ufs/core
401 #undef TRACE_INCLUDE_FILE
402 #define TRACE_INCLUDE_FILE ufs_trace
403 
404 /* This part must be outside protection */
405 #include <trace/define_trace.h>
406