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