blob: ad7107164f20ea2b7c371ed133605019d230b81e [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))
60 return -EINVAL;
61
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,
74 .owner = THIS_MODULE
75};
76
Felix Fietkaua830df02009-11-23 22:33:27 +010077#endif
78
Pavel Roskin991a0982010-01-29 17:22:26 -050079#define DMA_BUF_LEN 1024
80
Felix Fietkau15340692010-05-11 17:23:01 +020081static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
82 size_t count, loff_t *ppos)
83{
84 struct ath_softc *sc = file->private_data;
85 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
86 char buf[32];
87 unsigned int len;
88
Dan Carpenter2b87f3a2010-05-14 15:24:37 +020089 len = sprintf(buf, "0x%08x\n", common->tx_chainmask);
Felix Fietkau15340692010-05-11 17:23:01 +020090 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
91}
92
93static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
94 size_t count, loff_t *ppos)
95{
96 struct ath_softc *sc = file->private_data;
97 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
98 unsigned long mask;
99 char buf[32];
100 ssize_t len;
101
102 len = min(count, sizeof(buf) - 1);
103 if (copy_from_user(buf, user_buf, len))
104 return -EINVAL;
105
106 buf[len] = '\0';
107 if (strict_strtoul(buf, 0, &mask))
108 return -EINVAL;
109
110 common->tx_chainmask = mask;
111 sc->sc_ah->caps.tx_chainmask = mask;
112 return count;
113}
114
115static const struct file_operations fops_tx_chainmask = {
116 .read = read_file_tx_chainmask,
117 .write = write_file_tx_chainmask,
118 .open = ath9k_debugfs_open,
119 .owner = THIS_MODULE
120};
121
122
123static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
124 size_t count, loff_t *ppos)
125{
126 struct ath_softc *sc = file->private_data;
127 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
128 char buf[32];
129 unsigned int len;
130
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200131 len = sprintf(buf, "0x%08x\n", common->rx_chainmask);
Felix Fietkau15340692010-05-11 17:23:01 +0200132 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
133}
134
135static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
136 size_t count, loff_t *ppos)
137{
138 struct ath_softc *sc = file->private_data;
139 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
140 unsigned long mask;
141 char buf[32];
142 ssize_t len;
143
144 len = min(count, sizeof(buf) - 1);
145 if (copy_from_user(buf, user_buf, len))
146 return -EINVAL;
147
148 buf[len] = '\0';
149 if (strict_strtoul(buf, 0, &mask))
150 return -EINVAL;
151
152 common->rx_chainmask = mask;
153 sc->sc_ah->caps.rx_chainmask = mask;
154 return count;
155}
156
157static const struct file_operations fops_rx_chainmask = {
158 .read = read_file_rx_chainmask,
159 .write = write_file_rx_chainmask,
160 .open = ath9k_debugfs_open,
161 .owner = THIS_MODULE
162};
163
164
Sujith2a163c62008-11-28 22:21:08 +0530165static ssize_t read_file_dma(struct file *file, char __user *user_buf,
166 size_t count, loff_t *ppos)
167{
168 struct ath_softc *sc = file->private_data;
Sujithcbe61d82009-02-09 13:27:12 +0530169 struct ath_hw *ah = sc->sc_ah;
Pavel Roskin991a0982010-01-29 17:22:26 -0500170 char *buf;
171 int retval;
Sujith2a163c62008-11-28 22:21:08 +0530172 unsigned int len = 0;
173 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
174 int i, qcuOffset = 0, dcuOffset = 0;
175 u32 *qcuBase = &val[0], *dcuBase = &val[4];
176
Pavel Roskin991a0982010-01-29 17:22:26 -0500177 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
178 if (!buf)
179 return 0;
180
Sujith7cf4a2e2009-08-26 11:11:57 +0530181 ath9k_ps_wakeup(sc);
182
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400183 REG_WRITE_D(ah, AR_MACMISC,
Sujith2a163c62008-11-28 22:21:08 +0530184 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
185 (AR_MACMISC_MISC_OBS_BUS_1 <<
186 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
187
Pavel Roskin991a0982010-01-29 17:22:26 -0500188 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530189 "Raw DMA Debug values:\n");
190
191 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
192 if (i % 4 == 0)
Pavel Roskin991a0982010-01-29 17:22:26 -0500193 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530194
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400195 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
Pavel Roskin991a0982010-01-29 17:22:26 -0500196 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
Sujith2a163c62008-11-28 22:21:08 +0530197 i, val[i]);
198 }
199
Pavel Roskin991a0982010-01-29 17:22:26 -0500200 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
201 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530202 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
203
204 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
205 if (i == 8) {
206 qcuOffset = 0;
207 qcuBase++;
208 }
209
210 if (i == 6) {
211 dcuOffset = 0;
212 dcuBase++;
213 }
214
Pavel Roskin991a0982010-01-29 17:22:26 -0500215 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530216 "%2d %2x %1x %2x %2x\n",
217 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
218 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
219 val[2] & (0x7 << (i * 3)) >> (i * 3),
220 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
221 }
222
Pavel Roskin991a0982010-01-29 17:22:26 -0500223 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530224
Pavel Roskin991a0982010-01-29 17:22:26 -0500225 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530226 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
227 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
Pavel Roskin991a0982010-01-29 17:22:26 -0500228 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530229 "qcu_complete state: %2x dcu_complete state: %2x\n",
230 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
Pavel Roskin991a0982010-01-29 17:22:26 -0500231 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530232 "dcu_arb state: %2x dcu_fp state: %2x\n",
233 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
Pavel Roskin991a0982010-01-29 17:22:26 -0500234 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530235 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
236 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
Pavel Roskin991a0982010-01-29 17:22:26 -0500237 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530238 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
239 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
Pavel Roskin991a0982010-01-29 17:22:26 -0500240 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530241 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
242 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
243
Frans Pop60ece402010-03-24 19:46:30 +0100244 len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400245 REG_READ_D(ah, AR_OBS_BUS_1));
Pavel Roskin991a0982010-01-29 17:22:26 -0500246 len += snprintf(buf + len, DMA_BUF_LEN - len,
Frans Pop60ece402010-03-24 19:46:30 +0100247 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
Sujith2a163c62008-11-28 22:21:08 +0530248
Sujith7cf4a2e2009-08-26 11:11:57 +0530249 ath9k_ps_restore(sc);
250
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200251 if (len > DMA_BUF_LEN)
252 len = DMA_BUF_LEN;
253
Pavel Roskin991a0982010-01-29 17:22:26 -0500254 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
255 kfree(buf);
256 return retval;
Sujith2a163c62008-11-28 22:21:08 +0530257}
258
259static const struct file_operations fops_dma = {
260 .read = read_file_dma,
261 .open = ath9k_debugfs_open,
262 .owner = THIS_MODULE
263};
264
Sujith817e11d2008-12-07 21:42:44 +0530265
266void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
267{
268 if (status)
Sujith17d79042009-02-09 13:27:03 +0530269 sc->debug.stats.istats.total++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400270 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
271 if (status & ATH9K_INT_RXLP)
272 sc->debug.stats.istats.rxlp++;
273 if (status & ATH9K_INT_RXHP)
274 sc->debug.stats.istats.rxhp++;
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400275 if (status & ATH9K_INT_BB_WATCHDOG)
276 sc->debug.stats.istats.bb_watchdog++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400277 } else {
278 if (status & ATH9K_INT_RX)
279 sc->debug.stats.istats.rxok++;
280 }
Sujith817e11d2008-12-07 21:42:44 +0530281 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530282 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530283 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530284 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530285 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530286 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530287 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530288 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530289 if (status & ATH9K_INT_MIB)
Sujith17d79042009-02-09 13:27:03 +0530290 sc->debug.stats.istats.mib++;
Sujith817e11d2008-12-07 21:42:44 +0530291 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530292 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530293 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530294 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530295 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530296 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530297 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530298 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530299 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530300 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530301 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530302 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530303 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530304 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530305 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530306 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530307 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530308 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530309 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530310 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530311 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530312 sc->debug.stats.istats.dtim++;
Sujith817e11d2008-12-07 21:42:44 +0530313}
314
315static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
316 size_t count, loff_t *ppos)
317{
318 struct ath_softc *sc = file->private_data;
319 char buf[512];
320 unsigned int len = 0;
321
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400322 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
323 len += snprintf(buf + len, sizeof(buf) - len,
324 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
325 len += snprintf(buf + len, sizeof(buf) - len,
326 "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400327 len += snprintf(buf + len, sizeof(buf) - len,
328 "%8s: %10u\n", "WATCHDOG",
329 sc->debug.stats.istats.bb_watchdog);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400330 } else {
331 len += snprintf(buf + len, sizeof(buf) - len,
332 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
333 }
Sujith817e11d2008-12-07 21:42:44 +0530334 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530335 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
Sujith817e11d2008-12-07 21:42:44 +0530336 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530337 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
Sujith817e11d2008-12-07 21:42:44 +0530338 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530339 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
Sujith817e11d2008-12-07 21:42:44 +0530340 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530341 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
Sujith817e11d2008-12-07 21:42:44 +0530342 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530343 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
Sujith817e11d2008-12-07 21:42:44 +0530344 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530345 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
Sujith817e11d2008-12-07 21:42:44 +0530346 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530347 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
Sujith817e11d2008-12-07 21:42:44 +0530348 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530349 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
Sujith817e11d2008-12-07 21:42:44 +0530350 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530351 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
Sujith817e11d2008-12-07 21:42:44 +0530352 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530353 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
Sujith817e11d2008-12-07 21:42:44 +0530354 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530355 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
Sujith817e11d2008-12-07 21:42:44 +0530356 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530357 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
Sujith817e11d2008-12-07 21:42:44 +0530358 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530359 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
Sujith817e11d2008-12-07 21:42:44 +0530360 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530361 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
Sujith817e11d2008-12-07 21:42:44 +0530362 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530363 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
Sujith817e11d2008-12-07 21:42:44 +0530364 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530365 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
Sujith817e11d2008-12-07 21:42:44 +0530366 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530367 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
Sujith817e11d2008-12-07 21:42:44 +0530368
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200369 if (len > sizeof(buf))
370 len = sizeof(buf);
371
Sujith817e11d2008-12-07 21:42:44 +0530372 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
373}
374
375static const struct file_operations fops_interrupt = {
376 .read = read_file_interrupt,
377 .open = ath9k_debugfs_open,
378 .owner = THIS_MODULE
379};
380
Felix Fietkau545750d2009-11-23 22:21:01 +0100381void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
Sujith7a7dec62009-01-30 14:32:09 +0530382{
Jeff Hansenbedf0872009-05-27 12:48:28 +0000383 struct ath_rc_stats *stats;
Sujith7a7dec62009-01-30 14:32:09 +0530384
Felix Fietkau545750d2009-11-23 22:21:01 +0100385 stats = &sc->debug.stats.rcstats[final_rate];
Jeff Hansenbedf0872009-05-27 12:48:28 +0000386 stats->success++;
Sujith7a7dec62009-01-30 14:32:09 +0530387}
388
Sujith029bc432009-02-04 08:10:26 +0530389void ath_debug_stat_retries(struct ath_softc *sc, int rix,
Sujith9e712792009-02-20 15:13:20 +0530390 int xretries, int retries, u8 per)
Sujith029bc432009-02-04 08:10:26 +0530391{
Jeff Hansenbedf0872009-05-27 12:48:28 +0000392 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
Sujith029bc432009-02-04 08:10:26 +0530393
Jeff Hansenbedf0872009-05-27 12:48:28 +0000394 stats->xretries += xretries;
395 stats->retries += retries;
396 stats->per = per;
Sujith7a7dec62009-01-30 14:32:09 +0530397}
398
399static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
400 size_t count, loff_t *ppos)
401{
402 struct ath_softc *sc = file->private_data;
Jeff Hansenbedf0872009-05-27 12:48:28 +0000403 char *buf;
404 unsigned int len = 0, max;
405 int i = 0;
406 ssize_t retval;
Sujith7a7dec62009-01-30 14:32:09 +0530407
Sujith62b4fb62009-03-09 09:32:01 +0530408 if (sc->cur_rate_table == NULL)
409 return 0;
410
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200411 max = 80 + sc->cur_rate_table->rate_cnt * 1024 + 1;
412 buf = kmalloc(max, GFP_KERNEL);
Jeff Hansenbedf0872009-05-27 12:48:28 +0000413 if (buf == NULL)
414 return 0;
Jeff Hansenbedf0872009-05-27 12:48:28 +0000415
Luis R. Rodriguezc755ad32009-12-07 12:38:41 -0500416 len += sprintf(buf, "%6s %6s %6s "
417 "%10s %10s %10s %10s\n",
418 "HT", "MCS", "Rate",
419 "Success", "Retries", "XRetries", "PER");
Jeff Hansenbedf0872009-05-27 12:48:28 +0000420
421 for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
422 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
423 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
Luis R. Rodriguezc755ad32009-12-07 12:38:41 -0500424 char mcs[5];
425 char htmode[5];
426 int used_mcs = 0, used_htmode = 0;
427
428 if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) {
429 used_mcs = snprintf(mcs, 5, "%d",
430 sc->cur_rate_table->info[i].ratecode);
431
432 if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy))
433 used_htmode = snprintf(htmode, 5, "HT40");
434 else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy))
435 used_htmode = snprintf(htmode, 5, "HT20");
436 else
437 used_htmode = snprintf(htmode, 5, "????");
438 }
439
440 mcs[used_mcs] = '\0';
441 htmode[used_htmode] = '\0';
Jeff Hansenbedf0872009-05-27 12:48:28 +0000442
443 len += snprintf(buf + len, max - len,
Luis R. Rodriguezc755ad32009-12-07 12:38:41 -0500444 "%6s %6s %3u.%d: "
445 "%10u %10u %10u %10u\n",
446 htmode,
447 mcs,
448 ratekbps / 1000,
449 (ratekbps % 1000) / 100,
450 stats->success,
451 stats->retries,
452 stats->xretries,
Jeff Hansenbedf0872009-05-27 12:48:28 +0000453 stats->per);
454 }
455
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200456 if (len > max)
457 len = max;
458
Jeff Hansenbedf0872009-05-27 12:48:28 +0000459 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
460 kfree(buf);
461 return retval;
Sujith7a7dec62009-01-30 14:32:09 +0530462}
463
464static const struct file_operations fops_rcstat = {
465 .read = read_file_rcstat,
466 .open = ath9k_debugfs_open,
467 .owner = THIS_MODULE
468};
Alina Friedrichsen27abe062009-01-23 05:44:21 +0100469
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200470static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
471{
472 switch (state) {
473 case ATH_WIPHY_INACTIVE:
474 return "INACTIVE";
475 case ATH_WIPHY_ACTIVE:
476 return "ACTIVE";
477 case ATH_WIPHY_PAUSING:
478 return "PAUSING";
479 case ATH_WIPHY_PAUSED:
480 return "PAUSED";
481 case ATH_WIPHY_SCAN:
482 return "SCAN";
483 }
484 return "?";
485}
486
487static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
488 size_t count, loff_t *ppos)
489{
490 struct ath_softc *sc = file->private_data;
491 char buf[512];
492 unsigned int len = 0;
493 int i;
494 u8 addr[ETH_ALEN];
495
496 len += snprintf(buf + len, sizeof(buf) - len,
497 "primary: %s (%s chan=%d ht=%d)\n",
498 wiphy_name(sc->pri_wiphy->hw->wiphy),
499 ath_wiphy_state_str(sc->pri_wiphy->state),
500 sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
501 for (i = 0; i < sc->num_sec_wiphy; i++) {
502 struct ath_wiphy *aphy = sc->sec_wiphy[i];
503 if (aphy == NULL)
504 continue;
505 len += snprintf(buf + len, sizeof(buf) - len,
506 "secondary: %s (%s chan=%d ht=%d)\n",
507 wiphy_name(aphy->hw->wiphy),
508 ath_wiphy_state_str(aphy->state),
509 aphy->chan_idx, aphy->chan_is_ht);
510 }
511
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400512 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
513 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200514 len += snprintf(buf + len, sizeof(buf) - len,
515 "addr: %pM\n", addr);
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400516 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
517 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200518 len += snprintf(buf + len, sizeof(buf) - len,
519 "addrmask: %pM\n", addr);
520
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200521 if (len > sizeof(buf))
522 len = sizeof(buf);
523
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200524 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
525}
526
527static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
528{
529 int i;
530 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
531 return sc->pri_wiphy;
532 for (i = 0; i < sc->num_sec_wiphy; i++) {
533 struct ath_wiphy *aphy = sc->sec_wiphy[i];
534 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
535 return aphy;
536 }
537 return NULL;
538}
539
540static int del_wiphy(struct ath_softc *sc, const char *name)
541{
542 struct ath_wiphy *aphy = get_wiphy(sc, name);
543 if (!aphy)
544 return -ENOENT;
545 return ath9k_wiphy_del(aphy);
546}
547
548static int pause_wiphy(struct ath_softc *sc, const char *name)
549{
550 struct ath_wiphy *aphy = get_wiphy(sc, name);
551 if (!aphy)
552 return -ENOENT;
553 return ath9k_wiphy_pause(aphy);
554}
555
556static int unpause_wiphy(struct ath_softc *sc, const char *name)
557{
558 struct ath_wiphy *aphy = get_wiphy(sc, name);
559 if (!aphy)
560 return -ENOENT;
561 return ath9k_wiphy_unpause(aphy);
562}
563
564static int select_wiphy(struct ath_softc *sc, const char *name)
565{
566 struct ath_wiphy *aphy = get_wiphy(sc, name);
567 if (!aphy)
568 return -ENOENT;
569 return ath9k_wiphy_select(aphy);
570}
571
572static int schedule_wiphy(struct ath_softc *sc, const char *msec)
573{
574 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
575 return 0;
576}
577
578static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
579 size_t count, loff_t *ppos)
580{
581 struct ath_softc *sc = file->private_data;
582 char buf[50];
583 size_t len;
584
585 len = min(count, sizeof(buf) - 1);
586 if (copy_from_user(buf, user_buf, len))
587 return -EFAULT;
588 buf[len] = '\0';
589 if (len > 0 && buf[len - 1] == '\n')
590 buf[len - 1] = '\0';
591
592 if (strncmp(buf, "add", 3) == 0) {
593 int res = ath9k_wiphy_add(sc);
594 if (res < 0)
595 return res;
596 } else if (strncmp(buf, "del=", 4) == 0) {
597 int res = del_wiphy(sc, buf + 4);
598 if (res < 0)
599 return res;
600 } else if (strncmp(buf, "pause=", 6) == 0) {
601 int res = pause_wiphy(sc, buf + 6);
602 if (res < 0)
603 return res;
604 } else if (strncmp(buf, "unpause=", 8) == 0) {
605 int res = unpause_wiphy(sc, buf + 8);
606 if (res < 0)
607 return res;
608 } else if (strncmp(buf, "select=", 7) == 0) {
609 int res = select_wiphy(sc, buf + 7);
610 if (res < 0)
611 return res;
612 } else if (strncmp(buf, "schedule=", 9) == 0) {
613 int res = schedule_wiphy(sc, buf + 9);
614 if (res < 0)
615 return res;
616 } else
617 return -EOPNOTSUPP;
618
619 return count;
620}
621
622static const struct file_operations fops_wiphy = {
623 .read = read_file_wiphy,
624 .write = write_file_wiphy,
625 .open = ath9k_debugfs_open,
626 .owner = THIS_MODULE
627};
628
Sujithfec247c2009-07-27 12:08:16 +0530629#define PR(str, elem) \
630 do { \
631 len += snprintf(buf + len, size - len, \
632 "%s%13u%11u%10u%10u\n", str, \
633 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
634 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
635 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
636 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
637} while(0)
638
639static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
640 size_t count, loff_t *ppos)
641{
642 struct ath_softc *sc = file->private_data;
643 char *buf;
644 unsigned int len = 0, size = 2048;
645 ssize_t retval = 0;
646
647 buf = kzalloc(size, GFP_KERNEL);
648 if (buf == NULL)
649 return 0;
650
651 len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
652
653 PR("MPDUs Queued: ", queued);
654 PR("MPDUs Completed: ", completed);
655 PR("Aggregates: ", a_aggr);
656 PR("AMPDUs Queued: ", a_queued);
657 PR("AMPDUs Completed:", a_completed);
658 PR("AMPDUs Retried: ", a_retries);
659 PR("AMPDUs XRetried: ", a_xretries);
660 PR("FIFO Underrun: ", fifo_underrun);
661 PR("TXOP Exceeded: ", xtxop);
662 PR("TXTIMER Expiry: ", timer_exp);
663 PR("DESC CFG Error: ", desc_cfg_err);
664 PR("DATA Underrun: ", data_underrun);
665 PR("DELIM Underrun: ", delim_underrun);
666
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200667 if (len > size)
668 len = size;
669
Sujithfec247c2009-07-27 12:08:16 +0530670 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
671 kfree(buf);
672
673 return retval;
674}
675
676void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700677 struct ath_buf *bf, struct ath_tx_status *ts)
Sujithfec247c2009-07-27 12:08:16 +0530678{
Sujithfec247c2009-07-27 12:08:16 +0530679 if (bf_isampdu(bf)) {
680 if (bf_isxretried(bf))
681 TX_STAT_INC(txq->axq_qnum, a_xretries);
682 else
683 TX_STAT_INC(txq->axq_qnum, a_completed);
684 } else {
685 TX_STAT_INC(txq->axq_qnum, completed);
686 }
687
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700688 if (ts->ts_status & ATH9K_TXERR_FIFO)
Sujithfec247c2009-07-27 12:08:16 +0530689 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700690 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Sujithfec247c2009-07-27 12:08:16 +0530691 TX_STAT_INC(txq->axq_qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700692 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Sujithfec247c2009-07-27 12:08:16 +0530693 TX_STAT_INC(txq->axq_qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700694 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Sujithfec247c2009-07-27 12:08:16 +0530695 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700696 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Sujithfec247c2009-07-27 12:08:16 +0530697 TX_STAT_INC(txq->axq_qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700698 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Sujithfec247c2009-07-27 12:08:16 +0530699 TX_STAT_INC(txq->axq_qnum, delim_underrun);
700}
701
702static const struct file_operations fops_xmit = {
703 .read = read_file_xmit,
704 .open = ath9k_debugfs_open,
705 .owner = THIS_MODULE
706};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200707
Sujith1395d3f2010-01-08 10:36:11 +0530708static ssize_t read_file_recv(struct file *file, char __user *user_buf,
709 size_t count, loff_t *ppos)
710{
711#define PHY_ERR(s, p) \
712 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
713 sc->debug.stats.rxstats.phy_err_stats[p]);
714
715 struct ath_softc *sc = file->private_data;
716 char *buf;
717 unsigned int len = 0, size = 1152;
718 ssize_t retval = 0;
719
720 buf = kzalloc(size, GFP_KERNEL);
721 if (buf == NULL)
722 return 0;
723
724 len += snprintf(buf + len, size - len,
725 "%18s : %10u\n", "CRC ERR",
726 sc->debug.stats.rxstats.crc_err);
727 len += snprintf(buf + len, size - len,
728 "%18s : %10u\n", "DECRYPT CRC ERR",
729 sc->debug.stats.rxstats.decrypt_crc_err);
730 len += snprintf(buf + len, size - len,
731 "%18s : %10u\n", "PHY ERR",
732 sc->debug.stats.rxstats.phy_err);
733 len += snprintf(buf + len, size - len,
734 "%18s : %10u\n", "MIC ERR",
735 sc->debug.stats.rxstats.mic_err);
736 len += snprintf(buf + len, size - len,
737 "%18s : %10u\n", "PRE-DELIM CRC ERR",
738 sc->debug.stats.rxstats.pre_delim_crc_err);
739 len += snprintf(buf + len, size - len,
740 "%18s : %10u\n", "POST-DELIM CRC ERR",
741 sc->debug.stats.rxstats.post_delim_crc_err);
742 len += snprintf(buf + len, size - len,
743 "%18s : %10u\n", "DECRYPT BUSY ERR",
744 sc->debug.stats.rxstats.decrypt_busy_err);
745
746 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
747 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
748 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
749 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
750 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
751 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
752 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
753 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
754 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
755 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
756 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
757 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
758 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
759 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
760 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
761 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
762 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
763 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
764 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
765 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
766 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
767 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
768 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
769 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
770 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
771 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
772
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200773 if (len > size)
774 len = size;
775
Sujith1395d3f2010-01-08 10:36:11 +0530776 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
777 kfree(buf);
778
779 return retval;
780
781#undef PHY_ERR
782}
783
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700784void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +0530785{
786#define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
787#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
788
Sujith1395d3f2010-01-08 10:36:11 +0530789 u32 phyerr;
790
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700791 if (rs->rs_status & ATH9K_RXERR_CRC)
Sujith1395d3f2010-01-08 10:36:11 +0530792 RX_STAT_INC(crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700793 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
Sujith1395d3f2010-01-08 10:36:11 +0530794 RX_STAT_INC(decrypt_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700795 if (rs->rs_status & ATH9K_RXERR_MIC)
Sujith1395d3f2010-01-08 10:36:11 +0530796 RX_STAT_INC(mic_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700797 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
Sujith1395d3f2010-01-08 10:36:11 +0530798 RX_STAT_INC(pre_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700799 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
Sujith1395d3f2010-01-08 10:36:11 +0530800 RX_STAT_INC(post_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700801 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
Sujith1395d3f2010-01-08 10:36:11 +0530802 RX_STAT_INC(decrypt_busy_err);
803
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700804 if (rs->rs_status & ATH9K_RXERR_PHY) {
Sujith1395d3f2010-01-08 10:36:11 +0530805 RX_STAT_INC(phy_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700806 phyerr = rs->rs_phyerr & 0x24;
Sujith1395d3f2010-01-08 10:36:11 +0530807 RX_PHY_ERR_INC(phyerr);
808 }
809
810#undef RX_STAT_INC
811#undef RX_PHY_ERR_INC
812}
813
814static const struct file_operations fops_recv = {
815 .read = read_file_recv,
816 .open = ath9k_debugfs_open,
817 .owner = THIS_MODULE
818};
819
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200820static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
821 size_t count, loff_t *ppos)
822{
823 struct ath_softc *sc = file->private_data;
824 char buf[32];
825 unsigned int len;
826
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200827 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200828 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
829}
830
831static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
832 size_t count, loff_t *ppos)
833{
834 struct ath_softc *sc = file->private_data;
835 unsigned long regidx;
836 char buf[32];
837 ssize_t len;
838
839 len = min(count, sizeof(buf) - 1);
840 if (copy_from_user(buf, user_buf, len))
841 return -EINVAL;
842
843 buf[len] = '\0';
844 if (strict_strtoul(buf, 0, &regidx))
845 return -EINVAL;
846
847 sc->debug.regidx = regidx;
848 return count;
849}
850
851static const struct file_operations fops_regidx = {
852 .read = read_file_regidx,
853 .write = write_file_regidx,
854 .open = ath9k_debugfs_open,
855 .owner = THIS_MODULE
856};
857
858static ssize_t read_file_regval(struct file *file, char __user *user_buf,
859 size_t count, loff_t *ppos)
860{
861 struct ath_softc *sc = file->private_data;
862 struct ath_hw *ah = sc->sc_ah;
863 char buf[32];
864 unsigned int len;
865 u32 regval;
866
867 regval = REG_READ_D(ah, sc->debug.regidx);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200868 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200869 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
870}
871
872static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
873 size_t count, loff_t *ppos)
874{
875 struct ath_softc *sc = file->private_data;
876 struct ath_hw *ah = sc->sc_ah;
877 unsigned long regval;
878 char buf[32];
879 ssize_t len;
880
881 len = min(count, sizeof(buf) - 1);
882 if (copy_from_user(buf, user_buf, len))
883 return -EINVAL;
884
885 buf[len] = '\0';
886 if (strict_strtoul(buf, 0, &regval))
887 return -EINVAL;
888
889 REG_WRITE_D(ah, sc->debug.regidx, regval);
890 return count;
891}
892
893static const struct file_operations fops_regval = {
894 .read = read_file_regval,
895 .write = write_file_regval,
896 .open = ath9k_debugfs_open,
897 .owner = THIS_MODULE
898};
899
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700900int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +0530901{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400902 struct ath_common *common = ath9k_hw_common(ah);
903 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700904
Sujith7dd58742009-03-30 15:28:42 +0530905 if (!ath9k_debugfs_root)
906 return -ENOENT;
907
Sujith17d79042009-02-09 13:27:03 +0530908 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100909 ath9k_debugfs_root);
Sujith17d79042009-02-09 13:27:03 +0530910 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200911 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +0530912
Felix Fietkaua830df02009-11-23 22:33:27 +0100913#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200914 if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
915 sc->debug.debugfs_phy, sc, &fops_debug))
Jeff Hansen24939282009-05-27 12:48:29 +0000916 goto err;
Felix Fietkaua830df02009-11-23 22:33:27 +0100917#endif
Jeff Hansen24939282009-05-27 12:48:29 +0000918
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200919 if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
920 sc, &fops_dma))
Sujith2a163c62008-11-28 22:21:08 +0530921 goto err;
922
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200923 if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
924 sc, &fops_interrupt))
Sujith817e11d2008-12-07 21:42:44 +0530925 goto err;
926
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200927 if (!debugfs_create_file("rcstat", S_IRUSR, sc->debug.debugfs_phy,
928 sc, &fops_rcstat))
Sujith7a7dec62009-01-30 14:32:09 +0530929 goto err;
930
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200931 if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
932 sc->debug.debugfs_phy, sc, &fops_wiphy))
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200933 goto err;
934
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200935 if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
936 sc, &fops_xmit))
Sujithfec247c2009-07-27 12:08:16 +0530937 goto err;
938
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200939 if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
940 sc, &fops_recv))
Sujith1395d3f2010-01-08 10:36:11 +0530941 goto err;
942
Felix Fietkau15340692010-05-11 17:23:01 +0200943 if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
944 sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
945 goto err;
946
947 if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
948 sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
949 goto err;
950
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200951 if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
952 sc->debug.debugfs_phy, sc, &fops_regidx))
953 goto err;
954
955 if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
956 sc->debug.debugfs_phy, sc, &fops_regval))
957 goto err;
958
959 sc->debug.regidx = 0;
Sujith826d2682008-11-28 22:20:23 +0530960 return 0;
961err:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700962 ath9k_exit_debug(ah);
Sujith826d2682008-11-28 22:20:23 +0530963 return -ENOMEM;
964}
965
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700966void ath9k_exit_debug(struct ath_hw *ah)
Sujith826d2682008-11-28 22:20:23 +0530967{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400968 struct ath_common *common = ath9k_hw_common(ah);
969 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700970
Felix Fietkauc8a72c02010-05-11 17:23:00 +0200971 debugfs_remove_recursive(sc->debug.debugfs_phy);
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100972}
973
974int ath9k_debug_create_root(void)
975{
976 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
977 if (!ath9k_debugfs_root)
978 return -ENOENT;
979
980 return 0;
981}
982
983void ath9k_debug_remove_root(void)
984{
985 debugfs_remove(ath9k_debugfs_root);
986 ath9k_debugfs_root = NULL;
Sujith88b126a2008-11-28 22:19:02 +0530987}