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 <linux/slab.h>
18 #include <asm/unaligned.h>
22 #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))
27 static struct dentry *ath9k_debugfs_root;
29 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
31 file->private_data = inode->i_private;
35 #ifdef CONFIG_ATH_DEBUG
37 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
38 size_t count, loff_t *ppos)
40 struct ath_softc *sc = file->private_data;
41 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
45 len = sprintf(buf, "0x%08x\n", common->debug_mask);
46 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
49 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
50 size_t count, loff_t *ppos)
52 struct ath_softc *sc = file->private_data;
53 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
58 len = min(count, sizeof(buf) - 1);
59 if (copy_from_user(buf, user_buf, len))
63 if (strict_strtoul(buf, 0, &mask))
66 common->debug_mask = mask;
70 static const struct file_operations fops_debug = {
71 .read = read_file_debug,
72 .write = write_file_debug,
73 .open = ath9k_debugfs_open,
79 #define DMA_BUF_LEN 1024
81 static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf,
82 size_t count, loff_t *ppos)
84 struct ath_softc *sc = file->private_data;
85 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
89 len = sprintf(buf, "0x%08x\n", common->tx_chainmask);
90 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
93 static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf,
94 size_t count, loff_t *ppos)
96 struct ath_softc *sc = file->private_data;
97 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
102 len = min(count, sizeof(buf) - 1);
103 if (copy_from_user(buf, user_buf, len))
107 if (strict_strtoul(buf, 0, &mask))
110 common->tx_chainmask = mask;
111 sc->sc_ah->caps.tx_chainmask = mask;
115 static const struct file_operations fops_tx_chainmask = {
116 .read = read_file_tx_chainmask,
117 .write = write_file_tx_chainmask,
118 .open = ath9k_debugfs_open,
123 static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf,
124 size_t count, loff_t *ppos)
126 struct ath_softc *sc = file->private_data;
127 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
131 len = sprintf(buf, "0x%08x\n", common->rx_chainmask);
132 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
135 static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf,
136 size_t count, loff_t *ppos)
138 struct ath_softc *sc = file->private_data;
139 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
144 len = min(count, sizeof(buf) - 1);
145 if (copy_from_user(buf, user_buf, len))
149 if (strict_strtoul(buf, 0, &mask))
152 common->rx_chainmask = mask;
153 sc->sc_ah->caps.rx_chainmask = mask;
157 static const struct file_operations fops_rx_chainmask = {
158 .read = read_file_rx_chainmask,
159 .write = write_file_rx_chainmask,
160 .open = ath9k_debugfs_open,
165 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
166 size_t count, loff_t *ppos)
168 struct ath_softc *sc = file->private_data;
169 struct ath_hw *ah = sc->sc_ah;
172 unsigned int len = 0;
173 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
174 int i, qcuOffset = 0, dcuOffset = 0;
175 u32 *qcuBase = &val[0], *dcuBase = &val[4];
177 buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
183 REG_WRITE_D(ah, AR_MACMISC,
184 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
185 (AR_MACMISC_MISC_OBS_BUS_1 <<
186 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
188 len += snprintf(buf + len, DMA_BUF_LEN - len,
189 "Raw DMA Debug values:\n");
191 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
193 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
195 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
196 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
200 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
201 len += snprintf(buf + len, DMA_BUF_LEN - len,
202 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
204 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
215 len += snprintf(buf + len, DMA_BUF_LEN - len,
216 "%2d %2x %1x %2x %2x\n",
217 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
218 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
219 val[2] & (0x7 << (i * 3)) >> (i * 3),
220 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
223 len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
225 len += snprintf(buf + len, DMA_BUF_LEN - len,
226 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
227 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
228 len += snprintf(buf + len, DMA_BUF_LEN - len,
229 "qcu_complete state: %2x dcu_complete state: %2x\n",
230 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
231 len += snprintf(buf + len, DMA_BUF_LEN - len,
232 "dcu_arb state: %2x dcu_fp state: %2x\n",
233 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
234 len += snprintf(buf + len, DMA_BUF_LEN - len,
235 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
236 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
237 len += snprintf(buf + len, DMA_BUF_LEN - len,
238 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
239 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
240 len += snprintf(buf + len, DMA_BUF_LEN - len,
241 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
242 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
244 len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
245 REG_READ_D(ah, AR_OBS_BUS_1));
246 len += snprintf(buf + len, DMA_BUF_LEN - len,
247 "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
249 ath9k_ps_restore(sc);
251 if (len > DMA_BUF_LEN)
254 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
259 static const struct file_operations fops_dma = {
260 .read = read_file_dma,
261 .open = ath9k_debugfs_open,
266 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
269 sc->debug.stats.istats.total++;
270 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
271 if (status & ATH9K_INT_RXLP)
272 sc->debug.stats.istats.rxlp++;
273 if (status & ATH9K_INT_RXHP)
274 sc->debug.stats.istats.rxhp++;
275 if (status & ATH9K_INT_BB_WATCHDOG)
276 sc->debug.stats.istats.bb_watchdog++;
278 if (status & ATH9K_INT_RX)
279 sc->debug.stats.istats.rxok++;
281 if (status & ATH9K_INT_RXEOL)
282 sc->debug.stats.istats.rxeol++;
283 if (status & ATH9K_INT_RXORN)
284 sc->debug.stats.istats.rxorn++;
285 if (status & ATH9K_INT_TX)
286 sc->debug.stats.istats.txok++;
287 if (status & ATH9K_INT_TXURN)
288 sc->debug.stats.istats.txurn++;
289 if (status & ATH9K_INT_MIB)
290 sc->debug.stats.istats.mib++;
291 if (status & ATH9K_INT_RXPHY)
292 sc->debug.stats.istats.rxphyerr++;
293 if (status & ATH9K_INT_RXKCM)
294 sc->debug.stats.istats.rx_keycache_miss++;
295 if (status & ATH9K_INT_SWBA)
296 sc->debug.stats.istats.swba++;
297 if (status & ATH9K_INT_BMISS)
298 sc->debug.stats.istats.bmiss++;
299 if (status & ATH9K_INT_BNR)
300 sc->debug.stats.istats.bnr++;
301 if (status & ATH9K_INT_CST)
302 sc->debug.stats.istats.cst++;
303 if (status & ATH9K_INT_GTT)
304 sc->debug.stats.istats.gtt++;
305 if (status & ATH9K_INT_TIM)
306 sc->debug.stats.istats.tim++;
307 if (status & ATH9K_INT_CABEND)
308 sc->debug.stats.istats.cabend++;
309 if (status & ATH9K_INT_DTIMSYNC)
310 sc->debug.stats.istats.dtimsync++;
311 if (status & ATH9K_INT_DTIM)
312 sc->debug.stats.istats.dtim++;
315 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
316 size_t count, loff_t *ppos)
318 struct ath_softc *sc = file->private_data;
320 unsigned int len = 0;
322 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
323 len += snprintf(buf + len, sizeof(buf) - len,
324 "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
325 len += snprintf(buf + len, sizeof(buf) - len,
326 "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
327 len += snprintf(buf + len, sizeof(buf) - len,
328 "%8s: %10u\n", "WATCHDOG",
329 sc->debug.stats.istats.bb_watchdog);
331 len += snprintf(buf + len, sizeof(buf) - len,
332 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
334 len += snprintf(buf + len, sizeof(buf) - len,
335 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
336 len += snprintf(buf + len, sizeof(buf) - len,
337 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
338 len += snprintf(buf + len, sizeof(buf) - len,
339 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
340 len += snprintf(buf + len, sizeof(buf) - len,
341 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
342 len += snprintf(buf + len, sizeof(buf) - len,
343 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
344 len += snprintf(buf + len, sizeof(buf) - len,
345 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
346 len += snprintf(buf + len, sizeof(buf) - len,
347 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
348 len += snprintf(buf + len, sizeof(buf) - len,
349 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
350 len += snprintf(buf + len, sizeof(buf) - len,
351 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
352 len += snprintf(buf + len, sizeof(buf) - len,
353 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
354 len += snprintf(buf + len, sizeof(buf) - len,
355 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
356 len += snprintf(buf + len, sizeof(buf) - len,
357 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
358 len += snprintf(buf + len, sizeof(buf) - len,
359 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
360 len += snprintf(buf + len, sizeof(buf) - len,
361 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
362 len += snprintf(buf + len, sizeof(buf) - len,
363 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
364 len += snprintf(buf + len, sizeof(buf) - len,
365 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
366 len += snprintf(buf + len, sizeof(buf) - len,
367 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
369 if (len > sizeof(buf))
372 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
375 static const struct file_operations fops_interrupt = {
376 .read = read_file_interrupt,
377 .open = ath9k_debugfs_open,
381 void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
383 struct ath_rc_stats *stats;
385 stats = &sc->debug.stats.rcstats[final_rate];
389 void ath_debug_stat_retries(struct ath_softc *sc, int rix,
390 int xretries, int retries, u8 per)
392 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
394 stats->xretries += xretries;
395 stats->retries += retries;
399 static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
400 size_t count, loff_t *ppos)
402 struct ath_softc *sc = file->private_data;
404 unsigned int len = 0, max;
408 if (sc->cur_rate_table == NULL)
411 max = 80 + sc->cur_rate_table->rate_cnt * 1024 + 1;
412 buf = kmalloc(max, GFP_KERNEL);
416 len += sprintf(buf, "%6s %6s %6s "
417 "%10s %10s %10s %10s\n",
419 "Success", "Retries", "XRetries", "PER");
421 for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
422 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
423 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
426 int used_mcs = 0, used_htmode = 0;
428 if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) {
429 used_mcs = snprintf(mcs, 5, "%d",
430 sc->cur_rate_table->info[i].ratecode);
432 if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy))
433 used_htmode = snprintf(htmode, 5, "HT40");
434 else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy))
435 used_htmode = snprintf(htmode, 5, "HT20");
437 used_htmode = snprintf(htmode, 5, "????");
440 mcs[used_mcs] = '\0';
441 htmode[used_htmode] = '\0';
443 len += snprintf(buf + len, max - len,
445 "%10u %10u %10u %10u\n",
449 (ratekbps % 1000) / 100,
459 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
464 static const struct file_operations fops_rcstat = {
465 .read = read_file_rcstat,
466 .open = ath9k_debugfs_open,
470 static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
473 case ATH_WIPHY_INACTIVE:
475 case ATH_WIPHY_ACTIVE:
477 case ATH_WIPHY_PAUSING:
479 case ATH_WIPHY_PAUSED:
487 static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
488 size_t count, loff_t *ppos)
490 struct ath_softc *sc = file->private_data;
492 unsigned int len = 0;
496 len += snprintf(buf + len, sizeof(buf) - len,
497 "primary: %s (%s chan=%d ht=%d)\n",
498 wiphy_name(sc->pri_wiphy->hw->wiphy),
499 ath_wiphy_state_str(sc->pri_wiphy->state),
500 sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
501 for (i = 0; i < sc->num_sec_wiphy; i++) {
502 struct ath_wiphy *aphy = sc->sec_wiphy[i];
505 len += snprintf(buf + len, sizeof(buf) - len,
506 "secondary: %s (%s chan=%d ht=%d)\n",
507 wiphy_name(aphy->hw->wiphy),
508 ath_wiphy_state_str(aphy->state),
509 aphy->chan_idx, aphy->chan_is_ht);
512 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
513 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
514 len += snprintf(buf + len, sizeof(buf) - len,
515 "addr: %pM\n", addr);
516 put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
517 put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
518 len += snprintf(buf + len, sizeof(buf) - len,
519 "addrmask: %pM\n", addr);
521 if (len > sizeof(buf))
524 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
527 static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
530 if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
531 return sc->pri_wiphy;
532 for (i = 0; i < sc->num_sec_wiphy; i++) {
533 struct ath_wiphy *aphy = sc->sec_wiphy[i];
534 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
540 static int del_wiphy(struct ath_softc *sc, const char *name)
542 struct ath_wiphy *aphy = get_wiphy(sc, name);
545 return ath9k_wiphy_del(aphy);
548 static int pause_wiphy(struct ath_softc *sc, const char *name)
550 struct ath_wiphy *aphy = get_wiphy(sc, name);
553 return ath9k_wiphy_pause(aphy);
556 static int unpause_wiphy(struct ath_softc *sc, const char *name)
558 struct ath_wiphy *aphy = get_wiphy(sc, name);
561 return ath9k_wiphy_unpause(aphy);
564 static int select_wiphy(struct ath_softc *sc, const char *name)
566 struct ath_wiphy *aphy = get_wiphy(sc, name);
569 return ath9k_wiphy_select(aphy);
572 static int schedule_wiphy(struct ath_softc *sc, const char *msec)
574 ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
578 static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
579 size_t count, loff_t *ppos)
581 struct ath_softc *sc = file->private_data;
585 len = min(count, sizeof(buf) - 1);
586 if (copy_from_user(buf, user_buf, len))
589 if (len > 0 && buf[len - 1] == '\n')
592 if (strncmp(buf, "add", 3) == 0) {
593 int res = ath9k_wiphy_add(sc);
596 } else if (strncmp(buf, "del=", 4) == 0) {
597 int res = del_wiphy(sc, buf + 4);
600 } else if (strncmp(buf, "pause=", 6) == 0) {
601 int res = pause_wiphy(sc, buf + 6);
604 } else if (strncmp(buf, "unpause=", 8) == 0) {
605 int res = unpause_wiphy(sc, buf + 8);
608 } else if (strncmp(buf, "select=", 7) == 0) {
609 int res = select_wiphy(sc, buf + 7);
612 } else if (strncmp(buf, "schedule=", 9) == 0) {
613 int res = schedule_wiphy(sc, buf + 9);
622 static const struct file_operations fops_wiphy = {
623 .read = read_file_wiphy,
624 .write = write_file_wiphy,
625 .open = ath9k_debugfs_open,
629 #define PR(str, elem) \
631 len += snprintf(buf + len, size - len, \
632 "%s%13u%11u%10u%10u\n", str, \
633 sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BE]].elem, \
634 sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BK]].elem, \
635 sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VI]].elem, \
636 sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VO]].elem); \
639 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
640 size_t count, loff_t *ppos)
642 struct ath_softc *sc = file->private_data;
644 unsigned int len = 0, size = 2048;
647 buf = kzalloc(size, GFP_KERNEL);
651 len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
653 PR("MPDUs Queued: ", queued);
654 PR("MPDUs Completed: ", completed);
655 PR("Aggregates: ", a_aggr);
656 PR("AMPDUs Queued: ", a_queued);
657 PR("AMPDUs Completed:", a_completed);
658 PR("AMPDUs Retried: ", a_retries);
659 PR("AMPDUs XRetried: ", a_xretries);
660 PR("FIFO Underrun: ", fifo_underrun);
661 PR("TXOP Exceeded: ", xtxop);
662 PR("TXTIMER Expiry: ", timer_exp);
663 PR("DESC CFG Error: ", desc_cfg_err);
664 PR("DATA Underrun: ", data_underrun);
665 PR("DELIM Underrun: ", delim_underrun);
670 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
676 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
677 struct ath_buf *bf, struct ath_tx_status *ts)
679 if (bf_isampdu(bf)) {
680 if (bf_isxretried(bf))
681 TX_STAT_INC(txq->axq_qnum, a_xretries);
683 TX_STAT_INC(txq->axq_qnum, a_completed);
685 TX_STAT_INC(txq->axq_qnum, completed);
688 if (ts->ts_status & ATH9K_TXERR_FIFO)
689 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
690 if (ts->ts_status & ATH9K_TXERR_XTXOP)
691 TX_STAT_INC(txq->axq_qnum, xtxop);
692 if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
693 TX_STAT_INC(txq->axq_qnum, timer_exp);
694 if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
695 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
696 if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
697 TX_STAT_INC(txq->axq_qnum, data_underrun);
698 if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
699 TX_STAT_INC(txq->axq_qnum, delim_underrun);
702 static const struct file_operations fops_xmit = {
703 .read = read_file_xmit,
704 .open = ath9k_debugfs_open,
708 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
709 size_t count, loff_t *ppos)
711 #define PHY_ERR(s, p) \
712 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
713 sc->debug.stats.rxstats.phy_err_stats[p]);
715 struct ath_softc *sc = file->private_data;
717 unsigned int len = 0, size = 1152;
720 buf = kzalloc(size, GFP_KERNEL);
724 len += snprintf(buf + len, size - len,
725 "%18s : %10u\n", "CRC ERR",
726 sc->debug.stats.rxstats.crc_err);
727 len += snprintf(buf + len, size - len,
728 "%18s : %10u\n", "DECRYPT CRC ERR",
729 sc->debug.stats.rxstats.decrypt_crc_err);
730 len += snprintf(buf + len, size - len,
731 "%18s : %10u\n", "PHY ERR",
732 sc->debug.stats.rxstats.phy_err);
733 len += snprintf(buf + len, size - len,
734 "%18s : %10u\n", "MIC ERR",
735 sc->debug.stats.rxstats.mic_err);
736 len += snprintf(buf + len, size - len,
737 "%18s : %10u\n", "PRE-DELIM CRC ERR",
738 sc->debug.stats.rxstats.pre_delim_crc_err);
739 len += snprintf(buf + len, size - len,
740 "%18s : %10u\n", "POST-DELIM CRC ERR",
741 sc->debug.stats.rxstats.post_delim_crc_err);
742 len += snprintf(buf + len, size - len,
743 "%18s : %10u\n", "DECRYPT BUSY ERR",
744 sc->debug.stats.rxstats.decrypt_busy_err);
746 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
747 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
748 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
749 PHY_ERR("RATE", ATH9K_PHYERR_RATE);
750 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
751 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
752 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
753 PHY_ERR("TOR", ATH9K_PHYERR_TOR);
754 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
755 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
756 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
757 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
758 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
759 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
760 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
761 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
762 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
763 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
764 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
765 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
766 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
767 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
768 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
769 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
770 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
771 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
776 retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
784 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
786 #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
787 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
791 if (rs->rs_status & ATH9K_RXERR_CRC)
792 RX_STAT_INC(crc_err);
793 if (rs->rs_status & ATH9K_RXERR_DECRYPT)
794 RX_STAT_INC(decrypt_crc_err);
795 if (rs->rs_status & ATH9K_RXERR_MIC)
796 RX_STAT_INC(mic_err);
797 if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
798 RX_STAT_INC(pre_delim_crc_err);
799 if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
800 RX_STAT_INC(post_delim_crc_err);
801 if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
802 RX_STAT_INC(decrypt_busy_err);
804 if (rs->rs_status & ATH9K_RXERR_PHY) {
805 RX_STAT_INC(phy_err);
806 phyerr = rs->rs_phyerr & 0x24;
807 RX_PHY_ERR_INC(phyerr);
811 #undef RX_PHY_ERR_INC
814 static const struct file_operations fops_recv = {
815 .read = read_file_recv,
816 .open = ath9k_debugfs_open,
820 static ssize_t read_file_regidx(struct file *file, char __user *user_buf,
821 size_t count, loff_t *ppos)
823 struct ath_softc *sc = file->private_data;
827 len = sprintf(buf, "0x%08x\n", sc->debug.regidx);
828 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
831 static ssize_t write_file_regidx(struct file *file, const char __user *user_buf,
832 size_t count, loff_t *ppos)
834 struct ath_softc *sc = file->private_data;
835 unsigned long regidx;
839 len = min(count, sizeof(buf) - 1);
840 if (copy_from_user(buf, user_buf, len))
844 if (strict_strtoul(buf, 0, ®idx))
847 sc->debug.regidx = regidx;
851 static const struct file_operations fops_regidx = {
852 .read = read_file_regidx,
853 .write = write_file_regidx,
854 .open = ath9k_debugfs_open,
858 static ssize_t read_file_regval(struct file *file, char __user *user_buf,
859 size_t count, loff_t *ppos)
861 struct ath_softc *sc = file->private_data;
862 struct ath_hw *ah = sc->sc_ah;
867 regval = REG_READ_D(ah, sc->debug.regidx);
868 len = sprintf(buf, "0x%08x\n", regval);
869 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
872 static ssize_t write_file_regval(struct file *file, const char __user *user_buf,
873 size_t count, loff_t *ppos)
875 struct ath_softc *sc = file->private_data;
876 struct ath_hw *ah = sc->sc_ah;
877 unsigned long regval;
881 len = min(count, sizeof(buf) - 1);
882 if (copy_from_user(buf, user_buf, len))
886 if (strict_strtoul(buf, 0, ®val))
889 REG_WRITE_D(ah, sc->debug.regidx, regval);
893 static const struct file_operations fops_regval = {
894 .read = read_file_regval,
895 .write = write_file_regval,
896 .open = ath9k_debugfs_open,
900 int ath9k_init_debug(struct ath_hw *ah)
902 struct ath_common *common = ath9k_hw_common(ah);
903 struct ath_softc *sc = (struct ath_softc *) common->priv;
905 if (!ath9k_debugfs_root)
908 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
910 if (!sc->debug.debugfs_phy)
913 #ifdef CONFIG_ATH_DEBUG
914 if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR,
915 sc->debug.debugfs_phy, sc, &fops_debug))
919 if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy,
923 if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy,
924 sc, &fops_interrupt))
927 if (!debugfs_create_file("rcstat", S_IRUSR, sc->debug.debugfs_phy,
931 if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR,
932 sc->debug.debugfs_phy, sc, &fops_wiphy))
935 if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy,
939 if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy,
943 if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR,
944 sc->debug.debugfs_phy, sc, &fops_rx_chainmask))
947 if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR,
948 sc->debug.debugfs_phy, sc, &fops_tx_chainmask))
951 if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR,
952 sc->debug.debugfs_phy, sc, &fops_regidx))
955 if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR,
956 sc->debug.debugfs_phy, sc, &fops_regval))
959 if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR,
960 sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca))
963 sc->debug.regidx = 0;
966 ath9k_exit_debug(ah);
970 void ath9k_exit_debug(struct ath_hw *ah)
972 struct ath_common *common = ath9k_hw_common(ah);
973 struct ath_softc *sc = (struct ath_softc *) common->priv;
975 debugfs_remove_recursive(sc->debug.debugfs_phy);
978 int ath9k_debug_create_root(void)
980 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
981 if (!ath9k_debugfs_root)
987 void ath9k_debug_remove_root(void)
989 debugfs_remove(ath9k_debugfs_root);
990 ath9k_debugfs_root = NULL;