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.
60 #include <linux/export.h>
61 #include <linux/moduleparam.h>
63 #include <linux/seq_file.h>
64 #include <linux/list.h>
70 static unsigned int ath5k_debug;
71 module_param_named(debug, ath5k_debug, uint, 0);
74 /* debugfs: registers */
81 #define REG_STRUCT_INIT(r) { #r, r }
83 /* just a few random registers, might want to add more */
84 static const struct reg regs[] = {
85 REG_STRUCT_INIT(AR5K_CR),
86 REG_STRUCT_INIT(AR5K_RXDP),
87 REG_STRUCT_INIT(AR5K_CFG),
88 REG_STRUCT_INIT(AR5K_IER),
89 REG_STRUCT_INIT(AR5K_BCR),
90 REG_STRUCT_INIT(AR5K_RTSD0),
91 REG_STRUCT_INIT(AR5K_RTSD1),
92 REG_STRUCT_INIT(AR5K_TXCFG),
93 REG_STRUCT_INIT(AR5K_RXCFG),
94 REG_STRUCT_INIT(AR5K_RXJLA),
95 REG_STRUCT_INIT(AR5K_MIBC),
96 REG_STRUCT_INIT(AR5K_TOPS),
97 REG_STRUCT_INIT(AR5K_RXNOFRM),
98 REG_STRUCT_INIT(AR5K_TXNOFRM),
99 REG_STRUCT_INIT(AR5K_RPGTO),
100 REG_STRUCT_INIT(AR5K_RFCNT),
101 REG_STRUCT_INIT(AR5K_MISC),
102 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
103 REG_STRUCT_INIT(AR5K_ISR),
104 REG_STRUCT_INIT(AR5K_PISR),
105 REG_STRUCT_INIT(AR5K_SISR0),
106 REG_STRUCT_INIT(AR5K_SISR1),
107 REG_STRUCT_INIT(AR5K_SISR2),
108 REG_STRUCT_INIT(AR5K_SISR3),
109 REG_STRUCT_INIT(AR5K_SISR4),
110 REG_STRUCT_INIT(AR5K_IMR),
111 REG_STRUCT_INIT(AR5K_PIMR),
112 REG_STRUCT_INIT(AR5K_SIMR0),
113 REG_STRUCT_INIT(AR5K_SIMR1),
114 REG_STRUCT_INIT(AR5K_SIMR2),
115 REG_STRUCT_INIT(AR5K_SIMR3),
116 REG_STRUCT_INIT(AR5K_SIMR4),
117 REG_STRUCT_INIT(AR5K_DCM_ADDR),
118 REG_STRUCT_INIT(AR5K_DCCFG),
119 REG_STRUCT_INIT(AR5K_CCFG),
120 REG_STRUCT_INIT(AR5K_CPC0),
121 REG_STRUCT_INIT(AR5K_CPC1),
122 REG_STRUCT_INIT(AR5K_CPC2),
123 REG_STRUCT_INIT(AR5K_CPC3),
124 REG_STRUCT_INIT(AR5K_CPCOVF),
125 REG_STRUCT_INIT(AR5K_RESET_CTL),
126 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
127 REG_STRUCT_INIT(AR5K_INTPEND),
128 REG_STRUCT_INIT(AR5K_SFR),
129 REG_STRUCT_INIT(AR5K_PCICFG),
130 REG_STRUCT_INIT(AR5K_GPIOCR),
131 REG_STRUCT_INIT(AR5K_GPIODO),
132 REG_STRUCT_INIT(AR5K_SREV),
135 static void *reg_start(struct seq_file *seq, loff_t *pos)
137 return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL;
140 static void reg_stop(struct seq_file *seq, void *p)
145 static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
148 return *pos < ARRAY_SIZE(regs) ? (void *)®s[*pos] : NULL;
151 static int reg_show(struct seq_file *seq, void *p)
153 struct ath5k_hw *ah = seq->private;
155 seq_printf(seq, "%-25s0x%08x\n", r->name,
156 ath5k_hw_reg_read(ah, r->addr));
160 static const struct seq_operations register_seq_ops = {
167 static int open_file_registers(struct inode *inode, struct file *file)
171 res = seq_open(file, ®ister_seq_ops);
173 s = file->private_data;
174 s->private = inode->i_private;
179 static const struct file_operations fops_registers = {
180 .open = open_file_registers,
183 .release = seq_release,
184 .owner = THIS_MODULE,
188 /* debugfs: beacons */
190 static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
191 size_t count, loff_t *ppos)
193 struct ath5k_hw *ah = file->private_data;
195 unsigned int len = 0;
199 v = ath5k_hw_reg_read(ah, AR5K_BEACON);
200 len += snprintf(buf + len, sizeof(buf) - len,
201 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
202 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
203 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
205 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n",
206 "AR5K_LAST_TSTP", ath5k_hw_reg_read(ah, AR5K_LAST_TSTP));
208 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n\n",
209 "AR5K_BEACON_CNT", ath5k_hw_reg_read(ah, AR5K_BEACON_CNT));
211 v = ath5k_hw_reg_read(ah, AR5K_TIMER0);
212 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
213 "AR5K_TIMER0 (TBTT)", v, v);
215 v = ath5k_hw_reg_read(ah, AR5K_TIMER1);
216 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
217 "AR5K_TIMER1 (DMA)", v, v >> 3);
219 v = ath5k_hw_reg_read(ah, AR5K_TIMER2);
220 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
221 "AR5K_TIMER2 (SWBA)", v, v >> 3);
223 v = ath5k_hw_reg_read(ah, AR5K_TIMER3);
224 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
225 "AR5K_TIMER3 (ATIM)", v, v);
227 tsf = ath5k_hw_get_tsf64(ah);
228 len += snprintf(buf + len, sizeof(buf) - len,
229 "TSF\t\t0x%016llx\tTU: %08x\n",
230 (unsigned long long)tsf, TSF_TO_TU(tsf));
232 if (len > sizeof(buf))
235 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
238 static ssize_t write_file_beacon(struct file *file,
239 const char __user *userbuf,
240 size_t count, loff_t *ppos)
242 struct ath5k_hw *ah = file->private_data;
245 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
248 if (strncmp(buf, "disable", 7) == 0) {
249 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
250 printk(KERN_INFO "debugfs disable beacons\n");
251 } else if (strncmp(buf, "enable", 6) == 0) {
252 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
253 printk(KERN_INFO "debugfs enable beacons\n");
258 static const struct file_operations fops_beacon = {
259 .read = read_file_beacon,
260 .write = write_file_beacon,
262 .owner = THIS_MODULE,
263 .llseek = default_llseek,
269 static ssize_t write_file_reset(struct file *file,
270 const char __user *userbuf,
271 size_t count, loff_t *ppos)
273 struct ath5k_hw *ah = file->private_data;
274 ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
275 ieee80211_queue_work(ah->hw, &ah->reset_work);
279 static const struct file_operations fops_reset = {
280 .write = write_file_reset,
282 .owner = THIS_MODULE,
283 .llseek = noop_llseek,
287 /* debugfs: debug level */
289 static const struct {
290 enum ath5k_debug_level level;
294 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
295 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
296 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
297 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
298 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
299 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
300 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
301 { ATH5K_DEBUG_LED, "led", "LED management" },
302 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
303 { ATH5K_DEBUG_DMA, "dma", "dma start/stop" },
304 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
305 { ATH5K_DEBUG_DESC, "desc", "descriptor chains" },
306 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
309 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
310 size_t count, loff_t *ppos)
312 struct ath5k_hw *ah = file->private_data;
314 unsigned int len = 0;
317 len += snprintf(buf + len, sizeof(buf) - len,
318 "DEBUG LEVEL: 0x%08x\n\n", ah->debug.level);
320 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
321 len += snprintf(buf + len, sizeof(buf) - len,
322 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
323 ah->debug.level & dbg_info[i].level ? '+' : ' ',
324 dbg_info[i].level, dbg_info[i].desc);
326 len += snprintf(buf + len, sizeof(buf) - len,
327 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
328 ah->debug.level == dbg_info[i].level ? '+' : ' ',
329 dbg_info[i].level, dbg_info[i].desc);
331 if (len > sizeof(buf))
334 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
337 static ssize_t write_file_debug(struct file *file,
338 const char __user *userbuf,
339 size_t count, loff_t *ppos)
341 struct ath5k_hw *ah = file->private_data;
345 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
348 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
349 if (strncmp(buf, dbg_info[i].name,
350 strlen(dbg_info[i].name)) == 0) {
351 ah->debug.level ^= dbg_info[i].level; /* toggle bit */
358 static const struct file_operations fops_debug = {
359 .read = read_file_debug,
360 .write = write_file_debug,
362 .owner = THIS_MODULE,
363 .llseek = default_llseek,
367 /* debugfs: antenna */
369 static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
370 size_t count, loff_t *ppos)
372 struct ath5k_hw *ah = file->private_data;
374 unsigned int len = 0;
378 len += snprintf(buf + len, sizeof(buf) - len, "antenna mode\t%d\n",
380 len += snprintf(buf + len, sizeof(buf) - len, "default antenna\t%d\n",
382 len += snprintf(buf + len, sizeof(buf) - len, "tx antenna\t%d\n",
385 len += snprintf(buf + len, sizeof(buf) - len, "\nANTENNA\t\tRX\tTX\n");
386 for (i = 1; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) {
387 len += snprintf(buf + len, sizeof(buf) - len,
388 "[antenna %d]\t%d\t%d\n",
389 i, ah->stats.antenna_rx[i], ah->stats.antenna_tx[i]);
391 len += snprintf(buf + len, sizeof(buf) - len, "[invalid]\t%d\t%d\n",
392 ah->stats.antenna_rx[0], ah->stats.antenna_tx[0]);
394 v = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
395 len += snprintf(buf + len, sizeof(buf) - len,
396 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
398 v = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
399 len += snprintf(buf + len, sizeof(buf) - len,
400 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
401 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
402 len += snprintf(buf + len, sizeof(buf) - len,
403 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
404 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
405 len += snprintf(buf + len, sizeof(buf) - len,
406 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
407 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
408 len += snprintf(buf + len, sizeof(buf) - len,
409 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
410 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
412 v = ath5k_hw_reg_read(ah, AR5K_PHY_AGCCTL);
413 len += snprintf(buf + len, sizeof(buf) - len,
414 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
415 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
417 v = ath5k_hw_reg_read(ah, AR5K_PHY_RESTART);
418 len += snprintf(buf + len, sizeof(buf) - len,
419 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
420 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
422 v = ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ANT_DIV);
423 len += snprintf(buf + len, sizeof(buf) - len,
424 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
425 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
427 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
428 len += snprintf(buf + len, sizeof(buf) - len,
429 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
430 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
431 len += snprintf(buf + len, sizeof(buf) - len,
432 "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v);
434 if (len > sizeof(buf))
437 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
440 static ssize_t write_file_antenna(struct file *file,
441 const char __user *userbuf,
442 size_t count, loff_t *ppos)
444 struct ath5k_hw *ah = file->private_data;
448 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
451 if (strncmp(buf, "diversity", 9) == 0) {
452 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
453 printk(KERN_INFO "ath5k debug: enable diversity\n");
454 } else if (strncmp(buf, "fixed-a", 7) == 0) {
455 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
456 printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
457 } else if (strncmp(buf, "fixed-b", 7) == 0) {
458 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
459 printk(KERN_INFO "ath5k debug: fixed antenna B\n");
460 } else if (strncmp(buf, "clear", 5) == 0) {
461 for (i = 0; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) {
462 ah->stats.antenna_rx[i] = 0;
463 ah->stats.antenna_tx[i] = 0;
465 printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
470 static const struct file_operations fops_antenna = {
471 .read = read_file_antenna,
472 .write = write_file_antenna,
474 .owner = THIS_MODULE,
475 .llseek = default_llseek,
480 static ssize_t read_file_misc(struct file *file, char __user *user_buf,
481 size_t count, loff_t *ppos)
483 struct ath5k_hw *ah = file->private_data;
485 unsigned int len = 0;
486 u32 filt = ath5k_hw_get_rx_filter(ah);
488 len += snprintf(buf + len, sizeof(buf) - len, "bssid-mask: %pM\n",
490 len += snprintf(buf + len, sizeof(buf) - len, "filter-flags: 0x%x ",
492 if (filt & AR5K_RX_FILTER_UCAST)
493 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
494 if (filt & AR5K_RX_FILTER_MCAST)
495 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
496 if (filt & AR5K_RX_FILTER_BCAST)
497 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
498 if (filt & AR5K_RX_FILTER_CONTROL)
499 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
500 if (filt & AR5K_RX_FILTER_BEACON)
501 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
502 if (filt & AR5K_RX_FILTER_PROM)
503 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
504 if (filt & AR5K_RX_FILTER_XRPOLL)
505 len += snprintf(buf + len, sizeof(buf) - len, " XRPOLL");
506 if (filt & AR5K_RX_FILTER_PROBEREQ)
507 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
508 if (filt & AR5K_RX_FILTER_PHYERR_5212)
509 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR-5212");
510 if (filt & AR5K_RX_FILTER_RADARERR_5212)
511 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5212");
512 if (filt & AR5K_RX_FILTER_PHYERR_5211)
513 snprintf(buf + len, sizeof(buf) - len, " PHYERR-5211");
514 if (filt & AR5K_RX_FILTER_RADARERR_5211)
515 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5211");
517 len += snprintf(buf + len, sizeof(buf) - len, "\nopmode: %s (%d)\n",
518 ath_opmode_to_string(ah->opmode), ah->opmode);
520 if (len > sizeof(buf))
523 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
526 static const struct file_operations fops_misc = {
527 .read = read_file_misc,
529 .owner = THIS_MODULE,
533 /* debugfs: frameerrors */
535 static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
536 size_t count, loff_t *ppos)
538 struct ath5k_hw *ah = file->private_data;
539 struct ath5k_statistics *st = &ah->stats;
541 unsigned int len = 0;
544 len += snprintf(buf + len, sizeof(buf) - len,
545 "RX\n---------------------\n");
546 len += snprintf(buf + len, sizeof(buf) - len, "CRC\t%u\t(%u%%)\n",
548 st->rx_all_count > 0 ?
549 st->rxerr_crc * 100 / st->rx_all_count : 0);
550 len += snprintf(buf + len, sizeof(buf) - len, "PHY\t%u\t(%u%%)\n",
552 st->rx_all_count > 0 ?
553 st->rxerr_phy * 100 / st->rx_all_count : 0);
554 for (i = 0; i < 32; i++) {
555 if (st->rxerr_phy_code[i])
556 len += snprintf(buf + len, sizeof(buf) - len,
557 " phy_err[%u]\t%u\n",
558 i, st->rxerr_phy_code[i]);
561 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n",
563 st->rx_all_count > 0 ?
564 st->rxerr_fifo * 100 / st->rx_all_count : 0);
565 len += snprintf(buf + len, sizeof(buf) - len, "decrypt\t%u\t(%u%%)\n",
567 st->rx_all_count > 0 ?
568 st->rxerr_decrypt * 100 / st->rx_all_count : 0);
569 len += snprintf(buf + len, sizeof(buf) - len, "MIC\t%u\t(%u%%)\n",
571 st->rx_all_count > 0 ?
572 st->rxerr_mic * 100 / st->rx_all_count : 0);
573 len += snprintf(buf + len, sizeof(buf) - len, "process\t%u\t(%u%%)\n",
575 st->rx_all_count > 0 ?
576 st->rxerr_proc * 100 / st->rx_all_count : 0);
577 len += snprintf(buf + len, sizeof(buf) - len, "jumbo\t%u\t(%u%%)\n",
579 st->rx_all_count > 0 ?
580 st->rxerr_jumbo * 100 / st->rx_all_count : 0);
581 len += snprintf(buf + len, sizeof(buf) - len, "[RX all\t%u]\n",
583 len += snprintf(buf + len, sizeof(buf) - len, "RX-all-bytes\t%u\n",
586 len += snprintf(buf + len, sizeof(buf) - len,
587 "\nTX\n---------------------\n");
588 len += snprintf(buf + len, sizeof(buf) - len, "retry\t%u\t(%u%%)\n",
590 st->tx_all_count > 0 ?
591 st->txerr_retry * 100 / st->tx_all_count : 0);
592 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n",
594 st->tx_all_count > 0 ?
595 st->txerr_fifo * 100 / st->tx_all_count : 0);
596 len += snprintf(buf + len, sizeof(buf) - len, "filter\t%u\t(%u%%)\n",
598 st->tx_all_count > 0 ?
599 st->txerr_filt * 100 / st->tx_all_count : 0);
600 len += snprintf(buf + len, sizeof(buf) - len, "[TX all\t%u]\n",
602 len += snprintf(buf + len, sizeof(buf) - len, "TX-all-bytes\t%u\n",
605 if (len > sizeof(buf))
608 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
611 static ssize_t write_file_frameerrors(struct file *file,
612 const char __user *userbuf,
613 size_t count, loff_t *ppos)
615 struct ath5k_hw *ah = file->private_data;
616 struct ath5k_statistics *st = &ah->stats;
619 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
622 if (strncmp(buf, "clear", 5) == 0) {
626 st->rxerr_decrypt = 0;
630 st->rx_all_count = 0;
634 st->tx_all_count = 0;
635 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
640 static const struct file_operations fops_frameerrors = {
641 .read = read_file_frameerrors,
642 .write = write_file_frameerrors,
644 .owner = THIS_MODULE,
645 .llseek = default_llseek,
651 static ssize_t read_file_ani(struct file *file, char __user *user_buf,
652 size_t count, loff_t *ppos)
654 struct ath5k_hw *ah = file->private_data;
655 struct ath5k_statistics *st = &ah->stats;
656 struct ath5k_ani_state *as = &ah->ani_state;
659 unsigned int len = 0;
661 len += snprintf(buf + len, sizeof(buf) - len,
662 "HW has PHY error counters:\t%s\n",
663 ah->ah_capabilities.cap_has_phyerr_counters ?
665 len += snprintf(buf + len, sizeof(buf) - len,
666 "HW max spur immunity level:\t%d\n",
668 len += snprintf(buf + len, sizeof(buf) - len,
669 "\nANI state\n--------------------------------------------\n");
670 len += snprintf(buf + len, sizeof(buf) - len, "operating mode:\t\t\t");
671 switch (as->ani_mode) {
672 case ATH5K_ANI_MODE_OFF:
673 len += snprintf(buf + len, sizeof(buf) - len, "OFF\n");
675 case ATH5K_ANI_MODE_MANUAL_LOW:
676 len += snprintf(buf + len, sizeof(buf) - len,
679 case ATH5K_ANI_MODE_MANUAL_HIGH:
680 len += snprintf(buf + len, sizeof(buf) - len,
683 case ATH5K_ANI_MODE_AUTO:
684 len += snprintf(buf + len, sizeof(buf) - len, "AUTO\n");
687 len += snprintf(buf + len, sizeof(buf) - len,
691 len += snprintf(buf + len, sizeof(buf) - len,
692 "noise immunity level:\t\t%d\n",
693 as->noise_imm_level);
694 len += snprintf(buf + len, sizeof(buf) - len,
695 "spur immunity level:\t\t%d\n",
697 len += snprintf(buf + len, sizeof(buf) - len,
698 "firstep level:\t\t\t%d\n",
700 len += snprintf(buf + len, sizeof(buf) - len,
701 "OFDM weak signal detection:\t%s\n",
702 as->ofdm_weak_sig ? "on" : "off");
703 len += snprintf(buf + len, sizeof(buf) - len,
704 "CCK weak signal detection:\t%s\n",
705 as->cck_weak_sig ? "on" : "off");
707 len += snprintf(buf + len, sizeof(buf) - len,
708 "\nMIB INTERRUPTS:\t\t%u\n",
710 len += snprintf(buf + len, sizeof(buf) - len,
711 "beacon RSSI average:\t%d\n",
712 (int)ewma_read(&ah->ah_beacon_rssi_avg));
714 #define CC_PRINT(_struct, _field) \
716 _struct.cycles > 0 ? \
717 _struct._field * 100 / _struct.cycles : 0
719 len += snprintf(buf + len, sizeof(buf) - len,
720 "profcnt tx\t\t%u\t(%d%%)\n",
721 CC_PRINT(as->last_cc, tx_frame));
722 len += snprintf(buf + len, sizeof(buf) - len,
723 "profcnt rx\t\t%u\t(%d%%)\n",
724 CC_PRINT(as->last_cc, rx_frame));
725 len += snprintf(buf + len, sizeof(buf) - len,
726 "profcnt busy\t\t%u\t(%d%%)\n",
727 CC_PRINT(as->last_cc, rx_busy));
729 len += snprintf(buf + len, sizeof(buf) - len, "profcnt cycles\t\t%u\n",
731 len += snprintf(buf + len, sizeof(buf) - len,
732 "listen time\t\t%d\tlast: %d\n",
733 as->listen_time, as->last_listen);
734 len += snprintf(buf + len, sizeof(buf) - len,
735 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
736 as->ofdm_errors, as->last_ofdm_errors,
737 as->sum_ofdm_errors);
738 len += snprintf(buf + len, sizeof(buf) - len,
739 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
740 as->cck_errors, as->last_cck_errors,
742 len += snprintf(buf + len, sizeof(buf) - len,
743 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
744 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1),
745 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
746 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1)));
747 len += snprintf(buf + len, sizeof(buf) - len,
748 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
749 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2),
750 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
751 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2)));
753 if (len > sizeof(buf))
756 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
759 static ssize_t write_file_ani(struct file *file,
760 const char __user *userbuf,
761 size_t count, loff_t *ppos)
763 struct ath5k_hw *ah = file->private_data;
766 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
769 if (strncmp(buf, "sens-low", 8) == 0) {
770 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_HIGH);
771 } else if (strncmp(buf, "sens-high", 9) == 0) {
772 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_LOW);
773 } else if (strncmp(buf, "ani-off", 7) == 0) {
774 ath5k_ani_init(ah, ATH5K_ANI_MODE_OFF);
775 } else if (strncmp(buf, "ani-on", 6) == 0) {
776 ath5k_ani_init(ah, ATH5K_ANI_MODE_AUTO);
777 } else if (strncmp(buf, "noise-low", 9) == 0) {
778 ath5k_ani_set_noise_immunity_level(ah, 0);
779 } else if (strncmp(buf, "noise-high", 10) == 0) {
780 ath5k_ani_set_noise_immunity_level(ah,
781 ATH5K_ANI_MAX_NOISE_IMM_LVL);
782 } else if (strncmp(buf, "spur-low", 8) == 0) {
783 ath5k_ani_set_spur_immunity_level(ah, 0);
784 } else if (strncmp(buf, "spur-high", 9) == 0) {
785 ath5k_ani_set_spur_immunity_level(ah,
786 ah->ani_state.max_spur_level);
787 } else if (strncmp(buf, "fir-low", 7) == 0) {
788 ath5k_ani_set_firstep_level(ah, 0);
789 } else if (strncmp(buf, "fir-high", 8) == 0) {
790 ath5k_ani_set_firstep_level(ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
791 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
792 ath5k_ani_set_ofdm_weak_signal_detection(ah, false);
793 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
794 ath5k_ani_set_ofdm_weak_signal_detection(ah, true);
795 } else if (strncmp(buf, "cck-off", 7) == 0) {
796 ath5k_ani_set_cck_weak_signal_detection(ah, false);
797 } else if (strncmp(buf, "cck-on", 6) == 0) {
798 ath5k_ani_set_cck_weak_signal_detection(ah, true);
803 static const struct file_operations fops_ani = {
804 .read = read_file_ani,
805 .write = write_file_ani,
807 .owner = THIS_MODULE,
808 .llseek = default_llseek,
812 /* debugfs: queues etc */
814 static ssize_t read_file_queue(struct file *file, char __user *user_buf,
815 size_t count, loff_t *ppos)
817 struct ath5k_hw *ah = file->private_data;
819 unsigned int len = 0;
821 struct ath5k_txq *txq;
822 struct ath5k_buf *bf, *bf0;
825 len += snprintf(buf + len, sizeof(buf) - len,
826 "available txbuffers: %d\n", ah->txbuf_len);
828 for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) {
831 len += snprintf(buf + len, sizeof(buf) - len,
832 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
838 spin_lock_bh(&txq->lock);
839 list_for_each_entry_safe(bf, bf0, &txq->q, list)
841 spin_unlock_bh(&txq->lock);
843 len += snprintf(buf + len, sizeof(buf) - len,
844 " len: %d bufs: %d\n", txq->txq_len, n);
845 len += snprintf(buf + len, sizeof(buf) - len,
846 " stuck: %d\n", txq->txq_stuck);
849 if (len > sizeof(buf))
852 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
855 static ssize_t write_file_queue(struct file *file,
856 const char __user *userbuf,
857 size_t count, loff_t *ppos)
859 struct ath5k_hw *ah = file->private_data;
862 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
865 if (strncmp(buf, "start", 5) == 0)
866 ieee80211_wake_queues(ah->hw);
867 else if (strncmp(buf, "stop", 4) == 0)
868 ieee80211_stop_queues(ah->hw);
874 static const struct file_operations fops_queue = {
875 .read = read_file_queue,
876 .write = write_file_queue,
878 .owner = THIS_MODULE,
879 .llseek = default_llseek,
884 ath5k_debug_init_device(struct ath5k_hw *ah)
886 struct dentry *phydir;
888 ah->debug.level = ath5k_debug;
890 phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
894 debugfs_create_file("debug", S_IWUSR | S_IRUSR, phydir, ah,
897 debugfs_create_file("registers", S_IRUSR, phydir, ah, &fops_registers);
899 debugfs_create_file("beacon", S_IWUSR | S_IRUSR, phydir, ah,
902 debugfs_create_file("reset", S_IWUSR, phydir, ah, &fops_reset);
904 debugfs_create_file("antenna", S_IWUSR | S_IRUSR, phydir, ah,
907 debugfs_create_file("misc", S_IRUSR, phydir, ah, &fops_misc);
909 debugfs_create_file("frameerrors", S_IWUSR | S_IRUSR, phydir, ah,
912 debugfs_create_file("ani", S_IWUSR | S_IRUSR, phydir, ah, &fops_ani);
914 debugfs_create_file("queue", S_IWUSR | S_IRUSR, phydir, ah,
917 debugfs_create_bool("32khz_clock", S_IWUSR | S_IRUSR, phydir,
918 &ah->ah_use_32khz_clock);
921 /* functions used in other places */
924 ath5k_debug_dump_bands(struct ath5k_hw *ah)
928 if (likely(!(ah->debug.level & ATH5K_DEBUG_DUMPBANDS)))
933 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
934 struct ieee80211_supported_band *band = &ah->sbands[b];
936 switch (band->band) {
937 case IEEE80211_BAND_2GHZ:
938 strcpy(bname, "2 GHz");
940 case IEEE80211_BAND_5GHZ:
941 strcpy(bname, "5 GHz");
944 printk(KERN_DEBUG "Band not supported: %d\n",
948 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
949 band->n_channels, band->n_bitrates);
950 printk(KERN_DEBUG " channels:\n");
951 for (i = 0; i < band->n_channels; i++)
952 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
953 ieee80211_frequency_to_channel(
954 band->channels[i].center_freq),
955 band->channels[i].center_freq,
956 band->channels[i].hw_value,
957 band->channels[i].flags);
958 printk(KERN_DEBUG " rates:\n");
959 for (i = 0; i < band->n_bitrates; i++)
960 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
961 band->bitrates[i].bitrate,
962 band->bitrates[i].hw_value,
963 band->bitrates[i].flags,
964 band->bitrates[i].hw_value_short);
969 ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
970 struct ath5k_rx_status *rs)
972 struct ath5k_desc *ds = bf->desc;
973 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
975 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
976 ds, (unsigned long long)bf->daddr,
977 ds->ds_link, ds->ds_data,
978 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
979 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
980 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
984 ath5k_debug_printrxbuffs(struct ath5k_hw *ah)
986 struct ath5k_desc *ds;
987 struct ath5k_buf *bf;
988 struct ath5k_rx_status rs = {};
991 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC)))
994 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
995 ath5k_hw_get_rxdp(ah), ah->rxlink);
997 spin_lock_bh(&ah->rxbuflock);
998 list_for_each_entry(bf, &ah->rxbuf, list) {
1000 status = ah->ah_proc_rx_desc(ah, ds, &rs);
1002 ath5k_debug_printrxbuf(bf, status == 0, &rs);
1004 spin_unlock_bh(&ah->rxbuflock);
1008 ath5k_debug_printtxbuf(struct ath5k_hw *ah, struct ath5k_buf *bf)
1010 struct ath5k_desc *ds = bf->desc;
1011 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
1012 struct ath5k_tx_status ts = {};
1015 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC)))
1018 done = ah->ah_proc_tx_desc(ah, bf->desc, &ts);
1020 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1021 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
1022 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
1023 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
1024 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
1025 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');