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.
61 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
63 #include <linux/export.h>
64 #include <linux/moduleparam.h>
65 #include <linux/vmalloc.h>
67 #include <linux/seq_file.h>
68 #include <linux/list.h>
69 #include <linux/vmalloc.h>
75 static unsigned int ath5k_debug
;
76 module_param_named(debug
, ath5k_debug
, uint
, 0);
79 /* debugfs: registers */
86 #define REG_STRUCT_INIT(r) { #r, r }
88 /* just a few random registers, might want to add more */
89 static const struct reg regs
[] = {
90 REG_STRUCT_INIT(AR5K_CR
),
91 REG_STRUCT_INIT(AR5K_RXDP
),
92 REG_STRUCT_INIT(AR5K_CFG
),
93 REG_STRUCT_INIT(AR5K_IER
),
94 REG_STRUCT_INIT(AR5K_BCR
),
95 REG_STRUCT_INIT(AR5K_RTSD0
),
96 REG_STRUCT_INIT(AR5K_RTSD1
),
97 REG_STRUCT_INIT(AR5K_TXCFG
),
98 REG_STRUCT_INIT(AR5K_RXCFG
),
99 REG_STRUCT_INIT(AR5K_RXJLA
),
100 REG_STRUCT_INIT(AR5K_MIBC
),
101 REG_STRUCT_INIT(AR5K_TOPS
),
102 REG_STRUCT_INIT(AR5K_RXNOFRM
),
103 REG_STRUCT_INIT(AR5K_TXNOFRM
),
104 REG_STRUCT_INIT(AR5K_RPGTO
),
105 REG_STRUCT_INIT(AR5K_RFCNT
),
106 REG_STRUCT_INIT(AR5K_MISC
),
107 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT
),
108 REG_STRUCT_INIT(AR5K_ISR
),
109 REG_STRUCT_INIT(AR5K_PISR
),
110 REG_STRUCT_INIT(AR5K_SISR0
),
111 REG_STRUCT_INIT(AR5K_SISR1
),
112 REG_STRUCT_INIT(AR5K_SISR2
),
113 REG_STRUCT_INIT(AR5K_SISR3
),
114 REG_STRUCT_INIT(AR5K_SISR4
),
115 REG_STRUCT_INIT(AR5K_IMR
),
116 REG_STRUCT_INIT(AR5K_PIMR
),
117 REG_STRUCT_INIT(AR5K_SIMR0
),
118 REG_STRUCT_INIT(AR5K_SIMR1
),
119 REG_STRUCT_INIT(AR5K_SIMR2
),
120 REG_STRUCT_INIT(AR5K_SIMR3
),
121 REG_STRUCT_INIT(AR5K_SIMR4
),
122 REG_STRUCT_INIT(AR5K_DCM_ADDR
),
123 REG_STRUCT_INIT(AR5K_DCCFG
),
124 REG_STRUCT_INIT(AR5K_CCFG
),
125 REG_STRUCT_INIT(AR5K_CPC0
),
126 REG_STRUCT_INIT(AR5K_CPC1
),
127 REG_STRUCT_INIT(AR5K_CPC2
),
128 REG_STRUCT_INIT(AR5K_CPC3
),
129 REG_STRUCT_INIT(AR5K_CPCOVF
),
130 REG_STRUCT_INIT(AR5K_RESET_CTL
),
131 REG_STRUCT_INIT(AR5K_SLEEP_CTL
),
132 REG_STRUCT_INIT(AR5K_INTPEND
),
133 REG_STRUCT_INIT(AR5K_SFR
),
134 REG_STRUCT_INIT(AR5K_PCICFG
),
135 REG_STRUCT_INIT(AR5K_GPIOCR
),
136 REG_STRUCT_INIT(AR5K_GPIODO
),
137 REG_STRUCT_INIT(AR5K_SREV
),
140 static void *reg_start(struct seq_file
*seq
, loff_t
*pos
)
142 return *pos
< ARRAY_SIZE(regs
) ? (void *)®s
[*pos
] : NULL
;
145 static void reg_stop(struct seq_file
*seq
, void *p
)
150 static void *reg_next(struct seq_file
*seq
, void *p
, loff_t
*pos
)
153 return *pos
< ARRAY_SIZE(regs
) ? (void *)®s
[*pos
] : NULL
;
156 static int reg_show(struct seq_file
*seq
, void *p
)
158 struct ath5k_hw
*ah
= seq
->private;
160 seq_printf(seq
, "%-25s0x%08x\n", r
->name
,
161 ath5k_hw_reg_read(ah
, r
->addr
));
165 static const struct seq_operations register_seq_ops
= {
172 static int open_file_registers(struct inode
*inode
, struct file
*file
)
176 res
= seq_open(file
, ®ister_seq_ops
);
178 s
= file
->private_data
;
179 s
->private = inode
->i_private
;
184 static const struct file_operations fops_registers
= {
185 .open
= open_file_registers
,
188 .release
= seq_release
,
189 .owner
= THIS_MODULE
,
193 /* debugfs: beacons */
195 static ssize_t
read_file_beacon(struct file
*file
, char __user
*user_buf
,
196 size_t count
, loff_t
*ppos
)
198 struct ath5k_hw
*ah
= file
->private_data
;
200 unsigned int len
= 0;
204 v
= ath5k_hw_reg_read(ah
, AR5K_BEACON
);
205 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
206 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
207 "AR5K_BEACON", v
, v
& AR5K_BEACON_PERIOD
,
208 (v
& AR5K_BEACON_TIM
) >> AR5K_BEACON_TIM_S
);
210 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "%-24s0x%08x\n",
211 "AR5K_LAST_TSTP", ath5k_hw_reg_read(ah
, AR5K_LAST_TSTP
));
213 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "%-24s0x%08x\n\n",
214 "AR5K_BEACON_CNT", ath5k_hw_reg_read(ah
, AR5K_BEACON_CNT
));
216 v
= ath5k_hw_reg_read(ah
, AR5K_TIMER0
);
217 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "%-24s0x%08x\tTU: %08x\n",
218 "AR5K_TIMER0 (TBTT)", v
, v
);
220 v
= ath5k_hw_reg_read(ah
, AR5K_TIMER1
);
221 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "%-24s0x%08x\tTU: %08x\n",
222 "AR5K_TIMER1 (DMA)", v
, v
>> 3);
224 v
= ath5k_hw_reg_read(ah
, AR5K_TIMER2
);
225 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "%-24s0x%08x\tTU: %08x\n",
226 "AR5K_TIMER2 (SWBA)", v
, v
>> 3);
228 v
= ath5k_hw_reg_read(ah
, AR5K_TIMER3
);
229 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "%-24s0x%08x\tTU: %08x\n",
230 "AR5K_TIMER3 (ATIM)", v
, v
);
232 tsf
= ath5k_hw_get_tsf64(ah
);
233 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
234 "TSF\t\t0x%016llx\tTU: %08x\n",
235 (unsigned long long)tsf
, TSF_TO_TU(tsf
));
237 if (len
> sizeof(buf
))
240 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
243 static ssize_t
write_file_beacon(struct file
*file
,
244 const char __user
*userbuf
,
245 size_t count
, loff_t
*ppos
)
247 struct ath5k_hw
*ah
= file
->private_data
;
250 count
= min_t(size_t, count
, sizeof(buf
) - 1);
251 if (copy_from_user(buf
, userbuf
, count
))
255 if (strncmp(buf
, "disable", 7) == 0) {
256 AR5K_REG_DISABLE_BITS(ah
, AR5K_BEACON
, AR5K_BEACON_ENABLE
);
257 pr_info("debugfs disable beacons\n");
258 } else if (strncmp(buf
, "enable", 6) == 0) {
259 AR5K_REG_ENABLE_BITS(ah
, AR5K_BEACON
, AR5K_BEACON_ENABLE
);
260 pr_info("debugfs enable beacons\n");
265 static const struct file_operations fops_beacon
= {
266 .read
= read_file_beacon
,
267 .write
= write_file_beacon
,
269 .owner
= THIS_MODULE
,
270 .llseek
= default_llseek
,
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_hw
*ah
= file
->private_data
;
281 ATH5K_DBG(ah
, ATH5K_DEBUG_RESET
, "debug file triggered reset\n");
282 ieee80211_queue_work(ah
->hw
, &ah
->reset_work
);
286 static const struct file_operations fops_reset
= {
287 .write
= write_file_reset
,
289 .owner
= THIS_MODULE
,
290 .llseek
= noop_llseek
,
294 /* debugfs: debug level */
296 static const struct {
297 enum ath5k_debug_level level
;
301 { ATH5K_DEBUG_RESET
, "reset", "reset and initialization" },
302 { ATH5K_DEBUG_INTR
, "intr", "interrupt handling" },
303 { ATH5K_DEBUG_MODE
, "mode", "mode init/setup" },
304 { ATH5K_DEBUG_XMIT
, "xmit", "basic xmit operation" },
305 { ATH5K_DEBUG_BEACON
, "beacon", "beacon handling" },
306 { ATH5K_DEBUG_CALIBRATE
, "calib", "periodic calibration" },
307 { ATH5K_DEBUG_TXPOWER
, "txpower", "transmit power setting" },
308 { ATH5K_DEBUG_LED
, "led", "LED management" },
309 { ATH5K_DEBUG_DUMPBANDS
, "dumpbands", "dump bands" },
310 { ATH5K_DEBUG_DMA
, "dma", "dma start/stop" },
311 { ATH5K_DEBUG_ANI
, "ani", "adaptive noise immunity" },
312 { ATH5K_DEBUG_DESC
, "desc", "descriptor chains" },
313 { ATH5K_DEBUG_ANY
, "all", "show all debug levels" },
316 static ssize_t
read_file_debug(struct file
*file
, char __user
*user_buf
,
317 size_t count
, loff_t
*ppos
)
319 struct ath5k_hw
*ah
= file
->private_data
;
321 unsigned int len
= 0;
324 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
325 "DEBUG LEVEL: 0x%08x\n\n", ah
->debug
.level
);
327 for (i
= 0; i
< ARRAY_SIZE(dbg_info
) - 1; i
++) {
328 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
329 "%10s %c 0x%08x - %s\n", dbg_info
[i
].name
,
330 ah
->debug
.level
& dbg_info
[i
].level
? '+' : ' ',
331 dbg_info
[i
].level
, dbg_info
[i
].desc
);
333 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
334 "%10s %c 0x%08x - %s\n", dbg_info
[i
].name
,
335 ah
->debug
.level
== dbg_info
[i
].level
? '+' : ' ',
336 dbg_info
[i
].level
, dbg_info
[i
].desc
);
338 if (len
> sizeof(buf
))
341 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
344 static ssize_t
write_file_debug(struct file
*file
,
345 const char __user
*userbuf
,
346 size_t count
, loff_t
*ppos
)
348 struct ath5k_hw
*ah
= file
->private_data
;
352 count
= min_t(size_t, count
, sizeof(buf
) - 1);
353 if (copy_from_user(buf
, userbuf
, count
))
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 ah
->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
,
371 .owner
= THIS_MODULE
,
372 .llseek
= default_llseek
,
376 /* debugfs: antenna */
378 static ssize_t
read_file_antenna(struct file
*file
, char __user
*user_buf
,
379 size_t count
, loff_t
*ppos
)
381 struct ath5k_hw
*ah
= file
->private_data
;
383 unsigned int len
= 0;
387 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "antenna mode\t%d\n",
389 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "default antenna\t%d\n",
391 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "tx antenna\t%d\n",
394 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "\nANTENNA\t\tRX\tTX\n");
395 for (i
= 1; i
< ARRAY_SIZE(ah
->stats
.antenna_rx
); i
++) {
396 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
397 "[antenna %d]\t%d\t%d\n",
398 i
, ah
->stats
.antenna_rx
[i
], ah
->stats
.antenna_tx
[i
]);
400 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "[invalid]\t%d\t%d\n",
401 ah
->stats
.antenna_rx
[0], ah
->stats
.antenna_tx
[0]);
403 v
= ath5k_hw_reg_read(ah
, AR5K_DEFAULT_ANTENNA
);
404 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
405 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v
);
407 v
= ath5k_hw_reg_read(ah
, AR5K_STA_ID1
);
408 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
409 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
410 (v
& AR5K_STA_ID1_DEFAULT_ANTENNA
) != 0);
411 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
412 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
413 (v
& AR5K_STA_ID1_DESC_ANTENNA
) != 0);
414 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
415 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
416 (v
& AR5K_STA_ID1_RTS_DEF_ANTENNA
) != 0);
417 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
418 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
419 (v
& AR5K_STA_ID1_SELFGEN_DEF_ANT
) != 0);
421 v
= ath5k_hw_reg_read(ah
, AR5K_PHY_AGCCTL
);
422 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
423 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
424 (v
& AR5K_PHY_AGCCTL_OFDM_DIV_DIS
) != 0);
426 v
= ath5k_hw_reg_read(ah
, AR5K_PHY_RESTART
);
427 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
428 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
429 (v
& AR5K_PHY_RESTART_DIV_GC
) >> AR5K_PHY_RESTART_DIV_GC_S
);
431 v
= ath5k_hw_reg_read(ah
, AR5K_PHY_FAST_ANT_DIV
);
432 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
433 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
434 (v
& AR5K_PHY_FAST_ANT_DIV_EN
) != 0);
436 v
= ath5k_hw_reg_read(ah
, AR5K_PHY_ANT_SWITCH_TABLE_0
);
437 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
438 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v
);
439 v
= ath5k_hw_reg_read(ah
, AR5K_PHY_ANT_SWITCH_TABLE_1
);
440 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
441 "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v
);
443 if (len
> sizeof(buf
))
446 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
449 static ssize_t
write_file_antenna(struct file
*file
,
450 const char __user
*userbuf
,
451 size_t count
, loff_t
*ppos
)
453 struct ath5k_hw
*ah
= file
->private_data
;
457 count
= min_t(size_t, count
, sizeof(buf
) - 1);
458 if (copy_from_user(buf
, userbuf
, count
))
462 if (strncmp(buf
, "diversity", 9) == 0) {
463 ath5k_hw_set_antenna_mode(ah
, AR5K_ANTMODE_DEFAULT
);
464 pr_info("debug: enable diversity\n");
465 } else if (strncmp(buf
, "fixed-a", 7) == 0) {
466 ath5k_hw_set_antenna_mode(ah
, AR5K_ANTMODE_FIXED_A
);
467 pr_info("debug: fixed antenna A\n");
468 } else if (strncmp(buf
, "fixed-b", 7) == 0) {
469 ath5k_hw_set_antenna_mode(ah
, AR5K_ANTMODE_FIXED_B
);
470 pr_info("debug: fixed antenna B\n");
471 } else if (strncmp(buf
, "clear", 5) == 0) {
472 for (i
= 0; i
< ARRAY_SIZE(ah
->stats
.antenna_rx
); i
++) {
473 ah
->stats
.antenna_rx
[i
] = 0;
474 ah
->stats
.antenna_tx
[i
] = 0;
476 pr_info("debug: cleared antenna stats\n");
481 static const struct file_operations fops_antenna
= {
482 .read
= read_file_antenna
,
483 .write
= write_file_antenna
,
485 .owner
= THIS_MODULE
,
486 .llseek
= default_llseek
,
491 static ssize_t
read_file_misc(struct file
*file
, char __user
*user_buf
,
492 size_t count
, loff_t
*ppos
)
494 struct ath5k_hw
*ah
= file
->private_data
;
496 unsigned int len
= 0;
497 u32 filt
= ath5k_hw_get_rx_filter(ah
);
499 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "bssid-mask: %pM\n",
501 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "filter-flags: 0x%x ",
503 if (filt
& AR5K_RX_FILTER_UCAST
)
504 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " UCAST");
505 if (filt
& AR5K_RX_FILTER_MCAST
)
506 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " MCAST");
507 if (filt
& AR5K_RX_FILTER_BCAST
)
508 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " BCAST");
509 if (filt
& AR5K_RX_FILTER_CONTROL
)
510 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " CONTROL");
511 if (filt
& AR5K_RX_FILTER_BEACON
)
512 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " BEACON");
513 if (filt
& AR5K_RX_FILTER_PROM
)
514 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " PROM");
515 if (filt
& AR5K_RX_FILTER_XRPOLL
)
516 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " XRPOLL");
517 if (filt
& AR5K_RX_FILTER_PROBEREQ
)
518 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " PROBEREQ");
519 if (filt
& AR5K_RX_FILTER_PHYERR_5212
)
520 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " PHYERR-5212");
521 if (filt
& AR5K_RX_FILTER_RADARERR_5212
)
522 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " RADARERR-5212");
523 if (filt
& AR5K_RX_FILTER_PHYERR_5211
)
524 snprintf(buf
+ len
, sizeof(buf
) - len
, " PHYERR-5211");
525 if (filt
& AR5K_RX_FILTER_RADARERR_5211
)
526 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " RADARERR-5211");
528 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "\nopmode: %s (%d)\n",
529 ath_opmode_to_string(ah
->opmode
), ah
->opmode
);
531 if (len
> sizeof(buf
))
534 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
537 static const struct file_operations fops_misc
= {
538 .read
= read_file_misc
,
540 .owner
= THIS_MODULE
,
544 /* debugfs: frameerrors */
546 static ssize_t
read_file_frameerrors(struct file
*file
, char __user
*user_buf
,
547 size_t count
, loff_t
*ppos
)
549 struct ath5k_hw
*ah
= file
->private_data
;
550 struct ath5k_statistics
*st
= &ah
->stats
;
552 unsigned int len
= 0;
555 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
556 "RX\n---------------------\n");
557 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "CRC\t%u\t(%u%%)\n",
559 st
->rx_all_count
> 0 ?
560 st
->rxerr_crc
* 100 / st
->rx_all_count
: 0);
561 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "PHY\t%u\t(%u%%)\n",
563 st
->rx_all_count
> 0 ?
564 st
->rxerr_phy
* 100 / st
->rx_all_count
: 0);
565 for (i
= 0; i
< 32; i
++) {
566 if (st
->rxerr_phy_code
[i
])
567 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
568 " phy_err[%u]\t%u\n",
569 i
, st
->rxerr_phy_code
[i
]);
572 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "FIFO\t%u\t(%u%%)\n",
574 st
->rx_all_count
> 0 ?
575 st
->rxerr_fifo
* 100 / st
->rx_all_count
: 0);
576 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "decrypt\t%u\t(%u%%)\n",
578 st
->rx_all_count
> 0 ?
579 st
->rxerr_decrypt
* 100 / st
->rx_all_count
: 0);
580 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "MIC\t%u\t(%u%%)\n",
582 st
->rx_all_count
> 0 ?
583 st
->rxerr_mic
* 100 / st
->rx_all_count
: 0);
584 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "process\t%u\t(%u%%)\n",
586 st
->rx_all_count
> 0 ?
587 st
->rxerr_proc
* 100 / st
->rx_all_count
: 0);
588 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "jumbo\t%u\t(%u%%)\n",
590 st
->rx_all_count
> 0 ?
591 st
->rxerr_jumbo
* 100 / st
->rx_all_count
: 0);
592 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "[RX all\t%u]\n",
594 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "RX-all-bytes\t%u\n",
597 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
598 "\nTX\n---------------------\n");
599 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "retry\t%u\t(%u%%)\n",
601 st
->tx_all_count
> 0 ?
602 st
->txerr_retry
* 100 / st
->tx_all_count
: 0);
603 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "FIFO\t%u\t(%u%%)\n",
605 st
->tx_all_count
> 0 ?
606 st
->txerr_fifo
* 100 / st
->tx_all_count
: 0);
607 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "filter\t%u\t(%u%%)\n",
609 st
->tx_all_count
> 0 ?
610 st
->txerr_filt
* 100 / st
->tx_all_count
: 0);
611 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "[TX all\t%u]\n",
613 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "TX-all-bytes\t%u\n",
616 if (len
> sizeof(buf
))
619 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
622 static ssize_t
write_file_frameerrors(struct file
*file
,
623 const char __user
*userbuf
,
624 size_t count
, loff_t
*ppos
)
626 struct ath5k_hw
*ah
= file
->private_data
;
627 struct ath5k_statistics
*st
= &ah
->stats
;
630 count
= min_t(size_t, count
, sizeof(buf
) - 1);
631 if (copy_from_user(buf
, userbuf
, count
))
635 if (strncmp(buf
, "clear", 5) == 0) {
639 st
->rxerr_decrypt
= 0;
643 st
->rx_all_count
= 0;
647 st
->tx_all_count
= 0;
648 pr_info("debug: cleared frameerrors stats\n");
653 static const struct file_operations fops_frameerrors
= {
654 .read
= read_file_frameerrors
,
655 .write
= write_file_frameerrors
,
657 .owner
= THIS_MODULE
,
658 .llseek
= default_llseek
,
664 static ssize_t
read_file_ani(struct file
*file
, char __user
*user_buf
,
665 size_t count
, loff_t
*ppos
)
667 struct ath5k_hw
*ah
= file
->private_data
;
668 struct ath5k_statistics
*st
= &ah
->stats
;
669 struct ath5k_ani_state
*as
= &ah
->ani_state
;
672 unsigned int len
= 0;
674 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
675 "HW has PHY error counters:\t%s\n",
676 ah
->ah_capabilities
.cap_has_phyerr_counters
?
678 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
679 "HW max spur immunity level:\t%d\n",
681 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
682 "\nANI state\n--------------------------------------------\n");
683 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "operating mode:\t\t\t");
684 switch (as
->ani_mode
) {
685 case ATH5K_ANI_MODE_OFF
:
686 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "OFF\n");
688 case ATH5K_ANI_MODE_MANUAL_LOW
:
689 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
692 case ATH5K_ANI_MODE_MANUAL_HIGH
:
693 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
696 case ATH5K_ANI_MODE_AUTO
:
697 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "AUTO\n");
700 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
704 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
705 "noise immunity level:\t\t%d\n",
706 as
->noise_imm_level
);
707 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
708 "spur immunity level:\t\t%d\n",
710 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
711 "firstep level:\t\t\t%d\n",
713 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
714 "OFDM weak signal detection:\t%s\n",
715 as
->ofdm_weak_sig
? "on" : "off");
716 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
717 "CCK weak signal detection:\t%s\n",
718 as
->cck_weak_sig
? "on" : "off");
720 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
721 "\nMIB INTERRUPTS:\t\t%u\n",
723 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
724 "beacon RSSI average:\t%d\n",
725 (int)ewma_beacon_rssi_read(&ah
->ah_beacon_rssi_avg
));
727 #define CC_PRINT(_struct, _field) \
729 _struct.cycles > 0 ? \
730 _struct._field * 100 / _struct.cycles : 0
732 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
733 "profcnt tx\t\t%u\t(%d%%)\n",
734 CC_PRINT(as
->last_cc
, tx_frame
));
735 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
736 "profcnt rx\t\t%u\t(%d%%)\n",
737 CC_PRINT(as
->last_cc
, rx_frame
));
738 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
739 "profcnt busy\t\t%u\t(%d%%)\n",
740 CC_PRINT(as
->last_cc
, rx_busy
));
742 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "profcnt cycles\t\t%u\n",
744 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
745 "listen time\t\t%d\tlast: %d\n",
746 as
->listen_time
, as
->last_listen
);
747 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
748 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
749 as
->ofdm_errors
, as
->last_ofdm_errors
,
750 as
->sum_ofdm_errors
);
751 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
752 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
753 as
->cck_errors
, as
->last_cck_errors
,
755 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
756 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
757 ath5k_hw_reg_read(ah
, AR5K_PHYERR_CNT1
),
758 ATH5K_ANI_OFDM_TRIG_HIGH
- (ATH5K_PHYERR_CNT_MAX
-
759 ath5k_hw_reg_read(ah
, AR5K_PHYERR_CNT1
)));
760 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
761 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
762 ath5k_hw_reg_read(ah
, AR5K_PHYERR_CNT2
),
763 ATH5K_ANI_CCK_TRIG_HIGH
- (ATH5K_PHYERR_CNT_MAX
-
764 ath5k_hw_reg_read(ah
, AR5K_PHYERR_CNT2
)));
766 if (len
> sizeof(buf
))
769 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
772 static ssize_t
write_file_ani(struct file
*file
,
773 const char __user
*userbuf
,
774 size_t count
, loff_t
*ppos
)
776 struct ath5k_hw
*ah
= file
->private_data
;
779 count
= min_t(size_t, count
, sizeof(buf
) - 1);
780 if (copy_from_user(buf
, userbuf
, count
))
784 if (strncmp(buf
, "sens-low", 8) == 0) {
785 ath5k_ani_init(ah
, ATH5K_ANI_MODE_MANUAL_HIGH
);
786 } else if (strncmp(buf
, "sens-high", 9) == 0) {
787 ath5k_ani_init(ah
, ATH5K_ANI_MODE_MANUAL_LOW
);
788 } else if (strncmp(buf
, "ani-off", 7) == 0) {
789 ath5k_ani_init(ah
, ATH5K_ANI_MODE_OFF
);
790 } else if (strncmp(buf
, "ani-on", 6) == 0) {
791 ath5k_ani_init(ah
, ATH5K_ANI_MODE_AUTO
);
792 } else if (strncmp(buf
, "noise-low", 9) == 0) {
793 ath5k_ani_set_noise_immunity_level(ah
, 0);
794 } else if (strncmp(buf
, "noise-high", 10) == 0) {
795 ath5k_ani_set_noise_immunity_level(ah
,
796 ATH5K_ANI_MAX_NOISE_IMM_LVL
);
797 } else if (strncmp(buf
, "spur-low", 8) == 0) {
798 ath5k_ani_set_spur_immunity_level(ah
, 0);
799 } else if (strncmp(buf
, "spur-high", 9) == 0) {
800 ath5k_ani_set_spur_immunity_level(ah
,
801 ah
->ani_state
.max_spur_level
);
802 } else if (strncmp(buf
, "fir-low", 7) == 0) {
803 ath5k_ani_set_firstep_level(ah
, 0);
804 } else if (strncmp(buf
, "fir-high", 8) == 0) {
805 ath5k_ani_set_firstep_level(ah
, ATH5K_ANI_MAX_FIRSTEP_LVL
);
806 } else if (strncmp(buf
, "ofdm-off", 8) == 0) {
807 ath5k_ani_set_ofdm_weak_signal_detection(ah
, false);
808 } else if (strncmp(buf
, "ofdm-on", 7) == 0) {
809 ath5k_ani_set_ofdm_weak_signal_detection(ah
, true);
810 } else if (strncmp(buf
, "cck-off", 7) == 0) {
811 ath5k_ani_set_cck_weak_signal_detection(ah
, false);
812 } else if (strncmp(buf
, "cck-on", 6) == 0) {
813 ath5k_ani_set_cck_weak_signal_detection(ah
, true);
818 static const struct file_operations fops_ani
= {
819 .read
= read_file_ani
,
820 .write
= write_file_ani
,
822 .owner
= THIS_MODULE
,
823 .llseek
= default_llseek
,
827 /* debugfs: queues etc */
829 static ssize_t
read_file_queue(struct file
*file
, char __user
*user_buf
,
830 size_t count
, loff_t
*ppos
)
832 struct ath5k_hw
*ah
= file
->private_data
;
834 unsigned int len
= 0;
836 struct ath5k_txq
*txq
;
837 struct ath5k_buf
*bf
, *bf0
;
840 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
841 "available txbuffers: %d\n", ah
->txbuf_len
);
843 for (i
= 0; i
< ARRAY_SIZE(ah
->txqs
); i
++) {
846 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
847 "%02d: %ssetup\n", i
, txq
->setup
? "" : "not ");
853 spin_lock_bh(&txq
->lock
);
854 list_for_each_entry_safe(bf
, bf0
, &txq
->q
, list
)
856 spin_unlock_bh(&txq
->lock
);
858 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
859 " len: %d bufs: %d\n", txq
->txq_len
, n
);
860 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
861 " stuck: %d\n", txq
->txq_stuck
);
864 if (len
> sizeof(buf
))
867 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
870 static ssize_t
write_file_queue(struct file
*file
,
871 const char __user
*userbuf
,
872 size_t count
, loff_t
*ppos
)
874 struct ath5k_hw
*ah
= file
->private_data
;
877 count
= min_t(size_t, count
, sizeof(buf
) - 1);
878 if (copy_from_user(buf
, userbuf
, count
))
882 if (strncmp(buf
, "start", 5) == 0)
883 ieee80211_wake_queues(ah
->hw
);
884 else if (strncmp(buf
, "stop", 4) == 0)
885 ieee80211_stop_queues(ah
->hw
);
891 static const struct file_operations fops_queue
= {
892 .read
= read_file_queue
,
893 .write
= write_file_queue
,
895 .owner
= THIS_MODULE
,
896 .llseek
= default_llseek
,
899 /* debugfs: eeprom */
901 struct eeprom_private
{
906 static int open_file_eeprom(struct inode
*inode
, struct file
*file
)
908 struct eeprom_private
*ep
;
909 struct ath5k_hw
*ah
= inode
->i_private
;
915 /* Get eeprom size */
917 res
= ath5k_hw_nvram_read(ah
, AR5K_EEPROM_SIZE_UPPER
, &val
);
922 eesize
= AR5K_EEPROM_INFO_MAX
+ AR5K_EEPROM_INFO_BASE
;
924 eesize
= (val
& AR5K_EEPROM_SIZE_UPPER_MASK
) <<
925 AR5K_EEPROM_SIZE_ENDLOC_SHIFT
;
926 ath5k_hw_nvram_read(ah
, AR5K_EEPROM_SIZE_LOWER
, &val
);
927 eesize
= eesize
| val
;
933 /* Create buffer and read in eeprom */
935 buf
= vmalloc(eesize
);
941 for (i
= 0; i
< eesize
; ++i
) {
942 AR5K_EEPROM_READ(i
, val
);
946 /* Create private struct and assign to file */
948 ep
= kmalloc(sizeof(*ep
), GFP_KERNEL
);
957 file
->private_data
= (void *)ep
;
968 static ssize_t
read_file_eeprom(struct file
*file
, char __user
*user_buf
,
969 size_t count
, loff_t
*ppos
)
971 struct eeprom_private
*ep
= file
->private_data
;
973 return simple_read_from_buffer(user_buf
, count
, ppos
, ep
->buf
, ep
->len
);
976 static int release_file_eeprom(struct inode
*inode
, struct file
*file
)
978 struct eeprom_private
*ep
= file
->private_data
;
986 static const struct file_operations fops_eeprom
= {
987 .open
= open_file_eeprom
,
988 .read
= read_file_eeprom
,
989 .release
= release_file_eeprom
,
990 .owner
= THIS_MODULE
,
995 ath5k_debug_init_device(struct ath5k_hw
*ah
)
997 struct dentry
*phydir
;
999 ah
->debug
.level
= ath5k_debug
;
1001 phydir
= debugfs_create_dir("ath5k", ah
->hw
->wiphy
->debugfsdir
);
1005 debugfs_create_file("debug", S_IWUSR
| S_IRUSR
, phydir
, ah
,
1008 debugfs_create_file("registers", S_IRUSR
, phydir
, ah
, &fops_registers
);
1010 debugfs_create_file("beacon", S_IWUSR
| S_IRUSR
, phydir
, ah
,
1013 debugfs_create_file("reset", S_IWUSR
, phydir
, ah
, &fops_reset
);
1015 debugfs_create_file("antenna", S_IWUSR
| S_IRUSR
, phydir
, ah
,
1018 debugfs_create_file("misc", S_IRUSR
, phydir
, ah
, &fops_misc
);
1020 debugfs_create_file("eeprom", S_IRUSR
, phydir
, ah
, &fops_eeprom
);
1022 debugfs_create_file("frameerrors", S_IWUSR
| S_IRUSR
, phydir
, ah
,
1025 debugfs_create_file("ani", S_IWUSR
| S_IRUSR
, phydir
, ah
, &fops_ani
);
1027 debugfs_create_file("queue", S_IWUSR
| S_IRUSR
, phydir
, ah
,
1030 debugfs_create_bool("32khz_clock", S_IWUSR
| S_IRUSR
, phydir
,
1031 &ah
->ah_use_32khz_clock
);
1034 /* functions used in other places */
1037 ath5k_debug_dump_bands(struct ath5k_hw
*ah
)
1041 if (likely(!(ah
->debug
.level
& ATH5K_DEBUG_DUMPBANDS
)))
1044 BUG_ON(!ah
->sbands
);
1046 for (b
= 0; b
< NUM_NL80211_BANDS
; b
++) {
1047 struct ieee80211_supported_band
*band
= &ah
->sbands
[b
];
1049 switch (band
->band
) {
1050 case NL80211_BAND_2GHZ
:
1051 strcpy(bname
, "2 GHz");
1053 case NL80211_BAND_5GHZ
:
1054 strcpy(bname
, "5 GHz");
1057 printk(KERN_DEBUG
"Band not supported: %d\n",
1061 printk(KERN_DEBUG
"Band %s: channels %d, rates %d\n", bname
,
1062 band
->n_channels
, band
->n_bitrates
);
1063 printk(KERN_DEBUG
" channels:\n");
1064 for (i
= 0; i
< band
->n_channels
; i
++)
1065 printk(KERN_DEBUG
" %3d %d %.4x %.4x\n",
1066 ieee80211_frequency_to_channel(
1067 band
->channels
[i
].center_freq
),
1068 band
->channels
[i
].center_freq
,
1069 band
->channels
[i
].hw_value
,
1070 band
->channels
[i
].flags
);
1071 printk(KERN_DEBUG
" rates:\n");
1072 for (i
= 0; i
< band
->n_bitrates
; i
++)
1073 printk(KERN_DEBUG
" %4d %.4x %.4x %.4x\n",
1074 band
->bitrates
[i
].bitrate
,
1075 band
->bitrates
[i
].hw_value
,
1076 band
->bitrates
[i
].flags
,
1077 band
->bitrates
[i
].hw_value_short
);
1082 ath5k_debug_printrxbuf(struct ath5k_buf
*bf
, int done
,
1083 struct ath5k_rx_status
*rs
)
1085 struct ath5k_desc
*ds
= bf
->desc
;
1086 struct ath5k_hw_all_rx_desc
*rd
= &ds
->ud
.ds_rx
;
1088 printk(KERN_DEBUG
"R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
1089 ds
, (unsigned long long)bf
->daddr
,
1090 ds
->ds_link
, ds
->ds_data
,
1091 rd
->rx_ctl
.rx_control_0
, rd
->rx_ctl
.rx_control_1
,
1092 rd
->rx_stat
.rx_status_0
, rd
->rx_stat
.rx_status_1
,
1093 !done
? ' ' : (rs
->rs_status
== 0) ? '*' : '!');
1097 ath5k_debug_printrxbuffs(struct ath5k_hw
*ah
)
1099 struct ath5k_desc
*ds
;
1100 struct ath5k_buf
*bf
;
1101 struct ath5k_rx_status rs
= {};
1104 if (likely(!(ah
->debug
.level
& ATH5K_DEBUG_DESC
)))
1107 printk(KERN_DEBUG
"rxdp %x, rxlink %p\n",
1108 ath5k_hw_get_rxdp(ah
), ah
->rxlink
);
1110 spin_lock_bh(&ah
->rxbuflock
);
1111 list_for_each_entry(bf
, &ah
->rxbuf
, list
) {
1113 status
= ah
->ah_proc_rx_desc(ah
, ds
, &rs
);
1115 ath5k_debug_printrxbuf(bf
, status
== 0, &rs
);
1117 spin_unlock_bh(&ah
->rxbuflock
);
1121 ath5k_debug_printtxbuf(struct ath5k_hw
*ah
, struct ath5k_buf
*bf
)
1123 struct ath5k_desc
*ds
= bf
->desc
;
1124 struct ath5k_hw_5212_tx_desc
*td
= &ds
->ud
.ds_tx5212
;
1125 struct ath5k_tx_status ts
= {};
1128 if (likely(!(ah
->debug
.level
& ATH5K_DEBUG_DESC
)))
1131 done
= ah
->ah_proc_tx_desc(ah
, bf
->desc
, &ts
);
1133 printk(KERN_DEBUG
"T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1134 "%08x %c\n", ds
, (unsigned long long)bf
->daddr
, ds
->ds_link
,
1135 ds
->ds_data
, td
->tx_ctl
.tx_control_0
, td
->tx_ctl
.tx_control_1
,
1136 td
->tx_ctl
.tx_control_2
, td
->tx_ctl
.tx_control_3
,
1137 td
->tx_stat
.tx_status_0
, td
->tx_stat
.tx_status_1
,
1138 done
? ' ' : (ts
.ts_status
== 0) ? '*' : '!');