ath5k: Use four hardware queues
[deliverable/linux.git] / drivers / net / wireless / ath / ath5k / debug.c
CommitLineData
fa1c114f 1/*
be9b7259 2 * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com>
fa1c114f
JS
3 *
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.
8 *
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.
13 *
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/>.
16 *
17 *
18 * This file incorporates work covered by the following copyright and
19 * permission notice:
20 *
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>
26 *
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer,
34 * without modification.
35 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
36 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
37 * redistribution must be conditioned upon including a substantially
38 * similar Disclaimer requirement for further binary redistribution.
39 * 3. Neither the names of the above-listed copyright holders nor the names
40 * of any contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
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.
46 *
47 * NO WARRANTY
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
51 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
52 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
53 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
56 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
58 * THE POSSIBILITY OF SUCH DAMAGES.
59 */
60
fa1c114f 61#include "base.h"
c6e387a2 62#include "debug.h"
fa1c114f
JS
63
64static unsigned int ath5k_debug;
65module_param_named(debug, ath5k_debug, uint, 0);
66
67
b446197c 68#ifdef CONFIG_ATH5K_DEBUG
fa1c114f
JS
69
70#include <linux/seq_file.h>
71#include "reg.h"
2111ac0d 72#include "ani.h"
fa1c114f
JS
73
74static struct dentry *ath5k_global_debugfs;
75
76static int ath5k_debugfs_open(struct inode *inode, struct file *file)
77{
78 file->private_data = inode->i_private;
79 return 0;
80}
81
82
83/* debugfs: registers */
84
85struct reg {
2c91108c 86 const char *name;
fa1c114f
JS
87 int addr;
88};
89
90#define REG_STRUCT_INIT(r) { #r, r }
91
92/* just a few random registers, might want to add more */
2c91108c 93static const struct reg regs[] = {
fa1c114f
JS
94 REG_STRUCT_INIT(AR5K_CR),
95 REG_STRUCT_INIT(AR5K_RXDP),
96 REG_STRUCT_INIT(AR5K_CFG),
97 REG_STRUCT_INIT(AR5K_IER),
98 REG_STRUCT_INIT(AR5K_BCR),
99 REG_STRUCT_INIT(AR5K_RTSD0),
100 REG_STRUCT_INIT(AR5K_RTSD1),
101 REG_STRUCT_INIT(AR5K_TXCFG),
102 REG_STRUCT_INIT(AR5K_RXCFG),
103 REG_STRUCT_INIT(AR5K_RXJLA),
104 REG_STRUCT_INIT(AR5K_MIBC),
105 REG_STRUCT_INIT(AR5K_TOPS),
106 REG_STRUCT_INIT(AR5K_RXNOFRM),
107 REG_STRUCT_INIT(AR5K_TXNOFRM),
108 REG_STRUCT_INIT(AR5K_RPGTO),
109 REG_STRUCT_INIT(AR5K_RFCNT),
110 REG_STRUCT_INIT(AR5K_MISC),
111 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
112 REG_STRUCT_INIT(AR5K_ISR),
113 REG_STRUCT_INIT(AR5K_PISR),
114 REG_STRUCT_INIT(AR5K_SISR0),
115 REG_STRUCT_INIT(AR5K_SISR1),
116 REG_STRUCT_INIT(AR5K_SISR2),
117 REG_STRUCT_INIT(AR5K_SISR3),
118 REG_STRUCT_INIT(AR5K_SISR4),
119 REG_STRUCT_INIT(AR5K_IMR),
120 REG_STRUCT_INIT(AR5K_PIMR),
121 REG_STRUCT_INIT(AR5K_SIMR0),
122 REG_STRUCT_INIT(AR5K_SIMR1),
123 REG_STRUCT_INIT(AR5K_SIMR2),
124 REG_STRUCT_INIT(AR5K_SIMR3),
125 REG_STRUCT_INIT(AR5K_SIMR4),
126 REG_STRUCT_INIT(AR5K_DCM_ADDR),
127 REG_STRUCT_INIT(AR5K_DCCFG),
128 REG_STRUCT_INIT(AR5K_CCFG),
129 REG_STRUCT_INIT(AR5K_CPC0),
130 REG_STRUCT_INIT(AR5K_CPC1),
131 REG_STRUCT_INIT(AR5K_CPC2),
132 REG_STRUCT_INIT(AR5K_CPC3),
0bacdf30 133 REG_STRUCT_INIT(AR5K_CPCOVF),
fa1c114f
JS
134 REG_STRUCT_INIT(AR5K_RESET_CTL),
135 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
136 REG_STRUCT_INIT(AR5K_INTPEND),
137 REG_STRUCT_INIT(AR5K_SFR),
138 REG_STRUCT_INIT(AR5K_PCICFG),
139 REG_STRUCT_INIT(AR5K_GPIOCR),
140 REG_STRUCT_INIT(AR5K_GPIODO),
141 REG_STRUCT_INIT(AR5K_SREV),
142};
143
144static void *reg_start(struct seq_file *seq, loff_t *pos)
145{
2c91108c 146 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
fa1c114f
JS
147}
148
149static void reg_stop(struct seq_file *seq, void *p)
150{
151 /* nothing to do */
152}
153
154static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
155{
156 ++*pos;
2c91108c 157 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
fa1c114f
JS
158}
159
160static int reg_show(struct seq_file *seq, void *p)
161{
162 struct ath5k_softc *sc = seq->private;
163 struct reg *r = p;
164 seq_printf(seq, "%-25s0x%08x\n", r->name,
165 ath5k_hw_reg_read(sc->ah, r->addr));
166 return 0;
167}
168
4101dec9 169static const struct seq_operations register_seq_ops = {
fa1c114f
JS
170 .start = reg_start,
171 .next = reg_next,
172 .stop = reg_stop,
173 .show = reg_show
174};
175
176static int open_file_registers(struct inode *inode, struct file *file)
177{
178 struct seq_file *s;
179 int res;
180 res = seq_open(file, &register_seq_ops);
181 if (res == 0) {
182 s = file->private_data;
183 s->private = inode->i_private;
184 }
185 return res;
186}
187
188static const struct file_operations fops_registers = {
189 .open = open_file_registers,
190 .read = seq_read,
191 .llseek = seq_lseek,
192 .release = seq_release,
193 .owner = THIS_MODULE,
194};
195
196
fa1c114f
JS
197/* debugfs: beacons */
198
199static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
200 size_t count, loff_t *ppos)
201{
202 struct ath5k_softc *sc = file->private_data;
203 struct ath5k_hw *ah = sc->ah;
be9b7259
BR
204 char buf[500];
205 unsigned int len = 0;
fa1c114f
JS
206 unsigned int v;
207 u64 tsf;
208
209 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
210 len += snprintf(buf+len, sizeof(buf)-len,
211 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
212 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
213 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
214
215 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
216 "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
217
218 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
219 "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
220
221 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
222 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
223 "AR5K_TIMER0 (TBTT)", v, v);
224
225 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
226 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
227 "AR5K_TIMER1 (DMA)", v, v >> 3);
228
229 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
230 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
231 "AR5K_TIMER2 (SWBA)", v, v >> 3);
232
233 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
234 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
235 "AR5K_TIMER3 (ATIM)", v, v);
236
237 tsf = ath5k_hw_get_tsf64(sc->ah);
238 len += snprintf(buf+len, sizeof(buf)-len,
f868f4e1
JL
239 "TSF\t\t0x%016llx\tTU: %08x\n",
240 (unsigned long long)tsf, TSF_TO_TU(tsf));
fa1c114f 241
2189d13f
DC
242 if (len > sizeof(buf))
243 len = sizeof(buf);
244
fa1c114f
JS
245 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
246}
247
248static ssize_t write_file_beacon(struct file *file,
249 const char __user *userbuf,
250 size_t count, loff_t *ppos)
251{
252 struct ath5k_softc *sc = file->private_data;
253 struct ath5k_hw *ah = sc->ah;
be9b7259 254 char buf[20];
fa1c114f 255
be9b7259
BR
256 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
257 return -EFAULT;
258
259 if (strncmp(buf, "disable", 7) == 0) {
fa1c114f
JS
260 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
261 printk(KERN_INFO "debugfs disable beacons\n");
be9b7259 262 } else if (strncmp(buf, "enable", 6) == 0) {
fa1c114f
JS
263 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
264 printk(KERN_INFO "debugfs enable beacons\n");
265 }
266 return count;
267}
268
269static const struct file_operations fops_beacon = {
270 .read = read_file_beacon,
271 .write = write_file_beacon,
272 .open = ath5k_debugfs_open,
273 .owner = THIS_MODULE,
274};
275
276
277/* debugfs: reset */
278
279static ssize_t write_file_reset(struct file *file,
280 const char __user *userbuf,
281 size_t count, loff_t *ppos)
282{
283 struct ath5k_softc *sc = file->private_data;
8d67a031 284 ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
5faaff74 285 ieee80211_queue_work(sc->hw, &sc->reset_work);
fa1c114f
JS
286 return count;
287}
288
289static const struct file_operations fops_reset = {
290 .write = write_file_reset,
291 .open = ath5k_debugfs_open,
292 .owner = THIS_MODULE,
293};
294
295
be9b7259
BR
296/* debugfs: debug level */
297
2c91108c 298static const struct {
be9b7259
BR
299 enum ath5k_debug_level level;
300 const char *name;
301 const char *desc;
302} dbg_info[] = {
303 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
304 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
305 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
306 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
307 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
308 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
309 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
85519a65 310 { ATH5K_DEBUG_LED, "led", "LED management" },
be9b7259
BR
311 { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
312 { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
b446197c 313 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
2111ac0d 314 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
b4c52612 315 { ATH5K_DEBUG_DESC, "desc", "descriptor chains" },
be9b7259
BR
316 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
317};
318
319static ssize_t read_file_debug(struct file *file, char __user *user_buf,
320 size_t count, loff_t *ppos)
321{
322 struct ath5k_softc *sc = file->private_data;
323 char buf[700];
324 unsigned int len = 0;
325 unsigned int i;
326
327 len += snprintf(buf+len, sizeof(buf)-len,
328 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
329
330 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
331 len += snprintf(buf+len, sizeof(buf)-len,
332 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
333 sc->debug.level & dbg_info[i].level ? '+' : ' ',
334 dbg_info[i].level, dbg_info[i].desc);
335 }
336 len += snprintf(buf+len, sizeof(buf)-len,
337 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
338 sc->debug.level == dbg_info[i].level ? '+' : ' ',
339 dbg_info[i].level, dbg_info[i].desc);
340
2189d13f
DC
341 if (len > sizeof(buf))
342 len = sizeof(buf);
343
be9b7259
BR
344 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
345}
346
347static ssize_t write_file_debug(struct file *file,
348 const char __user *userbuf,
349 size_t count, loff_t *ppos)
350{
351 struct ath5k_softc *sc = file->private_data;
352 unsigned int i;
353 char buf[20];
354
355 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
356 return -EFAULT;
357
358 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
359 if (strncmp(buf, dbg_info[i].name,
360 strlen(dbg_info[i].name)) == 0) {
361 sc->debug.level ^= dbg_info[i].level; /* toggle bit */
362 break;
363 }
364 }
365 return count;
366}
367
368static const struct file_operations fops_debug = {
369 .read = read_file_debug,
370 .write = write_file_debug,
371 .open = ath5k_debugfs_open,
372 .owner = THIS_MODULE,
373};
374
375
604eeadd
BR
376/* debugfs: antenna */
377
378static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
379 size_t count, loff_t *ppos)
380{
381 struct ath5k_softc *sc = file->private_data;
382 char buf[700];
383 unsigned int len = 0;
384 unsigned int i;
385 unsigned int v;
386
387 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
388 sc->ah->ah_ant_mode);
389 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
390 sc->ah->ah_def_ant);
391 len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
392 sc->ah->ah_tx_ant);
393
394 len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
395 for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
396 len += snprintf(buf+len, sizeof(buf)-len,
397 "[antenna %d]\t%d\t%d\n",
398 i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
399 }
400 len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
401 sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);
402
403 v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
404 len += snprintf(buf+len, sizeof(buf)-len,
405 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
406
407 v = ath5k_hw_reg_read(sc->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);
420
421 v = ath5k_hw_reg_read(sc->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);
425
426 v = ath5k_hw_reg_read(sc->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);
430
431 v = ath5k_hw_reg_read(sc->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);
435
0ca74027
BR
436 v = ath5k_hw_reg_read(sc->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(sc->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);
442
2189d13f
DC
443 if (len > sizeof(buf))
444 len = sizeof(buf);
445
604eeadd
BR
446 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
447}
448
449static ssize_t write_file_antenna(struct file *file,
450 const char __user *userbuf,
451 size_t count, loff_t *ppos)
452{
453 struct ath5k_softc *sc = file->private_data;
454 unsigned int i;
455 char buf[20];
456
457 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
458 return -EFAULT;
459
460 if (strncmp(buf, "diversity", 9) == 0) {
461 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
462 printk(KERN_INFO "ath5k debug: enable diversity\n");
463 } else if (strncmp(buf, "fixed-a", 7) == 0) {
464 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
465 printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
466 } else if (strncmp(buf, "fixed-b", 7) == 0) {
467 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
468 printk(KERN_INFO "ath5k debug: fixed antenna B\n");
469 } else if (strncmp(buf, "clear", 5) == 0) {
470 for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
471 sc->stats.antenna_rx[i] = 0;
472 sc->stats.antenna_tx[i] = 0;
473 }
474 printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
475 }
476 return count;
477}
478
479static const struct file_operations fops_antenna = {
480 .read = read_file_antenna,
481 .write = write_file_antenna,
482 .open = ath5k_debugfs_open,
483 .owner = THIS_MODULE,
484};
485
486
7644395f
BR
487/* debugfs: frameerrors */
488
489static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
490 size_t count, loff_t *ppos)
491{
492 struct ath5k_softc *sc = file->private_data;
493 struct ath5k_statistics *st = &sc->stats;
494 char buf[700];
495 unsigned int len = 0;
da35111a 496 int i;
7644395f
BR
497
498 len += snprintf(buf+len, sizeof(buf)-len,
499 "RX\n---------------------\n");
500 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
501 st->rxerr_crc,
502 st->rx_all_count > 0 ?
503 st->rxerr_crc*100/st->rx_all_count : 0);
504 len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
505 st->rxerr_phy,
506 st->rx_all_count > 0 ?
507 st->rxerr_phy*100/st->rx_all_count : 0);
da35111a
BR
508 for (i = 0; i < 32; i++) {
509 if (st->rxerr_phy_code[i])
510 len += snprintf(buf+len, sizeof(buf)-len,
511 " phy_err[%d]\t%d\n",
512 i, st->rxerr_phy_code[i]);
513 }
514
7644395f
BR
515 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
516 st->rxerr_fifo,
517 st->rx_all_count > 0 ?
518 st->rxerr_fifo*100/st->rx_all_count : 0);
519 len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
520 st->rxerr_decrypt,
521 st->rx_all_count > 0 ?
522 st->rxerr_decrypt*100/st->rx_all_count : 0);
523 len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
524 st->rxerr_mic,
525 st->rx_all_count > 0 ?
526 st->rxerr_mic*100/st->rx_all_count : 0);
527 len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
528 st->rxerr_proc,
529 st->rx_all_count > 0 ?
530 st->rxerr_proc*100/st->rx_all_count : 0);
531 len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
532 st->rxerr_jumbo,
533 st->rx_all_count > 0 ?
534 st->rxerr_jumbo*100/st->rx_all_count : 0);
535 len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
536 st->rx_all_count);
537
538 len += snprintf(buf+len, sizeof(buf)-len,
539 "\nTX\n---------------------\n");
540 len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
541 st->txerr_retry,
542 st->tx_all_count > 0 ?
543 st->txerr_retry*100/st->tx_all_count : 0);
544 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
545 st->txerr_fifo,
546 st->tx_all_count > 0 ?
547 st->txerr_fifo*100/st->tx_all_count : 0);
548 len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
549 st->txerr_filt,
550 st->tx_all_count > 0 ?
551 st->txerr_filt*100/st->tx_all_count : 0);
552 len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
553 st->tx_all_count);
554
2189d13f
DC
555 if (len > sizeof(buf))
556 len = sizeof(buf);
557
7644395f
BR
558 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
559}
560
561static ssize_t write_file_frameerrors(struct file *file,
562 const char __user *userbuf,
563 size_t count, loff_t *ppos)
564{
565 struct ath5k_softc *sc = file->private_data;
566 struct ath5k_statistics *st = &sc->stats;
567 char buf[20];
568
569 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
570 return -EFAULT;
571
572 if (strncmp(buf, "clear", 5) == 0) {
573 st->rxerr_crc = 0;
574 st->rxerr_phy = 0;
575 st->rxerr_fifo = 0;
576 st->rxerr_decrypt = 0;
577 st->rxerr_mic = 0;
578 st->rxerr_proc = 0;
579 st->rxerr_jumbo = 0;
580 st->rx_all_count = 0;
581 st->txerr_retry = 0;
582 st->txerr_fifo = 0;
583 st->txerr_filt = 0;
584 st->tx_all_count = 0;
585 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
586 }
587 return count;
588}
589
590static const struct file_operations fops_frameerrors = {
591 .read = read_file_frameerrors,
592 .write = write_file_frameerrors,
593 .open = ath5k_debugfs_open,
594 .owner = THIS_MODULE,
595};
596
597
2111ac0d
BR
598/* debugfs: ani */
599
600static ssize_t read_file_ani(struct file *file, char __user *user_buf,
601 size_t count, loff_t *ppos)
602{
603 struct ath5k_softc *sc = file->private_data;
604 struct ath5k_statistics *st = &sc->stats;
605 struct ath5k_ani_state *as = &sc->ani_state;
606
607 char buf[700];
608 unsigned int len = 0;
609
610 len += snprintf(buf+len, sizeof(buf)-len,
611 "HW has PHY error counters:\t%s\n",
612 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
613 "yes" : "no");
614 len += snprintf(buf+len, sizeof(buf)-len,
615 "HW max spur immunity level:\t%d\n",
616 as->max_spur_level);
617 len += snprintf(buf+len, sizeof(buf)-len,
618 "\nANI state\n--------------------------------------------\n");
619 len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
620 switch (as->ani_mode) {
621 case ATH5K_ANI_MODE_OFF:
622 len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
623 break;
624 case ATH5K_ANI_MODE_MANUAL_LOW:
625 len += snprintf(buf+len, sizeof(buf)-len,
626 "MANUAL LOW\n");
627 break;
628 case ATH5K_ANI_MODE_MANUAL_HIGH:
629 len += snprintf(buf+len, sizeof(buf)-len,
630 "MANUAL HIGH\n");
631 break;
632 case ATH5K_ANI_MODE_AUTO:
633 len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
634 break;
635 default:
636 len += snprintf(buf+len, sizeof(buf)-len,
637 "??? (not good)\n");
638 break;
639 }
640 len += snprintf(buf+len, sizeof(buf)-len,
641 "noise immunity level:\t\t%d\n",
642 as->noise_imm_level);
643 len += snprintf(buf+len, sizeof(buf)-len,
644 "spur immunity level:\t\t%d\n",
645 as->spur_level);
646 len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
647 as->firstep_level);
648 len += snprintf(buf+len, sizeof(buf)-len,
649 "OFDM weak signal detection:\t%s\n",
650 as->ofdm_weak_sig ? "on" : "off");
651 len += snprintf(buf+len, sizeof(buf)-len,
652 "CCK weak signal detection:\t%s\n",
653 as->cck_weak_sig ? "on" : "off");
654
655 len += snprintf(buf+len, sizeof(buf)-len,
656 "\nMIB INTERRUPTS:\t\t%u\n",
657 st->mib_intr);
658 len += snprintf(buf+len, sizeof(buf)-len,
659 "beacon RSSI average:\t%d\n",
660 sc->ah->ah_beacon_rssi_avg.avg);
661 len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
662 as->pfc_tx,
663 as->pfc_cycles > 0 ?
664 as->pfc_tx*100/as->pfc_cycles : 0);
665 len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
666 as->pfc_rx,
667 as->pfc_cycles > 0 ?
668 as->pfc_rx*100/as->pfc_cycles : 0);
669 len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
670 as->pfc_busy,
671 as->pfc_cycles > 0 ?
672 as->pfc_busy*100/as->pfc_cycles : 0);
673 len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
674 as->pfc_cycles);
675 len += snprintf(buf+len, sizeof(buf)-len,
676 "listen time\t\t%d\tlast: %d\n",
677 as->listen_time, as->last_listen);
678 len += snprintf(buf+len, sizeof(buf)-len,
679 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
680 as->ofdm_errors, as->last_ofdm_errors,
681 as->sum_ofdm_errors);
682 len += snprintf(buf+len, sizeof(buf)-len,
683 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
684 as->cck_errors, as->last_cck_errors,
685 as->sum_cck_errors);
686 len += snprintf(buf+len, sizeof(buf)-len,
687 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
688 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
689 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
690 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
691 len += snprintf(buf+len, sizeof(buf)-len,
692 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
693 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
694 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
695 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
696
2189d13f
DC
697 if (len > sizeof(buf))
698 len = sizeof(buf);
699
2111ac0d
BR
700 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
701}
702
703static ssize_t write_file_ani(struct file *file,
704 const char __user *userbuf,
705 size_t count, loff_t *ppos)
706{
707 struct ath5k_softc *sc = file->private_data;
708 char buf[20];
709
710 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
711 return -EFAULT;
712
713 if (strncmp(buf, "sens-low", 8) == 0) {
714 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
715 } else if (strncmp(buf, "sens-high", 9) == 0) {
716 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
717 } else if (strncmp(buf, "ani-off", 7) == 0) {
718 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
719 } else if (strncmp(buf, "ani-on", 6) == 0) {
720 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
721 } else if (strncmp(buf, "noise-low", 9) == 0) {
722 ath5k_ani_set_noise_immunity_level(sc->ah, 0);
723 } else if (strncmp(buf, "noise-high", 10) == 0) {
724 ath5k_ani_set_noise_immunity_level(sc->ah,
725 ATH5K_ANI_MAX_NOISE_IMM_LVL);
726 } else if (strncmp(buf, "spur-low", 8) == 0) {
727 ath5k_ani_set_spur_immunity_level(sc->ah, 0);
728 } else if (strncmp(buf, "spur-high", 9) == 0) {
729 ath5k_ani_set_spur_immunity_level(sc->ah,
730 sc->ani_state.max_spur_level);
731 } else if (strncmp(buf, "fir-low", 7) == 0) {
732 ath5k_ani_set_firstep_level(sc->ah, 0);
733 } else if (strncmp(buf, "fir-high", 8) == 0) {
734 ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
735 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
736 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
737 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
738 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
739 } else if (strncmp(buf, "cck-off", 7) == 0) {
740 ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
741 } else if (strncmp(buf, "cck-on", 6) == 0) {
742 ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
743 }
744 return count;
745}
746
747static const struct file_operations fops_ani = {
748 .read = read_file_ani,
749 .write = write_file_ani,
750 .open = ath5k_debugfs_open,
751 .owner = THIS_MODULE,
752};
753
754
3cfd43f4
BR
755/* debugfs: queues etc */
756
757static ssize_t read_file_queue(struct file *file, char __user *user_buf,
758 size_t count, loff_t *ppos)
759{
760 struct ath5k_softc *sc = file->private_data;
761 char buf[700];
762 unsigned int len = 0;
763
764 struct ath5k_txq *txq;
765 struct ath5k_buf *bf, *bf0;
766 int i, n = 0;
767
768 len += snprintf(buf+len, sizeof(buf)-len,
769 "available txbuffers: %d\n", sc->txbuf_len);
770
771 for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) {
772 txq = &sc->txqs[i];
773
774 len += snprintf(buf+len, sizeof(buf)-len,
775 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
776
777 if (!txq->setup)
778 continue;
779
780 list_for_each_entry_safe(bf, bf0, &txq->q, list)
781 n++;
782 len += snprintf(buf+len, sizeof(buf)-len, " len: %d\n", n);
783 }
784
2189d13f
DC
785 if (len > sizeof(buf))
786 len = sizeof(buf);
787
3cfd43f4
BR
788 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
789}
790
791static ssize_t write_file_queue(struct file *file,
792 const char __user *userbuf,
793 size_t count, loff_t *ppos)
794{
795 struct ath5k_softc *sc = file->private_data;
796 char buf[20];
797
798 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
799 return -EFAULT;
800
801 if (strncmp(buf, "start", 5) == 0)
802 ieee80211_wake_queues(sc->hw);
803 else if (strncmp(buf, "stop", 4) == 0)
804 ieee80211_stop_queues(sc->hw);
805
806 return count;
807}
808
809
810static const struct file_operations fops_queue = {
811 .read = read_file_queue,
812 .write = write_file_queue,
813 .open = ath5k_debugfs_open,
814 .owner = THIS_MODULE,
815};
816
817
fa1c114f
JS
818/* init */
819
820void
821ath5k_debug_init(void)
822{
823 ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
824}
825
826void
827ath5k_debug_init_device(struct ath5k_softc *sc)
828{
829 sc->debug.level = ath5k_debug;
be9b7259 830
fa1c114f 831 sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
be9b7259
BR
832 ath5k_global_debugfs);
833
31670070
JS
834 sc->debug.debugfs_debug = debugfs_create_file("debug",
835 S_IWUSR | S_IRUSR,
be9b7259 836 sc->debug.debugfs_phydir, sc, &fops_debug);
fa1c114f 837
31670070 838 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
be9b7259 839 sc->debug.debugfs_phydir, sc, &fops_registers);
fa1c114f 840
31670070
JS
841 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
842 S_IWUSR | S_IRUSR,
be9b7259 843 sc->debug.debugfs_phydir, sc, &fops_beacon);
fa1c114f 844
33ab625f 845 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
be9b7259 846 sc->debug.debugfs_phydir, sc, &fops_reset);
604eeadd
BR
847
848 sc->debug.debugfs_antenna = debugfs_create_file("antenna",
849 S_IWUSR | S_IRUSR,
850 sc->debug.debugfs_phydir, sc, &fops_antenna);
7644395f
BR
851
852 sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
853 S_IWUSR | S_IRUSR,
854 sc->debug.debugfs_phydir, sc,
855 &fops_frameerrors);
2111ac0d
BR
856
857 sc->debug.debugfs_ani = debugfs_create_file("ani",
858 S_IWUSR | S_IRUSR,
859 sc->debug.debugfs_phydir, sc,
860 &fops_ani);
3cfd43f4
BR
861
862 sc->debug.debugfs_queue = debugfs_create_file("queue",
863 S_IWUSR | S_IRUSR,
864 sc->debug.debugfs_phydir, sc,
865 &fops_queue);
fa1c114f
JS
866}
867
868void
869ath5k_debug_finish(void)
870{
871 debugfs_remove(ath5k_global_debugfs);
872}
873
874void
875ath5k_debug_finish_device(struct ath5k_softc *sc)
876{
877 debugfs_remove(sc->debug.debugfs_debug);
878 debugfs_remove(sc->debug.debugfs_registers);
fa1c114f
JS
879 debugfs_remove(sc->debug.debugfs_beacon);
880 debugfs_remove(sc->debug.debugfs_reset);
604eeadd 881 debugfs_remove(sc->debug.debugfs_antenna);
7644395f 882 debugfs_remove(sc->debug.debugfs_frameerrors);
2111ac0d 883 debugfs_remove(sc->debug.debugfs_ani);
3cfd43f4 884 debugfs_remove(sc->debug.debugfs_queue);
fa1c114f
JS
885 debugfs_remove(sc->debug.debugfs_phydir);
886}
887
888
889/* functions used in other places */
890
891void
b446197c 892ath5k_debug_dump_bands(struct ath5k_softc *sc)
fa1c114f 893{
b446197c 894 unsigned int b, i;
fa1c114f 895
b446197c 896 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
fa1c114f
JS
897 return;
898
b446197c
LR
899 BUG_ON(!sc->sbands);
900
901 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
902 struct ieee80211_supported_band *band = &sc->sbands[b];
b7fcb5c4 903 char bname[6];
b446197c
LR
904 switch (band->band) {
905 case IEEE80211_BAND_2GHZ:
906 strcpy(bname, "2 GHz");
907 break;
908 case IEEE80211_BAND_5GHZ:
909 strcpy(bname, "5 GHz");
910 break;
911 default:
912 printk(KERN_DEBUG "Band not supported: %d\n",
913 band->band);
914 return;
915 }
916 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
917 band->n_channels, band->n_bitrates);
fa1c114f 918 printk(KERN_DEBUG " channels:\n");
b446197c 919 for (i = 0; i < band->n_channels; i++)
fa1c114f 920 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
b446197c
LR
921 ieee80211_frequency_to_channel(
922 band->channels[i].center_freq),
923 band->channels[i].center_freq,
924 band->channels[i].hw_value,
925 band->channels[i].flags);
fa1c114f 926 printk(KERN_DEBUG " rates:\n");
b446197c 927 for (i = 0; i < band->n_bitrates; i++)
fa1c114f 928 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
b446197c
LR
929 band->bitrates[i].bitrate,
930 band->bitrates[i].hw_value,
931 band->bitrates[i].flags,
932 band->bitrates[i].hw_value_short);
fa1c114f
JS
933 }
934}
935
936static inline void
b47f407b
BR
937ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
938 struct ath5k_rx_status *rs)
fa1c114f
JS
939{
940 struct ath5k_desc *ds = bf->desc;
19fd6e55 941 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
fa1c114f
JS
942
943 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
944 ds, (unsigned long long)bf->daddr,
19fd6e55
BR
945 ds->ds_link, ds->ds_data,
946 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
62412a8f 947 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
b47f407b 948 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
fa1c114f
JS
949}
950
951void
952ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
953{
954 struct ath5k_desc *ds;
955 struct ath5k_buf *bf;
b47f407b 956 struct ath5k_rx_status rs = {};
fa1c114f
JS
957 int status;
958
b4c52612 959 if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
fa1c114f
JS
960 return;
961
265faadd 962 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
c6e387a2 963 ath5k_hw_get_rxdp(ah), sc->rxlink);
fa1c114f
JS
964
965 spin_lock_bh(&sc->rxbuflock);
966 list_for_each_entry(bf, &sc->rxbuf, list) {
967 ds = bf->desc;
b47f407b 968 status = ah->ah_proc_rx_desc(ah, ds, &rs);
be9b7259 969 if (!status)
b47f407b 970 ath5k_debug_printrxbuf(bf, status == 0, &rs);
fa1c114f
JS
971 }
972 spin_unlock_bh(&sc->rxbuflock);
973}
974
975void
976ath5k_debug_dump_skb(struct ath5k_softc *sc,
977 struct sk_buff *skb, const char *prefix, int tx)
978{
979 char buf[16];
980
981 if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
982 (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
983 return;
984
985 snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
986
987 print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
988 min(200U, skb->len));
989
990 printk(KERN_DEBUG "\n");
991}
992
993void
b47f407b 994ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
fa1c114f
JS
995{
996 struct ath5k_desc *ds = bf->desc;
19fd6e55 997 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
b47f407b
BR
998 struct ath5k_tx_status ts = {};
999 int done;
fa1c114f 1000
b4c52612 1001 if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
fa1c114f
JS
1002 return;
1003
b47f407b
BR
1004 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
1005
fa1c114f
JS
1006 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1007 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
19fd6e55
BR
1008 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
1009 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
1010 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
b47f407b 1011 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
fa1c114f
JS
1012}
1013
b446197c 1014#endif /* ifdef CONFIG_ATH5K_DEBUG */
This page took 0.548326 seconds and 5 git commands to generate.