blob: 42ea5b1bdb122303753af6c16b830707772bbf67 [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"
Ben Greear92c68a62010-10-08 09:43:29 -070063#include "../debug.h"
Jiri Slabyfa1c1142007-08-12 17:33:16 +020064
65static unsigned int ath5k_debug;
66module_param_named(debug, ath5k_debug, uint, 0);
67
68
Luis R. Rodriguezb4461972008-02-04 10:03:54 -050069#ifdef CONFIG_ATH5K_DEBUG
Jiri Slabyfa1c1142007-08-12 17:33:16 +020070
71#include <linux/seq_file.h>
72#include "reg.h"
Bruno Randolf2111ac02010-04-02 18:44:08 +090073#include "ani.h"
Jiri Slabyfa1c1142007-08-12 17:33:16 +020074
Jiri Slabyfa1c1142007-08-12 17:33:16 +020075static 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 {
Jiri Slaby2c91108c2009-03-07 10:26:41 +010085 const char *name;
Jiri Slabyfa1c1142007-08-12 17:33:16 +020086 int addr;
87};
88
89#define REG_STRUCT_INIT(r) { #r, r }
90
91/* just a few random registers, might want to add more */
Jiri Slaby2c91108c2009-03-07 10:26:41 +010092static const struct reg regs[] = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +020093 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{
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100145 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200146}
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;
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100156 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200157}
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
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200196/* debugfs: beacons */
197
198static 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;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900203 char buf[500];
204 unsigned int len = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200205 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,
John W. Linvillef868f4e2008-03-07 16:38:43 -0500238 "TSF\t\t0x%016llx\tTU: %08x\n",
239 (unsigned long long)tsf, TSF_TO_TU(tsf));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200240
Dan Carpenter2189d132010-07-22 10:52:02 +0200241 if (len > sizeof(buf))
242 len = sizeof(buf);
243
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200244 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
245}
246
247static 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;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900253 char buf[20];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200254
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900255 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
256 return -EFAULT;
257
258 if (strncmp(buf, "disable", 7) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200259 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
260 printk(KERN_INFO "debugfs disable beacons\n");
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900261 } else if (strncmp(buf, "enable", 6) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200262 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
263 printk(KERN_INFO "debugfs enable beacons\n");
264 }
265 return count;
266}
267
268static 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
278static 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;
Bruno Randolf8d67a032010-06-16 19:11:12 +0900283 ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
Bob Copeland5faaff72010-07-13 11:32:40 -0400284 ieee80211_queue_work(sc->hw, &sc->reset_work);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200285 return count;
286}
287
288static const struct file_operations fops_reset = {
289 .write = write_file_reset,
290 .open = ath5k_debugfs_open,
291 .owner = THIS_MODULE,
292};
293
294
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900295/* debugfs: debug level */
296
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100297static const struct {
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900298 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" },
Bob Copeland85519a62008-10-29 08:30:53 -0400309 { ATH5K_DEBUG_LED, "led", "LED management" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900310 { ATH5K_DEBUG_DUMP_RX, "dumprx", "print received skb content" },
311 { ATH5K_DEBUG_DUMP_TX, "dumptx", "print transmit skb content" },
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500312 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
Bruno Randolf2111ac02010-04-02 18:44:08 +0900313 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
Bob Copelandb4c52612010-08-21 16:39:03 -0400314 { ATH5K_DEBUG_DESC, "desc", "descriptor chains" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900315 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
316};
317
318static 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
Dan Carpenter2189d132010-07-22 10:52:02 +0200340 if (len > sizeof(buf))
341 len = sizeof(buf);
342
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900343 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
344}
345
346static 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
367static 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
Bruno Randolf604eead2010-03-09 16:55:17 +0900375/* debugfs: antenna */
376
377static 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
Bruno Randolf0ca74022010-06-07 13:11:30 +0900435 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
Dan Carpenter2189d132010-07-22 10:52:02 +0200442 if (len > sizeof(buf))
443 len = sizeof(buf);
444
Bruno Randolf604eead2010-03-09 16:55:17 +0900445 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
446}
447
448static 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
478static 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
Ben Greear87fd2e62010-09-21 17:03:57 -0700485/* debugfs: misc */
486
487static 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)
Joe Perches908ebfb2010-10-12 11:07:44 -0700522 len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5211");
Ben Greear87fd2e62010-09-21 17:03:57 -0700523
Joe Perches908ebfb2010-10-12 11:07:44 -0700524 len += snprintf(buf+len, sizeof(buf)-len, "\nopmode: %s (%d)\n",
525 ath_opmode_to_string(sc->opmode), sc->opmode);
Ben Greear92c68a62010-10-08 09:43:29 -0700526
Ben Greear87fd2e62010-09-21 17:03:57 -0700527 if (len > sizeof(buf))
528 len = sizeof(buf);
529
530 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
531}
532
533static const struct file_operations fops_misc = {
534 .read = read_file_misc,
535 .open = ath5k_debugfs_open,
536 .owner = THIS_MODULE,
537};
538
Bruno Randolf604eead2010-03-09 16:55:17 +0900539
Bruno Randolf76443952010-03-09 16:56:00 +0900540/* debugfs: frameerrors */
541
542static 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;
Bruno Randolfda351112010-03-25 14:49:42 +0900549 int i;
Bruno Randolf76443952010-03-09 16:56:00 +0900550
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);
Bruno Randolfda351112010-03-25 14:49:42 +0900561 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
Bruno Randolf76443952010-03-09 16:56:00 +0900568 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);
Ben Greearb72acdd2010-10-01 10:54:04 -0700590 len += snprintf(buf+len, sizeof(buf)-len, "RX-all-bytes\t%d\n",
591 st->rx_bytes_count);
Bruno Randolf76443952010-03-09 16:56:00 +0900592
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);
Ben Greearb72acdd2010-10-01 10:54:04 -0700609 len += snprintf(buf+len, sizeof(buf)-len, "TX-all-bytes\t%d\n",
610 st->tx_bytes_count);
Bruno Randolf76443952010-03-09 16:56:00 +0900611
Dan Carpenter2189d132010-07-22 10:52:02 +0200612 if (len > sizeof(buf))
613 len = sizeof(buf);
614
Bruno Randolf76443952010-03-09 16:56:00 +0900615 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
616}
617
618static 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
647static 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
Bruno Randolf2111ac02010-04-02 18:44:08 +0900655/* debugfs: ani */
656
657static 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);
Felix Fietkau7109ca52010-10-08 22:13:54 +0200718
719#define CC_PRINT(_struct, _field) \
720 _struct._field, \
721 _struct.cycles > 0 ? \
722 _struct._field*100/_struct.cycles : 0
723
Bruno Randolf2111ac02010-04-02 18:44:08 +0900724 len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200725 CC_PRINT(as->last_cc, tx_frame));
Bruno Randolf2111ac02010-04-02 18:44:08 +0900726 len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200727 CC_PRINT(as->last_cc, rx_frame));
Bruno Randolf2111ac02010-04-02 18:44:08 +0900728 len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200729 CC_PRINT(as->last_cc, rx_busy));
730#undef CC_PRINT
Bruno Randolf2111ac02010-04-02 18:44:08 +0900731 len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200732 as->last_cc.cycles);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900733 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
Dan Carpenter2189d132010-07-22 10:52:02 +0200755 if (len > sizeof(buf))
756 len = sizeof(buf);
757
Bruno Randolf2111ac02010-04-02 18:44:08 +0900758 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
759}
760
761static 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
805static 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
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900813/* debugfs: queues etc */
814
815static 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;
Bruno Randolfcfddc112010-09-17 11:36:40 +0900824 int i, n;
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900825
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
Bruno Randolfcfddc112010-09-17 11:36:40 +0900838 n = 0;
839 spin_lock_bh(&txq->lock);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900840 list_for_each_entry_safe(bf, bf0, &txq->q, list)
841 n++;
Bruno Randolfcfddc112010-09-17 11:36:40 +0900842 spin_unlock_bh(&txq->lock);
843
844 len += snprintf(buf+len, sizeof(buf)-len,
845 " len: %d bufs: %d\n", txq->txq_len, n);
Bruno Randolf923e5b32010-09-17 11:37:02 +0900846 len += snprintf(buf+len, sizeof(buf)-len,
847 " stuck: %d\n", txq->txq_stuck);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900848 }
849
Dan Carpenter2189d132010-07-22 10:52:02 +0200850 if (len > sizeof(buf))
851 len = sizeof(buf);
852
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900853 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
854}
855
856static 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
875static 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
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200883void
884ath5k_debug_init_device(struct ath5k_softc *sc)
885{
886 sc->debug.level = ath5k_debug;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900887
Ben Greeard84a35d2010-10-12 10:55:38 -0700888 sc->debug.debugfs_phydir = debugfs_create_dir("ath5k",
889 sc->hw->wiphy->debugfsdir);
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900890
Jiri Slaby31670072009-06-28 23:25:27 +0200891 sc->debug.debugfs_debug = debugfs_create_file("debug",
892 S_IWUSR | S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900893 sc->debug.debugfs_phydir, sc, &fops_debug);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200894
Jiri Slaby31670072009-06-28 23:25:27 +0200895 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900896 sc->debug.debugfs_phydir, sc, &fops_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200897
Jiri Slaby31670072009-06-28 23:25:27 +0200898 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
899 S_IWUSR | S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900900 sc->debug.debugfs_phydir, sc, &fops_beacon);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200901
Cheng Renquan33ab6252008-11-22 11:22:49 +0800902 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900903 sc->debug.debugfs_phydir, sc, &fops_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +0900904
905 sc->debug.debugfs_antenna = debugfs_create_file("antenna",
906 S_IWUSR | S_IRUSR,
907 sc->debug.debugfs_phydir, sc, &fops_antenna);
Bruno Randolf76443952010-03-09 16:56:00 +0900908
Ben Greear87fd2e62010-09-21 17:03:57 -0700909 sc->debug.debugfs_misc = debugfs_create_file("misc",
910 S_IRUSR,
911 sc->debug.debugfs_phydir, sc, &fops_misc);
912
Bruno Randolf76443952010-03-09 16:56:00 +0900913 sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
914 S_IWUSR | S_IRUSR,
915 sc->debug.debugfs_phydir, sc,
916 &fops_frameerrors);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900917
918 sc->debug.debugfs_ani = debugfs_create_file("ani",
919 S_IWUSR | S_IRUSR,
920 sc->debug.debugfs_phydir, sc,
921 &fops_ani);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900922
923 sc->debug.debugfs_queue = debugfs_create_file("queue",
924 S_IWUSR | S_IRUSR,
925 sc->debug.debugfs_phydir, sc,
926 &fops_queue);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200927}
928
929void
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200930ath5k_debug_finish_device(struct ath5k_softc *sc)
931{
932 debugfs_remove(sc->debug.debugfs_debug);
933 debugfs_remove(sc->debug.debugfs_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200934 debugfs_remove(sc->debug.debugfs_beacon);
935 debugfs_remove(sc->debug.debugfs_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +0900936 debugfs_remove(sc->debug.debugfs_antenna);
Ben Greear87fd2e62010-09-21 17:03:57 -0700937 debugfs_remove(sc->debug.debugfs_misc);
Bruno Randolf76443952010-03-09 16:56:00 +0900938 debugfs_remove(sc->debug.debugfs_frameerrors);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900939 debugfs_remove(sc->debug.debugfs_ani);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900940 debugfs_remove(sc->debug.debugfs_queue);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200941 debugfs_remove(sc->debug.debugfs_phydir);
942}
943
944
945/* functions used in other places */
946
947void
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500948ath5k_debug_dump_bands(struct ath5k_softc *sc)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200949{
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500950 unsigned int b, i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200951
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500952 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200953 return;
954
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500955 BUG_ON(!sc->sbands);
956
957 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
958 struct ieee80211_supported_band *band = &sc->sbands[b];
Bob Copelandb7fcb5c2009-04-27 22:12:43 -0400959 char bname[6];
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500960 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);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200974 printk(KERN_DEBUG " channels:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500975 for (i = 0; i < band->n_channels; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200976 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500977 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);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200982 printk(KERN_DEBUG " rates:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500983 for (i = 0; i < band->n_bitrates; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200984 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500985 band->bitrates[i].bitrate,
986 band->bitrates[i].hw_value,
987 band->bitrates[i].flags,
988 band->bitrates[i].hw_value_short);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200989 }
990}
991
992static inline void
Bruno Randolfb47f4072008-03-05 18:35:45 +0900993ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
994 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200995{
996 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +0900997 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200998
999 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
1000 ds, (unsigned long long)bf->daddr,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001001 ds->ds_link, ds->ds_data,
1002 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
Bruno Randolf62412a82010-06-16 19:12:12 +09001003 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001004 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001005}
1006
1007void
1008ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
1009{
1010 struct ath5k_desc *ds;
1011 struct ath5k_buf *bf;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001012 struct ath5k_rx_status rs = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001013 int status;
1014
Bob Copelandb4c52612010-08-21 16:39:03 -04001015 if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001016 return;
1017
Bruno Randolf265faad2010-06-16 19:11:30 +09001018 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001019 ath5k_hw_get_rxdp(ah), sc->rxlink);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001020
1021 spin_lock_bh(&sc->rxbuflock);
1022 list_for_each_entry(bf, &sc->rxbuf, list) {
1023 ds = bf->desc;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001024 status = ah->ah_proc_rx_desc(ah, ds, &rs);
Bruno Randolfbe9b7252008-01-23 10:27:51 +09001025 if (!status)
Bruno Randolfb47f4072008-03-05 18:35:45 +09001026 ath5k_debug_printrxbuf(bf, status == 0, &rs);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001027 }
1028 spin_unlock_bh(&sc->rxbuflock);
1029}
1030
1031void
1032ath5k_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
1049void
Bruno Randolfb47f4072008-03-05 18:35:45 +09001050ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001051{
1052 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001053 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001054 struct ath5k_tx_status ts = {};
1055 int done;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001056
Bob Copelandb4c52612010-08-21 16:39:03 -04001057 if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001058 return;
1059
Bruno Randolfb47f4072008-03-05 18:35:45 +09001060 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
1061
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001062 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,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001064 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,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001067 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001068}
1069
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001070#endif /* ifdef CONFIG_ATH5K_DEBUG */