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