Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Atheros Communications Inc. |
| 3 | * |
| 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 | |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 17 | #include "ath9k.h" |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 18 | |
| 19 | static unsigned int ath9k_debug = DBG_DEFAULT; |
| 20 | module_param_named(debug, ath9k_debug, uint, 0); |
| 21 | |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 22 | static struct dentry *ath9k_debugfs_root; |
| 23 | |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 24 | void DPRINTF(struct ath_softc *sc, int dbg_mask, const char *fmt, ...) |
| 25 | { |
| 26 | if (!sc) |
| 27 | return; |
| 28 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 29 | if (sc->debug.debug_mask & dbg_mask) { |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 30 | va_list args; |
| 31 | |
| 32 | va_start(args, fmt); |
| 33 | printk(KERN_DEBUG "ath9k: "); |
| 34 | vprintk(fmt, args); |
| 35 | va_end(args); |
| 36 | } |
| 37 | } |
| 38 | |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 39 | static int ath9k_debugfs_open(struct inode *inode, struct file *file) |
| 40 | { |
| 41 | file->private_data = inode->i_private; |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static ssize_t read_file_dma(struct file *file, char __user *user_buf, |
| 46 | size_t count, loff_t *ppos) |
| 47 | { |
| 48 | struct ath_softc *sc = file->private_data; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 49 | struct ath_hw *ah = sc->sc_ah; |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 50 | char buf[1024]; |
| 51 | unsigned int len = 0; |
| 52 | u32 val[ATH9K_NUM_DMA_DEBUG_REGS]; |
| 53 | int i, qcuOffset = 0, dcuOffset = 0; |
| 54 | u32 *qcuBase = &val[0], *dcuBase = &val[4]; |
| 55 | |
| 56 | REG_WRITE(ah, AR_MACMISC, |
| 57 | ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | |
| 58 | (AR_MACMISC_MISC_OBS_BUS_1 << |
| 59 | AR_MACMISC_MISC_OBS_BUS_MSB_S))); |
| 60 | |
| 61 | len += snprintf(buf + len, sizeof(buf) - len, |
| 62 | "Raw DMA Debug values:\n"); |
| 63 | |
| 64 | for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { |
| 65 | if (i % 4 == 0) |
| 66 | len += snprintf(buf + len, sizeof(buf) - len, "\n"); |
| 67 | |
| 68 | val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32))); |
| 69 | len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ", |
| 70 | i, val[i]); |
| 71 | } |
| 72 | |
| 73 | len += snprintf(buf + len, sizeof(buf) - len, "\n\n"); |
| 74 | len += snprintf(buf + len, sizeof(buf) - len, |
| 75 | "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); |
| 76 | |
| 77 | for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { |
| 78 | if (i == 8) { |
| 79 | qcuOffset = 0; |
| 80 | qcuBase++; |
| 81 | } |
| 82 | |
| 83 | if (i == 6) { |
| 84 | dcuOffset = 0; |
| 85 | dcuBase++; |
| 86 | } |
| 87 | |
| 88 | len += snprintf(buf + len, sizeof(buf) - len, |
| 89 | "%2d %2x %1x %2x %2x\n", |
| 90 | i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset, |
| 91 | (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3), |
| 92 | val[2] & (0x7 << (i * 3)) >> (i * 3), |
| 93 | (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset); |
| 94 | } |
| 95 | |
| 96 | len += snprintf(buf + len, sizeof(buf) - len, "\n"); |
| 97 | |
| 98 | len += snprintf(buf + len, sizeof(buf) - len, |
| 99 | "qcu_stitch state: %2x qcu_fetch state: %2x\n", |
| 100 | (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); |
| 101 | len += snprintf(buf + len, sizeof(buf) - len, |
| 102 | "qcu_complete state: %2x dcu_complete state: %2x\n", |
| 103 | (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); |
| 104 | len += snprintf(buf + len, sizeof(buf) - len, |
| 105 | "dcu_arb state: %2x dcu_fp state: %2x\n", |
| 106 | (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); |
| 107 | len += snprintf(buf + len, sizeof(buf) - len, |
| 108 | "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", |
| 109 | (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); |
| 110 | len += snprintf(buf + len, sizeof(buf) - len, |
| 111 | "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", |
| 112 | (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); |
| 113 | len += snprintf(buf + len, sizeof(buf) - len, |
| 114 | "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", |
| 115 | (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); |
| 116 | |
| 117 | len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n", |
| 118 | REG_READ(ah, AR_OBS_BUS_1)); |
| 119 | len += snprintf(buf + len, sizeof(buf) - len, |
| 120 | "AR_CR: 0x%x \n", REG_READ(ah, AR_CR)); |
| 121 | |
| 122 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 123 | } |
| 124 | |
| 125 | static const struct file_operations fops_dma = { |
| 126 | .read = read_file_dma, |
| 127 | .open = ath9k_debugfs_open, |
| 128 | .owner = THIS_MODULE |
| 129 | }; |
| 130 | |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 131 | |
| 132 | void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status) |
| 133 | { |
| 134 | if (status) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 135 | sc->debug.stats.istats.total++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 136 | if (status & ATH9K_INT_RX) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 137 | sc->debug.stats.istats.rxok++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 138 | if (status & ATH9K_INT_RXEOL) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 139 | sc->debug.stats.istats.rxeol++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 140 | if (status & ATH9K_INT_RXORN) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 141 | sc->debug.stats.istats.rxorn++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 142 | if (status & ATH9K_INT_TX) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 143 | sc->debug.stats.istats.txok++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 144 | if (status & ATH9K_INT_TXURN) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 145 | sc->debug.stats.istats.txurn++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 146 | if (status & ATH9K_INT_MIB) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 147 | sc->debug.stats.istats.mib++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 148 | if (status & ATH9K_INT_RXPHY) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 149 | sc->debug.stats.istats.rxphyerr++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 150 | if (status & ATH9K_INT_RXKCM) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 151 | sc->debug.stats.istats.rx_keycache_miss++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 152 | if (status & ATH9K_INT_SWBA) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 153 | sc->debug.stats.istats.swba++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 154 | if (status & ATH9K_INT_BMISS) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 155 | sc->debug.stats.istats.bmiss++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 156 | if (status & ATH9K_INT_BNR) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 157 | sc->debug.stats.istats.bnr++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 158 | if (status & ATH9K_INT_CST) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 159 | sc->debug.stats.istats.cst++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 160 | if (status & ATH9K_INT_GTT) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 161 | sc->debug.stats.istats.gtt++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 162 | if (status & ATH9K_INT_TIM) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 163 | sc->debug.stats.istats.tim++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 164 | if (status & ATH9K_INT_CABEND) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 165 | sc->debug.stats.istats.cabend++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 166 | if (status & ATH9K_INT_DTIMSYNC) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 167 | sc->debug.stats.istats.dtimsync++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 168 | if (status & ATH9K_INT_DTIM) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 169 | sc->debug.stats.istats.dtim++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, |
| 173 | size_t count, loff_t *ppos) |
| 174 | { |
| 175 | struct ath_softc *sc = file->private_data; |
| 176 | char buf[512]; |
| 177 | unsigned int len = 0; |
| 178 | |
| 179 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 180 | "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 181 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 182 | "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 183 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 184 | "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 185 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 186 | "%8s: %10u\n", "TX", sc->debug.stats.istats.txok); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 187 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 188 | "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 189 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 190 | "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 191 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 192 | "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 193 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 194 | "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 195 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 196 | "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 197 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 198 | "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 199 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 200 | "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 201 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 202 | "%8s: %10u\n", "CST", sc->debug.stats.istats.cst); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 203 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 204 | "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 205 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 206 | "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 207 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 208 | "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 209 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 210 | "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 211 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 212 | "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 213 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 214 | "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 215 | |
| 216 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 217 | } |
| 218 | |
| 219 | static const struct file_operations fops_interrupt = { |
| 220 | .read = read_file_interrupt, |
| 221 | .open = ath9k_debugfs_open, |
| 222 | .owner = THIS_MODULE |
| 223 | }; |
| 224 | |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 225 | static void ath_debug_stat_11n_rc(struct ath_softc *sc, struct sk_buff *skb) |
| 226 | { |
| 227 | struct ath_tx_info_priv *tx_info_priv = NULL; |
| 228 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 229 | struct ieee80211_tx_rate *rates = tx_info->status.rates; |
| 230 | int final_ts_idx, idx; |
| 231 | |
| 232 | tx_info_priv = ATH_TX_INFO_PRIV(tx_info); |
| 233 | final_ts_idx = tx_info_priv->tx.ts_rateindex; |
| 234 | idx = sc->cur_rate_table->info[rates[final_ts_idx].idx].dot11rate; |
| 235 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 236 | sc->debug.stats.n_rcstats[idx].success++; |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static void ath_debug_stat_legacy_rc(struct ath_softc *sc, struct sk_buff *skb) |
| 240 | { |
| 241 | struct ath_tx_info_priv *tx_info_priv = NULL; |
| 242 | struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); |
| 243 | struct ieee80211_tx_rate *rates = tx_info->status.rates; |
| 244 | int final_ts_idx, idx; |
| 245 | |
| 246 | tx_info_priv = ATH_TX_INFO_PRIV(tx_info); |
| 247 | final_ts_idx = tx_info_priv->tx.ts_rateindex; |
| 248 | idx = rates[final_ts_idx].idx; |
| 249 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 250 | sc->debug.stats.legacy_rcstats[idx].success++; |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb) |
| 254 | { |
| 255 | if (conf_is_ht(&sc->hw->conf)) |
| 256 | ath_debug_stat_11n_rc(sc, skb); |
| 257 | else |
| 258 | ath_debug_stat_legacy_rc(sc, skb); |
| 259 | } |
| 260 | |
Sujith | 029bc43 | 2009-02-04 08:10:26 +0530 | [diff] [blame] | 261 | /* FIXME: legacy rates, later on .. */ |
| 262 | void ath_debug_stat_retries(struct ath_softc *sc, int rix, |
Sujith | 9e71279 | 2009-02-20 15:13:20 +0530 | [diff] [blame] | 263 | int xretries, int retries, u8 per) |
Sujith | 029bc43 | 2009-02-04 08:10:26 +0530 | [diff] [blame] | 264 | { |
| 265 | if (conf_is_ht(&sc->hw->conf)) { |
| 266 | int idx = sc->cur_rate_table->info[rix].dot11rate; |
| 267 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 268 | sc->debug.stats.n_rcstats[idx].xretries += xretries; |
| 269 | sc->debug.stats.n_rcstats[idx].retries += retries; |
Sujith | 9e71279 | 2009-02-20 15:13:20 +0530 | [diff] [blame] | 270 | sc->debug.stats.n_rcstats[idx].per = per; |
Sujith | 029bc43 | 2009-02-04 08:10:26 +0530 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 274 | static ssize_t ath_read_file_stat_11n_rc(struct file *file, |
| 275 | char __user *user_buf, |
| 276 | size_t count, loff_t *ppos) |
| 277 | { |
| 278 | struct ath_softc *sc = file->private_data; |
Sujith | 029bc43 | 2009-02-04 08:10:26 +0530 | [diff] [blame] | 279 | char buf[1024]; |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 280 | unsigned int len = 0; |
| 281 | int i = 0; |
| 282 | |
Sujith | 9e71279 | 2009-02-20 15:13:20 +0530 | [diff] [blame] | 283 | len += sprintf(buf, "%7s %13s %8s %8s %6s\n\n", "Rate", "Success", |
| 284 | "Retries", "XRetries", "PER"); |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 285 | |
| 286 | for (i = 0; i <= 15; i++) { |
| 287 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 9e71279 | 2009-02-20 15:13:20 +0530 | [diff] [blame] | 288 | "%5s%3d: %8u %8u %8u %8u\n", "MCS", i, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 289 | sc->debug.stats.n_rcstats[i].success, |
| 290 | sc->debug.stats.n_rcstats[i].retries, |
Sujith | 9e71279 | 2009-02-20 15:13:20 +0530 | [diff] [blame] | 291 | sc->debug.stats.n_rcstats[i].xretries, |
| 292 | sc->debug.stats.n_rcstats[i].per); |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 296 | } |
| 297 | |
| 298 | static ssize_t ath_read_file_stat_legacy_rc(struct file *file, |
| 299 | char __user *user_buf, |
| 300 | size_t count, loff_t *ppos) |
| 301 | { |
| 302 | struct ath_softc *sc = file->private_data; |
| 303 | char buf[512]; |
| 304 | unsigned int len = 0; |
| 305 | int i = 0; |
| 306 | |
| 307 | len += sprintf(buf, "%7s %13s\n\n", "Rate", "Success"); |
| 308 | |
| 309 | for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) { |
| 310 | len += snprintf(buf + len, sizeof(buf) - len, "%5u: %12u\n", |
| 311 | sc->cur_rate_table->info[i].ratekbps / 1000, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 312 | sc->debug.stats.legacy_rcstats[i].success); |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 316 | } |
| 317 | |
| 318 | static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, |
| 319 | size_t count, loff_t *ppos) |
| 320 | { |
| 321 | struct ath_softc *sc = file->private_data; |
| 322 | |
| 323 | if (conf_is_ht(&sc->hw->conf)) |
| 324 | return ath_read_file_stat_11n_rc(file, user_buf, count, ppos); |
| 325 | else |
| 326 | return ath_read_file_stat_legacy_rc(file, user_buf, count ,ppos); |
| 327 | } |
| 328 | |
| 329 | static const struct file_operations fops_rcstat = { |
| 330 | .read = read_file_rcstat, |
| 331 | .open = ath9k_debugfs_open, |
| 332 | .owner = THIS_MODULE |
| 333 | }; |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 334 | |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 335 | static const char * ath_wiphy_state_str(enum ath_wiphy_state state) |
| 336 | { |
| 337 | switch (state) { |
| 338 | case ATH_WIPHY_INACTIVE: |
| 339 | return "INACTIVE"; |
| 340 | case ATH_WIPHY_ACTIVE: |
| 341 | return "ACTIVE"; |
| 342 | case ATH_WIPHY_PAUSING: |
| 343 | return "PAUSING"; |
| 344 | case ATH_WIPHY_PAUSED: |
| 345 | return "PAUSED"; |
| 346 | case ATH_WIPHY_SCAN: |
| 347 | return "SCAN"; |
| 348 | } |
| 349 | return "?"; |
| 350 | } |
| 351 | |
| 352 | static ssize_t read_file_wiphy(struct file *file, char __user *user_buf, |
| 353 | size_t count, loff_t *ppos) |
| 354 | { |
| 355 | struct ath_softc *sc = file->private_data; |
| 356 | char buf[512]; |
| 357 | unsigned int len = 0; |
| 358 | int i; |
| 359 | u8 addr[ETH_ALEN]; |
| 360 | |
| 361 | len += snprintf(buf + len, sizeof(buf) - len, |
| 362 | "primary: %s (%s chan=%d ht=%d)\n", |
| 363 | wiphy_name(sc->pri_wiphy->hw->wiphy), |
| 364 | ath_wiphy_state_str(sc->pri_wiphy->state), |
| 365 | sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht); |
| 366 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 367 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 368 | if (aphy == NULL) |
| 369 | continue; |
| 370 | len += snprintf(buf + len, sizeof(buf) - len, |
| 371 | "secondary: %s (%s chan=%d ht=%d)\n", |
| 372 | wiphy_name(aphy->hw->wiphy), |
| 373 | ath_wiphy_state_str(aphy->state), |
| 374 | aphy->chan_idx, aphy->chan_is_ht); |
| 375 | } |
| 376 | |
| 377 | put_unaligned_le32(REG_READ(sc->sc_ah, AR_STA_ID0), addr); |
| 378 | put_unaligned_le16(REG_READ(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4); |
| 379 | len += snprintf(buf + len, sizeof(buf) - len, |
| 380 | "addr: %pM\n", addr); |
| 381 | put_unaligned_le32(REG_READ(sc->sc_ah, AR_BSSMSKL), addr); |
| 382 | put_unaligned_le16(REG_READ(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4); |
| 383 | len += snprintf(buf + len, sizeof(buf) - len, |
| 384 | "addrmask: %pM\n", addr); |
| 385 | |
| 386 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 387 | } |
| 388 | |
| 389 | static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name) |
| 390 | { |
| 391 | int i; |
| 392 | if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0) |
| 393 | return sc->pri_wiphy; |
| 394 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 395 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 396 | if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0) |
| 397 | return aphy; |
| 398 | } |
| 399 | return NULL; |
| 400 | } |
| 401 | |
| 402 | static int del_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_del(aphy); |
| 408 | } |
| 409 | |
| 410 | static int pause_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_pause(aphy); |
| 416 | } |
| 417 | |
| 418 | static int unpause_wiphy(struct ath_softc *sc, const char *name) |
| 419 | { |
| 420 | struct ath_wiphy *aphy = get_wiphy(sc, name); |
| 421 | if (!aphy) |
| 422 | return -ENOENT; |
| 423 | return ath9k_wiphy_unpause(aphy); |
| 424 | } |
| 425 | |
| 426 | static int select_wiphy(struct ath_softc *sc, const char *name) |
| 427 | { |
| 428 | struct ath_wiphy *aphy = get_wiphy(sc, name); |
| 429 | if (!aphy) |
| 430 | return -ENOENT; |
| 431 | return ath9k_wiphy_select(aphy); |
| 432 | } |
| 433 | |
| 434 | static int schedule_wiphy(struct ath_softc *sc, const char *msec) |
| 435 | { |
| 436 | ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0)); |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf, |
| 441 | size_t count, loff_t *ppos) |
| 442 | { |
| 443 | struct ath_softc *sc = file->private_data; |
| 444 | char buf[50]; |
| 445 | size_t len; |
| 446 | |
| 447 | len = min(count, sizeof(buf) - 1); |
| 448 | if (copy_from_user(buf, user_buf, len)) |
| 449 | return -EFAULT; |
| 450 | buf[len] = '\0'; |
| 451 | if (len > 0 && buf[len - 1] == '\n') |
| 452 | buf[len - 1] = '\0'; |
| 453 | |
| 454 | if (strncmp(buf, "add", 3) == 0) { |
| 455 | int res = ath9k_wiphy_add(sc); |
| 456 | if (res < 0) |
| 457 | return res; |
| 458 | } else if (strncmp(buf, "del=", 4) == 0) { |
| 459 | int res = del_wiphy(sc, buf + 4); |
| 460 | if (res < 0) |
| 461 | return res; |
| 462 | } else if (strncmp(buf, "pause=", 6) == 0) { |
| 463 | int res = pause_wiphy(sc, buf + 6); |
| 464 | if (res < 0) |
| 465 | return res; |
| 466 | } else if (strncmp(buf, "unpause=", 8) == 0) { |
| 467 | int res = unpause_wiphy(sc, buf + 8); |
| 468 | if (res < 0) |
| 469 | return res; |
| 470 | } else if (strncmp(buf, "select=", 7) == 0) { |
| 471 | int res = select_wiphy(sc, buf + 7); |
| 472 | if (res < 0) |
| 473 | return res; |
| 474 | } else if (strncmp(buf, "schedule=", 9) == 0) { |
| 475 | int res = schedule_wiphy(sc, buf + 9); |
| 476 | if (res < 0) |
| 477 | return res; |
| 478 | } else |
| 479 | return -EOPNOTSUPP; |
| 480 | |
| 481 | return count; |
| 482 | } |
| 483 | |
| 484 | static const struct file_operations fops_wiphy = { |
| 485 | .read = read_file_wiphy, |
| 486 | .write = write_file_wiphy, |
| 487 | .open = ath9k_debugfs_open, |
| 488 | .owner = THIS_MODULE |
| 489 | }; |
| 490 | |
| 491 | |
Sujith | 826d268 | 2008-11-28 22:20:23 +0530 | [diff] [blame] | 492 | int ath9k_init_debug(struct ath_softc *sc) |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 493 | { |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 494 | sc->debug.debug_mask = ath9k_debug; |
Sujith | 826d268 | 2008-11-28 22:20:23 +0530 | [diff] [blame] | 495 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 496 | sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy), |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 497 | ath9k_debugfs_root); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 498 | if (!sc->debug.debugfs_phy) |
Sujith | 826d268 | 2008-11-28 22:20:23 +0530 | [diff] [blame] | 499 | goto err; |
| 500 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 501 | sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUGO, |
| 502 | sc->debug.debugfs_phy, sc, &fops_dma); |
| 503 | if (!sc->debug.debugfs_dma) |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 504 | goto err; |
| 505 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 506 | sc->debug.debugfs_interrupt = debugfs_create_file("interrupt", |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 507 | S_IRUGO, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 508 | sc->debug.debugfs_phy, |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 509 | sc, &fops_interrupt); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 510 | if (!sc->debug.debugfs_interrupt) |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 511 | goto err; |
| 512 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 513 | sc->debug.debugfs_rcstat = debugfs_create_file("rcstat", |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 514 | S_IRUGO, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 515 | sc->debug.debugfs_phy, |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 516 | sc, &fops_rcstat); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 517 | if (!sc->debug.debugfs_rcstat) |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 518 | goto err; |
| 519 | |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 520 | sc->debug.debugfs_wiphy = debugfs_create_file( |
| 521 | "wiphy", S_IRUGO | S_IWUSR, sc->debug.debugfs_phy, sc, |
| 522 | &fops_wiphy); |
| 523 | if (!sc->debug.debugfs_wiphy) |
| 524 | goto err; |
| 525 | |
Sujith | 826d268 | 2008-11-28 22:20:23 +0530 | [diff] [blame] | 526 | return 0; |
| 527 | err: |
| 528 | ath9k_exit_debug(sc); |
| 529 | return -ENOMEM; |
| 530 | } |
| 531 | |
| 532 | void ath9k_exit_debug(struct ath_softc *sc) |
| 533 | { |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 534 | debugfs_remove(sc->debug.debugfs_wiphy); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 535 | debugfs_remove(sc->debug.debugfs_rcstat); |
| 536 | debugfs_remove(sc->debug.debugfs_interrupt); |
| 537 | debugfs_remove(sc->debug.debugfs_dma); |
| 538 | debugfs_remove(sc->debug.debugfs_phy); |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | int ath9k_debug_create_root(void) |
| 542 | { |
| 543 | ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL); |
| 544 | if (!ath9k_debugfs_root) |
| 545 | return -ENOENT; |
| 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | void ath9k_debug_remove_root(void) |
| 551 | { |
| 552 | debugfs_remove(ath9k_debugfs_root); |
| 553 | ath9k_debugfs_root = NULL; |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 554 | } |