blob: e01faf641288fbac6e7412c18025fac5537c52c9 [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>
Nick Kossifidisc6e387a2008-08-29 22:45:39 +030069#include "debug.h"
Pavel Roskin931be262011-07-26 22:26:59 -040070#include "ath5k.h"
71#include "reg.h"
72#include "base.h"
Jiri Slabyfa1c1142007-08-12 17:33:16 +020073
74static unsigned int ath5k_debug;
75module_param_named(debug, ath5k_debug, uint, 0);
76
77
Jiri Slabyfa1c1142007-08-12 17:33:16 +020078/* debugfs: registers */
79
80struct reg {
Jiri Slaby2c91108c2009-03-07 10:26:41 +010081 const char *name;
Jiri Slabyfa1c1142007-08-12 17:33:16 +020082 int addr;
83};
84
85#define REG_STRUCT_INIT(r) { #r, r }
86
87/* just a few random registers, might want to add more */
Jiri Slaby2c91108c2009-03-07 10:26:41 +010088static const struct reg regs[] = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +020089 REG_STRUCT_INIT(AR5K_CR),
90 REG_STRUCT_INIT(AR5K_RXDP),
91 REG_STRUCT_INIT(AR5K_CFG),
92 REG_STRUCT_INIT(AR5K_IER),
93 REG_STRUCT_INIT(AR5K_BCR),
94 REG_STRUCT_INIT(AR5K_RTSD0),
95 REG_STRUCT_INIT(AR5K_RTSD1),
96 REG_STRUCT_INIT(AR5K_TXCFG),
97 REG_STRUCT_INIT(AR5K_RXCFG),
98 REG_STRUCT_INIT(AR5K_RXJLA),
99 REG_STRUCT_INIT(AR5K_MIBC),
100 REG_STRUCT_INIT(AR5K_TOPS),
101 REG_STRUCT_INIT(AR5K_RXNOFRM),
102 REG_STRUCT_INIT(AR5K_TXNOFRM),
103 REG_STRUCT_INIT(AR5K_RPGTO),
104 REG_STRUCT_INIT(AR5K_RFCNT),
105 REG_STRUCT_INIT(AR5K_MISC),
106 REG_STRUCT_INIT(AR5K_QCUDCU_CLKGT),
107 REG_STRUCT_INIT(AR5K_ISR),
108 REG_STRUCT_INIT(AR5K_PISR),
109 REG_STRUCT_INIT(AR5K_SISR0),
110 REG_STRUCT_INIT(AR5K_SISR1),
111 REG_STRUCT_INIT(AR5K_SISR2),
112 REG_STRUCT_INIT(AR5K_SISR3),
113 REG_STRUCT_INIT(AR5K_SISR4),
114 REG_STRUCT_INIT(AR5K_IMR),
115 REG_STRUCT_INIT(AR5K_PIMR),
116 REG_STRUCT_INIT(AR5K_SIMR0),
117 REG_STRUCT_INIT(AR5K_SIMR1),
118 REG_STRUCT_INIT(AR5K_SIMR2),
119 REG_STRUCT_INIT(AR5K_SIMR3),
120 REG_STRUCT_INIT(AR5K_SIMR4),
121 REG_STRUCT_INIT(AR5K_DCM_ADDR),
122 REG_STRUCT_INIT(AR5K_DCCFG),
123 REG_STRUCT_INIT(AR5K_CCFG),
124 REG_STRUCT_INIT(AR5K_CPC0),
125 REG_STRUCT_INIT(AR5K_CPC1),
126 REG_STRUCT_INIT(AR5K_CPC2),
127 REG_STRUCT_INIT(AR5K_CPC3),
Nick Kossifidis0bacdf32008-07-30 13:18:59 +0300128 REG_STRUCT_INIT(AR5K_CPCOVF),
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200129 REG_STRUCT_INIT(AR5K_RESET_CTL),
130 REG_STRUCT_INIT(AR5K_SLEEP_CTL),
131 REG_STRUCT_INIT(AR5K_INTPEND),
132 REG_STRUCT_INIT(AR5K_SFR),
133 REG_STRUCT_INIT(AR5K_PCICFG),
134 REG_STRUCT_INIT(AR5K_GPIOCR),
135 REG_STRUCT_INIT(AR5K_GPIODO),
136 REG_STRUCT_INIT(AR5K_SREV),
137};
138
139static void *reg_start(struct seq_file *seq, loff_t *pos)
140{
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100141 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200142}
143
144static void reg_stop(struct seq_file *seq, void *p)
145{
146 /* nothing to do */
147}
148
149static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
150{
151 ++*pos;
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100152 return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200153}
154
155static int reg_show(struct seq_file *seq, void *p)
156{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400157 struct ath5k_hw *ah = seq->private;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200158 struct reg *r = p;
159 seq_printf(seq, "%-25s0x%08x\n", r->name,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400160 ath5k_hw_reg_read(ah, r->addr));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200161 return 0;
162}
163
Jan Engelhardt4101dec2009-01-14 13:52:18 -0800164static const struct seq_operations register_seq_ops = {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200165 .start = reg_start,
166 .next = reg_next,
167 .stop = reg_stop,
168 .show = reg_show
169};
170
171static int open_file_registers(struct inode *inode, struct file *file)
172{
173 struct seq_file *s;
174 int res;
175 res = seq_open(file, &register_seq_ops);
176 if (res == 0) {
177 s = file->private_data;
178 s->private = inode->i_private;
179 }
180 return res;
181}
182
183static const struct file_operations fops_registers = {
184 .open = open_file_registers,
185 .read = seq_read,
186 .llseek = seq_lseek,
187 .release = seq_release,
188 .owner = THIS_MODULE,
189};
190
191
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200192/* debugfs: beacons */
193
194static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
195 size_t count, loff_t *ppos)
196{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400197 struct ath5k_hw *ah = file->private_data;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900198 char buf[500];
199 unsigned int len = 0;
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200200 unsigned int v;
201 u64 tsf;
202
Pavel Roskine0d687b2011-07-14 20:21:55 -0400203 v = ath5k_hw_reg_read(ah, AR5K_BEACON);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400204 len += snprintf(buf + len, sizeof(buf) - len,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200205 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
206 "AR5K_BEACON", v, v & AR5K_BEACON_PERIOD,
207 (v & AR5K_BEACON_TIM) >> AR5K_BEACON_TIM_S);
208
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400209 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400210 "AR5K_LAST_TSTP", ath5k_hw_reg_read(ah, AR5K_LAST_TSTP));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200211
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400212 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\n\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400213 "AR5K_BEACON_CNT", ath5k_hw_reg_read(ah, AR5K_BEACON_CNT));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200214
Pavel Roskine0d687b2011-07-14 20:21:55 -0400215 v = ath5k_hw_reg_read(ah, AR5K_TIMER0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400216 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200217 "AR5K_TIMER0 (TBTT)", v, v);
218
Pavel Roskine0d687b2011-07-14 20:21:55 -0400219 v = ath5k_hw_reg_read(ah, AR5K_TIMER1);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400220 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200221 "AR5K_TIMER1 (DMA)", v, v >> 3);
222
Pavel Roskine0d687b2011-07-14 20:21:55 -0400223 v = ath5k_hw_reg_read(ah, AR5K_TIMER2);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400224 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200225 "AR5K_TIMER2 (SWBA)", v, v >> 3);
226
Pavel Roskine0d687b2011-07-14 20:21:55 -0400227 v = ath5k_hw_reg_read(ah, AR5K_TIMER3);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400228 len += snprintf(buf + len, sizeof(buf) - len, "%-24s0x%08x\tTU: %08x\n",
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200229 "AR5K_TIMER3 (ATIM)", v, v);
230
Pavel Roskine0d687b2011-07-14 20:21:55 -0400231 tsf = ath5k_hw_get_tsf64(ah);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400232 len += snprintf(buf + len, sizeof(buf) - len,
John W. Linvillef868f4e2008-03-07 16:38:43 -0500233 "TSF\t\t0x%016llx\tTU: %08x\n",
234 (unsigned long long)tsf, TSF_TO_TU(tsf));
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200235
Dan Carpenter2189d132010-07-22 10:52:02 +0200236 if (len > sizeof(buf))
237 len = sizeof(buf);
238
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200239 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
240}
241
242static ssize_t write_file_beacon(struct file *file,
243 const char __user *userbuf,
244 size_t count, loff_t *ppos)
245{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400246 struct ath5k_hw *ah = file->private_data;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900247 char buf[20];
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200248
Djalal Harouni8aada632013-08-25 11:50:49 +0100249 count = min_t(size_t, count, sizeof(buf) - 1);
250 if (copy_from_user(buf, userbuf, count))
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900251 return -EFAULT;
252
Djalal Harouni8aada632013-08-25 11:50:49 +0100253 buf[count] = '\0';
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900254 if (strncmp(buf, "disable", 7) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200255 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
Joe Perches516304b2012-03-18 17:30:52 -0700256 pr_info("debugfs disable beacons\n");
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900257 } else if (strncmp(buf, "enable", 6) == 0) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200258 AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
Joe Perches516304b2012-03-18 17:30:52 -0700259 pr_info("debugfs enable beacons\n");
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200260 }
261 return count;
262}
263
264static const struct file_operations fops_beacon = {
265 .read = read_file_beacon,
266 .write = write_file_beacon,
Stephen Boyd234e3402012-04-05 14:25:11 -0700267 .open = simple_open,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200268 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200269 .llseek = default_llseek,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200270};
271
272
273/* debugfs: reset */
274
275static ssize_t write_file_reset(struct file *file,
276 const char __user *userbuf,
277 size_t count, loff_t *ppos)
278{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400279 struct ath5k_hw *ah = file->private_data;
280 ATH5K_DBG(ah, ATH5K_DEBUG_RESET, "debug file triggered reset\n");
281 ieee80211_queue_work(ah->hw, &ah->reset_work);
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200282 return count;
283}
284
285static const struct file_operations fops_reset = {
286 .write = write_file_reset,
Stephen Boyd234e3402012-04-05 14:25:11 -0700287 .open = simple_open,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200288 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200289 .llseek = noop_llseek,
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200290};
291
292
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900293/* debugfs: debug level */
294
Jiri Slaby2c91108c2009-03-07 10:26:41 +0100295static const struct {
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900296 enum ath5k_debug_level level;
297 const char *name;
298 const char *desc;
299} dbg_info[] = {
300 { ATH5K_DEBUG_RESET, "reset", "reset and initialization" },
301 { ATH5K_DEBUG_INTR, "intr", "interrupt handling" },
302 { ATH5K_DEBUG_MODE, "mode", "mode init/setup" },
303 { ATH5K_DEBUG_XMIT, "xmit", "basic xmit operation" },
304 { ATH5K_DEBUG_BEACON, "beacon", "beacon handling" },
305 { ATH5K_DEBUG_CALIBRATE, "calib", "periodic calibration" },
306 { ATH5K_DEBUG_TXPOWER, "txpower", "transmit power setting" },
Bob Copeland85519a62008-10-29 08:30:53 -0400307 { ATH5K_DEBUG_LED, "led", "LED management" },
Luis R. Rodriguezb4461972008-02-04 10:03:54 -0500308 { ATH5K_DEBUG_DUMPBANDS, "dumpbands", "dump bands" },
Nick Kossifidisb3a28e62010-11-23 20:47:31 +0200309 { ATH5K_DEBUG_DMA, "dma", "dma start/stop" },
Bruno Randolf2111ac02010-04-02 18:44:08 +0900310 { ATH5K_DEBUG_ANI, "ani", "adaptive noise immunity" },
Bob Copelandb4c52612010-08-21 16:39:03 -0400311 { ATH5K_DEBUG_DESC, "desc", "descriptor chains" },
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900312 { ATH5K_DEBUG_ANY, "all", "show all debug levels" },
313};
314
315static ssize_t read_file_debug(struct file *file, char __user *user_buf,
316 size_t count, loff_t *ppos)
317{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400318 struct ath5k_hw *ah = file->private_data;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900319 char buf[700];
320 unsigned int len = 0;
321 unsigned int i;
322
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400323 len += snprintf(buf + len, sizeof(buf) - len,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400324 "DEBUG LEVEL: 0x%08x\n\n", ah->debug.level);
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900325
326 for (i = 0; i < ARRAY_SIZE(dbg_info) - 1; i++) {
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400327 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900328 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400329 ah->debug.level & dbg_info[i].level ? '+' : ' ',
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900330 dbg_info[i].level, dbg_info[i].desc);
331 }
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400332 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900333 "%10s %c 0x%08x - %s\n", dbg_info[i].name,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400334 ah->debug.level == dbg_info[i].level ? '+' : ' ',
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900335 dbg_info[i].level, dbg_info[i].desc);
336
Dan Carpenter2189d132010-07-22 10:52:02 +0200337 if (len > sizeof(buf))
338 len = sizeof(buf);
339
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900340 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
341}
342
343static ssize_t write_file_debug(struct file *file,
344 const char __user *userbuf,
345 size_t count, loff_t *ppos)
346{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400347 struct ath5k_hw *ah = file->private_data;
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900348 unsigned int i;
349 char buf[20];
350
Djalal Harouni8aada632013-08-25 11:50:49 +0100351 count = min_t(size_t, count, sizeof(buf) - 1);
352 if (copy_from_user(buf, userbuf, count))
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900353 return -EFAULT;
354
Djalal Harouni8aada632013-08-25 11:50:49 +0100355 buf[count] = '\0';
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900356 for (i = 0; i < ARRAY_SIZE(dbg_info); i++) {
357 if (strncmp(buf, dbg_info[i].name,
358 strlen(dbg_info[i].name)) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400359 ah->debug.level ^= dbg_info[i].level; /* toggle bit */
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900360 break;
361 }
362 }
363 return count;
364}
365
366static const struct file_operations fops_debug = {
367 .read = read_file_debug,
368 .write = write_file_debug,
Stephen Boyd234e3402012-04-05 14:25:11 -0700369 .open = simple_open,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900370 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200371 .llseek = default_llseek,
Bruno Randolfbe9b7252008-01-23 10:27:51 +0900372};
373
374
Bruno Randolf604eead2010-03-09 16:55:17 +0900375/* debugfs: antenna */
376
377static ssize_t read_file_antenna(struct file *file, char __user *user_buf,
378 size_t count, loff_t *ppos)
379{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400380 struct ath5k_hw *ah = file->private_data;
Bruno Randolf604eead2010-03-09 16:55:17 +0900381 char buf[700];
382 unsigned int len = 0;
383 unsigned int i;
384 unsigned int v;
385
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400386 len += snprintf(buf + len, sizeof(buf) - len, "antenna mode\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400387 ah->ah_ant_mode);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400388 len += snprintf(buf + len, sizeof(buf) - len, "default antenna\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400389 ah->ah_def_ant);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400390 len += snprintf(buf + len, sizeof(buf) - len, "tx antenna\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400391 ah->ah_tx_ant);
Bruno Randolf604eead2010-03-09 16:55:17 +0900392
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400393 len += snprintf(buf + len, sizeof(buf) - len, "\nANTENNA\t\tRX\tTX\n");
Pavel Roskine0d687b2011-07-14 20:21:55 -0400394 for (i = 1; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) {
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400395 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900396 "[antenna %d]\t%d\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400397 i, ah->stats.antenna_rx[i], ah->stats.antenna_tx[i]);
Bruno Randolf604eead2010-03-09 16:55:17 +0900398 }
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400399 len += snprintf(buf + len, sizeof(buf) - len, "[invalid]\t%d\t%d\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400400 ah->stats.antenna_rx[0], ah->stats.antenna_tx[0]);
Bruno Randolf604eead2010-03-09 16:55:17 +0900401
Pavel Roskine0d687b2011-07-14 20:21:55 -0400402 v = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400403 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900404 "\nAR5K_DEFAULT_ANTENNA\t0x%08x\n", v);
405
Pavel Roskine0d687b2011-07-14 20:21:55 -0400406 v = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400407 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900408 "AR5K_STA_ID1_DEFAULT_ANTENNA\t%d\n",
409 (v & AR5K_STA_ID1_DEFAULT_ANTENNA) != 0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400410 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900411 "AR5K_STA_ID1_DESC_ANTENNA\t%d\n",
412 (v & AR5K_STA_ID1_DESC_ANTENNA) != 0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400413 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900414 "AR5K_STA_ID1_RTS_DEF_ANTENNA\t%d\n",
415 (v & AR5K_STA_ID1_RTS_DEF_ANTENNA) != 0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400416 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900417 "AR5K_STA_ID1_SELFGEN_DEF_ANT\t%d\n",
418 (v & AR5K_STA_ID1_SELFGEN_DEF_ANT) != 0);
419
Pavel Roskine0d687b2011-07-14 20:21:55 -0400420 v = ath5k_hw_reg_read(ah, AR5K_PHY_AGCCTL);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400421 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900422 "\nAR5K_PHY_AGCCTL_OFDM_DIV_DIS\t%d\n",
423 (v & AR5K_PHY_AGCCTL_OFDM_DIV_DIS) != 0);
424
Pavel Roskine0d687b2011-07-14 20:21:55 -0400425 v = ath5k_hw_reg_read(ah, AR5K_PHY_RESTART);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400426 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900427 "AR5K_PHY_RESTART_DIV_GC\t\t%x\n",
428 (v & AR5K_PHY_RESTART_DIV_GC) >> AR5K_PHY_RESTART_DIV_GC_S);
429
Pavel Roskine0d687b2011-07-14 20:21:55 -0400430 v = ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ANT_DIV);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400431 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf604eead2010-03-09 16:55:17 +0900432 "AR5K_PHY_FAST_ANT_DIV_EN\t%d\n",
433 (v & AR5K_PHY_FAST_ANT_DIV_EN) != 0);
434
Pavel Roskine0d687b2011-07-14 20:21:55 -0400435 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_0);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400436 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf0ca74022010-06-07 13:11:30 +0900437 "\nAR5K_PHY_ANT_SWITCH_TABLE_0\t0x%08x\n", v);
Pavel Roskine0d687b2011-07-14 20:21:55 -0400438 v = ath5k_hw_reg_read(ah, AR5K_PHY_ANT_SWITCH_TABLE_1);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400439 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf0ca74022010-06-07 13:11:30 +0900440 "AR5K_PHY_ANT_SWITCH_TABLE_1\t0x%08x\n", v);
441
Dan Carpenter2189d132010-07-22 10:52:02 +0200442 if (len > sizeof(buf))
443 len = sizeof(buf);
444
Bruno Randolf604eead2010-03-09 16:55:17 +0900445 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
446}
447
448static ssize_t write_file_antenna(struct file *file,
449 const char __user *userbuf,
450 size_t count, loff_t *ppos)
451{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400452 struct ath5k_hw *ah = file->private_data;
Bruno Randolf604eead2010-03-09 16:55:17 +0900453 unsigned int i;
454 char buf[20];
455
Djalal Harouni8aada632013-08-25 11:50:49 +0100456 count = min_t(size_t, count, sizeof(buf) - 1);
457 if (copy_from_user(buf, userbuf, count))
Bruno Randolf604eead2010-03-09 16:55:17 +0900458 return -EFAULT;
459
Djalal Harouni8aada632013-08-25 11:50:49 +0100460 buf[count] = '\0';
Bruno Randolf604eead2010-03-09 16:55:17 +0900461 if (strncmp(buf, "diversity", 9) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400462 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
Joe Perches516304b2012-03-18 17:30:52 -0700463 pr_info("debug: enable diversity\n");
Bruno Randolf604eead2010-03-09 16:55:17 +0900464 } else if (strncmp(buf, "fixed-a", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400465 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
Joe Perches516304b2012-03-18 17:30:52 -0700466 pr_info("debug: fixed antenna A\n");
Bruno Randolf604eead2010-03-09 16:55:17 +0900467 } else if (strncmp(buf, "fixed-b", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400468 ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
Joe Perches516304b2012-03-18 17:30:52 -0700469 pr_info("debug: fixed antenna B\n");
Bruno Randolf604eead2010-03-09 16:55:17 +0900470 } else if (strncmp(buf, "clear", 5) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400471 for (i = 0; i < ARRAY_SIZE(ah->stats.antenna_rx); i++) {
472 ah->stats.antenna_rx[i] = 0;
473 ah->stats.antenna_tx[i] = 0;
Bruno Randolf604eead2010-03-09 16:55:17 +0900474 }
Joe Perches516304b2012-03-18 17:30:52 -0700475 pr_info("debug: cleared antenna stats\n");
Bruno Randolf604eead2010-03-09 16:55:17 +0900476 }
477 return count;
478}
479
480static const struct file_operations fops_antenna = {
481 .read = read_file_antenna,
482 .write = write_file_antenna,
Stephen Boyd234e3402012-04-05 14:25:11 -0700483 .open = simple_open,
Bruno Randolf604eead2010-03-09 16:55:17 +0900484 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200485 .llseek = default_llseek,
Bruno Randolf604eead2010-03-09 16:55:17 +0900486};
487
Ben Greear87fd2e62010-09-21 17:03:57 -0700488/* debugfs: misc */
489
490static ssize_t read_file_misc(struct file *file, char __user *user_buf,
491 size_t count, loff_t *ppos)
492{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400493 struct ath5k_hw *ah = file->private_data;
Ben Greear87fd2e62010-09-21 17:03:57 -0700494 char buf[700];
495 unsigned int len = 0;
Pavel Roskine0d687b2011-07-14 20:21:55 -0400496 u32 filt = ath5k_hw_get_rx_filter(ah);
Ben Greear87fd2e62010-09-21 17:03:57 -0700497
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400498 len += snprintf(buf + len, sizeof(buf) - len, "bssid-mask: %pM\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400499 ah->bssidmask);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400500 len += snprintf(buf + len, sizeof(buf) - len, "filter-flags: 0x%x ",
Ben Greear87fd2e62010-09-21 17:03:57 -0700501 filt);
502 if (filt & AR5K_RX_FILTER_UCAST)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400503 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
Ben Greear87fd2e62010-09-21 17:03:57 -0700504 if (filt & AR5K_RX_FILTER_MCAST)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400505 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
Ben Greear87fd2e62010-09-21 17:03:57 -0700506 if (filt & AR5K_RX_FILTER_BCAST)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400507 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
Ben Greear87fd2e62010-09-21 17:03:57 -0700508 if (filt & AR5K_RX_FILTER_CONTROL)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400509 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
Ben Greear87fd2e62010-09-21 17:03:57 -0700510 if (filt & AR5K_RX_FILTER_BEACON)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400511 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
Ben Greear87fd2e62010-09-21 17:03:57 -0700512 if (filt & AR5K_RX_FILTER_PROM)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400513 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
Ben Greear87fd2e62010-09-21 17:03:57 -0700514 if (filt & AR5K_RX_FILTER_XRPOLL)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400515 len += snprintf(buf + len, sizeof(buf) - len, " XRPOLL");
Ben Greear87fd2e62010-09-21 17:03:57 -0700516 if (filt & AR5K_RX_FILTER_PROBEREQ)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400517 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
Ben Greear87fd2e62010-09-21 17:03:57 -0700518 if (filt & AR5K_RX_FILTER_PHYERR_5212)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400519 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR-5212");
Ben Greear87fd2e62010-09-21 17:03:57 -0700520 if (filt & AR5K_RX_FILTER_RADARERR_5212)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400521 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5212");
Ben Greear87fd2e62010-09-21 17:03:57 -0700522 if (filt & AR5K_RX_FILTER_PHYERR_5211)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400523 snprintf(buf + len, sizeof(buf) - len, " PHYERR-5211");
Ben Greear87fd2e62010-09-21 17:03:57 -0700524 if (filt & AR5K_RX_FILTER_RADARERR_5211)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400525 len += snprintf(buf + len, sizeof(buf) - len, " RADARERR-5211");
Ben Greear87fd2e62010-09-21 17:03:57 -0700526
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400527 len += snprintf(buf + len, sizeof(buf) - len, "\nopmode: %s (%d)\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400528 ath_opmode_to_string(ah->opmode), ah->opmode);
Ben Greear92c68a62010-10-08 09:43:29 -0700529
Ben Greear87fd2e62010-09-21 17:03:57 -0700530 if (len > sizeof(buf))
531 len = sizeof(buf);
532
533 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
534}
535
536static const struct file_operations fops_misc = {
537 .read = read_file_misc,
Stephen Boyd234e3402012-04-05 14:25:11 -0700538 .open = simple_open,
Ben Greear87fd2e62010-09-21 17:03:57 -0700539 .owner = THIS_MODULE,
540};
541
Bruno Randolf604eead2010-03-09 16:55:17 +0900542
Bruno Randolf76443952010-03-09 16:56:00 +0900543/* debugfs: frameerrors */
544
545static ssize_t read_file_frameerrors(struct file *file, char __user *user_buf,
546 size_t count, loff_t *ppos)
547{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400548 struct ath5k_hw *ah = file->private_data;
549 struct ath5k_statistics *st = &ah->stats;
Bruno Randolf76443952010-03-09 16:56:00 +0900550 char buf[700];
551 unsigned int len = 0;
Bruno Randolfda351112010-03-25 14:49:42 +0900552 int i;
Bruno Randolf76443952010-03-09 16:56:00 +0900553
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400554 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf76443952010-03-09 16:56:00 +0900555 "RX\n---------------------\n");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400556 len += snprintf(buf + len, sizeof(buf) - len, "CRC\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900557 st->rxerr_crc,
558 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400559 st->rxerr_crc * 100 / st->rx_all_count : 0);
560 len += snprintf(buf + len, sizeof(buf) - len, "PHY\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900561 st->rxerr_phy,
562 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400563 st->rxerr_phy * 100 / st->rx_all_count : 0);
Bruno Randolfda351112010-03-25 14:49:42 +0900564 for (i = 0; i < 32; i++) {
565 if (st->rxerr_phy_code[i])
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400566 len += snprintf(buf + len, sizeof(buf) - len,
Ben Greear5d882c92010-11-08 10:50:03 -0800567 " phy_err[%u]\t%u\n",
Bruno Randolfda351112010-03-25 14:49:42 +0900568 i, st->rxerr_phy_code[i]);
569 }
570
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400571 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900572 st->rxerr_fifo,
573 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400574 st->rxerr_fifo * 100 / st->rx_all_count : 0);
575 len += snprintf(buf + len, sizeof(buf) - len, "decrypt\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900576 st->rxerr_decrypt,
577 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400578 st->rxerr_decrypt * 100 / st->rx_all_count : 0);
579 len += snprintf(buf + len, sizeof(buf) - len, "MIC\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900580 st->rxerr_mic,
581 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400582 st->rxerr_mic * 100 / st->rx_all_count : 0);
583 len += snprintf(buf + len, sizeof(buf) - len, "process\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900584 st->rxerr_proc,
585 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400586 st->rxerr_proc * 100 / st->rx_all_count : 0);
587 len += snprintf(buf + len, sizeof(buf) - len, "jumbo\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900588 st->rxerr_jumbo,
589 st->rx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400590 st->rxerr_jumbo * 100 / st->rx_all_count : 0);
591 len += snprintf(buf + len, sizeof(buf) - len, "[RX all\t%u]\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900592 st->rx_all_count);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400593 len += snprintf(buf + len, sizeof(buf) - len, "RX-all-bytes\t%u\n",
Ben Greearb72acdd2010-10-01 10:54:04 -0700594 st->rx_bytes_count);
Bruno Randolf76443952010-03-09 16:56:00 +0900595
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400596 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf76443952010-03-09 16:56:00 +0900597 "\nTX\n---------------------\n");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400598 len += snprintf(buf + len, sizeof(buf) - len, "retry\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900599 st->txerr_retry,
600 st->tx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400601 st->txerr_retry * 100 / st->tx_all_count : 0);
602 len += snprintf(buf + len, sizeof(buf) - len, "FIFO\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900603 st->txerr_fifo,
604 st->tx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400605 st->txerr_fifo * 100 / st->tx_all_count : 0);
606 len += snprintf(buf + len, sizeof(buf) - len, "filter\t%u\t(%u%%)\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900607 st->txerr_filt,
608 st->tx_all_count > 0 ?
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400609 st->txerr_filt * 100 / st->tx_all_count : 0);
610 len += snprintf(buf + len, sizeof(buf) - len, "[TX all\t%u]\n",
Bruno Randolf76443952010-03-09 16:56:00 +0900611 st->tx_all_count);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400612 len += snprintf(buf + len, sizeof(buf) - len, "TX-all-bytes\t%u\n",
Ben Greearb72acdd2010-10-01 10:54:04 -0700613 st->tx_bytes_count);
Bruno Randolf76443952010-03-09 16:56:00 +0900614
Dan Carpenter2189d132010-07-22 10:52:02 +0200615 if (len > sizeof(buf))
616 len = sizeof(buf);
617
Bruno Randolf76443952010-03-09 16:56:00 +0900618 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
619}
620
621static ssize_t write_file_frameerrors(struct file *file,
622 const char __user *userbuf,
623 size_t count, loff_t *ppos)
624{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400625 struct ath5k_hw *ah = file->private_data;
626 struct ath5k_statistics *st = &ah->stats;
Bruno Randolf76443952010-03-09 16:56:00 +0900627 char buf[20];
628
Djalal Harouni8aada632013-08-25 11:50:49 +0100629 count = min_t(size_t, count, sizeof(buf) - 1);
630 if (copy_from_user(buf, userbuf, count))
Bruno Randolf76443952010-03-09 16:56:00 +0900631 return -EFAULT;
632
Djalal Harouni8aada632013-08-25 11:50:49 +0100633 buf[count] = '\0';
Bruno Randolf76443952010-03-09 16:56:00 +0900634 if (strncmp(buf, "clear", 5) == 0) {
635 st->rxerr_crc = 0;
636 st->rxerr_phy = 0;
637 st->rxerr_fifo = 0;
638 st->rxerr_decrypt = 0;
639 st->rxerr_mic = 0;
640 st->rxerr_proc = 0;
641 st->rxerr_jumbo = 0;
642 st->rx_all_count = 0;
643 st->txerr_retry = 0;
644 st->txerr_fifo = 0;
645 st->txerr_filt = 0;
646 st->tx_all_count = 0;
Joe Perches516304b2012-03-18 17:30:52 -0700647 pr_info("debug: cleared frameerrors stats\n");
Bruno Randolf76443952010-03-09 16:56:00 +0900648 }
649 return count;
650}
651
652static const struct file_operations fops_frameerrors = {
653 .read = read_file_frameerrors,
654 .write = write_file_frameerrors,
Stephen Boyd234e3402012-04-05 14:25:11 -0700655 .open = simple_open,
Bruno Randolf76443952010-03-09 16:56:00 +0900656 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200657 .llseek = default_llseek,
Bruno Randolf76443952010-03-09 16:56:00 +0900658};
659
660
Bruno Randolf2111ac02010-04-02 18:44:08 +0900661/* debugfs: ani */
662
663static ssize_t read_file_ani(struct file *file, char __user *user_buf,
664 size_t count, loff_t *ppos)
665{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400666 struct ath5k_hw *ah = file->private_data;
667 struct ath5k_statistics *st = &ah->stats;
668 struct ath5k_ani_state *as = &ah->ani_state;
Bruno Randolf2111ac02010-04-02 18:44:08 +0900669
670 char buf[700];
671 unsigned int len = 0;
672
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400673 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900674 "HW has PHY error counters:\t%s\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400675 ah->ah_capabilities.cap_has_phyerr_counters ?
Bruno Randolf2111ac02010-04-02 18:44:08 +0900676 "yes" : "no");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400677 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900678 "HW max spur immunity level:\t%d\n",
679 as->max_spur_level);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400680 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900681 "\nANI state\n--------------------------------------------\n");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400682 len += snprintf(buf + len, sizeof(buf) - len, "operating mode:\t\t\t");
Bruno Randolf2111ac02010-04-02 18:44:08 +0900683 switch (as->ani_mode) {
684 case ATH5K_ANI_MODE_OFF:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400685 len += snprintf(buf + len, sizeof(buf) - len, "OFF\n");
Bruno Randolf2111ac02010-04-02 18:44:08 +0900686 break;
687 case ATH5K_ANI_MODE_MANUAL_LOW:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400688 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900689 "MANUAL LOW\n");
690 break;
691 case ATH5K_ANI_MODE_MANUAL_HIGH:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400692 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900693 "MANUAL HIGH\n");
694 break;
695 case ATH5K_ANI_MODE_AUTO:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400696 len += snprintf(buf + len, sizeof(buf) - len, "AUTO\n");
Bruno Randolf2111ac02010-04-02 18:44:08 +0900697 break;
698 default:
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400699 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900700 "??? (not good)\n");
701 break;
702 }
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400703 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900704 "noise immunity level:\t\t%d\n",
705 as->noise_imm_level);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400706 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900707 "spur immunity level:\t\t%d\n",
708 as->spur_level);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400709 len += snprintf(buf + len, sizeof(buf) - len,
710 "firstep level:\t\t\t%d\n",
Bruno Randolf2111ac02010-04-02 18:44:08 +0900711 as->firstep_level);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400712 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900713 "OFDM weak signal detection:\t%s\n",
714 as->ofdm_weak_sig ? "on" : "off");
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400715 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900716 "CCK weak signal detection:\t%s\n",
717 as->cck_weak_sig ? "on" : "off");
718
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400719 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900720 "\nMIB INTERRUPTS:\t\t%u\n",
721 st->mib_intr);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400722 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900723 "beacon RSSI average:\t%d\n",
Johannes Berg46f26dd2015-08-19 09:46:20 +0200724 (int)ewma_beacon_rssi_read(&ah->ah_beacon_rssi_avg));
Felix Fietkau7109ca52010-10-08 22:13:54 +0200725
726#define CC_PRINT(_struct, _field) \
727 _struct._field, \
728 _struct.cycles > 0 ? \
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400729 _struct._field * 100 / _struct.cycles : 0
Felix Fietkau7109ca52010-10-08 22:13:54 +0200730
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400731 len += snprintf(buf + len, sizeof(buf) - len,
732 "profcnt tx\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200733 CC_PRINT(as->last_cc, tx_frame));
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400734 len += snprintf(buf + len, sizeof(buf) - len,
735 "profcnt rx\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200736 CC_PRINT(as->last_cc, rx_frame));
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400737 len += snprintf(buf + len, sizeof(buf) - len,
738 "profcnt busy\t\t%u\t(%d%%)\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200739 CC_PRINT(as->last_cc, rx_busy));
740#undef CC_PRINT
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400741 len += snprintf(buf + len, sizeof(buf) - len, "profcnt cycles\t\t%u\n",
Felix Fietkau7109ca52010-10-08 22:13:54 +0200742 as->last_cc.cycles);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400743 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900744 "listen time\t\t%d\tlast: %d\n",
745 as->listen_time, as->last_listen);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400746 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900747 "OFDM errors\t\t%u\tlast: %u\tsum: %u\n",
748 as->ofdm_errors, as->last_ofdm_errors,
749 as->sum_ofdm_errors);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400750 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900751 "CCK errors\t\t%u\tlast: %u\tsum: %u\n",
752 as->cck_errors, as->last_cck_errors,
753 as->sum_cck_errors);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400754 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900755 "AR5K_PHYERR_CNT1\t%x\t(=%d)\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400756 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1),
Bruno Randolf2111ac02010-04-02 18:44:08 +0900757 ATH5K_ANI_OFDM_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
Pavel Roskine0d687b2011-07-14 20:21:55 -0400758 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT1)));
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400759 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900760 "AR5K_PHYERR_CNT2\t%x\t(=%d)\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -0400761 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2),
Bruno Randolf2111ac02010-04-02 18:44:08 +0900762 ATH5K_ANI_CCK_TRIG_HIGH - (ATH5K_PHYERR_CNT_MAX -
Pavel Roskine0d687b2011-07-14 20:21:55 -0400763 ath5k_hw_reg_read(ah, AR5K_PHYERR_CNT2)));
Bruno Randolf2111ac02010-04-02 18:44:08 +0900764
Dan Carpenter2189d132010-07-22 10:52:02 +0200765 if (len > sizeof(buf))
766 len = sizeof(buf);
767
Bruno Randolf2111ac02010-04-02 18:44:08 +0900768 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
769}
770
771static ssize_t write_file_ani(struct file *file,
772 const char __user *userbuf,
773 size_t count, loff_t *ppos)
774{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400775 struct ath5k_hw *ah = file->private_data;
Bruno Randolf2111ac02010-04-02 18:44:08 +0900776 char buf[20];
777
Djalal Harouni8aada632013-08-25 11:50:49 +0100778 count = min_t(size_t, count, sizeof(buf) - 1);
779 if (copy_from_user(buf, userbuf, count))
Bruno Randolf2111ac02010-04-02 18:44:08 +0900780 return -EFAULT;
781
Djalal Harouni8aada632013-08-25 11:50:49 +0100782 buf[count] = '\0';
Bruno Randolf2111ac02010-04-02 18:44:08 +0900783 if (strncmp(buf, "sens-low", 8) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400784 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_HIGH);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900785 } else if (strncmp(buf, "sens-high", 9) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400786 ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_LOW);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900787 } else if (strncmp(buf, "ani-off", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400788 ath5k_ani_init(ah, ATH5K_ANI_MODE_OFF);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900789 } else if (strncmp(buf, "ani-on", 6) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400790 ath5k_ani_init(ah, ATH5K_ANI_MODE_AUTO);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900791 } else if (strncmp(buf, "noise-low", 9) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400792 ath5k_ani_set_noise_immunity_level(ah, 0);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900793 } else if (strncmp(buf, "noise-high", 10) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400794 ath5k_ani_set_noise_immunity_level(ah,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900795 ATH5K_ANI_MAX_NOISE_IMM_LVL);
796 } else if (strncmp(buf, "spur-low", 8) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400797 ath5k_ani_set_spur_immunity_level(ah, 0);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900798 } else if (strncmp(buf, "spur-high", 9) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400799 ath5k_ani_set_spur_immunity_level(ah,
800 ah->ani_state.max_spur_level);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900801 } else if (strncmp(buf, "fir-low", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400802 ath5k_ani_set_firstep_level(ah, 0);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900803 } else if (strncmp(buf, "fir-high", 8) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400804 ath5k_ani_set_firstep_level(ah, ATH5K_ANI_MAX_FIRSTEP_LVL);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900805 } else if (strncmp(buf, "ofdm-off", 8) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400806 ath5k_ani_set_ofdm_weak_signal_detection(ah, false);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900807 } else if (strncmp(buf, "ofdm-on", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400808 ath5k_ani_set_ofdm_weak_signal_detection(ah, true);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900809 } else if (strncmp(buf, "cck-off", 7) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400810 ath5k_ani_set_cck_weak_signal_detection(ah, false);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900811 } else if (strncmp(buf, "cck-on", 6) == 0) {
Pavel Roskine0d687b2011-07-14 20:21:55 -0400812 ath5k_ani_set_cck_weak_signal_detection(ah, true);
Bruno Randolf2111ac02010-04-02 18:44:08 +0900813 }
814 return count;
815}
816
817static const struct file_operations fops_ani = {
818 .read = read_file_ani,
819 .write = write_file_ani,
Stephen Boyd234e3402012-04-05 14:25:11 -0700820 .open = simple_open,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900821 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200822 .llseek = default_llseek,
Bruno Randolf2111ac02010-04-02 18:44:08 +0900823};
824
825
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900826/* debugfs: queues etc */
827
828static ssize_t read_file_queue(struct file *file, char __user *user_buf,
829 size_t count, loff_t *ppos)
830{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400831 struct ath5k_hw *ah = file->private_data;
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900832 char buf[700];
833 unsigned int len = 0;
834
835 struct ath5k_txq *txq;
836 struct ath5k_buf *bf, *bf0;
Bruno Randolfcfddc112010-09-17 11:36:40 +0900837 int i, n;
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900838
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400839 len += snprintf(buf + len, sizeof(buf) - len,
Pavel Roskine0d687b2011-07-14 20:21:55 -0400840 "available txbuffers: %d\n", ah->txbuf_len);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900841
Pavel Roskine0d687b2011-07-14 20:21:55 -0400842 for (i = 0; i < ARRAY_SIZE(ah->txqs); i++) {
843 txq = &ah->txqs[i];
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900844
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400845 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900846 "%02d: %ssetup\n", i, txq->setup ? "" : "not ");
847
848 if (!txq->setup)
849 continue;
850
Bruno Randolfcfddc112010-09-17 11:36:40 +0900851 n = 0;
852 spin_lock_bh(&txq->lock);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900853 list_for_each_entry_safe(bf, bf0, &txq->q, list)
854 n++;
Bruno Randolfcfddc112010-09-17 11:36:40 +0900855 spin_unlock_bh(&txq->lock);
856
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400857 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolfcfddc112010-09-17 11:36:40 +0900858 " len: %d bufs: %d\n", txq->txq_len, n);
Pavel Roskine4bbf2f2011-07-07 18:14:13 -0400859 len += snprintf(buf + len, sizeof(buf) - len,
Bruno Randolf923e5b32010-09-17 11:37:02 +0900860 " stuck: %d\n", txq->txq_stuck);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900861 }
862
Dan Carpenter2189d132010-07-22 10:52:02 +0200863 if (len > sizeof(buf))
864 len = sizeof(buf);
865
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900866 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
867}
868
869static ssize_t write_file_queue(struct file *file,
870 const char __user *userbuf,
871 size_t count, loff_t *ppos)
872{
Pavel Roskine0d687b2011-07-14 20:21:55 -0400873 struct ath5k_hw *ah = file->private_data;
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900874 char buf[20];
875
Djalal Harouni8aada632013-08-25 11:50:49 +0100876 count = min_t(size_t, count, sizeof(buf) - 1);
877 if (copy_from_user(buf, userbuf, count))
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900878 return -EFAULT;
879
Djalal Harouni8aada632013-08-25 11:50:49 +0100880 buf[count] = '\0';
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900881 if (strncmp(buf, "start", 5) == 0)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400882 ieee80211_wake_queues(ah->hw);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900883 else if (strncmp(buf, "stop", 4) == 0)
Pavel Roskine0d687b2011-07-14 20:21:55 -0400884 ieee80211_stop_queues(ah->hw);
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900885
886 return count;
887}
888
889
890static const struct file_operations fops_queue = {
891 .read = read_file_queue,
892 .write = write_file_queue,
Stephen Boyd234e3402012-04-05 14:25:11 -0700893 .open = simple_open,
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900894 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200895 .llseek = default_llseek,
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900896};
897
Jade Bilkeydb906eb2014-08-30 15:14:14 -0400898/* debugfs: eeprom */
899
900struct eeprom_private {
901 u16 *buf;
902 int len;
903};
904
905static int open_file_eeprom(struct inode *inode, struct file *file)
906{
907 struct eeprom_private *ep;
908 struct ath5k_hw *ah = inode->i_private;
909 bool res;
910 int i, ret;
Sergey Ryazanovaf8a9a62016-08-02 14:19:28 +0300911 u32 eesize; /* NB: in 16-bit words */
Jade Bilkeydb906eb2014-08-30 15:14:14 -0400912 u16 val, *buf;
913
914 /* Get eeprom size */
915
916 res = ath5k_hw_nvram_read(ah, AR5K_EEPROM_SIZE_UPPER, &val);
917 if (!res)
918 return -EACCES;
919
920 if (val == 0) {
921 eesize = AR5K_EEPROM_INFO_MAX + AR5K_EEPROM_INFO_BASE;
922 } else {
923 eesize = (val & AR5K_EEPROM_SIZE_UPPER_MASK) <<
924 AR5K_EEPROM_SIZE_ENDLOC_SHIFT;
925 ath5k_hw_nvram_read(ah, AR5K_EEPROM_SIZE_LOWER, &val);
926 eesize = eesize | val;
927 }
928
929 if (eesize > 4096)
930 return -EINVAL;
931
932 /* Create buffer and read in eeprom */
933
Kees Cook42bc47b2018-06-12 14:27:11 -0700934 buf = vmalloc(array_size(eesize, 2));
Jade Bilkeydb906eb2014-08-30 15:14:14 -0400935 if (!buf) {
936 ret = -ENOMEM;
937 goto err;
938 }
939
940 for (i = 0; i < eesize; ++i) {
Colin Ian King8fed6822017-05-03 15:26:00 +0100941 if (!ath5k_hw_nvram_read(ah, i, &val)) {
942 ret = -EIO;
943 goto freebuf;
944 }
Jade Bilkeydb906eb2014-08-30 15:14:14 -0400945 buf[i] = val;
946 }
947
948 /* Create private struct and assign to file */
949
950 ep = kmalloc(sizeof(*ep), GFP_KERNEL);
951 if (!ep) {
952 ret = -ENOMEM;
953 goto freebuf;
954 }
955
956 ep->buf = buf;
Sergey Ryazanovaf8a9a62016-08-02 14:19:28 +0300957 ep->len = eesize * 2;
Jade Bilkeydb906eb2014-08-30 15:14:14 -0400958
959 file->private_data = (void *)ep;
960
961 return 0;
962
963freebuf:
964 vfree(buf);
965err:
966 return ret;
967
968}
969
970static ssize_t read_file_eeprom(struct file *file, char __user *user_buf,
971 size_t count, loff_t *ppos)
972{
973 struct eeprom_private *ep = file->private_data;
974
975 return simple_read_from_buffer(user_buf, count, ppos, ep->buf, ep->len);
976}
977
978static int release_file_eeprom(struct inode *inode, struct file *file)
979{
980 struct eeprom_private *ep = file->private_data;
981
982 vfree(ep->buf);
983 kfree(ep);
984
985 return 0;
986}
987
988static const struct file_operations fops_eeprom = {
989 .open = open_file_eeprom,
990 .read = read_file_eeprom,
991 .release = release_file_eeprom,
992 .owner = THIS_MODULE,
993};
994
Bruno Randolf3cfd43f2010-06-07 13:11:40 +0900995
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200996void
Pavel Roskine0d687b2011-07-14 20:21:55 -0400997ath5k_debug_init_device(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +0200998{
Felix Fietkau5b7916a2011-04-10 18:32:18 +0200999 struct dentry *phydir;
1000
Pavel Roskine0d687b2011-07-14 20:21:55 -04001001 ah->debug.level = ath5k_debug;
Bruno Randolfbe9b7252008-01-23 10:27:51 +09001002
Pavel Roskine0d687b2011-07-14 20:21:55 -04001003 phydir = debugfs_create_dir("ath5k", ah->hw->wiphy->debugfsdir);
Felix Fietkau5b7916a2011-04-10 18:32:18 +02001004 if (!phydir)
Pavel Roskine4bbf2f2011-07-07 18:14:13 -04001005 return;
Bruno Randolfbe9b7252008-01-23 10:27:51 +09001006
Joe Perches2ef00c52018-03-23 15:54:37 -07001007 debugfs_create_file("debug", 0600, phydir, ah, &fops_debug);
1008 debugfs_create_file("registers", 0400, phydir, ah, &fops_registers);
1009 debugfs_create_file("beacon", 0600, phydir, ah, &fops_beacon);
1010 debugfs_create_file("reset", 0200, phydir, ah, &fops_reset);
1011 debugfs_create_file("antenna", 0600, phydir, ah, &fops_antenna);
1012 debugfs_create_file("misc", 0400, phydir, ah, &fops_misc);
1013 debugfs_create_file("eeprom", 0400, phydir, ah, &fops_eeprom);
1014 debugfs_create_file("frameerrors", 0600, phydir, ah, &fops_frameerrors);
1015 debugfs_create_file("ani", 0600, phydir, ah, &fops_ani);
1016 debugfs_create_file("queue", 0600, phydir, ah, &fops_queue);
1017 debugfs_create_bool("32khz_clock", 0600, phydir,
Pavel Roskine0d687b2011-07-14 20:21:55 -04001018 &ah->ah_use_32khz_clock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001019}
1020
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001021/* functions used in other places */
1022
1023void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001024ath5k_debug_dump_bands(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001025{
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001026 unsigned int b, i;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001027
Pavel Roskine0d687b2011-07-14 20:21:55 -04001028 if (likely(!(ah->debug.level & ATH5K_DEBUG_DUMPBANDS)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001029 return;
1030
Pavel Roskine0d687b2011-07-14 20:21:55 -04001031 BUG_ON(!ah->sbands);
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001032
Johannes Berg57fbcce2016-04-12 15:56:15 +02001033 for (b = 0; b < NUM_NL80211_BANDS; b++) {
Pavel Roskine0d687b2011-07-14 20:21:55 -04001034 struct ieee80211_supported_band *band = &ah->sbands[b];
Bob Copelandb7fcb5c2009-04-27 22:12:43 -04001035 char bname[6];
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001036 switch (band->band) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02001037 case NL80211_BAND_2GHZ:
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001038 strcpy(bname, "2 GHz");
1039 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001040 case NL80211_BAND_5GHZ:
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001041 strcpy(bname, "5 GHz");
1042 break;
1043 default:
1044 printk(KERN_DEBUG "Band not supported: %d\n",
1045 band->band);
1046 return;
1047 }
1048 printk(KERN_DEBUG "Band %s: channels %d, rates %d\n", bname,
1049 band->n_channels, band->n_bitrates);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001050 printk(KERN_DEBUG " channels:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001051 for (i = 0; i < band->n_channels; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001052 printk(KERN_DEBUG " %3d %d %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001053 ieee80211_frequency_to_channel(
1054 band->channels[i].center_freq),
1055 band->channels[i].center_freq,
1056 band->channels[i].hw_value,
1057 band->channels[i].flags);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001058 printk(KERN_DEBUG " rates:\n");
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001059 for (i = 0; i < band->n_bitrates; i++)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001060 printk(KERN_DEBUG " %4d %.4x %.4x %.4x\n",
Luis R. Rodriguezb4461972008-02-04 10:03:54 -05001061 band->bitrates[i].bitrate,
1062 band->bitrates[i].hw_value,
1063 band->bitrates[i].flags,
1064 band->bitrates[i].hw_value_short);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001065 }
1066}
1067
1068static inline void
Bruno Randolfb47f4072008-03-05 18:35:45 +09001069ath5k_debug_printrxbuf(struct ath5k_buf *bf, int done,
1070 struct ath5k_rx_status *rs)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001071{
1072 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001073 struct ath5k_hw_all_rx_desc *rd = &ds->ud.ds_rx;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001074
1075 printk(KERN_DEBUG "R (%p %llx) %08x %08x %08x %08x %08x %08x %c\n",
1076 ds, (unsigned long long)bf->daddr,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001077 ds->ds_link, ds->ds_data,
1078 rd->rx_ctl.rx_control_0, rd->rx_ctl.rx_control_1,
Bruno Randolf62412a82010-06-16 19:12:12 +09001079 rd->rx_stat.rx_status_0, rd->rx_stat.rx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001080 !done ? ' ' : (rs->rs_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001081}
1082
1083void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001084ath5k_debug_printrxbuffs(struct ath5k_hw *ah)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001085{
1086 struct ath5k_desc *ds;
1087 struct ath5k_buf *bf;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001088 struct ath5k_rx_status rs = {};
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001089 int status;
1090
Pavel Roskine0d687b2011-07-14 20:21:55 -04001091 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001092 return;
1093
Bruno Randolf265faad2010-06-16 19:11:30 +09001094 printk(KERN_DEBUG "rxdp %x, rxlink %p\n",
Pavel Roskine0d687b2011-07-14 20:21:55 -04001095 ath5k_hw_get_rxdp(ah), ah->rxlink);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001096
Pavel Roskine0d687b2011-07-14 20:21:55 -04001097 spin_lock_bh(&ah->rxbuflock);
1098 list_for_each_entry(bf, &ah->rxbuf, list) {
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001099 ds = bf->desc;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001100 status = ah->ah_proc_rx_desc(ah, ds, &rs);
Bruno Randolfbe9b7252008-01-23 10:27:51 +09001101 if (!status)
Bruno Randolfb47f4072008-03-05 18:35:45 +09001102 ath5k_debug_printrxbuf(bf, status == 0, &rs);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001103 }
Pavel Roskine0d687b2011-07-14 20:21:55 -04001104 spin_unlock_bh(&ah->rxbuflock);
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001105}
1106
1107void
Pavel Roskine0d687b2011-07-14 20:21:55 -04001108ath5k_debug_printtxbuf(struct ath5k_hw *ah, struct ath5k_buf *bf)
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001109{
1110 struct ath5k_desc *ds = bf->desc;
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001111 struct ath5k_hw_5212_tx_desc *td = &ds->ud.ds_tx5212;
Bruno Randolfb47f4072008-03-05 18:35:45 +09001112 struct ath5k_tx_status ts = {};
1113 int done;
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001114
Pavel Roskine0d687b2011-07-14 20:21:55 -04001115 if (likely(!(ah->debug.level & ATH5K_DEBUG_DESC)))
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001116 return;
1117
Pavel Roskine0d687b2011-07-14 20:21:55 -04001118 done = ah->ah_proc_tx_desc(ah, bf->desc, &ts);
Bruno Randolfb47f4072008-03-05 18:35:45 +09001119
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001120 printk(KERN_DEBUG "T (%p %llx) %08x %08x %08x %08x %08x %08x %08x "
1121 "%08x %c\n", ds, (unsigned long long)bf->daddr, ds->ds_link,
Bruno Randolf19fd6e52008-03-05 18:35:23 +09001122 ds->ds_data, td->tx_ctl.tx_control_0, td->tx_ctl.tx_control_1,
1123 td->tx_ctl.tx_control_2, td->tx_ctl.tx_control_3,
1124 td->tx_stat.tx_status_0, td->tx_stat.tx_status_1,
Bruno Randolfb47f4072008-03-05 18:35:45 +09001125 done ? ' ' : (ts.ts_status == 0) ? '*' : '!');
Jiri Slabyfa1c1142007-08-12 17:33:16 +02001126}