blob: 90247dc74198e30b21ec89839318974e1aafef55 [file] [log] [blame]
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001/*
Bruno Randolfbe9b7252008-01-23 10:27:51 +09002 * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com>
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003 *
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
Jiri Slabyfa1c1142007-08-12 17:33:16 +020061#include "base.h"
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030062#include "debug.h"
Jiri Slabyfa1c1142007-08-12 17:33:16 +020063
64static unsigned int ath5k_debug;
65module_param_named(debug, ath5k_debug, uint, 0);
66
67
Luis R. Rodriguezb4461972008-02-04 10:03:54 -050068#ifdef CONFIG_ATH5K_DEBUG
Jiri Slabyfa1c1142007-08-12 17:33:16 +020069
70#include <linux/seq_file.h>
71#include "reg.h"
72
73static struct dentry *ath5k_global_debugfs;
74
75static int ath5k_debugfs_open(struct inode *inode, struct file *file)
76{
77 file->private_data = inode->i_private;
78 return 0;
79}
80
81
82/* debugfs: registers */
83
84struct reg {
Jiri Slaby2c91108c2009-03-07 10:26:41 +010085 const char *name;
Jiri Slabyfa1c1142007-08-12 17:33:16 +020086 int addr;
87};
88
89#define REG_STRUCT_INIT(r) { #r, r }
90
91/* just a few random registers, might want to add more */
Jiri Slaby2c91108c2009-03-07 10:26:41 +010092static const struct reg regs[] = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +020093 REG_STRUCT_INIT(AR5K_CR),
94 REG_STRUCT_INIT(AR5K_RXDP),
95 REG_STRUCT_INIT(AR5K_CFG),
96 REG_STRUCT_INIT(AR5K_IER),
97 REG_STRUCT_INIT(AR5K_BCR),
98 REG_STRUCT_INIT(AR5K_RTSD0),
99 REG_STRUCT_INIT(AR5K_RTSD1),
100 REG_STRUCT_INIT(AR5K_TXCFG),
101 REG_STRUCT_INIT(AR5K_RXCFG),
102 REG_STRUCT_INIT(AR5K_RXJLA),
103 REG_STRUCT_INIT(AR5K_MIBC),
104 REG_STRUCT_INIT(AR5K_TOPS),
105 REG_STRUCT_INIT(AR5K_RXNOFRM),
106 REG_STRUCT_INIT(AR5K_TXNOFRM),
107 REG_STRUCT_INIT(AR5K_RPGTO),
108 REG_STRUCT_INIT(AR5K_RFCNT),
109 REG_STRUCT_INIT(AR5K_MISC),
110 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
111 REG_STRUCT_INIT(AR5K_ISR),
112 REG_STRUCT_INIT(AR5K_PISR),
113 REG_STRUCT_INIT(AR5K_SISR0),
114 REG_STRUCT_INIT(AR5K_SISR1),
115 REG_STRUCT_INIT(AR5K_SISR2),
116 REG_STRUCT_INIT(AR5K_SISR3),
117 REG_STRUCT_INIT(AR5K_SISR4),
118 REG_STRUCT_INIT(AR5K_IMR),
119 REG_STRUCT_INIT(AR5K_PIMR),
120 REG_STRUCT_INIT(AR5K_SIMR0),
121 REG_STRUCT_INIT(AR5K_SIMR1),
122 REG_STRUCT_INIT(AR5K_SIMR2),
123 REG_STRUCT_INIT(AR5K_SIMR3),
124 REG_STRUCT_INIT(AR5K_SIMR4),
125 REG_STRUCT_INIT(AR5K_DCM_ADDR),
126 REG_STRUCT_INIT(AR5K_DCCFG),
127 REG_STRUCT_INIT(AR5K_CCFG),
128 REG_STRUCT_INIT(AR5K_CPC0),
129 REG_STRUCT_INIT(AR5K_CPC1),
130 REG_STRUCT_INIT(AR5K_CPC2),
131 REG_STRUCT_INIT(AR5K_CPC3),
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300132 REG_STRUCT_INIT(AR5K_CPCOVF),
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200133 REG_STRUCT_INIT(AR5K_RESET_CTL),
134 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
135 REG_STRUCT_INIT(AR5K_INTPEND),
136 REG_STRUCT_INIT(AR5K_SFR),
137 REG_STRUCT_INIT(AR5K_PCICFG),
138 REG_STRUCT_INIT(AR5K_GPIOCR),
139 REG_STRUCT_INIT(AR5K_GPIODO),
140 REG_STRUCT_INIT(AR5K_SREV),
141};
142
143static void *reg_start(struct seq_file *seq, loff_t *pos)
144{
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100145 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200146}
147
148static void reg_stop(struct seq_file *seq, void *p)
149{
150 /* nothing to do */
151}
152
153static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
154{
155 ++*pos;
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100156 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200157}
158
159static int reg_show(struct seq_file *seq, void *p)
160{
161 struct ath5k_softc *sc = seq->private;
162 struct reg *r = p;
163 seq_printf(seq, "%-25s0x%08x\n", r->name,
164 ath5k_hw_reg_read(sc->ah, r->addr));
165 return 0;
166}
167
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800168static const struct seq_operations register_seq_ops = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200169 .start = reg_start,
170 .next = reg_next,
171 .stop = reg_stop,
172 .show = reg_show
173};
174
175static int open_file_registers(struct inode *inode, struct file *file)
176{
177 struct seq_file *s;
178 int res;
179 res = seq_open(file, &register_seq_ops);
180 if (res == 0) {
181 s = file->private_data;
182 s->private = inode->i_private;
183 }
184 return res;
185}
186
187static const struct file_operations fops_registers = {
188 .open = open_file_registers,
189 .read = seq_read,
190 .llseek = seq_lseek,
191 .release = seq_release,
192 .owner = THIS_MODULE,
193};
194
195
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200196/* debugfs: beacons */
197
198static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
199 size_t count, loff_t *ppos)
200{
201 struct ath5k_softc *sc = file->private_data;
202 struct ath5k_hw *ah = sc->ah;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900203 char buf[500];
204 unsigned int len = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200205 unsigned int v;
206 u64 tsf;
207
208 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
209 len += snprintf(buf+len, sizeof(buf)-len,
210 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
211 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
212 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
213
214 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
215 "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
216
217 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
218 "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
219
220 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
221 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
222 "AR5K_TIMER0 (TBTT)", v, v);
223
224 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
225 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
226 "AR5K_TIMER1 (DMA)", v, v >> 3);
227
228 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
229 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
230 "AR5K_TIMER2 (SWBA)", v, v >> 3);
231
232 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
233 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
234 "AR5K_TIMER3 (ATIM)", v, v);
235
236 tsf = ath5k_hw_get_tsf64(sc->ah);
237 len += snprintf(buf+len, sizeof(buf)-len,
John W. Linvillef868f4e2008-03-07 16:38:43 -0500238 "TSF\t\t0x%016llx\tTU: %08x\n",
239 (unsigned long long)tsf, TSF_TO_TU(tsf));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200240
241 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
242}
243
244static ssize_t write_file_beacon(struct file *file,
245 const char __user *userbuf,
246 size_t count, loff_t *ppos)
247{
248 struct ath5k_softc *sc = file->private_data;
249 struct ath5k_hw *ah = sc->ah;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900250 char buf[20];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200251
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900252 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
253 return -EFAULT;
254
255 if (strncmp(buf, "disable", 7) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200256 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
257 printk(KERN_INFO "debugfs disable beacons\n");
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900258 } else if (strncmp(buf, "enable", 6) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200259 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
260 printk(KERN_INFO "debugfs enable beacons\n");
261 }
262 return count;
263}
264
265static const struct file_operations fops_beacon = {
266 .read = read_file_beacon,
267 .write = write_file_beacon,
268 .open = ath5k_debugfs_open,
269 .owner = THIS_MODULE,
270};
271
272
273/* debugfs: reset */
274
275static ssize_t write_file_reset(struct file *file,
276 const char __user *userbuf,
277 size_t count, loff_t *ppos)
278{
279 struct ath5k_softc *sc = file->private_data;
280 tasklet_schedule(&sc->restq);
281 return count;
282}
283
284static const struct file_operations fops_reset = {
285 .write = write_file_reset,
286 .open = ath5k_debugfs_open,
287 .owner = THIS_MODULE,
288};
289
290
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900291/* debugfs: debug level */
292
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100293static const struct {
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900294 enum ath5k_debug_level level;
295 const char *name;
296 const char *desc;
297} dbg_info[] = {
298 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
299 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
300 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
301 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
302 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
303 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
304 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
Bob Copeland85519a62008-10-29 08:30:53 -0400305 { ATH5K_DEBUG_LED, "led", "LED management" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900306 { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
307 { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500308 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900309 { ATH5K_DEBUG_TRACE, "trace", "trace function calls" },
310 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
311};
312
313static ssize_t read_file_debug(struct file *file, char __user *user_buf,
314 size_t count, loff_t *ppos)
315{
316 struct ath5k_softc *sc = file->private_data;
317 char buf[700];
318 unsigned int len = 0;
319 unsigned int i;
320
321 len += snprintf(buf+len, sizeof(buf)-len,
322 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
323
324 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
325 len += snprintf(buf+len, sizeof(buf)-len,
326 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
327 sc->debug.level & dbg_info[i].level ? '+' : ' ',
328 dbg_info[i].level, dbg_info[i].desc);
329 }
330 len += snprintf(buf+len, sizeof(buf)-len,
331 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
332 sc->debug.level == dbg_info[i].level ? '+' : ' ',
333 dbg_info[i].level, dbg_info[i].desc);
334
335 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
336}
337
338static ssize_t write_file_debug(struct file *file,
339 const char __user *userbuf,
340 size_t count, loff_t *ppos)
341{
342 struct ath5k_softc *sc = file->private_data;
343 unsigned int i;
344 char buf[20];
345
346 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
347 return -EFAULT;
348
349 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
350 if (strncmp(buf, dbg_info[i].name,
351 strlen(dbg_info[i].name)) == 0) {
352 sc->debug.level ^= dbg_info[i].level; /* toggle bit */
353 break;
354 }
355 }
356 return count;
357}
358
359static const struct file_operations fops_debug = {
360 .read = read_file_debug,
361 .write = write_file_debug,
362 .open = ath5k_debugfs_open,
363 .owner = THIS_MODULE,
364};
365
366
Bruno Randolf604eead2010-03-09 16:55:17 +0900367/* debugfs: antenna */
368
369static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
370 size_t count, loff_t *ppos)
371{
372 struct ath5k_softc *sc = file->private_data;
373 char buf[700];
374 unsigned int len = 0;
375 unsigned int i;
376 unsigned int v;
377
378 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
379 sc->ah->ah_ant_mode);
380 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
381 sc->ah->ah_def_ant);
382 len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
383 sc->ah->ah_tx_ant);
384
385 len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
386 for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
387 len += snprintf(buf+len, sizeof(buf)-len,
388 "[antenna %d]\t%d\t%d\n",
389 i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
390 }
391 len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
392 sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);
393
394 v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
395 len += snprintf(buf+len, sizeof(buf)-len,
396 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
397
398 v = ath5k_hw_reg_read(sc->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);
411
412 v = ath5k_hw_reg_read(sc->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);
416
417 v = ath5k_hw_reg_read(sc->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);
421
422 v = ath5k_hw_reg_read(sc->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);
426
427 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
428}
429
430static ssize_t write_file_antenna(struct file *file,
431 const char __user *userbuf,
432 size_t count, loff_t *ppos)
433{
434 struct ath5k_softc *sc = file->private_data;
435 unsigned int i;
436 char buf[20];
437
438 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
439 return -EFAULT;
440
441 if (strncmp(buf, "diversity", 9) == 0) {
442 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
443 printk(KERN_INFO "ath5k debug: enable diversity\n");
444 } else if (strncmp(buf, "fixed-a", 7) == 0) {
445 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
446 printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
447 } else if (strncmp(buf, "fixed-b", 7) == 0) {
448 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
449 printk(KERN_INFO "ath5k debug: fixed antenna B\n");
450 } else if (strncmp(buf, "clear", 5) == 0) {
451 for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
452 sc->stats.antenna_rx[i] = 0;
453 sc->stats.antenna_tx[i] = 0;
454 }
455 printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
456 }
457 return count;
458}
459
460static const struct file_operations fops_antenna = {
461 .read = read_file_antenna,
462 .write = write_file_antenna,
463 .open = ath5k_debugfs_open,
464 .owner = THIS_MODULE,
465};
466
467
Bruno Randolf76443952010-03-09 16:56:00 +0900468/* debugfs: frameerrors */
469
470static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
471 size_t count, loff_t *ppos)
472{
473 struct ath5k_softc *sc = file->private_data;
474 struct ath5k_statistics *st = &sc->stats;
475 char buf[700];
476 unsigned int len = 0;
Bruno Randolfda351112010-03-25 14:49:42 +0900477 int i;
Bruno Randolf76443952010-03-09 16:56:00 +0900478
479 len += snprintf(buf+len, sizeof(buf)-len,
480 "RX\n---------------------\n");
481 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
482 st->rxerr_crc,
483 st->rx_all_count > 0 ?
484 st->rxerr_crc*100/st->rx_all_count : 0);
485 len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
486 st->rxerr_phy,
487 st->rx_all_count > 0 ?
488 st->rxerr_phy*100/st->rx_all_count : 0);
Bruno Randolfda351112010-03-25 14:49:42 +0900489 for (i = 0; i < 32; i++) {
490 if (st->rxerr_phy_code[i])
491 len += snprintf(buf+len, sizeof(buf)-len,
492 " phy_err[%d]\t%d\n",
493 i, st->rxerr_phy_code[i]);
494 }
495
Bruno Randolf76443952010-03-09 16:56:00 +0900496 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
497 st->rxerr_fifo,
498 st->rx_all_count > 0 ?
499 st->rxerr_fifo*100/st->rx_all_count : 0);
500 len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
501 st->rxerr_decrypt,
502 st->rx_all_count > 0 ?
503 st->rxerr_decrypt*100/st->rx_all_count : 0);
504 len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
505 st->rxerr_mic,
506 st->rx_all_count > 0 ?
507 st->rxerr_mic*100/st->rx_all_count : 0);
508 len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
509 st->rxerr_proc,
510 st->rx_all_count > 0 ?
511 st->rxerr_proc*100/st->rx_all_count : 0);
512 len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
513 st->rxerr_jumbo,
514 st->rx_all_count > 0 ?
515 st->rxerr_jumbo*100/st->rx_all_count : 0);
516 len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
517 st->rx_all_count);
518
519 len += snprintf(buf+len, sizeof(buf)-len,
520 "\nTX\n---------------------\n");
521 len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
522 st->txerr_retry,
523 st->tx_all_count > 0 ?
524 st->txerr_retry*100/st->tx_all_count : 0);
525 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
526 st->txerr_fifo,
527 st->tx_all_count > 0 ?
528 st->txerr_fifo*100/st->tx_all_count : 0);
529 len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
530 st->txerr_filt,
531 st->tx_all_count > 0 ?
532 st->txerr_filt*100/st->tx_all_count : 0);
533 len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
534 st->tx_all_count);
535
536 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
537}
538
539static ssize_t write_file_frameerrors(struct file *file,
540 const char __user *userbuf,
541 size_t count, loff_t *ppos)
542{
543 struct ath5k_softc *sc = file->private_data;
544 struct ath5k_statistics *st = &sc->stats;
545 char buf[20];
546
547 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
548 return -EFAULT;
549
550 if (strncmp(buf, "clear", 5) == 0) {
551 st->rxerr_crc = 0;
552 st->rxerr_phy = 0;
553 st->rxerr_fifo = 0;
554 st->rxerr_decrypt = 0;
555 st->rxerr_mic = 0;
556 st->rxerr_proc = 0;
557 st->rxerr_jumbo = 0;
558 st->rx_all_count = 0;
559 st->txerr_retry = 0;
560 st->txerr_fifo = 0;
561 st->txerr_filt = 0;
562 st->tx_all_count = 0;
563 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
564 }
565 return count;
566}
567
568static const struct file_operations fops_frameerrors = {
569 .read = read_file_frameerrors,
570 .write = write_file_frameerrors,
571 .open = ath5k_debugfs_open,
572 .owner = THIS_MODULE,
573};
574
575
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200576/* init */
577
578void
579ath5k_debug_init(void)
580{
581 ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
582}
583
584void
585ath5k_debug_init_device(struct ath5k_softc *sc)
586{
587 sc->debug.level = ath5k_debug;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900588
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200589 sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900590 ath5k_global_debugfs);
591
Jiri Slaby31670072009-06-28 23:25:27 +0200592 sc->debug.debugfs_debug = debugfs_create_file("debug",
593 S_IWUSR | S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900594 sc->debug.debugfs_phydir, sc, &fops_debug);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200595
Jiri Slaby31670072009-06-28 23:25:27 +0200596 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900597 sc->debug.debugfs_phydir, sc, &fops_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200598
Jiri Slaby31670072009-06-28 23:25:27 +0200599 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
600 S_IWUSR | S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900601 sc->debug.debugfs_phydir, sc, &fops_beacon);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200602
Cheng Renquan33ab6252008-11-22 11:22:49 +0800603 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900604 sc->debug.debugfs_phydir, sc, &fops_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +0900605
606 sc->debug.debugfs_antenna = debugfs_create_file("antenna",
607 S_IWUSR | S_IRUSR,
608 sc->debug.debugfs_phydir, sc, &fops_antenna);
Bruno Randolf76443952010-03-09 16:56:00 +0900609
610 sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
611 S_IWUSR | S_IRUSR,
612 sc->debug.debugfs_phydir, sc,
613 &fops_frameerrors);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200614}
615
616void
617ath5k_debug_finish(void)
618{
619 debugfs_remove(ath5k_global_debugfs);
620}
621
622void
623ath5k_debug_finish_device(struct ath5k_softc *sc)
624{
625 debugfs_remove(sc->debug.debugfs_debug);
626 debugfs_remove(sc->debug.debugfs_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200627 debugfs_remove(sc->debug.debugfs_beacon);
628 debugfs_remove(sc->debug.debugfs_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +0900629 debugfs_remove(sc->debug.debugfs_antenna);
Bruno Randolf76443952010-03-09 16:56:00 +0900630 debugfs_remove(sc->debug.debugfs_frameerrors);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200631 debugfs_remove(sc->debug.debugfs_phydir);
632}
633
634
635/* functions used in other places */
636
637void
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500638ath5k_debug_dump_bands(struct ath5k_softc *sc)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200639{
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500640 unsigned int b, i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200641
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500642 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200643 return;
644
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500645 BUG_ON(!sc->sbands);
646
647 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
648 struct ieee80211_supported_band *band = &sc->sbands[b];
Bob Copelandb7fcb5c2009-04-27 22:12:43 -0400649 char bname[6];
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500650 switch (band->band) {
651 case IEEE80211_BAND_2GHZ:
652 strcpy(bname, "2 GHz");
653 break;
654 case IEEE80211_BAND_5GHZ:
655 strcpy(bname, "5 GHz");
656 break;
657 default:
658 printk(KERN_DEBUG "Band not supported: %d\n",
659 band->band);
660 return;
661 }
662 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
663 band->n_channels, band->n_bitrates);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200664 printk(KERN_DEBUG " channels:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500665 for (i = 0; i < band->n_channels; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200666 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500667 ieee80211_frequency_to_channel(
668 band->channels[i].center_freq),
669 band->channels[i].center_freq,
670 band->channels[i].hw_value,
671 band->channels[i].flags);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200672 printk(KERN_DEBUG " rates:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500673 for (i = 0; i < band->n_bitrates; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200674 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500675 band->bitrates[i].bitrate,
676 band->bitrates[i].hw_value,
677 band->bitrates[i].flags,
678 band->bitrates[i].hw_value_short);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200679 }
680}
681
682static inline void
Bruno Randolfb47f4072008-03-05 18:35:45 +0900683ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
684 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200685{
686 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900687 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200688
689 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
690 ds, (unsigned long long)bf->daddr,
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900691 ds->ds_link, ds->ds_data,
692 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
693 rd->u.rx_stat.rx_status_0, rd->u.rx_stat.rx_status_0,
Bruno Randolfb47f4072008-03-05 18:35:45 +0900694 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200695}
696
697void
698ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
699{
700 struct ath5k_desc *ds;
701 struct ath5k_buf *bf;
Bruno Randolfb47f4072008-03-05 18:35:45 +0900702 struct ath5k_rx_status rs = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200703 int status;
704
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900705 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200706 return;
707
708 printk(KERN_DEBUG "rx queue %x, link %p\n",
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300709 ath5k_hw_get_rxdp(ah), sc->rxlink);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200710
711 spin_lock_bh(&sc->rxbuflock);
712 list_for_each_entry(bf, &sc->rxbuf, list) {
713 ds = bf->desc;
Bruno Randolfb47f4072008-03-05 18:35:45 +0900714 status = ah->ah_proc_rx_desc(ah, ds, &rs);
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900715 if (!status)
Bruno Randolfb47f4072008-03-05 18:35:45 +0900716 ath5k_debug_printrxbuf(bf, status == 0, &rs);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200717 }
718 spin_unlock_bh(&sc->rxbuflock);
719}
720
721void
722ath5k_debug_dump_skb(struct ath5k_softc *sc,
723 struct sk_buff *skb, const char *prefix, int tx)
724{
725 char buf[16];
726
727 if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
728 (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
729 return;
730
731 snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
732
733 print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
734 min(200U, skb->len));
735
736 printk(KERN_DEBUG "\n");
737}
738
739void
Bruno Randolfb47f4072008-03-05 18:35:45 +0900740ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200741{
742 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900743 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
Bruno Randolfb47f4072008-03-05 18:35:45 +0900744 struct ath5k_tx_status ts = {};
745 int done;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200746
747 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
748 return;
749
Bruno Randolfb47f4072008-03-05 18:35:45 +0900750 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
751
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200752 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
753 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900754 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
755 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
756 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +0900757 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200758}
759
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500760#endif /* ifdef CONFIG_ATH5K_DEBUG */