blob: 0c3c74c157fb036123322ae7176f51543ae3f999 [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++) {
Luis R. Rodriguez191d6a12010-10-15 13:27:49 -0700464 struct ath_wiphy *aphy_tmp = sc->sec_wiphy[i];
465 if (aphy_tmp == NULL)
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200466 continue;
Luis R. Rodriguez191d6a12010-10-15 13:27:49 -0700467 chan = aphy_tmp->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",
Luis R. Rodriguez191d6a12010-10-15 13:27:49 -0700470 wiphy_name(aphy_tmp->hw->wiphy),
471 ath_wiphy_state_str(aphy_tmp->state),
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530472 ieee80211_frequency_to_channel(chan->center_freq),
Luis R. Rodriguez191d6a12010-10-15 13:27:49 -0700473 aphy_tmp->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 Fietkau066dae92010-11-07 14:59:39 +0100588 sc->debug.stats.txstats[WME_AC_BE].elem, \
589 sc->debug.stats.txstats[WME_AC_BK].elem, \
590 sc->debug.stats.txstats[WME_AC_VI].elem, \
591 sc->debug.stats.txstats[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
Felix Fietkau066dae92010-11-07 14:59:39 +0100633void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
634 struct ath_tx_status *ts)
Sujithfec247c2009-07-27 12:08:16 +0530635{
Felix Fietkau066dae92010-11-07 14:59:39 +0100636 int qnum = skb_get_queue_mapping(bf->bf_mpdu);
637
638 TX_STAT_INC(qnum, tx_pkts_all);
639 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
Ben Greear99c15bf2010-10-01 12:26:30 -0700640
Sujithfec247c2009-07-27 12:08:16 +0530641 if (bf_isampdu(bf)) {
642 if (bf_isxretried(bf))
Felix Fietkau066dae92010-11-07 14:59:39 +0100643 TX_STAT_INC(qnum, a_xretries);
Sujithfec247c2009-07-27 12:08:16 +0530644 else
Felix Fietkau066dae92010-11-07 14:59:39 +0100645 TX_STAT_INC(qnum, a_completed);
Sujithfec247c2009-07-27 12:08:16 +0530646 } else {
Felix Fietkau066dae92010-11-07 14:59:39 +0100647 TX_STAT_INC(qnum, completed);
Sujithfec247c2009-07-27 12:08:16 +0530648 }
649
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700650 if (ts->ts_status & ATH9K_TXERR_FIFO)
Felix Fietkau066dae92010-11-07 14:59:39 +0100651 TX_STAT_INC(qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700652 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Felix Fietkau066dae92010-11-07 14:59:39 +0100653 TX_STAT_INC(qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700654 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Felix Fietkau066dae92010-11-07 14:59:39 +0100655 TX_STAT_INC(qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700656 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100657 TX_STAT_INC(qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700658 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100659 TX_STAT_INC(qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700660 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100661 TX_STAT_INC(qnum, delim_underrun);
Sujithfec247c2009-07-27 12:08:16 +0530662}
663
664static const struct file_operations fops_xmit = {
665 .read = read_file_xmit,
666 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200667 .owner = THIS_MODULE,
668 .llseek = default_llseek,
Sujithfec247c2009-07-27 12:08:16 +0530669};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200670
Sujith1395d3f2010-01-08 10:36:11 +0530671static ssize_t read_file_recv(struct file *file, char __user *user_buf,
672 size_t count, loff_t *ppos)
673{
674#define PHY_ERR(s, p) \
675 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
676 sc->debug.stats.rxstats.phy_err_stats[p]);
677
678 struct ath_softc *sc = file->private_data;
679 char *buf;
680 unsigned int len = 0, size = 1152;
681 ssize_t retval = 0;
682
683 buf = kzalloc(size, GFP_KERNEL);
684 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200685 return -ENOMEM;
Sujith1395d3f2010-01-08 10:36:11 +0530686
687 len += snprintf(buf + len, size - len,
688 "%18s : %10u\n", "CRC ERR",
689 sc->debug.stats.rxstats.crc_err);
690 len += snprintf(buf + len, size - len,
691 "%18s : %10u\n", "DECRYPT CRC ERR",
692 sc->debug.stats.rxstats.decrypt_crc_err);
693 len += snprintf(buf + len, size - len,
694 "%18s : %10u\n", "PHY ERR",
695 sc->debug.stats.rxstats.phy_err);
696 len += snprintf(buf + len, size - len,
697 "%18s : %10u\n", "MIC ERR",
698 sc->debug.stats.rxstats.mic_err);
699 len += snprintf(buf + len, size - len,
700 "%18s : %10u\n", "PRE-DELIM CRC ERR",
701 sc->debug.stats.rxstats.pre_delim_crc_err);
702 len += snprintf(buf + len, size - len,
703 "%18s : %10u\n", "POST-DELIM CRC ERR",
704 sc->debug.stats.rxstats.post_delim_crc_err);
705 len += snprintf(buf + len, size - len,
706 "%18s : %10u\n", "DECRYPT BUSY ERR",
707 sc->debug.stats.rxstats.decrypt_busy_err);
708
709 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
710 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
711 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
712 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
713 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
714 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
715 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
716 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
717 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
718 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
719 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
720 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
721 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
722 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
723 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
724 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
725 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
726 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
727 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
728 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
729 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
730 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
731 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
732 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
733 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
734 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
735
Ben Greear99c15bf2010-10-01 12:26:30 -0700736 len += snprintf(buf + len, size - len,
737 "%18s : %10u\n", "RX-Pkts-All",
738 sc->debug.stats.rxstats.rx_pkts_all);
739 len += snprintf(buf + len, size - len,
740 "%18s : %10u\n", "RX-Bytes-All",
741 sc->debug.stats.rxstats.rx_bytes_all);
742
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200743 if (len > size)
744 len = size;
745
Sujith1395d3f2010-01-08 10:36:11 +0530746 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
747 kfree(buf);
748
749 return retval;
750
751#undef PHY_ERR
752}
753
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700754void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +0530755{
756#define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
757#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
758
Sujith1395d3f2010-01-08 10:36:11 +0530759 u32 phyerr;
760
Ben Greear99c15bf2010-10-01 12:26:30 -0700761 RX_STAT_INC(rx_pkts_all);
762 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
763
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700764 if (rs->rs_status & ATH9K_RXERR_CRC)
Sujith1395d3f2010-01-08 10:36:11 +0530765 RX_STAT_INC(crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700766 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
Sujith1395d3f2010-01-08 10:36:11 +0530767 RX_STAT_INC(decrypt_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700768 if (rs->rs_status & ATH9K_RXERR_MIC)
Sujith1395d3f2010-01-08 10:36:11 +0530769 RX_STAT_INC(mic_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700770 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
Sujith1395d3f2010-01-08 10:36:11 +0530771 RX_STAT_INC(pre_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700772 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
Sujith1395d3f2010-01-08 10:36:11 +0530773 RX_STAT_INC(post_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700774 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
Sujith1395d3f2010-01-08 10:36:11 +0530775 RX_STAT_INC(decrypt_busy_err);
776
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700777 if (rs->rs_status & ATH9K_RXERR_PHY) {
Sujith1395d3f2010-01-08 10:36:11 +0530778 RX_STAT_INC(phy_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700779 phyerr = rs->rs_phyerr & 0x24;
Sujith1395d3f2010-01-08 10:36:11 +0530780 RX_PHY_ERR_INC(phyerr);
781 }
782
783#undef RX_STAT_INC
784#undef RX_PHY_ERR_INC
785}
786
787static const struct file_operations fops_recv = {
788 .read = read_file_recv,
789 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200790 .owner = THIS_MODULE,
791 .llseek = default_llseek,
Sujith1395d3f2010-01-08 10:36:11 +0530792};
793
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200794static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
795 size_t count, loff_t *ppos)
796{
797 struct ath_softc *sc = file->private_data;
798 char buf[32];
799 unsigned int len;
800
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200801 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200802 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
803}
804
805static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
806 size_t count, loff_t *ppos)
807{
808 struct ath_softc *sc = file->private_data;
809 unsigned long regidx;
810 char buf[32];
811 ssize_t len;
812
813 len = min(count, sizeof(buf) - 1);
814 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200815 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200816
817 buf[len] = '\0';
818 if (strict_strtoul(buf, 0, &regidx))
819 return -EINVAL;
820
821 sc->debug.regidx = regidx;
822 return count;
823}
824
825static const struct file_operations fops_regidx = {
826 .read = read_file_regidx,
827 .write = write_file_regidx,
828 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200829 .owner = THIS_MODULE,
830 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200831};
832
833static ssize_t read_file_regval(struct file *file, char __user *user_buf,
834 size_t count, loff_t *ppos)
835{
836 struct ath_softc *sc = file->private_data;
837 struct ath_hw *ah = sc->sc_ah;
838 char buf[32];
839 unsigned int len;
840 u32 regval;
841
842 regval = REG_READ_D(ah, sc->debug.regidx);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200843 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200844 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
845}
846
847static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
848 size_t count, loff_t *ppos)
849{
850 struct ath_softc *sc = file->private_data;
851 struct ath_hw *ah = sc->sc_ah;
852 unsigned long regval;
853 char buf[32];
854 ssize_t len;
855
856 len = min(count, sizeof(buf) - 1);
857 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200858 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200859
860 buf[len] = '\0';
861 if (strict_strtoul(buf, 0, &regval))
862 return -EINVAL;
863
864 REG_WRITE_D(ah, sc->debug.regidx, regval);
865 return count;
866}
867
868static const struct file_operations fops_regval = {
869 .read = read_file_regval,
870 .write = write_file_regval,
871 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200872 .owner = THIS_MODULE,
873 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200874};
875
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700876int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +0530877{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400878 struct ath_common *common = ath9k_hw_common(ah);
879 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700880
Sujith7dd58742009-03-30 15:28:42 +0530881 if (!ath9k_debugfs_root)
882 return -ENOENT;
883
Sujith17d79042009-02-09 13:27:03 +0530884 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100885 ath9k_debugfs_root);
Sujith17d79042009-02-09 13:27:03 +0530886 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200887 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +0530888
Felix Fietkaua830df02009-11-23 22:33:27 +0100889#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200890 if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
891 sc->debug.debugfs_phy, sc, &fops_debug))
Jeff Hansen24939282009-05-27 12:48:29 +0000892 goto err;
Felix Fietkaua830df02009-11-23 22:33:27 +0100893#endif
Jeff Hansen24939282009-05-27 12:48:29 +0000894
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200895 if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
896 sc, &fops_dma))
Sujith2a163c62008-11-28 22:21:08 +0530897 goto err;
898
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200899 if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
900 sc, &fops_interrupt))
Sujith817e11d2008-12-07 21:42:44 +0530901 goto err;
902
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200903 if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
904 sc->debug.debugfs_phy, sc, &fops_wiphy))
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200905 goto err;
906
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200907 if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
908 sc, &fops_xmit))
Sujithfec247c2009-07-27 12:08:16 +0530909 goto err;
910
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200911 if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
912 sc, &fops_recv))
Sujith1395d3f2010-01-08 10:36:11 +0530913 goto err;
914
Felix Fietkau15340692010-05-11 17:23:01 +0200915 if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
916 sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
917 goto err;
918
919 if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
920 sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
921 goto err;
922
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200923 if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
924 sc->debug.debugfs_phy, sc, &fops_regidx))
925 goto err;
926
927 if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
928 sc->debug.debugfs_phy, sc, &fops_regval))
929 goto err;
930
Felix Fietkau41f3e542010-06-12 00:33:56 -0400931 if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
932 sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
933 goto err;
934
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200935 sc->debug.regidx = 0;
Sujith826d2682008-11-28 22:20:23 +0530936 return 0;
937err:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700938 ath9k_exit_debug(ah);
Sujith826d2682008-11-28 22:20:23 +0530939 return -ENOMEM;
940}
941
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700942void ath9k_exit_debug(struct ath_hw *ah)
Sujith826d2682008-11-28 22:20:23 +0530943{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400944 struct ath_common *common = ath9k_hw_common(ah);
945 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700946
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200947 debugfs_remove_recursive(sc->debug.debugfs_phy);
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100948}
949
950int ath9k_debug_create_root(void)
951{
952 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
953 if (!ath9k_debugfs_root)
954 return -ENOENT;
955
956 return 0;
957}
958
959void ath9k_debug_remove_root(void)
960{
961 debugfs_remove(ath9k_debugfs_root);
962 ath9k_debugfs_root = NULL;
Sujith88b126a2008-11-28 22:19:02 +0530963}