1 /*
2  * Copyright (c) 2005-2011 Atheros Communications Inc.
3  * Copyright (c) 2011-2013 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)
25 {
26 	const struct ieee80211_hdr *hdr = buf;
27 
28 	return ieee80211_hdrlen(hdr->frame_control);
29 }
30 #endif
31 
32 #define _TRACE_H_
33 
34 /* create empty functions when tracing is disabled */
35 #if !defined(CONFIG_ATH10K_TRACING)
36 #undef TRACE_EVENT
37 #define TRACE_EVENT(name, proto, ...) \
38 static inline void trace_ ## name(proto) {}
39 #undef DECLARE_EVENT_CLASS
40 #define DECLARE_EVENT_CLASS(...)
41 #undef DEFINE_EVENT
42 #define DEFINE_EVENT(evt_class, name, proto, ...) \
43 static inline void trace_ ## name(proto) {}
44 #endif /* !CONFIG_ATH10K_TRACING || __CHECKER__ */
45 
46 #undef TRACE_SYSTEM
47 #define TRACE_SYSTEM ath10k
48 
49 #define ATH10K_MSG_MAX 200
50 
51 DECLARE_EVENT_CLASS(ath10k_log_event,
52 	TP_PROTO(struct ath10k *ar, struct va_format *vaf),
53 	TP_ARGS(ar, vaf),
54 	TP_STRUCT__entry(
55 		__string(device, dev_name(ar->dev))
56 		__string(driver, dev_driver_string(ar->dev))
57 		__dynamic_array(char, msg, ATH10K_MSG_MAX)
58 	),
59 	TP_fast_assign(
60 		__assign_str(device, dev_name(ar->dev));
61 		__assign_str(driver, dev_driver_string(ar->dev));
62 		WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg),
63 				       ATH10K_MSG_MAX,
64 				       vaf->fmt,
65 				       *vaf->va) >= ATH10K_MSG_MAX);
66 	),
67 	TP_printk(
68 		"%s %s %s",
69 		__get_str(driver),
70 		__get_str(device),
71 		__get_str(msg)
72 	)
73 );
74 
75 DEFINE_EVENT(ath10k_log_event, ath10k_log_err,
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_warn,
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_info,
86 	     TP_PROTO(struct ath10k *ar, struct va_format *vaf),
87 	     TP_ARGS(ar, vaf)
88 );
89 
90 TRACE_EVENT(ath10k_log_dbg,
91 	TP_PROTO(struct ath10k *ar, unsigned int level, struct va_format *vaf),
92 	TP_ARGS(ar, level, vaf),
93 	TP_STRUCT__entry(
94 		__string(device, dev_name(ar->dev))
95 		__string(driver, dev_driver_string(ar->dev))
96 		__field(unsigned int, level)
97 		__dynamic_array(char, msg, ATH10K_MSG_MAX)
98 	),
99 	TP_fast_assign(
100 		__assign_str(device, dev_name(ar->dev));
101 		__assign_str(driver, dev_driver_string(ar->dev));
102 		__entry->level = level;
103 		WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg),
104 				       ATH10K_MSG_MAX,
105 				       vaf->fmt,
106 				       *vaf->va) >= ATH10K_MSG_MAX);
107 	),
108 	TP_printk(
109 		"%s %s %s",
110 		__get_str(driver),
111 		__get_str(device),
112 		__get_str(msg)
113 	)
114 );
115 
116 TRACE_EVENT(ath10k_log_dbg_dump,
117 	TP_PROTO(struct ath10k *ar, const char *msg, const char *prefix,
118 		 const void *buf, size_t buf_len),
119 
120 	TP_ARGS(ar, msg, prefix, buf, buf_len),
121 
122 	TP_STRUCT__entry(
123 		__string(device, dev_name(ar->dev))
124 		__string(driver, dev_driver_string(ar->dev))
125 		__string(msg, msg)
126 		__string(prefix, prefix)
127 		__field(size_t, buf_len)
128 		__dynamic_array(u8, buf, buf_len)
129 	),
130 
131 	TP_fast_assign(
132 		__assign_str(device, dev_name(ar->dev));
133 		__assign_str(driver, dev_driver_string(ar->dev));
134 		__assign_str(msg, msg);
135 		__assign_str(prefix, prefix);
136 		__entry->buf_len = buf_len;
137 		memcpy(__get_dynamic_array(buf), buf, buf_len);
138 	),
139 
140 	TP_printk(
141 		"%s %s %s/%s\n",
142 		__get_str(driver),
143 		__get_str(device),
144 		__get_str(prefix),
145 		__get_str(msg)
146 	)
147 );
148 
149 TRACE_EVENT(ath10k_wmi_cmd,
150 	TP_PROTO(struct ath10k *ar, int id, const void *buf, size_t buf_len,
151 		 int ret),
152 
153 	TP_ARGS(ar, id, buf, buf_len, ret),
154 
155 	TP_STRUCT__entry(
156 		__string(device, dev_name(ar->dev))
157 		__string(driver, dev_driver_string(ar->dev))
158 		__field(unsigned int, id)
159 		__field(size_t, buf_len)
160 		__dynamic_array(u8, buf, buf_len)
161 		__field(int, ret)
162 	),
163 
164 	TP_fast_assign(
165 		__assign_str(device, dev_name(ar->dev));
166 		__assign_str(driver, dev_driver_string(ar->dev));
167 		__entry->id = id;
168 		__entry->buf_len = buf_len;
169 		__entry->ret = ret;
170 		memcpy(__get_dynamic_array(buf), buf, buf_len);
171 	),
172 
173 	TP_printk(
174 		"%s %s id %d len %zu ret %d",
175 		__get_str(driver),
176 		__get_str(device),
177 		__entry->id,
178 		__entry->buf_len,
179 		__entry->ret
180 	)
181 );
182 
183 TRACE_EVENT(ath10k_wmi_event,
184 	TP_PROTO(struct ath10k *ar, int id, const void *buf, size_t buf_len),
185 
186 	TP_ARGS(ar, id, buf, buf_len),
187 
188 	TP_STRUCT__entry(
189 		__string(device, dev_name(ar->dev))
190 		__string(driver, dev_driver_string(ar->dev))
191 		__field(unsigned int, id)
192 		__field(size_t, buf_len)
193 		__dynamic_array(u8, buf, buf_len)
194 	),
195 
196 	TP_fast_assign(
197 		__assign_str(device, dev_name(ar->dev));
198 		__assign_str(driver, dev_driver_string(ar->dev));
199 		__entry->id = id;
200 		__entry->buf_len = buf_len;
201 		memcpy(__get_dynamic_array(buf), buf, buf_len);
202 	),
203 
204 	TP_printk(
205 		"%s %s id %d len %zu",
206 		__get_str(driver),
207 		__get_str(device),
208 		__entry->id,
209 		__entry->buf_len
210 	)
211 );
212 
213 TRACE_EVENT(ath10k_htt_stats,
214 	TP_PROTO(struct ath10k *ar, const void *buf, size_t buf_len),
215 
216 	TP_ARGS(ar, buf, buf_len),
217 
218 	TP_STRUCT__entry(
219 		__string(device, dev_name(ar->dev))
220 		__string(driver, dev_driver_string(ar->dev))
221 		__field(size_t, buf_len)
222 		__dynamic_array(u8, buf, buf_len)
223 	),
224 
225 	TP_fast_assign(
226 		__assign_str(device, dev_name(ar->dev));
227 		__assign_str(driver, dev_driver_string(ar->dev));
228 		__entry->buf_len = buf_len;
229 		memcpy(__get_dynamic_array(buf), buf, buf_len);
230 	),
231 
232 	TP_printk(
233 		"%s %s len %zu",
234 		__get_str(driver),
235 		__get_str(device),
236 		__entry->buf_len
237 	)
238 );
239 
240 TRACE_EVENT(ath10k_wmi_dbglog,
241 	TP_PROTO(struct ath10k *ar, const void *buf, size_t buf_len),
242 
243 	TP_ARGS(ar, buf, buf_len),
244 
245 	TP_STRUCT__entry(
246 		__string(device, dev_name(ar->dev))
247 		__string(driver, dev_driver_string(ar->dev))
248 		__field(size_t, buf_len)
249 		__dynamic_array(u8, buf, buf_len)
250 	),
251 
252 	TP_fast_assign(
253 		__assign_str(device, dev_name(ar->dev));
254 		__assign_str(driver, dev_driver_string(ar->dev));
255 		__entry->buf_len = buf_len;
256 		memcpy(__get_dynamic_array(buf), buf, buf_len);
257 	),
258 
259 	TP_printk(
260 		"%s %s len %zu",
261 		__get_str(driver),
262 		__get_str(device),
263 		__entry->buf_len
264 	)
265 );
266 
267 TRACE_EVENT(ath10k_htt_pktlog,
268 	    TP_PROTO(struct ath10k *ar, const void *buf, u16 buf_len),
269 
270 	TP_ARGS(ar, buf, buf_len),
271 
272 	TP_STRUCT__entry(
273 		__string(device, dev_name(ar->dev))
274 		__string(driver, dev_driver_string(ar->dev))
275 		__field(u16, buf_len)
276 		__dynamic_array(u8, pktlog, buf_len)
277 	),
278 
279 	TP_fast_assign(
280 		__assign_str(device, dev_name(ar->dev));
281 		__assign_str(driver, dev_driver_string(ar->dev));
282 		__entry->buf_len = buf_len;
283 		memcpy(__get_dynamic_array(pktlog), buf, buf_len);
284 	),
285 
286 	TP_printk(
287 		"%s %s size %hu",
288 		__get_str(driver),
289 		__get_str(device),
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))
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);
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 - ath10k_frm_hdr_len(data)))
391 	),
392 
393 	TP_fast_assign(
394 		__assign_str(device, dev_name(ar->dev));
395 		__assign_str(driver, dev_driver_string(ar->dev));
396 		__entry->len = len - ath10k_frm_hdr_len(data);
397 		memcpy(__get_dynamic_array(payload),
398 		       data + ath10k_frm_hdr_len(data), __entry->len);
399 	),
400 
401 	TP_printk(
402 		"%s %s len %zu\n",
403 		__get_str(driver),
404 		__get_str(device),
405 		__entry->len
406 	)
407 );
408 
409 DEFINE_EVENT(ath10k_hdr_event, ath10k_tx_hdr,
410 	     TP_PROTO(struct ath10k *ar, const void *data, size_t len),
411 	     TP_ARGS(ar, data, len)
412 );
413 
414 DEFINE_EVENT(ath10k_payload_event, ath10k_tx_payload,
415 	     TP_PROTO(struct ath10k *ar, const void *data, size_t len),
416 	     TP_ARGS(ar, data, len)
417 );
418 
419 DEFINE_EVENT(ath10k_hdr_event, ath10k_rx_hdr,
420 	     TP_PROTO(struct ath10k *ar, const void *data, size_t len),
421 	     TP_ARGS(ar, data, len)
422 );
423 
424 DEFINE_EVENT(ath10k_payload_event, ath10k_rx_payload,
425 	     TP_PROTO(struct ath10k *ar, const void *data, size_t len),
426 	     TP_ARGS(ar, data, len)
427 );
428 
429 TRACE_EVENT(ath10k_htt_rx_desc,
430 	    TP_PROTO(struct ath10k *ar, const void *data, size_t len),
431 
432 	TP_ARGS(ar, data, len),
433 
434 	TP_STRUCT__entry(
435 		__string(device, dev_name(ar->dev))
436 		__string(driver, dev_driver_string(ar->dev))
437 		__field(u16, len)
438 		__dynamic_array(u8, rxdesc, len)
439 	),
440 
441 	TP_fast_assign(
442 		__assign_str(device, dev_name(ar->dev));
443 		__assign_str(driver, dev_driver_string(ar->dev));
444 		__entry->len = len;
445 		memcpy(__get_dynamic_array(rxdesc), data, len);
446 	),
447 
448 	TP_printk(
449 		"%s %s rxdesc len %d",
450 		__get_str(driver),
451 		__get_str(device),
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