blob: fb339c3852ee6859b327a5d366165b1c45d8eea5 [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"
Bruno Randolf2111ac02010-04-02 18:44:08 +090072#include "ani.h"
Jiri Slabyfa1c1142007-08-12 17:33:16 +020073
74static struct dentry *ath5k_global_debugfs;
75
76static int ath5k_debugfs_open(struct inode *inode, struct file *file)
77{
78 file->private_data = inode->i_private;
79 return 0;
80}
81
82
83/* debugfs: registers */
84
85struct reg {
Jiri Slaby2c91108c2009-03-07 10:26:41 +010086 const char *name;
Jiri Slabyfa1c1142007-08-12 17:33:16 +020087 int addr;
88};
89
90#define REG_STRUCT_INIT(r) { #r, r }
91
92/* just a few random registers, might want to add more */
Jiri Slaby2c91108c2009-03-07 10:26:41 +010093static const struct reg regs[] = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +020094 REG_STRUCT_INIT(AR5K_CR),
95 REG_STRUCT_INIT(AR5K_RXDP),
96 REG_STRUCT_INIT(AR5K_CFG),
97 REG_STRUCT_INIT(AR5K_IER),
98 REG_STRUCT_INIT(AR5K_BCR),
99 REG_STRUCT_INIT(AR5K_RTSD0),
100 REG_STRUCT_INIT(AR5K_RTSD1),
101 REG_STRUCT_INIT(AR5K_TXCFG),
102 REG_STRUCT_INIT(AR5K_RXCFG),
103 REG_STRUCT_INIT(AR5K_RXJLA),
104 REG_STRUCT_INIT(AR5K_MIBC),
105 REG_STRUCT_INIT(AR5K_TOPS),
106 REG_STRUCT_INIT(AR5K_RXNOFRM),
107 REG_STRUCT_INIT(AR5K_TXNOFRM),
108 REG_STRUCT_INIT(AR5K_RPGTO),
109 REG_STRUCT_INIT(AR5K_RFCNT),
110 REG_STRUCT_INIT(AR5K_MISC),
111 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
112 REG_STRUCT_INIT(AR5K_ISR),
113 REG_STRUCT_INIT(AR5K_PISR),
114 REG_STRUCT_INIT(AR5K_SISR0),
115 REG_STRUCT_INIT(AR5K_SISR1),
116 REG_STRUCT_INIT(AR5K_SISR2),
117 REG_STRUCT_INIT(AR5K_SISR3),
118 REG_STRUCT_INIT(AR5K_SISR4),
119 REG_STRUCT_INIT(AR5K_IMR),
120 REG_STRUCT_INIT(AR5K_PIMR),
121 REG_STRUCT_INIT(AR5K_SIMR0),
122 REG_STRUCT_INIT(AR5K_SIMR1),
123 REG_STRUCT_INIT(AR5K_SIMR2),
124 REG_STRUCT_INIT(AR5K_SIMR3),
125 REG_STRUCT_INIT(AR5K_SIMR4),
126 REG_STRUCT_INIT(AR5K_DCM_ADDR),
127 REG_STRUCT_INIT(AR5K_DCCFG),
128 REG_STRUCT_INIT(AR5K_CCFG),
129 REG_STRUCT_INIT(AR5K_CPC0),
130 REG_STRUCT_INIT(AR5K_CPC1),
131 REG_STRUCT_INIT(AR5K_CPC2),
132 REG_STRUCT_INIT(AR5K_CPC3),
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300133 REG_STRUCT_INIT(AR5K_CPCOVF),
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200134 REG_STRUCT_INIT(AR5K_RESET_CTL),
135 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
136 REG_STRUCT_INIT(AR5K_INTPEND),
137 REG_STRUCT_INIT(AR5K_SFR),
138 REG_STRUCT_INIT(AR5K_PCICFG),
139 REG_STRUCT_INIT(AR5K_GPIOCR),
140 REG_STRUCT_INIT(AR5K_GPIODO),
141 REG_STRUCT_INIT(AR5K_SREV),
142};
143
144static void *reg_start(struct seq_file *seq, loff_t *pos)
145{
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100146 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200147}
148
149static void reg_stop(struct seq_file *seq, void *p)
150{
151 /* nothing to do */
152}
153
154static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
155{
156 ++*pos;
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100157 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200158}
159
160static int reg_show(struct seq_file *seq, void *p)
161{
162 struct ath5k_softc *sc = seq->private;
163 struct reg *r = p;
164 seq_printf(seq, "%-25s0x%08x\n", r->name,
165 ath5k_hw_reg_read(sc->ah, r->addr));
166 return 0;
167}
168
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800169static const struct seq_operations register_seq_ops = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200170 .start = reg_start,
171 .next = reg_next,
172 .stop = reg_stop,
173 .show = reg_show
174};
175
176static int open_file_registers(struct inode *inode, struct file *file)
177{
178 struct seq_file *s;
179 int res;
180 res = seq_open(file, &register_seq_ops);
181 if (res == 0) {
182 s = file->private_data;
183 s->private = inode->i_private;
184 }
185 return res;
186}
187
188static const struct file_operations fops_registers = {
189 .open = open_file_registers,
190 .read = seq_read,
191 .llseek = seq_lseek,
192 .release = seq_release,
193 .owner = THIS_MODULE,
194};
195
196
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200197/* debugfs: beacons */
198
199static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
200 size_t count, loff_t *ppos)
201{
202 struct ath5k_softc *sc = file->private_data;
203 struct ath5k_hw *ah = sc->ah;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900204 char buf[500];
205 unsigned int len = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200206 unsigned int v;
207 u64 tsf;
208
209 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
210 len += snprintf(buf+len, sizeof(buf)-len,
211 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
212 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
213 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
214
215 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
216 "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
217
218 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
219 "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
220
221 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
222 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
223 "AR5K_TIMER0 (TBTT)", v, v);
224
225 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
226 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
227 "AR5K_TIMER1 (DMA)", v, v >> 3);
228
229 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
230 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
231 "AR5K_TIMER2 (SWBA)", v, v >> 3);
232
233 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
234 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
235 "AR5K_TIMER3 (ATIM)", v, v);
236
237 tsf = ath5k_hw_get_tsf64(sc->ah);
238 len += snprintf(buf+len, sizeof(buf)-len,
John W. Linvillef868f4e2008-03-07 16:38:43 -0500239 "TSF\t\t0x%016llx\tTU: %08x\n",
240 (unsigned long long)tsf, TSF_TO_TU(tsf));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200241
Dan Carpenter2189d132010-07-22 10:52:02 +0200242 if (len > sizeof(buf))
243 len = sizeof(buf);
244
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200245 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
246}
247
248static ssize_t write_file_beacon(struct file *file,
249 const char __user *userbuf,
250 size_t count, loff_t *ppos)
251{
252 struct ath5k_softc *sc = file->private_data;
253 struct ath5k_hw *ah = sc->ah;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900254 char buf[20];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200255
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900256 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
257 return -EFAULT;
258
259 if (strncmp(buf, "disable", 7) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200260 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
261 printk(KERN_INFO "debugfs disable beacons\n");
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900262 } else if (strncmp(buf, "enable", 6) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200263 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
264 printk(KERN_INFO "debugfs enable beacons\n");
265 }
266 return count;
267}
268
269static const struct file_operations fops_beacon = {
270 .read = read_file_beacon,
271 .write = write_file_beacon,
272 .open = ath5k_debugfs_open,
273 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200274 .llseek = default_llseek,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200275};
276
277
278/* debugfs: reset */
279
280static ssize_t write_file_reset(struct file *file,
281 const char __user *userbuf,
282 size_t count, loff_t *ppos)
283{
284 struct ath5k_softc *sc = file->private_data;
Bruno Randolf8d67a032010-06-16 19:11:12 +0900285 ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
Bob Copeland5faaff72010-07-13 11:32:40 -0400286 ieee80211_queue_work(sc->hw, &sc->reset_work);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200287 return count;
288}
289
290static const struct file_operations fops_reset = {
291 .write = write_file_reset,
292 .open = ath5k_debugfs_open,
293 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200294 .llseek = noop_llseek,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200295};
296
297
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900298/* debugfs: debug level */
299
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100300static const struct {
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900301 enum ath5k_debug_level level;
302 const char *name;
303 const char *desc;
304} dbg_info[] = {
305 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
306 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
307 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
308 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
309 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
310 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
311 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
Bob Copeland85519a62008-10-29 08:30:53 -0400312 { ATH5K_DEBUG_LED, "led", "LED management" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900313 { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
314 { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500315 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
Bruno Randolf2111ac02010-04-02 18:44:08 +0900316 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900317 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
318};
319
320static ssize_t read_file_debug(struct file *file, char __user *user_buf,
321 size_t count, loff_t *ppos)
322{
323 struct ath5k_softc *sc = file->private_data;
324 char buf[700];
325 unsigned int len = 0;
326 unsigned int i;
327
328 len += snprintf(buf+len, sizeof(buf)-len,
329 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
330
331 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
332 len += snprintf(buf+len, sizeof(buf)-len,
333 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
334 sc->debug.level & dbg_info[i].level ? '+' : ' ',
335 dbg_info[i].level, dbg_info[i].desc);
336 }
337 len += snprintf(buf+len, sizeof(buf)-len,
338 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
339 sc->debug.level == dbg_info[i].level ? '+' : ' ',
340 dbg_info[i].level, dbg_info[i].desc);
341
Dan Carpenter2189d132010-07-22 10:52:02 +0200342 if (len > sizeof(buf))
343 len = sizeof(buf);
344
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900345 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
346}
347
348static ssize_t write_file_debug(struct file *file,
349 const char __user *userbuf,
350 size_t count, loff_t *ppos)
351{
352 struct ath5k_softc *sc = file->private_data;
353 unsigned int i;
354 char buf[20];
355
356 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
357 return -EFAULT;
358
359 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
360 if (strncmp(buf, dbg_info[i].name,
361 strlen(dbg_info[i].name)) == 0) {
362 sc->debug.level ^= dbg_info[i].level; /* toggle bit */
363 break;
364 }
365 }
366 return count;
367}
368
369static const struct file_operations fops_debug = {
370 .read = read_file_debug,
371 .write = write_file_debug,
372 .open = ath5k_debugfs_open,
373 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200374 .llseek = default_llseek,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900375};
376
377
Bruno Randolf604eead2010-03-09 16:55:17 +0900378/* debugfs: antenna */
379
380static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
381 size_t count, loff_t *ppos)
382{
383 struct ath5k_softc *sc = file->private_data;
384 char buf[700];
385 unsigned int len = 0;
386 unsigned int i;
387 unsigned int v;
388
389 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
390 sc->ah->ah_ant_mode);
391 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
392 sc->ah->ah_def_ant);
393 len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
394 sc->ah->ah_tx_ant);
395
396 len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
397 for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
398 len += snprintf(buf+len, sizeof(buf)-len,
399 "[antenna %d]\t%d\t%d\n",
400 i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
401 }
402 len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
403 sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);
404
405 v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
406 len += snprintf(buf+len, sizeof(buf)-len,
407 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
408
409 v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1);
410 len += snprintf(buf+len, sizeof(buf)-len,
411 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
412 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
413 len += snprintf(buf+len, sizeof(buf)-len,
414 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
415 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
416 len += snprintf(buf+len, sizeof(buf)-len,
417 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
418 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
419 len += snprintf(buf+len, sizeof(buf)-len,
420 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
421 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
422
423 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL);
424 len += snprintf(buf+len, sizeof(buf)-len,
425 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
426 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
427
428 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART);
429 len += snprintf(buf+len, sizeof(buf)-len,
430 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
431 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
432
433 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV);
434 len += snprintf(buf+len, sizeof(buf)-len,
435 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
436 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
437
Bruno Randolf0ca74022010-06-07 13:11:30 +0900438 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
439 len += snprintf(buf+len, sizeof(buf)-len,
440 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
441 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
442 len += snprintf(buf+len, sizeof(buf)-len,
443 "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v);
444
Dan Carpenter2189d132010-07-22 10:52:02 +0200445 if (len > sizeof(buf))
446 len = sizeof(buf);
447
Bruno Randolf604eead2010-03-09 16:55:17 +0900448 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
449}
450
451static ssize_t write_file_antenna(struct file *file,
452 const char __user *userbuf,
453 size_t count, loff_t *ppos)
454{
455 struct ath5k_softc *sc = file->private_data;
456 unsigned int i;
457 char buf[20];
458
459 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
460 return -EFAULT;
461
462 if (strncmp(buf, "diversity", 9) == 0) {
463 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
464 printk(KERN_INFO "ath5k debug: enable diversity\n");
465 } else if (strncmp(buf, "fixed-a", 7) == 0) {
466 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
467 printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
468 } else if (strncmp(buf, "fixed-b", 7) == 0) {
469 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
470 printk(KERN_INFO "ath5k debug: fixed antenna B\n");
471 } else if (strncmp(buf, "clear", 5) == 0) {
472 for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
473 sc->stats.antenna_rx[i] = 0;
474 sc->stats.antenna_tx[i] = 0;
475 }
476 printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
477 }
478 return count;
479}
480
481static const struct file_operations fops_antenna = {
482 .read = read_file_antenna,
483 .write = write_file_antenna,
484 .open = ath5k_debugfs_open,
485 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200486 .llseek = default_llseek,
Bruno Randolf604eead2010-03-09 16:55:17 +0900487};
488
489
Bruno Randolf76443952010-03-09 16:56:00 +0900490/* debugfs: frameerrors */
491
492static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
493 size_t count, loff_t *ppos)
494{
495 struct ath5k_softc *sc = file->private_data;
496 struct ath5k_statistics *st = &sc->stats;
497 char buf[700];
498 unsigned int len = 0;
Bruno Randolfda351112010-03-25 14:49:42 +0900499 int i;
Bruno Randolf76443952010-03-09 16:56:00 +0900500
501 len += snprintf(buf+len, sizeof(buf)-len,
502 "RX\n---------------------\n");
503 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%d\t(%d%%)\n",
504 st->rxerr_crc,
505 st->rx_all_count > 0 ?
506 st->rxerr_crc*100/st->rx_all_count : 0);
507 len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%d\t(%d%%)\n",
508 st->rxerr_phy,
509 st->rx_all_count > 0 ?
510 st->rxerr_phy*100/st->rx_all_count : 0);
Bruno Randolfda351112010-03-25 14:49:42 +0900511 for (i = 0; i < 32; i++) {
512 if (st->rxerr_phy_code[i])
513 len += snprintf(buf+len, sizeof(buf)-len,
514 " phy_err[%d]\t%d\n",
515 i, st->rxerr_phy_code[i]);
516 }
517
Bruno Randolf76443952010-03-09 16:56:00 +0900518 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
519 st->rxerr_fifo,
520 st->rx_all_count > 0 ?
521 st->rxerr_fifo*100/st->rx_all_count : 0);
522 len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%d\t(%d%%)\n",
523 st->rxerr_decrypt,
524 st->rx_all_count > 0 ?
525 st->rxerr_decrypt*100/st->rx_all_count : 0);
526 len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%d\t(%d%%)\n",
527 st->rxerr_mic,
528 st->rx_all_count > 0 ?
529 st->rxerr_mic*100/st->rx_all_count : 0);
530 len += snprintf(buf+len, sizeof(buf)-len, "process\t%d\t(%d%%)\n",
531 st->rxerr_proc,
532 st->rx_all_count > 0 ?
533 st->rxerr_proc*100/st->rx_all_count : 0);
534 len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%d\t(%d%%)\n",
535 st->rxerr_jumbo,
536 st->rx_all_count > 0 ?
537 st->rxerr_jumbo*100/st->rx_all_count : 0);
538 len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%d]\n",
539 st->rx_all_count);
540
541 len += snprintf(buf+len, sizeof(buf)-len,
542 "\nTX\n---------------------\n");
543 len += snprintf(buf+len, sizeof(buf)-len, "retry\t%d\t(%d%%)\n",
544 st->txerr_retry,
545 st->tx_all_count > 0 ?
546 st->txerr_retry*100/st->tx_all_count : 0);
547 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%d\t(%d%%)\n",
548 st->txerr_fifo,
549 st->tx_all_count > 0 ?
550 st->txerr_fifo*100/st->tx_all_count : 0);
551 len += snprintf(buf+len, sizeof(buf)-len, "filter\t%d\t(%d%%)\n",
552 st->txerr_filt,
553 st->tx_all_count > 0 ?
554 st->txerr_filt*100/st->tx_all_count : 0);
555 len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%d]\n",
556 st->tx_all_count);
557
Dan Carpenter2189d132010-07-22 10:52:02 +0200558 if (len > sizeof(buf))
559 len = sizeof(buf);
560
Bruno Randolf76443952010-03-09 16:56:00 +0900561 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
562}
563
564static ssize_t write_file_frameerrors(struct file *file,
565 const char __user *userbuf,
566 size_t count, loff_t *ppos)
567{
568 struct ath5k_softc *sc = file->private_data;
569 struct ath5k_statistics *st = &sc->stats;
570 char buf[20];
571
572 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
573 return -EFAULT;
574
575 if (strncmp(buf, "clear", 5) == 0) {
576 st->rxerr_crc = 0;
577 st->rxerr_phy = 0;
578 st->rxerr_fifo = 0;
579 st->rxerr_decrypt = 0;
580 st->rxerr_mic = 0;
581 st->rxerr_proc = 0;
582 st->rxerr_jumbo = 0;
583 st->rx_all_count = 0;
584 st->txerr_retry = 0;
585 st->txerr_fifo = 0;
586 st->txerr_filt = 0;
587 st->tx_all_count = 0;
588 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
589 }
590 return count;
591}
592
593static const struct file_operations fops_frameerrors = {
594 .read = read_file_frameerrors,
595 .write = write_file_frameerrors,
596 .open = ath5k_debugfs_open,
597 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200598 .llseek = default_llseek,
Bruno Randolf76443952010-03-09 16:56:00 +0900599};
600
601
Bruno Randolf2111ac02010-04-02 18:44:08 +0900602/* debugfs: ani */
603
604static ssize_t read_file_ani(struct file *file, char __user *user_buf,
605 size_t count, loff_t *ppos)
606{
607 struct ath5k_softc *sc = file->private_data;
608 struct ath5k_statistics *st = &sc->stats;
609 struct ath5k_ani_state *as = &sc->ani_state;
610
611 char buf[700];
612 unsigned int len = 0;
613
614 len += snprintf(buf+len, sizeof(buf)-len,
615 "HW has PHY error counters:\t%s\n",
616 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
617 "yes" : "no");
618 len += snprintf(buf+len, sizeof(buf)-len,
619 "HW max spur immunity level:\t%d\n",
620 as->max_spur_level);
621 len += snprintf(buf+len, sizeof(buf)-len,
622 "\nANI state\n--------------------------------------------\n");
623 len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
624 switch (as->ani_mode) {
625 case ATH5K_ANI_MODE_OFF:
626 len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
627 break;
628 case ATH5K_ANI_MODE_MANUAL_LOW:
629 len += snprintf(buf+len, sizeof(buf)-len,
630 "MANUAL LOW\n");
631 break;
632 case ATH5K_ANI_MODE_MANUAL_HIGH:
633 len += snprintf(buf+len, sizeof(buf)-len,
634 "MANUAL HIGH\n");
635 break;
636 case ATH5K_ANI_MODE_AUTO:
637 len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
638 break;
639 default:
640 len += snprintf(buf+len, sizeof(buf)-len,
641 "??? (not good)\n");
642 break;
643 }
644 len += snprintf(buf+len, sizeof(buf)-len,
645 "noise immunity level:\t\t%d\n",
646 as->noise_imm_level);
647 len += snprintf(buf+len, sizeof(buf)-len,
648 "spur immunity level:\t\t%d\n",
649 as->spur_level);
650 len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
651 as->firstep_level);
652 len += snprintf(buf+len, sizeof(buf)-len,
653 "OFDM weak signal detection:\t%s\n",
654 as->ofdm_weak_sig ? "on" : "off");
655 len += snprintf(buf+len, sizeof(buf)-len,
656 "CCK weak signal detection:\t%s\n",
657 as->cck_weak_sig ? "on" : "off");
658
659 len += snprintf(buf+len, sizeof(buf)-len,
660 "\nMIB INTERRUPTS:\t\t%u\n",
661 st->mib_intr);
662 len += snprintf(buf+len, sizeof(buf)-len,
663 "beacon RSSI average:\t%d\n",
664 sc->ah->ah_beacon_rssi_avg.avg);
665 len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
666 as->pfc_tx,
667 as->pfc_cycles > 0 ?
668 as->pfc_tx*100/as->pfc_cycles : 0);
669 len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
670 as->pfc_rx,
671 as->pfc_cycles > 0 ?
672 as->pfc_rx*100/as->pfc_cycles : 0);
673 len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
674 as->pfc_busy,
675 as->pfc_cycles > 0 ?
676 as->pfc_busy*100/as->pfc_cycles : 0);
677 len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
678 as->pfc_cycles);
679 len += snprintf(buf+len, sizeof(buf)-len,
680 "listen time\t\t%d\tlast: %d\n",
681 as->listen_time, as->last_listen);
682 len += snprintf(buf+len, sizeof(buf)-len,
683 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
684 as->ofdm_errors, as->last_ofdm_errors,
685 as->sum_ofdm_errors);
686 len += snprintf(buf+len, sizeof(buf)-len,
687 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
688 as->cck_errors, as->last_cck_errors,
689 as->sum_cck_errors);
690 len += snprintf(buf+len, sizeof(buf)-len,
691 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
692 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
693 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
694 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
695 len += snprintf(buf+len, sizeof(buf)-len,
696 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
697 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
698 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
699 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
700
Dan Carpenter2189d132010-07-22 10:52:02 +0200701 if (len > sizeof(buf))
702 len = sizeof(buf);
703
Bruno Randolf2111ac02010-04-02 18:44:08 +0900704 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
705}
706
707static ssize_t write_file_ani(struct file *file,
708 const char __user *userbuf,
709 size_t count, loff_t *ppos)
710{
711 struct ath5k_softc *sc = file->private_data;
712 char buf[20];
713
714 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
715 return -EFAULT;
716
717 if (strncmp(buf, "sens-low", 8) == 0) {
718 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
719 } else if (strncmp(buf, "sens-high", 9) == 0) {
720 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
721 } else if (strncmp(buf, "ani-off", 7) == 0) {
722 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
723 } else if (strncmp(buf, "ani-on", 6) == 0) {
724 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
725 } else if (strncmp(buf, "noise-low", 9) == 0) {
726 ath5k_ani_set_noise_immunity_level(sc->ah, 0);
727 } else if (strncmp(buf, "noise-high", 10) == 0) {
728 ath5k_ani_set_noise_immunity_level(sc->ah,
729 ATH5K_ANI_MAX_NOISE_IMM_LVL);
730 } else if (strncmp(buf, "spur-low", 8) == 0) {
731 ath5k_ani_set_spur_immunity_level(sc->ah, 0);
732 } else if (strncmp(buf, "spur-high", 9) == 0) {
733 ath5k_ani_set_spur_immunity_level(sc->ah,
734 sc->ani_state.max_spur_level);
735 } else if (strncmp(buf, "fir-low", 7) == 0) {
736 ath5k_ani_set_firstep_level(sc->ah, 0);
737 } else if (strncmp(buf, "fir-high", 8) == 0) {
738 ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
739 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
740 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
741 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
742 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
743 } else if (strncmp(buf, "cck-off", 7) == 0) {
744 ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
745 } else if (strncmp(buf, "cck-on", 6) == 0) {
746 ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
747 }
748 return count;
749}
750
751static const struct file_operations fops_ani = {
752 .read = read_file_ani,
753 .write = write_file_ani,
754 .open = ath5k_debugfs_open,
755 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200756 .llseek = default_llseek,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900757};
758
759
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900760/* debugfs: queues etc */
761
762static ssize_t read_file_queue(struct file *file, char __user *user_buf,
763 size_t count, loff_t *ppos)
764{
765 struct ath5k_softc *sc = file->private_data;
766 char buf[700];
767 unsigned int len = 0;
768
769 struct ath5k_txq *txq;
770 struct ath5k_buf *bf, *bf0;
771 int i, n = 0;
772
773 len += snprintf(buf+len, sizeof(buf)-len,
774 "available txbuffers: %d\n", sc->txbuf_len);
775
776 for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) {
777 txq = &sc->txqs[i];
778
779 len += snprintf(buf+len, sizeof(buf)-len,
780 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
781
782 if (!txq->setup)
783 continue;
784
785 list_for_each_entry_safe(bf, bf0, &txq->q, list)
786 n++;
787 len += snprintf(buf+len, sizeof(buf)-len, " len: %d\n", n);
788 }
789
Dan Carpenter2189d132010-07-22 10:52:02 +0200790 if (len > sizeof(buf))
791 len = sizeof(buf);
792
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900793 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
794}
795
796static ssize_t write_file_queue(struct file *file,
797 const char __user *userbuf,
798 size_t count, loff_t *ppos)
799{
800 struct ath5k_softc *sc = file->private_data;
801 char buf[20];
802
803 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
804 return -EFAULT;
805
806 if (strncmp(buf, "start", 5) == 0)
807 ieee80211_wake_queues(sc->hw);
808 else if (strncmp(buf, "stop", 4) == 0)
809 ieee80211_stop_queues(sc->hw);
810
811 return count;
812}
813
814
815static const struct file_operations fops_queue = {
816 .read = read_file_queue,
817 .write = write_file_queue,
818 .open = ath5k_debugfs_open,
819 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200820 .llseek = default_llseek,
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900821};
822
823
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200824/* init */
825
826void
827ath5k_debug_init(void)
828{
829 ath5k_global_debugfs = debugfs_create_dir("ath5k", NULL);
830}
831
832void
833ath5k_debug_init_device(struct ath5k_softc *sc)
834{
835 sc->debug.level = ath5k_debug;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900836
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200837 sc->debug.debugfs_phydir = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900838 ath5k_global_debugfs);
839
Jiri Slaby31670072009-06-28 23:25:27 +0200840 sc->debug.debugfs_debug = debugfs_create_file("debug",
841 S_IWUSR | S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900842 sc->debug.debugfs_phydir, sc, &fops_debug);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200843
Jiri Slaby31670072009-06-28 23:25:27 +0200844 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900845 sc->debug.debugfs_phydir, sc, &fops_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200846
Jiri Slaby31670072009-06-28 23:25:27 +0200847 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
848 S_IWUSR | S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900849 sc->debug.debugfs_phydir, sc, &fops_beacon);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200850
Cheng Renquan33ab6252008-11-22 11:22:49 +0800851 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900852 sc->debug.debugfs_phydir, sc, &fops_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +0900853
854 sc->debug.debugfs_antenna = debugfs_create_file("antenna",
855 S_IWUSR | S_IRUSR,
856 sc->debug.debugfs_phydir, sc, &fops_antenna);
Bruno Randolf76443952010-03-09 16:56:00 +0900857
858 sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
859 S_IWUSR | S_IRUSR,
860 sc->debug.debugfs_phydir, sc,
861 &fops_frameerrors);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900862
863 sc->debug.debugfs_ani = debugfs_create_file("ani",
864 S_IWUSR | S_IRUSR,
865 sc->debug.debugfs_phydir, sc,
866 &fops_ani);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900867
868 sc->debug.debugfs_queue = debugfs_create_file("queue",
869 S_IWUSR | S_IRUSR,
870 sc->debug.debugfs_phydir, sc,
871 &fops_queue);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200872}
873
874void
875ath5k_debug_finish(void)
876{
877 debugfs_remove(ath5k_global_debugfs);
878}
879
880void
881ath5k_debug_finish_device(struct ath5k_softc *sc)
882{
883 debugfs_remove(sc->debug.debugfs_debug);
884 debugfs_remove(sc->debug.debugfs_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200885 debugfs_remove(sc->debug.debugfs_beacon);
886 debugfs_remove(sc->debug.debugfs_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +0900887 debugfs_remove(sc->debug.debugfs_antenna);
Bruno Randolf76443952010-03-09 16:56:00 +0900888 debugfs_remove(sc->debug.debugfs_frameerrors);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900889 debugfs_remove(sc->debug.debugfs_ani);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900890 debugfs_remove(sc->debug.debugfs_queue);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200891 debugfs_remove(sc->debug.debugfs_phydir);
892}
893
894
895/* functions used in other places */
896
897void
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500898ath5k_debug_dump_bands(struct ath5k_softc *sc)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200899{
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500900 unsigned int b, i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200901
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500902 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200903 return;
904
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500905 BUG_ON(!sc->sbands);
906
907 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
908 struct ieee80211_supported_band *band = &sc->sbands[b];
Bob Copelandb7fcb5c2009-04-27 22:12:43 -0400909 char bname[6];
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500910 switch (band->band) {
911 case IEEE80211_BAND_2GHZ:
912 strcpy(bname, "2 GHz");
913 break;
914 case IEEE80211_BAND_5GHZ:
915 strcpy(bname, "5 GHz");
916 break;
917 default:
918 printk(KERN_DEBUG "Band not supported: %d\n",
919 band->band);
920 return;
921 }
922 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
923 band->n_channels, band->n_bitrates);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200924 printk(KERN_DEBUG " channels:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500925 for (i = 0; i < band->n_channels; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200926 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500927 ieee80211_frequency_to_channel(
928 band->channels[i].center_freq),
929 band->channels[i].center_freq,
930 band->channels[i].hw_value,
931 band->channels[i].flags);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200932 printk(KERN_DEBUG " rates:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500933 for (i = 0; i < band->n_bitrates; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200934 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500935 band->bitrates[i].bitrate,
936 band->bitrates[i].hw_value,
937 band->bitrates[i].flags,
938 band->bitrates[i].hw_value_short);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200939 }
940}
941
942static inline void
Bruno Randolfb47f4072008-03-05 18:35:45 +0900943ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
944 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200945{
946 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900947 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200948
949 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
950 ds, (unsigned long long)bf->daddr,
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900951 ds->ds_link, ds->ds_data,
952 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
Bruno Randolf62412a82010-06-16 19:12:12 +0900953 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +0900954 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200955}
956
957void
958ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
959{
960 struct ath5k_desc *ds;
961 struct ath5k_buf *bf;
Bruno Randolfb47f4072008-03-05 18:35:45 +0900962 struct ath5k_rx_status rs = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200963 int status;
964
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900965 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200966 return;
967
Bruno Randolf265faad2010-06-16 19:11:30 +0900968 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
Nick Kossifidisc6e387a2008-08-29 22:45:39 +0300969 ath5k_hw_get_rxdp(ah), sc->rxlink);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200970
971 spin_lock_bh(&sc->rxbuflock);
972 list_for_each_entry(bf, &sc->rxbuf, list) {
973 ds = bf->desc;
Bruno Randolfb47f4072008-03-05 18:35:45 +0900974 status = ah->ah_proc_rx_desc(ah, ds, &rs);
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900975 if (!status)
Bruno Randolfb47f4072008-03-05 18:35:45 +0900976 ath5k_debug_printrxbuf(bf, status == 0, &rs);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200977 }
978 spin_unlock_bh(&sc->rxbuflock);
979}
980
981void
982ath5k_debug_dump_skb(struct ath5k_softc *sc,
983 struct sk_buff *skb, const char *prefix, int tx)
984{
985 char buf[16];
986
987 if (likely(!((tx && (sc->debug.level & ATH5K_DEBUG_DUMP_TX)) ||
988 (!tx && (sc->debug.level & ATH5K_DEBUG_DUMP_RX)))))
989 return;
990
991 snprintf(buf, sizeof(buf), "%s %s", wiphy_name(sc->hw->wiphy), prefix);
992
993 print_hex_dump_bytes(buf, DUMP_PREFIX_NONE, skb->data,
994 min(200U, skb->len));
995
996 printk(KERN_DEBUG "\n");
997}
998
999void
Bruno Randolfb47f4072008-03-05 18:35:45 +09001000ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001001{
1002 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001003 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001004 struct ath5k_tx_status ts = {};
1005 int done;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001006
1007 if (likely(!(sc->debug.level & ATH5K_DEBUG_RESET)))
1008 return;
1009
Bruno Randolfb47f4072008-03-05 18:35:45 +09001010 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
1011
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001012 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1013 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001014 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
1015 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
1016 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001017 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001018}
1019
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001020#endif /* ifdef CONFIG_ATH5K_DEBUG */