]>
Commit | Line | Data |
---|---|---|
fa1c114f | 1 | /* |
be9b7259 | 2 | * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com> |
fa1c114f JS |
3 | * |
4 | * This file is free software: you may copy, redistribute and/or modify it | |
5 | * under the terms of the GNU General Public License as published by the | |
6 | * Free Software Foundation, either version 2 of the License, or (at your | |
7 | * option) any later version. | |
8 | * | |
9 | * This file is distributed in the hope that it will be useful, but | |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | * | |
17 | * | |
18 | * This file incorporates work covered by the following copyright and | |
19 | * permission notice: | |
20 | * | |
21 | * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting | |
22 | * Copyright (c) 2004-2005 Atheros Communications, Inc. | |
23 | * Copyright (c) 2006 Devicescape Software, Inc. | |
24 | * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com> | |
25 | * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu> | |
26 | * | |
27 | * All rights reserved. | |
28 | * | |
29 | * Redistribution and use in source and binary forms, with or without | |
30 | * modification, are permitted provided that the following conditions | |
31 | * are met: | |
32 | * 1. Redistributions of source code must retain the above copyright | |
33 | * notice, this list of conditions and the following disclaimer, | |
34 | * without modification. | |
35 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
36 | * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any | |
37 | * redistribution must be conditioned upon including a substantially | |
38 | * similar Disclaimer requirement for further binary redistribution. | |
39 | * 3. Neither the names of the above-listed copyright holders nor the names | |
40 | * of any contributors may be used to endorse or promote products derived | |
41 | * from this software without specific prior written permission. | |
42 | * | |
43 | * Alternatively, this software may be distributed under the terms of the | |
44 | * GNU General Public License ("GPL") version 2 as published by the Free | |
45 | * Software Foundation. | |
46 | * | |
47 | * NO WARRANTY | |
48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
49 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
50 | * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY | |
51 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
52 | * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, | |
53 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
54 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
55 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | |
56 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
57 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
58 | * THE POSSIBILITY OF SUCH DAMAGES. | |
59 | */ | |
60 | ||
fa1c114f | 61 | #include "base.h" |
c6e387a2 | 62 | #include "debug.h" |
92c68a66 | 63 | #include "../debug.h" |
fa1c114f JS |
64 | |
65 | static unsigned int ath5k_debug; | |
66 | module_param_named(debug, ath5k_debug, uint, 0); | |
67 | ||
68 | ||
b446197c | 69 | #ifdef CONFIG_ATH5K_DEBUG |
fa1c114f JS |
70 | |
71 | #include <linux/seq_file.h> | |
72 | #include "reg.h" | |
2111ac0d | 73 | #include "ani.h" |
fa1c114f | 74 | |
fa1c114f JS |
75 | static int ath5k_debugfs_open(struct inode *inode, struct file *file) |
76 | { | |
77 | file->private_data = inode->i_private; | |
78 | return 0; | |
79 | } | |
80 | ||
81 | ||
82 | /* debugfs: registers */ | |
83 | ||
84 | struct reg { | |
2c91108c | 85 | const char *name; |
fa1c114f JS |
86 | int addr; |
87 | }; | |
88 | ||
89 | #define REG_STRUCT_INIT(r) { #r, r } | |
90 | ||
91 | /* just a few random registers, might want to add more */ | |
2c91108c | 92 | static const struct reg regs[] = { |
fa1c114f JS |
93 | REG_STRUCT_INIT(AR5K_CR), |
94 | REG_STRUCT_INIT(AR5K_RXDP), | |
95 | REG_STRUCT_INIT(AR5K_CFG), | |
96 | REG_STRUCT_INIT(AR5K_IER), | |
97 | REG_STRUCT_INIT(AR5K_BCR), | |
98 | REG_STRUCT_INIT(AR5K_RTSD0), | |
99 | REG_STRUCT_INIT(AR5K_RTSD1), | |
100 | REG_STRUCT_INIT(AR5K_TXCFG), | |
101 | REG_STRUCT_INIT(AR5K_RXCFG), | |
102 | REG_STRUCT_INIT(AR5K_RXJLA), | |
103 | REG_STRUCT_INIT(AR5K_MIBC), | |
104 | REG_STRUCT_INIT(AR5K_TOPS), | |
105 | REG_STRUCT_INIT(AR5K_RXNOFRM), | |
106 | REG_STRUCT_INIT(AR5K_TXNOFRM), | |
107 | REG_STRUCT_INIT(AR5K_RPGTO), | |
108 | REG_STRUCT_INIT(AR5K_RFCNT), | |
109 | REG_STRUCT_INIT(AR5K_MISC), | |
110 | REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT), | |
111 | REG_STRUCT_INIT(AR5K_ISR), | |
112 | REG_STRUCT_INIT(AR5K_PISR), | |
113 | REG_STRUCT_INIT(AR5K_SISR0), | |
114 | REG_STRUCT_INIT(AR5K_SISR1), | |
115 | REG_STRUCT_INIT(AR5K_SISR2), | |
116 | REG_STRUCT_INIT(AR5K_SISR3), | |
117 | REG_STRUCT_INIT(AR5K_SISR4), | |
118 | REG_STRUCT_INIT(AR5K_IMR), | |
119 | REG_STRUCT_INIT(AR5K_PIMR), | |
120 | REG_STRUCT_INIT(AR5K_SIMR0), | |
121 | REG_STRUCT_INIT(AR5K_SIMR1), | |
122 | REG_STRUCT_INIT(AR5K_SIMR2), | |
123 | REG_STRUCT_INIT(AR5K_SIMR3), | |
124 | REG_STRUCT_INIT(AR5K_SIMR4), | |
125 | REG_STRUCT_INIT(AR5K_DCM_ADDR), | |
126 | REG_STRUCT_INIT(AR5K_DCCFG), | |
127 | REG_STRUCT_INIT(AR5K_CCFG), | |
128 | REG_STRUCT_INIT(AR5K_CPC0), | |
129 | REG_STRUCT_INIT(AR5K_CPC1), | |
130 | REG_STRUCT_INIT(AR5K_CPC2), | |
131 | REG_STRUCT_INIT(AR5K_CPC3), | |
0bacdf30 | 132 | REG_STRUCT_INIT(AR5K_CPCOVF), |
fa1c114f JS |
133 | REG_STRUCT_INIT(AR5K_RESET_CTL), |
134 | REG_STRUCT_INIT(AR5K_SLEEP_CTL), | |
135 | REG_STRUCT_INIT(AR5K_INTPEND), | |
136 | REG_STRUCT_INIT(AR5K_SFR), | |
137 | REG_STRUCT_INIT(AR5K_PCICFG), | |
138 | REG_STRUCT_INIT(AR5K_GPIOCR), | |
139 | REG_STRUCT_INIT(AR5K_GPIODO), | |
140 | REG_STRUCT_INIT(AR5K_SREV), | |
141 | }; | |
142 | ||
143 | static void *reg_start(struct seq_file *seq, loff_t *pos) | |
144 | { | |
2c91108c | 145 | return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL; |
fa1c114f JS |
146 | } |
147 | ||
148 | static void reg_stop(struct seq_file *seq, void *p) | |
149 | { | |
150 | /* nothing to do */ | |
151 | } | |
152 | ||
153 | static void *reg_next(struct seq_file *seq, void *p, loff_t *pos) | |
154 | { | |
155 | ++*pos; | |
2c91108c | 156 | return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL; |
fa1c114f JS |
157 | } |
158 | ||
159 | static int reg_show(struct seq_file *seq, void *p) | |
160 | { | |
161 | struct ath5k_softc *sc = seq->private; | |
162 | struct reg *r = p; | |
163 | seq_printf(seq, "%-25s0x%08x\n", r->name, | |
164 | ath5k_hw_reg_read(sc->ah, r->addr)); | |
165 | return 0; | |
166 | } | |
167 | ||
4101dec9 | 168 | static const struct seq_operations register_seq_ops = { |
fa1c114f JS |
169 | .start = reg_start, |
170 | .next = reg_next, | |
171 | .stop = reg_stop, | |
172 | .show = reg_show | |
173 | }; | |
174 | ||
175 | static int open_file_registers(struct inode *inode, struct file *file) | |
176 | { | |
177 | struct seq_file *s; | |
178 | int res; | |
179 | res = seq_open(file, ®ister_seq_ops); | |
180 | if (res == 0) { | |
181 | s = file->private_data; | |
182 | s->private = inode->i_private; | |
183 | } | |
184 | return res; | |
185 | } | |
186 | ||
187 | static const struct file_operations fops_registers = { | |
188 | .open = open_file_registers, | |
189 | .read = seq_read, | |
190 | .llseek = seq_lseek, | |
191 | .release = seq_release, | |
192 | .owner = THIS_MODULE, | |
193 | }; | |
194 | ||
195 | ||
fa1c114f JS |
196 | /* debugfs: beacons */ |
197 | ||
198 | static ssize_t read_file_beacon(struct file *file, char __user *user_buf, | |
199 | size_t count, loff_t *ppos) | |
200 | { | |
201 | struct ath5k_softc *sc = file->private_data; | |
202 | struct ath5k_hw *ah = sc->ah; | |
be9b7259 BR |
203 | char buf[500]; |
204 | unsigned int len = 0; | |
fa1c114f JS |
205 | unsigned int v; |
206 | u64 tsf; | |
207 | ||
208 | v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON); | |
209 | len += snprintf(buf+len, sizeof(buf)-len, | |
210 | "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n", | |
211 | "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD, | |
212 | (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S); | |
213 | ||
214 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n", | |
215 | "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP)); | |
216 | ||
217 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n", | |
218 | "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT)); | |
219 | ||
220 | v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0); | |
221 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n", | |
222 | "AR5K_TIMER0 (TBTT)", v, v); | |
223 | ||
224 | v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1); | |
225 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n", | |
226 | "AR5K_TIMER1 (DMA)", v, v >> 3); | |
227 | ||
228 | v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2); | |
229 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n", | |
230 | "AR5K_TIMER2 (SWBA)", v, v >> 3); | |
231 | ||
232 | v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3); | |
233 | len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n", | |
234 | "AR5K_TIMER3 (ATIM)", v, v); | |
235 | ||
236 | tsf = ath5k_hw_get_tsf64(sc->ah); | |
237 | len += snprintf(buf+len, sizeof(buf)-len, | |
f868f4e1 JL |
238 | "TSF\t\t0x%016llx\tTU: %08x\n", |
239 | (unsigned long long)tsf, TSF_TO_TU(tsf)); | |
fa1c114f | 240 | |
2189d13f DC |
241 | if (len > sizeof(buf)) |
242 | len = sizeof(buf); | |
243 | ||
fa1c114f JS |
244 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
245 | } | |
246 | ||
247 | static ssize_t write_file_beacon(struct file *file, | |
248 | const char __user *userbuf, | |
249 | size_t count, loff_t *ppos) | |
250 | { | |
251 | struct ath5k_softc *sc = file->private_data; | |
252 | struct ath5k_hw *ah = sc->ah; | |
be9b7259 | 253 | char buf[20]; |
fa1c114f | 254 | |
be9b7259 BR |
255 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) |
256 | return -EFAULT; | |
257 | ||
258 | if (strncmp(buf, "disable", 7) == 0) { | |
fa1c114f JS |
259 | AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE); |
260 | printk(KERN_INFO "debugfs disable beacons\n"); | |
be9b7259 | 261 | } else if (strncmp(buf, "enable", 6) == 0) { |
fa1c114f JS |
262 | AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE); |
263 | printk(KERN_INFO "debugfs enable beacons\n"); | |
264 | } | |
265 | return count; | |
266 | } | |
267 | ||
268 | static const struct file_operations fops_beacon = { | |
269 | .read = read_file_beacon, | |
270 | .write = write_file_beacon, | |
271 | .open = ath5k_debugfs_open, | |
272 | .owner = THIS_MODULE, | |
6038f373 | 273 | .llseek = default_llseek, |
fa1c114f JS |
274 | }; |
275 | ||
276 | ||
277 | /* debugfs: reset */ | |
278 | ||
279 | static ssize_t write_file_reset(struct file *file, | |
280 | const char __user *userbuf, | |
281 | size_t count, loff_t *ppos) | |
282 | { | |
283 | struct ath5k_softc *sc = file->private_data; | |
8d67a031 | 284 | ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n"); |
5faaff74 | 285 | ieee80211_queue_work(sc->hw, &sc->reset_work); |
fa1c114f JS |
286 | return count; |
287 | } | |
288 | ||
289 | static const struct file_operations fops_reset = { | |
290 | .write = write_file_reset, | |
291 | .open = ath5k_debugfs_open, | |
292 | .owner = THIS_MODULE, | |
6038f373 | 293 | .llseek = noop_llseek, |
fa1c114f JS |
294 | }; |
295 | ||
296 | ||
be9b7259 BR |
297 | /* debugfs: debug level */ |
298 | ||
2c91108c | 299 | static const struct { |
be9b7259 BR |
300 | enum ath5k_debug_level level; |
301 | const char *name; | |
302 | const char *desc; | |
303 | } dbg_info[] = { | |
304 | { ATH5K_DEBUG_RESET, "reset", "reset and initialization" }, | |
305 | { ATH5K_DEBUG_INTR, "intr", "interrupt handling" }, | |
306 | { ATH5K_DEBUG_MODE, "mode", "mode init/setup" }, | |
307 | { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" }, | |
308 | { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" }, | |
309 | { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" }, | |
310 | { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" }, | |
85519a65 | 311 | { ATH5K_DEBUG_LED, "led", "LED management" }, |
be9b7259 BR |
312 | { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" }, |
313 | { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" }, | |
b446197c | 314 | { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" }, |
2111ac0d | 315 | { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" }, |
b4c52612 | 316 | { ATH5K_DEBUG_DESC, "desc", "descriptor chains" }, |
be9b7259 BR |
317 | { ATH5K_DEBUG_ANY, "all", "show all debug levels" }, |
318 | }; | |
319 | ||
320 | static ssize_t read_file_debug(struct file *file, char __user *user_buf, | |
321 | size_t count, loff_t *ppos) | |
322 | { | |
323 | struct ath5k_softc *sc = file->private_data; | |
324 | char buf[700]; | |
325 | unsigned int len = 0; | |
326 | unsigned int i; | |
327 | ||
328 | len += snprintf(buf+len, sizeof(buf)-len, | |
329 | "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level); | |
330 | ||
331 | for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) { | |
332 | len += snprintf(buf+len, sizeof(buf)-len, | |
333 | "%10s %c 0x%08x - %s\n", dbg_info[i].name, | |
334 | sc->debug.level & dbg_info[i].level ? '+' : ' ', | |
335 | dbg_info[i].level, dbg_info[i].desc); | |
336 | } | |
337 | len += snprintf(buf+len, sizeof(buf)-len, | |
338 | "%10s %c 0x%08x - %s\n", dbg_info[i].name, | |
339 | sc->debug.level == dbg_info[i].level ? '+' : ' ', | |
340 | dbg_info[i].level, dbg_info[i].desc); | |
341 | ||
2189d13f DC |
342 | if (len > sizeof(buf)) |
343 | len = sizeof(buf); | |
344 | ||
be9b7259 BR |
345 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
346 | } | |
347 | ||
348 | static ssize_t write_file_debug(struct file *file, | |
349 | const char __user *userbuf, | |
350 | size_t count, loff_t *ppos) | |
351 | { | |
352 | struct ath5k_softc *sc = file->private_data; | |
353 | unsigned int i; | |
354 | char buf[20]; | |
355 | ||
356 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | |
357 | return -EFAULT; | |
358 | ||
359 | for (i = 0; i < ARRAY_SIZE(dbg_info); i++) { | |
360 | if (strncmp(buf, dbg_info[i].name, | |
361 | strlen(dbg_info[i].name)) == 0) { | |
362 | sc->debug.level ^= dbg_info[i].level; /* toggle bit */ | |
363 | break; | |
364 | } | |
365 | } | |
366 | return count; | |
367 | } | |
368 | ||
369 | static const struct file_operations fops_debug = { | |
370 | .read = read_file_debug, | |
371 | .write = write_file_debug, | |
372 | .open = ath5k_debugfs_open, | |
373 | .owner = THIS_MODULE, | |
6038f373 | 374 | .llseek = default_llseek, |
be9b7259 BR |
375 | }; |
376 | ||
377 | ||
604eeadd BR |
378 | /* debugfs: antenna */ |
379 | ||
380 | static ssize_t read_file_antenna(struct file *file, char __user *user_buf, | |
381 | size_t count, loff_t *ppos) | |
382 | { | |
383 | struct ath5k_softc *sc = file->private_data; | |
384 | char buf[700]; | |
385 | unsigned int len = 0; | |
386 | unsigned int i; | |
387 | unsigned int v; | |
388 | ||
389 | len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n", | |
390 | sc->ah->ah_ant_mode); | |
391 | len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n", | |
392 | sc->ah->ah_def_ant); | |
393 | len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n", | |
394 | sc->ah->ah_tx_ant); | |
395 | ||
396 | len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n"); | |
397 | for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) { | |
398 | len += snprintf(buf+len, sizeof(buf)-len, | |
399 | "[antenna %d]\t%d\t%d\n", | |
400 | i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]); | |
401 | } | |
402 | len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n", | |
403 | sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]); | |
404 | ||
405 | v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA); | |
406 | len += snprintf(buf+len, sizeof(buf)-len, | |
407 | "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v); | |
408 | ||
409 | v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1); | |
410 | len += snprintf(buf+len, sizeof(buf)-len, | |
411 | "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n", | |
412 | (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0); | |
413 | len += snprintf(buf+len, sizeof(buf)-len, | |
414 | "AR5K_STA_ID1_DESC_ANTENNA\t%d\n", | |
415 | (v & AR5K_STA_ID1_DESC_ANTENNA) != 0); | |
416 | len += snprintf(buf+len, sizeof(buf)-len, | |
417 | "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n", | |
418 | (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0); | |
419 | len += snprintf(buf+len, sizeof(buf)-len, | |
420 | "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n", | |
421 | (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0); | |
422 | ||
423 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL); | |
424 | len += snprintf(buf+len, sizeof(buf)-len, | |
425 | "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n", | |
426 | (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0); | |
427 | ||
428 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART); | |
429 | len += snprintf(buf+len, sizeof(buf)-len, | |
430 | "AR5K_PHY_RESTART_DIV_GC\t\t%x\n", | |
431 | (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S); | |
432 | ||
433 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV); | |
434 | len += snprintf(buf+len, sizeof(buf)-len, | |
435 | "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n", | |
436 | (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0); | |
437 | ||
0ca74027 BR |
438 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_0); |
439 | len += snprintf(buf+len, sizeof(buf)-len, | |
440 | "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v); | |
441 | v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_1); | |
442 | len += snprintf(buf+len, sizeof(buf)-len, | |
443 | "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v); | |
444 | ||
2189d13f DC |
445 | if (len > sizeof(buf)) |
446 | len = sizeof(buf); | |
447 | ||
604eeadd BR |
448 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
449 | } | |
450 | ||
451 | static ssize_t write_file_antenna(struct file *file, | |
452 | const char __user *userbuf, | |
453 | size_t count, loff_t *ppos) | |
454 | { | |
455 | struct ath5k_softc *sc = file->private_data; | |
456 | unsigned int i; | |
457 | char buf[20]; | |
458 | ||
459 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | |
460 | return -EFAULT; | |
461 | ||
462 | if (strncmp(buf, "diversity", 9) == 0) { | |
463 | ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT); | |
464 | printk(KERN_INFO "ath5k debug: enable diversity\n"); | |
465 | } else if (strncmp(buf, "fixed-a", 7) == 0) { | |
466 | ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A); | |
467 | printk(KERN_INFO "ath5k debugfs: fixed antenna A\n"); | |
468 | } else if (strncmp(buf, "fixed-b", 7) == 0) { | |
469 | ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B); | |
470 | printk(KERN_INFO "ath5k debug: fixed antenna B\n"); | |
471 | } else if (strncmp(buf, "clear", 5) == 0) { | |
472 | for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) { | |
473 | sc->stats.antenna_rx[i] = 0; | |
474 | sc->stats.antenna_tx[i] = 0; | |
475 | } | |
476 | printk(KERN_INFO "ath5k debug: cleared antenna stats\n"); | |
477 | } | |
478 | return count; | |
479 | } | |
480 | ||
481 | static const struct file_operations fops_antenna = { | |
482 | .read = read_file_antenna, | |
483 | .write = write_file_antenna, | |
484 | .open = ath5k_debugfs_open, | |
485 | .owner = THIS_MODULE, | |
6038f373 | 486 | .llseek = default_llseek, |
604eeadd BR |
487 | }; |
488 | ||
87fd2e6c BG |
489 | /* debugfs: misc */ |
490 | ||
491 | static ssize_t read_file_misc(struct file *file, char __user *user_buf, | |
492 | size_t count, loff_t *ppos) | |
493 | { | |
494 | struct ath5k_softc *sc = file->private_data; | |
495 | char buf[700]; | |
496 | unsigned int len = 0; | |
497 | u32 filt = ath5k_hw_get_rx_filter(sc->ah); | |
498 | ||
499 | len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n", | |
500 | sc->bssidmask); | |
501 | len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ", | |
502 | filt); | |
503 | if (filt & AR5K_RX_FILTER_UCAST) | |
504 | len += snprintf(buf+len, sizeof(buf)-len, " UCAST"); | |
505 | if (filt & AR5K_RX_FILTER_MCAST) | |
506 | len += snprintf(buf+len, sizeof(buf)-len, " MCAST"); | |
507 | if (filt & AR5K_RX_FILTER_BCAST) | |
508 | len += snprintf(buf+len, sizeof(buf)-len, " BCAST"); | |
509 | if (filt & AR5K_RX_FILTER_CONTROL) | |
510 | len += snprintf(buf+len, sizeof(buf)-len, " CONTROL"); | |
511 | if (filt & AR5K_RX_FILTER_BEACON) | |
512 | len += snprintf(buf+len, sizeof(buf)-len, " BEACON"); | |
513 | if (filt & AR5K_RX_FILTER_PROM) | |
514 | len += snprintf(buf+len, sizeof(buf)-len, " PROM"); | |
515 | if (filt & AR5K_RX_FILTER_XRPOLL) | |
516 | len += snprintf(buf+len, sizeof(buf)-len, " XRPOLL"); | |
517 | if (filt & AR5K_RX_FILTER_PROBEREQ) | |
518 | len += snprintf(buf+len, sizeof(buf)-len, " PROBEREQ"); | |
519 | if (filt & AR5K_RX_FILTER_PHYERR_5212) | |
520 | len += snprintf(buf+len, sizeof(buf)-len, " PHYERR-5212"); | |
521 | if (filt & AR5K_RX_FILTER_RADARERR_5212) | |
522 | len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5212"); | |
523 | if (filt & AR5K_RX_FILTER_PHYERR_5211) | |
524 | snprintf(buf+len, sizeof(buf)-len, " PHYERR-5211"); | |
525 | if (filt & AR5K_RX_FILTER_RADARERR_5211) | |
908ebfb9 JP |
526 | len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5211"); |
527 | ||
528 | len += snprintf(buf+len, sizeof(buf)-len, "\nopmode: %s (%d)\n", | |
529 | ath_opmode_to_string(sc->opmode), sc->opmode); | |
92c68a66 | 530 | |
87fd2e6c BG |
531 | if (len > sizeof(buf)) |
532 | len = sizeof(buf); | |
533 | ||
534 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
535 | } | |
536 | ||
537 | static const struct file_operations fops_misc = { | |
538 | .read = read_file_misc, | |
539 | .open = ath5k_debugfs_open, | |
540 | .owner = THIS_MODULE, | |
541 | }; | |
542 | ||
604eeadd | 543 | |
7644395f BR |
544 | /* debugfs: frameerrors */ |
545 | ||
546 | static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf, | |
547 | size_t count, loff_t *ppos) | |
548 | { | |
549 | struct ath5k_softc *sc = file->private_data; | |
550 | struct ath5k_statistics *st = &sc->stats; | |
551 | char buf[700]; | |
552 | unsigned int len = 0; | |
da35111a | 553 | int i; |
7644395f BR |
554 | |
555 | len += snprintf(buf+len, sizeof(buf)-len, | |
556 | "RX\n---------------------\n"); | |
5d882c97 | 557 | len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%u\t(%u%%)\n", |
7644395f BR |
558 | st->rxerr_crc, |
559 | st->rx_all_count > 0 ? | |
560 | st->rxerr_crc*100/st->rx_all_count : 0); | |
5d882c97 | 561 | len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%u\t(%u%%)\n", |
7644395f BR |
562 | st->rxerr_phy, |
563 | st->rx_all_count > 0 ? | |
564 | st->rxerr_phy*100/st->rx_all_count : 0); | |
da35111a BR |
565 | for (i = 0; i < 32; i++) { |
566 | if (st->rxerr_phy_code[i]) | |
567 | len += snprintf(buf+len, sizeof(buf)-len, | |
5d882c97 | 568 | " phy_err[%u]\t%u\n", |
da35111a BR |
569 | i, st->rxerr_phy_code[i]); |
570 | } | |
571 | ||
5d882c97 | 572 | len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%u\t(%u%%)\n", |
7644395f BR |
573 | st->rxerr_fifo, |
574 | st->rx_all_count > 0 ? | |
575 | st->rxerr_fifo*100/st->rx_all_count : 0); | |
5d882c97 | 576 | len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%u\t(%u%%)\n", |
7644395f BR |
577 | st->rxerr_decrypt, |
578 | st->rx_all_count > 0 ? | |
579 | st->rxerr_decrypt*100/st->rx_all_count : 0); | |
5d882c97 | 580 | len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%u\t(%u%%)\n", |
7644395f BR |
581 | st->rxerr_mic, |
582 | st->rx_all_count > 0 ? | |
583 | st->rxerr_mic*100/st->rx_all_count : 0); | |
5d882c97 | 584 | len += snprintf(buf+len, sizeof(buf)-len, "process\t%u\t(%u%%)\n", |
7644395f BR |
585 | st->rxerr_proc, |
586 | st->rx_all_count > 0 ? | |
587 | st->rxerr_proc*100/st->rx_all_count : 0); | |
5d882c97 | 588 | len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%u\t(%u%%)\n", |
7644395f BR |
589 | st->rxerr_jumbo, |
590 | st->rx_all_count > 0 ? | |
591 | st->rxerr_jumbo*100/st->rx_all_count : 0); | |
5d882c97 | 592 | len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%u]\n", |
7644395f | 593 | st->rx_all_count); |
5d882c97 | 594 | len += snprintf(buf+len, sizeof(buf)-len, "RX-all-bytes\t%u\n", |
b72acddb | 595 | st->rx_bytes_count); |
7644395f BR |
596 | |
597 | len += snprintf(buf+len, sizeof(buf)-len, | |
598 | "\nTX\n---------------------\n"); | |
5d882c97 | 599 | len += snprintf(buf+len, sizeof(buf)-len, "retry\t%u\t(%u%%)\n", |
7644395f BR |
600 | st->txerr_retry, |
601 | st->tx_all_count > 0 ? | |
602 | st->txerr_retry*100/st->tx_all_count : 0); | |
5d882c97 | 603 | len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%u\t(%u%%)\n", |
7644395f BR |
604 | st->txerr_fifo, |
605 | st->tx_all_count > 0 ? | |
606 | st->txerr_fifo*100/st->tx_all_count : 0); | |
5d882c97 | 607 | len += snprintf(buf+len, sizeof(buf)-len, "filter\t%u\t(%u%%)\n", |
7644395f BR |
608 | st->txerr_filt, |
609 | st->tx_all_count > 0 ? | |
610 | st->txerr_filt*100/st->tx_all_count : 0); | |
5d882c97 | 611 | len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%u]\n", |
7644395f | 612 | st->tx_all_count); |
5d882c97 | 613 | len += snprintf(buf+len, sizeof(buf)-len, "TX-all-bytes\t%u\n", |
b72acddb | 614 | st->tx_bytes_count); |
7644395f | 615 | |
2189d13f DC |
616 | if (len > sizeof(buf)) |
617 | len = sizeof(buf); | |
618 | ||
7644395f BR |
619 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
620 | } | |
621 | ||
622 | static ssize_t write_file_frameerrors(struct file *file, | |
623 | const char __user *userbuf, | |
624 | size_t count, loff_t *ppos) | |
625 | { | |
626 | struct ath5k_softc *sc = file->private_data; | |
627 | struct ath5k_statistics *st = &sc->stats; | |
628 | char buf[20]; | |
629 | ||
630 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | |
631 | return -EFAULT; | |
632 | ||
633 | if (strncmp(buf, "clear", 5) == 0) { | |
634 | st->rxerr_crc = 0; | |
635 | st->rxerr_phy = 0; | |
636 | st->rxerr_fifo = 0; | |
637 | st->rxerr_decrypt = 0; | |
638 | st->rxerr_mic = 0; | |
639 | st->rxerr_proc = 0; | |
640 | st->rxerr_jumbo = 0; | |
641 | st->rx_all_count = 0; | |
642 | st->txerr_retry = 0; | |
643 | st->txerr_fifo = 0; | |
644 | st->txerr_filt = 0; | |
645 | st->tx_all_count = 0; | |
646 | printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n"); | |
647 | } | |
648 | return count; | |
649 | } | |
650 | ||
651 | static const struct file_operations fops_frameerrors = { | |
652 | .read = read_file_frameerrors, | |
653 | .write = write_file_frameerrors, | |
654 | .open = ath5k_debugfs_open, | |
655 | .owner = THIS_MODULE, | |
6038f373 | 656 | .llseek = default_llseek, |
7644395f BR |
657 | }; |
658 | ||
659 | ||
2111ac0d BR |
660 | /* debugfs: ani */ |
661 | ||
662 | static ssize_t read_file_ani(struct file *file, char __user *user_buf, | |
663 | size_t count, loff_t *ppos) | |
664 | { | |
665 | struct ath5k_softc *sc = file->private_data; | |
666 | struct ath5k_statistics *st = &sc->stats; | |
667 | struct ath5k_ani_state *as = &sc->ani_state; | |
668 | ||
669 | char buf[700]; | |
670 | unsigned int len = 0; | |
671 | ||
672 | len += snprintf(buf+len, sizeof(buf)-len, | |
673 | "HW has PHY error counters:\t%s\n", | |
674 | sc->ah->ah_capabilities.cap_has_phyerr_counters ? | |
675 | "yes" : "no"); | |
676 | len += snprintf(buf+len, sizeof(buf)-len, | |
677 | "HW max spur immunity level:\t%d\n", | |
678 | as->max_spur_level); | |
679 | len += snprintf(buf+len, sizeof(buf)-len, | |
680 | "\nANI state\n--------------------------------------------\n"); | |
681 | len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t"); | |
682 | switch (as->ani_mode) { | |
683 | case ATH5K_ANI_MODE_OFF: | |
684 | len += snprintf(buf+len, sizeof(buf)-len, "OFF\n"); | |
685 | break; | |
686 | case ATH5K_ANI_MODE_MANUAL_LOW: | |
687 | len += snprintf(buf+len, sizeof(buf)-len, | |
688 | "MANUAL LOW\n"); | |
689 | break; | |
690 | case ATH5K_ANI_MODE_MANUAL_HIGH: | |
691 | len += snprintf(buf+len, sizeof(buf)-len, | |
692 | "MANUAL HIGH\n"); | |
693 | break; | |
694 | case ATH5K_ANI_MODE_AUTO: | |
695 | len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n"); | |
696 | break; | |
697 | default: | |
698 | len += snprintf(buf+len, sizeof(buf)-len, | |
699 | "??? (not good)\n"); | |
700 | break; | |
701 | } | |
702 | len += snprintf(buf+len, sizeof(buf)-len, | |
703 | "noise immunity level:\t\t%d\n", | |
704 | as->noise_imm_level); | |
705 | len += snprintf(buf+len, sizeof(buf)-len, | |
706 | "spur immunity level:\t\t%d\n", | |
707 | as->spur_level); | |
708 | len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n", | |
709 | as->firstep_level); | |
710 | len += snprintf(buf+len, sizeof(buf)-len, | |
711 | "OFDM weak signal detection:\t%s\n", | |
712 | as->ofdm_weak_sig ? "on" : "off"); | |
713 | len += snprintf(buf+len, sizeof(buf)-len, | |
714 | "CCK weak signal detection:\t%s\n", | |
715 | as->cck_weak_sig ? "on" : "off"); | |
716 | ||
717 | len += snprintf(buf+len, sizeof(buf)-len, | |
718 | "\nMIB INTERRUPTS:\t\t%u\n", | |
719 | st->mib_intr); | |
720 | len += snprintf(buf+len, sizeof(buf)-len, | |
721 | "beacon RSSI average:\t%d\n", | |
722 | sc->ah->ah_beacon_rssi_avg.avg); | |
7109ca5c FF |
723 | |
724 | #define CC_PRINT(_struct, _field) \ | |
725 | _struct._field, \ | |
726 | _struct.cycles > 0 ? \ | |
727 | _struct._field*100/_struct.cycles : 0 | |
728 | ||
2111ac0d | 729 | len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n", |
7109ca5c | 730 | CC_PRINT(as->last_cc, tx_frame)); |
2111ac0d | 731 | len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n", |
7109ca5c | 732 | CC_PRINT(as->last_cc, rx_frame)); |
2111ac0d | 733 | len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n", |
7109ca5c FF |
734 | CC_PRINT(as->last_cc, rx_busy)); |
735 | #undef CC_PRINT | |
2111ac0d | 736 | len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n", |
7109ca5c | 737 | as->last_cc.cycles); |
2111ac0d BR |
738 | len += snprintf(buf+len, sizeof(buf)-len, |
739 | "listen time\t\t%d\tlast: %d\n", | |
740 | as->listen_time, as->last_listen); | |
741 | len += snprintf(buf+len, sizeof(buf)-len, | |
742 | "OFDM errors\t\t%u\tlast: %u\tsum: %u\n", | |
743 | as->ofdm_errors, as->last_ofdm_errors, | |
744 | as->sum_ofdm_errors); | |
745 | len += snprintf(buf+len, sizeof(buf)-len, | |
746 | "CCK errors\t\t%u\tlast: %u\tsum: %u\n", | |
747 | as->cck_errors, as->last_cck_errors, | |
748 | as->sum_cck_errors); | |
749 | len += snprintf(buf+len, sizeof(buf)-len, | |
750 | "AR5K_PHYERR_CNT1\t%x\t(=%d)\n", | |
751 | ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1), | |
752 | ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX - | |
753 | ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1))); | |
754 | len += snprintf(buf+len, sizeof(buf)-len, | |
755 | "AR5K_PHYERR_CNT2\t%x\t(=%d)\n", | |
756 | ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2), | |
757 | ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX - | |
758 | ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2))); | |
759 | ||
2189d13f DC |
760 | if (len > sizeof(buf)) |
761 | len = sizeof(buf); | |
762 | ||
2111ac0d BR |
763 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
764 | } | |
765 | ||
766 | static ssize_t write_file_ani(struct file *file, | |
767 | const char __user *userbuf, | |
768 | size_t count, loff_t *ppos) | |
769 | { | |
770 | struct ath5k_softc *sc = file->private_data; | |
771 | char buf[20]; | |
772 | ||
773 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | |
774 | return -EFAULT; | |
775 | ||
776 | if (strncmp(buf, "sens-low", 8) == 0) { | |
777 | ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH); | |
778 | } else if (strncmp(buf, "sens-high", 9) == 0) { | |
779 | ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW); | |
780 | } else if (strncmp(buf, "ani-off", 7) == 0) { | |
781 | ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF); | |
782 | } else if (strncmp(buf, "ani-on", 6) == 0) { | |
783 | ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO); | |
784 | } else if (strncmp(buf, "noise-low", 9) == 0) { | |
785 | ath5k_ani_set_noise_immunity_level(sc->ah, 0); | |
786 | } else if (strncmp(buf, "noise-high", 10) == 0) { | |
787 | ath5k_ani_set_noise_immunity_level(sc->ah, | |
788 | ATH5K_ANI_MAX_NOISE_IMM_LVL); | |
789 | } else if (strncmp(buf, "spur-low", 8) == 0) { | |
790 | ath5k_ani_set_spur_immunity_level(sc->ah, 0); | |
791 | } else if (strncmp(buf, "spur-high", 9) == 0) { | |
792 | ath5k_ani_set_spur_immunity_level(sc->ah, | |
793 | sc->ani_state.max_spur_level); | |
794 | } else if (strncmp(buf, "fir-low", 7) == 0) { | |
795 | ath5k_ani_set_firstep_level(sc->ah, 0); | |
796 | } else if (strncmp(buf, "fir-high", 8) == 0) { | |
797 | ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL); | |
798 | } else if (strncmp(buf, "ofdm-off", 8) == 0) { | |
799 | ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false); | |
800 | } else if (strncmp(buf, "ofdm-on", 7) == 0) { | |
801 | ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true); | |
802 | } else if (strncmp(buf, "cck-off", 7) == 0) { | |
803 | ath5k_ani_set_cck_weak_signal_detection(sc->ah, false); | |
804 | } else if (strncmp(buf, "cck-on", 6) == 0) { | |
805 | ath5k_ani_set_cck_weak_signal_detection(sc->ah, true); | |
806 | } | |
807 | return count; | |
808 | } | |
809 | ||
810 | static const struct file_operations fops_ani = { | |
811 | .read = read_file_ani, | |
812 | .write = write_file_ani, | |
813 | .open = ath5k_debugfs_open, | |
814 | .owner = THIS_MODULE, | |
6038f373 | 815 | .llseek = default_llseek, |
2111ac0d BR |
816 | }; |
817 | ||
818 | ||
3cfd43f4 BR |
819 | /* debugfs: queues etc */ |
820 | ||
821 | static ssize_t read_file_queue(struct file *file, char __user *user_buf, | |
822 | size_t count, loff_t *ppos) | |
823 | { | |
824 | struct ath5k_softc *sc = file->private_data; | |
825 | char buf[700]; | |
826 | unsigned int len = 0; | |
827 | ||
828 | struct ath5k_txq *txq; | |
829 | struct ath5k_buf *bf, *bf0; | |
cfddc11c | 830 | int i, n; |
3cfd43f4 BR |
831 | |
832 | len += snprintf(buf+len, sizeof(buf)-len, | |
833 | "available txbuffers: %d\n", sc->txbuf_len); | |
834 | ||
835 | for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) { | |
836 | txq = &sc->txqs[i]; | |
837 | ||
838 | len += snprintf(buf+len, sizeof(buf)-len, | |
839 | "%02d: %ssetup\n", i, txq->setup ? "" : "not "); | |
840 | ||
841 | if (!txq->setup) | |
842 | continue; | |
843 | ||
cfddc11c BR |
844 | n = 0; |
845 | spin_lock_bh(&txq->lock); | |
3cfd43f4 BR |
846 | list_for_each_entry_safe(bf, bf0, &txq->q, list) |
847 | n++; | |
cfddc11c BR |
848 | spin_unlock_bh(&txq->lock); |
849 | ||
850 | len += snprintf(buf+len, sizeof(buf)-len, | |
851 | " len: %d bufs: %d\n", txq->txq_len, n); | |
923e5b3d BR |
852 | len += snprintf(buf+len, sizeof(buf)-len, |
853 | " stuck: %d\n", txq->txq_stuck); | |
3cfd43f4 BR |
854 | } |
855 | ||
2189d13f DC |
856 | if (len > sizeof(buf)) |
857 | len = sizeof(buf); | |
858 | ||
3cfd43f4 BR |
859 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
860 | } | |
861 | ||
862 | static ssize_t write_file_queue(struct file *file, | |
863 | const char __user *userbuf, | |
864 | size_t count, loff_t *ppos) | |
865 | { | |
866 | struct ath5k_softc *sc = file->private_data; | |
867 | char buf[20]; | |
868 | ||
869 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | |
870 | return -EFAULT; | |
871 | ||
872 | if (strncmp(buf, "start", 5) == 0) | |
873 | ieee80211_wake_queues(sc->hw); | |
874 | else if (strncmp(buf, "stop", 4) == 0) | |
875 | ieee80211_stop_queues(sc->hw); | |
876 | ||
877 | return count; | |
878 | } | |
879 | ||
880 | ||
881 | static const struct file_operations fops_queue = { | |
882 | .read = read_file_queue, | |
883 | .write = write_file_queue, | |
884 | .open = ath5k_debugfs_open, | |
885 | .owner = THIS_MODULE, | |
6038f373 | 886 | .llseek = default_llseek, |
3cfd43f4 BR |
887 | }; |
888 | ||
889 | ||
fa1c114f JS |
890 | void |
891 | ath5k_debug_init_device(struct ath5k_softc *sc) | |
892 | { | |
893 | sc->debug.level = ath5k_debug; | |
be9b7259 | 894 | |
d84a35d1 BG |
895 | sc->debug.debugfs_phydir = debugfs_create_dir("ath5k", |
896 | sc->hw->wiphy->debugfsdir); | |
be9b7259 | 897 | |
31670070 JS |
898 | sc->debug.debugfs_debug = debugfs_create_file("debug", |
899 | S_IWUSR | S_IRUSR, | |
be9b7259 | 900 | sc->debug.debugfs_phydir, sc, &fops_debug); |
fa1c114f | 901 | |
31670070 | 902 | sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR, |
be9b7259 | 903 | sc->debug.debugfs_phydir, sc, &fops_registers); |
fa1c114f | 904 | |
31670070 JS |
905 | sc->debug.debugfs_beacon = debugfs_create_file("beacon", |
906 | S_IWUSR | S_IRUSR, | |
be9b7259 | 907 | sc->debug.debugfs_phydir, sc, &fops_beacon); |
fa1c114f | 908 | |
33ab625f | 909 | sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR, |
be9b7259 | 910 | sc->debug.debugfs_phydir, sc, &fops_reset); |
604eeadd BR |
911 | |
912 | sc->debug.debugfs_antenna = debugfs_create_file("antenna", | |
913 | S_IWUSR | S_IRUSR, | |
914 | sc->debug.debugfs_phydir, sc, &fops_antenna); | |
7644395f | 915 | |
87fd2e6c BG |
916 | sc->debug.debugfs_misc = debugfs_create_file("misc", |
917 | S_IRUSR, | |
918 | sc->debug.debugfs_phydir, sc, &fops_misc); | |
919 | ||
7644395f BR |
920 | sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors", |
921 | S_IWUSR | S_IRUSR, | |
922 | sc->debug.debugfs_phydir, sc, | |
923 | &fops_frameerrors); | |
2111ac0d BR |
924 | |
925 | sc->debug.debugfs_ani = debugfs_create_file("ani", | |
926 | S_IWUSR | S_IRUSR, | |
927 | sc->debug.debugfs_phydir, sc, | |
928 | &fops_ani); | |
3cfd43f4 BR |
929 | |
930 | sc->debug.debugfs_queue = debugfs_create_file("queue", | |
931 | S_IWUSR | S_IRUSR, | |
932 | sc->debug.debugfs_phydir, sc, | |
933 | &fops_queue); | |
fa1c114f JS |
934 | } |
935 | ||
fa1c114f JS |
936 | void |
937 | ath5k_debug_finish_device(struct ath5k_softc *sc) | |
938 | { | |
939 | debugfs_remove(sc->debug.debugfs_debug); | |
940 | debugfs_remove(sc->debug.debugfs_registers); | |
fa1c114f JS |
941 | debugfs_remove(sc->debug.debugfs_beacon); |
942 | debugfs_remove(sc->debug.debugfs_reset); | |
604eeadd | 943 | debugfs_remove(sc->debug.debugfs_antenna); |
87fd2e6c | 944 | debugfs_remove(sc->debug.debugfs_misc); |
7644395f | 945 | debugfs_remove(sc->debug.debugfs_frameerrors); |
2111ac0d | 946 | debugfs_remove(sc->debug.debugfs_ani); |
3cfd43f4 | 947 | debugfs_remove(sc->debug.debugfs_queue); |
fa1c114f JS |
948 | debugfs_remove(sc->debug.debugfs_phydir); |
949 | } | |
950 | ||
951 | ||
952 | /* functions used in other places */ | |
953 | ||
954 | void | |
b446197c | 955 | ath5k_debug_dump_bands(struct ath5k_softc *sc) |
fa1c114f | 956 | { |
b446197c | 957 | unsigned int b, i; |
fa1c114f | 958 | |
b446197c | 959 | if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS))) |
fa1c114f JS |
960 | return; |
961 | ||
b446197c LR |
962 | BUG_ON(!sc->sbands); |
963 | ||
964 | for (b = 0; b < IEEE80211_NUM_BANDS; b++) { | |
965 | struct ieee80211_supported_band *band = &sc->sbands[b]; | |
b7fcb5c4 | 966 | char bname[6]; |
b446197c LR |
967 | switch (band->band) { |
968 | case IEEE80211_BAND_2GHZ: | |
969 | strcpy(bname, "2 GHz"); | |
970 | break; | |
971 | case IEEE80211_BAND_5GHZ: | |
972 | strcpy(bname, "5 GHz"); | |
973 | break; | |
974 | default: | |
975 | printk(KERN_DEBUG "Band not supported: %d\n", | |
976 | band->band); | |
977 | return; | |
978 | } | |
979 | printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname, | |
980 | band->n_channels, band->n_bitrates); | |
fa1c114f | 981 | printk(KERN_DEBUG " channels:\n"); |
b446197c | 982 | for (i = 0; i < band->n_channels; i++) |
fa1c114f | 983 | printk(KERN_DEBUG " %3d %d %.4x %.4x\n", |
b446197c LR |
984 | ieee80211_frequency_to_channel( |
985 | band->channels[i].center_freq), | |
986 | band->channels[i].center_freq, | |
987 | band->channels[i].hw_value, | |
988 | band->channels[i].flags); | |
fa1c114f | 989 | printk(KERN_DEBUG " rates:\n"); |
b446197c | 990 | for (i = 0; i < band->n_bitrates; i++) |
fa1c114f | 991 | printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n", |
b446197c LR |
992 | band->bitrates[i].bitrate, |
993 | band->bitrates[i].hw_value, | |
994 | band->bitrates[i].flags, | |
995 | band->bitrates[i].hw_value_short); | |
fa1c114f JS |
996 | } |
997 | } | |
998 | ||
999 | static inline void | |
b47f407b BR |
1000 | ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done, |
1001 | struct ath5k_rx_status *rs) | |
fa1c114f JS |
1002 | { |
1003 | struct ath5k_desc *ds = bf->desc; | |
19fd6e55 | 1004 | struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx; |
fa1c114f JS |
1005 | |
1006 | printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n", | |
1007 | ds, (unsigned long long)bf->daddr, | |
19fd6e55 BR |
1008 | ds->ds_link, ds->ds_data, |
1009 | rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1, | |
62412a8f | 1010 | rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1, |
b47f407b | 1011 | !done ? ' ' : (rs->rs_status == 0) ? '*' : '!'); |
fa1c114f JS |
1012 | } |
1013 | ||
1014 | void | |
1015 | ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah) | |
1016 | { | |
1017 | struct ath5k_desc *ds; | |
1018 | struct ath5k_buf *bf; | |
b47f407b | 1019 | struct ath5k_rx_status rs = {}; |
fa1c114f JS |
1020 | int status; |
1021 | ||
b4c52612 | 1022 | if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC))) |
fa1c114f JS |
1023 | return; |
1024 | ||
265faadd | 1025 | printk(KERN_DEBUG "rxdp %x, rxlink %p\n", |
c6e387a2 | 1026 | ath5k_hw_get_rxdp(ah), sc->rxlink); |
fa1c114f JS |
1027 | |
1028 | spin_lock_bh(&sc->rxbuflock); | |
1029 | list_for_each_entry(bf, &sc->rxbuf, list) { | |
1030 | ds = bf->desc; | |
b47f407b | 1031 | status = ah->ah_proc_rx_desc(ah, ds, &rs); |
be9b7259 | 1032 | if (!status) |
b47f407b | 1033 | ath5k_debug_printrxbuf(bf, status == 0, &rs); |
fa1c114f JS |
1034 | } |
1035 | spin_unlock_bh(&sc->rxbuflock); | |
1036 | } | |
1037 | ||
1038 | void | |
1039 | ath5k_debug_dump_skb(struct ath5k_softc *sc, | |
1040 | struct sk_buff *skb, const char *prefix, int tx) | |
1041 | { | |
1042 | char buf[16]; | |
1043 | ||
1044 | if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) || | |
1045 | (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX))))) | |
1046 | return; | |
1047 | ||
1048 | snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix); | |
1049 | ||
1050 | print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data, | |
1051 | min(200U, skb->len)); | |
1052 | ||
1053 | printk(KERN_DEBUG "\n"); | |
1054 | } | |
1055 | ||
1056 | void | |
b47f407b | 1057 | ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf) |
fa1c114f JS |
1058 | { |
1059 | struct ath5k_desc *ds = bf->desc; | |
19fd6e55 | 1060 | struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212; |
b47f407b BR |
1061 | struct ath5k_tx_status ts = {}; |
1062 | int done; | |
fa1c114f | 1063 | |
b4c52612 | 1064 | if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC))) |
fa1c114f JS |
1065 | return; |
1066 | ||
b47f407b BR |
1067 | done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts); |
1068 | ||
fa1c114f JS |
1069 | printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x " |
1070 | "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link, | |
19fd6e55 BR |
1071 | ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1, |
1072 | td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3, | |
1073 | td->tx_stat.tx_status_0, td->tx_stat.tx_status_1, | |
b47f407b | 1074 | done ? ' ' : (ts.ts_status == 0) ? '*' : '!'); |
fa1c114f JS |
1075 | } |
1076 | ||
b446197c | 1077 | #endif /* ifdef CONFIG_ATH5K_DEBUG */ |