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