GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / net / wireless / ath / ath5k / debug.c
blob4cccc29964f6ddd0c7665369b034651d099a90cc
1 /*
2 * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com>
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.
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.
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/>.
18 * This file incorporates work covered by the following copyright and
19 * permission notice:
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>
27 * All rights reserved.
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.
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.
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.
61 #include "base.h"
62 #include "debug.h"
64 static unsigned int ath5k_debug;
65 module_param_named(debug, ath5k_debug, uint, 0);
68 #ifdef CONFIG_ATH5K_DEBUG
70 #include <linux/seq_file.h>
71 #include "reg.h"
72 #include "ani.h"
74 static struct dentry *ath5k_global_debugfs;
76 static int ath5k_debugfs_open(struct inode *inode, struct file *file)
78 file->private_data = inode->i_private;
79 return 0;
83 /* debugfs: registers */
85 struct reg {
86 const char *name;
87 int addr;
90 #define REG_STRUCT_INIT(r) { #r, r }
92 /* just a few random registers, might want to add more */
93 static const struct reg regs[] = {
94 REG_STRUCT_INIT(AR5K_CR),
95 REG_STRUCT_INIT(AR5K_RXDP),
96 REG_STRUCT_INIT(AR5K_CFG),
97 REG_STRUCT_INIT(AR5K_IER),
98 REG_STRUCT_INIT(AR5K_BCR),
99 REG_STRUCT_INIT(AR5K_RTSD0),
100 REG_STRUCT_INIT(AR5K_RTSD1),
101 REG_STRUCT_INIT(AR5K_TXCFG),
102 REG_STRUCT_INIT(AR5K_RXCFG),
103 REG_STRUCT_INIT(AR5K_RXJLA),
104 REG_STRUCT_INIT(AR5K_MIBC),
105 REG_STRUCT_INIT(AR5K_TOPS),
106 REG_STRUCT_INIT(AR5K_RXNOFRM),
107 REG_STRUCT_INIT(AR5K_TXNOFRM),
108 REG_STRUCT_INIT(AR5K_RPGTO),
109 REG_STRUCT_INIT(AR5K_RFCNT),
110 REG_STRUCT_INIT(AR5K_MISC),
111 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
112 REG_STRUCT_INIT(AR5K_ISR),
113 REG_STRUCT_INIT(AR5K_PISR),
114 REG_STRUCT_INIT(AR5K_SISR0),
115 REG_STRUCT_INIT(AR5K_SISR1),
116 REG_STRUCT_INIT(AR5K_SISR2),
117 REG_STRUCT_INIT(AR5K_SISR3),
118 REG_STRUCT_INIT(AR5K_SISR4),
119 REG_STRUCT_INIT(AR5K_IMR),
120 REG_STRUCT_INIT(AR5K_PIMR),
121 REG_STRUCT_INIT(AR5K_SIMR0),
122 REG_STRUCT_INIT(AR5K_SIMR1),
123 REG_STRUCT_INIT(AR5K_SIMR2),
124 REG_STRUCT_INIT(AR5K_SIMR3),
125 REG_STRUCT_INIT(AR5K_SIMR4),
126 REG_STRUCT_INIT(AR5K_DCM_ADDR),
127 REG_STRUCT_INIT(AR5K_DCCFG),
128 REG_STRUCT_INIT(AR5K_CCFG),
129 REG_STRUCT_INIT(AR5K_CPC0),
130 REG_STRUCT_INIT(AR5K_CPC1),
131 REG_STRUCT_INIT(AR5K_CPC2),
132 REG_STRUCT_INIT(AR5K_CPC3),
133 REG_STRUCT_INIT(AR5K_CPCOVF),
134 REG_STRUCT_INIT(AR5K_RESET_CTL),
135 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
136 REG_STRUCT_INIT(AR5K_INTPEND),
137 REG_STRUCT_INIT(AR5K_SFR),
138 REG_STRUCT_INIT(AR5K_PCICFG),
139 REG_STRUCT_INIT(AR5K_GPIOCR),
140 REG_STRUCT_INIT(AR5K_GPIODO),
141 REG_STRUCT_INIT(AR5K_SREV),
144 static void *reg_start(struct seq_file *seq, loff_t *pos)
146 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
149 static void reg_stop(struct seq_file *seq, void *p)
151 /* nothing to do */
154 static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
156 ++*pos;
157 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
160 static int reg_show(struct seq_file *seq, void *p)
162 struct ath5k_softc *sc = seq->private;
163 struct reg *r = p;
164 seq_printf(seq, "%-25s0x%08x\n", r->name,
165 ath5k_hw_reg_read(sc->ah, r->addr));
166 return 0;
169 static const struct seq_operations register_seq_ops = {
170 .start = reg_start,
171 .next = reg_next,
172 .stop = reg_stop,
173 .show = reg_show
176 static int open_file_registers(struct inode *inode, struct file *file)
178 struct seq_file *s;
179 int res;
180 res = seq_open(file, &register_seq_ops);
181 if (res == 0) {
182 s = file->private_data;
183 s->private = inode->i_private;
185 return res;
188 static const struct file_operations fops_registers = {
189 .open = open_file_registers,
190 .read = seq_read,
191 .llseek = seq_lseek,
192 .release = seq_release,
193 .owner = THIS_MODULE,
197 /* debugfs: beacons */
199 static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
200 size_t count, loff_t *ppos)
202 struct ath5k_softc *sc = file->private_data;
203 struct ath5k_hw *ah = sc->ah;
204 char buf[500];
205 unsigned int len = 0;
206 unsigned int v;
207 u64 tsf;
209 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
210 len += snprintf(buf+len, sizeof(buf)-len,
211 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
212 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
213 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
215 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
216 "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
218 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
219 "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
221 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
222 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
223 "AR5K_TIMER0 (TBTT)", v, v);
225 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
226 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
227 "AR5K_TIMER1 (DMA)", v, v >> 3);
229 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
230 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
231 "AR5K_TIMER2 (SWBA)", v, v >> 3);
233 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
234 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
235 "AR5K_TIMER3 (ATIM)", v, v);
237 tsf = ath5k_hw_get_tsf64(sc->ah);
238 len += snprintf(buf+len, sizeof(buf)-len,
239 "TSF\t\t0x%016llx\tTU: %08x\n",
240 (unsigned long long)tsf, TSF_TO_TU(tsf));
242 if (len > sizeof(buf))
243 len = sizeof(buf);
245 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
248 static ssize_t write_file_beacon(struct file *file,
249 const char __user *userbuf,
250 size_t count, loff_t *ppos)
252 struct ath5k_softc *sc = file->private_data;
253 struct ath5k_hw *ah = sc->ah;
254 char buf[20];
256 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
257 return -EFAULT;
259 if (strncmp(buf, "disable", 7) == 0) {
260 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
261 printk(KERN_INFO "debugfs disable beacons\n");
262 } else if (strncmp(buf, "enable", 6) == 0) {
263 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
264 printk(KERN_INFO "debugfs enable beacons\n");
266 return count;
269 static const struct file_operations fops_beacon = {
270 .read = read_file_beacon,
271 .write = write_file_beacon,
272 .open = ath5k_debugfs_open,
273 .owner = THIS_MODULE,
277 /* debugfs: reset */
279 static ssize_t write_file_reset(struct file *file,
280 const char __user *userbuf,
281 size_t count, loff_t *ppos)
283 struct ath5k_softc *sc = file->private_data;
284 ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
285 ieee80211_queue_work(sc->hw, &sc->reset_work);
286 return count;
289 static const struct file_operations fops_reset = {
290 .write = write_file_reset,
291 .open = ath5k_debugfs_open,
292 .owner = THIS_MODULE,
296 /* debugfs: debug level */
298 static const struct {
299 enum ath5k_debug_level level;
300 const char *name;
301 const char *desc;
302 } dbg_info[] = {
303 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
304 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
305 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
306 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
307 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
308 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
309 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
310 { ATH5K_DEBUG_LED, "led", "LED management" },
311 { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
312 { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
313 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
314 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
315 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
318 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
319 size_t count, loff_t *ppos)
321 struct ath5k_softc *sc = file->private_data;
322 char buf[700];
323 unsigned int len = 0;
324 unsigned int i;
326 len += snprintf(buf+len, sizeof(buf)-len,
327 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
329 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
330 len += snprintf(buf+len, sizeof(buf)-len,
331 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
332 sc->debug.level & dbg_info[i].level ? '+' : ' ',
333 dbg_info[i].level, dbg_info[i].desc);
335 len += snprintf(buf+len, sizeof(buf)-len,
336 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
337 sc->debug.level == dbg_info[i].level ? '+' : ' ',
338 dbg_info[i].level, dbg_info[i].desc);
340 if (len > sizeof(buf))
341 len = sizeof(buf);
343 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
346 static ssize_t write_file_debug(struct file *file,
347 const char __user *userbuf,
348 size_t count, loff_t *ppos)
350 struct ath5k_softc *sc = file->private_data;
351 unsigned int i;
352 char buf[20];
354 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
355 return -EFAULT;
357 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
358 if (strncmp(buf, dbg_info[i].name,
359 strlen(dbg_info[i].name)) == 0) {
360 sc->debug.level ^= dbg_info[i].level; /* toggle bit */
361 break;
364 return count;
367 static const struct file_operations fops_debug = {
368 .read = read_file_debug,
369 .write = write_file_debug,
370 .open = ath5k_debugfs_open,
371 .owner = THIS_MODULE,
375 /* debugfs: antenna */
377 static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
378 size_t count, loff_t *ppos)
380 struct ath5k_softc *sc = file->private_data;
381 char buf[700];
382 unsigned int len = 0;
383 unsigned int i;
384 unsigned int v;
386 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
387 sc->ah->ah_ant_mode);
388 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
389 sc->ah->ah_def_ant);
390 len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
391 sc->ah->ah_tx_ant);
393 len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
394 for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
395 len += snprintf(buf+len, sizeof(buf)-len,
396 "[antenna %d]\t%d\t%d\n",
397 i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
399 len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
400 sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);
402 v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
403 len += snprintf(buf+len, sizeof(buf)-len,
404 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
406 v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1);
407 len += snprintf(buf+len, sizeof(buf)-len,
408 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
409 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
410 len += snprintf(buf+len, sizeof(buf)-len,
411 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
412 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
413 len += snprintf(buf+len, sizeof(buf)-len,
414 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
415 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
416 len += snprintf(buf+len, sizeof(buf)-len,
417 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
418 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
420 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL);
421 len += snprintf(buf+len, sizeof(buf)-len,
422 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
423 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
425 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART);
426 len += snprintf(buf+len, sizeof(buf)-len,
427 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
428 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
430 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV);
431 len += snprintf(buf+len, sizeof(buf)-len,
432 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
433 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
435 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
436 len += snprintf(buf+len, sizeof(buf)-len,
437 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
438 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
439 len += snprintf(buf+len, sizeof(buf)-len,
440 "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v);
442 if (len > sizeof(buf))
443 len = sizeof(buf);
445 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
448 static ssize_t write_file_antenna(struct file *file,
449 const char __user *userbuf,
450 size_t count, loff_t *ppos)
452 struct ath5k_softc *sc = file->private_data;
453 unsigned int i;
454 char buf[20];
456 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
457 return -EFAULT;
459 if (strncmp(buf, "diversity", 9) == 0) {
460 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
461 printk(KERN_INFO "ath5k debug: enable diversity\n");
462 } else if (strncmp(buf, "fixed-a", 7) == 0) {
463 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
464 printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
465 } else if (strncmp(buf, "fixed-b", 7) == 0) {
466 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
467 printk(KERN_INFO "ath5k debug: fixed antenna B\n");
468 } else if (strncmp(buf, "clear", 5) == 0) {
469 for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
470 sc->stats.antenna_rx[i] = 0;
471 sc->stats.antenna_tx[i] = 0;
473 printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
475 return count;
478 static const struct file_operations fops_antenna = {
479 .read = read_file_antenna,
480 .write = write_file_antenna,
481 .open = ath5k_debugfs_open,
482 .owner = THIS_MODULE,
486 /* debugfs: frameerrors */
488 static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
489 size_t count, loff_t *ppos)
491 struct ath5k_softc *sc = file->private_data;
492 struct ath5k_statistics *st = &sc->stats;
493 char buf[700];
494 unsigned int len = 0;
495 int i;
497 len += snprintf(buf+len, sizeof(buf)-len,
498 "RX\n---------------------\n");
499 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
500 st->rxerr_crc,
501 st->rx_all_count > 0 ?
502 st->rxerr_crc*100/st->rx_all_count : 0);
503 len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
504 st->rxerr_phy,
505 st->rx_all_count > 0 ?
506 st->rxerr_phy*100/st->rx_all_count : 0);
507 for (i = 0; i < 32; i++) {
508 if (st->rxerr_phy_code[i])
509 len += snprintf(buf+len, sizeof(buf)-len,
510 " phy_err[%d]\t%d\n",
511 i, st->rxerr_phy_code[i]);
514 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
515 st->rxerr_fifo,
516 st->rx_all_count > 0 ?
517 st->rxerr_fifo*100/st->rx_all_count : 0);
518 len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
519 st->rxerr_decrypt,
520 st->rx_all_count > 0 ?
521 st->rxerr_decrypt*100/st->rx_all_count : 0);
522 len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
523 st->rxerr_mic,
524 st->rx_all_count > 0 ?
525 st->rxerr_mic*100/st->rx_all_count : 0);
526 len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
527 st->rxerr_proc,
528 st->rx_all_count > 0 ?
529 st->rxerr_proc*100/st->rx_all_count : 0);
530 len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
531 st->rxerr_jumbo,
532 st->rx_all_count > 0 ?
533 st->rxerr_jumbo*100/st->rx_all_count : 0);
534 len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
535 st->rx_all_count);
537 len += snprintf(buf+len, sizeof(buf)-len,
538 "\nTX\n---------------------\n");
539 len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
540 st->txerr_retry,
541 st->tx_all_count > 0 ?
542 st->txerr_retry*100/st->tx_all_count : 0);
543 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
544 st->txerr_fifo,
545 st->tx_all_count > 0 ?
546 st->txerr_fifo*100/st->tx_all_count : 0);
547 len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
548 st->txerr_filt,
549 st->tx_all_count > 0 ?
550 st->txerr_filt*100/st->tx_all_count : 0);
551 len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
552 st->tx_all_count);
554 if (len > sizeof(buf))
555 len = sizeof(buf);
557 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
560 static ssize_t write_file_frameerrors(struct file *file,
561 const char __user *userbuf,
562 size_t count, loff_t *ppos)
564 struct ath5k_softc *sc = file->private_data;
565 struct ath5k_statistics *st = &sc->stats;
566 char buf[20];
568 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
569 return -EFAULT;
571 if (strncmp(buf, "clear", 5) == 0) {
572 st->rxerr_crc = 0;
573 st->rxerr_phy = 0;
574 st->rxerr_fifo = 0;
575 st->rxerr_decrypt = 0;
576 st->rxerr_mic = 0;
577 st->rxerr_proc = 0;
578 st->rxerr_jumbo = 0;
579 st->rx_all_count = 0;
580 st->txerr_retry = 0;
581 st->txerr_fifo = 0;
582 st->txerr_filt = 0;
583 st->tx_all_count = 0;
584 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
586 return count;
589 static const struct file_operations fops_frameerrors = {
590 .read = read_file_frameerrors,
591 .write = write_file_frameerrors,
592 .open = ath5k_debugfs_open,
593 .owner = THIS_MODULE,
597 /* debugfs: ani */
599 static ssize_t read_file_ani(struct file *file, char __user *user_buf,
600 size_t count, loff_t *ppos)
602 struct ath5k_softc *sc = file->private_data;
603 struct ath5k_statistics *st = &sc->stats;
604 struct ath5k_ani_state *as = &sc->ani_state;
606 char buf[700];
607 unsigned int len = 0;
609 len += snprintf(buf+len, sizeof(buf)-len,
610 "HW has PHY error counters:\t%s\n",
611 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
612 "yes" : "no");
613 len += snprintf(buf+len, sizeof(buf)-len,
614 "HW max spur immunity level:\t%d\n",
615 as->max_spur_level);
616 len += snprintf(buf+len, sizeof(buf)-len,
617 "\nANI state\n--------------------------------------------\n");
618 len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
619 switch (as->ani_mode) {
620 case ATH5K_ANI_MODE_OFF:
621 len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
622 break;
623 case ATH5K_ANI_MODE_MANUAL_LOW:
624 len += snprintf(buf+len, sizeof(buf)-len,
625 "MANUAL LOW\n");
626 break;
627 case ATH5K_ANI_MODE_MANUAL_HIGH:
628 len += snprintf(buf+len, sizeof(buf)-len,
629 "MANUAL HIGH\n");
630 break;
631 case ATH5K_ANI_MODE_AUTO:
632 len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
633 break;
634 default:
635 len += snprintf(buf+len, sizeof(buf)-len,
636 "??? (not good)\n");
637 break;
639 len += snprintf(buf+len, sizeof(buf)-len,
640 "noise immunity level:\t\t%d\n",
641 as->noise_imm_level);
642 len += snprintf(buf+len, sizeof(buf)-len,
643 "spur immunity level:\t\t%d\n",
644 as->spur_level);
645 len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
646 as->firstep_level);
647 len += snprintf(buf+len, sizeof(buf)-len,
648 "OFDM weak signal detection:\t%s\n",
649 as->ofdm_weak_sig ? "on" : "off");
650 len += snprintf(buf+len, sizeof(buf)-len,
651 "CCK weak signal detection:\t%s\n",
652 as->cck_weak_sig ? "on" : "off");
654 len += snprintf(buf+len, sizeof(buf)-len,
655 "\nMIB INTERRUPTS:\t\t%u\n",
656 st->mib_intr);
657 len += snprintf(buf+len, sizeof(buf)-len,
658 "beacon RSSI average:\t%d\n",
659 sc->ah->ah_beacon_rssi_avg.avg);
660 len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
661 as->pfc_tx,
662 as->pfc_cycles > 0 ?
663 as->pfc_tx*100/as->pfc_cycles : 0);
664 len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
665 as->pfc_rx,
666 as->pfc_cycles > 0 ?
667 as->pfc_rx*100/as->pfc_cycles : 0);
668 len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
669 as->pfc_busy,
670 as->pfc_cycles > 0 ?
671 as->pfc_busy*100/as->pfc_cycles : 0);
672 len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
673 as->pfc_cycles);
674 len += snprintf(buf+len, sizeof(buf)-len,
675 "listen time\t\t%d\tlast: %d\n",
676 as->listen_time, as->last_listen);
677 len += snprintf(buf+len, sizeof(buf)-len,
678 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
679 as->ofdm_errors, as->last_ofdm_errors,
680 as->sum_ofdm_errors);
681 len += snprintf(buf+len, sizeof(buf)-len,
682 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
683 as->cck_errors, as->last_cck_errors,
684 as->sum_cck_errors);
685 len += snprintf(buf+len, sizeof(buf)-len,
686 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
687 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
688 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
689 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
690 len += snprintf(buf+len, sizeof(buf)-len,
691 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
692 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
693 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
694 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
696 if (len > sizeof(buf))
697 len = sizeof(buf);
699 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
702 static ssize_t write_file_ani(struct file *file,
703 const char __user *userbuf,
704 size_t count, loff_t *ppos)
706 struct ath5k_softc *sc = file->private_data;
707 char buf[20];
709 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
710 return -EFAULT;
712 if (strncmp(buf, "sens-low", 8) == 0) {
713 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
714 } else if (strncmp(buf, "sens-high", 9) == 0) {
715 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
716 } else if (strncmp(buf, "ani-off", 7) == 0) {
717 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
718 } else if (strncmp(buf, "ani-on", 6) == 0) {
719 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
720 } else if (strncmp(buf, "noise-low", 9) == 0) {
721 ath5k_ani_set_noise_immunity_level(sc->ah, 0);
722 } else if (strncmp(buf, "noise-high", 10) == 0) {
723 ath5k_ani_set_noise_immunity_level(sc->ah,
724 ATH5K_ANI_MAX_NOISE_IMM_LVL);
725 } else if (strncmp(buf, "spur-low", 8) == 0) {
726 ath5k_ani_set_spur_immunity_level(sc->ah, 0);
727 } else if (strncmp(buf, "spur-high", 9) == 0) {
728 ath5k_ani_set_spur_immunity_level(sc->ah,
729 sc->ani_state.max_spur_level);
730 } else if (strncmp(buf, "fir-low", 7) == 0) {
731 ath5k_ani_set_firstep_level(sc->ah, 0);
732 } else if (strncmp(buf, "fir-high", 8) == 0) {
733 ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
734 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
735 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
736 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
737 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
738 } else if (strncmp(buf, "cck-off", 7) == 0) {
739 ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
740 } else if (strncmp(buf, "cck-on", 6) == 0) {
741 ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
743 return count;
746 static const struct file_operations fops_ani = {
747 .read = read_file_ani,
748 .write = write_file_ani,
749 .open = ath5k_debugfs_open,
750 .owner = THIS_MODULE,
754 /* debugfs: queues etc */
756 static ssize_t read_file_queue(struct file *file, char __user *user_buf,
757 size_t count, loff_t *ppos)
759 struct ath5k_softc *sc = file->private_data;
760 char buf[700];
761 unsigned int len = 0;
763 struct ath5k_txq *txq;
764 struct ath5k_buf *bf, *bf0;
765 int i, n = 0;
767 len += snprintf(buf+len, sizeof(buf)-len,
768 "available txbuffers: %d\n", sc->txbuf_len);
770 for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) {
771 txq = &sc->txqs[i];
773 len += snprintf(buf+len, sizeof(buf)-len,
774 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
776 if (!txq->setup)
777 continue;
779 list_for_each_entry_safe(bf, bf0, &txq->q, list)
780 n++;
781 len += snprintf(buf+len, sizeof(buf)-len, " len: %d\n", n);
784 if (len > sizeof(buf))
785 len = sizeof(buf);
787 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
790 static ssize_t write_file_queue(struct file *file,
791 const char __user *userbuf,
792 size_t count, loff_t *ppos)
794 struct ath5k_softc *sc = file->private_data;
795 char buf[20];
797 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
798 return -EFAULT;
800 if (strncmp(buf, "start", 5) == 0)
801 ieee80211_wake_queues(sc->hw);
802 else if (strncmp(buf, "stop", 4) == 0)
803 ieee80211_stop_queues(sc->hw);
805 return count;
809 static const struct file_operations fops_queue = {
810 .read = read_file_queue,
811 .write = write_file_queue,
812 .open = ath5k_debugfs_open,
813 .owner = THIS_MODULE,
817 /* init */
819 void
820 ath5k_debug_init(void)
822 ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
825 void
826 ath5k_debug_init_device(struct ath5k_softc *sc)
828 sc->debug.level = ath5k_debug;
830 sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
831 ath5k_global_debugfs);
833 sc->debug.debugfs_debug = debugfs_create_file("debug",
834 S_IWUSR | S_IRUSR,
835 sc->debug.debugfs_phydir, sc, &fops_debug);
837 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
838 sc->debug.debugfs_phydir, sc, &fops_registers);
840 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
841 S_IWUSR | S_IRUSR,
842 sc->debug.debugfs_phydir, sc, &fops_beacon);
844 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
845 sc->debug.debugfs_phydir, sc, &fops_reset);
847 sc->debug.debugfs_antenna = debugfs_create_file("antenna",
848 S_IWUSR | S_IRUSR,
849 sc->debug.debugfs_phydir, sc, &fops_antenna);
851 sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
852 S_IWUSR | S_IRUSR,
853 sc->debug.debugfs_phydir, sc,
854 &fops_frameerrors);
856 sc->debug.debugfs_ani = debugfs_create_file("ani",
857 S_IWUSR | S_IRUSR,
858 sc->debug.debugfs_phydir, sc,
859 &fops_ani);
861 sc->debug.debugfs_queue = debugfs_create_file("queue",
862 S_IWUSR | S_IRUSR,
863 sc->debug.debugfs_phydir, sc,
864 &fops_queue);
867 void
868 ath5k_debug_finish(void)
870 debugfs_remove(ath5k_global_debugfs);
873 void
874 ath5k_debug_finish_device(struct ath5k_softc *sc)
876 debugfs_remove(sc->debug.debugfs_debug);
877 debugfs_remove(sc->debug.debugfs_registers);
878 debugfs_remove(sc->debug.debugfs_beacon);
879 debugfs_remove(sc->debug.debugfs_reset);
880 debugfs_remove(sc->debug.debugfs_antenna);
881 debugfs_remove(sc->debug.debugfs_frameerrors);
882 debugfs_remove(sc->debug.debugfs_ani);
883 debugfs_remove(sc->debug.debugfs_queue);
884 debugfs_remove(sc->debug.debugfs_phydir);
888 /* functions used in other places */
890 void
891 ath5k_debug_dump_bands(struct ath5k_softc *sc)
893 unsigned int b, i;
895 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
896 return;
898 BUG_ON(!sc->sbands);
900 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
901 struct ieee80211_supported_band *band = &sc->sbands[b];
902 char bname[6];
903 switch (band->band) {
904 case IEEE80211_BAND_2GHZ:
905 strcpy(bname, "2 GHz");
906 break;
907 case IEEE80211_BAND_5GHZ:
908 strcpy(bname, "5 GHz");
909 break;
910 default:
911 printk(KERN_DEBUG "Band not supported: %d\n",
912 band->band);
913 return;
915 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
916 band->n_channels, band->n_bitrates);
917 printk(KERN_DEBUG " channels:\n");
918 for (i = 0; i < band->n_channels; i++)
919 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
920 ieee80211_frequency_to_channel(
921 band->channels[i].center_freq),
922 band->channels[i].center_freq,
923 band->channels[i].hw_value,
924 band->channels[i].flags);
925 printk(KERN_DEBUG " rates:\n");
926 for (i = 0; i < band->n_bitrates; i++)
927 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
928 band->bitrates[i].bitrate,
929 band->bitrates[i].hw_value,
930 band->bitrates[i].flags,
931 band->bitrates[i].hw_value_short);
935 static inline void
936 ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
937 struct ath5k_rx_status *rs)
939 struct ath5k_desc *ds = bf->desc;
940 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
942 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
943 ds, (unsigned long long)bf->daddr,
944 ds->ds_link, ds->ds_data,
945 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
946 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
947 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
950 void
951 ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
953 struct ath5k_desc *ds;
954 struct ath5k_buf *bf;
955 struct ath5k_rx_status rs = {};
956 int status;
958 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
959 return;
961 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
962 ath5k_hw_get_rxdp(ah), sc->rxlink);
964 spin_lock_bh(&sc->rxbuflock);
965 list_for_each_entry(bf, &sc->rxbuf, list) {
966 ds = bf->desc;
967 status = ah->ah_proc_rx_desc(ah, ds, &rs);
968 if (!status)
969 ath5k_debug_printrxbuf(bf, status == 0, &rs);
971 spin_unlock_bh(&sc->rxbuflock);
974 void
975 ath5k_debug_dump_skb(struct ath5k_softc *sc,
976 struct sk_buff *skb, const char *prefix, int tx)
978 char buf[16];
980 if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
981 (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
982 return;
984 snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
986 print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
987 min(200U, skb->len));
989 printk(KERN_DEBUG "\n");
992 void
993 ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
995 struct ath5k_desc *ds = bf->desc;
996 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
997 struct ath5k_tx_status ts = {};
998 int done;
1000 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
1001 return;
1003 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
1005 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1006 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
1007 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
1008 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
1009 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
1010 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
1013 #endif /* ifdef CONFIG_ATH5K_DEBUG */