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