blob: 650f00f59d79a2e337ec83d22bd3d963f7c85451 [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
682done:
683 if (len > size)
684 len = size;
685
686 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
687 kfree(buf);
688
689 return retval;
690}
691
692static ssize_t read_file_stations(struct file *file, char __user *user_buf,
693 size_t count, loff_t *ppos)
694{
695 struct ath_softc *sc = file->private_data;
696 char *buf;
697 unsigned int len = 0, size = 64000;
698 struct ath_node *an = NULL;
699 ssize_t retval = 0;
700 int q;
701
702 buf = kzalloc(size, GFP_KERNEL);
703 if (buf == NULL)
704 return -ENOMEM;
705
706 len += snprintf(buf + len, size - len,
707 "Stations:\n"
708 " tid: addr sched paused buf_q-empty an ac\n"
709 " ac: addr sched tid_q-empty txq\n");
710
711 spin_lock(&sc->nodes_lock);
712 list_for_each_entry(an, &sc->nodes, list) {
713 len += snprintf(buf + len, size - len,
714 "%pM\n", an->sta->addr);
715 if (len >= size)
716 goto done;
717
718 for (q = 0; q < WME_NUM_TID; q++) {
719 struct ath_atx_tid *tid = &(an->tid[q]);
720 len += snprintf(buf + len, size - len,
721 " tid: %p %s %s %i %p %p\n",
722 tid, tid->sched ? "sched" : "idle",
723 tid->paused ? "paused" : "running",
724 list_empty(&tid->buf_q),
725 tid->an, tid->ac);
726 if (len >= size)
727 goto done;
728 }
729
730 for (q = 0; q < WME_NUM_AC; q++) {
731 struct ath_atx_ac *ac = &(an->ac[q]);
732 len += snprintf(buf + len, size - len,
733 " ac: %p %s %i %p\n",
734 ac, ac->sched ? "sched" : "idle",
735 list_empty(&ac->tid_q), ac->txq);
736 if (len >= size)
737 goto done;
738 }
739 }
740
741done:
742 spin_unlock(&sc->nodes_lock);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200743 if (len > size)
744 len = size;
745
Sujithfec247c2009-07-27 12:08:16 +0530746 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
747 kfree(buf);
748
749 return retval;
750}
751
Felix Fietkau066dae92010-11-07 14:59:39 +0100752void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
753 struct ath_tx_status *ts)
Sujithfec247c2009-07-27 12:08:16 +0530754{
Felix Fietkau066dae92010-11-07 14:59:39 +0100755 int qnum = skb_get_queue_mapping(bf->bf_mpdu);
756
757 TX_STAT_INC(qnum, tx_pkts_all);
758 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
Ben Greear99c15bf2010-10-01 12:26:30 -0700759
Sujithfec247c2009-07-27 12:08:16 +0530760 if (bf_isampdu(bf)) {
761 if (bf_isxretried(bf))
Felix Fietkau066dae92010-11-07 14:59:39 +0100762 TX_STAT_INC(qnum, a_xretries);
Sujithfec247c2009-07-27 12:08:16 +0530763 else
Felix Fietkau066dae92010-11-07 14:59:39 +0100764 TX_STAT_INC(qnum, a_completed);
Sujithfec247c2009-07-27 12:08:16 +0530765 } else {
Felix Fietkau066dae92010-11-07 14:59:39 +0100766 TX_STAT_INC(qnum, completed);
Sujithfec247c2009-07-27 12:08:16 +0530767 }
768
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700769 if (ts->ts_status & ATH9K_TXERR_FIFO)
Felix Fietkau066dae92010-11-07 14:59:39 +0100770 TX_STAT_INC(qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700771 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Felix Fietkau066dae92010-11-07 14:59:39 +0100772 TX_STAT_INC(qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700773 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Felix Fietkau066dae92010-11-07 14:59:39 +0100774 TX_STAT_INC(qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700775 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100776 TX_STAT_INC(qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700777 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100778 TX_STAT_INC(qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700779 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100780 TX_STAT_INC(qnum, delim_underrun);
Sujithfec247c2009-07-27 12:08:16 +0530781}
782
783static const struct file_operations fops_xmit = {
784 .read = read_file_xmit,
785 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200786 .owner = THIS_MODULE,
787 .llseek = default_llseek,
Sujithfec247c2009-07-27 12:08:16 +0530788};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200789
Ben Greear7f010c92011-01-09 23:11:49 -0800790static const struct file_operations fops_stations = {
791 .read = read_file_stations,
792 .open = ath9k_debugfs_open,
793 .owner = THIS_MODULE,
794 .llseek = default_llseek,
795};
796
Sujith1395d3f2010-01-08 10:36:11 +0530797static ssize_t read_file_recv(struct file *file, char __user *user_buf,
798 size_t count, loff_t *ppos)
799{
800#define PHY_ERR(s, p) \
801 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
802 sc->debug.stats.rxstats.phy_err_stats[p]);
803
804 struct ath_softc *sc = file->private_data;
805 char *buf;
806 unsigned int len = 0, size = 1152;
807 ssize_t retval = 0;
808
809 buf = kzalloc(size, GFP_KERNEL);
810 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200811 return -ENOMEM;
Sujith1395d3f2010-01-08 10:36:11 +0530812
813 len += snprintf(buf + len, size - len,
814 "%18s : %10u\n", "CRC ERR",
815 sc->debug.stats.rxstats.crc_err);
816 len += snprintf(buf + len, size - len,
817 "%18s : %10u\n", "DECRYPT CRC ERR",
818 sc->debug.stats.rxstats.decrypt_crc_err);
819 len += snprintf(buf + len, size - len,
820 "%18s : %10u\n", "PHY ERR",
821 sc->debug.stats.rxstats.phy_err);
822 len += snprintf(buf + len, size - len,
823 "%18s : %10u\n", "MIC ERR",
824 sc->debug.stats.rxstats.mic_err);
825 len += snprintf(buf + len, size - len,
826 "%18s : %10u\n", "PRE-DELIM CRC ERR",
827 sc->debug.stats.rxstats.pre_delim_crc_err);
828 len += snprintf(buf + len, size - len,
829 "%18s : %10u\n", "POST-DELIM CRC ERR",
830 sc->debug.stats.rxstats.post_delim_crc_err);
831 len += snprintf(buf + len, size - len,
832 "%18s : %10u\n", "DECRYPT BUSY ERR",
833 sc->debug.stats.rxstats.decrypt_busy_err);
834
835 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
836 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
837 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
838 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
839 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
840 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
841 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
842 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
843 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
844 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
845 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
846 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
847 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
848 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
849 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
850 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
851 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
852 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
853 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
854 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
855 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
856 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
857 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
858 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
859 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
860 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
861
Ben Greear99c15bf2010-10-01 12:26:30 -0700862 len += snprintf(buf + len, size - len,
863 "%18s : %10u\n", "RX-Pkts-All",
864 sc->debug.stats.rxstats.rx_pkts_all);
865 len += snprintf(buf + len, size - len,
866 "%18s : %10u\n", "RX-Bytes-All",
867 sc->debug.stats.rxstats.rx_bytes_all);
868
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200869 if (len > size)
870 len = size;
871
Sujith1395d3f2010-01-08 10:36:11 +0530872 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
873 kfree(buf);
874
875 return retval;
876
877#undef PHY_ERR
878}
879
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700880void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +0530881{
882#define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
883#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
884
Sujith1395d3f2010-01-08 10:36:11 +0530885 u32 phyerr;
886
Ben Greear99c15bf2010-10-01 12:26:30 -0700887 RX_STAT_INC(rx_pkts_all);
888 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
889
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700890 if (rs->rs_status & ATH9K_RXERR_CRC)
Sujith1395d3f2010-01-08 10:36:11 +0530891 RX_STAT_INC(crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700892 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
Sujith1395d3f2010-01-08 10:36:11 +0530893 RX_STAT_INC(decrypt_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700894 if (rs->rs_status & ATH9K_RXERR_MIC)
Sujith1395d3f2010-01-08 10:36:11 +0530895 RX_STAT_INC(mic_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700896 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
Sujith1395d3f2010-01-08 10:36:11 +0530897 RX_STAT_INC(pre_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700898 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
Sujith1395d3f2010-01-08 10:36:11 +0530899 RX_STAT_INC(post_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700900 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
Sujith1395d3f2010-01-08 10:36:11 +0530901 RX_STAT_INC(decrypt_busy_err);
902
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700903 if (rs->rs_status & ATH9K_RXERR_PHY) {
Sujith1395d3f2010-01-08 10:36:11 +0530904 RX_STAT_INC(phy_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700905 phyerr = rs->rs_phyerr & 0x24;
Sujith1395d3f2010-01-08 10:36:11 +0530906 RX_PHY_ERR_INC(phyerr);
907 }
908
909#undef RX_STAT_INC
910#undef RX_PHY_ERR_INC
911}
912
913static const struct file_operations fops_recv = {
914 .read = read_file_recv,
915 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200916 .owner = THIS_MODULE,
917 .llseek = default_llseek,
Sujith1395d3f2010-01-08 10:36:11 +0530918};
919
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200920static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
921 size_t count, loff_t *ppos)
922{
923 struct ath_softc *sc = file->private_data;
924 char buf[32];
925 unsigned int len;
926
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200927 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200928 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
929}
930
931static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
932 size_t count, loff_t *ppos)
933{
934 struct ath_softc *sc = file->private_data;
935 unsigned long regidx;
936 char buf[32];
937 ssize_t len;
938
939 len = min(count, sizeof(buf) - 1);
940 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200941 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200942
943 buf[len] = '\0';
944 if (strict_strtoul(buf, 0, &regidx))
945 return -EINVAL;
946
947 sc->debug.regidx = regidx;
948 return count;
949}
950
951static const struct file_operations fops_regidx = {
952 .read = read_file_regidx,
953 .write = write_file_regidx,
954 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200955 .owner = THIS_MODULE,
956 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200957};
958
959static ssize_t read_file_regval(struct file *file, char __user *user_buf,
960 size_t count, loff_t *ppos)
961{
962 struct ath_softc *sc = file->private_data;
963 struct ath_hw *ah = sc->sc_ah;
964 char buf[32];
965 unsigned int len;
966 u32 regval;
967
968 regval = REG_READ_D(ah, sc->debug.regidx);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200969 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200970 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
971}
972
973static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
974 size_t count, loff_t *ppos)
975{
976 struct ath_softc *sc = file->private_data;
977 struct ath_hw *ah = sc->sc_ah;
978 unsigned long regval;
979 char buf[32];
980 ssize_t len;
981
982 len = min(count, sizeof(buf) - 1);
983 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200984 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200985
986 buf[len] = '\0';
987 if (strict_strtoul(buf, 0, &regval))
988 return -EINVAL;
989
990 REG_WRITE_D(ah, sc->debug.regidx, regval);
991 return count;
992}
993
994static const struct file_operations fops_regval = {
995 .read = read_file_regval,
996 .write = write_file_regval,
997 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200998 .owner = THIS_MODULE,
999 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001000};
1001
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001002int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +05301003{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001004 struct ath_common *common = ath9k_hw_common(ah);
1005 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001006
Ben Greeareb272442010-11-29 14:13:22 -08001007 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1008 sc->hw->wiphy->debugfsdir);
Sujith17d79042009-02-09 13:27:03 +05301009 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001010 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +05301011
Felix Fietkaua830df02009-11-23 22:33:27 +01001012#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001013 if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
1014 sc->debug.debugfs_phy, sc, &fops_debug))
Jeff Hansen24939282009-05-27 12:48:29 +00001015 goto err;
Felix Fietkaua830df02009-11-23 22:33:27 +01001016#endif
Jeff Hansen24939282009-05-27 12:48:29 +00001017
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001018 if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
1019 sc, &fops_dma))
Sujith2a163c62008-11-28 22:21:08 +05301020 goto err;
1021
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001022 if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
1023 sc, &fops_interrupt))
Sujith817e11d2008-12-07 21:42:44 +05301024 goto err;
1025
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001026 if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
1027 sc->debug.debugfs_phy, sc, &fops_wiphy))
Jouni Malinen39d89cd2009-03-03 19:23:40 +02001028 goto err;
1029
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001030 if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
1031 sc, &fops_xmit))
Sujithfec247c2009-07-27 12:08:16 +05301032 goto err;
1033
Ben Greear7f010c92011-01-09 23:11:49 -08001034 if (!debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy,
1035 sc, &fops_stations))
1036 goto err;
1037
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001038 if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
1039 sc, &fops_recv))
Sujith1395d3f2010-01-08 10:36:11 +05301040 goto err;
1041
Felix Fietkau15340692010-05-11 17:23:01 +02001042 if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1043 sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
1044 goto err;
1045
1046 if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1047 sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
1048 goto err;
1049
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001050 if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
1051 sc->debug.debugfs_phy, sc, &fops_regidx))
1052 goto err;
1053
1054 if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
1055 sc->debug.debugfs_phy, sc, &fops_regval))
1056 goto err;
1057
Felix Fietkau41f3e542010-06-12 00:33:56 -04001058 if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1059 sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
1060 goto err;
1061
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001062 sc->debug.regidx = 0;
Sujith826d2682008-11-28 22:20:23 +05301063 return 0;
1064err:
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001065 debugfs_remove_recursive(sc->debug.debugfs_phy);
Ben Greeareb272442010-11-29 14:13:22 -08001066 sc->debug.debugfs_phy = NULL;
1067 return -ENOMEM;
Sujith88b126a2008-11-28 22:19:02 +05301068}