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