1 /* SPDX-License-Identifier: ISC */
2 #if !defined(_ATH6KL_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
3 
4 #include <net/cfg80211.h>
5 #include <linux/skbuff.h>
6 #include <linux/tracepoint.h>
7 #include "wmi.h"
8 #include "hif.h"
9 
10 #if !defined(_ATH6KL_TRACE_H)
11 static inline unsigned int ath6kl_get_wmi_id(void *buf, size_t buf_len)
12 {
13 	struct wmi_cmd_hdr *hdr = buf;
14 
15 	if (buf_len < sizeof(*hdr))
16 		return 0;
17 
18 	return le16_to_cpu(hdr->cmd_id);
19 }
20 #endif /* __ATH6KL_TRACE_H */
21 
22 #define _ATH6KL_TRACE_H
23 
24 /* create empty functions when tracing is disabled */
25 #if !defined(CONFIG_ATH6KL_TRACING)
26 #undef TRACE_EVENT
27 #define TRACE_EVENT(name, proto, ...) \
28 static inline void trace_ ## name(proto) {}
29 #undef DECLARE_EVENT_CLASS
30 #define DECLARE_EVENT_CLASS(...)
31 #undef DEFINE_EVENT
32 #define DEFINE_EVENT(evt_class, name, proto, ...) \
33 static inline void trace_ ## name(proto) {}
34 #endif /* !CONFIG_ATH6KL_TRACING || __CHECKER__ */
35 
36 #undef TRACE_SYSTEM
37 #define TRACE_SYSTEM ath6kl
38 
39 TRACE_EVENT(ath6kl_wmi_cmd,
40 	TP_PROTO(void *buf, size_t buf_len),
41 
42 	TP_ARGS(buf, buf_len),
43 
44 	TP_STRUCT__entry(
45 		__field(unsigned int, id)
46 		__field(size_t, buf_len)
47 		__dynamic_array(u8, buf, buf_len)
48 	),
49 
50 	TP_fast_assign(
51 		__entry->id = ath6kl_get_wmi_id(buf, buf_len);
52 		__entry->buf_len = buf_len;
53 		memcpy(__get_dynamic_array(buf), buf, buf_len);
54 	),
55 
56 	TP_printk(
57 		"id %d len %zd",
58 		__entry->id, __entry->buf_len
59 	)
60 );
61 
62 TRACE_EVENT(ath6kl_wmi_event,
63 	TP_PROTO(void *buf, size_t buf_len),
64 
65 	TP_ARGS(buf, buf_len),
66 
67 	TP_STRUCT__entry(
68 		__field(unsigned int, id)
69 		__field(size_t, buf_len)
70 		__dynamic_array(u8, buf, buf_len)
71 	),
72 
73 	TP_fast_assign(
74 		__entry->id = ath6kl_get_wmi_id(buf, buf_len);
75 		__entry->buf_len = buf_len;
76 		memcpy(__get_dynamic_array(buf), buf, buf_len);
77 	),
78 
79 	TP_printk(
80 		"id %d len %zd",
81 		__entry->id, __entry->buf_len
82 	)
83 );
84 
85 TRACE_EVENT(ath6kl_sdio,
86 	TP_PROTO(unsigned int addr, int flags,
87 		 void *buf, size_t buf_len),
88 
89 	TP_ARGS(addr, flags, buf, buf_len),
90 
91 	TP_STRUCT__entry(
92 		__field(unsigned int, tx)
93 		__field(unsigned int, addr)
94 		__field(int, flags)
95 		__field(size_t, buf_len)
96 		__dynamic_array(u8, buf, buf_len)
97 	),
98 
99 	TP_fast_assign(
100 		__entry->addr = addr;
101 		__entry->flags = flags;
102 		__entry->buf_len = buf_len;
103 		memcpy(__get_dynamic_array(buf), buf, buf_len);
104 
105 		if (flags & HIF_WRITE)
106 			__entry->tx = 1;
107 		else
108 			__entry->tx = 0;
109 	),
110 
111 	TP_printk(
112 		"%s addr 0x%x flags 0x%x len %zd\n",
113 		__entry->tx ? "tx" : "rx",
114 		__entry->addr,
115 		__entry->flags,
116 		__entry->buf_len
117 	)
118 );
119 
120 TRACE_EVENT(ath6kl_sdio_scat,
121 	TP_PROTO(unsigned int addr, int flags, unsigned int total_len,
122 		 unsigned int entries, struct hif_scatter_item *list),
123 
124 	TP_ARGS(addr, flags, total_len, entries, list),
125 
126 	TP_STRUCT__entry(
127 		__field(unsigned int, tx)
128 		__field(unsigned int, addr)
129 		__field(int, flags)
130 		__field(unsigned int, entries)
131 		__field(size_t, total_len)
132 		__dynamic_array(unsigned int, len_array, entries)
133 		__dynamic_array(u8, data, total_len)
134 	),
135 
136 	TP_fast_assign(
137 		unsigned int *len_array;
138 		int i, offset = 0;
139 		size_t len;
140 
141 		__entry->addr = addr;
142 		__entry->flags = flags;
143 		__entry->entries = entries;
144 		__entry->total_len = total_len;
145 
146 		if (flags & HIF_WRITE)
147 			__entry->tx = 1;
148 		else
149 			__entry->tx = 0;
150 
151 		len_array = __get_dynamic_array(len_array);
152 
153 		for (i = 0; i < entries; i++) {
154 			len = list[i].len;
155 
156 			memcpy((u8 *) __get_dynamic_array(data) + offset,
157 			       list[i].buf, len);
158 
159 			len_array[i] = len;
160 			offset += len;
161 		}
162 	),
163 
164 	TP_printk(
165 		"%s addr 0x%x flags 0x%x entries %d total_len %zd\n",
166 		__entry->tx ? "tx" : "rx",
167 		__entry->addr,
168 		__entry->flags,
169 		__entry->entries,
170 		__entry->total_len
171 	)
172 );
173 
174 TRACE_EVENT(ath6kl_sdio_irq,
175 	TP_PROTO(void *buf, size_t buf_len),
176 
177 	TP_ARGS(buf, buf_len),
178 
179 	TP_STRUCT__entry(
180 		__field(size_t, buf_len)
181 		__dynamic_array(u8, buf, buf_len)
182 	),
183 
184 	TP_fast_assign(
185 		__entry->buf_len = buf_len;
186 		memcpy(__get_dynamic_array(buf), buf, buf_len);
187 	),
188 
189 	TP_printk(
190 		"irq len %zd\n", __entry->buf_len
191 	)
192 );
193 
194 TRACE_EVENT(ath6kl_htc_rx,
195 	TP_PROTO(int status, int endpoint, void *buf,
196 		 size_t buf_len),
197 
198 	TP_ARGS(status, endpoint, buf, buf_len),
199 
200 	TP_STRUCT__entry(
201 		__field(int, status)
202 		__field(int, endpoint)
203 		__field(size_t, buf_len)
204 		__dynamic_array(u8, buf, buf_len)
205 	),
206 
207 	TP_fast_assign(
208 		__entry->status = status;
209 		__entry->endpoint = endpoint;
210 		__entry->buf_len = buf_len;
211 		memcpy(__get_dynamic_array(buf), buf, buf_len);
212 	),
213 
214 	TP_printk(
215 		"status %d endpoint %d len %zd\n",
216 		__entry->status,
217 		__entry->endpoint,
218 		__entry->buf_len
219 	)
220 );
221 
222 TRACE_EVENT(ath6kl_htc_tx,
223 	TP_PROTO(int status, int endpoint, void *buf,
224 		 size_t buf_len),
225 
226 	TP_ARGS(status, endpoint, buf, buf_len),
227 
228 	TP_STRUCT__entry(
229 		__field(int, status)
230 		__field(int, endpoint)
231 		__field(size_t, buf_len)
232 		__dynamic_array(u8, buf, buf_len)
233 	),
234 
235 	TP_fast_assign(
236 		__entry->status = status;
237 		__entry->endpoint = endpoint;
238 		__entry->buf_len = buf_len;
239 		memcpy(__get_dynamic_array(buf), buf, buf_len);
240 	),
241 
242 	TP_printk(
243 		"status %d endpoint %d len %zd\n",
244 		__entry->status,
245 		__entry->endpoint,
246 		__entry->buf_len
247 	)
248 );
249 
250 #define ATH6KL_MSG_MAX 200
251 
252 DECLARE_EVENT_CLASS(ath6kl_log_event,
253 	TP_PROTO(struct va_format *vaf),
254 	TP_ARGS(vaf),
255 	TP_STRUCT__entry(
256 		__vstring(msg, vaf->fmt, vaf->va)
257 	),
258 	TP_fast_assign(
259 		__assign_vstr(msg, vaf->fmt, vaf->va);
260 	),
261 	TP_printk("%s", __get_str(msg))
262 );
263 
264 DEFINE_EVENT(ath6kl_log_event, ath6kl_log_err,
265 	     TP_PROTO(struct va_format *vaf),
266 	     TP_ARGS(vaf)
267 );
268 
269 DEFINE_EVENT(ath6kl_log_event, ath6kl_log_warn,
270 	     TP_PROTO(struct va_format *vaf),
271 	     TP_ARGS(vaf)
272 );
273 
274 DEFINE_EVENT(ath6kl_log_event, ath6kl_log_info,
275 	     TP_PROTO(struct va_format *vaf),
276 	     TP_ARGS(vaf)
277 );
278 
279 TRACE_EVENT(ath6kl_log_dbg,
280 	TP_PROTO(unsigned int level, struct va_format *vaf),
281 	TP_ARGS(level, vaf),
282 	TP_STRUCT__entry(
283 		__field(unsigned int, level)
284 		__vstring(msg, vaf->fmt, vaf->va)
285 	),
286 	TP_fast_assign(
287 		__entry->level = level;
288 		__assign_vstr(msg, vaf->fmt, vaf->va);
289 	),
290 	TP_printk("%s", __get_str(msg))
291 );
292 
293 TRACE_EVENT(ath6kl_log_dbg_dump,
294 	TP_PROTO(const char *msg, const char *prefix,
295 		 const void *buf, size_t buf_len),
296 
297 	TP_ARGS(msg, prefix, buf, buf_len),
298 
299 	TP_STRUCT__entry(
300 		__string(msg, msg)
301 		__string(prefix, prefix)
302 		__field(size_t, buf_len)
303 		__dynamic_array(u8, buf, buf_len)
304 	),
305 
306 	TP_fast_assign(
307 		__assign_str(msg, msg);
308 		__assign_str(prefix, prefix);
309 		__entry->buf_len = buf_len;
310 		memcpy(__get_dynamic_array(buf), buf, buf_len);
311 	),
312 
313 	TP_printk(
314 		"%s/%s\n", __get_str(prefix), __get_str(msg)
315 	)
316 );
317 
318 #endif /* _ ATH6KL_TRACE_H || TRACE_HEADER_MULTI_READ*/
319 
320 /* we don't want to use include/trace/events */
321 #undef TRACE_INCLUDE_PATH
322 #define TRACE_INCLUDE_PATH .
323 #undef TRACE_INCLUDE_FILE
324 #define TRACE_INCLUDE_FILE trace
325 
326 /* This part must be outside protection */
327 #include <trace/define_trace.h>
328