blob: 929d7ccc031c2197d55d172f8a633c18425df35e [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 */
Joe Perches516304b2012-03-18 17:30:52 -070060
61#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
62
Paul Gortmakeree40fa02011-05-27 16:14:23 -040063#include <linux/export.h>
Paul Gortmaker6eb07ca2011-09-15 19:46:05 -040064#include <linux/moduleparam.h>
Stephen Rothwell32bc6d12014-09-09 16:37:11 -070065#include <linux/vmalloc.h>
Jiri Slabyfa1c1142007-08-12 17:33:16 +020066
Pavel Roskin931be262011-07-26 22:26:59 -040067#include <linux/seq_file.h>
68#include <linux/list.h>
Felix Fietkau005eff52014-09-27 18:05:47 +020069#include <linux/vmalloc.h>
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030070#include "debug.h"
Pavel Roskin931be262011-07-26 22:26:59 -040071#include "ath5k.h"
72#include "reg.h"
73#include "base.h"
Jiri Slabyfa1c1142007-08-12 17:33:16 +020074
75static unsigned int ath5k_debug;
76module_param_named(debug, ath5k_debug, uint, 0);
77
78
Jiri Slabyfa1c1142007-08-12 17:33:16 +020079/* debugfs: registers */
80
81struct reg {
Jiri Slaby2c91108c2009-03-07 10:26:41 +010082 const char *name;
Jiri Slabyfa1c1142007-08-12 17:33:16 +020083 int addr;
84};
85
86#define REG_STRUCT_INIT(r) { #r, r }
87
88/* just a few random registers, might want to add more */
Jiri Slaby2c91108c2009-03-07 10:26:41 +010089static const struct reg regs[] = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +020090 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),
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300129 REG_STRUCT_INIT(AR5K_CPCOVF),
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200130 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{
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100142 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200143}
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;
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100153 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200154}
155
156static int reg_show(struct seq_file *seq, void *p)
157{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400158 struct ath5k_hw *ah = seq->private;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200159 struct reg *r = p;
160 seq_printf(seq, "%-25s0x%08x\n", r->name,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400161 ath5k_hw_reg_read(ah, r->addr));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200162 return 0;
163}
164
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800165static const struct seq_operations register_seq_ops = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200166 .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
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200193/* debugfs: beacons */
194
195static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
196 size_t count, loff_t *ppos)
197{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400198 struct ath5k_hw *ah = file->private_data;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900199 char buf[500];
200 unsigned int len = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200201 unsigned int v;
202 u64 tsf;
203
Pavel Roskine0d687b2011-07-14 20:21:55 -0400204 v = ath5k_hw_reg_read(ah, AR5K_BEACON);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400205 len += snprintf(buf + len, sizeof(buf) - len,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200206 "%-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
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400210 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400211 "AR5K_LAST_TSTP", ath5k_hw_reg_read(ah, AR5K_LAST_TSTP));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200212
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400213 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400214 "AR5K_BEACON_CNT", ath5k_hw_reg_read(ah, AR5K_BEACON_CNT));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200215
Pavel Roskine0d687b2011-07-14 20:21:55 -0400216 v = ath5k_hw_reg_read(ah, AR5K_TIMER0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400217 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200218 "AR5K_TIMER0 (TBTT)", v, v);
219
Pavel Roskine0d687b2011-07-14 20:21:55 -0400220 v = ath5k_hw_reg_read(ah, AR5K_TIMER1);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400221 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200222 "AR5K_TIMER1 (DMA)", v, v >> 3);
223
Pavel Roskine0d687b2011-07-14 20:21:55 -0400224 v = ath5k_hw_reg_read(ah, AR5K_TIMER2);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400225 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200226 "AR5K_TIMER2 (SWBA)", v, v >> 3);
227
Pavel Roskine0d687b2011-07-14 20:21:55 -0400228 v = ath5k_hw_reg_read(ah, AR5K_TIMER3);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400229 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200230 "AR5K_TIMER3 (ATIM)", v, v);
231
Pavel Roskine0d687b2011-07-14 20:21:55 -0400232 tsf = ath5k_hw_get_tsf64(ah);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400233 len += snprintf(buf + len, sizeof(buf) - len,
John W. Linvillef868f4e2008-03-07 16:38:43 -0500234 "TSF\t\t0x%016llx\tTU: %08x\n",
235 (unsigned long long)tsf, TSF_TO_TU(tsf));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200236
Dan Carpenter2189d132010-07-22 10:52:02 +0200237 if (len > sizeof(buf))
238 len = sizeof(buf);
239
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200240 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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400247 struct ath5k_hw *ah = file->private_data;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900248 char buf[20];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200249
Djalal Harouni8aada632013-08-25 11:50:49 +0100250 count = min_t(size_t, count, sizeof(buf) - 1);
251 if (copy_from_user(buf, userbuf, count))
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900252 return -EFAULT;
253
Djalal Harouni8aada632013-08-25 11:50:49 +0100254 buf[count] = '\0';
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900255 if (strncmp(buf, "disable", 7) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200256 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
Joe Perches516304b2012-03-18 17:30:52 -0700257 pr_info("debugfs disable beacons\n");
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900258 } else if (strncmp(buf, "enable", 6) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200259 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
Joe Perches516304b2012-03-18 17:30:52 -0700260 pr_info("debugfs enable beacons\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200261 }
262 return count;
263}
264
265static const struct file_operations fops_beacon = {
266 .read = read_file_beacon,
267 .write = write_file_beacon,
Stephen Boyd234e3402012-04-05 14:25:11 -0700268 .open = simple_open,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200269 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200270 .llseek = default_llseek,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200271};
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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400280 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);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200283 return count;
284}
285
286static const struct file_operations fops_reset = {
287 .write = write_file_reset,
Stephen Boyd234e3402012-04-05 14:25:11 -0700288 .open = simple_open,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200289 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200290 .llseek = noop_llseek,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200291};
292
293
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900294/* debugfs: debug level */
295
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100296static const struct {
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900297 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" },
Bob Copeland85519a62008-10-29 08:30:53 -0400308 { ATH5K_DEBUG_LED, "led", "LED management" },
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500309 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
Nick Kossifidisb3a28e62010-11-23 20:47:31 +0200310 { ATH5K_DEBUG_DMA, "dma", "dma start/stop" },
Bruno Randolf2111ac02010-04-02 18:44:08 +0900311 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
Bob Copelandb4c52612010-08-21 16:39:03 -0400312 { ATH5K_DEBUG_DESC, "desc", "descriptor chains" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900313 { 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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400319 struct ath5k_hw *ah = file->private_data;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900320 char buf[700];
321 unsigned int len = 0;
322 unsigned int i;
323
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400324 len += snprintf(buf + len, sizeof(buf) - len,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400325 "DEBUG LEVEL: 0x%08x\n\n", ah->debug.level);
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900326
327 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400328 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900329 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400330 ah->debug.level & dbg_info[i].level ? '+' : ' ',
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900331 dbg_info[i].level, dbg_info[i].desc);
332 }
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400333 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900334 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400335 ah->debug.level == dbg_info[i].level ? '+' : ' ',
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900336 dbg_info[i].level, dbg_info[i].desc);
337
Dan Carpenter2189d132010-07-22 10:52:02 +0200338 if (len > sizeof(buf))
339 len = sizeof(buf);
340
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900341 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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400348 struct ath5k_hw *ah = file->private_data;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900349 unsigned int i;
350 char buf[20];
351
Djalal Harouni8aada632013-08-25 11:50:49 +0100352 count = min_t(size_t, count, sizeof(buf) - 1);
353 if (copy_from_user(buf, userbuf, count))
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900354 return -EFAULT;
355
Djalal Harouni8aada632013-08-25 11:50:49 +0100356 buf[count] = '\0';
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900357 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
358 if (strncmp(buf, dbg_info[i].name,
359 strlen(dbg_info[i].name)) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400360 ah->debug.level ^= dbg_info[i].level; /* toggle bit */
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900361 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,
Stephen Boyd234e3402012-04-05 14:25:11 -0700370 .open = simple_open,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900371 .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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400381 struct ath5k_hw *ah = file->private_data;
Bruno Randolf604eead2010-03-09 16:55:17 +0900382 char buf[700];
383 unsigned int len = 0;
384 unsigned int i;
385 unsigned int v;
386
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400387 len += snprintf(buf + len, sizeof(buf) - len, "antenna mode\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400388 ah->ah_ant_mode);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400389 len += snprintf(buf + len, sizeof(buf) - len, "default antenna\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400390 ah->ah_def_ant);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400391 len += snprintf(buf + len, sizeof(buf) - len, "tx antenna\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400392 ah->ah_tx_ant);
Bruno Randolf604eead2010-03-09 16:55:17 +0900393
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400394 len += snprintf(buf + len, sizeof(buf) - len, "\nANTENNA\t\tRX\tTX\n");
Pavel Roskine0d687b2011-07-14 20:21:55 -0400395 for (i = 1; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) {
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400396 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900397 "[antenna %d]\t%d\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400398 i, ah->stats.antenna_rx[i], ah->stats.antenna_tx[i]);
Bruno Randolf604eead2010-03-09 16:55:17 +0900399 }
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400400 len += snprintf(buf + len, sizeof(buf) - len, "[invalid]\t%d\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400401 ah->stats.antenna_rx[0], ah->stats.antenna_tx[0]);
Bruno Randolf604eead2010-03-09 16:55:17 +0900402
Pavel Roskine0d687b2011-07-14 20:21:55 -0400403 v = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400404 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900405 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
406
Pavel Roskine0d687b2011-07-14 20:21:55 -0400407 v = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400408 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900409 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
410 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400411 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900412 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
413 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400414 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900415 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
416 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400417 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900418 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
419 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
420
Pavel Roskine0d687b2011-07-14 20:21:55 -0400421 v = ath5k_hw_reg_read(ah, AR5K_PHY_AGCCTL);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400422 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900423 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
424 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
425
Pavel Roskine0d687b2011-07-14 20:21:55 -0400426 v = ath5k_hw_reg_read(ah, AR5K_PHY_RESTART);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400427 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900428 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
429 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
430
Pavel Roskine0d687b2011-07-14 20:21:55 -0400431 v = ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ANT_DIV);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400432 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900433 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
434 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
435
Pavel Roskine0d687b2011-07-14 20:21:55 -0400436 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400437 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf0ca74022010-06-07 13:11:30 +0900438 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
Pavel Roskine0d687b2011-07-14 20:21:55 -0400439 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400440 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf0ca74022010-06-07 13:11:30 +0900441 "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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400453 struct ath5k_hw *ah = file->private_data;
Bruno Randolf604eead2010-03-09 16:55:17 +0900454 unsigned int i;
455 char buf[20];
456
Djalal Harouni8aada632013-08-25 11:50:49 +0100457 count = min_t(size_t, count, sizeof(buf) - 1);
458 if (copy_from_user(buf, userbuf, count))
Bruno Randolf604eead2010-03-09 16:55:17 +0900459 return -EFAULT;
460
Djalal Harouni8aada632013-08-25 11:50:49 +0100461 buf[count] = '\0';
Bruno Randolf604eead2010-03-09 16:55:17 +0900462 if (strncmp(buf, "diversity", 9) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400463 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
Joe Perches516304b2012-03-18 17:30:52 -0700464 pr_info("debug: enable diversity\n");
Bruno Randolf604eead2010-03-09 16:55:17 +0900465 } else if (strncmp(buf, "fixed-a", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400466 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
Joe Perches516304b2012-03-18 17:30:52 -0700467 pr_info("debug: fixed antenna A\n");
Bruno Randolf604eead2010-03-09 16:55:17 +0900468 } else if (strncmp(buf, "fixed-b", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400469 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
Joe Perches516304b2012-03-18 17:30:52 -0700470 pr_info("debug: fixed antenna B\n");
Bruno Randolf604eead2010-03-09 16:55:17 +0900471 } else if (strncmp(buf, "clear", 5) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400472 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;
Bruno Randolf604eead2010-03-09 16:55:17 +0900475 }
Joe Perches516304b2012-03-18 17:30:52 -0700476 pr_info("debug: cleared antenna stats\n");
Bruno Randolf604eead2010-03-09 16:55:17 +0900477 }
478 return count;
479}
480
481static const struct file_operations fops_antenna = {
482 .read = read_file_antenna,
483 .write = write_file_antenna,
Stephen Boyd234e3402012-04-05 14:25:11 -0700484 .open = simple_open,
Bruno Randolf604eead2010-03-09 16:55:17 +0900485 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200486 .llseek = default_llseek,
Bruno Randolf604eead2010-03-09 16:55:17 +0900487};
488
Ben Greear87fd2e62010-09-21 17:03:57 -0700489/* debugfs: misc */
490
491static ssize_t read_file_misc(struct file *file, char __user *user_buf,
492 size_t count, loff_t *ppos)
493{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400494 struct ath5k_hw *ah = file->private_data;
Ben Greear87fd2e62010-09-21 17:03:57 -0700495 char buf[700];
496 unsigned int len = 0;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400497 u32 filt = ath5k_hw_get_rx_filter(ah);
Ben Greear87fd2e62010-09-21 17:03:57 -0700498
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400499 len += snprintf(buf + len, sizeof(buf) - len, "bssid-mask: %pM\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400500 ah->bssidmask);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400501 len += snprintf(buf + len, sizeof(buf) - len, "filter-flags: 0x%x ",
Ben Greear87fd2e62010-09-21 17:03:57 -0700502 filt);
503 if (filt & AR5K_RX_FILTER_UCAST)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400504 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
Ben Greear87fd2e62010-09-21 17:03:57 -0700505 if (filt & AR5K_RX_FILTER_MCAST)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400506 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
Ben Greear87fd2e62010-09-21 17:03:57 -0700507 if (filt & AR5K_RX_FILTER_BCAST)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400508 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
Ben Greear87fd2e62010-09-21 17:03:57 -0700509 if (filt & AR5K_RX_FILTER_CONTROL)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400510 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
Ben Greear87fd2e62010-09-21 17:03:57 -0700511 if (filt & AR5K_RX_FILTER_BEACON)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400512 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
Ben Greear87fd2e62010-09-21 17:03:57 -0700513 if (filt & AR5K_RX_FILTER_PROM)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400514 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
Ben Greear87fd2e62010-09-21 17:03:57 -0700515 if (filt & AR5K_RX_FILTER_XRPOLL)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400516 len += snprintf(buf + len, sizeof(buf) - len, " XRPOLL");
Ben Greear87fd2e62010-09-21 17:03:57 -0700517 if (filt & AR5K_RX_FILTER_PROBEREQ)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400518 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
Ben Greear87fd2e62010-09-21 17:03:57 -0700519 if (filt & AR5K_RX_FILTER_PHYERR_5212)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400520 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR-5212");
Ben Greear87fd2e62010-09-21 17:03:57 -0700521 if (filt & AR5K_RX_FILTER_RADARERR_5212)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400522 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5212");
Ben Greear87fd2e62010-09-21 17:03:57 -0700523 if (filt & AR5K_RX_FILTER_PHYERR_5211)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400524 snprintf(buf + len, sizeof(buf) - len, " PHYERR-5211");
Ben Greear87fd2e62010-09-21 17:03:57 -0700525 if (filt & AR5K_RX_FILTER_RADARERR_5211)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400526 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5211");
Ben Greear87fd2e62010-09-21 17:03:57 -0700527
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400528 len += snprintf(buf + len, sizeof(buf) - len, "\nopmode: %s (%d)\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400529 ath_opmode_to_string(ah->opmode), ah->opmode);
Ben Greear92c68a62010-10-08 09:43:29 -0700530
Ben Greear87fd2e62010-09-21 17:03:57 -0700531 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,
Stephen Boyd234e3402012-04-05 14:25:11 -0700539 .open = simple_open,
Ben Greear87fd2e62010-09-21 17:03:57 -0700540 .owner = THIS_MODULE,
541};
542
Bruno Randolf604eead2010-03-09 16:55:17 +0900543
Bruno Randolf76443952010-03-09 16:56:00 +0900544/* debugfs: frameerrors */
545
546static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
547 size_t count, loff_t *ppos)
548{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400549 struct ath5k_hw *ah = file->private_data;
550 struct ath5k_statistics *st = &ah->stats;
Bruno Randolf76443952010-03-09 16:56:00 +0900551 char buf[700];
552 unsigned int len = 0;
Bruno Randolfda351112010-03-25 14:49:42 +0900553 int i;
Bruno Randolf76443952010-03-09 16:56:00 +0900554
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400555 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf76443952010-03-09 16:56:00 +0900556 "RX\n---------------------\n");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400557 len += snprintf(buf + len, sizeof(buf) - len, "CRC\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900558 st->rxerr_crc,
559 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400560 st->rxerr_crc * 100 / st->rx_all_count : 0);
561 len += snprintf(buf + len, sizeof(buf) - len, "PHY\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900562 st->rxerr_phy,
563 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400564 st->rxerr_phy * 100 / st->rx_all_count : 0);
Bruno Randolfda351112010-03-25 14:49:42 +0900565 for (i = 0; i < 32; i++) {
566 if (st->rxerr_phy_code[i])
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400567 len += snprintf(buf + len, sizeof(buf) - len,
Ben Greear5d882c92010-11-08 10:50:03 -0800568 " phy_err[%u]\t%u\n",
Bruno Randolfda351112010-03-25 14:49:42 +0900569 i, st->rxerr_phy_code[i]);
570 }
571
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400572 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900573 st->rxerr_fifo,
574 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400575 st->rxerr_fifo * 100 / st->rx_all_count : 0);
576 len += snprintf(buf + len, sizeof(buf) - len, "decrypt\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900577 st->rxerr_decrypt,
578 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400579 st->rxerr_decrypt * 100 / st->rx_all_count : 0);
580 len += snprintf(buf + len, sizeof(buf) - len, "MIC\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900581 st->rxerr_mic,
582 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400583 st->rxerr_mic * 100 / st->rx_all_count : 0);
584 len += snprintf(buf + len, sizeof(buf) - len, "process\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900585 st->rxerr_proc,
586 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400587 st->rxerr_proc * 100 / st->rx_all_count : 0);
588 len += snprintf(buf + len, sizeof(buf) - len, "jumbo\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900589 st->rxerr_jumbo,
590 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400591 st->rxerr_jumbo * 100 / st->rx_all_count : 0);
592 len += snprintf(buf + len, sizeof(buf) - len, "[RX all\t%u]\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900593 st->rx_all_count);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400594 len += snprintf(buf + len, sizeof(buf) - len, "RX-all-bytes\t%u\n",
Ben Greearb72acdd2010-10-01 10:54:04 -0700595 st->rx_bytes_count);
Bruno Randolf76443952010-03-09 16:56:00 +0900596
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400597 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf76443952010-03-09 16:56:00 +0900598 "\nTX\n---------------------\n");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400599 len += snprintf(buf + len, sizeof(buf) - len, "retry\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900600 st->txerr_retry,
601 st->tx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400602 st->txerr_retry * 100 / st->tx_all_count : 0);
603 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900604 st->txerr_fifo,
605 st->tx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400606 st->txerr_fifo * 100 / st->tx_all_count : 0);
607 len += snprintf(buf + len, sizeof(buf) - len, "filter\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900608 st->txerr_filt,
609 st->tx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400610 st->txerr_filt * 100 / st->tx_all_count : 0);
611 len += snprintf(buf + len, sizeof(buf) - len, "[TX all\t%u]\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900612 st->tx_all_count);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400613 len += snprintf(buf + len, sizeof(buf) - len, "TX-all-bytes\t%u\n",
Ben Greearb72acdd2010-10-01 10:54:04 -0700614 st->tx_bytes_count);
Bruno Randolf76443952010-03-09 16:56:00 +0900615
Dan Carpenter2189d132010-07-22 10:52:02 +0200616 if (len > sizeof(buf))
617 len = sizeof(buf);
618
Bruno Randolf76443952010-03-09 16:56:00 +0900619 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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400626 struct ath5k_hw *ah = file->private_data;
627 struct ath5k_statistics *st = &ah->stats;
Bruno Randolf76443952010-03-09 16:56:00 +0900628 char buf[20];
629
Djalal Harouni8aada632013-08-25 11:50:49 +0100630 count = min_t(size_t, count, sizeof(buf) - 1);
631 if (copy_from_user(buf, userbuf, count))
Bruno Randolf76443952010-03-09 16:56:00 +0900632 return -EFAULT;
633
Djalal Harouni8aada632013-08-25 11:50:49 +0100634 buf[count] = '\0';
Bruno Randolf76443952010-03-09 16:56:00 +0900635 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;
Joe Perches516304b2012-03-18 17:30:52 -0700648 pr_info("debug: cleared frameerrors stats\n");
Bruno Randolf76443952010-03-09 16:56:00 +0900649 }
650 return count;
651}
652
653static const struct file_operations fops_frameerrors = {
654 .read = read_file_frameerrors,
655 .write = write_file_frameerrors,
Stephen Boyd234e3402012-04-05 14:25:11 -0700656 .open = simple_open,
Bruno Randolf76443952010-03-09 16:56:00 +0900657 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200658 .llseek = default_llseek,
Bruno Randolf76443952010-03-09 16:56:00 +0900659};
660
661
Bruno Randolf2111ac02010-04-02 18:44:08 +0900662/* debugfs: ani */
663
664static ssize_t read_file_ani(struct file *file, char __user *user_buf,
665 size_t count, loff_t *ppos)
666{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400667 struct ath5k_hw *ah = file->private_data;
668 struct ath5k_statistics *st = &ah->stats;
669 struct ath5k_ani_state *as = &ah->ani_state;
Bruno Randolf2111ac02010-04-02 18:44:08 +0900670
671 char buf[700];
672 unsigned int len = 0;
673
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400674 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900675 "HW has PHY error counters:\t%s\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400676 ah->ah_capabilities.cap_has_phyerr_counters ?
Bruno Randolf2111ac02010-04-02 18:44:08 +0900677 "yes" : "no");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400678 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900679 "HW max spur immunity level:\t%d\n",
680 as->max_spur_level);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400681 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900682 "\nANI state\n--------------------------------------------\n");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400683 len += snprintf(buf + len, sizeof(buf) - len, "operating mode:\t\t\t");
Bruno Randolf2111ac02010-04-02 18:44:08 +0900684 switch (as->ani_mode) {
685 case ATH5K_ANI_MODE_OFF:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400686 len += snprintf(buf + len, sizeof(buf) - len, "OFF\n");
Bruno Randolf2111ac02010-04-02 18:44:08 +0900687 break;
688 case ATH5K_ANI_MODE_MANUAL_LOW:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400689 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900690 "MANUAL LOW\n");
691 break;
692 case ATH5K_ANI_MODE_MANUAL_HIGH:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400693 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900694 "MANUAL HIGH\n");
695 break;
696 case ATH5K_ANI_MODE_AUTO:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400697 len += snprintf(buf + len, sizeof(buf) - len, "AUTO\n");
Bruno Randolf2111ac02010-04-02 18:44:08 +0900698 break;
699 default:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400700 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900701 "??? (not good)\n");
702 break;
703 }
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400704 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900705 "noise immunity level:\t\t%d\n",
706 as->noise_imm_level);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400707 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900708 "spur immunity level:\t\t%d\n",
709 as->spur_level);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400710 len += snprintf(buf + len, sizeof(buf) - len,
711 "firstep level:\t\t\t%d\n",
Bruno Randolf2111ac02010-04-02 18:44:08 +0900712 as->firstep_level);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400713 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900714 "OFDM weak signal detection:\t%s\n",
715 as->ofdm_weak_sig ? "on" : "off");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400716 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900717 "CCK weak signal detection:\t%s\n",
718 as->cck_weak_sig ? "on" : "off");
719
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400720 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900721 "\nMIB INTERRUPTS:\t\t%u\n",
722 st->mib_intr);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400723 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900724 "beacon RSSI average:\t%d\n",
Johannes Berg46f26dd2015-08-19 09:46:20 +0200725 (int)ewma_beacon_rssi_read(&ah->ah_beacon_rssi_avg));
Felix Fietkau7109ca52010-10-08 22:13:54 +0200726
727#define CC_PRINT(_struct, _field) \
728 _struct._field, \
729 _struct.cycles > 0 ? \
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400730 _struct._field * 100 / _struct.cycles : 0
Felix Fietkau7109ca52010-10-08 22:13:54 +0200731
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400732 len += snprintf(buf + len, sizeof(buf) - len,
733 "profcnt tx\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200734 CC_PRINT(as->last_cc, tx_frame));
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400735 len += snprintf(buf + len, sizeof(buf) - len,
736 "profcnt rx\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200737 CC_PRINT(as->last_cc, rx_frame));
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400738 len += snprintf(buf + len, sizeof(buf) - len,
739 "profcnt busy\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200740 CC_PRINT(as->last_cc, rx_busy));
741#undef CC_PRINT
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400742 len += snprintf(buf + len, sizeof(buf) - len, "profcnt cycles\t\t%u\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200743 as->last_cc.cycles);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400744 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900745 "listen time\t\t%d\tlast: %d\n",
746 as->listen_time, as->last_listen);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400747 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900748 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
749 as->ofdm_errors, as->last_ofdm_errors,
750 as->sum_ofdm_errors);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400751 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900752 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
753 as->cck_errors, as->last_cck_errors,
754 as->sum_cck_errors);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400755 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900756 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400757 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1),
Bruno Randolf2111ac02010-04-02 18:44:08 +0900758 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
Pavel Roskine0d687b2011-07-14 20:21:55 -0400759 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1)));
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400760 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900761 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400762 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2),
Bruno Randolf2111ac02010-04-02 18:44:08 +0900763 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
Pavel Roskine0d687b2011-07-14 20:21:55 -0400764 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2)));
Bruno Randolf2111ac02010-04-02 18:44:08 +0900765
Dan Carpenter2189d132010-07-22 10:52:02 +0200766 if (len > sizeof(buf))
767 len = sizeof(buf);
768
Bruno Randolf2111ac02010-04-02 18:44:08 +0900769 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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400776 struct ath5k_hw *ah = file->private_data;
Bruno Randolf2111ac02010-04-02 18:44:08 +0900777 char buf[20];
778
Djalal Harouni8aada632013-08-25 11:50:49 +0100779 count = min_t(size_t, count, sizeof(buf) - 1);
780 if (copy_from_user(buf, userbuf, count))
Bruno Randolf2111ac02010-04-02 18:44:08 +0900781 return -EFAULT;
782
Djalal Harouni8aada632013-08-25 11:50:49 +0100783 buf[count] = '\0';
Bruno Randolf2111ac02010-04-02 18:44:08 +0900784 if (strncmp(buf, "sens-low", 8) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400785 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_HIGH);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900786 } else if (strncmp(buf, "sens-high", 9) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400787 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_LOW);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900788 } else if (strncmp(buf, "ani-off", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400789 ath5k_ani_init(ah, ATH5K_ANI_MODE_OFF);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900790 } else if (strncmp(buf, "ani-on", 6) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400791 ath5k_ani_init(ah, ATH5K_ANI_MODE_AUTO);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900792 } else if (strncmp(buf, "noise-low", 9) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400793 ath5k_ani_set_noise_immunity_level(ah, 0);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900794 } else if (strncmp(buf, "noise-high", 10) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400795 ath5k_ani_set_noise_immunity_level(ah,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900796 ATH5K_ANI_MAX_NOISE_IMM_LVL);
797 } else if (strncmp(buf, "spur-low", 8) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400798 ath5k_ani_set_spur_immunity_level(ah, 0);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900799 } else if (strncmp(buf, "spur-high", 9) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400800 ath5k_ani_set_spur_immunity_level(ah,
801 ah->ani_state.max_spur_level);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900802 } else if (strncmp(buf, "fir-low", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400803 ath5k_ani_set_firstep_level(ah, 0);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900804 } else if (strncmp(buf, "fir-high", 8) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400805 ath5k_ani_set_firstep_level(ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900806 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400807 ath5k_ani_set_ofdm_weak_signal_detection(ah, false);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900808 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400809 ath5k_ani_set_ofdm_weak_signal_detection(ah, true);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900810 } else if (strncmp(buf, "cck-off", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400811 ath5k_ani_set_cck_weak_signal_detection(ah, false);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900812 } else if (strncmp(buf, "cck-on", 6) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400813 ath5k_ani_set_cck_weak_signal_detection(ah, true);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900814 }
815 return count;
816}
817
818static const struct file_operations fops_ani = {
819 .read = read_file_ani,
820 .write = write_file_ani,
Stephen Boyd234e3402012-04-05 14:25:11 -0700821 .open = simple_open,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900822 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200823 .llseek = default_llseek,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900824};
825
826
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900827/* 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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400832 struct ath5k_hw *ah = file->private_data;
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900833 char buf[700];
834 unsigned int len = 0;
835
836 struct ath5k_txq *txq;
837 struct ath5k_buf *bf, *bf0;
Bruno Randolfcfddc112010-09-17 11:36:40 +0900838 int i, n;
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900839
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400840 len += snprintf(buf + len, sizeof(buf) - len,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400841 "available txbuffers: %d\n", ah->txbuf_len);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900842
Pavel Roskine0d687b2011-07-14 20:21:55 -0400843 for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) {
844 txq = &ah->txqs[i];
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900845
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400846 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900847 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
848
849 if (!txq->setup)
850 continue;
851
Bruno Randolfcfddc112010-09-17 11:36:40 +0900852 n = 0;
853 spin_lock_bh(&txq->lock);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900854 list_for_each_entry_safe(bf, bf0, &txq->q, list)
855 n++;
Bruno Randolfcfddc112010-09-17 11:36:40 +0900856 spin_unlock_bh(&txq->lock);
857
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400858 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolfcfddc112010-09-17 11:36:40 +0900859 " len: %d bufs: %d\n", txq->txq_len, n);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400860 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf923e5b32010-09-17 11:37:02 +0900861 " stuck: %d\n", txq->txq_stuck);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900862 }
863
Dan Carpenter2189d132010-07-22 10:52:02 +0200864 if (len > sizeof(buf))
865 len = sizeof(buf);
866
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900867 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{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400874 struct ath5k_hw *ah = file->private_data;
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900875 char buf[20];
876
Djalal Harouni8aada632013-08-25 11:50:49 +0100877 count = min_t(size_t, count, sizeof(buf) - 1);
878 if (copy_from_user(buf, userbuf, count))
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900879 return -EFAULT;
880
Djalal Harouni8aada632013-08-25 11:50:49 +0100881 buf[count] = '\0';
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900882 if (strncmp(buf, "start", 5) == 0)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400883 ieee80211_wake_queues(ah->hw);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900884 else if (strncmp(buf, "stop", 4) == 0)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400885 ieee80211_stop_queues(ah->hw);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900886
887 return count;
888}
889
890
891static const struct file_operations fops_queue = {
892 .read = read_file_queue,
893 .write = write_file_queue,
Stephen Boyd234e3402012-04-05 14:25:11 -0700894 .open = simple_open,
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900895 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200896 .llseek = default_llseek,
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900897};
898
Jade Bilkeydb906eb2014-08-30 15:14:14 -0400899/* 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;
912 u32 eesize;
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
935 buf = vmalloc(eesize);
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;
955 ep->len = i;
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
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900993
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200994void
Pavel Roskine0d687b2011-07-14 20:21:55 -0400995ath5k_debug_init_device(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200996{
Felix Fietkau5b7916a2011-04-10 18:32:18 +0200997 struct dentry *phydir;
998
Pavel Roskine0d687b2011-07-14 20:21:55 -0400999 ah->debug.level = ath5k_debug;
Bruno Randolfbe9b7252008-01-23 10:27:51 +09001000
Pavel Roskine0d687b2011-07-14 20:21:55 -04001001 phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
Felix Fietkau5b7916a2011-04-10 18:32:18 +02001002 if (!phydir)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -04001003 return;
Bruno Randolfbe9b7252008-01-23 10:27:51 +09001004
Pavel Roskine0d687b2011-07-14 20:21:55 -04001005 debugfs_create_file("debug", S_IWUSR | S_IRUSR, phydir, ah,
Felix Fietkau5b7916a2011-04-10 18:32:18 +02001006 &fops_debug);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001007
Pavel Roskine0d687b2011-07-14 20:21:55 -04001008 debugfs_create_file("registers", S_IRUSR, phydir, ah, &fops_registers);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001009
Pavel Roskine0d687b2011-07-14 20:21:55 -04001010 debugfs_create_file("beacon", S_IWUSR | S_IRUSR, phydir, ah,
Felix Fietkau5b7916a2011-04-10 18:32:18 +02001011 &fops_beacon);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001012
Pavel Roskine0d687b2011-07-14 20:21:55 -04001013 debugfs_create_file("reset", S_IWUSR, phydir, ah, &fops_reset);
Bruno Randolf604eead2010-03-09 16:55:17 +09001014
Pavel Roskine0d687b2011-07-14 20:21:55 -04001015 debugfs_create_file("antenna", S_IWUSR | S_IRUSR, phydir, ah,
Felix Fietkau5b7916a2011-04-10 18:32:18 +02001016 &fops_antenna);
Bruno Randolf76443952010-03-09 16:56:00 +09001017
Pavel Roskine0d687b2011-07-14 20:21:55 -04001018 debugfs_create_file("misc", S_IRUSR, phydir, ah, &fops_misc);
Ben Greear87fd2e62010-09-21 17:03:57 -07001019
Jade Bilkeydb906eb2014-08-30 15:14:14 -04001020 debugfs_create_file("eeprom", S_IRUSR, phydir, ah, &fops_eeprom);
1021
Pavel Roskine0d687b2011-07-14 20:21:55 -04001022 debugfs_create_file("frameerrors", S_IWUSR | S_IRUSR, phydir, ah,
Felix Fietkau5b7916a2011-04-10 18:32:18 +02001023 &fops_frameerrors);
Bruno Randolf2111ac02010-04-02 18:44:08 +09001024
Pavel Roskine0d687b2011-07-14 20:21:55 -04001025 debugfs_create_file("ani", S_IWUSR | S_IRUSR, phydir, ah, &fops_ani);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +09001026
Pavel Roskine0d687b2011-07-14 20:21:55 -04001027 debugfs_create_file("queue", S_IWUSR | S_IRUSR, phydir, ah,
Felix Fietkau5b7916a2011-04-10 18:32:18 +02001028 &fops_queue);
Felix Fietkau63402112011-07-12 09:02:04 +08001029
1030 debugfs_create_bool("32khz_clock", S_IWUSR | S_IRUSR, phydir,
Pavel Roskine0d687b2011-07-14 20:21:55 -04001031 &ah->ah_use_32khz_clock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001032}
1033
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001034/* functions used in other places */
1035
1036void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001037ath5k_debug_dump_bands(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001038{
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001039 unsigned int b, i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001040
Pavel Roskine0d687b2011-07-14 20:21:55 -04001041 if (likely(!(ah->debug.level & ATH5K_DEBUG_DUMPBANDS)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001042 return;
1043
Pavel Roskine0d687b2011-07-14 20:21:55 -04001044 BUG_ON(!ah->sbands);
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001045
Johannes Berg57fbcce2016-04-12 15:56:15 +02001046 for (b = 0; b < NUM_NL80211_BANDS; b++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001047 struct ieee80211_supported_band *band = &ah->sbands[b];
Bob Copelandb7fcb5c2009-04-27 22:12:43 -04001048 char bname[6];
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001049 switch (band->band) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02001050 case NL80211_BAND_2GHZ:
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001051 strcpy(bname, "2 GHz");
1052 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001053 case NL80211_BAND_5GHZ:
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001054 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);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001063 printk(KERN_DEBUG " channels:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001064 for (i = 0; i < band->n_channels; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001065 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001066 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);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001071 printk(KERN_DEBUG " rates:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001072 for (i = 0; i < band->n_bitrates; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001073 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001074 band->bitrates[i].bitrate,
1075 band->bitrates[i].hw_value,
1076 band->bitrates[i].flags,
1077 band->bitrates[i].hw_value_short);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001078 }
1079}
1080
1081static inline void
Bruno Randolfb47f4072008-03-05 18:35:45 +09001082ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
1083 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001084{
1085 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001086 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001087
1088 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
1089 ds, (unsigned long long)bf->daddr,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001090 ds->ds_link, ds->ds_data,
1091 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
Bruno Randolf62412a82010-06-16 19:12:12 +09001092 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001093 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001094}
1095
1096void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001097ath5k_debug_printrxbuffs(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001098{
1099 struct ath5k_desc *ds;
1100 struct ath5k_buf *bf;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001101 struct ath5k_rx_status rs = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001102 int status;
1103
Pavel Roskine0d687b2011-07-14 20:21:55 -04001104 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001105 return;
1106
Bruno Randolf265faad2010-06-16 19:11:30 +09001107 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -04001108 ath5k_hw_get_rxdp(ah), ah->rxlink);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001109
Pavel Roskine0d687b2011-07-14 20:21:55 -04001110 spin_lock_bh(&ah->rxbuflock);
1111 list_for_each_entry(bf, &ah->rxbuf, list) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001112 ds = bf->desc;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001113 status = ah->ah_proc_rx_desc(ah, ds, &rs);
Bruno Randolfbe9b7252008-01-23 10:27:51 +09001114 if (!status)
Bruno Randolfb47f4072008-03-05 18:35:45 +09001115 ath5k_debug_printrxbuf(bf, status == 0, &rs);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001116 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04001117 spin_unlock_bh(&ah->rxbuflock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001118}
1119
1120void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001121ath5k_debug_printtxbuf(struct ath5k_hw *ah, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001122{
1123 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001124 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001125 struct ath5k_tx_status ts = {};
1126 int done;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001127
Pavel Roskine0d687b2011-07-14 20:21:55 -04001128 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001129 return;
1130
Pavel Roskine0d687b2011-07-14 20:21:55 -04001131 done = ah->ah_proc_tx_desc(ah, bf->desc, &ts);
Bruno Randolfb47f4072008-03-05 18:35:45 +09001132
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001133 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,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001135 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,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001138 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001139}