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