blob: 9e009ccd006941b3debb68e7635ec75a9dde215e [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
Sujith2a163c62008-11-28 22:21:08 +053027static int ath9k_debugfs_open(struct inode *inode, struct file *file)
28{
29 file->private_data = inode->i_private;
30 return 0;
31}
32
Felix Fietkaua830df02009-11-23 22:33:27 +010033#ifdef CONFIG_ATH_DEBUG
34
Jeff Hansen24939282009-05-27 12:48:29 +000035static ssize_t read_file_debug(struct file *file, char __user *user_buf,
36 size_t count, loff_t *ppos)
37{
38 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070039 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000040 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053041 unsigned int len;
42
Dan Carpenter2b87f3a2010-05-14 15:24:37 +020043 len = sprintf(buf, "0x%08x\n", common->debug_mask);
Jeff Hansen24939282009-05-27 12:48:29 +000044 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
45}
46
47static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
48 size_t count, loff_t *ppos)
49{
50 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070051 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000052 unsigned long mask;
53 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053054 ssize_t len;
55
56 len = min(count, sizeof(buf) - 1);
57 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +020058 return -EFAULT;
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053059
60 buf[len] = '\0';
61 if (strict_strtoul(buf, 0, &mask))
62 return -EINVAL;
63
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070064 common->debug_mask = mask;
Jeff Hansen24939282009-05-27 12:48:29 +000065 return count;
66}
67
68static const struct file_operations fops_debug = {
69 .read = read_file_debug,
70 .write = write_file_debug,
71 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +020072 .owner = THIS_MODULE,
73 .llseek = default_llseek,
Jeff Hansen24939282009-05-27 12:48:29 +000074};
75
Felix Fietkaua830df02009-11-23 22:33:27 +010076#endif
77
Pavel Roskin991a0982010-01-29 17:22:26 -050078#define DMA_BUF_LEN 1024
79
Felix Fietkau15340692010-05-11 17:23:01 +020080static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
81 size_t count, loff_t *ppos)
82{
83 struct ath_softc *sc = file->private_data;
84 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
85 char buf[32];
86 unsigned int len;
87
Dan Carpenter2b87f3a2010-05-14 15:24:37 +020088 len = sprintf(buf, "0x%08x\n", common->tx_chainmask);
Felix Fietkau15340692010-05-11 17:23:01 +020089 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
90}
91
92static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
93 size_t count, loff_t *ppos)
94{
95 struct ath_softc *sc = file->private_data;
96 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
97 unsigned long mask;
98 char buf[32];
99 ssize_t len;
100
101 len = min(count, sizeof(buf) - 1);
102 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200103 return -EFAULT;
Felix Fietkau15340692010-05-11 17:23:01 +0200104
105 buf[len] = '\0';
106 if (strict_strtoul(buf, 0, &mask))
107 return -EINVAL;
108
109 common->tx_chainmask = mask;
110 sc->sc_ah->caps.tx_chainmask = mask;
111 return count;
112}
113
114static const struct file_operations fops_tx_chainmask = {
115 .read = read_file_tx_chainmask,
116 .write = write_file_tx_chainmask,
117 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200118 .owner = THIS_MODULE,
119 .llseek = default_llseek,
Felix Fietkau15340692010-05-11 17:23:01 +0200120};
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))
Dan Carpenter04236062010-05-14 15:25:39 +0200146 return -EFAULT;
Felix Fietkau15340692010-05-11 17:23:01 +0200147
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,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200161 .owner = THIS_MODULE,
162 .llseek = default_llseek,
Felix Fietkau15340692010-05-11 17:23:01 +0200163};
164
165
Sujith2a163c62008-11-28 22:21:08 +0530166static ssize_t read_file_dma(struct file *file, char __user *user_buf,
167 size_t count, loff_t *ppos)
168{
169 struct ath_softc *sc = file->private_data;
Sujithcbe61d82009-02-09 13:27:12 +0530170 struct ath_hw *ah = sc->sc_ah;
Pavel Roskin991a0982010-01-29 17:22:26 -0500171 char *buf;
172 int retval;
Sujith2a163c62008-11-28 22:21:08 +0530173 unsigned int len = 0;
174 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
175 int i, qcuOffset = 0, dcuOffset = 0;
176 u32 *qcuBase = &val[0], *dcuBase = &val[4];
177
Pavel Roskin991a0982010-01-29 17:22:26 -0500178 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
179 if (!buf)
Dan Carpenter04236062010-05-14 15:25:39 +0200180 return -ENOMEM;
Pavel Roskin991a0982010-01-29 17:22:26 -0500181
Sujith7cf4a2e2009-08-26 11:11:57 +0530182 ath9k_ps_wakeup(sc);
183
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400184 REG_WRITE_D(ah, AR_MACMISC,
Sujith2a163c62008-11-28 22:21:08 +0530185 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
186 (AR_MACMISC_MISC_OBS_BUS_1 <<
187 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
188
Pavel Roskin991a0982010-01-29 17:22:26 -0500189 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530190 "Raw DMA Debug values:\n");
191
192 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
193 if (i % 4 == 0)
Pavel Roskin991a0982010-01-29 17:22:26 -0500194 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530195
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400196 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
Pavel Roskin991a0982010-01-29 17:22:26 -0500197 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
Sujith2a163c62008-11-28 22:21:08 +0530198 i, val[i]);
199 }
200
Pavel Roskin991a0982010-01-29 17:22:26 -0500201 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
202 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530203 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
204
205 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
206 if (i == 8) {
207 qcuOffset = 0;
208 qcuBase++;
209 }
210
211 if (i == 6) {
212 dcuOffset = 0;
213 dcuBase++;
214 }
215
Pavel Roskin991a0982010-01-29 17:22:26 -0500216 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530217 "%2d %2x %1x %2x %2x\n",
218 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
219 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
220 val[2] & (0x7 << (i * 3)) >> (i * 3),
221 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
222 }
223
Pavel Roskin991a0982010-01-29 17:22:26 -0500224 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
Sujith2a163c62008-11-28 22:21:08 +0530225
Pavel Roskin991a0982010-01-29 17:22:26 -0500226 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530227 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
228 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
Pavel Roskin991a0982010-01-29 17:22:26 -0500229 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530230 "qcu_complete state: %2x dcu_complete state: %2x\n",
231 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
Pavel Roskin991a0982010-01-29 17:22:26 -0500232 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530233 "dcu_arb state: %2x dcu_fp state: %2x\n",
234 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
Pavel Roskin991a0982010-01-29 17:22:26 -0500235 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530236 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
237 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
Pavel Roskin991a0982010-01-29 17:22:26 -0500238 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530239 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
240 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
Pavel Roskin991a0982010-01-29 17:22:26 -0500241 len += snprintf(buf + len, DMA_BUF_LEN - len,
Sujith2a163c62008-11-28 22:21:08 +0530242 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
243 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
244
Frans Pop60ece402010-03-24 19:46:30 +0100245 len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400246 REG_READ_D(ah, AR_OBS_BUS_1));
Pavel Roskin991a0982010-01-29 17:22:26 -0500247 len += snprintf(buf + len, DMA_BUF_LEN - len,
Frans Pop60ece402010-03-24 19:46:30 +0100248 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
Sujith2a163c62008-11-28 22:21:08 +0530249
Sujith7cf4a2e2009-08-26 11:11:57 +0530250 ath9k_ps_restore(sc);
251
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200252 if (len > DMA_BUF_LEN)
253 len = DMA_BUF_LEN;
254
Pavel Roskin991a0982010-01-29 17:22:26 -0500255 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
256 kfree(buf);
257 return retval;
Sujith2a163c62008-11-28 22:21:08 +0530258}
259
260static const struct file_operations fops_dma = {
261 .read = read_file_dma,
262 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200263 .owner = THIS_MODULE,
264 .llseek = default_llseek,
Sujith2a163c62008-11-28 22:21:08 +0530265};
266
Sujith817e11d2008-12-07 21:42:44 +0530267
268void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
269{
270 if (status)
Sujith17d79042009-02-09 13:27:03 +0530271 sc->debug.stats.istats.total++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400272 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
273 if (status & ATH9K_INT_RXLP)
274 sc->debug.stats.istats.rxlp++;
275 if (status & ATH9K_INT_RXHP)
276 sc->debug.stats.istats.rxhp++;
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400277 if (status & ATH9K_INT_BB_WATCHDOG)
278 sc->debug.stats.istats.bb_watchdog++;
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400279 } else {
280 if (status & ATH9K_INT_RX)
281 sc->debug.stats.istats.rxok++;
282 }
Sujith817e11d2008-12-07 21:42:44 +0530283 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530284 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530285 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530286 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530287 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530288 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530289 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530290 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530291 if (status & ATH9K_INT_MIB)
Sujith17d79042009-02-09 13:27:03 +0530292 sc->debug.stats.istats.mib++;
Sujith817e11d2008-12-07 21:42:44 +0530293 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530294 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530295 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530296 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530297 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530298 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530299 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530300 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530301 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530302 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530303 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530304 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530305 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530306 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530307 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530308 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530309 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530310 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530311 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530312 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530313 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530314 sc->debug.stats.istats.dtim++;
Sujith817e11d2008-12-07 21:42:44 +0530315}
316
317static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
318 size_t count, loff_t *ppos)
319{
320 struct ath_softc *sc = file->private_data;
321 char buf[512];
322 unsigned int len = 0;
323
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400324 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
325 len += snprintf(buf + len, sizeof(buf) - len,
326 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
327 len += snprintf(buf + len, sizeof(buf) - len,
328 "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400329 len += snprintf(buf + len, sizeof(buf) - len,
330 "%8s: %10u\n", "WATCHDOG",
331 sc->debug.stats.istats.bb_watchdog);
Luis R. Rodrigueza9616f42010-04-15 17:39:30 -0400332 } else {
333 len += snprintf(buf + len, sizeof(buf) - len,
334 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
335 }
Sujith817e11d2008-12-07 21:42:44 +0530336 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530337 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
Sujith817e11d2008-12-07 21:42:44 +0530338 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530339 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
Sujith817e11d2008-12-07 21:42:44 +0530340 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530341 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
Sujith817e11d2008-12-07 21:42:44 +0530342 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530343 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
Sujith817e11d2008-12-07 21:42:44 +0530344 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530345 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
Sujith817e11d2008-12-07 21:42:44 +0530346 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530347 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
Sujith817e11d2008-12-07 21:42:44 +0530348 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530349 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
Sujith817e11d2008-12-07 21:42:44 +0530350 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530351 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
Sujith817e11d2008-12-07 21:42:44 +0530352 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530353 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
Sujith817e11d2008-12-07 21:42:44 +0530354 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530355 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
Sujith817e11d2008-12-07 21:42:44 +0530356 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530357 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
Sujith817e11d2008-12-07 21:42:44 +0530358 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530359 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
Sujith817e11d2008-12-07 21:42:44 +0530360 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530361 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
Sujith817e11d2008-12-07 21:42:44 +0530362 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530363 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
Sujith817e11d2008-12-07 21:42:44 +0530364 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530365 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
Sujith817e11d2008-12-07 21:42:44 +0530366 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530367 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
Sujith817e11d2008-12-07 21:42:44 +0530368 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530369 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
Sujith817e11d2008-12-07 21:42:44 +0530370
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200371 if (len > sizeof(buf))
372 len = sizeof(buf);
373
Sujith817e11d2008-12-07 21:42:44 +0530374 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
375}
376
377static const struct file_operations fops_interrupt = {
378 .read = read_file_interrupt,
379 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200380 .owner = THIS_MODULE,
381 .llseek = default_llseek,
Sujith817e11d2008-12-07 21:42:44 +0530382};
383
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200384static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
385{
386 switch (state) {
387 case ATH_WIPHY_INACTIVE:
388 return "INACTIVE";
389 case ATH_WIPHY_ACTIVE:
390 return "ACTIVE";
391 case ATH_WIPHY_PAUSING:
392 return "PAUSING";
393 case ATH_WIPHY_PAUSED:
394 return "PAUSED";
395 case ATH_WIPHY_SCAN:
396 return "SCAN";
397 }
398 return "?";
399}
400
401static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
402 size_t count, loff_t *ppos)
403{
404 struct ath_softc *sc = file->private_data;
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530405 struct ath_wiphy *aphy = sc->pri_wiphy;
406 struct ieee80211_channel *chan = aphy->hw->conf.channel;
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200407 char buf[512];
408 unsigned int len = 0;
409 int i;
410 u8 addr[ETH_ALEN];
Ben Greear39057512010-09-14 12:46:04 -0700411 u32 tmp;
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200412
413 len += snprintf(buf + len, sizeof(buf) - len,
414 "primary: %s (%s chan=%d ht=%d)\n",
415 wiphy_name(sc->pri_wiphy->hw->wiphy),
416 ath_wiphy_state_str(sc->pri_wiphy->state),
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530417 ieee80211_frequency_to_channel(chan->center_freq),
418 aphy->chan_is_ht);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200419
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400420 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
421 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200422 len += snprintf(buf + len, sizeof(buf) - len,
423 "addr: %pM\n", addr);
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400424 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
425 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200426 len += snprintf(buf + len, sizeof(buf) - len,
427 "addrmask: %pM\n", addr);
Ben Greear39057512010-09-14 12:46:04 -0700428 tmp = ath9k_hw_getrxfilter(sc->sc_ah);
429 len += snprintf(buf + len, sizeof(buf) - len,
430 "rfilt: 0x%x", tmp);
431 if (tmp & ATH9K_RX_FILTER_UCAST)
432 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
433 if (tmp & ATH9K_RX_FILTER_MCAST)
434 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
435 if (tmp & ATH9K_RX_FILTER_BCAST)
436 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
437 if (tmp & ATH9K_RX_FILTER_CONTROL)
438 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
439 if (tmp & ATH9K_RX_FILTER_BEACON)
440 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
441 if (tmp & ATH9K_RX_FILTER_PROM)
442 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
443 if (tmp & ATH9K_RX_FILTER_PROBEREQ)
444 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
445 if (tmp & ATH9K_RX_FILTER_PHYERR)
446 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
447 if (tmp & ATH9K_RX_FILTER_MYBEACON)
448 len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
449 if (tmp & ATH9K_RX_FILTER_COMP_BAR)
450 len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
451 if (tmp & ATH9K_RX_FILTER_PSPOLL)
452 len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
453 if (tmp & ATH9K_RX_FILTER_PHYRADAR)
454 len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
455 if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
456 len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n");
457 else
458 len += snprintf(buf + len, sizeof(buf) - len, "\n");
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200459
Ben Greear39057512010-09-14 12:46:04 -0700460 /* Put variable-length stuff down here, and check for overflows. */
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200461 for (i = 0; i < sc->num_sec_wiphy; i++) {
Luis R. Rodriguez191d6a12010-10-15 13:27:49 -0700462 struct ath_wiphy *aphy_tmp = sc->sec_wiphy[i];
463 if (aphy_tmp == NULL)
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200464 continue;
Luis R. Rodriguez191d6a12010-10-15 13:27:49 -0700465 chan = aphy_tmp->hw->conf.channel;
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200466 len += snprintf(buf + len, sizeof(buf) - len,
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530467 "secondary: %s (%s chan=%d ht=%d)\n",
Luis R. Rodriguez191d6a12010-10-15 13:27:49 -0700468 wiphy_name(aphy_tmp->hw->wiphy),
469 ath_wiphy_state_str(aphy_tmp->state),
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530470 ieee80211_frequency_to_channel(chan->center_freq),
Luis R. Rodriguez191d6a12010-10-15 13:27:49 -0700471 aphy_tmp->chan_is_ht);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200472 }
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200473 if (len > sizeof(buf))
474 len = sizeof(buf);
475
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200476 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
477}
478
479static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
480{
481 int i;
482 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
483 return sc->pri_wiphy;
484 for (i = 0; i < sc->num_sec_wiphy; i++) {
485 struct ath_wiphy *aphy = sc->sec_wiphy[i];
486 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
487 return aphy;
488 }
489 return NULL;
490}
491
492static int del_wiphy(struct ath_softc *sc, const char *name)
493{
494 struct ath_wiphy *aphy = get_wiphy(sc, name);
495 if (!aphy)
496 return -ENOENT;
497 return ath9k_wiphy_del(aphy);
498}
499
500static int pause_wiphy(struct ath_softc *sc, const char *name)
501{
502 struct ath_wiphy *aphy = get_wiphy(sc, name);
503 if (!aphy)
504 return -ENOENT;
505 return ath9k_wiphy_pause(aphy);
506}
507
508static int unpause_wiphy(struct ath_softc *sc, const char *name)
509{
510 struct ath_wiphy *aphy = get_wiphy(sc, name);
511 if (!aphy)
512 return -ENOENT;
513 return ath9k_wiphy_unpause(aphy);
514}
515
516static int select_wiphy(struct ath_softc *sc, const char *name)
517{
518 struct ath_wiphy *aphy = get_wiphy(sc, name);
519 if (!aphy)
520 return -ENOENT;
521 return ath9k_wiphy_select(aphy);
522}
523
524static int schedule_wiphy(struct ath_softc *sc, const char *msec)
525{
526 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
527 return 0;
528}
529
530static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
531 size_t count, loff_t *ppos)
532{
533 struct ath_softc *sc = file->private_data;
534 char buf[50];
535 size_t len;
536
537 len = min(count, sizeof(buf) - 1);
538 if (copy_from_user(buf, user_buf, len))
539 return -EFAULT;
540 buf[len] = '\0';
541 if (len > 0 && buf[len - 1] == '\n')
542 buf[len - 1] = '\0';
543
544 if (strncmp(buf, "add", 3) == 0) {
545 int res = ath9k_wiphy_add(sc);
546 if (res < 0)
547 return res;
548 } else if (strncmp(buf, "del=", 4) == 0) {
549 int res = del_wiphy(sc, buf + 4);
550 if (res < 0)
551 return res;
552 } else if (strncmp(buf, "pause=", 6) == 0) {
553 int res = pause_wiphy(sc, buf + 6);
554 if (res < 0)
555 return res;
556 } else if (strncmp(buf, "unpause=", 8) == 0) {
557 int res = unpause_wiphy(sc, buf + 8);
558 if (res < 0)
559 return res;
560 } else if (strncmp(buf, "select=", 7) == 0) {
561 int res = select_wiphy(sc, buf + 7);
562 if (res < 0)
563 return res;
564 } else if (strncmp(buf, "schedule=", 9) == 0) {
565 int res = schedule_wiphy(sc, buf + 9);
566 if (res < 0)
567 return res;
568 } else
569 return -EOPNOTSUPP;
570
571 return count;
572}
573
574static const struct file_operations fops_wiphy = {
575 .read = read_file_wiphy,
576 .write = write_file_wiphy,
577 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200578 .owner = THIS_MODULE,
579 .llseek = default_llseek,
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200580};
581
Sujithfec247c2009-07-27 12:08:16 +0530582#define PR(str, elem) \
583 do { \
584 len += snprintf(buf + len, size - len, \
585 "%s%13u%11u%10u%10u\n", str, \
Felix Fietkau066dae92010-11-07 14:59:39 +0100586 sc->debug.stats.txstats[WME_AC_BE].elem, \
587 sc->debug.stats.txstats[WME_AC_BK].elem, \
588 sc->debug.stats.txstats[WME_AC_VI].elem, \
589 sc->debug.stats.txstats[WME_AC_VO].elem); \
Ben Greear7f010c92011-01-09 23:11:49 -0800590 if (len >= size) \
591 goto done; \
Sujithfec247c2009-07-27 12:08:16 +0530592} while(0)
593
Ben Greear1f427dd2011-01-09 23:11:43 -0800594#define PRX(str, elem) \
595do { \
596 len += snprintf(buf + len, size - len, \
597 "%s%13u%11u%10u%10u\n", str, \
598 (unsigned int)(sc->tx.txq[WME_AC_BE].elem), \
599 (unsigned int)(sc->tx.txq[WME_AC_BK].elem), \
600 (unsigned int)(sc->tx.txq[WME_AC_VI].elem), \
601 (unsigned int)(sc->tx.txq[WME_AC_VO].elem)); \
Ben Greear7f010c92011-01-09 23:11:49 -0800602 if (len >= size) \
603 goto done; \
Ben Greear1f427dd2011-01-09 23:11:43 -0800604} while(0)
605
Ben Greear2dac4fb2011-01-09 23:11:45 -0800606#define PRQLE(str, elem) \
607do { \
608 len += snprintf(buf + len, size - len, \
609 "%s%13i%11i%10i%10i\n", str, \
610 list_empty(&sc->tx.txq[WME_AC_BE].elem), \
611 list_empty(&sc->tx.txq[WME_AC_BK].elem), \
612 list_empty(&sc->tx.txq[WME_AC_VI].elem), \
613 list_empty(&sc->tx.txq[WME_AC_VO].elem)); \
Ben Greear7f010c92011-01-09 23:11:49 -0800614 if (len >= size) \
615 goto done; \
Ben Greear2dac4fb2011-01-09 23:11:45 -0800616} while (0)
617
Sujithfec247c2009-07-27 12:08:16 +0530618static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
619 size_t count, loff_t *ppos)
620{
621 struct ath_softc *sc = file->private_data;
622 char *buf;
Ben Greear7f010c92011-01-09 23:11:49 -0800623 unsigned int len = 0, size = 8000;
Ben Greear2dac4fb2011-01-09 23:11:45 -0800624 int i;
Sujithfec247c2009-07-27 12:08:16 +0530625 ssize_t retval = 0;
Ben Greear2dac4fb2011-01-09 23:11:45 -0800626 char tmp[32];
Sujithfec247c2009-07-27 12:08:16 +0530627
628 buf = kzalloc(size, GFP_KERNEL);
629 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200630 return -ENOMEM;
Sujithfec247c2009-07-27 12:08:16 +0530631
Ben Greear7f010c92011-01-09 23:11:49 -0800632 len += sprintf(buf, "Num-Tx-Queues: %i tx-queues-setup: 0x%x\n"
633 "%30s %10s%10s%10s\n\n",
634 ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
635 "BE", "BK", "VI", "VO");
Sujithfec247c2009-07-27 12:08:16 +0530636
637 PR("MPDUs Queued: ", queued);
638 PR("MPDUs Completed: ", completed);
639 PR("Aggregates: ", a_aggr);
Ben Greearbda8add2011-01-09 23:11:48 -0800640 PR("AMPDUs Queued HW:", a_queued_hw);
641 PR("AMPDUs Queued SW:", a_queued_sw);
Sujithfec247c2009-07-27 12:08:16 +0530642 PR("AMPDUs Completed:", a_completed);
643 PR("AMPDUs Retried: ", a_retries);
644 PR("AMPDUs XRetried: ", a_xretries);
645 PR("FIFO Underrun: ", fifo_underrun);
646 PR("TXOP Exceeded: ", xtxop);
647 PR("TXTIMER Expiry: ", timer_exp);
648 PR("DESC CFG Error: ", desc_cfg_err);
649 PR("DATA Underrun: ", data_underrun);
650 PR("DELIM Underrun: ", delim_underrun);
Ben Greear99c15bf2010-10-01 12:26:30 -0700651 PR("TX-Pkts-All: ", tx_pkts_all);
652 PR("TX-Bytes-All: ", tx_bytes_all);
Ben Greear2dac4fb2011-01-09 23:11:45 -0800653 PR("hw-put-tx-buf: ", puttxbuf);
654 PR("hw-tx-start: ", txstart);
655 PR("hw-tx-proc-desc: ", txprocdesc);
Ben Greear7f010c92011-01-09 23:11:49 -0800656 len += snprintf(buf + len, size - len,
657 "%s%11p%11p%10p%10p\n", "txq-memory-address:",
658 &(sc->tx.txq[WME_AC_BE]),
659 &(sc->tx.txq[WME_AC_BK]),
660 &(sc->tx.txq[WME_AC_VI]),
661 &(sc->tx.txq[WME_AC_VO]));
662 if (len >= size)
663 goto done;
Sujithfec247c2009-07-27 12:08:16 +0530664
Ben Greear1f427dd2011-01-09 23:11:43 -0800665 PRX("axq-qnum: ", axq_qnum);
666 PRX("axq-depth: ", axq_depth);
Ben Greear2dac4fb2011-01-09 23:11:45 -0800667 PRX("axq-ampdu_depth: ", axq_ampdu_depth);
Ben Greear1f427dd2011-01-09 23:11:43 -0800668 PRX("axq-stopped ", stopped);
669 PRX("tx-in-progress ", axq_tx_inprogress);
670 PRX("pending-frames ", pending_frames);
Ben Greear2dac4fb2011-01-09 23:11:45 -0800671 PRX("txq_headidx: ", txq_headidx);
672 PRX("txq_tailidx: ", txq_headidx);
Ben Greear1f427dd2011-01-09 23:11:43 -0800673
Ben Greear2dac4fb2011-01-09 23:11:45 -0800674 PRQLE("axq_q empty: ", axq_q);
675 PRQLE("axq_acq empty: ", axq_acq);
676 PRQLE("txq_fifo_pending: ", txq_fifo_pending);
677 for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
678 snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
679 PRQLE(tmp, txq_fifo[i]);
680 }
Ben Greear7f010c92011-01-09 23:11:49 -0800681
Ben Greear71e025a2011-01-09 23:11:50 -0800682 /* Print out more detailed queue-info */
683 for (i = 0; i <= WME_AC_BK; i++) {
684 struct ath_txq *txq = &(sc->tx.txq[i]);
685 struct ath_atx_ac *ac;
686 struct ath_atx_tid *tid;
687 if (len >= size)
688 goto done;
689 spin_lock_bh(&txq->axq_lock);
690 if (!list_empty(&txq->axq_acq)) {
691 ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
692 list);
693 len += snprintf(buf + len, size - len,
694 "txq[%i] first-ac: %p sched: %i\n",
695 i, ac, ac->sched);
696 if (list_empty(&ac->tid_q) || (len >= size))
697 goto done_for;
698 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
699 list);
700 len += snprintf(buf + len, size - len,
701 " first-tid: %p sched: %i paused: %i\n",
702 tid, tid->sched, tid->paused);
703 }
704 done_for:
705 spin_unlock_bh(&txq->axq_lock);
706 }
707
Ben Greear7f010c92011-01-09 23:11:49 -0800708done:
709 if (len > size)
710 len = size;
711
712 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
713 kfree(buf);
714
715 return retval;
716}
717
718static ssize_t read_file_stations(struct file *file, char __user *user_buf,
719 size_t count, loff_t *ppos)
720{
721 struct ath_softc *sc = file->private_data;
722 char *buf;
723 unsigned int len = 0, size = 64000;
724 struct ath_node *an = NULL;
725 ssize_t retval = 0;
726 int q;
727
728 buf = kzalloc(size, GFP_KERNEL);
729 if (buf == NULL)
730 return -ENOMEM;
731
732 len += snprintf(buf + len, size - len,
733 "Stations:\n"
734 " tid: addr sched paused buf_q-empty an ac\n"
735 " ac: addr sched tid_q-empty txq\n");
736
737 spin_lock(&sc->nodes_lock);
738 list_for_each_entry(an, &sc->nodes, list) {
739 len += snprintf(buf + len, size - len,
740 "%pM\n", an->sta->addr);
741 if (len >= size)
742 goto done;
743
744 for (q = 0; q < WME_NUM_TID; q++) {
745 struct ath_atx_tid *tid = &(an->tid[q]);
746 len += snprintf(buf + len, size - len,
747 " tid: %p %s %s %i %p %p\n",
748 tid, tid->sched ? "sched" : "idle",
749 tid->paused ? "paused" : "running",
750 list_empty(&tid->buf_q),
751 tid->an, tid->ac);
752 if (len >= size)
753 goto done;
754 }
755
756 for (q = 0; q < WME_NUM_AC; q++) {
757 struct ath_atx_ac *ac = &(an->ac[q]);
758 len += snprintf(buf + len, size - len,
759 " ac: %p %s %i %p\n",
760 ac, ac->sched ? "sched" : "idle",
761 list_empty(&ac->tid_q), ac->txq);
762 if (len >= size)
763 goto done;
764 }
765 }
766
767done:
768 spin_unlock(&sc->nodes_lock);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200769 if (len > size)
770 len = size;
771
Sujithfec247c2009-07-27 12:08:16 +0530772 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
773 kfree(buf);
774
775 return retval;
776}
777
Felix Fietkau066dae92010-11-07 14:59:39 +0100778void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
779 struct ath_tx_status *ts)
Sujithfec247c2009-07-27 12:08:16 +0530780{
Felix Fietkau066dae92010-11-07 14:59:39 +0100781 int qnum = skb_get_queue_mapping(bf->bf_mpdu);
782
783 TX_STAT_INC(qnum, tx_pkts_all);
784 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
Ben Greear99c15bf2010-10-01 12:26:30 -0700785
Sujithfec247c2009-07-27 12:08:16 +0530786 if (bf_isampdu(bf)) {
787 if (bf_isxretried(bf))
Felix Fietkau066dae92010-11-07 14:59:39 +0100788 TX_STAT_INC(qnum, a_xretries);
Sujithfec247c2009-07-27 12:08:16 +0530789 else
Felix Fietkau066dae92010-11-07 14:59:39 +0100790 TX_STAT_INC(qnum, a_completed);
Sujithfec247c2009-07-27 12:08:16 +0530791 } else {
Felix Fietkau066dae92010-11-07 14:59:39 +0100792 TX_STAT_INC(qnum, completed);
Sujithfec247c2009-07-27 12:08:16 +0530793 }
794
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700795 if (ts->ts_status & ATH9K_TXERR_FIFO)
Felix Fietkau066dae92010-11-07 14:59:39 +0100796 TX_STAT_INC(qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700797 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Felix Fietkau066dae92010-11-07 14:59:39 +0100798 TX_STAT_INC(qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700799 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Felix Fietkau066dae92010-11-07 14:59:39 +0100800 TX_STAT_INC(qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700801 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100802 TX_STAT_INC(qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700803 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100804 TX_STAT_INC(qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700805 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100806 TX_STAT_INC(qnum, delim_underrun);
Sujithfec247c2009-07-27 12:08:16 +0530807}
808
809static const struct file_operations fops_xmit = {
810 .read = read_file_xmit,
811 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200812 .owner = THIS_MODULE,
813 .llseek = default_llseek,
Sujithfec247c2009-07-27 12:08:16 +0530814};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200815
Ben Greear7f010c92011-01-09 23:11:49 -0800816static const struct file_operations fops_stations = {
817 .read = read_file_stations,
818 .open = ath9k_debugfs_open,
819 .owner = THIS_MODULE,
820 .llseek = default_llseek,
821};
822
Sujith1395d3f2010-01-08 10:36:11 +0530823static ssize_t read_file_recv(struct file *file, char __user *user_buf,
824 size_t count, loff_t *ppos)
825{
826#define PHY_ERR(s, p) \
827 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
828 sc->debug.stats.rxstats.phy_err_stats[p]);
829
830 struct ath_softc *sc = file->private_data;
831 char *buf;
832 unsigned int len = 0, size = 1152;
833 ssize_t retval = 0;
834
835 buf = kzalloc(size, GFP_KERNEL);
836 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200837 return -ENOMEM;
Sujith1395d3f2010-01-08 10:36:11 +0530838
839 len += snprintf(buf + len, size - len,
840 "%18s : %10u\n", "CRC ERR",
841 sc->debug.stats.rxstats.crc_err);
842 len += snprintf(buf + len, size - len,
843 "%18s : %10u\n", "DECRYPT CRC ERR",
844 sc->debug.stats.rxstats.decrypt_crc_err);
845 len += snprintf(buf + len, size - len,
846 "%18s : %10u\n", "PHY ERR",
847 sc->debug.stats.rxstats.phy_err);
848 len += snprintf(buf + len, size - len,
849 "%18s : %10u\n", "MIC ERR",
850 sc->debug.stats.rxstats.mic_err);
851 len += snprintf(buf + len, size - len,
852 "%18s : %10u\n", "PRE-DELIM CRC ERR",
853 sc->debug.stats.rxstats.pre_delim_crc_err);
854 len += snprintf(buf + len, size - len,
855 "%18s : %10u\n", "POST-DELIM CRC ERR",
856 sc->debug.stats.rxstats.post_delim_crc_err);
857 len += snprintf(buf + len, size - len,
858 "%18s : %10u\n", "DECRYPT BUSY ERR",
859 sc->debug.stats.rxstats.decrypt_busy_err);
860
861 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
862 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
863 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
864 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
865 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
866 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
867 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
868 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
869 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
870 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
871 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
872 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
873 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
874 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
875 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
876 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
877 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
878 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
879 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
880 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
881 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
882 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
883 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
884 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
885 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
886 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
887
Ben Greear99c15bf2010-10-01 12:26:30 -0700888 len += snprintf(buf + len, size - len,
889 "%18s : %10u\n", "RX-Pkts-All",
890 sc->debug.stats.rxstats.rx_pkts_all);
891 len += snprintf(buf + len, size - len,
892 "%18s : %10u\n", "RX-Bytes-All",
893 sc->debug.stats.rxstats.rx_bytes_all);
894
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200895 if (len > size)
896 len = size;
897
Sujith1395d3f2010-01-08 10:36:11 +0530898 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
899 kfree(buf);
900
901 return retval;
902
903#undef PHY_ERR
904}
905
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700906void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +0530907{
908#define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
909#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
910
Sujith1395d3f2010-01-08 10:36:11 +0530911 u32 phyerr;
912
Ben Greear99c15bf2010-10-01 12:26:30 -0700913 RX_STAT_INC(rx_pkts_all);
914 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
915
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700916 if (rs->rs_status & ATH9K_RXERR_CRC)
Sujith1395d3f2010-01-08 10:36:11 +0530917 RX_STAT_INC(crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700918 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
Sujith1395d3f2010-01-08 10:36:11 +0530919 RX_STAT_INC(decrypt_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700920 if (rs->rs_status & ATH9K_RXERR_MIC)
Sujith1395d3f2010-01-08 10:36:11 +0530921 RX_STAT_INC(mic_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700922 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
Sujith1395d3f2010-01-08 10:36:11 +0530923 RX_STAT_INC(pre_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700924 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
Sujith1395d3f2010-01-08 10:36:11 +0530925 RX_STAT_INC(post_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700926 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
Sujith1395d3f2010-01-08 10:36:11 +0530927 RX_STAT_INC(decrypt_busy_err);
928
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700929 if (rs->rs_status & ATH9K_RXERR_PHY) {
Sujith1395d3f2010-01-08 10:36:11 +0530930 RX_STAT_INC(phy_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700931 phyerr = rs->rs_phyerr & 0x24;
Sujith1395d3f2010-01-08 10:36:11 +0530932 RX_PHY_ERR_INC(phyerr);
933 }
934
935#undef RX_STAT_INC
936#undef RX_PHY_ERR_INC
937}
938
939static const struct file_operations fops_recv = {
940 .read = read_file_recv,
941 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200942 .owner = THIS_MODULE,
943 .llseek = default_llseek,
Sujith1395d3f2010-01-08 10:36:11 +0530944};
945
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200946static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
947 size_t count, loff_t *ppos)
948{
949 struct ath_softc *sc = file->private_data;
950 char buf[32];
951 unsigned int len;
952
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200953 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200954 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
955}
956
957static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
958 size_t count, loff_t *ppos)
959{
960 struct ath_softc *sc = file->private_data;
961 unsigned long regidx;
962 char buf[32];
963 ssize_t len;
964
965 len = min(count, sizeof(buf) - 1);
966 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200967 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200968
969 buf[len] = '\0';
970 if (strict_strtoul(buf, 0, &regidx))
971 return -EINVAL;
972
973 sc->debug.regidx = regidx;
974 return count;
975}
976
977static const struct file_operations fops_regidx = {
978 .read = read_file_regidx,
979 .write = write_file_regidx,
980 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200981 .owner = THIS_MODULE,
982 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200983};
984
985static ssize_t read_file_regval(struct file *file, char __user *user_buf,
986 size_t count, loff_t *ppos)
987{
988 struct ath_softc *sc = file->private_data;
989 struct ath_hw *ah = sc->sc_ah;
990 char buf[32];
991 unsigned int len;
992 u32 regval;
993
994 regval = REG_READ_D(ah, sc->debug.regidx);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200995 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200996 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
997}
998
999static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1000 size_t count, loff_t *ppos)
1001{
1002 struct ath_softc *sc = file->private_data;
1003 struct ath_hw *ah = sc->sc_ah;
1004 unsigned long regval;
1005 char buf[32];
1006 ssize_t len;
1007
1008 len = min(count, sizeof(buf) - 1);
1009 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +02001010 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001011
1012 buf[len] = '\0';
1013 if (strict_strtoul(buf, 0, &regval))
1014 return -EINVAL;
1015
1016 REG_WRITE_D(ah, sc->debug.regidx, regval);
1017 return count;
1018}
1019
1020static const struct file_operations fops_regval = {
1021 .read = read_file_regval,
1022 .write = write_file_regval,
1023 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001024 .owner = THIS_MODULE,
1025 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001026};
1027
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001028int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +05301029{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001030 struct ath_common *common = ath9k_hw_common(ah);
1031 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001032
Ben Greeareb272442010-11-29 14:13:22 -08001033 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1034 sc->hw->wiphy->debugfsdir);
Sujith17d79042009-02-09 13:27:03 +05301035 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001036 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +05301037
Felix Fietkaua830df02009-11-23 22:33:27 +01001038#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001039 if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
1040 sc->debug.debugfs_phy, sc, &fops_debug))
Jeff Hansen24939282009-05-27 12:48:29 +00001041 goto err;
Felix Fietkaua830df02009-11-23 22:33:27 +01001042#endif
Jeff Hansen24939282009-05-27 12:48:29 +00001043
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001044 if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
1045 sc, &fops_dma))
Sujith2a163c62008-11-28 22:21:08 +05301046 goto err;
1047
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001048 if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
1049 sc, &fops_interrupt))
Sujith817e11d2008-12-07 21:42:44 +05301050 goto err;
1051
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001052 if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
1053 sc->debug.debugfs_phy, sc, &fops_wiphy))
Jouni Malinen39d89cd2009-03-03 19:23:40 +02001054 goto err;
1055
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001056 if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
1057 sc, &fops_xmit))
Sujithfec247c2009-07-27 12:08:16 +05301058 goto err;
1059
Ben Greear7f010c92011-01-09 23:11:49 -08001060 if (!debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy,
1061 sc, &fops_stations))
1062 goto err;
1063
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001064 if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
1065 sc, &fops_recv))
Sujith1395d3f2010-01-08 10:36:11 +05301066 goto err;
1067
Felix Fietkau15340692010-05-11 17:23:01 +02001068 if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1069 sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
1070 goto err;
1071
1072 if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1073 sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
1074 goto err;
1075
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001076 if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
1077 sc->debug.debugfs_phy, sc, &fops_regidx))
1078 goto err;
1079
1080 if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
1081 sc->debug.debugfs_phy, sc, &fops_regval))
1082 goto err;
1083
Felix Fietkau41f3e542010-06-12 00:33:56 -04001084 if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1085 sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
1086 goto err;
1087
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001088 sc->debug.regidx = 0;
Sujith826d2682008-11-28 22:20:23 +05301089 return 0;
1090err:
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001091 debugfs_remove_recursive(sc->debug.debugfs_phy);
Ben Greeareb272442010-11-29 14:13:22 -08001092 sc->debug.debugfs_phy = NULL;
1093 return -ENOMEM;
Sujith88b126a2008-11-28 22:19:02 +05301094}