blob: 0230f30e9e9aac1fa59d8d1ddb4faa7012db3d89 [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
Jiri Slabyfa1c1142007-08-12 17:33:16 +020074static int ath5k_debugfs_open(struct inode *inode, struct file *file)
75{
76 file->private_data = inode->i_private;
77 return 0;
78}
79
80
81/* debugfs: registers */
82
83struct reg {
Jiri Slaby2c91108c2009-03-07 10:26:41 +010084 const char *name;
Jiri Slabyfa1c1142007-08-12 17:33:16 +020085 int addr;
86};
87
88#define REG_STRUCT_INIT(r) { #r, r }
89
90/* just a few random registers, might want to add more */
Jiri Slaby2c91108c2009-03-07 10:26:41 +010091static const struct reg regs[] = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +020092 REG_STRUCT_INIT(AR5K_CR),
93 REG_STRUCT_INIT(AR5K_RXDP),
94 REG_STRUCT_INIT(AR5K_CFG),
95 REG_STRUCT_INIT(AR5K_IER),
96 REG_STRUCT_INIT(AR5K_BCR),
97 REG_STRUCT_INIT(AR5K_RTSD0),
98 REG_STRUCT_INIT(AR5K_RTSD1),
99 REG_STRUCT_INIT(AR5K_TXCFG),
100 REG_STRUCT_INIT(AR5K_RXCFG),
101 REG_STRUCT_INIT(AR5K_RXJLA),
102 REG_STRUCT_INIT(AR5K_MIBC),
103 REG_STRUCT_INIT(AR5K_TOPS),
104 REG_STRUCT_INIT(AR5K_RXNOFRM),
105 REG_STRUCT_INIT(AR5K_TXNOFRM),
106 REG_STRUCT_INIT(AR5K_RPGTO),
107 REG_STRUCT_INIT(AR5K_RFCNT),
108 REG_STRUCT_INIT(AR5K_MISC),
109 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
110 REG_STRUCT_INIT(AR5K_ISR),
111 REG_STRUCT_INIT(AR5K_PISR),
112 REG_STRUCT_INIT(AR5K_SISR0),
113 REG_STRUCT_INIT(AR5K_SISR1),
114 REG_STRUCT_INIT(AR5K_SISR2),
115 REG_STRUCT_INIT(AR5K_SISR3),
116 REG_STRUCT_INIT(AR5K_SISR4),
117 REG_STRUCT_INIT(AR5K_IMR),
118 REG_STRUCT_INIT(AR5K_PIMR),
119 REG_STRUCT_INIT(AR5K_SIMR0),
120 REG_STRUCT_INIT(AR5K_SIMR1),
121 REG_STRUCT_INIT(AR5K_SIMR2),
122 REG_STRUCT_INIT(AR5K_SIMR3),
123 REG_STRUCT_INIT(AR5K_SIMR4),
124 REG_STRUCT_INIT(AR5K_DCM_ADDR),
125 REG_STRUCT_INIT(AR5K_DCCFG),
126 REG_STRUCT_INIT(AR5K_CCFG),
127 REG_STRUCT_INIT(AR5K_CPC0),
128 REG_STRUCT_INIT(AR5K_CPC1),
129 REG_STRUCT_INIT(AR5K_CPC2),
130 REG_STRUCT_INIT(AR5K_CPC3),
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300131 REG_STRUCT_INIT(AR5K_CPCOVF),
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200132 REG_STRUCT_INIT(AR5K_RESET_CTL),
133 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
134 REG_STRUCT_INIT(AR5K_INTPEND),
135 REG_STRUCT_INIT(AR5K_SFR),
136 REG_STRUCT_INIT(AR5K_PCICFG),
137 REG_STRUCT_INIT(AR5K_GPIOCR),
138 REG_STRUCT_INIT(AR5K_GPIODO),
139 REG_STRUCT_INIT(AR5K_SREV),
140};
141
142static void *reg_start(struct seq_file *seq, loff_t *pos)
143{
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100144 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200145}
146
147static void reg_stop(struct seq_file *seq, void *p)
148{
149 /* nothing to do */
150}
151
152static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
153{
154 ++*pos;
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100155 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200156}
157
158static int reg_show(struct seq_file *seq, void *p)
159{
160 struct ath5k_softc *sc = seq->private;
161 struct reg *r = p;
162 seq_printf(seq, "%-25s0x%08x\n", r->name,
163 ath5k_hw_reg_read(sc->ah, r->addr));
164 return 0;
165}
166
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800167static const struct seq_operations register_seq_ops = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200168 .start = reg_start,
169 .next = reg_next,
170 .stop = reg_stop,
171 .show = reg_show
172};
173
174static int open_file_registers(struct inode *inode, struct file *file)
175{
176 struct seq_file *s;
177 int res;
178 res = seq_open(file, &register_seq_ops);
179 if (res == 0) {
180 s = file->private_data;
181 s->private = inode->i_private;
182 }
183 return res;
184}
185
186static const struct file_operations fops_registers = {
187 .open = open_file_registers,
188 .read = seq_read,
189 .llseek = seq_lseek,
190 .release = seq_release,
191 .owner = THIS_MODULE,
192};
193
194
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200195/* debugfs: beacons */
196
197static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
198 size_t count, loff_t *ppos)
199{
200 struct ath5k_softc *sc = file->private_data;
201 struct ath5k_hw *ah = sc->ah;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900202 char buf[500];
203 unsigned int len = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200204 unsigned int v;
205 u64 tsf;
206
207 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
208 len += snprintf(buf+len, sizeof(buf)-len,
209 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
210 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
211 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
212
213 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n",
214 "AR5K_LAST_TSTP", ath5k_hw_reg_read(sc->ah, AR5K_LAST_TSTP));
215
216 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\n\n",
217 "AR5K_BEACON_CNT", ath5k_hw_reg_read(sc->ah, AR5K_BEACON_CNT));
218
219 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER0);
220 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
221 "AR5K_TIMER0 (TBTT)", v, v);
222
223 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER1);
224 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
225 "AR5K_TIMER1 (DMA)", v, v >> 3);
226
227 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER2);
228 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
229 "AR5K_TIMER2 (SWBA)", v, v >> 3);
230
231 v = ath5k_hw_reg_read(sc->ah, AR5K_TIMER3);
232 len += snprintf(buf+len, sizeof(buf)-len, "%-24s0x%08x\tTU: %08x\n",
233 "AR5K_TIMER3 (ATIM)", v, v);
234
235 tsf = ath5k_hw_get_tsf64(sc->ah);
236 len += snprintf(buf+len, sizeof(buf)-len,
John W. Linvillef868f4e2008-03-07 16:38:43 -0500237 "TSF\t\t0x%016llx\tTU: %08x\n",
238 (unsigned long long)tsf, TSF_TO_TU(tsf));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200239
Dan Carpenter2189d132010-07-22 10:52:02 +0200240 if (len > sizeof(buf))
241 len = sizeof(buf);
242
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200243 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
244}
245
246static ssize_t write_file_beacon(struct file *file,
247 const char __user *userbuf,
248 size_t count, loff_t *ppos)
249{
250 struct ath5k_softc *sc = file->private_data;
251 struct ath5k_hw *ah = sc->ah;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900252 char buf[20];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200253
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900254 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
255 return -EFAULT;
256
257 if (strncmp(buf, "disable", 7) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200258 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
259 printk(KERN_INFO "debugfs disable beacons\n");
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900260 } else if (strncmp(buf, "enable", 6) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200261 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
262 printk(KERN_INFO "debugfs enable beacons\n");
263 }
264 return count;
265}
266
267static const struct file_operations fops_beacon = {
268 .read = read_file_beacon,
269 .write = write_file_beacon,
270 .open = ath5k_debugfs_open,
271 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200272 .llseek = default_llseek,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200273};
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,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200292 .llseek = noop_llseek,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200293};
294
295
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900296/* debugfs: debug level */
297
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100298static const struct {
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900299 enum ath5k_debug_level level;
300 const char *name;
301 const char *desc;
302} dbg_info[] = {
303 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
304 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
305 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
306 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
307 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
308 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
309 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
Bob Copeland85519a62008-10-29 08:30:53 -0400310 { ATH5K_DEBUG_LED, "led", "LED management" },
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500311 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
Nick Kossifidisb3a28e62010-11-23 20:47:31 +0200312 { ATH5K_DEBUG_DMA, "dma", "dma start/stop" },
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,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200372 .llseek = default_llseek,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900373};
374
375
Bruno Randolf604eead2010-03-09 16:55:17 +0900376/* debugfs: antenna */
377
378static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
379 size_t count, loff_t *ppos)
380{
381 struct ath5k_softc *sc = file->private_data;
382 char buf[700];
383 unsigned int len = 0;
384 unsigned int i;
385 unsigned int v;
386
387 len += snprintf(buf+len, sizeof(buf)-len, "antenna mode\t%d\n",
388 sc->ah->ah_ant_mode);
389 len += snprintf(buf+len, sizeof(buf)-len, "default antenna\t%d\n",
390 sc->ah->ah_def_ant);
391 len += snprintf(buf+len, sizeof(buf)-len, "tx antenna\t%d\n",
392 sc->ah->ah_tx_ant);
393
394 len += snprintf(buf+len, sizeof(buf)-len, "\nANTENNA\t\tRX\tTX\n");
395 for (i = 1; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
396 len += snprintf(buf+len, sizeof(buf)-len,
397 "[antenna %d]\t%d\t%d\n",
398 i, sc->stats.antenna_rx[i], sc->stats.antenna_tx[i]);
399 }
400 len += snprintf(buf+len, sizeof(buf)-len, "[invalid]\t%d\t%d\n",
401 sc->stats.antenna_rx[0], sc->stats.antenna_tx[0]);
402
403 v = ath5k_hw_reg_read(sc->ah, AR5K_DEFAULT_ANTENNA);
404 len += snprintf(buf+len, sizeof(buf)-len,
405 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
406
407 v = ath5k_hw_reg_read(sc->ah, AR5K_STA_ID1);
408 len += snprintf(buf+len, sizeof(buf)-len,
409 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
410 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
411 len += snprintf(buf+len, sizeof(buf)-len,
412 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
413 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
414 len += snprintf(buf+len, sizeof(buf)-len,
415 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
416 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
417 len += snprintf(buf+len, sizeof(buf)-len,
418 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
419 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
420
421 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_AGCCTL);
422 len += snprintf(buf+len, sizeof(buf)-len,
423 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
424 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
425
426 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_RESTART);
427 len += snprintf(buf+len, sizeof(buf)-len,
428 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
429 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
430
431 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_FAST_ANT_DIV);
432 len += snprintf(buf+len, sizeof(buf)-len,
433 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
434 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
435
Bruno Randolf0ca74022010-06-07 13:11:30 +0900436 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
437 len += snprintf(buf+len, sizeof(buf)-len,
438 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
439 v = ath5k_hw_reg_read(sc->ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
440 len += snprintf(buf+len, sizeof(buf)-len,
441 "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v);
442
Dan Carpenter2189d132010-07-22 10:52:02 +0200443 if (len > sizeof(buf))
444 len = sizeof(buf);
445
Bruno Randolf604eead2010-03-09 16:55:17 +0900446 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
447}
448
449static ssize_t write_file_antenna(struct file *file,
450 const char __user *userbuf,
451 size_t count, loff_t *ppos)
452{
453 struct ath5k_softc *sc = file->private_data;
454 unsigned int i;
455 char buf[20];
456
457 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
458 return -EFAULT;
459
460 if (strncmp(buf, "diversity", 9) == 0) {
461 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_DEFAULT);
462 printk(KERN_INFO "ath5k debug: enable diversity\n");
463 } else if (strncmp(buf, "fixed-a", 7) == 0) {
464 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_A);
465 printk(KERN_INFO "ath5k debugfs: fixed antenna A\n");
466 } else if (strncmp(buf, "fixed-b", 7) == 0) {
467 ath5k_hw_set_antenna_mode(sc->ah, AR5K_ANTMODE_FIXED_B);
468 printk(KERN_INFO "ath5k debug: fixed antenna B\n");
469 } else if (strncmp(buf, "clear", 5) == 0) {
470 for (i = 0; i < ARRAY_SIZE(sc->stats.antenna_rx); i++) {
471 sc->stats.antenna_rx[i] = 0;
472 sc->stats.antenna_tx[i] = 0;
473 }
474 printk(KERN_INFO "ath5k debug: cleared antenna stats\n");
475 }
476 return count;
477}
478
479static const struct file_operations fops_antenna = {
480 .read = read_file_antenna,
481 .write = write_file_antenna,
482 .open = ath5k_debugfs_open,
483 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200484 .llseek = default_llseek,
Bruno Randolf604eead2010-03-09 16:55:17 +0900485};
486
Ben Greear87fd2e62010-09-21 17:03:57 -0700487/* debugfs: misc */
488
489static ssize_t read_file_misc(struct file *file, char __user *user_buf,
490 size_t count, loff_t *ppos)
491{
492 struct ath5k_softc *sc = file->private_data;
493 char buf[700];
494 unsigned int len = 0;
495 u32 filt = ath5k_hw_get_rx_filter(sc->ah);
496
497 len += snprintf(buf+len, sizeof(buf)-len, "bssid-mask: %pM\n",
498 sc->bssidmask);
499 len += snprintf(buf+len, sizeof(buf)-len, "filter-flags: 0x%x ",
500 filt);
501 if (filt & AR5K_RX_FILTER_UCAST)
502 len += snprintf(buf+len, sizeof(buf)-len, " UCAST");
503 if (filt & AR5K_RX_FILTER_MCAST)
504 len += snprintf(buf+len, sizeof(buf)-len, " MCAST");
505 if (filt & AR5K_RX_FILTER_BCAST)
506 len += snprintf(buf+len, sizeof(buf)-len, " BCAST");
507 if (filt & AR5K_RX_FILTER_CONTROL)
508 len += snprintf(buf+len, sizeof(buf)-len, " CONTROL");
509 if (filt & AR5K_RX_FILTER_BEACON)
510 len += snprintf(buf+len, sizeof(buf)-len, " BEACON");
511 if (filt & AR5K_RX_FILTER_PROM)
512 len += snprintf(buf+len, sizeof(buf)-len, " PROM");
513 if (filt & AR5K_RX_FILTER_XRPOLL)
514 len += snprintf(buf+len, sizeof(buf)-len, " XRPOLL");
515 if (filt & AR5K_RX_FILTER_PROBEREQ)
516 len += snprintf(buf+len, sizeof(buf)-len, " PROBEREQ");
517 if (filt & AR5K_RX_FILTER_PHYERR_5212)
518 len += snprintf(buf+len, sizeof(buf)-len, " PHYERR-5212");
519 if (filt & AR5K_RX_FILTER_RADARERR_5212)
520 len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5212");
521 if (filt & AR5K_RX_FILTER_PHYERR_5211)
522 snprintf(buf+len, sizeof(buf)-len, " PHYERR-5211");
523 if (filt & AR5K_RX_FILTER_RADARERR_5211)
Joe Perches908ebfb2010-10-12 11:07:44 -0700524 len += snprintf(buf+len, sizeof(buf)-len, " RADARERR-5211");
Ben Greear87fd2e62010-09-21 17:03:57 -0700525
Joe Perches908ebfb2010-10-12 11:07:44 -0700526 len += snprintf(buf+len, sizeof(buf)-len, "\nopmode: %s (%d)\n",
527 ath_opmode_to_string(sc->opmode), sc->opmode);
Ben Greear92c68a62010-10-08 09:43:29 -0700528
Ben Greear87fd2e62010-09-21 17:03:57 -0700529 if (len > sizeof(buf))
530 len = sizeof(buf);
531
532 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
533}
534
535static const struct file_operations fops_misc = {
536 .read = read_file_misc,
537 .open = ath5k_debugfs_open,
538 .owner = THIS_MODULE,
539};
540
Bruno Randolf604eead2010-03-09 16:55:17 +0900541
Bruno Randolf76443952010-03-09 16:56:00 +0900542/* debugfs: frameerrors */
543
544static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
545 size_t count, loff_t *ppos)
546{
547 struct ath5k_softc *sc = file->private_data;
548 struct ath5k_statistics *st = &sc->stats;
549 char buf[700];
550 unsigned int len = 0;
Bruno Randolfda351112010-03-25 14:49:42 +0900551 int i;
Bruno Randolf76443952010-03-09 16:56:00 +0900552
553 len += snprintf(buf+len, sizeof(buf)-len,
554 "RX\n---------------------\n");
Ben Greear5d882c92010-11-08 10:50:03 -0800555 len += snprintf(buf+len, sizeof(buf)-len, "CRC\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900556 st->rxerr_crc,
557 st->rx_all_count > 0 ?
558 st->rxerr_crc*100/st->rx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800559 len += snprintf(buf+len, sizeof(buf)-len, "PHY\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900560 st->rxerr_phy,
561 st->rx_all_count > 0 ?
562 st->rxerr_phy*100/st->rx_all_count : 0);
Bruno Randolfda351112010-03-25 14:49:42 +0900563 for (i = 0; i < 32; i++) {
564 if (st->rxerr_phy_code[i])
565 len += snprintf(buf+len, sizeof(buf)-len,
Ben Greear5d882c92010-11-08 10:50:03 -0800566 " phy_err[%u]\t%u\n",
Bruno Randolfda351112010-03-25 14:49:42 +0900567 i, st->rxerr_phy_code[i]);
568 }
569
Ben Greear5d882c92010-11-08 10:50:03 -0800570 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900571 st->rxerr_fifo,
572 st->rx_all_count > 0 ?
573 st->rxerr_fifo*100/st->rx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800574 len += snprintf(buf+len, sizeof(buf)-len, "decrypt\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900575 st->rxerr_decrypt,
576 st->rx_all_count > 0 ?
577 st->rxerr_decrypt*100/st->rx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800578 len += snprintf(buf+len, sizeof(buf)-len, "MIC\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900579 st->rxerr_mic,
580 st->rx_all_count > 0 ?
581 st->rxerr_mic*100/st->rx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800582 len += snprintf(buf+len, sizeof(buf)-len, "process\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900583 st->rxerr_proc,
584 st->rx_all_count > 0 ?
585 st->rxerr_proc*100/st->rx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800586 len += snprintf(buf+len, sizeof(buf)-len, "jumbo\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900587 st->rxerr_jumbo,
588 st->rx_all_count > 0 ?
589 st->rxerr_jumbo*100/st->rx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800590 len += snprintf(buf+len, sizeof(buf)-len, "[RX all\t%u]\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900591 st->rx_all_count);
Ben Greear5d882c92010-11-08 10:50:03 -0800592 len += snprintf(buf+len, sizeof(buf)-len, "RX-all-bytes\t%u\n",
Ben Greearb72acdd2010-10-01 10:54:04 -0700593 st->rx_bytes_count);
Bruno Randolf76443952010-03-09 16:56:00 +0900594
595 len += snprintf(buf+len, sizeof(buf)-len,
596 "\nTX\n---------------------\n");
Ben Greear5d882c92010-11-08 10:50:03 -0800597 len += snprintf(buf+len, sizeof(buf)-len, "retry\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900598 st->txerr_retry,
599 st->tx_all_count > 0 ?
600 st->txerr_retry*100/st->tx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800601 len += snprintf(buf+len, sizeof(buf)-len, "FIFO\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900602 st->txerr_fifo,
603 st->tx_all_count > 0 ?
604 st->txerr_fifo*100/st->tx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800605 len += snprintf(buf+len, sizeof(buf)-len, "filter\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900606 st->txerr_filt,
607 st->tx_all_count > 0 ?
608 st->txerr_filt*100/st->tx_all_count : 0);
Ben Greear5d882c92010-11-08 10:50:03 -0800609 len += snprintf(buf+len, sizeof(buf)-len, "[TX all\t%u]\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900610 st->tx_all_count);
Ben Greear5d882c92010-11-08 10:50:03 -0800611 len += snprintf(buf+len, sizeof(buf)-len, "TX-all-bytes\t%u\n",
Ben Greearb72acdd2010-10-01 10:54:04 -0700612 st->tx_bytes_count);
Bruno Randolf76443952010-03-09 16:56:00 +0900613
Dan Carpenter2189d132010-07-22 10:52:02 +0200614 if (len > sizeof(buf))
615 len = sizeof(buf);
616
Bruno Randolf76443952010-03-09 16:56:00 +0900617 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
618}
619
620static ssize_t write_file_frameerrors(struct file *file,
621 const char __user *userbuf,
622 size_t count, loff_t *ppos)
623{
624 struct ath5k_softc *sc = file->private_data;
625 struct ath5k_statistics *st = &sc->stats;
626 char buf[20];
627
628 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
629 return -EFAULT;
630
631 if (strncmp(buf, "clear", 5) == 0) {
632 st->rxerr_crc = 0;
633 st->rxerr_phy = 0;
634 st->rxerr_fifo = 0;
635 st->rxerr_decrypt = 0;
636 st->rxerr_mic = 0;
637 st->rxerr_proc = 0;
638 st->rxerr_jumbo = 0;
639 st->rx_all_count = 0;
640 st->txerr_retry = 0;
641 st->txerr_fifo = 0;
642 st->txerr_filt = 0;
643 st->tx_all_count = 0;
644 printk(KERN_INFO "ath5k debug: cleared frameerrors stats\n");
645 }
646 return count;
647}
648
649static const struct file_operations fops_frameerrors = {
650 .read = read_file_frameerrors,
651 .write = write_file_frameerrors,
652 .open = ath5k_debugfs_open,
653 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200654 .llseek = default_llseek,
Bruno Randolf76443952010-03-09 16:56:00 +0900655};
656
657
Bruno Randolf2111ac02010-04-02 18:44:08 +0900658/* debugfs: ani */
659
660static ssize_t read_file_ani(struct file *file, char __user *user_buf,
661 size_t count, loff_t *ppos)
662{
663 struct ath5k_softc *sc = file->private_data;
664 struct ath5k_statistics *st = &sc->stats;
665 struct ath5k_ani_state *as = &sc->ani_state;
666
667 char buf[700];
668 unsigned int len = 0;
669
670 len += snprintf(buf+len, sizeof(buf)-len,
671 "HW has PHY error counters:\t%s\n",
672 sc->ah->ah_capabilities.cap_has_phyerr_counters ?
673 "yes" : "no");
674 len += snprintf(buf+len, sizeof(buf)-len,
675 "HW max spur immunity level:\t%d\n",
676 as->max_spur_level);
677 len += snprintf(buf+len, sizeof(buf)-len,
678 "\nANI state\n--------------------------------------------\n");
679 len += snprintf(buf+len, sizeof(buf)-len, "operating mode:\t\t\t");
680 switch (as->ani_mode) {
681 case ATH5K_ANI_MODE_OFF:
682 len += snprintf(buf+len, sizeof(buf)-len, "OFF\n");
683 break;
684 case ATH5K_ANI_MODE_MANUAL_LOW:
685 len += snprintf(buf+len, sizeof(buf)-len,
686 "MANUAL LOW\n");
687 break;
688 case ATH5K_ANI_MODE_MANUAL_HIGH:
689 len += snprintf(buf+len, sizeof(buf)-len,
690 "MANUAL HIGH\n");
691 break;
692 case ATH5K_ANI_MODE_AUTO:
693 len += snprintf(buf+len, sizeof(buf)-len, "AUTO\n");
694 break;
695 default:
696 len += snprintf(buf+len, sizeof(buf)-len,
697 "??? (not good)\n");
698 break;
699 }
700 len += snprintf(buf+len, sizeof(buf)-len,
701 "noise immunity level:\t\t%d\n",
702 as->noise_imm_level);
703 len += snprintf(buf+len, sizeof(buf)-len,
704 "spur immunity level:\t\t%d\n",
705 as->spur_level);
706 len += snprintf(buf+len, sizeof(buf)-len, "firstep level:\t\t\t%d\n",
707 as->firstep_level);
708 len += snprintf(buf+len, sizeof(buf)-len,
709 "OFDM weak signal detection:\t%s\n",
710 as->ofdm_weak_sig ? "on" : "off");
711 len += snprintf(buf+len, sizeof(buf)-len,
712 "CCK weak signal detection:\t%s\n",
713 as->cck_weak_sig ? "on" : "off");
714
715 len += snprintf(buf+len, sizeof(buf)-len,
716 "\nMIB INTERRUPTS:\t\t%u\n",
717 st->mib_intr);
718 len += snprintf(buf+len, sizeof(buf)-len,
719 "beacon RSSI average:\t%d\n",
Bruno Randolfeef39be2010-11-16 10:58:43 +0900720 (int)ewma_read(&sc->ah->ah_beacon_rssi_avg));
Felix Fietkau7109ca52010-10-08 22:13:54 +0200721
722#define CC_PRINT(_struct, _field) \
723 _struct._field, \
724 _struct.cycles > 0 ? \
725 _struct._field*100/_struct.cycles : 0
726
Bruno Randolf2111ac02010-04-02 18:44:08 +0900727 len += snprintf(buf+len, sizeof(buf)-len, "profcnt tx\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200728 CC_PRINT(as->last_cc, tx_frame));
Bruno Randolf2111ac02010-04-02 18:44:08 +0900729 len += snprintf(buf+len, sizeof(buf)-len, "profcnt rx\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200730 CC_PRINT(as->last_cc, rx_frame));
Bruno Randolf2111ac02010-04-02 18:44:08 +0900731 len += snprintf(buf+len, sizeof(buf)-len, "profcnt busy\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200732 CC_PRINT(as->last_cc, rx_busy));
733#undef CC_PRINT
Bruno Randolf2111ac02010-04-02 18:44:08 +0900734 len += snprintf(buf+len, sizeof(buf)-len, "profcnt cycles\t\t%u\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200735 as->last_cc.cycles);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900736 len += snprintf(buf+len, sizeof(buf)-len,
737 "listen time\t\t%d\tlast: %d\n",
738 as->listen_time, as->last_listen);
739 len += snprintf(buf+len, sizeof(buf)-len,
740 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
741 as->ofdm_errors, as->last_ofdm_errors,
742 as->sum_ofdm_errors);
743 len += snprintf(buf+len, sizeof(buf)-len,
744 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
745 as->cck_errors, as->last_cck_errors,
746 as->sum_cck_errors);
747 len += snprintf(buf+len, sizeof(buf)-len,
748 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
749 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1),
750 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
751 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT1)));
752 len += snprintf(buf+len, sizeof(buf)-len,
753 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
754 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2),
755 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
756 ath5k_hw_reg_read(sc->ah, AR5K_PHYERR_CNT2)));
757
Dan Carpenter2189d132010-07-22 10:52:02 +0200758 if (len > sizeof(buf))
759 len = sizeof(buf);
760
Bruno Randolf2111ac02010-04-02 18:44:08 +0900761 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
762}
763
764static ssize_t write_file_ani(struct file *file,
765 const char __user *userbuf,
766 size_t count, loff_t *ppos)
767{
768 struct ath5k_softc *sc = file->private_data;
769 char buf[20];
770
771 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
772 return -EFAULT;
773
774 if (strncmp(buf, "sens-low", 8) == 0) {
775 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_HIGH);
776 } else if (strncmp(buf, "sens-high", 9) == 0) {
777 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_MANUAL_LOW);
778 } else if (strncmp(buf, "ani-off", 7) == 0) {
779 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_OFF);
780 } else if (strncmp(buf, "ani-on", 6) == 0) {
781 ath5k_ani_init(sc->ah, ATH5K_ANI_MODE_AUTO);
782 } else if (strncmp(buf, "noise-low", 9) == 0) {
783 ath5k_ani_set_noise_immunity_level(sc->ah, 0);
784 } else if (strncmp(buf, "noise-high", 10) == 0) {
785 ath5k_ani_set_noise_immunity_level(sc->ah,
786 ATH5K_ANI_MAX_NOISE_IMM_LVL);
787 } else if (strncmp(buf, "spur-low", 8) == 0) {
788 ath5k_ani_set_spur_immunity_level(sc->ah, 0);
789 } else if (strncmp(buf, "spur-high", 9) == 0) {
790 ath5k_ani_set_spur_immunity_level(sc->ah,
791 sc->ani_state.max_spur_level);
792 } else if (strncmp(buf, "fir-low", 7) == 0) {
793 ath5k_ani_set_firstep_level(sc->ah, 0);
794 } else if (strncmp(buf, "fir-high", 8) == 0) {
795 ath5k_ani_set_firstep_level(sc->ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
796 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
797 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, false);
798 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
799 ath5k_ani_set_ofdm_weak_signal_detection(sc->ah, true);
800 } else if (strncmp(buf, "cck-off", 7) == 0) {
801 ath5k_ani_set_cck_weak_signal_detection(sc->ah, false);
802 } else if (strncmp(buf, "cck-on", 6) == 0) {
803 ath5k_ani_set_cck_weak_signal_detection(sc->ah, true);
804 }
805 return count;
806}
807
808static const struct file_operations fops_ani = {
809 .read = read_file_ani,
810 .write = write_file_ani,
811 .open = ath5k_debugfs_open,
812 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200813 .llseek = default_llseek,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900814};
815
816
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900817/* debugfs: queues etc */
818
819static ssize_t read_file_queue(struct file *file, char __user *user_buf,
820 size_t count, loff_t *ppos)
821{
822 struct ath5k_softc *sc = file->private_data;
823 char buf[700];
824 unsigned int len = 0;
825
826 struct ath5k_txq *txq;
827 struct ath5k_buf *bf, *bf0;
Bruno Randolfcfddc112010-09-17 11:36:40 +0900828 int i, n;
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900829
830 len += snprintf(buf+len, sizeof(buf)-len,
831 "available txbuffers: %d\n", sc->txbuf_len);
832
833 for (i = 0; i < ARRAY_SIZE(sc->txqs); i++) {
834 txq = &sc->txqs[i];
835
836 len += snprintf(buf+len, sizeof(buf)-len,
837 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
838
839 if (!txq->setup)
840 continue;
841
Bruno Randolfcfddc112010-09-17 11:36:40 +0900842 n = 0;
843 spin_lock_bh(&txq->lock);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900844 list_for_each_entry_safe(bf, bf0, &txq->q, list)
845 n++;
Bruno Randolfcfddc112010-09-17 11:36:40 +0900846 spin_unlock_bh(&txq->lock);
847
848 len += snprintf(buf+len, sizeof(buf)-len,
849 " len: %d bufs: %d\n", txq->txq_len, n);
Bruno Randolf923e5b32010-09-17 11:37:02 +0900850 len += snprintf(buf+len, sizeof(buf)-len,
851 " stuck: %d\n", txq->txq_stuck);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900852 }
853
Dan Carpenter2189d132010-07-22 10:52:02 +0200854 if (len > sizeof(buf))
855 len = sizeof(buf);
856
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900857 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
858}
859
860static ssize_t write_file_queue(struct file *file,
861 const char __user *userbuf,
862 size_t count, loff_t *ppos)
863{
864 struct ath5k_softc *sc = file->private_data;
865 char buf[20];
866
867 if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
868 return -EFAULT;
869
870 if (strncmp(buf, "start", 5) == 0)
871 ieee80211_wake_queues(sc->hw);
872 else if (strncmp(buf, "stop", 4) == 0)
873 ieee80211_stop_queues(sc->hw);
874
875 return count;
876}
877
878
879static const struct file_operations fops_queue = {
880 .read = read_file_queue,
881 .write = write_file_queue,
882 .open = ath5k_debugfs_open,
883 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200884 .llseek = default_llseek,
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900885};
886
887
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200888void
889ath5k_debug_init_device(struct ath5k_softc *sc)
890{
891 sc->debug.level = ath5k_debug;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900892
Ben Greeard84a35d2010-10-12 10:55:38 -0700893 sc->debug.debugfs_phydir = debugfs_create_dir("ath5k",
894 sc->hw->wiphy->debugfsdir);
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900895
Jiri Slaby31670072009-06-28 23:25:27 +0200896 sc->debug.debugfs_debug = debugfs_create_file("debug",
897 S_IWUSR | S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900898 sc->debug.debugfs_phydir, sc, &fops_debug);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200899
Jiri Slaby31670072009-06-28 23:25:27 +0200900 sc->debug.debugfs_registers = debugfs_create_file("registers", S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900901 sc->debug.debugfs_phydir, sc, &fops_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200902
Jiri Slaby31670072009-06-28 23:25:27 +0200903 sc->debug.debugfs_beacon = debugfs_create_file("beacon",
904 S_IWUSR | S_IRUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900905 sc->debug.debugfs_phydir, sc, &fops_beacon);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200906
Cheng Renquan33ab6252008-11-22 11:22:49 +0800907 sc->debug.debugfs_reset = debugfs_create_file("reset", S_IWUSR,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900908 sc->debug.debugfs_phydir, sc, &fops_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +0900909
910 sc->debug.debugfs_antenna = debugfs_create_file("antenna",
911 S_IWUSR | S_IRUSR,
912 sc->debug.debugfs_phydir, sc, &fops_antenna);
Bruno Randolf76443952010-03-09 16:56:00 +0900913
Ben Greear87fd2e62010-09-21 17:03:57 -0700914 sc->debug.debugfs_misc = debugfs_create_file("misc",
915 S_IRUSR,
916 sc->debug.debugfs_phydir, sc, &fops_misc);
917
Bruno Randolf76443952010-03-09 16:56:00 +0900918 sc->debug.debugfs_frameerrors = debugfs_create_file("frameerrors",
919 S_IWUSR | S_IRUSR,
920 sc->debug.debugfs_phydir, sc,
921 &fops_frameerrors);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900922
923 sc->debug.debugfs_ani = debugfs_create_file("ani",
924 S_IWUSR | S_IRUSR,
925 sc->debug.debugfs_phydir, sc,
926 &fops_ani);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900927
928 sc->debug.debugfs_queue = debugfs_create_file("queue",
929 S_IWUSR | S_IRUSR,
930 sc->debug.debugfs_phydir, sc,
931 &fops_queue);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200932}
933
934void
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200935ath5k_debug_finish_device(struct ath5k_softc *sc)
936{
937 debugfs_remove(sc->debug.debugfs_debug);
938 debugfs_remove(sc->debug.debugfs_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200939 debugfs_remove(sc->debug.debugfs_beacon);
940 debugfs_remove(sc->debug.debugfs_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +0900941 debugfs_remove(sc->debug.debugfs_antenna);
Ben Greear87fd2e62010-09-21 17:03:57 -0700942 debugfs_remove(sc->debug.debugfs_misc);
Bruno Randolf76443952010-03-09 16:56:00 +0900943 debugfs_remove(sc->debug.debugfs_frameerrors);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900944 debugfs_remove(sc->debug.debugfs_ani);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900945 debugfs_remove(sc->debug.debugfs_queue);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200946 debugfs_remove(sc->debug.debugfs_phydir);
947}
948
949
950/* functions used in other places */
951
952void
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500953ath5k_debug_dump_bands(struct ath5k_softc *sc)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200954{
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500955 unsigned int b, i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200956
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500957 if (likely(!(sc->debug.level & ATH5K_DEBUG_DUMPBANDS)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200958 return;
959
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500960 BUG_ON(!sc->sbands);
961
962 for (b = 0; b < IEEE80211_NUM_BANDS; b++) {
963 struct ieee80211_supported_band *band = &sc->sbands[b];
Bob Copelandb7fcb5c2009-04-27 22:12:43 -0400964 char bname[6];
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500965 switch (band->band) {
966 case IEEE80211_BAND_2GHZ:
967 strcpy(bname, "2 GHz");
968 break;
969 case IEEE80211_BAND_5GHZ:
970 strcpy(bname, "5 GHz");
971 break;
972 default:
973 printk(KERN_DEBUG "Band not supported: %d\n",
974 band->band);
975 return;
976 }
977 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
978 band->n_channels, band->n_bitrates);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200979 printk(KERN_DEBUG " channels:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500980 for (i = 0; i < band->n_channels; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200981 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500982 ieee80211_frequency_to_channel(
983 band->channels[i].center_freq),
984 band->channels[i].center_freq,
985 band->channels[i].hw_value,
986 band->channels[i].flags);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200987 printk(KERN_DEBUG " rates:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500988 for (i = 0; i < band->n_bitrates; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200989 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500990 band->bitrates[i].bitrate,
991 band->bitrates[i].hw_value,
992 band->bitrates[i].flags,
993 band->bitrates[i].hw_value_short);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200994 }
995}
996
997static inline void
Bruno Randolfb47f4072008-03-05 18:35:45 +0900998ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
999 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001000{
1001 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001002 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001003
1004 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
1005 ds, (unsigned long long)bf->daddr,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001006 ds->ds_link, ds->ds_data,
1007 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
Bruno Randolf62412a82010-06-16 19:12:12 +09001008 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001009 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001010}
1011
1012void
1013ath5k_debug_printrxbuffs(struct ath5k_softc *sc, struct ath5k_hw *ah)
1014{
1015 struct ath5k_desc *ds;
1016 struct ath5k_buf *bf;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001017 struct ath5k_rx_status rs = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001018 int status;
1019
Bob Copelandb4c52612010-08-21 16:39:03 -04001020 if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001021 return;
1022
Bruno Randolf265faad2010-06-16 19:11:30 +09001023 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
Nick Kossifidisc6e387a2008-08-29 22:45:39 +03001024 ath5k_hw_get_rxdp(ah), sc->rxlink);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001025
1026 spin_lock_bh(&sc->rxbuflock);
1027 list_for_each_entry(bf, &sc->rxbuf, list) {
1028 ds = bf->desc;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001029 status = ah->ah_proc_rx_desc(ah, ds, &rs);
Bruno Randolfbe9b7252008-01-23 10:27:51 +09001030 if (!status)
Bruno Randolfb47f4072008-03-05 18:35:45 +09001031 ath5k_debug_printrxbuf(bf, status == 0, &rs);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001032 }
1033 spin_unlock_bh(&sc->rxbuflock);
1034}
1035
1036void
Bruno Randolfb47f4072008-03-05 18:35:45 +09001037ath5k_debug_printtxbuf(struct ath5k_softc *sc, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001038{
1039 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001040 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001041 struct ath5k_tx_status ts = {};
1042 int done;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001043
Bob Copelandb4c52612010-08-21 16:39:03 -04001044 if (likely(!(sc->debug.level & ATH5K_DEBUG_DESC)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001045 return;
1046
Bruno Randolfb47f4072008-03-05 18:35:45 +09001047 done = sc->ah->ah_proc_tx_desc(sc->ah, bf->desc, &ts);
1048
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001049 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1050 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001051 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
1052 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
1053 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001054 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001055}
1056
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001057#endif /* ifdef CONFIG_ATH5K_DEBUG */