blob: 43e71a944cb17331340e2460b9f0fae79323e9da [file] [log] [blame]
Sujith88b126a2008-11-28 22:19:02 +05301/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Sujith88b126a2008-11-28 22:19:02 +05303 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Gabor Juhos52103112009-03-06 09:57:39 +010018#include <asm/unaligned.h>
19
Sujith394cf0a2009-02-09 13:26:54 +053020#include "ath9k.h"
Sujith88b126a2008-11-28 22:19:02 +053021
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -040022#define REG_WRITE_D(_ah, _reg, _val) \
23 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
24#define REG_READ_D(_ah, _reg) \
25 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
26
Gabor Juhos19d8bc22009-03-05 16:55:18 +010027static struct dentry *ath9k_debugfs_root;
28
Sujith2a163c62008-11-28 22:21:08 +053029static int ath9k_debugfs_open(struct inode *inode, struct file *file)
30{
31 file->private_data = inode->i_private;
32 return 0;
33}
34
Felix Fietkaua830df02009-11-23 22:33:27 +010035#ifdef CONFIG_ATH_DEBUG
36
Jeff Hansen24939282009-05-27 12:48:29 +000037static ssize_t read_file_debug(struct file *file, char __user *user_buf,
38 size_t count, loff_t *ppos)
39{
40 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070041 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000042 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053043 unsigned int len;
44
Dan Carpenter2b87f3a2010-05-14 15:24:37 +020045 len = sprintf(buf, "0x%08x\n", common->debug_mask);
Jeff Hansen24939282009-05-27 12:48:29 +000046 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
47}
48
49static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
50 size_t count, loff_t *ppos)
51{
52 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070053 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000054 unsigned long mask;
55 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053056 ssize_t len;
57
58 len = min(count, sizeof(buf) - 1);
59 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +020060 return -EFAULT;
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053061
62 buf[len] = '\0';
63 if (strict_strtoul(buf, 0, &mask))
64 return -EINVAL;
65
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070066 common->debug_mask = mask;
Jeff Hansen24939282009-05-27 12:48:29 +000067 return count;
68}
69
70static const struct file_operations fops_debug = {
71 .read = read_file_debug,
72 .write = write_file_debug,
73 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +020074 .owner = THIS_MODULE,
75 .llseek = default_llseek,
Jeff Hansen24939282009-05-27 12:48:29 +000076};
77
Felix Fietkaua830df02009-11-23 22:33:27 +010078#endif
79
Pavel Roskin991a0982010-01-29 17:22:26 -050080#define DMA_BUF_LEN 1024
81
Felix Fietkau15340692010-05-11 17:23:01 +020082static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
83 size_t count, loff_t *ppos)
84{
85 struct ath_softc *sc = file->private_data;
86 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
87 char buf[32];
88 unsigned int len;
89
Dan Carpenter2b87f3a2010-05-14 15:24:37 +020090 len = sprintf(buf, "0x%08x\n", common->tx_chainmask);
Felix Fietkau15340692010-05-11 17:23:01 +020091 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
92}
93
94static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
95 size_t count, loff_t *ppos)
96{
97 struct ath_softc *sc = file->private_data;
98 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
99 unsigned long mask;
100 char buf[32];
101 ssize_t len;
102
103 len = min(count, sizeof(buf) - 1);
104 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200105 return -EFAULT;
Felix Fietkau15340692010-05-11 17:23:01 +0200106
107 buf[len] = '\0';
108 if (strict_strtoul(buf, 0, &mask))
109 return -EINVAL;
110
111 common->tx_chainmask = mask;
112 sc->sc_ah->caps.tx_chainmask = mask;
113 return count;
114}
115
116static const struct file_operations fops_tx_chainmask = {
117 .read = read_file_tx_chainmask,
118 .write = write_file_tx_chainmask,
119 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200120 .owner = THIS_MODULE,
121 .llseek = default_llseek,
Felix Fietkau15340692010-05-11 17:23:01 +0200122};
123
124
125static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
126 size_t count, loff_t *ppos)
127{
128 struct ath_softc *sc = file->private_data;
129 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
130 char buf[32];
131 unsigned int len;
132
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200133 len = sprintf(buf, "0x%08x\n", common->rx_chainmask);
Felix Fietkau15340692010-05-11 17:23:01 +0200134 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
135}
136
137static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
138 size_t count, loff_t *ppos)
139{
140 struct ath_softc *sc = file->private_data;
141 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
142 unsigned long mask;
143 char buf[32];
144 ssize_t len;
145
146 len = min(count, sizeof(buf) - 1);
147 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200148 return -EFAULT;
Felix Fietkau15340692010-05-11 17:23:01 +0200149
150 buf[len] = '\0';
151 if (strict_strtoul(buf, 0, &mask))
152 return -EINVAL;
153
154 common->rx_chainmask = mask;
155 sc->sc_ah->caps.rx_chainmask = mask;
156 return count;
157}
158
159static const struct file_operations fops_rx_chainmask = {
160 .read = read_file_rx_chainmask,
161 .write = write_file_rx_chainmask,
162 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200163 .owner = THIS_MODULE,
164 .llseek = default_llseek,
Felix Fietkau15340692010-05-11 17:23:01 +0200165};
166
167
Sujith2a163c62008-11-28 22:21:08 +0530168static ssize_t read_file_dma(struct file *file, char __user *user_buf,
169 size_t count, loff_t *ppos)
170{
171 struct ath_softc *sc = file->private_data;
Sujithcbe61d82009-02-09 13:27:12 +0530172 struct ath_hw *ah = sc->sc_ah;
Pavel Roskin991a0982010-01-29 17:22:26 -0500173 char *buf;
174 int retval;
Sujith2a163c62008-11-28 22:21:08 +0530175 unsigned int len = 0;
176 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
177 int i, qcuOffset = 0, dcuOffset = 0;
178 u32 *qcuBase = &val[0], *dcuBase = &val[4];
179
Pavel Roskin991a0982010-01-29 17:22:26 -0500180 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
181 if (!buf)
Dan Carpenter04236062010-05-14 15:25:39 +0200182 return -ENOMEM;
Pavel Roskin991a0982010-01-29 17:22:26 -0500183
Sujith7cf4a2e2009-08-26 11:11:57 +0530184 ath9k_ps_wakeup(sc);
185
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400186 REG_WRITE_D(ah, AR_MACMISC,
Sujith2a163c62008-11-28 22:21:08 +0530187 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
188 (AR_MACMISC_MISC_OBS_BUS_1 <<
189 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
190
Pavel Roskin991a0982010-01-29 17:22:26 -0500191 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530192 "Raw DMA Debug values:\n");
193
194 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
195 if (i % 4 == 0)
Pavel Roskin991a0982010-01-29 17:22:26 -0500196 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530197
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400198 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
Pavel Roskin991a0982010-01-29 17:22:26 -0500199 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
Sujith2a163c62008-11-28 22:21:08 +0530200 i, val[i]);
201 }
202
Pavel Roskin991a0982010-01-29 17:22:26 -0500203 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
204 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530205 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
206
207 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
208 if (i == 8) {
209 qcuOffset = 0;
210 qcuBase++;
211 }
212
213 if (i == 6) {
214 dcuOffset = 0;
215 dcuBase++;
216 }
217
Pavel Roskin991a0982010-01-29 17:22:26 -0500218 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530219 "%2d %2x %1x %2x %2x\n",
220 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
221 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
222 val[2] & (0x7 << (i * 3)) >> (i * 3),
223 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
224 }
225
Pavel Roskin991a0982010-01-29 17:22:26 -0500226 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530227
Pavel Roskin991a0982010-01-29 17:22:26 -0500228 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530229 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
230 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
Pavel Roskin991a0982010-01-29 17:22:26 -0500231 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530232 "qcu_complete state: %2x dcu_complete state: %2x\n",
233 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
Pavel Roskin991a0982010-01-29 17:22:26 -0500234 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530235 "dcu_arb state: %2x dcu_fp state: %2x\n",
236 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
Pavel Roskin991a0982010-01-29 17:22:26 -0500237 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530238 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
239 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
Pavel Roskin991a0982010-01-29 17:22:26 -0500240 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530241 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
242 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
Pavel Roskin991a0982010-01-29 17:22:26 -0500243 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530244 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
245 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
246
Frans Pop60ece402010-03-24 19:46:30 +0100247 len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400248 REG_READ_D(ah, AR_OBS_BUS_1));
Pavel Roskin991a0982010-01-29 17:22:26 -0500249 len += snprintf(buf + len, DMA_BUF_LEN - len,
Frans Pop60ece402010-03-24 19:46:30 +0100250 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
Sujith2a163c62008-11-28 22:21:08 +0530251
Sujith7cf4a2e2009-08-26 11:11:57 +0530252 ath9k_ps_restore(sc);
253
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200254 if (len > DMA_BUF_LEN)
255 len = DMA_BUF_LEN;
256
Pavel Roskin991a0982010-01-29 17:22:26 -0500257 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
258 kfree(buf);
259 return retval;
Sujith2a163c62008-11-28 22:21:08 +0530260}
261
262static const struct file_operations fops_dma = {
263 .read = read_file_dma,
264 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200265 .owner = THIS_MODULE,
266 .llseek = default_llseek,
Sujith2a163c62008-11-28 22:21:08 +0530267};
268
Sujith817e11d2008-12-07 21:42:44 +0530269
270void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
271{
272 if (status)
Sujith17d79042009-02-09 13:27:03 +0530273 sc->debug.stats.istats.total++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400274 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
275 if (status & ATH9K_INT_RXLP)
276 sc->debug.stats.istats.rxlp++;
277 if (status & ATH9K_INT_RXHP)
278 sc->debug.stats.istats.rxhp++;
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400279 if (status & ATH9K_INT_BB_WATCHDOG)
280 sc->debug.stats.istats.bb_watchdog++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400281 } else {
282 if (status & ATH9K_INT_RX)
283 sc->debug.stats.istats.rxok++;
284 }
Sujith817e11d2008-12-07 21:42:44 +0530285 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530286 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530287 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530288 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530289 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530290 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530291 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530292 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530293 if (status & ATH9K_INT_MIB)
Sujith17d79042009-02-09 13:27:03 +0530294 sc->debug.stats.istats.mib++;
Sujith817e11d2008-12-07 21:42:44 +0530295 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530296 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530297 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530298 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530299 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530300 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530301 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530302 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530303 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530304 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530305 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530306 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530307 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530308 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530309 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530310 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530311 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530312 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530313 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530314 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530315 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530316 sc->debug.stats.istats.dtim++;
Sujith817e11d2008-12-07 21:42:44 +0530317}
318
319static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
320 size_t count, loff_t *ppos)
321{
322 struct ath_softc *sc = file->private_data;
323 char buf[512];
324 unsigned int len = 0;
325
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400326 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
327 len += snprintf(buf + len, sizeof(buf) - len,
328 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
329 len += snprintf(buf + len, sizeof(buf) - len,
330 "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400331 len += snprintf(buf + len, sizeof(buf) - len,
332 "%8s: %10u\n", "WATCHDOG",
333 sc->debug.stats.istats.bb_watchdog);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400334 } else {
335 len += snprintf(buf + len, sizeof(buf) - len,
336 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
337 }
Sujith817e11d2008-12-07 21:42:44 +0530338 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530339 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
Sujith817e11d2008-12-07 21:42:44 +0530340 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530341 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
Sujith817e11d2008-12-07 21:42:44 +0530342 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530343 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
Sujith817e11d2008-12-07 21:42:44 +0530344 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530345 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
Sujith817e11d2008-12-07 21:42:44 +0530346 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530347 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
Sujith817e11d2008-12-07 21:42:44 +0530348 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530349 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
Sujith817e11d2008-12-07 21:42:44 +0530350 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530351 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
Sujith817e11d2008-12-07 21:42:44 +0530352 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530353 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
Sujith817e11d2008-12-07 21:42:44 +0530354 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530355 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
Sujith817e11d2008-12-07 21:42:44 +0530356 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530357 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
Sujith817e11d2008-12-07 21:42:44 +0530358 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530359 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
Sujith817e11d2008-12-07 21:42:44 +0530360 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530361 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
Sujith817e11d2008-12-07 21:42:44 +0530362 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530363 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
Sujith817e11d2008-12-07 21:42:44 +0530364 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530365 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
Sujith817e11d2008-12-07 21:42:44 +0530366 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530367 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
Sujith817e11d2008-12-07 21:42:44 +0530368 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530369 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
Sujith817e11d2008-12-07 21:42:44 +0530370 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530371 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
Sujith817e11d2008-12-07 21:42:44 +0530372
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200373 if (len > sizeof(buf))
374 len = sizeof(buf);
375
Sujith817e11d2008-12-07 21:42:44 +0530376 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
377}
378
379static const struct file_operations fops_interrupt = {
380 .read = read_file_interrupt,
381 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200382 .owner = THIS_MODULE,
383 .llseek = default_llseek,
Sujith817e11d2008-12-07 21:42:44 +0530384};
385
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200386static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
387{
388 switch (state) {
389 case ATH_WIPHY_INACTIVE:
390 return "INACTIVE";
391 case ATH_WIPHY_ACTIVE:
392 return "ACTIVE";
393 case ATH_WIPHY_PAUSING:
394 return "PAUSING";
395 case ATH_WIPHY_PAUSED:
396 return "PAUSED";
397 case ATH_WIPHY_SCAN:
398 return "SCAN";
399 }
400 return "?";
401}
402
403static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
404 size_t count, loff_t *ppos)
405{
406 struct ath_softc *sc = file->private_data;
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530407 struct ath_wiphy *aphy = sc->pri_wiphy;
408 struct ieee80211_channel *chan = aphy->hw->conf.channel;
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200409 char buf[512];
410 unsigned int len = 0;
411 int i;
412 u8 addr[ETH_ALEN];
Ben Greear39057512010-09-14 12:46:04 -0700413 u32 tmp;
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200414
415 len += snprintf(buf + len, sizeof(buf) - len,
416 "primary: %s (%s chan=%d ht=%d)\n",
417 wiphy_name(sc->pri_wiphy->hw->wiphy),
418 ath_wiphy_state_str(sc->pri_wiphy->state),
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530419 ieee80211_frequency_to_channel(chan->center_freq),
420 aphy->chan_is_ht);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200421
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400422 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
423 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200424 len += snprintf(buf + len, sizeof(buf) - len,
425 "addr: %pM\n", addr);
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400426 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
427 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200428 len += snprintf(buf + len, sizeof(buf) - len,
429 "addrmask: %pM\n", addr);
Ben Greear39057512010-09-14 12:46:04 -0700430 tmp = ath9k_hw_getrxfilter(sc->sc_ah);
431 len += snprintf(buf + len, sizeof(buf) - len,
432 "rfilt: 0x%x", tmp);
433 if (tmp & ATH9K_RX_FILTER_UCAST)
434 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
435 if (tmp & ATH9K_RX_FILTER_MCAST)
436 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
437 if (tmp & ATH9K_RX_FILTER_BCAST)
438 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
439 if (tmp & ATH9K_RX_FILTER_CONTROL)
440 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
441 if (tmp & ATH9K_RX_FILTER_BEACON)
442 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
443 if (tmp & ATH9K_RX_FILTER_PROM)
444 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
445 if (tmp & ATH9K_RX_FILTER_PROBEREQ)
446 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
447 if (tmp & ATH9K_RX_FILTER_PHYERR)
448 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
449 if (tmp & ATH9K_RX_FILTER_MYBEACON)
450 len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
451 if (tmp & ATH9K_RX_FILTER_COMP_BAR)
452 len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
453 if (tmp & ATH9K_RX_FILTER_PSPOLL)
454 len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
455 if (tmp & ATH9K_RX_FILTER_PHYRADAR)
456 len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
457 if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
458 len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n");
459 else
460 len += snprintf(buf + len, sizeof(buf) - len, "\n");
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200461
Ben Greear39057512010-09-14 12:46:04 -0700462 /* Put variable-length stuff down here, and check for overflows. */
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200463 for (i = 0; i < sc->num_sec_wiphy; i++) {
464 struct ath_wiphy *aphy = sc->sec_wiphy[i];
465 if (aphy == NULL)
466 continue;
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530467 chan = aphy->hw->conf.channel;
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200468 len += snprintf(buf + len, sizeof(buf) - len,
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530469 "secondary: %s (%s chan=%d ht=%d)\n",
470 wiphy_name(aphy->hw->wiphy),
471 ath_wiphy_state_str(aphy->state),
472 ieee80211_frequency_to_channel(chan->center_freq),
473 aphy->chan_is_ht);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200474 }
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200475 if (len > sizeof(buf))
476 len = sizeof(buf);
477
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200478 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
479}
480
481static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
482{
483 int i;
484 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
485 return sc->pri_wiphy;
486 for (i = 0; i < sc->num_sec_wiphy; i++) {
487 struct ath_wiphy *aphy = sc->sec_wiphy[i];
488 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
489 return aphy;
490 }
491 return NULL;
492}
493
494static int del_wiphy(struct ath_softc *sc, const char *name)
495{
496 struct ath_wiphy *aphy = get_wiphy(sc, name);
497 if (!aphy)
498 return -ENOENT;
499 return ath9k_wiphy_del(aphy);
500}
501
502static int pause_wiphy(struct ath_softc *sc, const char *name)
503{
504 struct ath_wiphy *aphy = get_wiphy(sc, name);
505 if (!aphy)
506 return -ENOENT;
507 return ath9k_wiphy_pause(aphy);
508}
509
510static int unpause_wiphy(struct ath_softc *sc, const char *name)
511{
512 struct ath_wiphy *aphy = get_wiphy(sc, name);
513 if (!aphy)
514 return -ENOENT;
515 return ath9k_wiphy_unpause(aphy);
516}
517
518static int select_wiphy(struct ath_softc *sc, const char *name)
519{
520 struct ath_wiphy *aphy = get_wiphy(sc, name);
521 if (!aphy)
522 return -ENOENT;
523 return ath9k_wiphy_select(aphy);
524}
525
526static int schedule_wiphy(struct ath_softc *sc, const char *msec)
527{
528 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
529 return 0;
530}
531
532static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
533 size_t count, loff_t *ppos)
534{
535 struct ath_softc *sc = file->private_data;
536 char buf[50];
537 size_t len;
538
539 len = min(count, sizeof(buf) - 1);
540 if (copy_from_user(buf, user_buf, len))
541 return -EFAULT;
542 buf[len] = '\0';
543 if (len > 0 && buf[len - 1] == '\n')
544 buf[len - 1] = '\0';
545
546 if (strncmp(buf, "add", 3) == 0) {
547 int res = ath9k_wiphy_add(sc);
548 if (res < 0)
549 return res;
550 } else if (strncmp(buf, "del=", 4) == 0) {
551 int res = del_wiphy(sc, buf + 4);
552 if (res < 0)
553 return res;
554 } else if (strncmp(buf, "pause=", 6) == 0) {
555 int res = pause_wiphy(sc, buf + 6);
556 if (res < 0)
557 return res;
558 } else if (strncmp(buf, "unpause=", 8) == 0) {
559 int res = unpause_wiphy(sc, buf + 8);
560 if (res < 0)
561 return res;
562 } else if (strncmp(buf, "select=", 7) == 0) {
563 int res = select_wiphy(sc, buf + 7);
564 if (res < 0)
565 return res;
566 } else if (strncmp(buf, "schedule=", 9) == 0) {
567 int res = schedule_wiphy(sc, buf + 9);
568 if (res < 0)
569 return res;
570 } else
571 return -EOPNOTSUPP;
572
573 return count;
574}
575
576static const struct file_operations fops_wiphy = {
577 .read = read_file_wiphy,
578 .write = write_file_wiphy,
579 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200580 .owner = THIS_MODULE,
581 .llseek = default_llseek,
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200582};
583
Sujithfec247c2009-07-27 12:08:16 +0530584#define PR(str, elem) \
585 do { \
586 len += snprintf(buf + len, size - len, \
587 "%s%13u%11u%10u%10u\n", str, \
Felix Fietkau1d2231e2010-06-12 00:33:51 -0400588 sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BE]].elem, \
589 sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BK]].elem, \
590 sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VI]].elem, \
591 sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VO]].elem); \
Sujithfec247c2009-07-27 12:08:16 +0530592} while(0)
593
594static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
595 size_t count, loff_t *ppos)
596{
597 struct ath_softc *sc = file->private_data;
598 char *buf;
599 unsigned int len = 0, size = 2048;
600 ssize_t retval = 0;
601
602 buf = kzalloc(size, GFP_KERNEL);
603 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200604 return -ENOMEM;
Sujithfec247c2009-07-27 12:08:16 +0530605
606 len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
607
608 PR("MPDUs Queued: ", queued);
609 PR("MPDUs Completed: ", completed);
610 PR("Aggregates: ", a_aggr);
611 PR("AMPDUs Queued: ", a_queued);
612 PR("AMPDUs Completed:", a_completed);
613 PR("AMPDUs Retried: ", a_retries);
614 PR("AMPDUs XRetried: ", a_xretries);
615 PR("FIFO Underrun: ", fifo_underrun);
616 PR("TXOP Exceeded: ", xtxop);
617 PR("TXTIMER Expiry: ", timer_exp);
618 PR("DESC CFG Error: ", desc_cfg_err);
619 PR("DATA Underrun: ", data_underrun);
620 PR("DELIM Underrun: ", delim_underrun);
Ben Greear99c15bf2010-10-01 12:26:30 -0700621 PR("TX-Pkts-All: ", tx_pkts_all);
622 PR("TX-Bytes-All: ", tx_bytes_all);
Sujithfec247c2009-07-27 12:08:16 +0530623
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200624 if (len > size)
625 len = size;
626
Sujithfec247c2009-07-27 12:08:16 +0530627 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
628 kfree(buf);
629
630 return retval;
631}
632
633void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700634 struct ath_buf *bf, struct ath_tx_status *ts)
Sujithfec247c2009-07-27 12:08:16 +0530635{
Ben Greear99c15bf2010-10-01 12:26:30 -0700636 TX_STAT_INC(txq->axq_qnum, tx_pkts_all);
637 sc->debug.stats.txstats[txq->axq_qnum].tx_bytes_all += bf->bf_mpdu->len;
638
Sujithfec247c2009-07-27 12:08:16 +0530639 if (bf_isampdu(bf)) {
640 if (bf_isxretried(bf))
641 TX_STAT_INC(txq->axq_qnum, a_xretries);
642 else
643 TX_STAT_INC(txq->axq_qnum, a_completed);
644 } else {
645 TX_STAT_INC(txq->axq_qnum, completed);
646 }
647
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700648 if (ts->ts_status & ATH9K_TXERR_FIFO)
Sujithfec247c2009-07-27 12:08:16 +0530649 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700650 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Sujithfec247c2009-07-27 12:08:16 +0530651 TX_STAT_INC(txq->axq_qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700652 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Sujithfec247c2009-07-27 12:08:16 +0530653 TX_STAT_INC(txq->axq_qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700654 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Sujithfec247c2009-07-27 12:08:16 +0530655 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700656 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Sujithfec247c2009-07-27 12:08:16 +0530657 TX_STAT_INC(txq->axq_qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700658 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Sujithfec247c2009-07-27 12:08:16 +0530659 TX_STAT_INC(txq->axq_qnum, delim_underrun);
660}
661
662static const struct file_operations fops_xmit = {
663 .read = read_file_xmit,
664 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200665 .owner = THIS_MODULE,
666 .llseek = default_llseek,
Sujithfec247c2009-07-27 12:08:16 +0530667};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200668
Sujith1395d3f2010-01-08 10:36:11 +0530669static ssize_t read_file_recv(struct file *file, char __user *user_buf,
670 size_t count, loff_t *ppos)
671{
672#define PHY_ERR(s, p) \
673 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
674 sc->debug.stats.rxstats.phy_err_stats[p]);
675
676 struct ath_softc *sc = file->private_data;
677 char *buf;
678 unsigned int len = 0, size = 1152;
679 ssize_t retval = 0;
680
681 buf = kzalloc(size, GFP_KERNEL);
682 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200683 return -ENOMEM;
Sujith1395d3f2010-01-08 10:36:11 +0530684
685 len += snprintf(buf + len, size - len,
686 "%18s : %10u\n", "CRC ERR",
687 sc->debug.stats.rxstats.crc_err);
688 len += snprintf(buf + len, size - len,
689 "%18s : %10u\n", "DECRYPT CRC ERR",
690 sc->debug.stats.rxstats.decrypt_crc_err);
691 len += snprintf(buf + len, size - len,
692 "%18s : %10u\n", "PHY ERR",
693 sc->debug.stats.rxstats.phy_err);
694 len += snprintf(buf + len, size - len,
695 "%18s : %10u\n", "MIC ERR",
696 sc->debug.stats.rxstats.mic_err);
697 len += snprintf(buf + len, size - len,
698 "%18s : %10u\n", "PRE-DELIM CRC ERR",
699 sc->debug.stats.rxstats.pre_delim_crc_err);
700 len += snprintf(buf + len, size - len,
701 "%18s : %10u\n", "POST-DELIM CRC ERR",
702 sc->debug.stats.rxstats.post_delim_crc_err);
703 len += snprintf(buf + len, size - len,
704 "%18s : %10u\n", "DECRYPT BUSY ERR",
705 sc->debug.stats.rxstats.decrypt_busy_err);
706
707 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
708 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
709 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
710 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
711 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
712 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
713 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
714 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
715 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
716 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
717 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
718 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
719 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
720 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
721 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
722 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
723 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
724 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
725 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
726 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
727 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
728 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
729 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
730 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
731 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
732 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
733
Ben Greear99c15bf2010-10-01 12:26:30 -0700734 len += snprintf(buf + len, size - len,
735 "%18s : %10u\n", "RX-Pkts-All",
736 sc->debug.stats.rxstats.rx_pkts_all);
737 len += snprintf(buf + len, size - len,
738 "%18s : %10u\n", "RX-Bytes-All",
739 sc->debug.stats.rxstats.rx_bytes_all);
740
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200741 if (len > size)
742 len = size;
743
Sujith1395d3f2010-01-08 10:36:11 +0530744 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
745 kfree(buf);
746
747 return retval;
748
749#undef PHY_ERR
750}
751
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700752void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +0530753{
754#define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
755#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
756
Sujith1395d3f2010-01-08 10:36:11 +0530757 u32 phyerr;
758
Ben Greear99c15bf2010-10-01 12:26:30 -0700759 RX_STAT_INC(rx_pkts_all);
760 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
761
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700762 if (rs->rs_status & ATH9K_RXERR_CRC)
Sujith1395d3f2010-01-08 10:36:11 +0530763 RX_STAT_INC(crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700764 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
Sujith1395d3f2010-01-08 10:36:11 +0530765 RX_STAT_INC(decrypt_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700766 if (rs->rs_status & ATH9K_RXERR_MIC)
Sujith1395d3f2010-01-08 10:36:11 +0530767 RX_STAT_INC(mic_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700768 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
Sujith1395d3f2010-01-08 10:36:11 +0530769 RX_STAT_INC(pre_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700770 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
Sujith1395d3f2010-01-08 10:36:11 +0530771 RX_STAT_INC(post_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700772 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
Sujith1395d3f2010-01-08 10:36:11 +0530773 RX_STAT_INC(decrypt_busy_err);
774
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700775 if (rs->rs_status & ATH9K_RXERR_PHY) {
Sujith1395d3f2010-01-08 10:36:11 +0530776 RX_STAT_INC(phy_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700777 phyerr = rs->rs_phyerr & 0x24;
Sujith1395d3f2010-01-08 10:36:11 +0530778 RX_PHY_ERR_INC(phyerr);
779 }
780
781#undef RX_STAT_INC
782#undef RX_PHY_ERR_INC
783}
784
785static const struct file_operations fops_recv = {
786 .read = read_file_recv,
787 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200788 .owner = THIS_MODULE,
789 .llseek = default_llseek,
Sujith1395d3f2010-01-08 10:36:11 +0530790};
791
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200792static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
793 size_t count, loff_t *ppos)
794{
795 struct ath_softc *sc = file->private_data;
796 char buf[32];
797 unsigned int len;
798
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200799 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200800 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
801}
802
803static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
804 size_t count, loff_t *ppos)
805{
806 struct ath_softc *sc = file->private_data;
807 unsigned long regidx;
808 char buf[32];
809 ssize_t len;
810
811 len = min(count, sizeof(buf) - 1);
812 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200813 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200814
815 buf[len] = '\0';
816 if (strict_strtoul(buf, 0, &regidx))
817 return -EINVAL;
818
819 sc->debug.regidx = regidx;
820 return count;
821}
822
823static const struct file_operations fops_regidx = {
824 .read = read_file_regidx,
825 .write = write_file_regidx,
826 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200827 .owner = THIS_MODULE,
828 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200829};
830
831static ssize_t read_file_regval(struct file *file, char __user *user_buf,
832 size_t count, loff_t *ppos)
833{
834 struct ath_softc *sc = file->private_data;
835 struct ath_hw *ah = sc->sc_ah;
836 char buf[32];
837 unsigned int len;
838 u32 regval;
839
840 regval = REG_READ_D(ah, sc->debug.regidx);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200841 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200842 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
843}
844
845static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
846 size_t count, loff_t *ppos)
847{
848 struct ath_softc *sc = file->private_data;
849 struct ath_hw *ah = sc->sc_ah;
850 unsigned long regval;
851 char buf[32];
852 ssize_t len;
853
854 len = min(count, sizeof(buf) - 1);
855 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200856 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200857
858 buf[len] = '\0';
859 if (strict_strtoul(buf, 0, &regval))
860 return -EINVAL;
861
862 REG_WRITE_D(ah, sc->debug.regidx, regval);
863 return count;
864}
865
866static const struct file_operations fops_regval = {
867 .read = read_file_regval,
868 .write = write_file_regval,
869 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200870 .owner = THIS_MODULE,
871 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200872};
873
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700874int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +0530875{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400876 struct ath_common *common = ath9k_hw_common(ah);
877 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700878
Sujith7dd58742009-03-30 15:28:42 +0530879 if (!ath9k_debugfs_root)
880 return -ENOENT;
881
Sujith17d79042009-02-09 13:27:03 +0530882 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100883 ath9k_debugfs_root);
Sujith17d79042009-02-09 13:27:03 +0530884 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200885 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +0530886
Felix Fietkaua830df02009-11-23 22:33:27 +0100887#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200888 if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
889 sc->debug.debugfs_phy, sc, &fops_debug))
Jeff Hansen24939282009-05-27 12:48:29 +0000890 goto err;
Felix Fietkaua830df02009-11-23 22:33:27 +0100891#endif
Jeff Hansen24939282009-05-27 12:48:29 +0000892
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200893 if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
894 sc, &fops_dma))
Sujith2a163c62008-11-28 22:21:08 +0530895 goto err;
896
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200897 if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
898 sc, &fops_interrupt))
Sujith817e11d2008-12-07 21:42:44 +0530899 goto err;
900
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200901 if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
902 sc->debug.debugfs_phy, sc, &fops_wiphy))
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200903 goto err;
904
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200905 if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
906 sc, &fops_xmit))
Sujithfec247c2009-07-27 12:08:16 +0530907 goto err;
908
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200909 if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
910 sc, &fops_recv))
Sujith1395d3f2010-01-08 10:36:11 +0530911 goto err;
912
Felix Fietkau15340692010-05-11 17:23:01 +0200913 if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
914 sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
915 goto err;
916
917 if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
918 sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
919 goto err;
920
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200921 if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
922 sc->debug.debugfs_phy, sc, &fops_regidx))
923 goto err;
924
925 if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
926 sc->debug.debugfs_phy, sc, &fops_regval))
927 goto err;
928
Felix Fietkau41f3e542010-06-12 00:33:56 -0400929 if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
930 sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
931 goto err;
932
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200933 sc->debug.regidx = 0;
Sujith826d2682008-11-28 22:20:23 +0530934 return 0;
935err:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700936 ath9k_exit_debug(ah);
Sujith826d2682008-11-28 22:20:23 +0530937 return -ENOMEM;
938}
939
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700940void ath9k_exit_debug(struct ath_hw *ah)
Sujith826d2682008-11-28 22:20:23 +0530941{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400942 struct ath_common *common = ath9k_hw_common(ah);
943 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700944
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200945 debugfs_remove_recursive(sc->debug.debugfs_phy);
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100946}
947
948int ath9k_debug_create_root(void)
949{
950 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
951 if (!ath9k_debugfs_root)
952 return -ENOENT;
953
954 return 0;
955}
956
957void ath9k_debug_remove_root(void)
958{
959 debugfs_remove(ath9k_debugfs_root);
960 ath9k_debugfs_root = NULL;
Sujith88b126a2008-11-28 22:19:02 +0530961}