1 /*
2  * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
3  * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14 
15 #if !defined(__MT7601U_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
16 #define __MT7601U_TRACE_H
17 
18 #include <linux/tracepoint.h>
19 #include "mt7601u.h"
20 #include "mac.h"
21 
22 #undef TRACE_SYSTEM
23 #define TRACE_SYSTEM mt7601u
24 
25 #define MAXNAME		32
26 #define DEV_ENTRY	__array(char, wiphy_name, 32)
27 #define DEV_ASSIGN	strlcpy(__entry->wiphy_name,			\
28 				wiphy_name(dev->hw->wiphy), MAXNAME)
29 #define DEV_PR_FMT	"%s "
30 #define DEV_PR_ARG	__entry->wiphy_name
31 
32 #define REG_ENTRY	__field(u32, reg) __field(u32, val)
33 #define REG_ASSIGN	__entry->reg = reg; __entry->val = val
34 #define REG_PR_FMT	"%04x=%08x"
35 #define REG_PR_ARG	__entry->reg, __entry->val
36 
37 DECLARE_EVENT_CLASS(dev_reg_evt,
38 	TP_PROTO(struct mt7601u_dev *dev, u32 reg, u32 val),
39 	TP_ARGS(dev, reg, val),
40 	TP_STRUCT__entry(
41 		DEV_ENTRY
42 		REG_ENTRY
43 	),
44 	TP_fast_assign(
45 		DEV_ASSIGN;
46 		REG_ASSIGN;
47 	),
48 	TP_printk(
49 		DEV_PR_FMT REG_PR_FMT,
50 		DEV_PR_ARG, REG_PR_ARG
51 	)
52 );
53 
54 DEFINE_EVENT(dev_reg_evt, reg_read,
55 	TP_PROTO(struct mt7601u_dev *dev, u32 reg, u32 val),
56 	TP_ARGS(dev, reg, val)
57 );
58 
59 DEFINE_EVENT(dev_reg_evt, reg_write,
60 	TP_PROTO(struct mt7601u_dev *dev, u32 reg, u32 val),
61 	TP_ARGS(dev, reg, val)
62 );
63 
64 TRACE_EVENT(mt_submit_urb,
65 	TP_PROTO(struct mt7601u_dev *dev, struct urb *u),
66 	TP_ARGS(dev, u),
67 	TP_STRUCT__entry(
68 		DEV_ENTRY __field(unsigned, pipe) __field(u32, len)
69 	),
70 	TP_fast_assign(
71 		DEV_ASSIGN;
72 		__entry->pipe = u->pipe;
73 		__entry->len = u->transfer_buffer_length;
74 	),
75 	TP_printk(DEV_PR_FMT "p:%08x len:%u",
76 		  DEV_PR_ARG, __entry->pipe, __entry->len)
77 );
78 
79 #define trace_mt_submit_urb_sync(__dev, __pipe, __len) ({	\
80 	struct urb u;					\
81 	u.pipe = __pipe;				\
82 	u.transfer_buffer_length = __len;		\
83 	trace_mt_submit_urb(__dev, &u);			\
84 })
85 
86 TRACE_EVENT(mt_mcu_msg_send,
87 	TP_PROTO(struct mt7601u_dev *dev,
88 		 struct sk_buff *skb, u32 csum, bool resp),
89 	TP_ARGS(dev, skb, csum, resp),
90 	TP_STRUCT__entry(
91 		DEV_ENTRY
92 		__field(u32, info)
93 		__field(u32, csum)
94 		__field(bool, resp)
95 	),
96 	TP_fast_assign(
97 		DEV_ASSIGN;
98 		__entry->info = *(u32 *)skb->data;
99 		__entry->csum = csum;
100 		__entry->resp = resp;
101 	),
102 	TP_printk(DEV_PR_FMT "i:%08x c:%08x r:%d",
103 		  DEV_PR_ARG, __entry->info, __entry->csum, __entry->resp)
104 );
105 
106 TRACE_EVENT(mt_vend_req,
107 	TP_PROTO(struct mt7601u_dev *dev, unsigned pipe, u8 req, u8 req_type,
108 		 u16 val, u16 offset, void *buf, size_t buflen, int ret),
109 	TP_ARGS(dev, pipe, req, req_type, val, offset, buf, buflen, ret),
110 	TP_STRUCT__entry(
111 		DEV_ENTRY
112 		__field(unsigned, pipe) __field(u8, req) __field(u8, req_type)
113 		__field(u16, val) __field(u16, offset) __field(void*, buf)
114 		__field(int, buflen) __field(int, ret)
115 	),
116 	TP_fast_assign(
117 		DEV_ASSIGN;
118 		__entry->pipe = pipe;
119 		__entry->req = req;
120 		__entry->req_type = req_type;
121 		__entry->val = val;
122 		__entry->offset = offset;
123 		__entry->buf = buf;
124 		__entry->buflen = buflen;
125 		__entry->ret = ret;
126 	),
127 	TP_printk(DEV_PR_FMT
128 		  "%d p:%08x req:%02hhx %02hhx val:%04hx %04hx buf:%d %d",
129 		  DEV_PR_ARG, __entry->ret, __entry->pipe, __entry->req,
130 		  __entry->req_type, __entry->val, __entry->offset,
131 		  !!__entry->buf, __entry->buflen)
132 );
133 
134 TRACE_EVENT(ee_read,
135 	TP_PROTO(struct mt7601u_dev *dev, int offset, u16 val),
136 	TP_ARGS(dev, offset, val),
137 	TP_STRUCT__entry(
138 		DEV_ENTRY
139 		__field(int, o) __field(u16, v)
140 	),
141 	TP_fast_assign(
142 		DEV_ASSIGN;
143 		__entry->o = offset;
144 		__entry->v = val;
145 	),
146 	TP_printk(DEV_PR_FMT "%04x=%04x", DEV_PR_ARG, __entry->o, __entry->v)
147 );
148 
149 DECLARE_EVENT_CLASS(dev_rf_reg_evt,
150 	TP_PROTO(struct mt7601u_dev *dev, u8 bank, u8 reg, u8 val),
151 	TP_ARGS(dev, bank, reg, val),
152 	TP_STRUCT__entry(
153 		DEV_ENTRY
154 		__field(u8, bank)
155 		__field(u8, reg)
156 		__field(u8, val)
157 	),
158 	TP_fast_assign(
159 		DEV_ASSIGN;
160 		REG_ASSIGN;
161 		__entry->bank = bank;
162 	),
163 	TP_printk(
164 		DEV_PR_FMT "%02hhx:%02hhx=%02hhx",
165 		DEV_PR_ARG, __entry->bank, __entry->reg, __entry->val
166 	)
167 );
168 
169 DEFINE_EVENT(dev_rf_reg_evt, rf_read,
170 	TP_PROTO(struct mt7601u_dev *dev, u8 bank, u8 reg, u8 val),
171 	TP_ARGS(dev, bank, reg, val)
172 );
173 
174 DEFINE_EVENT(dev_rf_reg_evt, rf_write,
175 	TP_PROTO(struct mt7601u_dev *dev, u8 bank, u8 reg, u8 val),
176 	TP_ARGS(dev, bank, reg, val)
177 );
178 
179 DECLARE_EVENT_CLASS(dev_bbp_reg_evt,
180 	TP_PROTO(struct mt7601u_dev *dev, u8 reg, u8 val),
181 	TP_ARGS(dev, reg, val),
182 	TP_STRUCT__entry(
183 		DEV_ENTRY
184 		__field(u8, reg)
185 		__field(u8, val)
186 	),
187 	TP_fast_assign(
188 		DEV_ASSIGN;
189 		REG_ASSIGN;
190 	),
191 	TP_printk(
192 		DEV_PR_FMT "%02hhx=%02hhx",
193 		DEV_PR_ARG, __entry->reg, __entry->val
194 	)
195 );
196 
197 DEFINE_EVENT(dev_bbp_reg_evt, bbp_read,
198 	TP_PROTO(struct mt7601u_dev *dev, u8 reg, u8 val),
199 	TP_ARGS(dev, reg, val)
200 );
201 
202 DEFINE_EVENT(dev_bbp_reg_evt, bbp_write,
203 	TP_PROTO(struct mt7601u_dev *dev, u8 reg, u8 val),
204 	TP_ARGS(dev, reg, val)
205 );
206 
207 DECLARE_EVENT_CLASS(dev_simple_evt,
208 	TP_PROTO(struct mt7601u_dev *dev, u8 val),
209 	TP_ARGS(dev, val),
210 	TP_STRUCT__entry(
211 		DEV_ENTRY
212 		__field(u8, val)
213 	),
214 	TP_fast_assign(
215 		DEV_ASSIGN;
216 		__entry->val = val;
217 	),
218 	TP_printk(
219 		DEV_PR_FMT "%02hhx", DEV_PR_ARG, __entry->val
220 	)
221 );
222 
223 DEFINE_EVENT(dev_simple_evt, temp_mode,
224 	TP_PROTO(struct mt7601u_dev *dev, u8 val),
225 	TP_ARGS(dev, val)
226 );
227 
228 DEFINE_EVENT(dev_simple_evt, read_temp,
229 	TP_PROTO(struct mt7601u_dev *dev, u8 val),
230 	TP_ARGS(dev, val)
231 );
232 
233 DEFINE_EVENT(dev_simple_evt, freq_cal_adjust,
234 	TP_PROTO(struct mt7601u_dev *dev, u8 val),
235 	TP_ARGS(dev, val)
236 );
237 
238 TRACE_EVENT(freq_cal_offset,
239 	TP_PROTO(struct mt7601u_dev *dev, u8 phy_mode, s8 freq_off),
240 	TP_ARGS(dev, phy_mode, freq_off),
241 	TP_STRUCT__entry(
242 		DEV_ENTRY
243 		__field(u8, phy_mode)
244 		__field(s8, freq_off)
245 	),
246 	TP_fast_assign(
247 		DEV_ASSIGN;
248 		__entry->phy_mode = phy_mode;
249 		__entry->freq_off = freq_off;
250 	),
251 	TP_printk(DEV_PR_FMT "phy:%02hhx off:%02hhx",
252 		  DEV_PR_ARG, __entry->phy_mode, __entry->freq_off)
253 );
254 
255 TRACE_EVENT(mt_rx,
256 	TP_PROTO(struct mt7601u_dev *dev, struct mt7601u_rxwi *rxwi, u32 f),
257 	TP_ARGS(dev, rxwi, f),
258 	TP_STRUCT__entry(
259 		DEV_ENTRY
260 		__field_struct(struct mt7601u_rxwi, rxwi)
261 		__field(u32, fce_info)
262 	),
263 	TP_fast_assign(
264 		DEV_ASSIGN;
265 		__entry->rxwi = *rxwi;
266 		__entry->fce_info = f;
267 	),
268 	TP_printk(DEV_PR_FMT "rxi:%08x ctl:%08x frag_sn:%04hx rate:%04hx "
269 		  "uknw:%02hhx z:%02hhx%02hhx%02hhx snr:%02hhx "
270 		  "ant:%02hhx gain:%02hhx freq_o:%02hhx "
271 		  "r:%08x ea:%08x fce:%08x", DEV_PR_ARG,
272 		  le32_to_cpu(__entry->rxwi.rxinfo),
273 		  le32_to_cpu(__entry->rxwi.ctl),
274 		  le16_to_cpu(__entry->rxwi.frag_sn),
275 		  le16_to_cpu(__entry->rxwi.rate),
276 		  __entry->rxwi.unknown,
277 		  __entry->rxwi.zero[0], __entry->rxwi.zero[1],
278 		  __entry->rxwi.zero[2],
279 		  __entry->rxwi.snr, __entry->rxwi.ant,
280 		  __entry->rxwi.gain, __entry->rxwi.freq_off,
281 		  __entry->rxwi.resv2, __entry->rxwi.expert_ant,
282 		  __entry->fce_info)
283 );
284 
285 TRACE_EVENT(mt_tx,
286 	TP_PROTO(struct mt7601u_dev *dev, struct sk_buff *skb,
287 		 struct mt76_sta *sta, struct mt76_txwi *h),
288 	TP_ARGS(dev, skb, sta, h),
289 	TP_STRUCT__entry(
290 		DEV_ENTRY
291 		__field_struct(struct mt76_txwi, h)
292 		__field(struct sk_buff *, skb)
293 		__field(struct mt76_sta *, sta)
294 	),
295 	TP_fast_assign(
296 		DEV_ASSIGN;
297 		__entry->h = *h;
298 		__entry->skb = skb;
299 		__entry->sta = sta;
300 	),
301 	TP_printk(DEV_PR_FMT "skb:%p sta:%p  flg:%04hx rate_ctl:%04hx "
302 		  "ack:%02hhx wcid:%02hhx len_ctl:%05hx", DEV_PR_ARG,
303 		  __entry->skb, __entry->sta,
304 		  le16_to_cpu(__entry->h.flags),
305 		  le16_to_cpu(__entry->h.rate_ctl),
306 		  __entry->h.ack_ctl, __entry->h.wcid,
307 		  le16_to_cpu(__entry->h.len_ctl))
308 );
309 
310 TRACE_EVENT(mt_tx_dma_done,
311 	TP_PROTO(struct mt7601u_dev *dev, struct sk_buff *skb),
312 	TP_ARGS(dev, skb),
313 	TP_STRUCT__entry(
314 		DEV_ENTRY
315 		__field(struct sk_buff *, skb)
316 	),
317 	TP_fast_assign(
318 		DEV_ASSIGN;
319 		__entry->skb = skb;
320 	),
321 	TP_printk(DEV_PR_FMT "%p", DEV_PR_ARG, __entry->skb)
322 );
323 
324 TRACE_EVENT(mt_tx_status_cleaned,
325 	TP_PROTO(struct mt7601u_dev *dev, int cleaned),
326 	TP_ARGS(dev, cleaned),
327 	TP_STRUCT__entry(
328 		DEV_ENTRY
329 		__field(int, cleaned)
330 	),
331 	TP_fast_assign(
332 		DEV_ASSIGN;
333 		__entry->cleaned = cleaned;
334 	),
335 	TP_printk(DEV_PR_FMT "%d", DEV_PR_ARG, __entry->cleaned)
336 );
337 
338 TRACE_EVENT(mt_tx_status,
339 	TP_PROTO(struct mt7601u_dev *dev, u32 stat1, u32 stat2),
340 	TP_ARGS(dev, stat1, stat2),
341 	TP_STRUCT__entry(
342 		DEV_ENTRY
343 		__field(u32, stat1)	__field(u32, stat2)
344 	),
345 	TP_fast_assign(
346 		DEV_ASSIGN;
347 		__entry->stat1 = stat1;
348 		__entry->stat2 = stat2;
349 	),
350 	TP_printk(DEV_PR_FMT "%08x %08x",
351 		  DEV_PR_ARG, __entry->stat1, __entry->stat2)
352 );
353 
354 TRACE_EVENT(mt_rx_dma_aggr,
355 	TP_PROTO(struct mt7601u_dev *dev, int cnt, bool paged),
356 	TP_ARGS(dev, cnt, paged),
357 	TP_STRUCT__entry(
358 		DEV_ENTRY
359 		__field(u8, cnt)
360 		__field(bool, paged)
361 	),
362 	TP_fast_assign(
363 		DEV_ASSIGN;
364 		__entry->cnt = cnt;
365 		__entry->paged = paged;
366 	),
367 	TP_printk(DEV_PR_FMT "cnt:%d paged:%d",
368 		  DEV_PR_ARG, __entry->cnt, __entry->paged)
369 );
370 
371 DEFINE_EVENT(dev_simple_evt, set_key,
372 	TP_PROTO(struct mt7601u_dev *dev, u8 val),
373 	TP_ARGS(dev, val)
374 );
375 
376 TRACE_EVENT(set_shared_key,
377 	TP_PROTO(struct mt7601u_dev *dev, u8 vid, u8 key),
378 	TP_ARGS(dev, vid, key),
379 	TP_STRUCT__entry(
380 		DEV_ENTRY
381 		__field(u8, vid)
382 		__field(u8, key)
383 	),
384 	TP_fast_assign(
385 		DEV_ASSIGN;
386 		__entry->vid = vid;
387 		__entry->key = key;
388 	),
389 	TP_printk(DEV_PR_FMT "phy:%02hhx off:%02hhx",
390 		  DEV_PR_ARG, __entry->vid, __entry->key)
391 );
392 
393 #endif
394 
395 #undef TRACE_INCLUDE_PATH
396 #define TRACE_INCLUDE_PATH .
397 #undef TRACE_INCLUDE_FILE
398 #define TRACE_INCLUDE_FILE trace
399 
400 #include <trace/define_trace.h>
401