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