Merge remote-tracking branch 'mmc-uh/next'
[deliverable/linux.git] / drivers / net / wireless / ath / ath5k / debug.c
CommitLineData
fa1c114f 1/*
be9b7259 2 * Copyright (c) 2007-2008 Bruno Randolf <bruno@thinktube.com>
fa1c114f
JS
3 *
4 * This file is free software: you may copy, redistribute and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation, either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This file is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 *
18 * This file incorporates work covered by the following copyright and
19 * permission notice:
20 *
21 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
22 * Copyright (c) 2004-2005 Atheros Communications, Inc.
23 * Copyright (c) 2006 Devicescape Software, Inc.
24 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
25 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
26 *
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer,
34 * without modification.
35 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
36 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
37 * redistribution must be conditioned upon including a substantially
38 * similar Disclaimer requirement for further binary redistribution.
39 * 3. Neither the names of the above-listed copyright holders nor the names
40 * of any contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * Alternatively, this software may be distributed under the terms of the
44 * GNU General Public License ("GPL") version 2 as published by the Free
45 * Software Foundation.
46 *
47 * NO WARRANTY
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
51 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
52 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
53 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
56 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
58 * THE POSSIBILITY OF SUCH DAMAGES.
59 */
516304b0
JP
60
61#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
62
ee40fa06 63#include <linux/export.h>
6eb07caf 64#include <linux/moduleparam.h>
32bc6d1a 65#include <linux/vmalloc.h>
fa1c114f 66
931be260
PR
67#include <linux/seq_file.h>
68#include <linux/list.h>
005eff59 69#include <linux/vmalloc.h>
c6e387a2 70#include "debug.h"
931be260
PR
71#include "ath5k.h"
72#include "reg.h"
73#include "base.h"
fa1c114f
JS
74
75static unsigned int ath5k_debug;
76module_param_named(debug, ath5k_debug, uint, 0);
77
78
fa1c114f
JS
79/* debugfs: registers */
80
81struct reg {
2c91108c 82 const char *name;
fa1c114f
JS
83 int addr;
84};
85
86#define REG_STRUCT_INIT(r) { #r, r }
87
88/* just a few random registers, might want to add more */
2c91108c 89static const struct reg regs[] = {
fa1c114f
JS
90 REG_STRUCT_INIT(AR5K_CR),
91 REG_STRUCT_INIT(AR5K_RXDP),
92 REG_STRUCT_INIT(AR5K_CFG),
93 REG_STRUCT_INIT(AR5K_IER),
94 REG_STRUCT_INIT(AR5K_BCR),
95 REG_STRUCT_INIT(AR5K_RTSD0),
96 REG_STRUCT_INIT(AR5K_RTSD1),
97 REG_STRUCT_INIT(AR5K_TXCFG),
98 REG_STRUCT_INIT(AR5K_RXCFG),
99 REG_STRUCT_INIT(AR5K_RXJLA),
100 REG_STRUCT_INIT(AR5K_MIBC),
101 REG_STRUCT_INIT(AR5K_TOPS),
102 REG_STRUCT_INIT(AR5K_RXNOFRM),
103 REG_STRUCT_INIT(AR5K_TXNOFRM),
104 REG_STRUCT_INIT(AR5K_RPGTO),
105 REG_STRUCT_INIT(AR5K_RFCNT),
106 REG_STRUCT_INIT(AR5K_MISC),
107 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
108 REG_STRUCT_INIT(AR5K_ISR),
109 REG_STRUCT_INIT(AR5K_PISR),
110 REG_STRUCT_INIT(AR5K_SISR0),
111 REG_STRUCT_INIT(AR5K_SISR1),
112 REG_STRUCT_INIT(AR5K_SISR2),
113 REG_STRUCT_INIT(AR5K_SISR3),
114 REG_STRUCT_INIT(AR5K_SISR4),
115 REG_STRUCT_INIT(AR5K_IMR),
116 REG_STRUCT_INIT(AR5K_PIMR),
117 REG_STRUCT_INIT(AR5K_SIMR0),
118 REG_STRUCT_INIT(AR5K_SIMR1),
119 REG_STRUCT_INIT(AR5K_SIMR2),
120 REG_STRUCT_INIT(AR5K_SIMR3),
121 REG_STRUCT_INIT(AR5K_SIMR4),
122 REG_STRUCT_INIT(AR5K_DCM_ADDR),
123 REG_STRUCT_INIT(AR5K_DCCFG),
124 REG_STRUCT_INIT(AR5K_CCFG),
125 REG_STRUCT_INIT(AR5K_CPC0),
126 REG_STRUCT_INIT(AR5K_CPC1),
127 REG_STRUCT_INIT(AR5K_CPC2),
128 REG_STRUCT_INIT(AR5K_CPC3),
0bacdf30 129 REG_STRUCT_INIT(AR5K_CPCOVF),
fa1c114f
JS
130 REG_STRUCT_INIT(AR5K_RESET_CTL),
131 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
132 REG_STRUCT_INIT(AR5K_INTPEND),
133 REG_STRUCT_INIT(AR5K_SFR),
134 REG_STRUCT_INIT(AR5K_PCICFG),
135 REG_STRUCT_INIT(AR5K_GPIOCR),
136 REG_STRUCT_INIT(AR5K_GPIODO),
137 REG_STRUCT_INIT(AR5K_SREV),
138};
139
140static void *reg_start(struct seq_file *seq, loff_t *pos)
141{
2c91108c 142 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
fa1c114f
JS
143}
144
145static void reg_stop(struct seq_file *seq, void *p)
146{
147 /* nothing to do */
148}
149
150static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
151{
152 ++*pos;
2c91108c 153 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
fa1c114f
JS
154}
155
156static int reg_show(struct seq_file *seq, void *p)
157{
e0d687bd 158 struct ath5k_hw *ah = seq->private;
fa1c114f
JS
159 struct reg *r = p;
160 seq_printf(seq, "%-25s0x%08x\n", r->name,
e0d687bd 161 ath5k_hw_reg_read(ah, r->addr));
fa1c114f
JS
162 return 0;
163}
164
4101dec9 165static const struct seq_operations register_seq_ops = {
fa1c114f
JS
166 .start = reg_start,
167 .next = reg_next,
168 .stop = reg_stop,
169 .show = reg_show
170};
171
172static int open_file_registers(struct inode *inode, struct file *file)
173{
174 struct seq_file *s;
175 int res;
176 res = seq_open(file, &register_seq_ops);
177 if (res == 0) {
178 s = file->private_data;
179 s->private = inode->i_private;
180 }
181 return res;
182}
183
184static const struct file_operations fops_registers = {
185 .open = open_file_registers,
186 .read = seq_read,
187 .llseek = seq_lseek,
188 .release = seq_release,
189 .owner = THIS_MODULE,
190};
191
192
fa1c114f
JS
193/* debugfs: beacons */
194
195static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
196 size_t count, loff_t *ppos)
197{
e0d687bd 198 struct ath5k_hw *ah = file->private_data;
be9b7259
BR
199 char buf[500];
200 unsigned int len = 0;
fa1c114f
JS
201 unsigned int v;
202 u64 tsf;
203
e0d687bd 204 v = ath5k_hw_reg_read(ah, AR5K_BEACON);
e4bbf2f5 205 len += snprintf(buf + len, sizeof(buf) - len,
fa1c114f
JS
206 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
207 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
208 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
209
e4bbf2f5 210 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n",
e0d687bd 211 "AR5K_LAST_TSTP", ath5k_hw_reg_read(ah, AR5K_LAST_TSTP));
fa1c114f 212
e4bbf2f5 213 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n\n",
e0d687bd 214 "AR5K_BEACON_CNT", ath5k_hw_reg_read(ah, AR5K_BEACON_CNT));
fa1c114f 215
e0d687bd 216 v = ath5k_hw_reg_read(ah, AR5K_TIMER0);
e4bbf2f5 217 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
fa1c114f
JS
218 "AR5K_TIMER0 (TBTT)", v, v);
219
e0d687bd 220 v = ath5k_hw_reg_read(ah, AR5K_TIMER1);
e4bbf2f5 221 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
fa1c114f
JS
222 "AR5K_TIMER1 (DMA)", v, v >> 3);
223
e0d687bd 224 v = ath5k_hw_reg_read(ah, AR5K_TIMER2);
e4bbf2f5 225 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
fa1c114f
JS
226 "AR5K_TIMER2 (SWBA)", v, v >> 3);
227
e0d687bd 228 v = ath5k_hw_reg_read(ah, AR5K_TIMER3);
e4bbf2f5 229 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
fa1c114f
JS
230 "AR5K_TIMER3 (ATIM)", v, v);
231
e0d687bd 232 tsf = ath5k_hw_get_tsf64(ah);
e4bbf2f5 233 len += snprintf(buf + len, sizeof(buf) - len,
f868f4e1
JL
234 "TSF\t\t0x%016llx\tTU: %08x\n",
235 (unsigned long long)tsf, TSF_TO_TU(tsf));
fa1c114f 236
2189d13f
DC
237 if (len > sizeof(buf))
238 len = sizeof(buf);
239
fa1c114f
JS
240 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
241}
242
243static ssize_t write_file_beacon(struct file *file,
244 const char __user *userbuf,
245 size_t count, loff_t *ppos)
246{
e0d687bd 247 struct ath5k_hw *ah = file->private_data;
be9b7259 248 char buf[20];
fa1c114f 249
8aada63c
DH
250 count = min_t(size_t, count, sizeof(buf) - 1);
251 if (copy_from_user(buf, userbuf, count))
be9b7259
BR
252 return -EFAULT;
253
8aada63c 254 buf[count] = '\0';
be9b7259 255 if (strncmp(buf, "disable", 7) == 0) {
fa1c114f 256 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
516304b0 257 pr_info("debugfs disable beacons\n");
be9b7259 258 } else if (strncmp(buf, "enable", 6) == 0) {
fa1c114f 259 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
516304b0 260 pr_info("debugfs enable beacons\n");
fa1c114f
JS
261 }
262 return count;
263}
264
265static const struct file_operations fops_beacon = {
266 .read = read_file_beacon,
267 .write = write_file_beacon,
234e3405 268 .open = simple_open,
fa1c114f 269 .owner = THIS_MODULE,
6038f373 270 .llseek = default_llseek,
fa1c114f
JS
271};
272
273
274/* debugfs: reset */
275
276static ssize_t write_file_reset(struct file *file,
277 const char __user *userbuf,
278 size_t count, loff_t *ppos)
279{
e0d687bd
PR
280 struct ath5k_hw *ah = file->private_data;
281 ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
282 ieee80211_queue_work(ah->hw, &ah->reset_work);
fa1c114f
JS
283 return count;
284}
285
286static const struct file_operations fops_reset = {
287 .write = write_file_reset,
234e3405 288 .open = simple_open,
fa1c114f 289 .owner = THIS_MODULE,
6038f373 290 .llseek = noop_llseek,
fa1c114f
JS
291};
292
293
be9b7259
BR
294/* debugfs: debug level */
295
2c91108c 296static const struct {
be9b7259
BR
297 enum ath5k_debug_level level;
298 const char *name;
299 const char *desc;
300} dbg_info[] = {
301 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
302 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
303 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
304 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
305 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
306 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
307 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
85519a65 308 { ATH5K_DEBUG_LED, "led", "LED management" },
b446197c 309 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
b3a28e68 310 { ATH5K_DEBUG_DMA, "dma", "dma start/stop" },
2111ac0d 311 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
b4c52612 312 { ATH5K_DEBUG_DESC, "desc", "descriptor chains" },
be9b7259
BR
313 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
314};
315
316static ssize_t read_file_debug(struct file *file, char __user *user_buf,
317 size_t count, loff_t *ppos)
318{
e0d687bd 319 struct ath5k_hw *ah = file->private_data;
be9b7259
BR
320 char buf[700];
321 unsigned int len = 0;
322 unsigned int i;
323
e4bbf2f5 324 len += snprintf(buf + len, sizeof(buf) - len,
e0d687bd 325 "DEBUG LEVEL: 0x%08x\n\n", ah->debug.level);
be9b7259
BR
326
327 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
e4bbf2f5 328 len += snprintf(buf + len, sizeof(buf) - len,
be9b7259 329 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
e0d687bd 330 ah->debug.level & dbg_info[i].level ? '+' : ' ',
be9b7259
BR
331 dbg_info[i].level, dbg_info[i].desc);
332 }
e4bbf2f5 333 len += snprintf(buf + len, sizeof(buf) - len,
be9b7259 334 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
e0d687bd 335 ah->debug.level == dbg_info[i].level ? '+' : ' ',
be9b7259
BR
336 dbg_info[i].level, dbg_info[i].desc);
337
2189d13f
DC
338 if (len > sizeof(buf))
339 len = sizeof(buf);
340
be9b7259
BR
341 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
342}
343
344static ssize_t write_file_debug(struct file *file,
345 const char __user *userbuf,
346 size_t count, loff_t *ppos)
347{
e0d687bd 348 struct ath5k_hw *ah = file->private_data;
be9b7259
BR
349 unsigned int i;
350 char buf[20];
351
8aada63c
DH
352 count = min_t(size_t, count, sizeof(buf) - 1);
353 if (copy_from_user(buf, userbuf, count))
be9b7259
BR
354 return -EFAULT;
355
8aada63c 356 buf[count] = '\0';
be9b7259
BR
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) {
e0d687bd 360 ah->debug.level ^= dbg_info[i].level; /* toggle bit */
be9b7259
BR
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,
234e3405 370 .open = simple_open,
be9b7259 371 .owner = THIS_MODULE,
6038f373 372 .llseek = default_llseek,
be9b7259
BR
373};
374
375
604eeadd
BR
376/* debugfs: antenna */
377
378static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
379 size_t count, loff_t *ppos)
380{
e0d687bd 381 struct ath5k_hw *ah = file->private_data;
604eeadd
BR
382 char buf[700];
383 unsigned int len = 0;
384 unsigned int i;
385 unsigned int v;
386
e4bbf2f5 387 len += snprintf(buf + len, sizeof(buf) - len, "antenna mode\t%d\n",
e0d687bd 388 ah->ah_ant_mode);
e4bbf2f5 389 len += snprintf(buf + len, sizeof(buf) - len, "default antenna\t%d\n",
e0d687bd 390 ah->ah_def_ant);
e4bbf2f5 391 len += snprintf(buf + len, sizeof(buf) - len, "tx antenna\t%d\n",
e0d687bd 392 ah->ah_tx_ant);
604eeadd 393
e4bbf2f5 394 len += snprintf(buf + len, sizeof(buf) - len, "\nANTENNA\t\tRX\tTX\n");
e0d687bd 395 for (i = 1; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) {
e4bbf2f5 396 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd 397 "[antenna %d]\t%d\t%d\n",
e0d687bd 398 i, ah->stats.antenna_rx[i], ah->stats.antenna_tx[i]);
604eeadd 399 }
e4bbf2f5 400 len += snprintf(buf + len, sizeof(buf) - len, "[invalid]\t%d\t%d\n",
e0d687bd 401 ah->stats.antenna_rx[0], ah->stats.antenna_tx[0]);
604eeadd 402
e0d687bd 403 v = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
e4bbf2f5 404 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd
BR
405 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
406
e0d687bd 407 v = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
e4bbf2f5 408 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd
BR
409 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
410 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
e4bbf2f5 411 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd
BR
412 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
413 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
e4bbf2f5 414 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd
BR
415 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
416 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
e4bbf2f5 417 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd
BR
418 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
419 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
420
e0d687bd 421 v = ath5k_hw_reg_read(ah, AR5K_PHY_AGCCTL);
e4bbf2f5 422 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd
BR
423 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
424 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
425
e0d687bd 426 v = ath5k_hw_reg_read(ah, AR5K_PHY_RESTART);
e4bbf2f5 427 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd
BR
428 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
429 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
430
e0d687bd 431 v = ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ANT_DIV);
e4bbf2f5 432 len += snprintf(buf + len, sizeof(buf) - len,
604eeadd
BR
433 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
434 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
435
e0d687bd 436 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
e4bbf2f5 437 len += snprintf(buf + len, sizeof(buf) - len,
0ca74027 438 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
e0d687bd 439 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
e4bbf2f5 440 len += snprintf(buf + len, sizeof(buf) - len,
0ca74027
BR
441 "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v);
442
2189d13f
DC
443 if (len > sizeof(buf))
444 len = sizeof(buf);
445
604eeadd
BR
446 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{
e0d687bd 453 struct ath5k_hw *ah = file->private_data;
604eeadd
BR
454 unsigned int i;
455 char buf[20];
456
8aada63c
DH
457 count = min_t(size_t, count, sizeof(buf) - 1);
458 if (copy_from_user(buf, userbuf, count))
604eeadd
BR
459 return -EFAULT;
460
8aada63c 461 buf[count] = '\0';
604eeadd 462 if (strncmp(buf, "diversity", 9) == 0) {
e0d687bd 463 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
516304b0 464 pr_info("debug: enable diversity\n");
604eeadd 465 } else if (strncmp(buf, "fixed-a", 7) == 0) {
e0d687bd 466 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
516304b0 467 pr_info("debug: fixed antenna A\n");
604eeadd 468 } else if (strncmp(buf, "fixed-b", 7) == 0) {
e0d687bd 469 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
516304b0 470 pr_info("debug: fixed antenna B\n");
604eeadd 471 } else if (strncmp(buf, "clear", 5) == 0) {
e0d687bd
PR
472 for (i = 0; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) {
473 ah->stats.antenna_rx[i] = 0;
474 ah->stats.antenna_tx[i] = 0;
604eeadd 475 }
516304b0 476 pr_info("debug: cleared antenna stats\n");
604eeadd
BR
477 }
478 return count;
479}
480
481static const struct file_operations fops_antenna = {
482 .read = read_file_antenna,
483 .write = write_file_antenna,
234e3405 484 .open = simple_open,
604eeadd 485 .owner = THIS_MODULE,
6038f373 486 .llseek = default_llseek,
604eeadd
BR
487};
488
87fd2e6c
BG
489/* debugfs: misc */
490
491static ssize_t read_file_misc(struct file *file, char __user *user_buf,
492 size_t count, loff_t *ppos)
493{
e0d687bd 494 struct ath5k_hw *ah = file->private_data;
87fd2e6c
BG
495 char buf[700];
496 unsigned int len = 0;
e0d687bd 497 u32 filt = ath5k_hw_get_rx_filter(ah);
87fd2e6c 498
e4bbf2f5 499 len += snprintf(buf + len, sizeof(buf) - len, "bssid-mask: %pM\n",
e0d687bd 500 ah->bssidmask);
e4bbf2f5 501 len += snprintf(buf + len, sizeof(buf) - len, "filter-flags: 0x%x ",
87fd2e6c
BG
502 filt);
503 if (filt & AR5K_RX_FILTER_UCAST)
e4bbf2f5 504 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
87fd2e6c 505 if (filt & AR5K_RX_FILTER_MCAST)
e4bbf2f5 506 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
87fd2e6c 507 if (filt & AR5K_RX_FILTER_BCAST)
e4bbf2f5 508 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
87fd2e6c 509 if (filt & AR5K_RX_FILTER_CONTROL)
e4bbf2f5 510 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
87fd2e6c 511 if (filt & AR5K_RX_FILTER_BEACON)
e4bbf2f5 512 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
87fd2e6c 513 if (filt & AR5K_RX_FILTER_PROM)
e4bbf2f5 514 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
87fd2e6c 515 if (filt & AR5K_RX_FILTER_XRPOLL)
e4bbf2f5 516 len += snprintf(buf + len, sizeof(buf) - len, " XRPOLL");
87fd2e6c 517 if (filt & AR5K_RX_FILTER_PROBEREQ)
e4bbf2f5 518 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
87fd2e6c 519 if (filt & AR5K_RX_FILTER_PHYERR_5212)
e4bbf2f5 520 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR-5212");
87fd2e6c 521 if (filt & AR5K_RX_FILTER_RADARERR_5212)
e4bbf2f5 522 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5212");
87fd2e6c 523 if (filt & AR5K_RX_FILTER_PHYERR_5211)
e4bbf2f5 524 snprintf(buf + len, sizeof(buf) - len, " PHYERR-5211");
87fd2e6c 525 if (filt & AR5K_RX_FILTER_RADARERR_5211)
e4bbf2f5 526 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5211");
908ebfb9 527
e4bbf2f5 528 len += snprintf(buf + len, sizeof(buf) - len, "\nopmode: %s (%d)\n",
e0d687bd 529 ath_opmode_to_string(ah->opmode), ah->opmode);
92c68a66 530
87fd2e6c
BG
531 if (len > sizeof(buf))
532 len = sizeof(buf);
533
534 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
535}
536
537static const struct file_operations fops_misc = {
538 .read = read_file_misc,
234e3405 539 .open = simple_open,
87fd2e6c
BG
540 .owner = THIS_MODULE,
541};
542
604eeadd 543
7644395f
BR
544/* debugfs: frameerrors */
545
546static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
547 size_t count, loff_t *ppos)
548{
e0d687bd
PR
549 struct ath5k_hw *ah = file->private_data;
550 struct ath5k_statistics *st = &ah->stats;
7644395f
BR
551 char buf[700];
552 unsigned int len = 0;
da35111a 553 int i;
7644395f 554
e4bbf2f5 555 len += snprintf(buf + len, sizeof(buf) - len,
7644395f 556 "RX\n---------------------\n");
e4bbf2f5 557 len += snprintf(buf + len, sizeof(buf) - len, "CRC\t%u\t(%u%%)\n",
7644395f
BR
558 st->rxerr_crc,
559 st->rx_all_count > 0 ?
e4bbf2f5
PR
560 st->rxerr_crc * 100 / st->rx_all_count : 0);
561 len += snprintf(buf + len, sizeof(buf) - len, "PHY\t%u\t(%u%%)\n",
7644395f
BR
562 st->rxerr_phy,
563 st->rx_all_count > 0 ?
e4bbf2f5 564 st->rxerr_phy * 100 / st->rx_all_count : 0);
da35111a
BR
565 for (i = 0; i < 32; i++) {
566 if (st->rxerr_phy_code[i])
e4bbf2f5 567 len += snprintf(buf + len, sizeof(buf) - len,
5d882c97 568 " phy_err[%u]\t%u\n",
da35111a
BR
569 i, st->rxerr_phy_code[i]);
570 }
571
e4bbf2f5 572 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n",
7644395f
BR
573 st->rxerr_fifo,
574 st->rx_all_count > 0 ?
e4bbf2f5
PR
575 st->rxerr_fifo * 100 / st->rx_all_count : 0);
576 len += snprintf(buf + len, sizeof(buf) - len, "decrypt\t%u\t(%u%%)\n",
7644395f
BR
577 st->rxerr_decrypt,
578 st->rx_all_count > 0 ?
e4bbf2f5
PR
579 st->rxerr_decrypt * 100 / st->rx_all_count : 0);
580 len += snprintf(buf + len, sizeof(buf) - len, "MIC\t%u\t(%u%%)\n",
7644395f
BR
581 st->rxerr_mic,
582 st->rx_all_count > 0 ?
e4bbf2f5
PR
583 st->rxerr_mic * 100 / st->rx_all_count : 0);
584 len += snprintf(buf + len, sizeof(buf) - len, "process\t%u\t(%u%%)\n",
7644395f
BR
585 st->rxerr_proc,
586 st->rx_all_count > 0 ?
e4bbf2f5
PR
587 st->rxerr_proc * 100 / st->rx_all_count : 0);
588 len += snprintf(buf + len, sizeof(buf) - len, "jumbo\t%u\t(%u%%)\n",
7644395f
BR
589 st->rxerr_jumbo,
590 st->rx_all_count > 0 ?
e4bbf2f5
PR
591 st->rxerr_jumbo * 100 / st->rx_all_count : 0);
592 len += snprintf(buf + len, sizeof(buf) - len, "[RX all\t%u]\n",
7644395f 593 st->rx_all_count);
e4bbf2f5 594 len += snprintf(buf + len, sizeof(buf) - len, "RX-all-bytes\t%u\n",
b72acddb 595 st->rx_bytes_count);
7644395f 596
e4bbf2f5 597 len += snprintf(buf + len, sizeof(buf) - len,
7644395f 598 "\nTX\n---------------------\n");
e4bbf2f5 599 len += snprintf(buf + len, sizeof(buf) - len, "retry\t%u\t(%u%%)\n",
7644395f
BR
600 st->txerr_retry,
601 st->tx_all_count > 0 ?
e4bbf2f5
PR
602 st->txerr_retry * 100 / st->tx_all_count : 0);
603 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n",
7644395f
BR
604 st->txerr_fifo,
605 st->tx_all_count > 0 ?
e4bbf2f5
PR
606 st->txerr_fifo * 100 / st->tx_all_count : 0);
607 len += snprintf(buf + len, sizeof(buf) - len, "filter\t%u\t(%u%%)\n",
7644395f
BR
608 st->txerr_filt,
609 st->tx_all_count > 0 ?
e4bbf2f5
PR
610 st->txerr_filt * 100 / st->tx_all_count : 0);
611 len += snprintf(buf + len, sizeof(buf) - len, "[TX all\t%u]\n",
7644395f 612 st->tx_all_count);
e4bbf2f5 613 len += snprintf(buf + len, sizeof(buf) - len, "TX-all-bytes\t%u\n",
b72acddb 614 st->tx_bytes_count);
7644395f 615
2189d13f
DC
616 if (len > sizeof(buf))
617 len = sizeof(buf);
618
7644395f
BR
619 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
620}
621
622static ssize_t write_file_frameerrors(struct file *file,
623 const char __user *userbuf,
624 size_t count, loff_t *ppos)
625{
e0d687bd
PR
626 struct ath5k_hw *ah = file->private_data;
627 struct ath5k_statistics *st = &ah->stats;
7644395f
BR
628 char buf[20];
629
8aada63c
DH
630 count = min_t(size_t, count, sizeof(buf) - 1);
631 if (copy_from_user(buf, userbuf, count))
7644395f
BR
632 return -EFAULT;
633
8aada63c 634 buf[count] = '\0';
7644395f
BR
635 if (strncmp(buf, "clear", 5) == 0) {
636 st->rxerr_crc = 0;
637 st->rxerr_phy = 0;
638 st->rxerr_fifo = 0;
639 st->rxerr_decrypt = 0;
640 st->rxerr_mic = 0;
641 st->rxerr_proc = 0;
642 st->rxerr_jumbo = 0;
643 st->rx_all_count = 0;
644 st->txerr_retry = 0;
645 st->txerr_fifo = 0;
646 st->txerr_filt = 0;
647 st->tx_all_count = 0;
516304b0 648 pr_info("debug: cleared frameerrors stats\n");
7644395f
BR
649 }
650 return count;
651}
652
653static const struct file_operations fops_frameerrors = {
654 .read = read_file_frameerrors,
655 .write = write_file_frameerrors,
234e3405 656 .open = simple_open,
7644395f 657 .owner = THIS_MODULE,
6038f373 658 .llseek = default_llseek,
7644395f
BR
659};
660
661
2111ac0d
BR
662/* debugfs: ani */
663
664static ssize_t read_file_ani(struct file *file, char __user *user_buf,
665 size_t count, loff_t *ppos)
666{
e0d687bd
PR
667 struct ath5k_hw *ah = file->private_data;
668 struct ath5k_statistics *st = &ah->stats;
669 struct ath5k_ani_state *as = &ah->ani_state;
2111ac0d
BR
670
671 char buf[700];
672 unsigned int len = 0;
673
e4bbf2f5 674 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d 675 "HW has PHY error counters:\t%s\n",
e0d687bd 676 ah->ah_capabilities.cap_has_phyerr_counters ?
2111ac0d 677 "yes" : "no");
e4bbf2f5 678 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
679 "HW max spur immunity level:\t%d\n",
680 as->max_spur_level);
e4bbf2f5 681 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d 682 "\nANI state\n--------------------------------------------\n");
e4bbf2f5 683 len += snprintf(buf + len, sizeof(buf) - len, "operating mode:\t\t\t");
2111ac0d
BR
684 switch (as->ani_mode) {
685 case ATH5K_ANI_MODE_OFF:
e4bbf2f5 686 len += snprintf(buf + len, sizeof(buf) - len, "OFF\n");
2111ac0d
BR
687 break;
688 case ATH5K_ANI_MODE_MANUAL_LOW:
e4bbf2f5 689 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
690 "MANUAL LOW\n");
691 break;
692 case ATH5K_ANI_MODE_MANUAL_HIGH:
e4bbf2f5 693 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
694 "MANUAL HIGH\n");
695 break;
696 case ATH5K_ANI_MODE_AUTO:
e4bbf2f5 697 len += snprintf(buf + len, sizeof(buf) - len, "AUTO\n");
2111ac0d
BR
698 break;
699 default:
e4bbf2f5 700 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
701 "??? (not good)\n");
702 break;
703 }
e4bbf2f5 704 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
705 "noise immunity level:\t\t%d\n",
706 as->noise_imm_level);
e4bbf2f5 707 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
708 "spur immunity level:\t\t%d\n",
709 as->spur_level);
e4bbf2f5
PR
710 len += snprintf(buf + len, sizeof(buf) - len,
711 "firstep level:\t\t\t%d\n",
2111ac0d 712 as->firstep_level);
e4bbf2f5 713 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
714 "OFDM weak signal detection:\t%s\n",
715 as->ofdm_weak_sig ? "on" : "off");
e4bbf2f5 716 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
717 "CCK weak signal detection:\t%s\n",
718 as->cck_weak_sig ? "on" : "off");
719
e4bbf2f5 720 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
721 "\nMIB INTERRUPTS:\t\t%u\n",
722 st->mib_intr);
e4bbf2f5 723 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d 724 "beacon RSSI average:\t%d\n",
46f26ddf 725 (int)ewma_beacon_rssi_read(&ah->ah_beacon_rssi_avg));
7109ca5c
FF
726
727#define CC_PRINT(_struct, _field) \
728 _struct._field, \
729 _struct.cycles > 0 ? \
e4bbf2f5 730 _struct._field * 100 / _struct.cycles : 0
7109ca5c 731
e4bbf2f5
PR
732 len += snprintf(buf + len, sizeof(buf) - len,
733 "profcnt tx\t\t%u\t(%d%%)\n",
7109ca5c 734 CC_PRINT(as->last_cc, tx_frame));
e4bbf2f5
PR
735 len += snprintf(buf + len, sizeof(buf) - len,
736 "profcnt rx\t\t%u\t(%d%%)\n",
7109ca5c 737 CC_PRINT(as->last_cc, rx_frame));
e4bbf2f5
PR
738 len += snprintf(buf + len, sizeof(buf) - len,
739 "profcnt busy\t\t%u\t(%d%%)\n",
7109ca5c
FF
740 CC_PRINT(as->last_cc, rx_busy));
741#undef CC_PRINT
e4bbf2f5 742 len += snprintf(buf + len, sizeof(buf) - len, "profcnt cycles\t\t%u\n",
7109ca5c 743 as->last_cc.cycles);
e4bbf2f5 744 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
745 "listen time\t\t%d\tlast: %d\n",
746 as->listen_time, as->last_listen);
e4bbf2f5 747 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
748 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
749 as->ofdm_errors, as->last_ofdm_errors,
750 as->sum_ofdm_errors);
e4bbf2f5 751 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d
BR
752 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
753 as->cck_errors, as->last_cck_errors,
754 as->sum_cck_errors);
e4bbf2f5 755 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d 756 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
e0d687bd 757 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1),
2111ac0d 758 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
e0d687bd 759 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1)));
e4bbf2f5 760 len += snprintf(buf + len, sizeof(buf) - len,
2111ac0d 761 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
e0d687bd 762 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2),
2111ac0d 763 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
e0d687bd 764 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2)));
2111ac0d 765
2189d13f
DC
766 if (len > sizeof(buf))
767 len = sizeof(buf);
768
2111ac0d
BR
769 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
770}
771
772static ssize_t write_file_ani(struct file *file,
773 const char __user *userbuf,
774 size_t count, loff_t *ppos)
775{
e0d687bd 776 struct ath5k_hw *ah = file->private_data;
2111ac0d
BR
777 char buf[20];
778
8aada63c
DH
779 count = min_t(size_t, count, sizeof(buf) - 1);
780 if (copy_from_user(buf, userbuf, count))
2111ac0d
BR
781 return -EFAULT;
782
8aada63c 783 buf[count] = '\0';
2111ac0d 784 if (strncmp(buf, "sens-low", 8) == 0) {
e0d687bd 785 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_HIGH);
2111ac0d 786 } else if (strncmp(buf, "sens-high", 9) == 0) {
e0d687bd 787 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_LOW);
2111ac0d 788 } else if (strncmp(buf, "ani-off", 7) == 0) {
e0d687bd 789 ath5k_ani_init(ah, ATH5K_ANI_MODE_OFF);
2111ac0d 790 } else if (strncmp(buf, "ani-on", 6) == 0) {
e0d687bd 791 ath5k_ani_init(ah, ATH5K_ANI_MODE_AUTO);
2111ac0d 792 } else if (strncmp(buf, "noise-low", 9) == 0) {
e0d687bd 793 ath5k_ani_set_noise_immunity_level(ah, 0);
2111ac0d 794 } else if (strncmp(buf, "noise-high", 10) == 0) {
e0d687bd 795 ath5k_ani_set_noise_immunity_level(ah,
2111ac0d
BR
796 ATH5K_ANI_MAX_NOISE_IMM_LVL);
797 } else if (strncmp(buf, "spur-low", 8) == 0) {
e0d687bd 798 ath5k_ani_set_spur_immunity_level(ah, 0);
2111ac0d 799 } else if (strncmp(buf, "spur-high", 9) == 0) {
e0d687bd
PR
800 ath5k_ani_set_spur_immunity_level(ah,
801 ah->ani_state.max_spur_level);
2111ac0d 802 } else if (strncmp(buf, "fir-low", 7) == 0) {
e0d687bd 803 ath5k_ani_set_firstep_level(ah, 0);
2111ac0d 804 } else if (strncmp(buf, "fir-high", 8) == 0) {
e0d687bd 805 ath5k_ani_set_firstep_level(ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
2111ac0d 806 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
e0d687bd 807 ath5k_ani_set_ofdm_weak_signal_detection(ah, false);
2111ac0d 808 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
e0d687bd 809 ath5k_ani_set_ofdm_weak_signal_detection(ah, true);
2111ac0d 810 } else if (strncmp(buf, "cck-off", 7) == 0) {
e0d687bd 811 ath5k_ani_set_cck_weak_signal_detection(ah, false);
2111ac0d 812 } else if (strncmp(buf, "cck-on", 6) == 0) {
e0d687bd 813 ath5k_ani_set_cck_weak_signal_detection(ah, true);
2111ac0d
BR
814 }
815 return count;
816}
817
818static const struct file_operations fops_ani = {
819 .read = read_file_ani,
820 .write = write_file_ani,
234e3405 821 .open = simple_open,
2111ac0d 822 .owner = THIS_MODULE,
6038f373 823 .llseek = default_llseek,
2111ac0d
BR
824};
825
826
3cfd43f4
BR
827/* debugfs: queues etc */
828
829static ssize_t read_file_queue(struct file *file, char __user *user_buf,
830 size_t count, loff_t *ppos)
831{
e0d687bd 832 struct ath5k_hw *ah = file->private_data;
3cfd43f4
BR
833 char buf[700];
834 unsigned int len = 0;
835
836 struct ath5k_txq *txq;
837 struct ath5k_buf *bf, *bf0;
cfddc11c 838 int i, n;
3cfd43f4 839
e4bbf2f5 840 len += snprintf(buf + len, sizeof(buf) - len,
e0d687bd 841 "available txbuffers: %d\n", ah->txbuf_len);
3cfd43f4 842
e0d687bd
PR
843 for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) {
844 txq = &ah->txqs[i];
3cfd43f4 845
e4bbf2f5 846 len += snprintf(buf + len, sizeof(buf) - len,
3cfd43f4
BR
847 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
848
849 if (!txq->setup)
850 continue;
851
cfddc11c
BR
852 n = 0;
853 spin_lock_bh(&txq->lock);
3cfd43f4
BR
854 list_for_each_entry_safe(bf, bf0, &txq->q, list)
855 n++;
cfddc11c
BR
856 spin_unlock_bh(&txq->lock);
857
e4bbf2f5 858 len += snprintf(buf + len, sizeof(buf) - len,
cfddc11c 859 " len: %d bufs: %d\n", txq->txq_len, n);
e4bbf2f5 860 len += snprintf(buf + len, sizeof(buf) - len,
923e5b3d 861 " stuck: %d\n", txq->txq_stuck);
3cfd43f4
BR
862 }
863
2189d13f
DC
864 if (len > sizeof(buf))
865 len = sizeof(buf);
866
3cfd43f4
BR
867 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
868}
869
870static ssize_t write_file_queue(struct file *file,
871 const char __user *userbuf,
872 size_t count, loff_t *ppos)
873{
e0d687bd 874 struct ath5k_hw *ah = file->private_data;
3cfd43f4
BR
875 char buf[20];
876
8aada63c
DH
877 count = min_t(size_t, count, sizeof(buf) - 1);
878 if (copy_from_user(buf, userbuf, count))
3cfd43f4
BR
879 return -EFAULT;
880
8aada63c 881 buf[count] = '\0';
3cfd43f4 882 if (strncmp(buf, "start", 5) == 0)
e0d687bd 883 ieee80211_wake_queues(ah->hw);
3cfd43f4 884 else if (strncmp(buf, "stop", 4) == 0)
e0d687bd 885 ieee80211_stop_queues(ah->hw);
3cfd43f4
BR
886
887 return count;
888}
889
890
891static const struct file_operations fops_queue = {
892 .read = read_file_queue,
893 .write = write_file_queue,
234e3405 894 .open = simple_open,
3cfd43f4 895 .owner = THIS_MODULE,
6038f373 896 .llseek = default_llseek,
3cfd43f4
BR
897};
898
db906eb2
JB
899/* debugfs: eeprom */
900
901struct eeprom_private {
902 u16 *buf;
903 int len;
904};
905
906static int open_file_eeprom(struct inode *inode, struct file *file)
907{
908 struct eeprom_private *ep;
909 struct ath5k_hw *ah = inode->i_private;
910 bool res;
911 int i, ret;
af8a9a67 912 u32 eesize; /* NB: in 16-bit words */
db906eb2
JB
913 u16 val, *buf;
914
915 /* Get eeprom size */
916
917 res = ath5k_hw_nvram_read(ah, AR5K_EEPROM_SIZE_UPPER, &val);
918 if (!res)
919 return -EACCES;
920
921 if (val == 0) {
922 eesize = AR5K_EEPROM_INFO_MAX + AR5K_EEPROM_INFO_BASE;
923 } else {
924 eesize = (val & AR5K_EEPROM_SIZE_UPPER_MASK) <<
925 AR5K_EEPROM_SIZE_ENDLOC_SHIFT;
926 ath5k_hw_nvram_read(ah, AR5K_EEPROM_SIZE_LOWER, &val);
927 eesize = eesize | val;
928 }
929
930 if (eesize > 4096)
931 return -EINVAL;
932
933 /* Create buffer and read in eeprom */
934
af8a9a67 935 buf = vmalloc(eesize * 2);
db906eb2
JB
936 if (!buf) {
937 ret = -ENOMEM;
938 goto err;
939 }
940
941 for (i = 0; i < eesize; ++i) {
942 AR5K_EEPROM_READ(i, val);
943 buf[i] = val;
944 }
945
946 /* Create private struct and assign to file */
947
948 ep = kmalloc(sizeof(*ep), GFP_KERNEL);
949 if (!ep) {
950 ret = -ENOMEM;
951 goto freebuf;
952 }
953
954 ep->buf = buf;
af8a9a67 955 ep->len = eesize * 2;
db906eb2
JB
956
957 file->private_data = (void *)ep;
958
959 return 0;
960
961freebuf:
962 vfree(buf);
963err:
964 return ret;
965
966}
967
968static ssize_t read_file_eeprom(struct file *file, char __user *user_buf,
969 size_t count, loff_t *ppos)
970{
971 struct eeprom_private *ep = file->private_data;
972
973 return simple_read_from_buffer(user_buf, count, ppos, ep->buf, ep->len);
974}
975
976static int release_file_eeprom(struct inode *inode, struct file *file)
977{
978 struct eeprom_private *ep = file->private_data;
979
980 vfree(ep->buf);
981 kfree(ep);
982
983 return 0;
984}
985
986static const struct file_operations fops_eeprom = {
987 .open = open_file_eeprom,
988 .read = read_file_eeprom,
989 .release = release_file_eeprom,
990 .owner = THIS_MODULE,
991};
992
3cfd43f4 993
fa1c114f 994void
e0d687bd 995ath5k_debug_init_device(struct ath5k_hw *ah)
fa1c114f 996{
5b7916ad 997 struct dentry *phydir;
be9b7259 998
e0d687bd 999 ah->debug.level = ath5k_debug;
be9b7259 1000
e0d687bd 1001 phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
5b7916ad 1002 if (!phydir)
e4bbf2f5 1003 return;
fa1c114f 1004
e0d687bd 1005 debugfs_create_file("debug", S_IWUSR | S_IRUSR, phydir, ah,
5b7916ad 1006 &fops_debug);
fa1c114f 1007
e0d687bd 1008 debugfs_create_file("registers", S_IRUSR, phydir, ah, &fops_registers);
fa1c114f 1009
e0d687bd 1010 debugfs_create_file("beacon", S_IWUSR | S_IRUSR, phydir, ah,
5b7916ad 1011 &fops_beacon);
604eeadd 1012
e0d687bd 1013 debugfs_create_file("reset", S_IWUSR, phydir, ah, &fops_reset);
7644395f 1014
e0d687bd 1015 debugfs_create_file("antenna", S_IWUSR | S_IRUSR, phydir, ah,
5b7916ad 1016 &fops_antenna);
87fd2e6c 1017
e0d687bd 1018 debugfs_create_file("misc", S_IRUSR, phydir, ah, &fops_misc);
2111ac0d 1019
db906eb2
JB
1020 debugfs_create_file("eeprom", S_IRUSR, phydir, ah, &fops_eeprom);
1021
e0d687bd 1022 debugfs_create_file("frameerrors", S_IWUSR | S_IRUSR, phydir, ah,
5b7916ad 1023 &fops_frameerrors);
3cfd43f4 1024
e0d687bd 1025 debugfs_create_file("ani", S_IWUSR | S_IRUSR, phydir, ah, &fops_ani);
fa1c114f 1026
e0d687bd 1027 debugfs_create_file("queue", S_IWUSR | S_IRUSR, phydir, ah,
5b7916ad 1028 &fops_queue);
6340211c
FF
1029
1030 debugfs_create_bool("32khz_clock", S_IWUSR | S_IRUSR, phydir,
e0d687bd 1031 &ah->ah_use_32khz_clock);
fa1c114f
JS
1032}
1033
fa1c114f
JS
1034/* functions used in other places */
1035
1036void
e0d687bd 1037ath5k_debug_dump_bands(struct ath5k_hw *ah)
fa1c114f 1038{
b446197c 1039 unsigned int b, i;
fa1c114f 1040
e0d687bd 1041 if (likely(!(ah->debug.level & ATH5K_DEBUG_DUMPBANDS)))
fa1c114f
JS
1042 return;
1043
e0d687bd 1044 BUG_ON(!ah->sbands);
b446197c 1045
57fbcce3 1046 for (b = 0; b < NUM_NL80211_BANDS; b++) {
e0d687bd 1047 struct ieee80211_supported_band *band = &ah->sbands[b];
b7fcb5c4 1048 char bname[6];
b446197c 1049 switch (band->band) {
57fbcce3 1050 case NL80211_BAND_2GHZ:
b446197c
LR
1051 strcpy(bname, "2 GHz");
1052 break;
57fbcce3 1053 case NL80211_BAND_5GHZ:
b446197c
LR
1054 strcpy(bname, "5 GHz");
1055 break;
1056 default:
1057 printk(KERN_DEBUG "Band not supported: %d\n",
1058 band->band);
1059 return;
1060 }
1061 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
1062 band->n_channels, band->n_bitrates);
fa1c114f 1063 printk(KERN_DEBUG " channels:\n");
b446197c 1064 for (i = 0; i < band->n_channels; i++)
fa1c114f 1065 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
b446197c
LR
1066 ieee80211_frequency_to_channel(
1067 band->channels[i].center_freq),
1068 band->channels[i].center_freq,
1069 band->channels[i].hw_value,
1070 band->channels[i].flags);
fa1c114f 1071 printk(KERN_DEBUG " rates:\n");
b446197c 1072 for (i = 0; i < band->n_bitrates; i++)
fa1c114f 1073 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
b446197c
LR
1074 band->bitrates[i].bitrate,
1075 band->bitrates[i].hw_value,
1076 band->bitrates[i].flags,
1077 band->bitrates[i].hw_value_short);
fa1c114f
JS
1078 }
1079}
1080
1081static inline void
b47f407b
BR
1082ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
1083 struct ath5k_rx_status *rs)
fa1c114f
JS
1084{
1085 struct ath5k_desc *ds = bf->desc;
19fd6e55 1086 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
fa1c114f
JS
1087
1088 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
1089 ds, (unsigned long long)bf->daddr,
19fd6e55
BR
1090 ds->ds_link, ds->ds_data,
1091 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
62412a8f 1092 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
b47f407b 1093 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
fa1c114f
JS
1094}
1095
1096void
e0d687bd 1097ath5k_debug_printrxbuffs(struct ath5k_hw *ah)
fa1c114f
JS
1098{
1099 struct ath5k_desc *ds;
1100 struct ath5k_buf *bf;
b47f407b 1101 struct ath5k_rx_status rs = {};
fa1c114f
JS
1102 int status;
1103
e0d687bd 1104 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC)))
fa1c114f
JS
1105 return;
1106
265faadd 1107 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
e0d687bd 1108 ath5k_hw_get_rxdp(ah), ah->rxlink);
fa1c114f 1109
e0d687bd
PR
1110 spin_lock_bh(&ah->rxbuflock);
1111 list_for_each_entry(bf, &ah->rxbuf, list) {
fa1c114f 1112 ds = bf->desc;
b47f407b 1113 status = ah->ah_proc_rx_desc(ah, ds, &rs);
be9b7259 1114 if (!status)
b47f407b 1115 ath5k_debug_printrxbuf(bf, status == 0, &rs);
fa1c114f 1116 }
e0d687bd 1117 spin_unlock_bh(&ah->rxbuflock);
fa1c114f
JS
1118}
1119
fa1c114f 1120void
e0d687bd 1121ath5k_debug_printtxbuf(struct ath5k_hw *ah, struct ath5k_buf *bf)
fa1c114f
JS
1122{
1123 struct ath5k_desc *ds = bf->desc;
19fd6e55 1124 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
b47f407b
BR
1125 struct ath5k_tx_status ts = {};
1126 int done;
fa1c114f 1127
e0d687bd 1128 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC)))
fa1c114f
JS
1129 return;
1130
e0d687bd 1131 done = ah->ah_proc_tx_desc(ah, bf->desc, &ts);
b47f407b 1132
fa1c114f
JS
1133 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1134 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
19fd6e55
BR
1135 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
1136 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
1137 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
b47f407b 1138 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
fa1c114f 1139}
This page took 0.960901 seconds and 5 git commands to generate.