blob: 5dfc0e97d96d9f9967b5996df8fdb43f8087c926 [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. Rodriguezc46917b2009-09-13 02:42:02 -070021static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
Sujith88b126a2008-11-28 22:19:02 +053022module_param_named(debug, ath9k_debug, uint, 0);
23
Gabor Juhos19d8bc22009-03-05 16:55:18 +010024static struct dentry *ath9k_debugfs_root;
25
Sujith2a163c62008-11-28 22:21:08 +053026static int ath9k_debugfs_open(struct inode *inode, struct file *file)
27{
28 file->private_data = inode->i_private;
29 return 0;
30}
31
Jeff Hansen24939282009-05-27 12:48:29 +000032static ssize_t read_file_debug(struct file *file, char __user *user_buf,
33 size_t count, loff_t *ppos)
34{
35 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070036 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000037 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053038 unsigned int len;
39
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070040 len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask);
Jeff Hansen24939282009-05-27 12:48:29 +000041 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
42}
43
44static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
45 size_t count, loff_t *ppos)
46{
47 struct ath_softc *sc = file->private_data;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070048 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Jeff Hansen24939282009-05-27 12:48:29 +000049 unsigned long mask;
50 char buf[32];
Vasanthakumar Thiagarajan581f7252009-06-02 19:28:55 +053051 ssize_t len;
52
53 len = min(count, sizeof(buf) - 1);
54 if (copy_from_user(buf, user_buf, len))
55 return -EINVAL;
56
57 buf[len] = '\0';
58 if (strict_strtoul(buf, 0, &mask))
59 return -EINVAL;
60
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070061 common->debug_mask = mask;
Jeff Hansen24939282009-05-27 12:48:29 +000062 return count;
63}
64
65static const struct file_operations fops_debug = {
66 .read = read_file_debug,
67 .write = write_file_debug,
68 .open = ath9k_debugfs_open,
69 .owner = THIS_MODULE
70};
71
Sujith2a163c62008-11-28 22:21:08 +053072static ssize_t read_file_dma(struct file *file, char __user *user_buf,
73 size_t count, loff_t *ppos)
74{
75 struct ath_softc *sc = file->private_data;
Sujithcbe61d82009-02-09 13:27:12 +053076 struct ath_hw *ah = sc->sc_ah;
Sujith2a163c62008-11-28 22:21:08 +053077 char buf[1024];
78 unsigned int len = 0;
79 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
80 int i, qcuOffset = 0, dcuOffset = 0;
81 u32 *qcuBase = &val[0], *dcuBase = &val[4];
82
Sujith7cf4a2e2009-08-26 11:11:57 +053083 ath9k_ps_wakeup(sc);
84
Sujith2a163c62008-11-28 22:21:08 +053085 REG_WRITE(ah, AR_MACMISC,
86 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
87 (AR_MACMISC_MISC_OBS_BUS_1 <<
88 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
89
90 len += snprintf(buf + len, sizeof(buf) - len,
91 "Raw DMA Debug values:\n");
92
93 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
94 if (i % 4 == 0)
95 len += snprintf(buf + len, sizeof(buf) - len, "\n");
96
97 val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32)));
98 len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ",
99 i, val[i]);
100 }
101
102 len += snprintf(buf + len, sizeof(buf) - len, "\n\n");
103 len += snprintf(buf + len, sizeof(buf) - len,
104 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
105
106 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
107 if (i == 8) {
108 qcuOffset = 0;
109 qcuBase++;
110 }
111
112 if (i == 6) {
113 dcuOffset = 0;
114 dcuBase++;
115 }
116
117 len += snprintf(buf + len, sizeof(buf) - len,
118 "%2d %2x %1x %2x %2x\n",
119 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
120 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
121 val[2] & (0x7 << (i * 3)) >> (i * 3),
122 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
123 }
124
125 len += snprintf(buf + len, sizeof(buf) - len, "\n");
126
127 len += snprintf(buf + len, sizeof(buf) - len,
128 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
129 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
130 len += snprintf(buf + len, sizeof(buf) - len,
131 "qcu_complete state: %2x dcu_complete state: %2x\n",
132 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
133 len += snprintf(buf + len, sizeof(buf) - len,
134 "dcu_arb state: %2x dcu_fp state: %2x\n",
135 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
136 len += snprintf(buf + len, sizeof(buf) - len,
137 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
138 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
139 len += snprintf(buf + len, sizeof(buf) - len,
140 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
141 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
142 len += snprintf(buf + len, sizeof(buf) - len,
143 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
144 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
145
146 len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n",
147 REG_READ(ah, AR_OBS_BUS_1));
148 len += snprintf(buf + len, sizeof(buf) - len,
149 "AR_CR: 0x%x \n", REG_READ(ah, AR_CR));
150
Sujith7cf4a2e2009-08-26 11:11:57 +0530151 ath9k_ps_restore(sc);
152
Sujith2a163c62008-11-28 22:21:08 +0530153 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
154}
155
156static const struct file_operations fops_dma = {
157 .read = read_file_dma,
158 .open = ath9k_debugfs_open,
159 .owner = THIS_MODULE
160};
161
Sujith817e11d2008-12-07 21:42:44 +0530162
163void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
164{
165 if (status)
Sujith17d79042009-02-09 13:27:03 +0530166 sc->debug.stats.istats.total++;
Sujith817e11d2008-12-07 21:42:44 +0530167 if (status & ATH9K_INT_RX)
Sujith17d79042009-02-09 13:27:03 +0530168 sc->debug.stats.istats.rxok++;
Sujith817e11d2008-12-07 21:42:44 +0530169 if (status & ATH9K_INT_RXEOL)
Sujith17d79042009-02-09 13:27:03 +0530170 sc->debug.stats.istats.rxeol++;
Sujith817e11d2008-12-07 21:42:44 +0530171 if (status & ATH9K_INT_RXORN)
Sujith17d79042009-02-09 13:27:03 +0530172 sc->debug.stats.istats.rxorn++;
Sujith817e11d2008-12-07 21:42:44 +0530173 if (status & ATH9K_INT_TX)
Sujith17d79042009-02-09 13:27:03 +0530174 sc->debug.stats.istats.txok++;
Sujith817e11d2008-12-07 21:42:44 +0530175 if (status & ATH9K_INT_TXURN)
Sujith17d79042009-02-09 13:27:03 +0530176 sc->debug.stats.istats.txurn++;
Sujith817e11d2008-12-07 21:42:44 +0530177 if (status & ATH9K_INT_MIB)
Sujith17d79042009-02-09 13:27:03 +0530178 sc->debug.stats.istats.mib++;
Sujith817e11d2008-12-07 21:42:44 +0530179 if (status & ATH9K_INT_RXPHY)
Sujith17d79042009-02-09 13:27:03 +0530180 sc->debug.stats.istats.rxphyerr++;
Sujith817e11d2008-12-07 21:42:44 +0530181 if (status & ATH9K_INT_RXKCM)
Sujith17d79042009-02-09 13:27:03 +0530182 sc->debug.stats.istats.rx_keycache_miss++;
Sujith817e11d2008-12-07 21:42:44 +0530183 if (status & ATH9K_INT_SWBA)
Sujith17d79042009-02-09 13:27:03 +0530184 sc->debug.stats.istats.swba++;
Sujith817e11d2008-12-07 21:42:44 +0530185 if (status & ATH9K_INT_BMISS)
Sujith17d79042009-02-09 13:27:03 +0530186 sc->debug.stats.istats.bmiss++;
Sujith817e11d2008-12-07 21:42:44 +0530187 if (status & ATH9K_INT_BNR)
Sujith17d79042009-02-09 13:27:03 +0530188 sc->debug.stats.istats.bnr++;
Sujith817e11d2008-12-07 21:42:44 +0530189 if (status & ATH9K_INT_CST)
Sujith17d79042009-02-09 13:27:03 +0530190 sc->debug.stats.istats.cst++;
Sujith817e11d2008-12-07 21:42:44 +0530191 if (status & ATH9K_INT_GTT)
Sujith17d79042009-02-09 13:27:03 +0530192 sc->debug.stats.istats.gtt++;
Sujith817e11d2008-12-07 21:42:44 +0530193 if (status & ATH9K_INT_TIM)
Sujith17d79042009-02-09 13:27:03 +0530194 sc->debug.stats.istats.tim++;
Sujith817e11d2008-12-07 21:42:44 +0530195 if (status & ATH9K_INT_CABEND)
Sujith17d79042009-02-09 13:27:03 +0530196 sc->debug.stats.istats.cabend++;
Sujith817e11d2008-12-07 21:42:44 +0530197 if (status & ATH9K_INT_DTIMSYNC)
Sujith17d79042009-02-09 13:27:03 +0530198 sc->debug.stats.istats.dtimsync++;
Sujith817e11d2008-12-07 21:42:44 +0530199 if (status & ATH9K_INT_DTIM)
Sujith17d79042009-02-09 13:27:03 +0530200 sc->debug.stats.istats.dtim++;
Sujith817e11d2008-12-07 21:42:44 +0530201}
202
203static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
204 size_t count, loff_t *ppos)
205{
206 struct ath_softc *sc = file->private_data;
207 char buf[512];
208 unsigned int len = 0;
209
210 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530211 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
Sujith817e11d2008-12-07 21:42:44 +0530212 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530213 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
Sujith817e11d2008-12-07 21:42:44 +0530214 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530215 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
Sujith817e11d2008-12-07 21:42:44 +0530216 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530217 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
Sujith817e11d2008-12-07 21:42:44 +0530218 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530219 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
Sujith817e11d2008-12-07 21:42:44 +0530220 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530221 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
Sujith817e11d2008-12-07 21:42:44 +0530222 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530223 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
Sujith817e11d2008-12-07 21:42:44 +0530224 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530225 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
Sujith817e11d2008-12-07 21:42:44 +0530226 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530227 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
Sujith817e11d2008-12-07 21:42:44 +0530228 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530229 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
Sujith817e11d2008-12-07 21:42:44 +0530230 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530231 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
Sujith817e11d2008-12-07 21:42:44 +0530232 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530233 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
Sujith817e11d2008-12-07 21:42:44 +0530234 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530235 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
Sujith817e11d2008-12-07 21:42:44 +0530236 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530237 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
Sujith817e11d2008-12-07 21:42:44 +0530238 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530239 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
Sujith817e11d2008-12-07 21:42:44 +0530240 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530241 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
Sujith817e11d2008-12-07 21:42:44 +0530242 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530243 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
Sujith817e11d2008-12-07 21:42:44 +0530244 len += snprintf(buf + len, sizeof(buf) - len,
Sujith17d79042009-02-09 13:27:03 +0530245 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
Sujith817e11d2008-12-07 21:42:44 +0530246
247 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
248}
249
250static const struct file_operations fops_interrupt = {
251 .read = read_file_interrupt,
252 .open = ath9k_debugfs_open,
253 .owner = THIS_MODULE
254};
255
Jeff Hansenbedf0872009-05-27 12:48:28 +0000256void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb)
Sujith7a7dec62009-01-30 14:32:09 +0530257{
258 struct ath_tx_info_priv *tx_info_priv = NULL;
259 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
260 struct ieee80211_tx_rate *rates = tx_info->status.rates;
261 int final_ts_idx, idx;
Jeff Hansenbedf0872009-05-27 12:48:28 +0000262 struct ath_rc_stats *stats;
Sujith7a7dec62009-01-30 14:32:09 +0530263
264 tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
265 final_ts_idx = tx_info_priv->tx.ts_rateindex;
266 idx = rates[final_ts_idx].idx;
Jeff Hansenbedf0872009-05-27 12:48:28 +0000267 stats = &sc->debug.stats.rcstats[idx];
268 stats->success++;
Sujith7a7dec62009-01-30 14:32:09 +0530269}
270
Sujith029bc432009-02-04 08:10:26 +0530271void ath_debug_stat_retries(struct ath_softc *sc, int rix,
Sujith9e712792009-02-20 15:13:20 +0530272 int xretries, int retries, u8 per)
Sujith029bc432009-02-04 08:10:26 +0530273{
Jeff Hansenbedf0872009-05-27 12:48:28 +0000274 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
Sujith029bc432009-02-04 08:10:26 +0530275
Jeff Hansenbedf0872009-05-27 12:48:28 +0000276 stats->xretries += xretries;
277 stats->retries += retries;
278 stats->per = per;
Sujith7a7dec62009-01-30 14:32:09 +0530279}
280
281static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
282 size_t count, loff_t *ppos)
283{
284 struct ath_softc *sc = file->private_data;
Jeff Hansenbedf0872009-05-27 12:48:28 +0000285 char *buf;
286 unsigned int len = 0, max;
287 int i = 0;
288 ssize_t retval;
Sujith7a7dec62009-01-30 14:32:09 +0530289
Sujith62b4fb62009-03-09 09:32:01 +0530290 if (sc->cur_rate_table == NULL)
291 return 0;
292
Jeff Hansenbedf0872009-05-27 12:48:28 +0000293 max = 80 + sc->cur_rate_table->rate_cnt * 64;
294 buf = kmalloc(max + 1, GFP_KERNEL);
295 if (buf == NULL)
296 return 0;
297 buf[max] = 0;
298
299 len += sprintf(buf, "%5s %15s %8s %9s %3s\n\n", "Rate", "Success",
300 "Retries", "XRetries", "PER");
301
302 for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
303 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
304 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
305
306 len += snprintf(buf + len, max - len,
307 "%3u.%d: %8u %8u %8u %8u\n", ratekbps / 1000,
308 (ratekbps % 1000) / 100, stats->success,
309 stats->retries, stats->xretries,
310 stats->per);
311 }
312
313 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
314 kfree(buf);
315 return retval;
Sujith7a7dec62009-01-30 14:32:09 +0530316}
317
318static const struct file_operations fops_rcstat = {
319 .read = read_file_rcstat,
320 .open = ath9k_debugfs_open,
321 .owner = THIS_MODULE
322};
Alina Friedrichsen27abe062009-01-23 05:44:21 +0100323
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200324static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
325{
326 switch (state) {
327 case ATH_WIPHY_INACTIVE:
328 return "INACTIVE";
329 case ATH_WIPHY_ACTIVE:
330 return "ACTIVE";
331 case ATH_WIPHY_PAUSING:
332 return "PAUSING";
333 case ATH_WIPHY_PAUSED:
334 return "PAUSED";
335 case ATH_WIPHY_SCAN:
336 return "SCAN";
337 }
338 return "?";
339}
340
341static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
342 size_t count, loff_t *ppos)
343{
344 struct ath_softc *sc = file->private_data;
345 char buf[512];
346 unsigned int len = 0;
347 int i;
348 u8 addr[ETH_ALEN];
349
350 len += snprintf(buf + len, sizeof(buf) - len,
351 "primary: %s (%s chan=%d ht=%d)\n",
352 wiphy_name(sc->pri_wiphy->hw->wiphy),
353 ath_wiphy_state_str(sc->pri_wiphy->state),
354 sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
355 for (i = 0; i < sc->num_sec_wiphy; i++) {
356 struct ath_wiphy *aphy = sc->sec_wiphy[i];
357 if (aphy == NULL)
358 continue;
359 len += snprintf(buf + len, sizeof(buf) - len,
360 "secondary: %s (%s chan=%d ht=%d)\n",
361 wiphy_name(aphy->hw->wiphy),
362 ath_wiphy_state_str(aphy->state),
363 aphy->chan_idx, aphy->chan_is_ht);
364 }
365
366 put_unaligned_le32(REG_READ(sc->sc_ah, AR_STA_ID0), addr);
367 put_unaligned_le16(REG_READ(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
368 len += snprintf(buf + len, sizeof(buf) - len,
369 "addr: %pM\n", addr);
370 put_unaligned_le32(REG_READ(sc->sc_ah, AR_BSSMSKL), addr);
371 put_unaligned_le16(REG_READ(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
372 len += snprintf(buf + len, sizeof(buf) - len,
373 "addrmask: %pM\n", addr);
374
375 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
376}
377
378static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
379{
380 int i;
381 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
382 return sc->pri_wiphy;
383 for (i = 0; i < sc->num_sec_wiphy; i++) {
384 struct ath_wiphy *aphy = sc->sec_wiphy[i];
385 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
386 return aphy;
387 }
388 return NULL;
389}
390
391static int del_wiphy(struct ath_softc *sc, const char *name)
392{
393 struct ath_wiphy *aphy = get_wiphy(sc, name);
394 if (!aphy)
395 return -ENOENT;
396 return ath9k_wiphy_del(aphy);
397}
398
399static int pause_wiphy(struct ath_softc *sc, const char *name)
400{
401 struct ath_wiphy *aphy = get_wiphy(sc, name);
402 if (!aphy)
403 return -ENOENT;
404 return ath9k_wiphy_pause(aphy);
405}
406
407static int unpause_wiphy(struct ath_softc *sc, const char *name)
408{
409 struct ath_wiphy *aphy = get_wiphy(sc, name);
410 if (!aphy)
411 return -ENOENT;
412 return ath9k_wiphy_unpause(aphy);
413}
414
415static int select_wiphy(struct ath_softc *sc, const char *name)
416{
417 struct ath_wiphy *aphy = get_wiphy(sc, name);
418 if (!aphy)
419 return -ENOENT;
420 return ath9k_wiphy_select(aphy);
421}
422
423static int schedule_wiphy(struct ath_softc *sc, const char *msec)
424{
425 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
426 return 0;
427}
428
429static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
430 size_t count, loff_t *ppos)
431{
432 struct ath_softc *sc = file->private_data;
433 char buf[50];
434 size_t len;
435
436 len = min(count, sizeof(buf) - 1);
437 if (copy_from_user(buf, user_buf, len))
438 return -EFAULT;
439 buf[len] = '\0';
440 if (len > 0 && buf[len - 1] == '\n')
441 buf[len - 1] = '\0';
442
443 if (strncmp(buf, "add", 3) == 0) {
444 int res = ath9k_wiphy_add(sc);
445 if (res < 0)
446 return res;
447 } else if (strncmp(buf, "del=", 4) == 0) {
448 int res = del_wiphy(sc, buf + 4);
449 if (res < 0)
450 return res;
451 } else if (strncmp(buf, "pause=", 6) == 0) {
452 int res = pause_wiphy(sc, buf + 6);
453 if (res < 0)
454 return res;
455 } else if (strncmp(buf, "unpause=", 8) == 0) {
456 int res = unpause_wiphy(sc, buf + 8);
457 if (res < 0)
458 return res;
459 } else if (strncmp(buf, "select=", 7) == 0) {
460 int res = select_wiphy(sc, buf + 7);
461 if (res < 0)
462 return res;
463 } else if (strncmp(buf, "schedule=", 9) == 0) {
464 int res = schedule_wiphy(sc, buf + 9);
465 if (res < 0)
466 return res;
467 } else
468 return -EOPNOTSUPP;
469
470 return count;
471}
472
473static const struct file_operations fops_wiphy = {
474 .read = read_file_wiphy,
475 .write = write_file_wiphy,
476 .open = ath9k_debugfs_open,
477 .owner = THIS_MODULE
478};
479
Sujithfec247c2009-07-27 12:08:16 +0530480#define PR(str, elem) \
481 do { \
482 len += snprintf(buf + len, size - len, \
483 "%s%13u%11u%10u%10u\n", str, \
484 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
485 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
486 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
487 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
488} while(0)
489
490static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
491 size_t count, loff_t *ppos)
492{
493 struct ath_softc *sc = file->private_data;
494 char *buf;
495 unsigned int len = 0, size = 2048;
496 ssize_t retval = 0;
497
498 buf = kzalloc(size, GFP_KERNEL);
499 if (buf == NULL)
500 return 0;
501
502 len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
503
504 PR("MPDUs Queued: ", queued);
505 PR("MPDUs Completed: ", completed);
506 PR("Aggregates: ", a_aggr);
507 PR("AMPDUs Queued: ", a_queued);
508 PR("AMPDUs Completed:", a_completed);
509 PR("AMPDUs Retried: ", a_retries);
510 PR("AMPDUs XRetried: ", a_xretries);
511 PR("FIFO Underrun: ", fifo_underrun);
512 PR("TXOP Exceeded: ", xtxop);
513 PR("TXTIMER Expiry: ", timer_exp);
514 PR("DESC CFG Error: ", desc_cfg_err);
515 PR("DATA Underrun: ", data_underrun);
516 PR("DELIM Underrun: ", delim_underrun);
517
518 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
519 kfree(buf);
520
521 return retval;
522}
523
524void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
525 struct ath_buf *bf)
526{
527 struct ath_desc *ds = bf->bf_desc;
528
529 if (bf_isampdu(bf)) {
530 if (bf_isxretried(bf))
531 TX_STAT_INC(txq->axq_qnum, a_xretries);
532 else
533 TX_STAT_INC(txq->axq_qnum, a_completed);
534 } else {
535 TX_STAT_INC(txq->axq_qnum, completed);
536 }
537
538 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO)
539 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
540 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP)
541 TX_STAT_INC(txq->axq_qnum, xtxop);
542 if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED)
543 TX_STAT_INC(txq->axq_qnum, timer_exp);
544 if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR)
545 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
546 if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN)
547 TX_STAT_INC(txq->axq_qnum, data_underrun);
548 if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN)
549 TX_STAT_INC(txq->axq_qnum, delim_underrun);
550}
551
552static const struct file_operations fops_xmit = {
553 .read = read_file_xmit,
554 .open = ath9k_debugfs_open,
555 .owner = THIS_MODULE
556};
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200557
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700558int ath9k_init_debug(struct ath_hw *ah)
Sujith88b126a2008-11-28 22:19:02 +0530559{
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700560 struct ath_softc *sc = ah->ah_sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700561 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700562
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700563 common->debug_mask = ath9k_debug;
Sujith826d2682008-11-28 22:20:23 +0530564
Sujith7dd58742009-03-30 15:28:42 +0530565 if (!ath9k_debugfs_root)
566 return -ENOENT;
567
Sujith17d79042009-02-09 13:27:03 +0530568 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100569 ath9k_debugfs_root);
Sujith17d79042009-02-09 13:27:03 +0530570 if (!sc->debug.debugfs_phy)
Sujith826d2682008-11-28 22:20:23 +0530571 goto err;
572
Jeff Hansen24939282009-05-27 12:48:29 +0000573 sc->debug.debugfs_debug = debugfs_create_file("debug",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200574 S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
Jeff Hansen24939282009-05-27 12:48:29 +0000575 if (!sc->debug.debugfs_debug)
576 goto err;
577
Jiri Slaby9d49e862009-06-28 23:25:28 +0200578 sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530579 sc->debug.debugfs_phy, sc, &fops_dma);
580 if (!sc->debug.debugfs_dma)
Sujith2a163c62008-11-28 22:21:08 +0530581 goto err;
582
Sujith17d79042009-02-09 13:27:03 +0530583 sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200584 S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530585 sc->debug.debugfs_phy,
Sujith817e11d2008-12-07 21:42:44 +0530586 sc, &fops_interrupt);
Sujith17d79042009-02-09 13:27:03 +0530587 if (!sc->debug.debugfs_interrupt)
Sujith817e11d2008-12-07 21:42:44 +0530588 goto err;
589
Sujith17d79042009-02-09 13:27:03 +0530590 sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
Jiri Slaby9d49e862009-06-28 23:25:28 +0200591 S_IRUSR,
Sujith17d79042009-02-09 13:27:03 +0530592 sc->debug.debugfs_phy,
Sujith7a7dec62009-01-30 14:32:09 +0530593 sc, &fops_rcstat);
Sujith17d79042009-02-09 13:27:03 +0530594 if (!sc->debug.debugfs_rcstat)
Sujith7a7dec62009-01-30 14:32:09 +0530595 goto err;
596
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200597 sc->debug.debugfs_wiphy = debugfs_create_file(
Jiri Slaby9d49e862009-06-28 23:25:28 +0200598 "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200599 &fops_wiphy);
600 if (!sc->debug.debugfs_wiphy)
601 goto err;
602
Sujithfec247c2009-07-27 12:08:16 +0530603 sc->debug.debugfs_xmit = debugfs_create_file("xmit",
604 S_IRUSR,
605 sc->debug.debugfs_phy,
606 sc, &fops_xmit);
607 if (!sc->debug.debugfs_xmit)
608 goto err;
609
Sujith826d2682008-11-28 22:20:23 +0530610 return 0;
611err:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700612 ath9k_exit_debug(ah);
Sujith826d2682008-11-28 22:20:23 +0530613 return -ENOMEM;
614}
615
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700616void ath9k_exit_debug(struct ath_hw *ah)
Sujith826d2682008-11-28 22:20:23 +0530617{
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700618 struct ath_softc *sc = ah->ah_sc;
619
Sujithfec247c2009-07-27 12:08:16 +0530620 debugfs_remove(sc->debug.debugfs_xmit);
Jouni Malinen39d89cd2009-03-03 19:23:40 +0200621 debugfs_remove(sc->debug.debugfs_wiphy);
Sujith17d79042009-02-09 13:27:03 +0530622 debugfs_remove(sc->debug.debugfs_rcstat);
623 debugfs_remove(sc->debug.debugfs_interrupt);
624 debugfs_remove(sc->debug.debugfs_dma);
Jeff Hansen24939282009-05-27 12:48:29 +0000625 debugfs_remove(sc->debug.debugfs_debug);
Sujith17d79042009-02-09 13:27:03 +0530626 debugfs_remove(sc->debug.debugfs_phy);
Gabor Juhos19d8bc22009-03-05 16:55:18 +0100627}
628
629int ath9k_debug_create_root(void)
630{
631 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
632 if (!ath9k_debugfs_root)
633 return -ENOENT;
634
635 return 0;
636}
637
638void ath9k_debug_remove_root(void)
639{
640 debugfs_remove(ath9k_debugfs_root);
641 ath9k_debugfs_root = NULL;
Sujith88b126a2008-11-28 22:19:02 +0530642}