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