1 /*
2  * Copyright (c) 2013 Qualcomm Atheros, Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #undef TRACE_SYSTEM
18 #define TRACE_SYSTEM wil6210
19 #if !defined(WIL6210_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
20 #define WIL6210_TRACE_H
21 
22 #include <linux/tracepoint.h>
23 #include "wil6210.h"
24 #include "txrx.h"
25 
26 /* create empty functions when tracing is disabled */
27 #if !defined(CONFIG_WIL6210_TRACING) || defined(__CHECKER__)
28 
29 #undef TRACE_EVENT
30 #define TRACE_EVENT(name, proto, ...) \
31 static inline void trace_ ## name(proto) {}
32 #undef DECLARE_EVENT_CLASS
33 #define DECLARE_EVENT_CLASS(...)
34 #undef DEFINE_EVENT
35 #define DEFINE_EVENT(evt_class, name, proto, ...) \
36 static inline void trace_ ## name(proto) {}
37 #endif /* !CONFIG_WIL6210_TRACING || defined(__CHECKER__) */
38 
39 DECLARE_EVENT_CLASS(wil6210_wmi,
40 	TP_PROTO(struct wil6210_mbox_hdr_wmi *wmi, void *buf, u16 buf_len),
41 
42 	TP_ARGS(wmi, buf, buf_len),
43 
44 	TP_STRUCT__entry(
45 		__field(u8, mid)
46 		__field(u16, id)
47 		__field(u32, timestamp)
48 		__field(u16, buf_len)
49 		__dynamic_array(u8, buf, buf_len)
50 	),
51 
52 	TP_fast_assign(
53 		__entry->mid = wmi->mid;
54 		__entry->id = le16_to_cpu(wmi->id);
55 		__entry->timestamp = le32_to_cpu(wmi->timestamp);
56 		__entry->buf_len = buf_len;
57 		memcpy(__get_dynamic_array(buf), buf, buf_len);
58 	),
59 
60 	TP_printk(
61 		"MID %d id 0x%04x len %d timestamp %d",
62 		__entry->mid, __entry->id, __entry->buf_len, __entry->timestamp
63 	)
64 );
65 
66 DEFINE_EVENT(wil6210_wmi, wil6210_wmi_cmd,
67 	TP_PROTO(struct wil6210_mbox_hdr_wmi *wmi, void *buf, u16 buf_len),
68 	TP_ARGS(wmi, buf, buf_len)
69 );
70 
71 DEFINE_EVENT(wil6210_wmi, wil6210_wmi_event,
72 	TP_PROTO(struct wil6210_mbox_hdr_wmi *wmi, void *buf, u16 buf_len),
73 	TP_ARGS(wmi, buf, buf_len)
74 );
75 
76 #define WIL6210_MSG_MAX (200)
77 
78 DECLARE_EVENT_CLASS(wil6210_log_event,
79 	TP_PROTO(struct va_format *vaf),
80 	TP_ARGS(vaf),
81 	TP_STRUCT__entry(
82 		__dynamic_array(char, msg, WIL6210_MSG_MAX)
83 	),
84 	TP_fast_assign(
85 		WARN_ON_ONCE(vsnprintf(__get_dynamic_array(msg),
86 				       WIL6210_MSG_MAX,
87 				       vaf->fmt,
88 				       *vaf->va) >= WIL6210_MSG_MAX);
89 	),
90 	TP_printk("%s", __get_str(msg))
91 );
92 
93 DEFINE_EVENT(wil6210_log_event, wil6210_log_err,
94 	TP_PROTO(struct va_format *vaf),
95 	TP_ARGS(vaf)
96 );
97 
98 DEFINE_EVENT(wil6210_log_event, wil6210_log_info,
99 	TP_PROTO(struct va_format *vaf),
100 	TP_ARGS(vaf)
101 );
102 
103 DEFINE_EVENT(wil6210_log_event, wil6210_log_dbg,
104 	TP_PROTO(struct va_format *vaf),
105 	TP_ARGS(vaf)
106 );
107 
108 #define wil_pseudo_irq_cause(x) __print_flags(x, "|",	\
109 	{BIT_DMA_PSEUDO_CAUSE_RX,	"Rx" },		\
110 	{BIT_DMA_PSEUDO_CAUSE_TX,	"Tx" },		\
111 	{BIT_DMA_PSEUDO_CAUSE_MISC,	"Misc" })
112 
113 TRACE_EVENT(wil6210_irq_pseudo,
114 	TP_PROTO(u32 x),
115 	TP_ARGS(x),
116 	TP_STRUCT__entry(
117 		__field(u32, x)
118 	),
119 	TP_fast_assign(
120 		__entry->x = x;
121 	),
122 	TP_printk("cause 0x%08x : %s", __entry->x,
123 		  wil_pseudo_irq_cause(__entry->x))
124 );
125 
126 DECLARE_EVENT_CLASS(wil6210_irq,
127 	TP_PROTO(u32 x),
128 	TP_ARGS(x),
129 	TP_STRUCT__entry(
130 		__field(u32, x)
131 	),
132 	TP_fast_assign(
133 		__entry->x = x;
134 	),
135 	TP_printk("cause 0x%08x", __entry->x)
136 );
137 
138 DEFINE_EVENT(wil6210_irq, wil6210_irq_rx,
139 	TP_PROTO(u32 x),
140 	TP_ARGS(x)
141 );
142 
143 DEFINE_EVENT(wil6210_irq, wil6210_irq_tx,
144 	TP_PROTO(u32 x),
145 	TP_ARGS(x)
146 );
147 
148 DEFINE_EVENT(wil6210_irq, wil6210_irq_misc,
149 	TP_PROTO(u32 x),
150 	TP_ARGS(x)
151 );
152 
153 DEFINE_EVENT(wil6210_irq, wil6210_irq_misc_thread,
154 	TP_PROTO(u32 x),
155 	TP_ARGS(x)
156 );
157 
158 TRACE_EVENT(wil6210_rx,
159 	TP_PROTO(u16 index, struct vring_rx_desc *d),
160 	TP_ARGS(index, d),
161 	TP_STRUCT__entry(
162 		__field(u16, index)
163 		__field(unsigned int, len)
164 		__field(u8, mid)
165 		__field(u8, cid)
166 		__field(u8, tid)
167 		__field(u8, type)
168 		__field(u8, subtype)
169 		__field(u16, seq)
170 		__field(u8, mcs)
171 	),
172 	TP_fast_assign(
173 		__entry->index = index;
174 		__entry->len = d->dma.length;
175 		__entry->mid = wil_rxdesc_mid(d);
176 		__entry->cid = wil_rxdesc_cid(d);
177 		__entry->tid = wil_rxdesc_tid(d);
178 		__entry->type = wil_rxdesc_ftype(d);
179 		__entry->subtype = wil_rxdesc_subtype(d);
180 		__entry->seq = wil_rxdesc_seq(d);
181 		__entry->mcs = wil_rxdesc_mcs(d);
182 	),
183 	TP_printk("index %d len %d mid %d cid %d tid %d mcs %d seq 0x%03x"
184 		  " type 0x%1x subtype 0x%1x", __entry->index, __entry->len,
185 		  __entry->mid, __entry->cid, __entry->tid, __entry->mcs,
186 		  __entry->seq, __entry->type, __entry->subtype)
187 );
188 
189 TRACE_EVENT(wil6210_tx,
190 	TP_PROTO(u8 vring, u16 index, unsigned int len, u8 frags),
191 	TP_ARGS(vring, index, len, frags),
192 	TP_STRUCT__entry(
193 		__field(u8, vring)
194 		__field(u8, frags)
195 		__field(u16, index)
196 		__field(unsigned int, len)
197 	),
198 	TP_fast_assign(
199 		__entry->vring = vring;
200 		__entry->frags = frags;
201 		__entry->index = index;
202 		__entry->len = len;
203 	),
204 	TP_printk("vring %d index %d len %d frags %d",
205 		  __entry->vring, __entry->index, __entry->len, __entry->frags)
206 );
207 
208 TRACE_EVENT(wil6210_tx_done,
209 	TP_PROTO(u8 vring, u16 index, unsigned int len, u8 err),
210 	TP_ARGS(vring, index, len, err),
211 	TP_STRUCT__entry(
212 		__field(u8, vring)
213 		__field(u8, err)
214 		__field(u16, index)
215 		__field(unsigned int, len)
216 	),
217 	TP_fast_assign(
218 		__entry->vring = vring;
219 		__entry->index = index;
220 		__entry->len = len;
221 		__entry->err = err;
222 	),
223 	TP_printk("vring %d index %d len %d err 0x%02x",
224 		  __entry->vring, __entry->index, __entry->len,
225 		  __entry->err)
226 );
227 
228 #endif /* WIL6210_TRACE_H || TRACE_HEADER_MULTI_READ*/
229 
230 #if defined(CONFIG_WIL6210_TRACING) && !defined(__CHECKER__)
231 /* we don't want to use include/trace/events */
232 #undef TRACE_INCLUDE_PATH
233 #define TRACE_INCLUDE_PATH .
234 #undef TRACE_INCLUDE_FILE
235 #define TRACE_INCLUDE_FILE trace
236 
237 /* This part must be outside protection */
238 #include <trace/define_trace.h>
239 #endif /* defined(CONFIG_WIL6210_TRACING) && !defined(__CHECKER__) */
240