blob: 608fa06e531cfc107cb8fdc3a0bba7c43c47fb0f [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
Gabor Juhos52103112009-03-06 09:57:39 +010017#include <asm/unaligned.h>
18
Sujith394cf0a2009-02-09 13:26:54 +053019#include "ath9k.h"
Sujith88b126a2008-11-28 22:19:02 +053020
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -040021#define REG_WRITE_D(_ah, _reg, _val) \
22 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
23#define REG_READ_D(_ah, _reg) \
24 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
25
Gabor Juhos19d8bc22009-03-05 16:55:18 +010026static struct dentry *ath9k_debugfs_root;
27
Sujith2a163c62008-11-28 22:21:08 +053028static int ath9k_debugfs_open(struct inode *inode, struct file *file)
29{
30 file->private_data = inode->i_private;
31 return 0;
32}
33
Jeff Hansen24939282009-05-27 12:48:29 +000034static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35 size_t count, loff_t *ppos)
36{
37 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070038 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000039 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053040 unsigned int len;
41
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070042 len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask);
Jeff Hansen24939282009-05-27 12:48:29 +000043 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
44}
45
46static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
47 size_t count, loff_t *ppos)
48{
49 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070050 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000051 unsigned long mask;
52 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053053 ssize_t len;
54
55 len = min(count, sizeof(buf) - 1);
56 if (copy_from_user(buf, user_buf, len))
57 return -EINVAL;
58
59 buf[len] = '\0';
60 if (strict_strtoul(buf, 0, &mask))
61 return -EINVAL;
62
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070063 common->debug_mask = mask;
Jeff Hansen24939282009-05-27 12:48:29 +000064 return count;
65}
66
67static const struct file_operations fops_debug = {
68 .read = read_file_debug,
69 .write = write_file_debug,
70 .open = ath9k_debugfs_open,
71 .owner = THIS_MODULE
72};
73
Sujith2a163c62008-11-28 22:21:08 +053074static ssize_t read_file_dma(struct file *file, char __user *user_buf,
75 size_t count, loff_t *ppos)
76{
77 struct ath_softc *sc = file->private_data;
Sujithcbe61d82009-02-09 13:27:12 +053078 struct ath_hw *ah = sc->sc_ah;
Sujith2a163c62008-11-28 22:21:08 +053079 char buf[1024];
80 unsigned int len = 0;
81 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
82 int i, qcuOffset = 0, dcuOffset = 0;
83 u32 *qcuBase = &val[0], *dcuBase = &val[4];
84
Sujith7cf4a2e2009-08-26 11:11:57 +053085 ath9k_ps_wakeup(sc);
86
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -040087 REG_WRITE_D(ah, AR_MACMISC,
Sujith2a163c62008-11-28 22:21:08 +053088 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
89 (AR_MACMISC_MISC_OBS_BUS_1 <<
90 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
91
92 len += snprintf(buf + len, sizeof(buf) - len,
93 "Raw DMA Debug values:\n");
94
95 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
96 if (i % 4 == 0)
97 len += snprintf(buf + len, sizeof(buf) - len, "\n");
98
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -040099 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
Sujith2a163c62008-11-28 22:21:08 +0530100 len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ",
101 i, val[i]);
102 }
103
104 len += snprintf(buf + len, sizeof(buf) - len, "\n\n");
105 len += snprintf(buf + len, sizeof(buf) - len,
106 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
107
108 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
109 if (i == 8) {
110 qcuOffset = 0;
111 qcuBase++;
112 }
113
114 if (i == 6) {
115 dcuOffset = 0;
116 dcuBase++;
117 }
118
119 len += snprintf(buf + len, sizeof(buf) - len,
120 "%2d %2x %1x %2x %2x\n",
121 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
122 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
123 val[2] & (0x7 << (i * 3)) >> (i * 3),
124 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
125 }
126
127 len += snprintf(buf + len, sizeof(buf) - len, "\n");
128
129 len += snprintf(buf + len, sizeof(buf) - len,
130 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
131 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
132 len += snprintf(buf + len, sizeof(buf) - len,
133 "qcu_complete state: %2x dcu_complete state: %2x\n",
134 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
135 len += snprintf(buf + len, sizeof(buf) - len,
136 "dcu_arb state: %2x dcu_fp state: %2x\n",
137 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
138 len += snprintf(buf + len, sizeof(buf) - len,
139 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
140 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
141 len += snprintf(buf + len, sizeof(buf) - len,
142 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
143 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
144 len += snprintf(buf + len, sizeof(buf) - len,
145 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
146 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
147
148 len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n",
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400149 REG_READ_D(ah, AR_OBS_BUS_1));
Sujith2a163c62008-11-28 22:21:08 +0530150 len += snprintf(buf + len, sizeof(buf) - len,
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400151 "AR_CR: 0x%x \n", REG_READ_D(ah, AR_CR));
Sujith2a163c62008-11-28 22:21:08 +0530152
Sujith7cf4a2e2009-08-26 11:11:57 +0530153 ath9k_ps_restore(sc);
154
Sujith2a163c62008-11-28 22:21:08 +0530155 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
156}
157
158static const struct file_operations fops_dma = {
159 .read = read_file_dma,
160 .open = ath9k_debugfs_open,
161 .owner = THIS_MODULE
162};
163
Sujith817e11d2008-12-07 21:42:44 +0530164
165void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
166{
167 if (status)
Sujith17d79042009-02-09 13:27:03 +0530168 sc->debug.stats.istats.total++;
Sujith817e11d2008-12-07 21:42:44 +0530169 if (status & ATH9K_INT_RX)
Sujith17d79042009-02-09 13:27:03 +0530170 sc->debug.stats.istats.rxok++;
Sujith817e11d2008-12-07 21:42:44 +0530171 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530172 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530173 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530174 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530175 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530176 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530177 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530178 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530179 if (status & ATH9K_INT_MIB)
Sujith17d79042009-02-09 13:27:03 +0530180 sc->debug.stats.istats.mib++;
Sujith817e11d2008-12-07 21:42:44 +0530181 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530182 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530183 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530184 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530185 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530186 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530187 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530188 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530189 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530190 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530191 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530192 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530193 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530194 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530195 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530196 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530197 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530198 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530199 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530200 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530201 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530202 sc->debug.stats.istats.dtim++;
Sujith817e11d2008-12-07 21:42:44 +0530203}
204
205static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
206 size_t count, loff_t *ppos)
207{
208 struct ath_softc *sc = file->private_data;
209 char buf[512];
210 unsigned int len = 0;
211
212 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530213 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
Sujith817e11d2008-12-07 21:42:44 +0530214 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530215 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
Sujith817e11d2008-12-07 21:42:44 +0530216 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530217 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
Sujith817e11d2008-12-07 21:42:44 +0530218 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530219 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
Sujith817e11d2008-12-07 21:42:44 +0530220 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530221 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
Sujith817e11d2008-12-07 21:42:44 +0530222 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530223 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
Sujith817e11d2008-12-07 21:42:44 +0530224 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530225 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
Sujith817e11d2008-12-07 21:42:44 +0530226 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530227 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
Sujith817e11d2008-12-07 21:42:44 +0530228 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530229 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
Sujith817e11d2008-12-07 21:42:44 +0530230 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530231 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
Sujith817e11d2008-12-07 21:42:44 +0530232 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530233 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
Sujith817e11d2008-12-07 21:42:44 +0530234 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530235 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
Sujith817e11d2008-12-07 21:42:44 +0530236 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530237 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
Sujith817e11d2008-12-07 21:42:44 +0530238 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530239 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
Sujith817e11d2008-12-07 21:42:44 +0530240 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530241 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
Sujith817e11d2008-12-07 21:42:44 +0530242 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530243 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
Sujith817e11d2008-12-07 21:42:44 +0530244 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530245 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
Sujith817e11d2008-12-07 21:42:44 +0530246 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530247 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
Sujith817e11d2008-12-07 21:42:44 +0530248
249 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
250}
251
252static const struct file_operations fops_interrupt = {
253 .read = read_file_interrupt,
254 .open = ath9k_debugfs_open,
255 .owner = THIS_MODULE
256};
257
Felix Fietkau545750d2009-11-23 22:21:01 +0100258void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
Sujith7a7dec62009-01-30 14:32:09 +0530259{
Jeff Hansenbedf0872009-05-27 12:48:28 +0000260 struct ath_rc_stats *stats;
Sujith7a7dec62009-01-30 14:32:09 +0530261
Felix Fietkau545750d2009-11-23 22:21:01 +0100262 stats = &sc->debug.stats.rcstats[final_rate];
Jeff Hansenbedf0872009-05-27 12:48:28 +0000263 stats->success++;
Sujith7a7dec62009-01-30 14:32:09 +0530264}
265
Sujith029bc432009-02-04 08:10:26 +0530266void ath_debug_stat_retries(struct ath_softc *sc, int rix,
Sujith9e712792009-02-20 15:13:20 +0530267 int xretries, int retries, u8 per)
Sujith029bc432009-02-04 08:10:26 +0530268{
Jeff Hansenbedf0872009-05-27 12:48:28 +0000269 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
Sujith029bc432009-02-04 08:10:26 +0530270
Jeff Hansenbedf0872009-05-27 12:48:28 +0000271 stats->xretries += xretries;
272 stats->retries += retries;
273 stats->per = per;
Sujith7a7dec62009-01-30 14:32:09 +0530274}
275
276static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
277 size_t count, loff_t *ppos)
278{
279 struct ath_softc *sc = file->private_data;
Jeff Hansenbedf0872009-05-27 12:48:28 +0000280 char *buf;
281 unsigned int len = 0, max;
282 int i = 0;
283 ssize_t retval;
Sujith7a7dec62009-01-30 14:32:09 +0530284
Sujith62b4fb62009-03-09 09:32:01 +0530285 if (sc->cur_rate_table == NULL)
286 return 0;
287
Jeff Hansenbedf0872009-05-27 12:48:28 +0000288 max = 80 + sc->cur_rate_table->rate_cnt * 64;
289 buf = kmalloc(max + 1, GFP_KERNEL);
290 if (buf == NULL)
291 return 0;
292 buf[max] = 0;
293
294 len += sprintf(buf, "%5s %15s %8s %9s %3s\n\n", "Rate", "Success",
295 "Retries", "XRetries", "PER");
296
297 for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
298 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
299 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
300
301 len += snprintf(buf + len, max - len,
302 "%3u.%d: %8u %8u %8u %8u\n", ratekbps / 1000,
303 (ratekbps % 1000) / 100, stats->success,
304 stats->retries, stats->xretries,
305 stats->per);
306 }
307
308 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
309 kfree(buf);
310 return retval;
Sujith7a7dec62009-01-30 14:32:09 +0530311}
312
313static const struct file_operations fops_rcstat = {
314 .read = read_file_rcstat,
315 .open = ath9k_debugfs_open,
316 .owner = THIS_MODULE
317};
Alina Friedrichsen27abe062009-01-23 05:44:21 +0100318
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200319static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
320{
321 switch (state) {
322 case ATH_WIPHY_INACTIVE:
323 return "INACTIVE";
324 case ATH_WIPHY_ACTIVE:
325 return "ACTIVE";
326 case ATH_WIPHY_PAUSING:
327 return "PAUSING";
328 case ATH_WIPHY_PAUSED:
329 return "PAUSED";
330 case ATH_WIPHY_SCAN:
331 return "SCAN";
332 }
333 return "?";
334}
335
336static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
337 size_t count, loff_t *ppos)
338{
339 struct ath_softc *sc = file->private_data;
340 char buf[512];
341 unsigned int len = 0;
342 int i;
343 u8 addr[ETH_ALEN];
344
345 len += snprintf(buf + len, sizeof(buf) - len,
346 "primary: %s (%s chan=%d ht=%d)\n",
347 wiphy_name(sc->pri_wiphy->hw->wiphy),
348 ath_wiphy_state_str(sc->pri_wiphy->state),
349 sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
350 for (i = 0; i < sc->num_sec_wiphy; i++) {
351 struct ath_wiphy *aphy = sc->sec_wiphy[i];
352 if (aphy == NULL)
353 continue;
354 len += snprintf(buf + len, sizeof(buf) - len,
355 "secondary: %s (%s chan=%d ht=%d)\n",
356 wiphy_name(aphy->hw->wiphy),
357 ath_wiphy_state_str(aphy->state),
358 aphy->chan_idx, aphy->chan_is_ht);
359 }
360
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400361 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
362 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200363 len += snprintf(buf + len, sizeof(buf) - len,
364 "addr: %pM\n", addr);
Luis R. Rodriguez475a6e42009-09-23 23:06:59 -0400365 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
366 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200367 len += snprintf(buf + len, sizeof(buf) - len,
368 "addrmask: %pM\n", addr);
369
370 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
371}
372
373static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
374{
375 int i;
376 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
377 return sc->pri_wiphy;
378 for (i = 0; i < sc->num_sec_wiphy; i++) {
379 struct ath_wiphy *aphy = sc->sec_wiphy[i];
380 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
381 return aphy;
382 }
383 return NULL;
384}
385
386static int del_wiphy(struct ath_softc *sc, const char *name)
387{
388 struct ath_wiphy *aphy = get_wiphy(sc, name);
389 if (!aphy)
390 return -ENOENT;
391 return ath9k_wiphy_del(aphy);
392}
393
394static int pause_wiphy(struct ath_softc *sc, const char *name)
395{
396 struct ath_wiphy *aphy = get_wiphy(sc, name);
397 if (!aphy)
398 return -ENOENT;
399 return ath9k_wiphy_pause(aphy);
400}
401
402static int unpause_wiphy(struct ath_softc *sc, const char *name)
403{
404 struct ath_wiphy *aphy = get_wiphy(sc, name);
405 if (!aphy)
406 return -ENOENT;
407 return ath9k_wiphy_unpause(aphy);
408}
409
410static int select_wiphy(struct ath_softc *sc, const char *name)
411{
412 struct ath_wiphy *aphy = get_wiphy(sc, name);
413 if (!aphy)
414 return -ENOENT;
415 return ath9k_wiphy_select(aphy);
416}
417
418static int schedule_wiphy(struct ath_softc *sc, const char *msec)
419{
420 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
421 return 0;
422}
423
424static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
425 size_t count, loff_t *ppos)
426{
427 struct ath_softc *sc = file->private_data;
428 char buf[50];
429 size_t len;
430
431 len = min(count, sizeof(buf) - 1);
432 if (copy_from_user(buf, user_buf, len))
433 return -EFAULT;
434 buf[len] = '\0';
435 if (len > 0 && buf[len - 1] == '\n')
436 buf[len - 1] = '\0';
437
438 if (strncmp(buf, "add", 3) == 0) {
439 int res = ath9k_wiphy_add(sc);
440 if (res < 0)
441 return res;
442 } else if (strncmp(buf, "del=", 4) == 0) {
443 int res = del_wiphy(sc, buf + 4);
444 if (res < 0)
445 return res;
446 } else if (strncmp(buf, "pause=", 6) == 0) {
447 int res = pause_wiphy(sc, buf + 6);
448 if (res < 0)
449 return res;
450 } else if (strncmp(buf, "unpause=", 8) == 0) {
451 int res = unpause_wiphy(sc, buf + 8);
452 if (res < 0)
453 return res;
454 } else if (strncmp(buf, "select=", 7) == 0) {
455 int res = select_wiphy(sc, buf + 7);
456 if (res < 0)
457 return res;
458 } else if (strncmp(buf, "schedule=", 9) == 0) {
459 int res = schedule_wiphy(sc, buf + 9);
460 if (res < 0)
461 return res;
462 } else
463 return -EOPNOTSUPP;
464
465 return count;
466}
467
468static const struct file_operations fops_wiphy = {
469 .read = read_file_wiphy,
470 .write = write_file_wiphy,
471 .open = ath9k_debugfs_open,
472 .owner = THIS_MODULE
473};
474
Sujithfec247c2009-07-27 12:08:16 +0530475#define PR(str, elem) \
476 do { \
477 len += snprintf(buf + len, size - len, \
478 "%s%13u%11u%10u%10u\n", str, \
479 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
480 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
481 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
482 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
483} while(0)
484
485static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
486 size_t count, loff_t *ppos)
487{
488 struct ath_softc *sc = file->private_data;
489 char *buf;
490 unsigned int len = 0, size = 2048;
491 ssize_t retval = 0;
492
493 buf = kzalloc(size, GFP_KERNEL);
494 if (buf == NULL)
495 return 0;
496
497 len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
498
499 PR("MPDUs Queued: ", queued);
500 PR("MPDUs Completed: ", completed);
501 PR("Aggregates: ", a_aggr);
502 PR("AMPDUs Queued: ", a_queued);
503 PR("AMPDUs Completed:", a_completed);
504 PR("AMPDUs Retried: ", a_retries);
505 PR("AMPDUs XRetried: ", a_xretries);
506 PR("FIFO Underrun: ", fifo_underrun);
507 PR("TXOP Exceeded: ", xtxop);
508 PR("TXTIMER Expiry: ", timer_exp);
509 PR("DESC CFG Error: ", desc_cfg_err);
510 PR("DATA Underrun: ", data_underrun);
511 PR("DELIM Underrun: ", delim_underrun);
512
513 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
514 kfree(buf);
515
516 return retval;
517}
518
519void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
520 struct ath_buf *bf)
521{
522 struct ath_desc *ds = bf->bf_desc;
523
524 if (bf_isampdu(bf)) {
525 if (bf_isxretried(bf))
526 TX_STAT_INC(txq->axq_qnum, a_xretries);
527 else
528 TX_STAT_INC(txq->axq_qnum, a_completed);
529 } else {
530 TX_STAT_INC(txq->axq_qnum, completed);
531 }
532
533 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO)
534 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
535 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP)
536 TX_STAT_INC(txq->axq_qnum, xtxop);
537 if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED)
538 TX_STAT_INC(txq->axq_qnum, timer_exp);
539 if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR)
540 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
541 if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN)
542 TX_STAT_INC(txq->axq_qnum, data_underrun);
543 if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN)
544 TX_STAT_INC(txq->axq_qnum, delim_underrun);
545}
546
547static const struct file_operations fops_xmit = {
548 .read = read_file_xmit,
549 .open = ath9k_debugfs_open,
550 .owner = THIS_MODULE
551};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200552
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700553int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +0530554{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400555 struct ath_common *common = ath9k_hw_common(ah);
556 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700557
Sujith7dd58742009-03-30 15:28:42 +0530558 if (!ath9k_debugfs_root)
559 return -ENOENT;
560
Sujith17d79042009-02-09 13:27:03 +0530561 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100562 ath9k_debugfs_root);
Sujith17d79042009-02-09 13:27:03 +0530563 if (!sc->debug.debugfs_phy)
Sujith826d2682008-11-28 22:20:23 +0530564 goto err;
565
Jeff Hansen24939282009-05-27 12:48:29 +0000566 sc->debug.debugfs_debug = debugfs_create_file("debug",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200567 S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
Jeff Hansen24939282009-05-27 12:48:29 +0000568 if (!sc->debug.debugfs_debug)
569 goto err;
570
Jiri Slaby9d49e862009-06-28 23:25:28 +0200571 sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530572 sc->debug.debugfs_phy, sc, &fops_dma);
573 if (!sc->debug.debugfs_dma)
Sujith2a163c62008-11-28 22:21:08 +0530574 goto err;
575
Sujith17d79042009-02-09 13:27:03 +0530576 sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200577 S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530578 sc->debug.debugfs_phy,
Sujith817e11d2008-12-07 21:42:44 +0530579 sc, &fops_interrupt);
Sujith17d79042009-02-09 13:27:03 +0530580 if (!sc->debug.debugfs_interrupt)
Sujith817e11d2008-12-07 21:42:44 +0530581 goto err;
582
Sujith17d79042009-02-09 13:27:03 +0530583 sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200584 S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530585 sc->debug.debugfs_phy,
Sujith7a7dec62009-01-30 14:32:09 +0530586 sc, &fops_rcstat);
Sujith17d79042009-02-09 13:27:03 +0530587 if (!sc->debug.debugfs_rcstat)
Sujith7a7dec62009-01-30 14:32:09 +0530588 goto err;
589
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200590 sc->debug.debugfs_wiphy = debugfs_create_file(
Jiri Slaby9d49e862009-06-28 23:25:28 +0200591 "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200592 &fops_wiphy);
593 if (!sc->debug.debugfs_wiphy)
594 goto err;
595
Sujithfec247c2009-07-27 12:08:16 +0530596 sc->debug.debugfs_xmit = debugfs_create_file("xmit",
597 S_IRUSR,
598 sc->debug.debugfs_phy,
599 sc, &fops_xmit);
600 if (!sc->debug.debugfs_xmit)
601 goto err;
602
Sujith826d2682008-11-28 22:20:23 +0530603 return 0;
604err:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700605 ath9k_exit_debug(ah);
Sujith826d2682008-11-28 22:20:23 +0530606 return -ENOMEM;
607}
608
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700609void ath9k_exit_debug(struct ath_hw *ah)
Sujith826d2682008-11-28 22:20:23 +0530610{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -0400611 struct ath_common *common = ath9k_hw_common(ah);
612 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700613
Sujithfec247c2009-07-27 12:08:16 +0530614 debugfs_remove(sc->debug.debugfs_xmit);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200615 debugfs_remove(sc->debug.debugfs_wiphy);
Sujith17d79042009-02-09 13:27:03 +0530616 debugfs_remove(sc->debug.debugfs_rcstat);
617 debugfs_remove(sc->debug.debugfs_interrupt);
618 debugfs_remove(sc->debug.debugfs_dma);
Jeff Hansen24939282009-05-27 12:48:29 +0000619 debugfs_remove(sc->debug.debugfs_debug);
Sujith17d79042009-02-09 13:27:03 +0530620 debugfs_remove(sc->debug.debugfs_phy);
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100621}
622
623int ath9k_debug_create_root(void)
624{
625 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
626 if (!ath9k_debugfs_root)
627 return -ENOENT;
628
629 return 0;
630}
631
632void ath9k_debug_remove_root(void)
633{
634 debugfs_remove(ath9k_debugfs_root);
635 ath9k_debugfs_root = NULL;
Sujith88b126a2008-11-28 22:19:02 +0530636}