2 * Copyright (c) 2008-2009 Atheros Communications Inc.
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.
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.
17 #include <asm/unaligned.h>
21 #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))
26 static struct dentry *ath9k_debugfs_root;
28 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
30 file->private_data = inode->i_private;
34 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
35 size_t count, loff_t *ppos)
37 struct ath_softc *sc = file->private_data;
38 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
42 len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask);
43 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
46 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
47 size_t count, loff_t *ppos)
49 struct ath_softc *sc = file->private_data;
50 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
55 len = min(count, sizeof(buf) - 1);
56 if (copy_from_user(buf, user_buf, len))
60 if (strict_strtoul(buf, 0, &mask))
63 common->debug_mask = mask;
67 static const struct file_operations fops_debug = {
68 .read = read_file_debug,
69 .write = write_file_debug,
70 .open = ath9k_debugfs_open,
74 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
75 size_t count, loff_t *ppos)
77 struct ath_softc *sc = file->private_data;
78 struct ath_hw *ah = sc->sc_ah;
81 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
82 int i, qcuOffset = 0, dcuOffset = 0;
83 u32 *qcuBase = &val[0], *dcuBase = &val[4];
87 REG_WRITE_D(ah, AR_MACMISC,
88 ((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)));
92 len += snprintf(buf + len, sizeof(buf) - len,
93 "Raw DMA Debug values:\n");
95 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
97 len += snprintf(buf + len, sizeof(buf) - len, "\n");
99 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
100 len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ",
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");
108 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
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);
127 len += snprintf(buf + len, sizeof(buf) - len, "\n");
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);
148 len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n",
149 REG_READ_D(ah, AR_OBS_BUS_1));
150 len += snprintf(buf + len, sizeof(buf) - len,
151 "AR_CR: 0x%x \n", REG_READ_D(ah, AR_CR));
153 ath9k_ps_restore(sc);
155 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
158 static const struct file_operations fops_dma = {
159 .read = read_file_dma,
160 .open = ath9k_debugfs_open,
165 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
168 sc->debug.stats.istats.total++;
169 if (status & ATH9K_INT_RX)
170 sc->debug.stats.istats.rxok++;
171 if (status & ATH9K_INT_RXEOL)
172 sc->debug.stats.istats.rxeol++;
173 if (status & ATH9K_INT_RXORN)
174 sc->debug.stats.istats.rxorn++;
175 if (status & ATH9K_INT_TX)
176 sc->debug.stats.istats.txok++;
177 if (status & ATH9K_INT_TXURN)
178 sc->debug.stats.istats.txurn++;
179 if (status & ATH9K_INT_MIB)
180 sc->debug.stats.istats.mib++;
181 if (status & ATH9K_INT_RXPHY)
182 sc->debug.stats.istats.rxphyerr++;
183 if (status & ATH9K_INT_RXKCM)
184 sc->debug.stats.istats.rx_keycache_miss++;
185 if (status & ATH9K_INT_SWBA)
186 sc->debug.stats.istats.swba++;
187 if (status & ATH9K_INT_BMISS)
188 sc->debug.stats.istats.bmiss++;
189 if (status & ATH9K_INT_BNR)
190 sc->debug.stats.istats.bnr++;
191 if (status & ATH9K_INT_CST)
192 sc->debug.stats.istats.cst++;
193 if (status & ATH9K_INT_GTT)
194 sc->debug.stats.istats.gtt++;
195 if (status & ATH9K_INT_TIM)
196 sc->debug.stats.istats.tim++;
197 if (status & ATH9K_INT_CABEND)
198 sc->debug.stats.istats.cabend++;
199 if (status & ATH9K_INT_DTIMSYNC)
200 sc->debug.stats.istats.dtimsync++;
201 if (status & ATH9K_INT_DTIM)
202 sc->debug.stats.istats.dtim++;
205 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
206 size_t count, loff_t *ppos)
208 struct ath_softc *sc = file->private_data;
210 unsigned int len = 0;
212 len += snprintf(buf + len, sizeof(buf) - len,
213 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
214 len += snprintf(buf + len, sizeof(buf) - len,
215 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
216 len += snprintf(buf + len, sizeof(buf) - len,
217 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
218 len += snprintf(buf + len, sizeof(buf) - len,
219 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
220 len += snprintf(buf + len, sizeof(buf) - len,
221 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
222 len += snprintf(buf + len, sizeof(buf) - len,
223 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
224 len += snprintf(buf + len, sizeof(buf) - len,
225 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
226 len += snprintf(buf + len, sizeof(buf) - len,
227 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
228 len += snprintf(buf + len, sizeof(buf) - len,
229 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
230 len += snprintf(buf + len, sizeof(buf) - len,
231 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
232 len += snprintf(buf + len, sizeof(buf) - len,
233 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
234 len += snprintf(buf + len, sizeof(buf) - len,
235 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
236 len += snprintf(buf + len, sizeof(buf) - len,
237 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
238 len += snprintf(buf + len, sizeof(buf) - len,
239 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
240 len += snprintf(buf + len, sizeof(buf) - len,
241 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
242 len += snprintf(buf + len, sizeof(buf) - len,
243 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
244 len += snprintf(buf + len, sizeof(buf) - len,
245 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
246 len += snprintf(buf + len, sizeof(buf) - len,
247 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
249 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
252 static const struct file_operations fops_interrupt = {
253 .read = read_file_interrupt,
254 .open = ath9k_debugfs_open,
258 void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb)
260 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
261 struct ieee80211_tx_rate *rates = tx_info->status.rates;
262 int final_ts_idx = 0, idx, i;
263 struct ath_rc_stats *stats;
265 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
271 idx = rates[final_ts_idx].idx;
272 stats = &sc->debug.stats.rcstats[idx];
276 void ath_debug_stat_retries(struct ath_softc *sc, int rix,
277 int xretries, int retries, u8 per)
279 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
281 stats->xretries += xretries;
282 stats->retries += retries;
286 static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
287 size_t count, loff_t *ppos)
289 struct ath_softc *sc = file->private_data;
291 unsigned int len = 0, max;
295 if (sc->cur_rate_table == NULL)
298 max = 80 + sc->cur_rate_table->rate_cnt * 64;
299 buf = kmalloc(max + 1, GFP_KERNEL);
304 len += sprintf(buf, "%5s %15s %8s %9s %3s\n\n", "Rate", "Success",
305 "Retries", "XRetries", "PER");
307 for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
308 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
309 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
311 len += snprintf(buf + len, max - len,
312 "%3u.%d: %8u %8u %8u %8u\n", ratekbps / 1000,
313 (ratekbps % 1000) / 100, stats->success,
314 stats->retries, stats->xretries,
318 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
323 static const struct file_operations fops_rcstat = {
324 .read = read_file_rcstat,
325 .open = ath9k_debugfs_open,
329 static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
332 case ATH_WIPHY_INACTIVE:
334 case ATH_WIPHY_ACTIVE:
336 case ATH_WIPHY_PAUSING:
338 case ATH_WIPHY_PAUSED:
346 static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
347 size_t count, loff_t *ppos)
349 struct ath_softc *sc = file->private_data;
351 unsigned int len = 0;
355 len += snprintf(buf + len, sizeof(buf) - len,
356 "primary: %s (%s chan=%d ht=%d)\n",
357 wiphy_name(sc->pri_wiphy->hw->wiphy),
358 ath_wiphy_state_str(sc->pri_wiphy->state),
359 sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
360 for (i = 0; i < sc->num_sec_wiphy; i++) {
361 struct ath_wiphy *aphy = sc->sec_wiphy[i];
364 len += snprintf(buf + len, sizeof(buf) - len,
365 "secondary: %s (%s chan=%d ht=%d)\n",
366 wiphy_name(aphy->hw->wiphy),
367 ath_wiphy_state_str(aphy->state),
368 aphy->chan_idx, aphy->chan_is_ht);
371 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
372 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
373 len += snprintf(buf + len, sizeof(buf) - len,
374 "addr: %pM\n", addr);
375 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
376 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
377 len += snprintf(buf + len, sizeof(buf) - len,
378 "addrmask: %pM\n", addr);
380 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
383 static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
386 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
387 return sc->pri_wiphy;
388 for (i = 0; i < sc->num_sec_wiphy; i++) {
389 struct ath_wiphy *aphy = sc->sec_wiphy[i];
390 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
396 static int del_wiphy(struct ath_softc *sc, const char *name)
398 struct ath_wiphy *aphy = get_wiphy(sc, name);
401 return ath9k_wiphy_del(aphy);
404 static int pause_wiphy(struct ath_softc *sc, const char *name)
406 struct ath_wiphy *aphy = get_wiphy(sc, name);
409 return ath9k_wiphy_pause(aphy);
412 static int unpause_wiphy(struct ath_softc *sc, const char *name)
414 struct ath_wiphy *aphy = get_wiphy(sc, name);
417 return ath9k_wiphy_unpause(aphy);
420 static int select_wiphy(struct ath_softc *sc, const char *name)
422 struct ath_wiphy *aphy = get_wiphy(sc, name);
425 return ath9k_wiphy_select(aphy);
428 static int schedule_wiphy(struct ath_softc *sc, const char *msec)
430 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
434 static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
435 size_t count, loff_t *ppos)
437 struct ath_softc *sc = file->private_data;
441 len = min(count, sizeof(buf) - 1);
442 if (copy_from_user(buf, user_buf, len))
445 if (len > 0 && buf[len - 1] == '\n')
448 if (strncmp(buf, "add", 3) == 0) {
449 int res = ath9k_wiphy_add(sc);
452 } else if (strncmp(buf, "del=", 4) == 0) {
453 int res = del_wiphy(sc, buf + 4);
456 } else if (strncmp(buf, "pause=", 6) == 0) {
457 int res = pause_wiphy(sc, buf + 6);
460 } else if (strncmp(buf, "unpause=", 8) == 0) {
461 int res = unpause_wiphy(sc, buf + 8);
464 } else if (strncmp(buf, "select=", 7) == 0) {
465 int res = select_wiphy(sc, buf + 7);
468 } else if (strncmp(buf, "schedule=", 9) == 0) {
469 int res = schedule_wiphy(sc, buf + 9);
478 static const struct file_operations fops_wiphy = {
479 .read = read_file_wiphy,
480 .write = write_file_wiphy,
481 .open = ath9k_debugfs_open,
485 #define PR(str, elem) \
487 len += snprintf(buf + len, size - len, \
488 "%s%13u%11u%10u%10u\n", str, \
489 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
490 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
491 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
492 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
495 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
496 size_t count, loff_t *ppos)
498 struct ath_softc *sc = file->private_data;
500 unsigned int len = 0, size = 2048;
503 buf = kzalloc(size, GFP_KERNEL);
507 len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
509 PR("MPDUs Queued: ", queued);
510 PR("MPDUs Completed: ", completed);
511 PR("Aggregates: ", a_aggr);
512 PR("AMPDUs Queued: ", a_queued);
513 PR("AMPDUs Completed:", a_completed);
514 PR("AMPDUs Retried: ", a_retries);
515 PR("AMPDUs XRetried: ", a_xretries);
516 PR("FIFO Underrun: ", fifo_underrun);
517 PR("TXOP Exceeded: ", xtxop);
518 PR("TXTIMER Expiry: ", timer_exp);
519 PR("DESC CFG Error: ", desc_cfg_err);
520 PR("DATA Underrun: ", data_underrun);
521 PR("DELIM Underrun: ", delim_underrun);
523 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
529 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
532 struct ath_desc *ds = bf->bf_desc;
534 if (bf_isampdu(bf)) {
535 if (bf_isxretried(bf))
536 TX_STAT_INC(txq->axq_qnum, a_xretries);
538 TX_STAT_INC(txq->axq_qnum, a_completed);
540 TX_STAT_INC(txq->axq_qnum, completed);
543 if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO)
544 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
545 if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP)
546 TX_STAT_INC(txq->axq_qnum, xtxop);
547 if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED)
548 TX_STAT_INC(txq->axq_qnum, timer_exp);
549 if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR)
550 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
551 if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN)
552 TX_STAT_INC(txq->axq_qnum, data_underrun);
553 if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN)
554 TX_STAT_INC(txq->axq_qnum, delim_underrun);
557 static const struct file_operations fops_xmit = {
558 .read = read_file_xmit,
559 .open = ath9k_debugfs_open,
563 int ath9k_init_debug(struct ath_hw *ah)
565 struct ath_common *common = ath9k_hw_common(ah);
566 struct ath_softc *sc = (struct ath_softc *) common->priv;
568 if (!ath9k_debugfs_root)
571 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
573 if (!sc->debug.debugfs_phy)
576 sc->debug.debugfs_debug = debugfs_create_file("debug",
577 S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
578 if (!sc->debug.debugfs_debug)
581 sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
582 sc->debug.debugfs_phy, sc, &fops_dma);
583 if (!sc->debug.debugfs_dma)
586 sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
588 sc->debug.debugfs_phy,
589 sc, &fops_interrupt);
590 if (!sc->debug.debugfs_interrupt)
593 sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
595 sc->debug.debugfs_phy,
597 if (!sc->debug.debugfs_rcstat)
600 sc->debug.debugfs_wiphy = debugfs_create_file(
601 "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
603 if (!sc->debug.debugfs_wiphy)
606 sc->debug.debugfs_xmit = debugfs_create_file("xmit",
608 sc->debug.debugfs_phy,
610 if (!sc->debug.debugfs_xmit)
615 ath9k_exit_debug(ah);
619 void ath9k_exit_debug(struct ath_hw *ah)
621 struct ath_common *common = ath9k_hw_common(ah);
622 struct ath_softc *sc = (struct ath_softc *) common->priv;
624 debugfs_remove(sc->debug.debugfs_xmit);
625 debugfs_remove(sc->debug.debugfs_wiphy);
626 debugfs_remove(sc->debug.debugfs_rcstat);
627 debugfs_remove(sc->debug.debugfs_interrupt);
628 debugfs_remove(sc->debug.debugfs_dma);
629 debugfs_remove(sc->debug.debugfs_debug);
630 debugfs_remove(sc->debug.debugfs_phy);
633 int ath9k_debug_create_root(void)
635 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
636 if (!ath9k_debugfs_root)
642 void ath9k_debug_remove_root(void)
644 debugfs_remove(ath9k_debugfs_root);
645 ath9k_debugfs_root = NULL;