blob: 5cfcf8c235a4429d6778ecf9afdeb5f18f91f448 [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
Ben Greear4e6975f2011-01-31 10:37:36 -0800384static const char *channel_type_str(enum nl80211_channel_type t)
385{
386 switch (t) {
387 case NL80211_CHAN_NO_HT:
388 return "no ht";
389 case NL80211_CHAN_HT20:
390 return "ht20";
391 case NL80211_CHAN_HT40MINUS:
392 return "ht40-";
393 case NL80211_CHAN_HT40PLUS:
394 return "ht40+";
395 default:
396 return "???";
397 }
398}
399
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200400static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
401 size_t count, loff_t *ppos)
402{
403 struct ath_softc *sc = file->private_data;
Felix Fietkau34302392011-01-24 19:23:15 +0100404 struct ieee80211_channel *chan = sc->hw->conf.channel;
Ben Greear4e6975f2011-01-31 10:37:36 -0800405 struct ieee80211_conf *conf = &(sc->hw->conf);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200406 char buf[512];
407 unsigned int len = 0;
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200408 u8 addr[ETH_ALEN];
Ben Greear39057512010-09-14 12:46:04 -0700409 u32 tmp;
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200410
411 len += snprintf(buf + len, sizeof(buf) - len,
Ben Greear4e6975f2011-01-31 10:37:36 -0800412 "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n",
Felix Fietkau34302392011-01-24 19:23:15 +0100413 wiphy_name(sc->hw->wiphy),
Mohammed Shafi Shajakhan8e0167a2010-10-01 15:25:05 +0530414 ieee80211_frequency_to_channel(chan->center_freq),
Ben Greear4e6975f2011-01-31 10:37:36 -0800415 chan->center_freq,
416 conf->channel_type,
417 channel_type_str(conf->channel_type));
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200418
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400419 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
420 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200421 len += snprintf(buf + len, sizeof(buf) - len,
422 "addr: %pM\n", addr);
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400423 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
424 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200425 len += snprintf(buf + len, sizeof(buf) - len,
426 "addrmask: %pM\n", addr);
Ben Greear39057512010-09-14 12:46:04 -0700427 tmp = ath9k_hw_getrxfilter(sc->sc_ah);
428 len += snprintf(buf + len, sizeof(buf) - len,
429 "rfilt: 0x%x", tmp);
430 if (tmp & ATH9K_RX_FILTER_UCAST)
431 len += snprintf(buf + len, sizeof(buf) - len, " UCAST");
432 if (tmp & ATH9K_RX_FILTER_MCAST)
433 len += snprintf(buf + len, sizeof(buf) - len, " MCAST");
434 if (tmp & ATH9K_RX_FILTER_BCAST)
435 len += snprintf(buf + len, sizeof(buf) - len, " BCAST");
436 if (tmp & ATH9K_RX_FILTER_CONTROL)
437 len += snprintf(buf + len, sizeof(buf) - len, " CONTROL");
438 if (tmp & ATH9K_RX_FILTER_BEACON)
439 len += snprintf(buf + len, sizeof(buf) - len, " BEACON");
440 if (tmp & ATH9K_RX_FILTER_PROM)
441 len += snprintf(buf + len, sizeof(buf) - len, " PROM");
442 if (tmp & ATH9K_RX_FILTER_PROBEREQ)
443 len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ");
444 if (tmp & ATH9K_RX_FILTER_PHYERR)
445 len += snprintf(buf + len, sizeof(buf) - len, " PHYERR");
446 if (tmp & ATH9K_RX_FILTER_MYBEACON)
447 len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON");
448 if (tmp & ATH9K_RX_FILTER_COMP_BAR)
449 len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR");
450 if (tmp & ATH9K_RX_FILTER_PSPOLL)
451 len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL");
452 if (tmp & ATH9K_RX_FILTER_PHYRADAR)
453 len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR");
454 if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL)
455 len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n");
456 else
457 len += snprintf(buf + len, sizeof(buf) - len, "\n");
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200458
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200459 if (len > sizeof(buf))
460 len = sizeof(buf);
461
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200462 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
463}
464
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200465static const struct file_operations fops_wiphy = {
466 .read = read_file_wiphy,
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200467 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200468 .owner = THIS_MODULE,
469 .llseek = default_llseek,
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200470};
471
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100472#define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum
Sujithfec247c2009-07-27 12:08:16 +0530473#define PR(str, elem) \
474 do { \
475 len += snprintf(buf + len, size - len, \
476 "%s%13u%11u%10u%10u\n", str, \
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100477 sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \
478 sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \
479 sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \
480 sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \
Ben Greear7f010c92011-01-09 23:11:49 -0800481 if (len >= size) \
482 goto done; \
Sujithfec247c2009-07-27 12:08:16 +0530483} while(0)
484
Ben Greear1f427dd2011-01-09 23:11:43 -0800485#define PRX(str, elem) \
486do { \
487 len += snprintf(buf + len, size - len, \
488 "%s%13u%11u%10u%10u\n", str, \
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100489 (unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem), \
490 (unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem), \
491 (unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem), \
492 (unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem)); \
Ben Greear7f010c92011-01-09 23:11:49 -0800493 if (len >= size) \
494 goto done; \
Ben Greear1f427dd2011-01-09 23:11:43 -0800495} while(0)
496
Ben Greear2dac4fb2011-01-09 23:11:45 -0800497#define PRQLE(str, elem) \
498do { \
499 len += snprintf(buf + len, size - len, \
500 "%s%13i%11i%10i%10i\n", str, \
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100501 list_empty(&sc->tx.txq_map[WME_AC_BE]->elem), \
502 list_empty(&sc->tx.txq_map[WME_AC_BK]->elem), \
503 list_empty(&sc->tx.txq_map[WME_AC_VI]->elem), \
504 list_empty(&sc->tx.txq_map[WME_AC_VO]->elem)); \
Ben Greear7f010c92011-01-09 23:11:49 -0800505 if (len >= size) \
506 goto done; \
Ben Greear2dac4fb2011-01-09 23:11:45 -0800507} while (0)
508
Sujithfec247c2009-07-27 12:08:16 +0530509static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
510 size_t count, loff_t *ppos)
511{
512 struct ath_softc *sc = file->private_data;
513 char *buf;
Ben Greear7f010c92011-01-09 23:11:49 -0800514 unsigned int len = 0, size = 8000;
Ben Greear2dac4fb2011-01-09 23:11:45 -0800515 int i;
Sujithfec247c2009-07-27 12:08:16 +0530516 ssize_t retval = 0;
Ben Greear2dac4fb2011-01-09 23:11:45 -0800517 char tmp[32];
Sujithfec247c2009-07-27 12:08:16 +0530518
519 buf = kzalloc(size, GFP_KERNEL);
520 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200521 return -ENOMEM;
Sujithfec247c2009-07-27 12:08:16 +0530522
Ben Greear60f2d1d2011-01-09 23:11:52 -0800523 len += sprintf(buf, "Num-Tx-Queues: %i tx-queues-setup: 0x%x"
524 " poll-work-seen: %u\n"
Ben Greear7f010c92011-01-09 23:11:49 -0800525 "%30s %10s%10s%10s\n\n",
526 ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup,
Ben Greear60f2d1d2011-01-09 23:11:52 -0800527 sc->tx_complete_poll_work_seen,
Ben Greear7f010c92011-01-09 23:11:49 -0800528 "BE", "BK", "VI", "VO");
Sujithfec247c2009-07-27 12:08:16 +0530529
530 PR("MPDUs Queued: ", queued);
531 PR("MPDUs Completed: ", completed);
532 PR("Aggregates: ", a_aggr);
Ben Greearbda8add2011-01-09 23:11:48 -0800533 PR("AMPDUs Queued HW:", a_queued_hw);
534 PR("AMPDUs Queued SW:", a_queued_sw);
Sujithfec247c2009-07-27 12:08:16 +0530535 PR("AMPDUs Completed:", a_completed);
536 PR("AMPDUs Retried: ", a_retries);
537 PR("AMPDUs XRetried: ", a_xretries);
538 PR("FIFO Underrun: ", fifo_underrun);
539 PR("TXOP Exceeded: ", xtxop);
540 PR("TXTIMER Expiry: ", timer_exp);
541 PR("DESC CFG Error: ", desc_cfg_err);
542 PR("DATA Underrun: ", data_underrun);
543 PR("DELIM Underrun: ", delim_underrun);
Ben Greear99c15bf2010-10-01 12:26:30 -0700544 PR("TX-Pkts-All: ", tx_pkts_all);
545 PR("TX-Bytes-All: ", tx_bytes_all);
Ben Greear2dac4fb2011-01-09 23:11:45 -0800546 PR("hw-put-tx-buf: ", puttxbuf);
547 PR("hw-tx-start: ", txstart);
548 PR("hw-tx-proc-desc: ", txprocdesc);
Ben Greear7f010c92011-01-09 23:11:49 -0800549 len += snprintf(buf + len, size - len,
550 "%s%11p%11p%10p%10p\n", "txq-memory-address:",
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100551 &(sc->tx.txq_map[WME_AC_BE]),
552 &(sc->tx.txq_map[WME_AC_BK]),
553 &(sc->tx.txq_map[WME_AC_VI]),
554 &(sc->tx.txq_map[WME_AC_VO]));
Ben Greear7f010c92011-01-09 23:11:49 -0800555 if (len >= size)
556 goto done;
Sujithfec247c2009-07-27 12:08:16 +0530557
Ben Greear1f427dd2011-01-09 23:11:43 -0800558 PRX("axq-qnum: ", axq_qnum);
559 PRX("axq-depth: ", axq_depth);
Ben Greear2dac4fb2011-01-09 23:11:45 -0800560 PRX("axq-ampdu_depth: ", axq_ampdu_depth);
Ben Greear1f427dd2011-01-09 23:11:43 -0800561 PRX("axq-stopped ", stopped);
562 PRX("tx-in-progress ", axq_tx_inprogress);
563 PRX("pending-frames ", pending_frames);
Ben Greear2dac4fb2011-01-09 23:11:45 -0800564 PRX("txq_headidx: ", txq_headidx);
565 PRX("txq_tailidx: ", txq_headidx);
Ben Greear1f427dd2011-01-09 23:11:43 -0800566
Ben Greear2dac4fb2011-01-09 23:11:45 -0800567 PRQLE("axq_q empty: ", axq_q);
568 PRQLE("axq_acq empty: ", axq_acq);
569 PRQLE("txq_fifo_pending: ", txq_fifo_pending);
570 for (i = 0; i < ATH_TXFIFO_DEPTH; i++) {
571 snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i);
572 PRQLE(tmp, txq_fifo[i]);
573 }
Ben Greear7f010c92011-01-09 23:11:49 -0800574
Ben Greear71e025a2011-01-09 23:11:50 -0800575 /* Print out more detailed queue-info */
576 for (i = 0; i <= WME_AC_BK; i++) {
577 struct ath_txq *txq = &(sc->tx.txq[i]);
578 struct ath_atx_ac *ac;
579 struct ath_atx_tid *tid;
580 if (len >= size)
581 goto done;
582 spin_lock_bh(&txq->axq_lock);
583 if (!list_empty(&txq->axq_acq)) {
584 ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac,
585 list);
586 len += snprintf(buf + len, size - len,
587 "txq[%i] first-ac: %p sched: %i\n",
588 i, ac, ac->sched);
589 if (list_empty(&ac->tid_q) || (len >= size))
590 goto done_for;
591 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
592 list);
593 len += snprintf(buf + len, size - len,
594 " first-tid: %p sched: %i paused: %i\n",
595 tid, tid->sched, tid->paused);
596 }
597 done_for:
598 spin_unlock_bh(&txq->axq_lock);
599 }
600
Ben Greear7f010c92011-01-09 23:11:49 -0800601done:
602 if (len > size)
603 len = size;
604
605 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
606 kfree(buf);
607
608 return retval;
609}
610
611static ssize_t read_file_stations(struct file *file, char __user *user_buf,
612 size_t count, loff_t *ppos)
613{
614 struct ath_softc *sc = file->private_data;
615 char *buf;
616 unsigned int len = 0, size = 64000;
617 struct ath_node *an = NULL;
618 ssize_t retval = 0;
619 int q;
620
621 buf = kzalloc(size, GFP_KERNEL);
622 if (buf == NULL)
623 return -ENOMEM;
624
625 len += snprintf(buf + len, size - len,
626 "Stations:\n"
627 " tid: addr sched paused buf_q-empty an ac\n"
628 " ac: addr sched tid_q-empty txq\n");
629
630 spin_lock(&sc->nodes_lock);
631 list_for_each_entry(an, &sc->nodes, list) {
632 len += snprintf(buf + len, size - len,
633 "%pM\n", an->sta->addr);
634 if (len >= size)
635 goto done;
636
637 for (q = 0; q < WME_NUM_TID; q++) {
638 struct ath_atx_tid *tid = &(an->tid[q]);
639 len += snprintf(buf + len, size - len,
640 " tid: %p %s %s %i %p %p\n",
641 tid, tid->sched ? "sched" : "idle",
642 tid->paused ? "paused" : "running",
643 list_empty(&tid->buf_q),
644 tid->an, tid->ac);
645 if (len >= size)
646 goto done;
647 }
648
649 for (q = 0; q < WME_NUM_AC; q++) {
650 struct ath_atx_ac *ac = &(an->ac[q]);
651 len += snprintf(buf + len, size - len,
652 " ac: %p %s %i %p\n",
653 ac, ac->sched ? "sched" : "idle",
654 list_empty(&ac->tid_q), ac->txq);
655 if (len >= size)
656 goto done;
657 }
658 }
659
660done:
661 spin_unlock(&sc->nodes_lock);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200662 if (len > size)
663 len = size;
664
Sujithfec247c2009-07-27 12:08:16 +0530665 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
666 kfree(buf);
667
668 return retval;
669}
670
Ben Greear55f6d0f2011-01-17 11:54:50 -0800671static ssize_t read_file_misc(struct file *file, char __user *user_buf,
672 size_t count, loff_t *ppos)
673{
674 struct ath_softc *sc = file->private_data;
675 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
676 struct ath_hw *ah = sc->sc_ah;
677 struct ieee80211_hw *hw = sc->hw;
678 char *buf;
679 unsigned int len = 0, size = 8000;
680 ssize_t retval = 0;
681 const char *tmp;
682 unsigned int reg;
683 struct ath9k_vif_iter_data iter_data;
684
685 ath9k_calculate_iter_data(hw, NULL, &iter_data);
686
687 buf = kzalloc(size, GFP_KERNEL);
688 if (buf == NULL)
689 return -ENOMEM;
690
691 switch (sc->sc_ah->opmode) {
692 case NL80211_IFTYPE_ADHOC:
693 tmp = "ADHOC";
694 break;
695 case NL80211_IFTYPE_MESH_POINT:
696 tmp = "MESH";
697 break;
698 case NL80211_IFTYPE_AP:
699 tmp = "AP";
700 break;
701 case NL80211_IFTYPE_STATION:
702 tmp = "STATION";
703 break;
704 default:
705 tmp = "???";
706 break;
707 }
708
709 len += snprintf(buf + len, size - len,
710 "curbssid: %pM\n"
711 "OP-Mode: %s(%i)\n"
712 "Beacon-Timer-Register: 0x%x\n",
713 common->curbssid,
714 tmp, (int)(sc->sc_ah->opmode),
715 REG_READ(ah, AR_BEACON_PERIOD));
716
717 reg = REG_READ(ah, AR_TIMER_MODE);
718 len += snprintf(buf + len, size - len, "Timer-Mode-Register: 0x%x (",
719 reg);
720 if (reg & AR_TBTT_TIMER_EN)
721 len += snprintf(buf + len, size - len, "TBTT ");
722 if (reg & AR_DBA_TIMER_EN)
723 len += snprintf(buf + len, size - len, "DBA ");
724 if (reg & AR_SWBA_TIMER_EN)
725 len += snprintf(buf + len, size - len, "SWBA ");
726 if (reg & AR_HCF_TIMER_EN)
727 len += snprintf(buf + len, size - len, "HCF ");
728 if (reg & AR_TIM_TIMER_EN)
729 len += snprintf(buf + len, size - len, "TIM ");
730 if (reg & AR_DTIM_TIMER_EN)
731 len += snprintf(buf + len, size - len, "DTIM ");
732 len += snprintf(buf + len, size - len, ")\n");
733
734 reg = sc->sc_ah->imask;
735 len += snprintf(buf + len, size - len, "imask: 0x%x (", reg);
736 if (reg & ATH9K_INT_SWBA)
737 len += snprintf(buf + len, size - len, "SWBA ");
738 if (reg & ATH9K_INT_BMISS)
739 len += snprintf(buf + len, size - len, "BMISS ");
740 if (reg & ATH9K_INT_CST)
741 len += snprintf(buf + len, size - len, "CST ");
742 if (reg & ATH9K_INT_RX)
743 len += snprintf(buf + len, size - len, "RX ");
744 if (reg & ATH9K_INT_RXHP)
745 len += snprintf(buf + len, size - len, "RXHP ");
746 if (reg & ATH9K_INT_RXLP)
747 len += snprintf(buf + len, size - len, "RXLP ");
748 if (reg & ATH9K_INT_BB_WATCHDOG)
749 len += snprintf(buf + len, size - len, "BB_WATCHDOG ");
750 /* there are other IRQs if one wanted to add them. */
751 len += snprintf(buf + len, size - len, ")\n");
752
753 len += snprintf(buf + len, size - len,
754 "VIF Counts: AP: %i STA: %i MESH: %i WDS: %i"
755 " ADHOC: %i OTHER: %i nvifs: %hi beacon-vifs: %hi\n",
756 iter_data.naps, iter_data.nstations, iter_data.nmeshes,
757 iter_data.nwds, iter_data.nadhocs, iter_data.nothers,
758 sc->nvifs, sc->nbcnvifs);
759
760 len += snprintf(buf + len, size - len,
761 "Calculated-BSSID-Mask: %pM\n",
762 iter_data.mask);
763
764 if (len > size)
765 len = size;
766
767 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
768 kfree(buf);
769
770 return retval;
771}
772
Felix Fietkau066dae92010-11-07 14:59:39 +0100773void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf,
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100774 struct ath_tx_status *ts, struct ath_txq *txq)
Sujithfec247c2009-07-27 12:08:16 +0530775{
Felix Fietkau5bec3e52011-01-24 21:29:25 +0100776 int qnum = txq->axq_qnum;
Felix Fietkau066dae92010-11-07 14:59:39 +0100777
778 TX_STAT_INC(qnum, tx_pkts_all);
779 sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len;
Ben Greear99c15bf2010-10-01 12:26:30 -0700780
Sujithfec247c2009-07-27 12:08:16 +0530781 if (bf_isampdu(bf)) {
782 if (bf_isxretried(bf))
Felix Fietkau066dae92010-11-07 14:59:39 +0100783 TX_STAT_INC(qnum, a_xretries);
Sujithfec247c2009-07-27 12:08:16 +0530784 else
Felix Fietkau066dae92010-11-07 14:59:39 +0100785 TX_STAT_INC(qnum, a_completed);
Sujithfec247c2009-07-27 12:08:16 +0530786 } else {
Felix Fietkau066dae92010-11-07 14:59:39 +0100787 TX_STAT_INC(qnum, completed);
Sujithfec247c2009-07-27 12:08:16 +0530788 }
789
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700790 if (ts->ts_status & ATH9K_TXERR_FIFO)
Felix Fietkau066dae92010-11-07 14:59:39 +0100791 TX_STAT_INC(qnum, fifo_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700792 if (ts->ts_status & ATH9K_TXERR_XTXOP)
Felix Fietkau066dae92010-11-07 14:59:39 +0100793 TX_STAT_INC(qnum, xtxop);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700794 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
Felix Fietkau066dae92010-11-07 14:59:39 +0100795 TX_STAT_INC(qnum, timer_exp);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700796 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
Felix Fietkau066dae92010-11-07 14:59:39 +0100797 TX_STAT_INC(qnum, desc_cfg_err);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700798 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100799 TX_STAT_INC(qnum, data_underrun);
Felix Fietkaudb1a0522010-03-29 20:07:11 -0700800 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
Felix Fietkau066dae92010-11-07 14:59:39 +0100801 TX_STAT_INC(qnum, delim_underrun);
Sujithfec247c2009-07-27 12:08:16 +0530802}
803
804static const struct file_operations fops_xmit = {
805 .read = read_file_xmit,
806 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200807 .owner = THIS_MODULE,
808 .llseek = default_llseek,
Sujithfec247c2009-07-27 12:08:16 +0530809};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200810
Ben Greear7f010c92011-01-09 23:11:49 -0800811static const struct file_operations fops_stations = {
812 .read = read_file_stations,
813 .open = ath9k_debugfs_open,
814 .owner = THIS_MODULE,
815 .llseek = default_llseek,
816};
817
Ben Greear55f6d0f2011-01-17 11:54:50 -0800818static const struct file_operations fops_misc = {
819 .read = read_file_misc,
820 .open = ath9k_debugfs_open,
821 .owner = THIS_MODULE,
822 .llseek = default_llseek,
823};
824
Sujith1395d3f2010-01-08 10:36:11 +0530825static ssize_t read_file_recv(struct file *file, char __user *user_buf,
826 size_t count, loff_t *ppos)
827{
828#define PHY_ERR(s, p) \
829 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
830 sc->debug.stats.rxstats.phy_err_stats[p]);
831
832 struct ath_softc *sc = file->private_data;
833 char *buf;
834 unsigned int len = 0, size = 1152;
835 ssize_t retval = 0;
836
837 buf = kzalloc(size, GFP_KERNEL);
838 if (buf == NULL)
Dan Carpenter04236062010-05-14 15:25:39 +0200839 return -ENOMEM;
Sujith1395d3f2010-01-08 10:36:11 +0530840
841 len += snprintf(buf + len, size - len,
842 "%18s : %10u\n", "CRC ERR",
843 sc->debug.stats.rxstats.crc_err);
844 len += snprintf(buf + len, size - len,
845 "%18s : %10u\n", "DECRYPT CRC ERR",
846 sc->debug.stats.rxstats.decrypt_crc_err);
847 len += snprintf(buf + len, size - len,
848 "%18s : %10u\n", "PHY ERR",
849 sc->debug.stats.rxstats.phy_err);
850 len += snprintf(buf + len, size - len,
851 "%18s : %10u\n", "MIC ERR",
852 sc->debug.stats.rxstats.mic_err);
853 len += snprintf(buf + len, size - len,
854 "%18s : %10u\n", "PRE-DELIM CRC ERR",
855 sc->debug.stats.rxstats.pre_delim_crc_err);
856 len += snprintf(buf + len, size - len,
857 "%18s : %10u\n", "POST-DELIM CRC ERR",
858 sc->debug.stats.rxstats.post_delim_crc_err);
859 len += snprintf(buf + len, size - len,
860 "%18s : %10u\n", "DECRYPT BUSY ERR",
861 sc->debug.stats.rxstats.decrypt_busy_err);
862
863 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
864 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
865 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
866 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
867 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
868 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
869 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
870 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
871 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
872 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
873 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
874 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
875 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
876 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
877 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
878 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
879 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
880 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
881 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
882 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
883 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
884 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
885 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
886 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
887 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
888 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
889
Ben Greear99c15bf2010-10-01 12:26:30 -0700890 len += snprintf(buf + len, size - len,
891 "%18s : %10u\n", "RX-Pkts-All",
892 sc->debug.stats.rxstats.rx_pkts_all);
893 len += snprintf(buf + len, size - len,
894 "%18s : %10u\n", "RX-Bytes-All",
895 sc->debug.stats.rxstats.rx_bytes_all);
896
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200897 if (len > size)
898 len = size;
899
Sujith1395d3f2010-01-08 10:36:11 +0530900 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
901 kfree(buf);
902
903 return retval;
904
905#undef PHY_ERR
906}
907
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700908void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
Sujith1395d3f2010-01-08 10:36:11 +0530909{
910#define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
911#define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
912
Sujith1395d3f2010-01-08 10:36:11 +0530913 u32 phyerr;
914
Ben Greear99c15bf2010-10-01 12:26:30 -0700915 RX_STAT_INC(rx_pkts_all);
916 sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen;
917
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700918 if (rs->rs_status & ATH9K_RXERR_CRC)
Sujith1395d3f2010-01-08 10:36:11 +0530919 RX_STAT_INC(crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700920 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
Sujith1395d3f2010-01-08 10:36:11 +0530921 RX_STAT_INC(decrypt_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700922 if (rs->rs_status & ATH9K_RXERR_MIC)
Sujith1395d3f2010-01-08 10:36:11 +0530923 RX_STAT_INC(mic_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700924 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
Sujith1395d3f2010-01-08 10:36:11 +0530925 RX_STAT_INC(pre_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700926 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
Sujith1395d3f2010-01-08 10:36:11 +0530927 RX_STAT_INC(post_delim_crc_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700928 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
Sujith1395d3f2010-01-08 10:36:11 +0530929 RX_STAT_INC(decrypt_busy_err);
930
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700931 if (rs->rs_status & ATH9K_RXERR_PHY) {
Sujith1395d3f2010-01-08 10:36:11 +0530932 RX_STAT_INC(phy_err);
Felix Fietkau8e6f5aa2010-03-29 20:09:27 -0700933 phyerr = rs->rs_phyerr & 0x24;
Sujith1395d3f2010-01-08 10:36:11 +0530934 RX_PHY_ERR_INC(phyerr);
935 }
936
937#undef RX_STAT_INC
938#undef RX_PHY_ERR_INC
939}
940
941static const struct file_operations fops_recv = {
942 .read = read_file_recv,
943 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200944 .owner = THIS_MODULE,
945 .llseek = default_llseek,
Sujith1395d3f2010-01-08 10:36:11 +0530946};
947
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200948static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
949 size_t count, loff_t *ppos)
950{
951 struct ath_softc *sc = file->private_data;
952 char buf[32];
953 unsigned int len;
954
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200955 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200956 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
957}
958
959static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
960 size_t count, loff_t *ppos)
961{
962 struct ath_softc *sc = file->private_data;
963 unsigned long regidx;
964 char buf[32];
965 ssize_t len;
966
967 len = min(count, sizeof(buf) - 1);
968 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +0200969 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200970
971 buf[len] = '\0';
972 if (strict_strtoul(buf, 0, &regidx))
973 return -EINVAL;
974
975 sc->debug.regidx = regidx;
976 return count;
977}
978
979static const struct file_operations fops_regidx = {
980 .read = read_file_regidx,
981 .write = write_file_regidx,
982 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200983 .owner = THIS_MODULE,
984 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200985};
986
987static ssize_t read_file_regval(struct file *file, char __user *user_buf,
988 size_t count, loff_t *ppos)
989{
990 struct ath_softc *sc = file->private_data;
991 struct ath_hw *ah = sc->sc_ah;
992 char buf[32];
993 unsigned int len;
994 u32 regval;
995
996 regval = REG_READ_D(ah, sc->debug.regidx);
Dan Carpenter2b87f3a2010-05-14 15:24:37 +0200997 len = sprintf(buf, "0x%08x\n", regval);
Felix Fietkau9bff0bc2010-05-11 17:23:02 +0200998 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
999}
1000
1001static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
1002 size_t count, loff_t *ppos)
1003{
1004 struct ath_softc *sc = file->private_data;
1005 struct ath_hw *ah = sc->sc_ah;
1006 unsigned long regval;
1007 char buf[32];
1008 ssize_t len;
1009
1010 len = min(count, sizeof(buf) - 1);
1011 if (copy_from_user(buf, user_buf, len))
Dan Carpenter04236062010-05-14 15:25:39 +02001012 return -EFAULT;
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001013
1014 buf[len] = '\0';
1015 if (strict_strtoul(buf, 0, &regval))
1016 return -EINVAL;
1017
1018 REG_WRITE_D(ah, sc->debug.regidx, regval);
1019 return count;
1020}
1021
1022static const struct file_operations fops_regval = {
1023 .read = read_file_regval,
1024 .write = write_file_regval,
1025 .open = ath9k_debugfs_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001026 .owner = THIS_MODULE,
1027 .llseek = default_llseek,
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001028};
1029
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001030int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +05301031{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001032 struct ath_common *common = ath9k_hw_common(ah);
1033 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001034
Ben Greeareb272442010-11-29 14:13:22 -08001035 sc->debug.debugfs_phy = debugfs_create_dir("ath9k",
1036 sc->hw->wiphy->debugfsdir);
Sujith17d79042009-02-09 13:27:03 +05301037 if (!sc->debug.debugfs_phy)
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001038 return -ENOMEM;
Sujith826d2682008-11-28 22:20:23 +05301039
Felix Fietkaua830df02009-11-23 22:33:27 +01001040#ifdef CONFIG_ATH_DEBUG
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001041 if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
1042 sc->debug.debugfs_phy, sc, &fops_debug))
Jeff Hansen24939282009-05-27 12:48:29 +00001043 goto err;
Felix Fietkaua830df02009-11-23 22:33:27 +01001044#endif
Jeff Hansen24939282009-05-27 12:48:29 +00001045
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001046 if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
1047 sc, &fops_dma))
Sujith2a163c62008-11-28 22:21:08 +05301048 goto err;
1049
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001050 if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
1051 sc, &fops_interrupt))
Sujith817e11d2008-12-07 21:42:44 +05301052 goto err;
1053
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001054 if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
1055 sc->debug.debugfs_phy, sc, &fops_wiphy))
Jouni Malinen39d89cd2009-03-03 19:23:40 +02001056 goto err;
1057
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001058 if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
1059 sc, &fops_xmit))
Sujithfec247c2009-07-27 12:08:16 +05301060 goto err;
1061
Ben Greear7f010c92011-01-09 23:11:49 -08001062 if (!debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy,
1063 sc, &fops_stations))
1064 goto err;
1065
Ben Greear55f6d0f2011-01-17 11:54:50 -08001066 if (!debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy,
1067 sc, &fops_misc))
1068 goto err;
1069
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001070 if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
1071 sc, &fops_recv))
Sujith1395d3f2010-01-08 10:36:11 +05301072 goto err;
1073
Felix Fietkau15340692010-05-11 17:23:01 +02001074 if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
1075 sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
1076 goto err;
1077
1078 if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
1079 sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
1080 goto err;
1081
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001082 if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
1083 sc->debug.debugfs_phy, sc, &fops_regidx))
1084 goto err;
1085
1086 if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
1087 sc->debug.debugfs_phy, sc, &fops_regval))
1088 goto err;
1089
Felix Fietkau41f3e542010-06-12 00:33:56 -04001090 if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
1091 sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
1092 goto err;
1093
Felix Fietkau9bff0bc2010-05-11 17:23:02 +02001094 sc->debug.regidx = 0;
Sujith826d2682008-11-28 22:20:23 +05301095 return 0;
1096err:
Felix Fietkauc8a72c02010-05-11 17:23:00 +02001097 debugfs_remove_recursive(sc->debug.debugfs_phy);
Ben Greeareb272442010-11-29 14:13:22 -08001098 sc->debug.debugfs_phy = NULL;
1099 return -ENOMEM;
Sujith88b126a2008-11-28 22:19:02 +05301100}