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
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
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.
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.
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>
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;
83 /* debugfs: registers */
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 *)®s[*pos] : NULL;
149 static void reg_stop(struct seq_file *seq, void *p)
154 static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
157 return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL;
160 static int reg_show(struct seq_file *seq, void *p)
162 struct ath5k_softc *sc = seq->private;
164 seq_printf(seq, "%-25s0x%08x\n", r->name,
165 ath5k_hw_reg_read(sc->ah, r->addr));
169 static const struct seq_operations register_seq_ops = {
176 static int open_file_registers(struct inode *inode, struct file *file)
180 res = seq_open(file, ®ister_seq_ops);
182 s = file->private_data;
183 s->private = inode->i_private;
188 static const struct file_operations fops_registers = {
189 .open = open_file_registers,
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;
205 unsigned int len = 0;
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 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
245 static ssize_t write_file_beacon(struct file *file,
246 const char __user *userbuf,
247 size_t count, loff_t *ppos)
249 struct ath5k_softc *sc = file->private_data;
250 struct ath5k_hw *ah = sc->ah;
253 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
256 if (strncmp(buf, "disable", 7) == 0) {
257 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
258 printk(KERN_INFO "debugfs disable beacons\n");
259 } else if (strncmp(buf, "enable", 6) == 0) {
260 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
261 printk(KERN_INFO "debugfs enable beacons\n");
266 static const struct file_operations fops_beacon = {
267 .read = read_file_beacon,
268 .write = write_file_beacon,
269 .open = ath5k_debugfs_open,
270 .owner = THIS_MODULE,
276 static ssize_t write_file_reset(struct file *file,
277 const char __user *userbuf,
278 size_t count, loff_t *ppos)
280 struct ath5k_softc *sc = file->private_data;
281 tasklet_schedule(&sc->restq);
285 static const struct file_operations fops_reset = {
286 .write = write_file_reset,
287 .open = ath5k_debugfs_open,
288 .owner = THIS_MODULE,
292 /* debugfs: debug level */
294 static const struct {
295 enum ath5k_debug_level level;
299 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
300 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
301 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
302 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
303 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
304 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
305 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
306 { ATH5K_DEBUG_LED, "led", "LED management" },
307 { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
308 { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
309 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
310 { ATH5K_DEBUG_TRACE, "trace", "trace function calls" },
311 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
312 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
315 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
316 size_t count, loff_t *ppos)
318 struct ath5k_softc *sc = file->private_data;
320 unsigned int len = 0;
323 len += snprintf(buf+len, sizeof(buf)-len,
324 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
326 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
327 len += snprintf(buf+len, sizeof(buf)-len,
328 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
329 sc->debug.level & dbg_info[i].level ? '+' : ' ',
330 dbg_info[i].level, dbg_info[i].desc);
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);
337 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
340 static ssize_t write_file_debug(struct file *file,
341 const char __user *userbuf,
342 size_t count, loff_t *ppos)
344 struct ath5k_softc *sc = file->private_data;
348 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
351 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
352 if (strncmp(buf, dbg_info[i].name,
353 strlen(dbg_info[i].name)) == 0) {
354 sc->debug.level ^= dbg_info[i].level; /* toggle bit */
361 static const struct file_operations fops_debug = {
362 .read = read_file_debug,
363 .write = write_file_debug,
364 .open = ath5k_debugfs_open,
365 .owner = THIS_MODULE,
369 /* debugfs: antenna */
371 static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
372 size_t count, loff_t *ppos)
374 struct ath5k_softc *sc = file->private_data;
376 unsigned int len = 0;
380 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
381 sc->ah->ah_ant_mode);
382 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
384 len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
387 len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
388 for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
389 len += snprintf(buf+len, sizeof(buf)-len,
390 "[antenna %d]\t%d\t%d\n",
391 i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
393 len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
394 sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);
396 v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
397 len += snprintf(buf+len, sizeof(buf)-len,
398 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
400 v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1);
401 len += snprintf(buf+len, sizeof(buf)-len,
402 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
403 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
404 len += snprintf(buf+len, sizeof(buf)-len,
405 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
406 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
407 len += snprintf(buf+len, sizeof(buf)-len,
408 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
409 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
410 len += snprintf(buf+len, sizeof(buf)-len,
411 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
412 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
414 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL);
415 len += snprintf(buf+len, sizeof(buf)-len,
416 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
417 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
419 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART);
420 len += snprintf(buf+len, sizeof(buf)-len,
421 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
422 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
424 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV);
425 len += snprintf(buf+len, sizeof(buf)-len,
426 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
427 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
429 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
432 static ssize_t write_file_antenna(struct file *file,
433 const char __user *userbuf,
434 size_t count, loff_t *ppos)
436 struct ath5k_softc *sc = file->private_data;
440 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
443 if (strncmp(buf, "diversity", 9) == 0) {
444 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
445 printk(KERN_INFO "ath5k debug: enable diversity\n");
446 } else if (strncmp(buf, "fixed-a", 7) == 0) {
447 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
448 printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
449 } else if (strncmp(buf, "fixed-b", 7) == 0) {
450 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
451 printk(KERN_INFO "ath5k debug: fixed antenna B\n");
452 } else if (strncmp(buf, "clear", 5) == 0) {
453 for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
454 sc->stats.antenna_rx[i] = 0;
455 sc->stats.antenna_tx[i] = 0;
457 printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
462 static const struct file_operations fops_antenna = {
463 .read = read_file_antenna,
464 .write = write_file_antenna,
465 .open = ath5k_debugfs_open,
466 .owner = THIS_MODULE,
470 /* debugfs: frameerrors */
472 static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
473 size_t count, loff_t *ppos)
475 struct ath5k_softc *sc = file->private_data;
476 struct ath5k_statistics *st = &sc->stats;
478 unsigned int len = 0;
481 len += snprintf(buf+len, sizeof(buf)-len,
482 "RX\n---------------------\n");
483 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
485 st->rx_all_count > 0 ?
486 st->rxerr_crc*100/st->rx_all_count : 0);
487 len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
489 st->rx_all_count > 0 ?
490 st->rxerr_phy*100/st->rx_all_count : 0);
491 for (i = 0; i < 32; i++) {
492 if (st->rxerr_phy_code[i])
493 len += snprintf(buf+len, sizeof(buf)-len,
494 " phy_err[%d]\t%d\n",
495 i, st->rxerr_phy_code[i]);
498 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
500 st->rx_all_count > 0 ?
501 st->rxerr_fifo*100/st->rx_all_count : 0);
502 len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
504 st->rx_all_count > 0 ?
505 st->rxerr_decrypt*100/st->rx_all_count : 0);
506 len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
508 st->rx_all_count > 0 ?
509 st->rxerr_mic*100/st->rx_all_count : 0);
510 len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
512 st->rx_all_count > 0 ?
513 st->rxerr_proc*100/st->rx_all_count : 0);
514 len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
516 st->rx_all_count > 0 ?
517 st->rxerr_jumbo*100/st->rx_all_count : 0);
518 len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
521 len += snprintf(buf+len, sizeof(buf)-len,
522 "\nTX\n---------------------\n");
523 len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
525 st->tx_all_count > 0 ?
526 st->txerr_retry*100/st->tx_all_count : 0);
527 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
529 st->tx_all_count > 0 ?
530 st->txerr_fifo*100/st->tx_all_count : 0);
531 len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
533 st->tx_all_count > 0 ?
534 st->txerr_filt*100/st->tx_all_count : 0);
535 len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
538 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
541 static ssize_t write_file_frameerrors(struct file *file,
542 const char __user *userbuf,
543 size_t count, loff_t *ppos)
545 struct ath5k_softc *sc = file->private_data;
546 struct ath5k_statistics *st = &sc->stats;
549 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
552 if (strncmp(buf, "clear", 5) == 0) {
556 st->rxerr_decrypt = 0;
560 st->rx_all_count = 0;
564 st->tx_all_count = 0;
565 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
570 static const struct file_operations fops_frameerrors = {
571 .read = read_file_frameerrors,
572 .write = write_file_frameerrors,
573 .open = ath5k_debugfs_open,
574 .owner = THIS_MODULE,
580 static ssize_t read_file_ani(struct file *file, char __user *user_buf,
581 size_t count, loff_t *ppos)
583 struct ath5k_softc *sc = file->private_data;
584 struct ath5k_statistics *st = &sc->stats;
585 struct ath5k_ani_state *as = &sc->ani_state;
588 unsigned int len = 0;
590 len += snprintf(buf+len, sizeof(buf)-len,
591 "HW has PHY error counters:\t%s\n",
592 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
594 len += snprintf(buf+len, sizeof(buf)-len,
595 "HW max spur immunity level:\t%d\n",
597 len += snprintf(buf+len, sizeof(buf)-len,
598 "\nANI state\n--------------------------------------------\n");
599 len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
600 switch (as->ani_mode) {
601 case ATH5K_ANI_MODE_OFF:
602 len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
604 case ATH5K_ANI_MODE_MANUAL_LOW:
605 len += snprintf(buf+len, sizeof(buf)-len,
608 case ATH5K_ANI_MODE_MANUAL_HIGH:
609 len += snprintf(buf+len, sizeof(buf)-len,
612 case ATH5K_ANI_MODE_AUTO:
613 len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
616 len += snprintf(buf+len, sizeof(buf)-len,
620 len += snprintf(buf+len, sizeof(buf)-len,
621 "noise immunity level:\t\t%d\n",
622 as->noise_imm_level);
623 len += snprintf(buf+len, sizeof(buf)-len,
624 "spur immunity level:\t\t%d\n",
626 len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
628 len += snprintf(buf+len, sizeof(buf)-len,
629 "OFDM weak signal detection:\t%s\n",
630 as->ofdm_weak_sig ? "on" : "off");
631 len += snprintf(buf+len, sizeof(buf)-len,
632 "CCK weak signal detection:\t%s\n",
633 as->cck_weak_sig ? "on" : "off");
635 len += snprintf(buf+len, sizeof(buf)-len,
636 "\nMIB INTERRUPTS:\t\t%u\n",
638 len += snprintf(buf+len, sizeof(buf)-len,
639 "beacon RSSI average:\t%d\n",
640 sc->ah->ah_beacon_rssi_avg.avg);
641 len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
644 as->pfc_tx*100/as->pfc_cycles : 0);
645 len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
648 as->pfc_rx*100/as->pfc_cycles : 0);
649 len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
652 as->pfc_busy*100/as->pfc_cycles : 0);
653 len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
655 len += snprintf(buf+len, sizeof(buf)-len,
656 "listen time\t\t%d\tlast: %d\n",
657 as->listen_time, as->last_listen);
658 len += snprintf(buf+len, sizeof(buf)-len,
659 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
660 as->ofdm_errors, as->last_ofdm_errors,
661 as->sum_ofdm_errors);
662 len += snprintf(buf+len, sizeof(buf)-len,
663 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
664 as->cck_errors, as->last_cck_errors,
666 len += snprintf(buf+len, sizeof(buf)-len,
667 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
668 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
669 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
670 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
671 len += snprintf(buf+len, sizeof(buf)-len,
672 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
673 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
674 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
675 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
677 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
680 static ssize_t write_file_ani(struct file *file,
681 const char __user *userbuf,
682 size_t count, loff_t *ppos)
684 struct ath5k_softc *sc = file->private_data;
687 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
690 if (strncmp(buf, "sens-low", 8) == 0) {
691 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
692 } else if (strncmp(buf, "sens-high", 9) == 0) {
693 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
694 } else if (strncmp(buf, "ani-off", 7) == 0) {
695 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
696 } else if (strncmp(buf, "ani-on", 6) == 0) {
697 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
698 } else if (strncmp(buf, "noise-low", 9) == 0) {
699 ath5k_ani_set_noise_immunity_level(sc->ah, 0);
700 } else if (strncmp(buf, "noise-high", 10) == 0) {
701 ath5k_ani_set_noise_immunity_level(sc->ah,
702 ATH5K_ANI_MAX_NOISE_IMM_LVL);
703 } else if (strncmp(buf, "spur-low", 8) == 0) {
704 ath5k_ani_set_spur_immunity_level(sc->ah, 0);
705 } else if (strncmp(buf, "spur-high", 9) == 0) {
706 ath5k_ani_set_spur_immunity_level(sc->ah,
707 sc->ani_state.max_spur_level);
708 } else if (strncmp(buf, "fir-low", 7) == 0) {
709 ath5k_ani_set_firstep_level(sc->ah, 0);
710 } else if (strncmp(buf, "fir-high", 8) == 0) {
711 ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
712 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
713 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
714 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
715 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
716 } else if (strncmp(buf, "cck-off", 7) == 0) {
717 ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
718 } else if (strncmp(buf, "cck-on", 6) == 0) {
719 ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
724 static const struct file_operations fops_ani = {
725 .read = read_file_ani,
726 .write = write_file_ani,
727 .open = ath5k_debugfs_open,
728 .owner = THIS_MODULE,
735 ath5k_debug_init(void)
737 ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
741 ath5k_debug_init_device(struct ath5k_softc *sc)
743 sc->debug.level = ath5k_debug;
745 sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
746 ath5k_global_debugfs);
748 sc->debug.debugfs_debug = debugfs_create_file("debug",
750 sc->debug.debugfs_phydir, sc, &fops_debug);
752 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
753 sc->debug.debugfs_phydir, sc, &fops_registers);
755 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
757 sc->debug.debugfs_phydir, sc, &fops_beacon);
759 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
760 sc->debug.debugfs_phydir, sc, &fops_reset);
762 sc->debug.debugfs_antenna = debugfs_create_file("antenna",
764 sc->debug.debugfs_phydir, sc, &fops_antenna);
766 sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
768 sc->debug.debugfs_phydir, sc,
771 sc->debug.debugfs_ani = debugfs_create_file("ani",
773 sc->debug.debugfs_phydir, sc,
778 ath5k_debug_finish(void)
780 debugfs_remove(ath5k_global_debugfs);
784 ath5k_debug_finish_device(struct ath5k_softc *sc)
786 debugfs_remove(sc->debug.debugfs_debug);
787 debugfs_remove(sc->debug.debugfs_registers);
788 debugfs_remove(sc->debug.debugfs_beacon);
789 debugfs_remove(sc->debug.debugfs_reset);
790 debugfs_remove(sc->debug.debugfs_antenna);
791 debugfs_remove(sc->debug.debugfs_frameerrors);
792 debugfs_remove(sc->debug.debugfs_ani);
793 debugfs_remove(sc->debug.debugfs_phydir);
797 /* functions used in other places */
800 ath5k_debug_dump_bands(struct ath5k_softc *sc)
804 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
809 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
810 struct ieee80211_supported_band *band = &sc->sbands[b];
812 switch (band->band) {
813 case IEEE80211_BAND_2GHZ:
814 strcpy(bname, "2 GHz");
816 case IEEE80211_BAND_5GHZ:
817 strcpy(bname, "5 GHz");
820 printk(KERN_DEBUG "Band not supported: %d\n",
824 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
825 band->n_channels, band->n_bitrates);
826 printk(KERN_DEBUG " channels:\n");
827 for (i = 0; i < band->n_channels; i++)
828 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
829 ieee80211_frequency_to_channel(
830 band->channels[i].center_freq),
831 band->channels[i].center_freq,
832 band->channels[i].hw_value,
833 band->channels[i].flags);
834 printk(KERN_DEBUG " rates:\n");
835 for (i = 0; i < band->n_bitrates; i++)
836 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
837 band->bitrates[i].bitrate,
838 band->bitrates[i].hw_value,
839 band->bitrates[i].flags,
840 band->bitrates[i].hw_value_short);
845 ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
846 struct ath5k_rx_status *rs)
848 struct ath5k_desc *ds = bf->desc;
849 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
851 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
852 ds, (unsigned long long)bf->daddr,
853 ds->ds_link, ds->ds_data,
854 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
855 rd->u.rx_stat.rx_status_0, rd->u.rx_stat.rx_status_0,
856 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
860 ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
862 struct ath5k_desc *ds;
863 struct ath5k_buf *bf;
864 struct ath5k_rx_status rs = {};
867 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
870 printk(KERN_DEBUG "rx queue %x, link %p\n",
871 ath5k_hw_get_rxdp(ah), sc->rxlink);
873 spin_lock_bh(&sc->rxbuflock);
874 list_for_each_entry(bf, &sc->rxbuf, list) {
876 status = ah->ah_proc_rx_desc(ah, ds, &rs);
878 ath5k_debug_printrxbuf(bf, status == 0, &rs);
880 spin_unlock_bh(&sc->rxbuflock);
884 ath5k_debug_dump_skb(struct ath5k_softc *sc,
885 struct sk_buff *skb, const char *prefix, int tx)
889 if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
890 (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
893 snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
895 print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
896 min(200U, skb->len));
898 printk(KERN_DEBUG "\n");
902 ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
904 struct ath5k_desc *ds = bf->desc;
905 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
906 struct ath5k_tx_status ts = {};
909 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
912 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
914 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
915 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
916 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
917 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
918 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
919 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
922 #endif /* ifdef CONFIG_ATH5K_DEBUG */