1 /* SPDX-License-Identifier: ISC */
2 /*
3  * Copyright (c) 2005-2011 Atheros Communications Inc.
4  * Copyright (c) 2011-2016 Qualcomm Atheros, Inc.
5  */
6 
7 #if !defined(_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
8 
9 #include <linux/tracepoint.h>
10 #include "core.h"
11 
12 #if !defined(_TRACE_H_)
13 static inline u32 ath10k_frm_hdr_len(const void *buf, size_t len)
14 {
15 	const struct ieee80211_hdr *hdr = buf;
16 
17 	/* In some rare cases (e.g. fcs error) device reports frame buffer
18 	 * shorter than what frame header implies (e.g. len = 0). The buffer
19 	 * can still be accessed so do a simple min() to guarantee caller
20 	 * doesn't get value greater than len.
21 	 */
22 	return min_t(u32, len, ieee80211_hdrlen(hdr->frame_control));
23 }
24 #endif
25 
26 #define _TRACE_H_
27 
28 /* create empty functions when tracing is disabled */
29 #if !defined(CONFIG_ATH10K_TRACING)
30 #undef TRACE_EVENT
31 #define TRACE_EVENT(name, proto, ...) \
32 static inline void trace_ ## name(proto) {} \
33 static inline bool trace_##name##_enabled(void) \
34 {						\
35 	return false;				\
36 }
37 #undef DECLARE_EVENT_CLASS
38 #define DECLARE_EVENT_CLASS(...)
39 #undef DEFINE_EVENT
40 #define DEFINE_EVENT(evt_class, name, proto, ...) \
41 static inline void trace_ ## name(proto) {}
42 #endif /* !CONFIG_ATH10K_TRACING || __CHECKER__ */
43 
44 #undef TRACE_SYSTEM
45 #define TRACE_SYSTEM ath10k
46 
47 #define ATH10K_MSG_MAX 400
48 
49 DECLARE_EVENT_CLASS(ath10k_log_event,
50 	TP_PROTO(struct ath10k *ar, struct va_format *vaf),
51 	TP_ARGS(ar, vaf),
52 	TP_STRUCT__entry(
53 		__string(device, dev_name(ar->dev))
54 		__string(driver, dev_driver_string(ar->dev))
55 		__dynamic_array(char, msg, ATH10K_MSG_MAX)
56 	),
57 	TP_fast_assign(
58 		__assign_str(device, dev_name(ar->dev));
59 		__assign_str(driver, dev_driver_string(ar->dev));
60 		WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg),
61 				       ATH10K_MSG_MAX,
62 				       vaf->fmt,
63 				       *vaf->va) >= ATH10K_MSG_MAX);
64 	),
65 	TP_printk(
66 		"%s %s %s",
67 		__get_str(driver),
68 		__get_str(device),
69 		__get_str(msg)
70 	)
71 );
72 
73 DEFINE_EVENT(ath10k_log_event, ath10k_log_err,
74 	     TP_PROTO(struct ath10k *ar, struct va_format *vaf),
75 	     TP_ARGS(ar, vaf)
76 );
77 
78 DEFINE_EVENT(ath10k_log_event, ath10k_log_warn,
79 	     TP_PROTO(struct ath10k *ar, struct va_format *vaf),
80 	     TP_ARGS(ar, vaf)
81 );
82 
83 DEFINE_EVENT(ath10k_log_event, ath10k_log_info,
84 	     TP_PROTO(struct ath10k *ar, struct va_format *vaf),
85 	     TP_ARGS(ar, vaf)
86 );
87 
88 TRACE_EVENT(ath10k_log_dbg,
89 	TP_PROTO(struct ath10k *ar, unsigned int level, struct va_format *vaf),
90 	TP_ARGS(ar, level, vaf),
91 	TP_STRUCT__entry(
92 		__string(device, dev_name(ar->dev))
93 		__string(driver, dev_driver_string(ar->dev))
94 		__field(unsigned int, level)
95 		__dynamic_array(char, msg, ATH10K_MSG_MAX)
96 	),
97 	TP_fast_assign(
98 		__assign_str(device, dev_name(ar->dev));
99 		__assign_str(driver, dev_driver_string(ar->dev));
100 		__entry->level = level;
101 		WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg),
102 				       ATH10K_MSG_MAX,
103 				       vaf->fmt,
104 				       *vaf->va) >= ATH10K_MSG_MAX);
105 	),
106 	TP_printk(
107 		"%s %s %s",
108 		__get_str(driver),
109 		__get_str(device),
110 		__get_str(msg)
111 	)
112 );
113 
114 TRACE_EVENT(ath10k_log_dbg_dump,
115 	TP_PROTO(struct ath10k *ar, const char *msg, const char *prefix,
116 		 const void *buf, size_t buf_len),
117 
118 	TP_ARGS(ar, msg, prefix, buf, buf_len),
119 
120 	TP_STRUCT__entry(
121 		__string(device, dev_name(ar->dev))
122 		__string(driver, dev_driver_string(ar->dev))
123 		__string(msg, msg)
124 		__string(prefix, prefix)
125 		__field(size_t, buf_len)
126 		__dynamic_array(u8, buf, buf_len)
127 	),
128 
129 	TP_fast_assign(
130 		__assign_str(device, dev_name(ar->dev));
131 		__assign_str(driver, dev_driver_string(ar->dev));
132 		__assign_str(msg, msg);
133 		__assign_str(prefix, prefix);
134 		__entry->buf_len = buf_len;
135 		memcpy(__get_dynamic_array(buf), buf, buf_len);
136 	),
137 
138 	TP_printk(
139 		"%s %s %s/%s\n",
140 		__get_str(driver),
141 		__get_str(device),
142 		__get_str(prefix),
143 		__get_str(msg)
144 	)
145 );
146 
147 TRACE_EVENT(ath10k_wmi_cmd,
148 	TP_PROTO(struct ath10k *ar, int id, const void *buf, size_t buf_len),
149 
150 	TP_ARGS(ar, id, buf, buf_len),
151 
152 	TP_STRUCT__entry(
153 		__string(device, dev_name(ar->dev))
154 		__string(driver, dev_driver_string(ar->dev))
155 		__field(unsigned int, id)
156 		__field(size_t, buf_len)
157 		__dynamic_array(u8, buf, buf_len)
158 	),
159 
160 	TP_fast_assign(
161 		__assign_str(device, dev_name(ar->dev));
162 		__assign_str(driver, dev_driver_string(ar->dev));
163 		__entry->id = id;
164 		__entry->buf_len = buf_len;
165 		memcpy(__get_dynamic_array(buf), buf, buf_len);
166 	),
167 
168 	TP_printk(
169 		"%s %s id %d len %zu",
170 		__get_str(driver),
171 		__get_str(device),
172 		__entry->id,
173 		__entry->buf_len
174 	)
175 );
176 
177 TRACE_EVENT(ath10k_wmi_event,
178 	TP_PROTO(struct ath10k *ar, int id, const void *buf, size_t buf_len),
179 
180 	TP_ARGS(ar, id, buf, buf_len),
181 
182 	TP_STRUCT__entry(
183 		__string(device, dev_name(ar->dev))
184 		__string(driver, dev_driver_string(ar->dev))
185 		__field(unsigned int, id)
186 		__field(size_t, buf_len)
187 		__dynamic_array(u8, buf, buf_len)
188 	),
189 
190 	TP_fast_assign(
191 		__assign_str(device, dev_name(ar->dev));
192 		__assign_str(driver, dev_driver_string(ar->dev));
193 		__entry->id = id;
194 		__entry->buf_len = buf_len;
195 		memcpy(__get_dynamic_array(buf), buf, buf_len);
196 	),
197 
198 	TP_printk(
199 		"%s %s id %d len %zu",
200 		__get_str(driver),
201 		__get_str(device),
202 		__entry->id,
203 		__entry->buf_len
204 	)
205 );
206 
207 TRACE_EVENT(ath10k_htt_stats,
208 	TP_PROTO(struct ath10k *ar, const void *buf, size_t buf_len),
209 
210 	TP_ARGS(ar, buf, buf_len),
211 
212 	TP_STRUCT__entry(
213 		__string(device, dev_name(ar->dev))
214 		__string(driver, dev_driver_string(ar->dev))
215 		__field(size_t, buf_len)
216 		__dynamic_array(u8, buf, buf_len)
217 	),
218 
219 	TP_fast_assign(
220 		__assign_str(device, dev_name(ar->dev));
221 		__assign_str(driver, dev_driver_string(ar->dev));
222 		__entry->buf_len = buf_len;
223 		memcpy(__get_dynamic_array(buf), buf, buf_len);
224 	),
225 
226 	TP_printk(
227 		"%s %s len %zu",
228 		__get_str(driver),
229 		__get_str(device),
230 		__entry->buf_len
231 	)
232 );
233 
234 TRACE_EVENT(ath10k_wmi_dbglog,
235 	TP_PROTO(struct ath10k *ar, const void *buf, size_t buf_len),
236 
237 	TP_ARGS(ar, buf, buf_len),
238 
239 	TP_STRUCT__entry(
240 		__string(device, dev_name(ar->dev))
241 		__string(driver, dev_driver_string(ar->dev))
242 		__field(u8, hw_type)
243 		__field(size_t, buf_len)
244 		__dynamic_array(u8, buf, buf_len)
245 	),
246 
247 	TP_fast_assign(
248 		__assign_str(device, dev_name(ar->dev));
249 		__assign_str(driver, dev_driver_string(ar->dev));
250 		__entry->hw_type = ar->hw_rev;
251 		__entry->buf_len = buf_len;
252 		memcpy(__get_dynamic_array(buf), buf, buf_len);
253 	),
254 
255 	TP_printk(
256 		"%s %s %d len %zu",
257 		__get_str(driver),
258 		__get_str(device),
259 		__entry->hw_type,
260 		__entry->buf_len
261 	)
262 );
263 
264 TRACE_EVENT(ath10k_htt_pktlog,
265 	    TP_PROTO(struct ath10k *ar, const void *buf, u16 buf_len),
266 
267 	TP_ARGS(ar, buf, buf_len),
268 
269 	TP_STRUCT__entry(
270 		__string(device, dev_name(ar->dev))
271 		__string(driver, dev_driver_string(ar->dev))
272 		__field(u8, hw_type)
273 		__field(u16, buf_len)
274 		__dynamic_array(u8, pktlog, buf_len)
275 	),
276 
277 	TP_fast_assign(
278 		__assign_str(device, dev_name(ar->dev));
279 		__assign_str(driver, dev_driver_string(ar->dev));
280 		__entry->hw_type = ar->hw_rev;
281 		__entry->buf_len = buf_len;
282 		memcpy(__get_dynamic_array(pktlog), buf, buf_len);
283 	),
284 
285 	TP_printk(
286 		"%s %s %d size %hu",
287 		__get_str(driver),
288 		__get_str(device),
289 		__entry->hw_type,
290 		__entry->buf_len
291 	 )
292 );
293 
294 TRACE_EVENT(ath10k_htt_tx,
295 	    TP_PROTO(struct ath10k *ar, u16 msdu_id, u16 msdu_len,
296 		     u8 vdev_id, u8 tid),
297 
298 	TP_ARGS(ar, msdu_id, msdu_len, vdev_id, tid),
299 
300 	TP_STRUCT__entry(
301 		__string(device, dev_name(ar->dev))
302 		__string(driver, dev_driver_string(ar->dev))
303 		__field(u16, msdu_id)
304 		__field(u16, msdu_len)
305 		__field(u8, vdev_id)
306 		__field(u8, tid)
307 	),
308 
309 	TP_fast_assign(
310 		__assign_str(device, dev_name(ar->dev));
311 		__assign_str(driver, dev_driver_string(ar->dev));
312 		__entry->msdu_id = msdu_id;
313 		__entry->msdu_len = msdu_len;
314 		__entry->vdev_id = vdev_id;
315 		__entry->tid = tid;
316 	),
317 
318 	TP_printk(
319 		"%s %s msdu_id %d msdu_len %d vdev_id %d tid %d",
320 		__get_str(driver),
321 		__get_str(device),
322 		__entry->msdu_id,
323 		__entry->msdu_len,
324 		__entry->vdev_id,
325 		__entry->tid
326 	 )
327 );
328 
329 TRACE_EVENT(ath10k_txrx_tx_unref,
330 	    TP_PROTO(struct ath10k *ar, u16 msdu_id),
331 
332 	TP_ARGS(ar, msdu_id),
333 
334 	TP_STRUCT__entry(
335 		__string(device, dev_name(ar->dev))
336 		__string(driver, dev_driver_string(ar->dev))
337 		__field(u16, msdu_id)
338 	),
339 
340 	TP_fast_assign(
341 		__assign_str(device, dev_name(ar->dev));
342 		__assign_str(driver, dev_driver_string(ar->dev));
343 		__entry->msdu_id = msdu_id;
344 	),
345 
346 	TP_printk(
347 		"%s %s msdu_id %d",
348 		__get_str(driver),
349 		__get_str(device),
350 		__entry->msdu_id
351 	 )
352 );
353 
354 DECLARE_EVENT_CLASS(ath10k_hdr_event,
355 		    TP_PROTO(struct ath10k *ar, const void *data, size_t len),
356 
357 	TP_ARGS(ar, data, len),
358 
359 	TP_STRUCT__entry(
360 		__string(device, dev_name(ar->dev))
361 		__string(driver, dev_driver_string(ar->dev))
362 		__field(size_t, len)
363 		__dynamic_array(u8, data, ath10k_frm_hdr_len(data, len))
364 	),
365 
366 	TP_fast_assign(
367 		__assign_str(device, dev_name(ar->dev));
368 		__assign_str(driver, dev_driver_string(ar->dev));
369 		__entry->len = ath10k_frm_hdr_len(data, len);
370 		memcpy(__get_dynamic_array(data), data, __entry->len);
371 	),
372 
373 	TP_printk(
374 		"%s %s len %zu\n",
375 		__get_str(driver),
376 		__get_str(device),
377 		__entry->len
378 	)
379 );
380 
381 DECLARE_EVENT_CLASS(ath10k_payload_event,
382 		    TP_PROTO(struct ath10k *ar, const void *data, size_t len),
383 
384 	TP_ARGS(ar, data, len),
385 
386 	TP_STRUCT__entry(
387 		__string(device, dev_name(ar->dev))
388 		__string(driver, dev_driver_string(ar->dev))
389 		__field(size_t, len)
390 		__dynamic_array(u8, payload, (len -
391 					      ath10k_frm_hdr_len(data, len)))
392 	),
393 
394 	TP_fast_assign(
395 		__assign_str(device, dev_name(ar->dev));
396 		__assign_str(driver, dev_driver_string(ar->dev));
397 		__entry->len = len - ath10k_frm_hdr_len(data, len);
398 		memcpy(__get_dynamic_array(payload),
399 		       data + ath10k_frm_hdr_len(data, len), __entry->len);
400 	),
401 
402 	TP_printk(
403 		"%s %s len %zu\n",
404 		__get_str(driver),
405 		__get_str(device),
406 		__entry->len
407 	)
408 );
409 
410 DEFINE_EVENT(ath10k_hdr_event, ath10k_tx_hdr,
411 	     TP_PROTO(struct ath10k *ar, const void *data, size_t len),
412 	     TP_ARGS(ar, data, len)
413 );
414 
415 DEFINE_EVENT(ath10k_payload_event, ath10k_tx_payload,
416 	     TP_PROTO(struct ath10k *ar, const void *data, size_t len),
417 	     TP_ARGS(ar, data, len)
418 );
419 
420 DEFINE_EVENT(ath10k_hdr_event, ath10k_rx_hdr,
421 	     TP_PROTO(struct ath10k *ar, const void *data, size_t len),
422 	     TP_ARGS(ar, data, len)
423 );
424 
425 DEFINE_EVENT(ath10k_payload_event, ath10k_rx_payload,
426 	     TP_PROTO(struct ath10k *ar, const void *data, size_t len),
427 	     TP_ARGS(ar, data, len)
428 );
429 
430 TRACE_EVENT(ath10k_htt_rx_desc,
431 	    TP_PROTO(struct ath10k *ar, const void *data, size_t len),
432 
433 	TP_ARGS(ar, data, len),
434 
435 	TP_STRUCT__entry(
436 		__string(device, dev_name(ar->dev))
437 		__string(driver, dev_driver_string(ar->dev))
438 		__field(u8, hw_type)
439 		__field(u16, len)
440 		__dynamic_array(u8, rxdesc, len)
441 	),
442 
443 	TP_fast_assign(
444 		__assign_str(device, dev_name(ar->dev));
445 		__assign_str(driver, dev_driver_string(ar->dev));
446 		__entry->hw_type = ar->hw_rev;
447 		__entry->len = len;
448 		memcpy(__get_dynamic_array(rxdesc), data, len);
449 	),
450 
451 	TP_printk(
452 		"%s %s %d rxdesc len %d",
453 		__get_str(driver),
454 		__get_str(device),
455 		__entry->hw_type,
456 		__entry->len
457 	 )
458 );
459 
460 TRACE_EVENT(ath10k_wmi_diag_container,
461 	    TP_PROTO(struct ath10k *ar,
462 		     u8 type,
463 		     u32 timestamp,
464 		     u32 code,
465 		     u16 len,
466 		     const void *data),
467 
468 	TP_ARGS(ar, type, timestamp, code, len, data),
469 
470 	TP_STRUCT__entry(
471 		__string(device, dev_name(ar->dev))
472 		__string(driver, dev_driver_string(ar->dev))
473 		__field(u8, type)
474 		__field(u32, timestamp)
475 		__field(u32, code)
476 		__field(u16, len)
477 		__dynamic_array(u8, data, len)
478 	),
479 
480 	TP_fast_assign(
481 		__assign_str(device, dev_name(ar->dev));
482 		__assign_str(driver, dev_driver_string(ar->dev));
483 		__entry->type = type;
484 		__entry->timestamp = timestamp;
485 		__entry->code = code;
486 		__entry->len = len;
487 		memcpy(__get_dynamic_array(data), data, len);
488 	),
489 
490 	TP_printk(
491 		"%s %s diag container type %hhu timestamp %u code %u len %d",
492 		__get_str(driver),
493 		__get_str(device),
494 		__entry->type,
495 		__entry->timestamp,
496 		__entry->code,
497 		__entry->len
498 	)
499 );
500 
501 TRACE_EVENT(ath10k_wmi_diag,
502 	    TP_PROTO(struct ath10k *ar, const void *data, size_t len),
503 
504 	TP_ARGS(ar, data, len),
505 
506 	TP_STRUCT__entry(
507 		__string(device, dev_name(ar->dev))
508 		__string(driver, dev_driver_string(ar->dev))
509 		__field(u16, len)
510 		__dynamic_array(u8, data, len)
511 	),
512 
513 	TP_fast_assign(
514 		__assign_str(device, dev_name(ar->dev));
515 		__assign_str(driver, dev_driver_string(ar->dev));
516 		__entry->len = len;
517 		memcpy(__get_dynamic_array(data), data, len);
518 	),
519 
520 	TP_printk(
521 		"%s %s tlv diag len %d",
522 		__get_str(driver),
523 		__get_str(device),
524 		__entry->len
525 	)
526 );
527 
528 #endif /* _TRACE_H_ || TRACE_HEADER_MULTI_READ*/
529 
530 /* we don't want to use include/trace/events */
531 #undef TRACE_INCLUDE_PATH
532 #define TRACE_INCLUDE_PATH .
533 #undef TRACE_INCLUDE_FILE
534 #define TRACE_INCLUDE_FILE trace
535 
536 /* This part must be outside protection */
537 #include <trace/define_trace.h>
538