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.
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.
65 static unsigned int ath5k_debug;
66 module_param_named(debug, ath5k_debug, uint, 0);
69 #ifdef CONFIG_ATH5K_DEBUG
71 #include <linux/seq_file.h>
75 static int ath5k_debugfs_open(struct inode *inode, struct file *file)
77 file->private_data = inode->i_private;
82 /* debugfs: registers */
89 #define REG_STRUCT_INIT(r) { #r, r }
91 /* just a few random registers, might want to add more */
92 static const struct reg regs[] = {
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),
132 REG_STRUCT_INIT(AR5K_CPCOVF),
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),
143 static void *reg_start(struct seq_file *seq, loff_t *pos)
145 return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL;
148 static void reg_stop(struct seq_file *seq, void *p)
153 static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
156 return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL;
159 static int reg_show(struct seq_file *seq, void *p)
161 struct ath5k_softc *sc = seq->private;
163 seq_printf(seq, "%-25s0x%08x\n", r->name,
164 ath5k_hw_reg_read(sc->ah, r->addr));
168 static const struct seq_operations register_seq_ops = {
175 static int open_file_registers(struct inode *inode, struct file *file)
179 res = seq_open(file, ®ister_seq_ops);
181 s = file->private_data;
182 s->private = inode->i_private;
187 static const struct file_operations fops_registers = {
188 .open = open_file_registers,
191 .release = seq_release,
192 .owner = THIS_MODULE,
196 /* debugfs: beacons */
198 static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
199 size_t count, loff_t *ppos)
201 struct ath5k_softc *sc = file->private_data;
202 struct ath5k_hw *ah = sc->ah;
204 unsigned int len = 0;
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);
214 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
215 "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
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));
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);
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);
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);
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);
236 tsf = ath5k_hw_get_tsf64(sc->ah);
237 len += snprintf(buf+len, sizeof(buf)-len,
238 "TSF\t\t0x%016llx\tTU: %08x\n",
239 (unsigned long long)tsf, TSF_TO_TU(tsf));
241 if (len > sizeof(buf))
244 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
247 static ssize_t write_file_beacon(struct file *file,
248 const char __user *userbuf,
249 size_t count, loff_t *ppos)
251 struct ath5k_softc *sc = file->private_data;
252 struct ath5k_hw *ah = sc->ah;
255 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
258 if (strncmp(buf, "disable", 7) == 0) {
259 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
260 printk(KERN_INFO "debugfs disable beacons\n");
261 } else if (strncmp(buf, "enable", 6) == 0) {
262 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
263 printk(KERN_INFO "debugfs enable beacons\n");
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,
278 static ssize_t write_file_reset(struct file *file,
279 const char __user *userbuf,
280 size_t count, loff_t *ppos)
282 struct ath5k_softc *sc = file->private_data;
283 ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
284 ieee80211_queue_work(sc->hw, &sc->reset_work);
288 static const struct file_operations fops_reset = {
289 .write = write_file_reset,
290 .open = ath5k_debugfs_open,
291 .owner = THIS_MODULE,
295 /* debugfs: debug level */
297 static const struct {
298 enum ath5k_debug_level level;
302 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
303 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
304 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
305 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
306 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
307 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
308 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
309 { ATH5K_DEBUG_LED, "led", "LED management" },
310 { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
311 { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
312 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
313 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
314 { ATH5K_DEBUG_DESC, "desc", "descriptor chains" },
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;
323 unsigned int len = 0;
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))
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;
354 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
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 */
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;
382 unsigned int len = 0;
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",
390 len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
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))
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;
456 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
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");
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,
487 static ssize_t read_file_misc(struct file *file, char __user *user_buf,
488 size_t count, loff_t *ppos)
490 struct ath5k_softc *sc = file->private_data;
492 unsigned int len = 0;
493 u32 filt = ath5k_hw_get_rx_filter(sc->ah);
495 len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
497 len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
499 if (filt & AR5K_RX_FILTER_UCAST)
500 len += snprintf(buf+len, sizeof(buf)-len, " UCAST");
501 if (filt & AR5K_RX_FILTER_MCAST)
502 len += snprintf(buf+len, sizeof(buf)-len, " MCAST");
503 if (filt & AR5K_RX_FILTER_BCAST)
504 len += snprintf(buf+len, sizeof(buf)-len, " BCAST");
505 if (filt & AR5K_RX_FILTER_CONTROL)
506 len += snprintf(buf+len, sizeof(buf)-len, " CONTROL");
507 if (filt & AR5K_RX_FILTER_BEACON)
508 len += snprintf(buf+len, sizeof(buf)-len, " BEACON");
509 if (filt & AR5K_RX_FILTER_PROM)
510 len += snprintf(buf+len, sizeof(buf)-len, " PROM");
511 if (filt & AR5K_RX_FILTER_XRPOLL)
512 len += snprintf(buf+len, sizeof(buf)-len, " XRPOLL");
513 if (filt & AR5K_RX_FILTER_PROBEREQ)
514 len += snprintf(buf+len, sizeof(buf)-len, " PROBEREQ");
515 if (filt & AR5K_RX_FILTER_PHYERR_5212)
516 len += snprintf(buf+len, sizeof(buf)-len, " PHYERR-5212");
517 if (filt & AR5K_RX_FILTER_RADARERR_5212)
518 len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5212");
519 if (filt & AR5K_RX_FILTER_PHYERR_5211)
520 snprintf(buf+len, sizeof(buf)-len, " PHYERR-5211");
521 if (filt & AR5K_RX_FILTER_RADARERR_5211)
522 len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5211");
524 len += snprintf(buf+len, sizeof(buf)-len, "\nopmode: %s (%d)\n",
525 ath_opmode_to_string(sc->opmode), sc->opmode);
527 if (len > sizeof(buf))
530 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
533 static const struct file_operations fops_misc = {
534 .read = read_file_misc,
535 .open = ath5k_debugfs_open,
536 .owner = THIS_MODULE,
540 /* debugfs: frameerrors */
542 static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
543 size_t count, loff_t *ppos)
545 struct ath5k_softc *sc = file->private_data;
546 struct ath5k_statistics *st = &sc->stats;
548 unsigned int len = 0;
551 len += snprintf(buf+len, sizeof(buf)-len,
552 "RX\n---------------------\n");
553 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
555 st->rx_all_count > 0 ?
556 st->rxerr_crc*100/st->rx_all_count : 0);
557 len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
559 st->rx_all_count > 0 ?
560 st->rxerr_phy*100/st->rx_all_count : 0);
561 for (i = 0; i < 32; i++) {
562 if (st->rxerr_phy_code[i])
563 len += snprintf(buf+len, sizeof(buf)-len,
564 " phy_err[%d]\t%d\n",
565 i, st->rxerr_phy_code[i]);
568 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
570 st->rx_all_count > 0 ?
571 st->rxerr_fifo*100/st->rx_all_count : 0);
572 len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
574 st->rx_all_count > 0 ?
575 st->rxerr_decrypt*100/st->rx_all_count : 0);
576 len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
578 st->rx_all_count > 0 ?
579 st->rxerr_mic*100/st->rx_all_count : 0);
580 len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
582 st->rx_all_count > 0 ?
583 st->rxerr_proc*100/st->rx_all_count : 0);
584 len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
586 st->rx_all_count > 0 ?
587 st->rxerr_jumbo*100/st->rx_all_count : 0);
588 len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
590 len += snprintf(buf+len, sizeof(buf)-len, "RX-all-bytes\t%d\n",
593 len += snprintf(buf+len, sizeof(buf)-len,
594 "\nTX\n---------------------\n");
595 len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
597 st->tx_all_count > 0 ?
598 st->txerr_retry*100/st->tx_all_count : 0);
599 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
601 st->tx_all_count > 0 ?
602 st->txerr_fifo*100/st->tx_all_count : 0);
603 len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
605 st->tx_all_count > 0 ?
606 st->txerr_filt*100/st->tx_all_count : 0);
607 len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
609 len += snprintf(buf+len, sizeof(buf)-len, "TX-all-bytes\t%d\n",
612 if (len > sizeof(buf))
615 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
618 static ssize_t write_file_frameerrors(struct file *file,
619 const char __user *userbuf,
620 size_t count, loff_t *ppos)
622 struct ath5k_softc *sc = file->private_data;
623 struct ath5k_statistics *st = &sc->stats;
626 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
629 if (strncmp(buf, "clear", 5) == 0) {
633 st->rxerr_decrypt = 0;
637 st->rx_all_count = 0;
641 st->tx_all_count = 0;
642 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
647 static const struct file_operations fops_frameerrors = {
648 .read = read_file_frameerrors,
649 .write = write_file_frameerrors,
650 .open = ath5k_debugfs_open,
651 .owner = THIS_MODULE,
657 static ssize_t read_file_ani(struct file *file, char __user *user_buf,
658 size_t count, loff_t *ppos)
660 struct ath5k_softc *sc = file->private_data;
661 struct ath5k_statistics *st = &sc->stats;
662 struct ath5k_ani_state *as = &sc->ani_state;
665 unsigned int len = 0;
667 len += snprintf(buf+len, sizeof(buf)-len,
668 "HW has PHY error counters:\t%s\n",
669 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
671 len += snprintf(buf+len, sizeof(buf)-len,
672 "HW max spur immunity level:\t%d\n",
674 len += snprintf(buf+len, sizeof(buf)-len,
675 "\nANI state\n--------------------------------------------\n");
676 len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
677 switch (as->ani_mode) {
678 case ATH5K_ANI_MODE_OFF:
679 len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
681 case ATH5K_ANI_MODE_MANUAL_LOW:
682 len += snprintf(buf+len, sizeof(buf)-len,
685 case ATH5K_ANI_MODE_MANUAL_HIGH:
686 len += snprintf(buf+len, sizeof(buf)-len,
689 case ATH5K_ANI_MODE_AUTO:
690 len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
693 len += snprintf(buf+len, sizeof(buf)-len,
697 len += snprintf(buf+len, sizeof(buf)-len,
698 "noise immunity level:\t\t%d\n",
699 as->noise_imm_level);
700 len += snprintf(buf+len, sizeof(buf)-len,
701 "spur immunity level:\t\t%d\n",
703 len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
705 len += snprintf(buf+len, sizeof(buf)-len,
706 "OFDM weak signal detection:\t%s\n",
707 as->ofdm_weak_sig ? "on" : "off");
708 len += snprintf(buf+len, sizeof(buf)-len,
709 "CCK weak signal detection:\t%s\n",
710 as->cck_weak_sig ? "on" : "off");
712 len += snprintf(buf+len, sizeof(buf)-len,
713 "\nMIB INTERRUPTS:\t\t%u\n",
715 len += snprintf(buf+len, sizeof(buf)-len,
716 "beacon RSSI average:\t%d\n",
717 sc->ah->ah_beacon_rssi_avg.avg);
719 #define CC_PRINT(_struct, _field) \
721 _struct.cycles > 0 ? \
722 _struct._field*100/_struct.cycles : 0
724 len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
725 CC_PRINT(as->last_cc, tx_frame));
726 len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
727 CC_PRINT(as->last_cc, rx_frame));
728 len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
729 CC_PRINT(as->last_cc, rx_busy));
731 len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
733 len += snprintf(buf+len, sizeof(buf)-len,
734 "listen time\t\t%d\tlast: %d\n",
735 as->listen_time, as->last_listen);
736 len += snprintf(buf+len, sizeof(buf)-len,
737 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
738 as->ofdm_errors, as->last_ofdm_errors,
739 as->sum_ofdm_errors);
740 len += snprintf(buf+len, sizeof(buf)-len,
741 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
742 as->cck_errors, as->last_cck_errors,
744 len += snprintf(buf+len, sizeof(buf)-len,
745 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
746 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
747 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
748 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
749 len += snprintf(buf+len, sizeof(buf)-len,
750 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
751 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
752 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
753 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
755 if (len > sizeof(buf))
758 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
761 static ssize_t write_file_ani(struct file *file,
762 const char __user *userbuf,
763 size_t count, loff_t *ppos)
765 struct ath5k_softc *sc = file->private_data;
768 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
771 if (strncmp(buf, "sens-low", 8) == 0) {
772 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
773 } else if (strncmp(buf, "sens-high", 9) == 0) {
774 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
775 } else if (strncmp(buf, "ani-off", 7) == 0) {
776 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
777 } else if (strncmp(buf, "ani-on", 6) == 0) {
778 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
779 } else if (strncmp(buf, "noise-low", 9) == 0) {
780 ath5k_ani_set_noise_immunity_level(sc->ah, 0);
781 } else if (strncmp(buf, "noise-high", 10) == 0) {
782 ath5k_ani_set_noise_immunity_level(sc->ah,
783 ATH5K_ANI_MAX_NOISE_IMM_LVL);
784 } else if (strncmp(buf, "spur-low", 8) == 0) {
785 ath5k_ani_set_spur_immunity_level(sc->ah, 0);
786 } else if (strncmp(buf, "spur-high", 9) == 0) {
787 ath5k_ani_set_spur_immunity_level(sc->ah,
788 sc->ani_state.max_spur_level);
789 } else if (strncmp(buf, "fir-low", 7) == 0) {
790 ath5k_ani_set_firstep_level(sc->ah, 0);
791 } else if (strncmp(buf, "fir-high", 8) == 0) {
792 ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
793 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
794 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
795 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
796 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
797 } else if (strncmp(buf, "cck-off", 7) == 0) {
798 ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
799 } else if (strncmp(buf, "cck-on", 6) == 0) {
800 ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
805 static const struct file_operations fops_ani = {
806 .read = read_file_ani,
807 .write = write_file_ani,
808 .open = ath5k_debugfs_open,
809 .owner = THIS_MODULE,
813 /* debugfs: queues etc */
815 static ssize_t read_file_queue(struct file *file, char __user *user_buf,
816 size_t count, loff_t *ppos)
818 struct ath5k_softc *sc = file->private_data;
820 unsigned int len = 0;
822 struct ath5k_txq *txq;
823 struct ath5k_buf *bf, *bf0;
826 len += snprintf(buf+len, sizeof(buf)-len,
827 "available txbuffers: %d\n", sc->txbuf_len);
829 for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) {
832 len += snprintf(buf+len, sizeof(buf)-len,
833 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
839 spin_lock_bh(&txq->lock);
840 list_for_each_entry_safe(bf, bf0, &txq->q, list)
842 spin_unlock_bh(&txq->lock);
844 len += snprintf(buf+len, sizeof(buf)-len,
845 " len: %d bufs: %d\n", txq->txq_len, n);
846 len += snprintf(buf+len, sizeof(buf)-len,
847 " stuck: %d\n", txq->txq_stuck);
850 if (len > sizeof(buf))
853 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
856 static ssize_t write_file_queue(struct file *file,
857 const char __user *userbuf,
858 size_t count, loff_t *ppos)
860 struct ath5k_softc *sc = file->private_data;
863 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
866 if (strncmp(buf, "start", 5) == 0)
867 ieee80211_wake_queues(sc->hw);
868 else if (strncmp(buf, "stop", 4) == 0)
869 ieee80211_stop_queues(sc->hw);
875 static const struct file_operations fops_queue = {
876 .read = read_file_queue,
877 .write = write_file_queue,
878 .open = ath5k_debugfs_open,
879 .owner = THIS_MODULE,
884 ath5k_debug_init_device(struct ath5k_softc *sc)
886 sc->debug.level = ath5k_debug;
888 sc->debug.debugfs_phydir = debugfs_create_dir("ath5k",
889 sc->hw->wiphy->debugfsdir);
891 sc->debug.debugfs_debug = debugfs_create_file("debug",
893 sc->debug.debugfs_phydir, sc, &fops_debug);
895 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
896 sc->debug.debugfs_phydir, sc, &fops_registers);
898 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
900 sc->debug.debugfs_phydir, sc, &fops_beacon);
902 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
903 sc->debug.debugfs_phydir, sc, &fops_reset);
905 sc->debug.debugfs_antenna = debugfs_create_file("antenna",
907 sc->debug.debugfs_phydir, sc, &fops_antenna);
909 sc->debug.debugfs_misc = debugfs_create_file("misc",
911 sc->debug.debugfs_phydir, sc, &fops_misc);
913 sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
915 sc->debug.debugfs_phydir, sc,
918 sc->debug.debugfs_ani = debugfs_create_file("ani",
920 sc->debug.debugfs_phydir, sc,
923 sc->debug.debugfs_queue = debugfs_create_file("queue",
925 sc->debug.debugfs_phydir, sc,
930 ath5k_debug_finish_device(struct ath5k_softc *sc)
932 debugfs_remove(sc->debug.debugfs_debug);
933 debugfs_remove(sc->debug.debugfs_registers);
934 debugfs_remove(sc->debug.debugfs_beacon);
935 debugfs_remove(sc->debug.debugfs_reset);
936 debugfs_remove(sc->debug.debugfs_antenna);
937 debugfs_remove(sc->debug.debugfs_misc);
938 debugfs_remove(sc->debug.debugfs_frameerrors);
939 debugfs_remove(sc->debug.debugfs_ani);
940 debugfs_remove(sc->debug.debugfs_queue);
941 debugfs_remove(sc->debug.debugfs_phydir);
945 /* functions used in other places */
948 ath5k_debug_dump_bands(struct ath5k_softc *sc)
952 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
957 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
958 struct ieee80211_supported_band *band = &sc->sbands[b];
960 switch (band->band) {
961 case IEEE80211_BAND_2GHZ:
962 strcpy(bname, "2 GHz");
964 case IEEE80211_BAND_5GHZ:
965 strcpy(bname, "5 GHz");
968 printk(KERN_DEBUG "Band not supported: %d\n",
972 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
973 band->n_channels, band->n_bitrates);
974 printk(KERN_DEBUG " channels:\n");
975 for (i = 0; i < band->n_channels; i++)
976 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
977 ieee80211_frequency_to_channel(
978 band->channels[i].center_freq),
979 band->channels[i].center_freq,
980 band->channels[i].hw_value,
981 band->channels[i].flags);
982 printk(KERN_DEBUG " rates:\n");
983 for (i = 0; i < band->n_bitrates; i++)
984 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
985 band->bitrates[i].bitrate,
986 band->bitrates[i].hw_value,
987 band->bitrates[i].flags,
988 band->bitrates[i].hw_value_short);
993 ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
994 struct ath5k_rx_status *rs)
996 struct ath5k_desc *ds = bf->desc;
997 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
999 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
1000 ds, (unsigned long long)bf->daddr,
1001 ds->ds_link, ds->ds_data,
1002 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
1003 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
1004 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
1008 ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
1010 struct ath5k_desc *ds;
1011 struct ath5k_buf *bf;
1012 struct ath5k_rx_status rs = {};
1015 if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
1018 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
1019 ath5k_hw_get_rxdp(ah), sc->rxlink);
1021 spin_lock_bh(&sc->rxbuflock);
1022 list_for_each_entry(bf, &sc->rxbuf, list) {
1024 status = ah->ah_proc_rx_desc(ah, ds, &rs);
1026 ath5k_debug_printrxbuf(bf, status == 0, &rs);
1028 spin_unlock_bh(&sc->rxbuflock);
1032 ath5k_debug_dump_skb(struct ath5k_softc *sc,
1033 struct sk_buff *skb, const char *prefix, int tx)
1037 if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
1038 (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
1041 snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
1043 print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
1044 min(200U, skb->len));
1046 printk(KERN_DEBUG "\n");
1050 ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
1052 struct ath5k_desc *ds = bf->desc;
1053 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
1054 struct ath5k_tx_status ts = {};
1057 if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
1060 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
1062 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1063 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
1064 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
1065 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
1066 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
1067 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
1070 #endif /* ifdef CONFIG_ATH5K_DEBUG */