blob: 129b72684dafc17e54cab670669f637520830d52 [file] [log] [blame]
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001/*
Bruno Randolfbe9b7252008-01-23 10:27:51 +09002 * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com>
Jiri Slabyfa1c1142007-08-12 17:33:16 +02003 *
4 * This file is free software: you may copy, redistribute and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation, either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This file is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 *
18 * This file incorporates work covered by the following copyright and
19 * permission notice:
20 *
21 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
22 * Copyright (c) 2004-2005 Atheros Communications, Inc.
23 * Copyright (c) 2006 Devicescape Software, Inc.
24 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
25 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
26 *
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer,
34 * without modification.
35 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
36 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
37 * redistribution must be conditioned upon including a substantially
38 * similar Disclaimer requirement for further binary redistribution.
39 * 3. Neither the names of the above-listed copyright holders nor the names
40 * of any contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * Alternatively, this software may be distributed under the terms of the
44 * GNU General Public License ("GPL") version 2 as published by the Free
45 * Software Foundation.
46 *
47 * NO WARRANTY
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
51 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
52 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
53 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
56 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
58 * THE POSSIBILITY OF SUCH DAMAGES.
59 */
60
Jiri Slabyfa1c1142007-08-12 17:33:16 +020061#include "base.h"
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030062#include "debug.h"
Jiri Slabyfa1c1142007-08-12 17:33:16 +020063
64static unsigned int ath5k_debug;
65module_param_named(debug, ath5k_debug, uint, 0);
66
67
Luis R. Rodriguezb4461972008-02-04 10:03:54 -050068#ifdef CONFIG_ATH5K_DEBUG
Jiri Slabyfa1c1142007-08-12 17:33:16 +020069
70#include <linux/seq_file.h>
71#include "reg.h"
72
73static struct dentry *ath5k_global_debugfs;
74
75static int ath5k_debugfs_open(struct inode *inode, struct file *file)
76{
77 file->private_data = inode->i_private;
78 return 0;
79}
80
81
82/* debugfs: registers */
83
84struct reg {
85 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 */
92static 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),
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300132 REG_STRUCT_INIT(AR5K_CPCOVF),
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200133 REG_STRUCT_INIT(AR5K_RESET_CTL),
134 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
135 REG_STRUCT_INIT(AR5K_INTPEND),
136 REG_STRUCT_INIT(AR5K_SFR),
137 REG_STRUCT_INIT(AR5K_PCICFG),
138 REG_STRUCT_INIT(AR5K_GPIOCR),
139 REG_STRUCT_INIT(AR5K_GPIODO),
140 REG_STRUCT_INIT(AR5K_SREV),
141};
142
143static void *reg_start(struct seq_file *seq, loff_t *pos)
144{
145 return *pos < ARRAY_SIZE(regs) ? &regs[*pos] : NULL;
146}
147
148static void reg_stop(struct seq_file *seq, void *p)
149{
150 /* nothing to do */
151}
152
153static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
154{
155 ++*pos;
156 return *pos < ARRAY_SIZE(regs) ? &regs[*pos] : NULL;
157}
158
159static int reg_show(struct seq_file *seq, void *p)
160{
161 struct ath5k_softc *sc = seq->private;
162 struct reg *r = p;
163 seq_printf(seq, "%-25s0x%08x\n", r->name,
164 ath5k_hw_reg_read(sc->ah, r->addr));
165 return 0;
166}
167
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800168static const struct seq_operations register_seq_ops = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200169 .start = reg_start,
170 .next = reg_next,
171 .stop = reg_stop,
172 .show = reg_show
173};
174
175static int open_file_registers(struct inode *inode, struct file *file)
176{
177 struct seq_file *s;
178 int res;
179 res = seq_open(file, &register_seq_ops);
180 if (res == 0) {
181 s = file->private_data;
182 s->private = inode->i_private;
183 }
184 return res;
185}
186
187static const struct file_operations fops_registers = {
188 .open = open_file_registers,
189 .read = seq_read,
190 .llseek = seq_lseek,
191 .release = seq_release,
192 .owner = THIS_MODULE,
193};
194
195
196/* debugfs: TSF */
197
198static ssize_t read_file_tsf(struct file *file, char __user *user_buf,
199 size_t count, loff_t *ppos)
200{
201 struct ath5k_softc *sc = file->private_data;
202 char buf[100];
John W. Linvillef868f4e2008-03-07 16:38:43 -0500203 snprintf(buf, sizeof(buf), "0x%016llx\n",
204 (unsigned long long)ath5k_hw_get_tsf64(sc->ah));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200205 return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
206}
207
208static ssize_t write_file_tsf(struct file *file,
209 const char __user *userbuf,
210 size_t count, loff_t *ppos)
211{
212 struct ath5k_softc *sc = file->private_data;
Alina Friedrichsen8cab7582009-01-23 05:39:13 +0100213 char buf[21];
214 unsigned long long tsf;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900215
Alina Friedrichsen8cab7582009-01-23 05:39:13 +0100216 if (copy_from_user(buf, userbuf, min(count, sizeof(buf) - 1)))
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900217 return -EFAULT;
Alina Friedrichsen8cab7582009-01-23 05:39:13 +0100218 buf[sizeof(buf) - 1] = '\0';
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900219
220 if (strncmp(buf, "reset", 5) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200221 ath5k_hw_reset_tsf(sc->ah);
222 printk(KERN_INFO "debugfs reset TSF\n");
Alina Friedrichsen8cab7582009-01-23 05:39:13 +0100223 } else {
224 tsf = simple_strtoul(buf, NULL, 0);
225 ath5k_hw_set_tsf64(sc->ah, tsf);
226 printk(KERN_INFO "debugfs set TSF to %#018llx\n", tsf);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200227 }
Alina Friedrichsen8cab7582009-01-23 05:39:13 +0100228
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200229 return count;
230}
231
232static const struct file_operations fops_tsf = {
233 .read = read_file_tsf,
234 .write = write_file_tsf,
235 .open = ath5k_debugfs_open,
236 .owner = THIS_MODULE,
237};
238
239
240/* debugfs: beacons */
241
242static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
243 size_t count, loff_t *ppos)
244{
245 struct ath5k_softc *sc = file->private_data;
246 struct ath5k_hw *ah = sc->ah;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900247 char buf[500];
248 unsigned int len = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200249 unsigned int v;
250 u64 tsf;
251
252 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
253 len += snprintf(buf+len, sizeof(buf)-len,
254 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
255 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
256 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
257
258 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
259 "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
260
261 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
262 "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
263
264 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
265 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
266 "AR5K_TIMER0 (TBTT)", v, v);
267
268 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
269 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
270 "AR5K_TIMER1 (DMA)", v, v >> 3);
271
272 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
273 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
274 "AR5K_TIMER2 (SWBA)", v, v >> 3);
275
276 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
277 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
278 "AR5K_TIMER3 (ATIM)", v, v);
279
280 tsf = ath5k_hw_get_tsf64(sc->ah);
281 len += snprintf(buf+len, sizeof(buf)-len,
John W. Linvillef868f4e2008-03-07 16:38:43 -0500282 "TSF\t\t0x%016llx\tTU: %08x\n",
283 (unsigned long long)tsf, TSF_TO_TU(tsf));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200284
285 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
286}
287
288static ssize_t write_file_beacon(struct file *file,
289 const char __user *userbuf,
290 size_t count, loff_t *ppos)
291{
292 struct ath5k_softc *sc = file->private_data;
293 struct ath5k_hw *ah = sc->ah;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900294 char buf[20];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200295
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900296 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
297 return -EFAULT;
298
299 if (strncmp(buf, "disable", 7) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200300 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
301 printk(KERN_INFO "debugfs disable beacons\n");
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900302 } else if (strncmp(buf, "enable", 6) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200303 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
304 printk(KERN_INFO "debugfs enable beacons\n");
305 }
306 return count;
307}
308
309static const struct file_operations fops_beacon = {
310 .read = read_file_beacon,
311 .write = write_file_beacon,
312 .open = ath5k_debugfs_open,
313 .owner = THIS_MODULE,
314};
315
316
317/* debugfs: reset */
318
319static ssize_t write_file_reset(struct file *file,
320 const char __user *userbuf,
321 size_t count, loff_t *ppos)
322{
323 struct ath5k_softc *sc = file->private_data;
324 tasklet_schedule(&sc->restq);
325 return count;
326}
327
328static const struct file_operations fops_reset = {
329 .write = write_file_reset,
330 .open = ath5k_debugfs_open,
331 .owner = THIS_MODULE,
332};
333
334
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900335/* debugfs: debug level */
336
337static struct {
338 enum ath5k_debug_level level;
339 const char *name;
340 const char *desc;
341} dbg_info[] = {
342 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
343 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
344 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
345 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
346 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
347 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
348 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
Bob Copeland85519a62008-10-29 08:30:53 -0400349 { ATH5K_DEBUG_LED, "led", "LED management" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900350 { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
351 { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500352 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900353 { ATH5K_DEBUG_TRACE, "trace", "trace function calls" },
354 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
355};
356
357static ssize_t read_file_debug(struct file *file, char __user *user_buf,
358 size_t count, loff_t *ppos)
359{
360 struct ath5k_softc *sc = file->private_data;
361 char buf[700];
362 unsigned int len = 0;
363 unsigned int i;
364
365 len += snprintf(buf+len, sizeof(buf)-len,
366 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
367
368 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
369 len += snprintf(buf+len, sizeof(buf)-len,
370 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
371 sc->debug.level & dbg_info[i].level ? '+' : ' ',
372 dbg_info[i].level, dbg_info[i].desc);
373 }
374 len += snprintf(buf+len, sizeof(buf)-len,
375 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
376 sc->debug.level == dbg_info[i].level ? '+' : ' ',
377 dbg_info[i].level, dbg_info[i].desc);
378
379 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
380}
381
382static ssize_t write_file_debug(struct file *file,
383 const char __user *userbuf,
384 size_t count, loff_t *ppos)
385{
386 struct ath5k_softc *sc = file->private_data;
387 unsigned int i;
388 char buf[20];
389
390 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
391 return -EFAULT;
392
393 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
394 if (strncmp(buf, dbg_info[i].name,
395 strlen(dbg_info[i].name)) == 0) {
396 sc->debug.level ^= dbg_info[i].level; /* toggle bit */
397 break;
398 }
399 }
400 return count;
401}
402
403static const struct file_operations fops_debug = {
404 .read = read_file_debug,
405 .write = write_file_debug,
406 .open = ath5k_debugfs_open,
407 .owner = THIS_MODULE,
408};
409
410
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200411/* init */
412
413void
414ath5k_debug_init(void)
415{
416 ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
417}
418
419void
420ath5k_debug_init_device(struct ath5k_softc *sc)
421{
422 sc->debug.level = ath5k_debug;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900423
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200424 sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900425 ath5k_global_debugfs);
426
Cheng Renquan33ab6252008-11-22 11:22:49 +0800427 sc->debug.debugfs_debug = debugfs_create_file("debug", S_IWUSR | S_IRUGO,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900428 sc->debug.debugfs_phydir, sc, &fops_debug);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200429
Cheng Renquan33ab6252008-11-22 11:22:49 +0800430 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUGO,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900431 sc->debug.debugfs_phydir, sc, &fops_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200432
Cheng Renquan33ab6252008-11-22 11:22:49 +0800433 sc->debug.debugfs_tsf = debugfs_create_file("tsf", S_IWUSR | S_IRUGO,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900434 sc->debug.debugfs_phydir, sc, &fops_tsf);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200435
Cheng Renquan33ab6252008-11-22 11:22:49 +0800436 sc->debug.debugfs_beacon = debugfs_create_file("beacon", S_IWUSR | S_IRUGO,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900437 sc->debug.debugfs_phydir, sc, &fops_beacon);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200438
Cheng Renquan33ab6252008-11-22 11:22:49 +0800439 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900440 sc->debug.debugfs_phydir, sc, &fops_reset);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200441}
442
443void
444ath5k_debug_finish(void)
445{
446 debugfs_remove(ath5k_global_debugfs);
447}
448
449void
450ath5k_debug_finish_device(struct ath5k_softc *sc)
451{
452 debugfs_remove(sc->debug.debugfs_debug);
453 debugfs_remove(sc->debug.debugfs_registers);
454 debugfs_remove(sc->debug.debugfs_tsf);
455 debugfs_remove(sc->debug.debugfs_beacon);
456 debugfs_remove(sc->debug.debugfs_reset);
457 debugfs_remove(sc->debug.debugfs_phydir);
458}
459
460
461/* functions used in other places */
462
463void
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500464ath5k_debug_dump_bands(struct ath5k_softc *sc)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200465{
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500466 unsigned int b, i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200467
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500468 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200469 return;
470
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500471 BUG_ON(!sc->sbands);
472
473 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
474 struct ieee80211_supported_band *band = &sc->sbands[b];
475 char bname[5];
476 switch (band->band) {
477 case IEEE80211_BAND_2GHZ:
478 strcpy(bname, "2 GHz");
479 break;
480 case IEEE80211_BAND_5GHZ:
481 strcpy(bname, "5 GHz");
482 break;
483 default:
484 printk(KERN_DEBUG "Band not supported: %d\n",
485 band->band);
486 return;
487 }
488 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
489 band->n_channels, band->n_bitrates);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200490 printk(KERN_DEBUG " channels:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500491 for (i = 0; i < band->n_channels; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200492 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500493 ieee80211_frequency_to_channel(
494 band->channels[i].center_freq),
495 band->channels[i].center_freq,
496 band->channels[i].hw_value,
497 band->channels[i].flags);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200498 printk(KERN_DEBUG " rates:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500499 for (i = 0; i < band->n_bitrates; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200500 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500501 band->bitrates[i].bitrate,
502 band->bitrates[i].hw_value,
503 band->bitrates[i].flags,
504 band->bitrates[i].hw_value_short);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200505 }
506}
507
508static inline void
Bruno Randolfb47f4072008-03-05 18:35:45 +0900509ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
510 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200511{
512 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900513 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200514
515 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
516 ds, (unsigned long long)bf->daddr,
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900517 ds->ds_link, ds->ds_data,
518 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
519 rd->u.rx_stat.rx_status_0, rd->u.rx_stat.rx_status_0,
Bruno Randolfb47f4072008-03-05 18:35:45 +0900520 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200521}
522
523void
524ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
525{
526 struct ath5k_desc *ds;
527 struct ath5k_buf *bf;
Bruno Randolfb47f4072008-03-05 18:35:45 +0900528 struct ath5k_rx_status rs = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200529 int status;
530
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900531 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200532 return;
533
534 printk(KERN_DEBUG "rx queue %x, link %p\n",
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300535 ath5k_hw_get_rxdp(ah), sc->rxlink);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200536
537 spin_lock_bh(&sc->rxbuflock);
538 list_for_each_entry(bf, &sc->rxbuf, list) {
539 ds = bf->desc;
Bruno Randolfb47f4072008-03-05 18:35:45 +0900540 status = ah->ah_proc_rx_desc(ah, ds, &rs);
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900541 if (!status)
Bruno Randolfb47f4072008-03-05 18:35:45 +0900542 ath5k_debug_printrxbuf(bf, status == 0, &rs);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200543 }
544 spin_unlock_bh(&sc->rxbuflock);
545}
546
547void
548ath5k_debug_dump_skb(struct ath5k_softc *sc,
549 struct sk_buff *skb, const char *prefix, int tx)
550{
551 char buf[16];
552
553 if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
554 (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
555 return;
556
557 snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
558
559 print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
560 min(200U, skb->len));
561
562 printk(KERN_DEBUG "\n");
563}
564
565void
Bruno Randolfb47f4072008-03-05 18:35:45 +0900566ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200567{
568 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900569 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
Bruno Randolfb47f4072008-03-05 18:35:45 +0900570 struct ath5k_tx_status ts = {};
571 int done;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200572
573 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
574 return;
575
Bruno Randolfb47f4072008-03-05 18:35:45 +0900576 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
577
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200578 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
579 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900580 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
581 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
582 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +0900583 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200584}
585
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500586#endif /* ifdef CONFIG_ATH5K_DEBUG */