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 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Gabor Juhos | 5210311 | 2009-03-06 09:57:39 +0100 | [diff] [blame] | 18 | #include <asm/unaligned.h> |
| 19 | |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 20 | #include "ath9k.h" |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 21 | |
Luis R. Rodriguez | 475a6e4 | 2009-09-23 23:06:59 -0400 | [diff] [blame] | 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)) |
| 26 | |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 27 | static struct dentry *ath9k_debugfs_root; |
| 28 | |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 29 | static int ath9k_debugfs_open(struct inode *inode, struct file *file) |
| 30 | { |
| 31 | file->private_data = inode->i_private; |
| 32 | return 0; |
| 33 | } |
| 34 | |
Felix Fietkau | a830df0 | 2009-11-23 22:33:27 +0100 | [diff] [blame] | 35 | #ifdef CONFIG_ATH_DEBUG |
| 36 | |
Jeff Hansen | 2493928 | 2009-05-27 12:48:29 +0000 | [diff] [blame] | 37 | static ssize_t read_file_debug(struct file *file, char __user *user_buf, |
| 38 | size_t count, loff_t *ppos) |
| 39 | { |
| 40 | struct ath_softc *sc = file->private_data; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 41 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jeff Hansen | 2493928 | 2009-05-27 12:48:29 +0000 | [diff] [blame] | 42 | char buf[32]; |
Vasanthakumar Thiagarajan | 581f725 | 2009-06-02 19:28:55 +0530 | [diff] [blame] | 43 | unsigned int len; |
| 44 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 45 | len = sprintf(buf, "0x%08x\n", common->debug_mask); |
Jeff Hansen | 2493928 | 2009-05-27 12:48:29 +0000 | [diff] [blame] | 46 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 47 | } |
| 48 | |
| 49 | static ssize_t write_file_debug(struct file *file, const char __user *user_buf, |
| 50 | size_t count, loff_t *ppos) |
| 51 | { |
| 52 | struct ath_softc *sc = file->private_data; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 53 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Jeff Hansen | 2493928 | 2009-05-27 12:48:29 +0000 | [diff] [blame] | 54 | unsigned long mask; |
| 55 | char buf[32]; |
Vasanthakumar Thiagarajan | 581f725 | 2009-06-02 19:28:55 +0530 | [diff] [blame] | 56 | ssize_t len; |
| 57 | |
| 58 | len = min(count, sizeof(buf) - 1); |
| 59 | if (copy_from_user(buf, user_buf, len)) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 60 | return -EFAULT; |
Vasanthakumar Thiagarajan | 581f725 | 2009-06-02 19:28:55 +0530 | [diff] [blame] | 61 | |
| 62 | buf[len] = '\0'; |
| 63 | if (strict_strtoul(buf, 0, &mask)) |
| 64 | return -EINVAL; |
| 65 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 66 | common->debug_mask = mask; |
Jeff Hansen | 2493928 | 2009-05-27 12:48:29 +0000 | [diff] [blame] | 67 | return count; |
| 68 | } |
| 69 | |
| 70 | static const struct file_operations fops_debug = { |
| 71 | .read = read_file_debug, |
| 72 | .write = write_file_debug, |
| 73 | .open = ath9k_debugfs_open, |
| 74 | .owner = THIS_MODULE |
| 75 | }; |
| 76 | |
Felix Fietkau | a830df0 | 2009-11-23 22:33:27 +0100 | [diff] [blame] | 77 | #endif |
| 78 | |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 79 | #define DMA_BUF_LEN 1024 |
| 80 | |
Felix Fietkau | 1534069 | 2010-05-11 17:23:01 +0200 | [diff] [blame] | 81 | static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf, |
| 82 | size_t count, loff_t *ppos) |
| 83 | { |
| 84 | struct ath_softc *sc = file->private_data; |
| 85 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 86 | char buf[32]; |
| 87 | unsigned int len; |
| 88 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 89 | len = sprintf(buf, "0x%08x\n", common->tx_chainmask); |
Felix Fietkau | 1534069 | 2010-05-11 17:23:01 +0200 | [diff] [blame] | 90 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 91 | } |
| 92 | |
| 93 | static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf, |
| 94 | size_t count, loff_t *ppos) |
| 95 | { |
| 96 | struct ath_softc *sc = file->private_data; |
| 97 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 98 | unsigned long mask; |
| 99 | char buf[32]; |
| 100 | ssize_t len; |
| 101 | |
| 102 | len = min(count, sizeof(buf) - 1); |
| 103 | if (copy_from_user(buf, user_buf, len)) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 104 | return -EFAULT; |
Felix Fietkau | 1534069 | 2010-05-11 17:23:01 +0200 | [diff] [blame] | 105 | |
| 106 | buf[len] = '\0'; |
| 107 | if (strict_strtoul(buf, 0, &mask)) |
| 108 | return -EINVAL; |
| 109 | |
| 110 | common->tx_chainmask = mask; |
| 111 | sc->sc_ah->caps.tx_chainmask = mask; |
| 112 | return count; |
| 113 | } |
| 114 | |
| 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, |
| 119 | .owner = THIS_MODULE |
| 120 | }; |
| 121 | |
| 122 | |
| 123 | static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf, |
| 124 | size_t count, loff_t *ppos) |
| 125 | { |
| 126 | struct ath_softc *sc = file->private_data; |
| 127 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 128 | char buf[32]; |
| 129 | unsigned int len; |
| 130 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 131 | len = sprintf(buf, "0x%08x\n", common->rx_chainmask); |
Felix Fietkau | 1534069 | 2010-05-11 17:23:01 +0200 | [diff] [blame] | 132 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 133 | } |
| 134 | |
| 135 | static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf, |
| 136 | size_t count, loff_t *ppos) |
| 137 | { |
| 138 | struct ath_softc *sc = file->private_data; |
| 139 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 140 | unsigned long mask; |
| 141 | char buf[32]; |
| 142 | ssize_t len; |
| 143 | |
| 144 | len = min(count, sizeof(buf) - 1); |
| 145 | if (copy_from_user(buf, user_buf, len)) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 146 | return -EFAULT; |
Felix Fietkau | 1534069 | 2010-05-11 17:23:01 +0200 | [diff] [blame] | 147 | |
| 148 | buf[len] = '\0'; |
| 149 | if (strict_strtoul(buf, 0, &mask)) |
| 150 | return -EINVAL; |
| 151 | |
| 152 | common->rx_chainmask = mask; |
| 153 | sc->sc_ah->caps.rx_chainmask = mask; |
| 154 | return count; |
| 155 | } |
| 156 | |
| 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, |
| 161 | .owner = THIS_MODULE |
| 162 | }; |
| 163 | |
| 164 | |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 165 | static ssize_t read_file_dma(struct file *file, char __user *user_buf, |
| 166 | size_t count, loff_t *ppos) |
| 167 | { |
| 168 | struct ath_softc *sc = file->private_data; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 169 | struct ath_hw *ah = sc->sc_ah; |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 170 | char *buf; |
| 171 | int retval; |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 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]; |
| 176 | |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 177 | buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL); |
| 178 | if (!buf) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 179 | return -ENOMEM; |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 180 | |
Sujith | 7cf4a2e | 2009-08-26 11:11:57 +0530 | [diff] [blame] | 181 | ath9k_ps_wakeup(sc); |
| 182 | |
Luis R. Rodriguez | 475a6e4 | 2009-09-23 23:06:59 -0400 | [diff] [blame] | 183 | REG_WRITE_D(ah, AR_MACMISC, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 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))); |
| 187 | |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 188 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 189 | "Raw DMA Debug values:\n"); |
| 190 | |
| 191 | for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { |
| 192 | if (i % 4 == 0) |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 193 | len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 194 | |
Luis R. Rodriguez | 475a6e4 | 2009-09-23 23:06:59 -0400 | [diff] [blame] | 195 | val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32))); |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 196 | len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ", |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 197 | i, val[i]); |
| 198 | } |
| 199 | |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 200 | len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n"); |
| 201 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 202 | "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); |
| 203 | |
| 204 | for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { |
| 205 | if (i == 8) { |
| 206 | qcuOffset = 0; |
| 207 | qcuBase++; |
| 208 | } |
| 209 | |
| 210 | if (i == 6) { |
| 211 | dcuOffset = 0; |
| 212 | dcuBase++; |
| 213 | } |
| 214 | |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 215 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 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); |
| 221 | } |
| 222 | |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 223 | len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 224 | |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 225 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 226 | "qcu_stitch state: %2x qcu_fetch state: %2x\n", |
| 227 | (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 228 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 229 | "qcu_complete state: %2x dcu_complete state: %2x\n", |
| 230 | (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 231 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 232 | "dcu_arb state: %2x dcu_fp state: %2x\n", |
| 233 | (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 234 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 235 | "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", |
| 236 | (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 237 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 238 | "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", |
| 239 | (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 240 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 241 | "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", |
| 242 | (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); |
| 243 | |
Frans Pop | 60ece40 | 2010-03-24 19:46:30 +0100 | [diff] [blame] | 244 | len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n", |
Luis R. Rodriguez | 475a6e4 | 2009-09-23 23:06:59 -0400 | [diff] [blame] | 245 | REG_READ_D(ah, AR_OBS_BUS_1)); |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 246 | len += snprintf(buf + len, DMA_BUF_LEN - len, |
Frans Pop | 60ece40 | 2010-03-24 19:46:30 +0100 | [diff] [blame] | 247 | "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR)); |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 248 | |
Sujith | 7cf4a2e | 2009-08-26 11:11:57 +0530 | [diff] [blame] | 249 | ath9k_ps_restore(sc); |
| 250 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 251 | if (len > DMA_BUF_LEN) |
| 252 | len = DMA_BUF_LEN; |
| 253 | |
Pavel Roskin | 991a098 | 2010-01-29 17:22:26 -0500 | [diff] [blame] | 254 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 255 | kfree(buf); |
| 256 | return retval; |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | static const struct file_operations fops_dma = { |
| 260 | .read = read_file_dma, |
| 261 | .open = ath9k_debugfs_open, |
| 262 | .owner = THIS_MODULE |
| 263 | }; |
| 264 | |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 265 | |
| 266 | void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status) |
| 267 | { |
| 268 | if (status) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 269 | sc->debug.stats.istats.total++; |
Luis R. Rodriguez | a9616f4 | 2010-04-15 17:39:30 -0400 | [diff] [blame] | 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++; |
Luis R. Rodriguez | 08578b8 | 2010-05-13 13:33:44 -0400 | [diff] [blame] | 275 | if (status & ATH9K_INT_BB_WATCHDOG) |
| 276 | sc->debug.stats.istats.bb_watchdog++; |
Luis R. Rodriguez | a9616f4 | 2010-04-15 17:39:30 -0400 | [diff] [blame] | 277 | } else { |
| 278 | if (status & ATH9K_INT_RX) |
| 279 | sc->debug.stats.istats.rxok++; |
| 280 | } |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 281 | if (status & ATH9K_INT_RXEOL) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 282 | sc->debug.stats.istats.rxeol++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 283 | if (status & ATH9K_INT_RXORN) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 284 | sc->debug.stats.istats.rxorn++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 285 | if (status & ATH9K_INT_TX) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 286 | sc->debug.stats.istats.txok++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 287 | if (status & ATH9K_INT_TXURN) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 288 | sc->debug.stats.istats.txurn++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 289 | if (status & ATH9K_INT_MIB) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 290 | sc->debug.stats.istats.mib++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 291 | if (status & ATH9K_INT_RXPHY) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 292 | sc->debug.stats.istats.rxphyerr++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 293 | if (status & ATH9K_INT_RXKCM) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 294 | sc->debug.stats.istats.rx_keycache_miss++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 295 | if (status & ATH9K_INT_SWBA) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 296 | sc->debug.stats.istats.swba++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 297 | if (status & ATH9K_INT_BMISS) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 298 | sc->debug.stats.istats.bmiss++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 299 | if (status & ATH9K_INT_BNR) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 300 | sc->debug.stats.istats.bnr++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 301 | if (status & ATH9K_INT_CST) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 302 | sc->debug.stats.istats.cst++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 303 | if (status & ATH9K_INT_GTT) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 304 | sc->debug.stats.istats.gtt++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 305 | if (status & ATH9K_INT_TIM) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 306 | sc->debug.stats.istats.tim++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 307 | if (status & ATH9K_INT_CABEND) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 308 | sc->debug.stats.istats.cabend++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 309 | if (status & ATH9K_INT_DTIMSYNC) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 310 | sc->debug.stats.istats.dtimsync++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 311 | if (status & ATH9K_INT_DTIM) |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 312 | sc->debug.stats.istats.dtim++; |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, |
| 316 | size_t count, loff_t *ppos) |
| 317 | { |
| 318 | struct ath_softc *sc = file->private_data; |
| 319 | char buf[512]; |
| 320 | unsigned int len = 0; |
| 321 | |
Luis R. Rodriguez | a9616f4 | 2010-04-15 17:39:30 -0400 | [diff] [blame] | 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); |
Luis R. Rodriguez | 08578b8 | 2010-05-13 13:33:44 -0400 | [diff] [blame] | 327 | len += snprintf(buf + len, sizeof(buf) - len, |
| 328 | "%8s: %10u\n", "WATCHDOG", |
| 329 | sc->debug.stats.istats.bb_watchdog); |
Luis R. Rodriguez | a9616f4 | 2010-04-15 17:39:30 -0400 | [diff] [blame] | 330 | } else { |
| 331 | len += snprintf(buf + len, sizeof(buf) - len, |
| 332 | "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok); |
| 333 | } |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 334 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 335 | "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 336 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 337 | "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 338 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 339 | "%8s: %10u\n", "TX", sc->debug.stats.istats.txok); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 340 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 341 | "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 342 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 343 | "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 344 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 345 | "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 346 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 347 | "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 348 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 349 | "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 350 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 351 | "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 352 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 353 | "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 354 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 355 | "%8s: %10u\n", "CST", sc->debug.stats.istats.cst); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 356 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 357 | "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 358 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 359 | "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 360 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 361 | "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 362 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 363 | "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 364 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 365 | "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 366 | len += snprintf(buf + len, sizeof(buf) - len, |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 367 | "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total); |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 368 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 369 | if (len > sizeof(buf)) |
| 370 | len = sizeof(buf); |
| 371 | |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 372 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 373 | } |
| 374 | |
| 375 | static const struct file_operations fops_interrupt = { |
| 376 | .read = read_file_interrupt, |
| 377 | .open = ath9k_debugfs_open, |
| 378 | .owner = THIS_MODULE |
| 379 | }; |
| 380 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 381 | void ath_debug_stat_rc(struct ath_softc *sc, int final_rate) |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 382 | { |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 383 | struct ath_rc_stats *stats; |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 384 | |
Felix Fietkau | 545750d | 2009-11-23 22:21:01 +0100 | [diff] [blame] | 385 | stats = &sc->debug.stats.rcstats[final_rate]; |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 386 | stats->success++; |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 387 | } |
| 388 | |
Sujith | 029bc43 | 2009-02-04 08:10:26 +0530 | [diff] [blame] | 389 | void ath_debug_stat_retries(struct ath_softc *sc, int rix, |
Sujith | 9e71279 | 2009-02-20 15:13:20 +0530 | [diff] [blame] | 390 | int xretries, int retries, u8 per) |
Sujith | 029bc43 | 2009-02-04 08:10:26 +0530 | [diff] [blame] | 391 | { |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 392 | struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix]; |
Sujith | 029bc43 | 2009-02-04 08:10:26 +0530 | [diff] [blame] | 393 | |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 394 | stats->xretries += xretries; |
| 395 | stats->retries += retries; |
| 396 | stats->per = per; |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, |
| 400 | size_t count, loff_t *ppos) |
| 401 | { |
| 402 | struct ath_softc *sc = file->private_data; |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 403 | char *buf; |
| 404 | unsigned int len = 0, max; |
| 405 | int i = 0; |
| 406 | ssize_t retval; |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 407 | |
Sujith | 62b4fb6 | 2009-03-09 09:32:01 +0530 | [diff] [blame] | 408 | if (sc->cur_rate_table == NULL) |
| 409 | return 0; |
| 410 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 411 | max = 80 + sc->cur_rate_table->rate_cnt * 1024 + 1; |
| 412 | buf = kmalloc(max, GFP_KERNEL); |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 413 | if (buf == NULL) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 414 | return -ENOMEM; |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 415 | |
Luis R. Rodriguez | c755ad3 | 2009-12-07 12:38:41 -0500 | [diff] [blame] | 416 | len += sprintf(buf, "%6s %6s %6s " |
| 417 | "%10s %10s %10s %10s\n", |
| 418 | "HT", "MCS", "Rate", |
| 419 | "Success", "Retries", "XRetries", "PER"); |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 420 | |
| 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]; |
Luis R. Rodriguez | c755ad3 | 2009-12-07 12:38:41 -0500 | [diff] [blame] | 424 | char mcs[5]; |
| 425 | char htmode[5]; |
| 426 | int used_mcs = 0, used_htmode = 0; |
| 427 | |
| 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); |
| 431 | |
| 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"); |
| 436 | else |
| 437 | used_htmode = snprintf(htmode, 5, "????"); |
| 438 | } |
| 439 | |
| 440 | mcs[used_mcs] = '\0'; |
| 441 | htmode[used_htmode] = '\0'; |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 442 | |
| 443 | len += snprintf(buf + len, max - len, |
Luis R. Rodriguez | c755ad3 | 2009-12-07 12:38:41 -0500 | [diff] [blame] | 444 | "%6s %6s %3u.%d: " |
| 445 | "%10u %10u %10u %10u\n", |
| 446 | htmode, |
| 447 | mcs, |
| 448 | ratekbps / 1000, |
| 449 | (ratekbps % 1000) / 100, |
| 450 | stats->success, |
| 451 | stats->retries, |
| 452 | stats->xretries, |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 453 | stats->per); |
| 454 | } |
| 455 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 456 | if (len > max) |
| 457 | len = max; |
| 458 | |
Jeff Hansen | bedf087 | 2009-05-27 12:48:28 +0000 | [diff] [blame] | 459 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 460 | kfree(buf); |
| 461 | return retval; |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | static const struct file_operations fops_rcstat = { |
| 465 | .read = read_file_rcstat, |
| 466 | .open = ath9k_debugfs_open, |
| 467 | .owner = THIS_MODULE |
| 468 | }; |
Alina Friedrichsen | 27abe06 | 2009-01-23 05:44:21 +0100 | [diff] [blame] | 469 | |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 470 | static const char * ath_wiphy_state_str(enum ath_wiphy_state state) |
| 471 | { |
| 472 | switch (state) { |
| 473 | case ATH_WIPHY_INACTIVE: |
| 474 | return "INACTIVE"; |
| 475 | case ATH_WIPHY_ACTIVE: |
| 476 | return "ACTIVE"; |
| 477 | case ATH_WIPHY_PAUSING: |
| 478 | return "PAUSING"; |
| 479 | case ATH_WIPHY_PAUSED: |
| 480 | return "PAUSED"; |
| 481 | case ATH_WIPHY_SCAN: |
| 482 | return "SCAN"; |
| 483 | } |
| 484 | return "?"; |
| 485 | } |
| 486 | |
| 487 | static ssize_t read_file_wiphy(struct file *file, char __user *user_buf, |
| 488 | size_t count, loff_t *ppos) |
| 489 | { |
| 490 | struct ath_softc *sc = file->private_data; |
Mohammed Shafi Shajakhan | 8e0167a | 2010-10-01 15:25:05 +0530 | [diff] [blame] | 491 | struct ath_wiphy *aphy = sc->pri_wiphy; |
| 492 | struct ieee80211_channel *chan = aphy->hw->conf.channel; |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 493 | char buf[512]; |
| 494 | unsigned int len = 0; |
| 495 | int i; |
| 496 | u8 addr[ETH_ALEN]; |
Ben Greear | 3905751 | 2010-09-14 12:46:04 -0700 | [diff] [blame] | 497 | u32 tmp; |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 498 | |
| 499 | len += snprintf(buf + len, sizeof(buf) - len, |
| 500 | "primary: %s (%s chan=%d ht=%d)\n", |
| 501 | wiphy_name(sc->pri_wiphy->hw->wiphy), |
| 502 | ath_wiphy_state_str(sc->pri_wiphy->state), |
Mohammed Shafi Shajakhan | 8e0167a | 2010-10-01 15:25:05 +0530 | [diff] [blame] | 503 | ieee80211_frequency_to_channel(chan->center_freq), |
| 504 | aphy->chan_is_ht); |
Ben Greear | 3905751 | 2010-09-14 12:46:04 -0700 | [diff] [blame] | 505 | |
| 506 | put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr); |
| 507 | put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4); |
| 508 | len += snprintf(buf + len, sizeof(buf) - len, |
| 509 | "addr: %pM\n", addr); |
| 510 | put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr); |
| 511 | put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4); |
| 512 | len += snprintf(buf + len, sizeof(buf) - len, |
| 513 | "addrmask: %pM\n", addr); |
| 514 | tmp = ath9k_hw_getrxfilter(sc->sc_ah); |
| 515 | len += snprintf(buf + len, sizeof(buf) - len, |
| 516 | "rfilt: 0x%x", tmp); |
| 517 | if (tmp & ATH9K_RX_FILTER_UCAST) |
| 518 | len += snprintf(buf + len, sizeof(buf) - len, " UCAST"); |
| 519 | if (tmp & ATH9K_RX_FILTER_MCAST) |
| 520 | len += snprintf(buf + len, sizeof(buf) - len, " MCAST"); |
| 521 | if (tmp & ATH9K_RX_FILTER_BCAST) |
| 522 | len += snprintf(buf + len, sizeof(buf) - len, " BCAST"); |
| 523 | if (tmp & ATH9K_RX_FILTER_CONTROL) |
| 524 | len += snprintf(buf + len, sizeof(buf) - len, " CONTROL"); |
| 525 | if (tmp & ATH9K_RX_FILTER_BEACON) |
| 526 | len += snprintf(buf + len, sizeof(buf) - len, " BEACON"); |
| 527 | if (tmp & ATH9K_RX_FILTER_PROM) |
| 528 | len += snprintf(buf + len, sizeof(buf) - len, " PROM"); |
| 529 | if (tmp & ATH9K_RX_FILTER_PROBEREQ) |
| 530 | len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ"); |
| 531 | if (tmp & ATH9K_RX_FILTER_PHYERR) |
| 532 | len += snprintf(buf + len, sizeof(buf) - len, " PHYERR"); |
| 533 | if (tmp & ATH9K_RX_FILTER_MYBEACON) |
| 534 | len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON"); |
| 535 | if (tmp & ATH9K_RX_FILTER_COMP_BAR) |
| 536 | len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR"); |
| 537 | if (tmp & ATH9K_RX_FILTER_PSPOLL) |
| 538 | len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL"); |
| 539 | if (tmp & ATH9K_RX_FILTER_PHYRADAR) |
| 540 | len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR"); |
| 541 | if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL) |
| 542 | len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n"); |
| 543 | else |
| 544 | len += snprintf(buf + len, sizeof(buf) - len, "\n"); |
| 545 | |
| 546 | /* Put variable-length stuff down here, and check for overflows. */ |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 547 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 548 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 549 | if (aphy == NULL) |
| 550 | continue; |
Mohammed Shafi Shajakhan | 8e0167a | 2010-10-01 15:25:05 +0530 | [diff] [blame] | 551 | chan = aphy->hw->conf.channel; |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 552 | len += snprintf(buf + len, sizeof(buf) - len, |
Mohammed Shafi Shajakhan | 8e0167a | 2010-10-01 15:25:05 +0530 | [diff] [blame] | 553 | "secondary: %s (%s chan=%d ht=%d)\n", |
| 554 | wiphy_name(aphy->hw->wiphy), |
| 555 | ath_wiphy_state_str(aphy->state), |
| 556 | ieee80211_frequency_to_channel(chan->center_freq), |
| 557 | aphy->chan_is_ht); |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 558 | } |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 559 | if (len > sizeof(buf)) |
| 560 | len = sizeof(buf); |
| 561 | |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 562 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 563 | } |
| 564 | |
| 565 | static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name) |
| 566 | { |
| 567 | int i; |
| 568 | if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0) |
| 569 | return sc->pri_wiphy; |
| 570 | for (i = 0; i < sc->num_sec_wiphy; i++) { |
| 571 | struct ath_wiphy *aphy = sc->sec_wiphy[i]; |
| 572 | if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0) |
| 573 | return aphy; |
| 574 | } |
| 575 | return NULL; |
| 576 | } |
| 577 | |
| 578 | static int del_wiphy(struct ath_softc *sc, const char *name) |
| 579 | { |
| 580 | struct ath_wiphy *aphy = get_wiphy(sc, name); |
| 581 | if (!aphy) |
| 582 | return -ENOENT; |
| 583 | return ath9k_wiphy_del(aphy); |
| 584 | } |
| 585 | |
| 586 | static int pause_wiphy(struct ath_softc *sc, const char *name) |
| 587 | { |
| 588 | struct ath_wiphy *aphy = get_wiphy(sc, name); |
| 589 | if (!aphy) |
| 590 | return -ENOENT; |
| 591 | return ath9k_wiphy_pause(aphy); |
| 592 | } |
| 593 | |
| 594 | static int unpause_wiphy(struct ath_softc *sc, const char *name) |
| 595 | { |
| 596 | struct ath_wiphy *aphy = get_wiphy(sc, name); |
| 597 | if (!aphy) |
| 598 | return -ENOENT; |
| 599 | return ath9k_wiphy_unpause(aphy); |
| 600 | } |
| 601 | |
| 602 | static int select_wiphy(struct ath_softc *sc, const char *name) |
| 603 | { |
| 604 | struct ath_wiphy *aphy = get_wiphy(sc, name); |
| 605 | if (!aphy) |
| 606 | return -ENOENT; |
| 607 | return ath9k_wiphy_select(aphy); |
| 608 | } |
| 609 | |
| 610 | static int schedule_wiphy(struct ath_softc *sc, const char *msec) |
| 611 | { |
| 612 | ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0)); |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf, |
| 617 | size_t count, loff_t *ppos) |
| 618 | { |
| 619 | struct ath_softc *sc = file->private_data; |
| 620 | char buf[50]; |
| 621 | size_t len; |
| 622 | |
| 623 | len = min(count, sizeof(buf) - 1); |
| 624 | if (copy_from_user(buf, user_buf, len)) |
| 625 | return -EFAULT; |
| 626 | buf[len] = '\0'; |
| 627 | if (len > 0 && buf[len - 1] == '\n') |
| 628 | buf[len - 1] = '\0'; |
| 629 | |
| 630 | if (strncmp(buf, "add", 3) == 0) { |
| 631 | int res = ath9k_wiphy_add(sc); |
| 632 | if (res < 0) |
| 633 | return res; |
| 634 | } else if (strncmp(buf, "del=", 4) == 0) { |
| 635 | int res = del_wiphy(sc, buf + 4); |
| 636 | if (res < 0) |
| 637 | return res; |
| 638 | } else if (strncmp(buf, "pause=", 6) == 0) { |
| 639 | int res = pause_wiphy(sc, buf + 6); |
| 640 | if (res < 0) |
| 641 | return res; |
| 642 | } else if (strncmp(buf, "unpause=", 8) == 0) { |
| 643 | int res = unpause_wiphy(sc, buf + 8); |
| 644 | if (res < 0) |
| 645 | return res; |
| 646 | } else if (strncmp(buf, "select=", 7) == 0) { |
| 647 | int res = select_wiphy(sc, buf + 7); |
| 648 | if (res < 0) |
| 649 | return res; |
| 650 | } else if (strncmp(buf, "schedule=", 9) == 0) { |
| 651 | int res = schedule_wiphy(sc, buf + 9); |
| 652 | if (res < 0) |
| 653 | return res; |
| 654 | } else |
| 655 | return -EOPNOTSUPP; |
| 656 | |
| 657 | return count; |
| 658 | } |
| 659 | |
| 660 | static const struct file_operations fops_wiphy = { |
| 661 | .read = read_file_wiphy, |
| 662 | .write = write_file_wiphy, |
| 663 | .open = ath9k_debugfs_open, |
| 664 | .owner = THIS_MODULE |
| 665 | }; |
| 666 | |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 667 | #define PR(str, elem) \ |
| 668 | do { \ |
| 669 | len += snprintf(buf + len, size - len, \ |
| 670 | "%s%13u%11u%10u%10u\n", str, \ |
Felix Fietkau | 1d2231e | 2010-06-12 00:33:51 -0400 | [diff] [blame] | 671 | sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BE]].elem, \ |
| 672 | sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_BK]].elem, \ |
| 673 | sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VI]].elem, \ |
| 674 | sc->debug.stats.txstats[sc->tx.hwq_map[WME_AC_VO]].elem); \ |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 675 | } while(0) |
| 676 | |
| 677 | static ssize_t read_file_xmit(struct file *file, char __user *user_buf, |
| 678 | size_t count, loff_t *ppos) |
| 679 | { |
| 680 | struct ath_softc *sc = file->private_data; |
| 681 | char *buf; |
| 682 | unsigned int len = 0, size = 2048; |
| 683 | ssize_t retval = 0; |
| 684 | |
| 685 | buf = kzalloc(size, GFP_KERNEL); |
| 686 | if (buf == NULL) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 687 | return -ENOMEM; |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 688 | |
| 689 | len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO"); |
| 690 | |
| 691 | PR("MPDUs Queued: ", queued); |
| 692 | PR("MPDUs Completed: ", completed); |
| 693 | PR("Aggregates: ", a_aggr); |
| 694 | PR("AMPDUs Queued: ", a_queued); |
| 695 | PR("AMPDUs Completed:", a_completed); |
| 696 | PR("AMPDUs Retried: ", a_retries); |
| 697 | PR("AMPDUs XRetried: ", a_xretries); |
| 698 | PR("FIFO Underrun: ", fifo_underrun); |
| 699 | PR("TXOP Exceeded: ", xtxop); |
| 700 | PR("TXTIMER Expiry: ", timer_exp); |
| 701 | PR("DESC CFG Error: ", desc_cfg_err); |
| 702 | PR("DATA Underrun: ", data_underrun); |
| 703 | PR("DELIM Underrun: ", delim_underrun); |
Ben Greear | 99c15bf | 2010-10-01 12:26:30 -0700 | [diff] [blame^] | 704 | PR("TX-Pkts-All: ", tx_pkts_all); |
| 705 | PR("TX-Bytes-All: ", tx_bytes_all); |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 706 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 707 | if (len > size) |
| 708 | len = size; |
| 709 | |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 710 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 711 | kfree(buf); |
| 712 | |
| 713 | return retval; |
| 714 | } |
| 715 | |
| 716 | void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq, |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 717 | struct ath_buf *bf, struct ath_tx_status *ts) |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 718 | { |
Ben Greear | 99c15bf | 2010-10-01 12:26:30 -0700 | [diff] [blame^] | 719 | TX_STAT_INC(txq->axq_qnum, tx_pkts_all); |
| 720 | sc->debug.stats.txstats[txq->axq_qnum].tx_bytes_all += bf->bf_mpdu->len; |
| 721 | |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 722 | if (bf_isampdu(bf)) { |
| 723 | if (bf_isxretried(bf)) |
| 724 | TX_STAT_INC(txq->axq_qnum, a_xretries); |
| 725 | else |
| 726 | TX_STAT_INC(txq->axq_qnum, a_completed); |
| 727 | } else { |
| 728 | TX_STAT_INC(txq->axq_qnum, completed); |
| 729 | } |
| 730 | |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 731 | if (ts->ts_status & ATH9K_TXERR_FIFO) |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 732 | TX_STAT_INC(txq->axq_qnum, fifo_underrun); |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 733 | if (ts->ts_status & ATH9K_TXERR_XTXOP) |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 734 | TX_STAT_INC(txq->axq_qnum, xtxop); |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 735 | if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED) |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 736 | TX_STAT_INC(txq->axq_qnum, timer_exp); |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 737 | if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR) |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 738 | TX_STAT_INC(txq->axq_qnum, desc_cfg_err); |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 739 | if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN) |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 740 | TX_STAT_INC(txq->axq_qnum, data_underrun); |
Felix Fietkau | db1a052 | 2010-03-29 20:07:11 -0700 | [diff] [blame] | 741 | if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN) |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 742 | TX_STAT_INC(txq->axq_qnum, delim_underrun); |
| 743 | } |
| 744 | |
| 745 | static const struct file_operations fops_xmit = { |
| 746 | .read = read_file_xmit, |
| 747 | .open = ath9k_debugfs_open, |
| 748 | .owner = THIS_MODULE |
| 749 | }; |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 750 | |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 751 | static ssize_t read_file_recv(struct file *file, char __user *user_buf, |
| 752 | size_t count, loff_t *ppos) |
| 753 | { |
| 754 | #define PHY_ERR(s, p) \ |
| 755 | len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \ |
| 756 | sc->debug.stats.rxstats.phy_err_stats[p]); |
| 757 | |
| 758 | struct ath_softc *sc = file->private_data; |
| 759 | char *buf; |
| 760 | unsigned int len = 0, size = 1152; |
| 761 | ssize_t retval = 0; |
| 762 | |
| 763 | buf = kzalloc(size, GFP_KERNEL); |
| 764 | if (buf == NULL) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 765 | return -ENOMEM; |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 766 | |
| 767 | len += snprintf(buf + len, size - len, |
| 768 | "%18s : %10u\n", "CRC ERR", |
| 769 | sc->debug.stats.rxstats.crc_err); |
| 770 | len += snprintf(buf + len, size - len, |
| 771 | "%18s : %10u\n", "DECRYPT CRC ERR", |
| 772 | sc->debug.stats.rxstats.decrypt_crc_err); |
| 773 | len += snprintf(buf + len, size - len, |
| 774 | "%18s : %10u\n", "PHY ERR", |
| 775 | sc->debug.stats.rxstats.phy_err); |
| 776 | len += snprintf(buf + len, size - len, |
| 777 | "%18s : %10u\n", "MIC ERR", |
| 778 | sc->debug.stats.rxstats.mic_err); |
| 779 | len += snprintf(buf + len, size - len, |
| 780 | "%18s : %10u\n", "PRE-DELIM CRC ERR", |
| 781 | sc->debug.stats.rxstats.pre_delim_crc_err); |
| 782 | len += snprintf(buf + len, size - len, |
| 783 | "%18s : %10u\n", "POST-DELIM CRC ERR", |
| 784 | sc->debug.stats.rxstats.post_delim_crc_err); |
| 785 | len += snprintf(buf + len, size - len, |
| 786 | "%18s : %10u\n", "DECRYPT BUSY ERR", |
| 787 | sc->debug.stats.rxstats.decrypt_busy_err); |
| 788 | |
| 789 | PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN); |
| 790 | PHY_ERR("TIMING", ATH9K_PHYERR_TIMING); |
| 791 | PHY_ERR("PARITY", ATH9K_PHYERR_PARITY); |
| 792 | PHY_ERR("RATE", ATH9K_PHYERR_RATE); |
| 793 | PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH); |
| 794 | PHY_ERR("RADAR", ATH9K_PHYERR_RADAR); |
| 795 | PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE); |
| 796 | PHY_ERR("TOR", ATH9K_PHYERR_TOR); |
| 797 | PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING); |
| 798 | PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY); |
| 799 | PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL); |
| 800 | PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL); |
| 801 | PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP); |
| 802 | PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE); |
| 803 | PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART); |
| 804 | PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT); |
| 805 | PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING); |
| 806 | PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC); |
| 807 | PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL); |
| 808 | PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE); |
| 809 | PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART); |
| 810 | PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL); |
| 811 | PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP); |
| 812 | PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR); |
| 813 | PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL); |
| 814 | PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL); |
| 815 | |
Ben Greear | 99c15bf | 2010-10-01 12:26:30 -0700 | [diff] [blame^] | 816 | len += snprintf(buf + len, size - len, |
| 817 | "%18s : %10u\n", "RX-Pkts-All", |
| 818 | sc->debug.stats.rxstats.rx_pkts_all); |
| 819 | len += snprintf(buf + len, size - len, |
| 820 | "%18s : %10u\n", "RX-Bytes-All", |
| 821 | sc->debug.stats.rxstats.rx_bytes_all); |
| 822 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 823 | if (len > size) |
| 824 | len = size; |
| 825 | |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 826 | retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 827 | kfree(buf); |
| 828 | |
| 829 | return retval; |
| 830 | |
| 831 | #undef PHY_ERR |
| 832 | } |
| 833 | |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 834 | void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs) |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 835 | { |
| 836 | #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++ |
| 837 | #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++ |
| 838 | |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 839 | u32 phyerr; |
| 840 | |
Ben Greear | 99c15bf | 2010-10-01 12:26:30 -0700 | [diff] [blame^] | 841 | RX_STAT_INC(rx_pkts_all); |
| 842 | sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen; |
| 843 | |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 844 | if (rs->rs_status & ATH9K_RXERR_CRC) |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 845 | RX_STAT_INC(crc_err); |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 846 | if (rs->rs_status & ATH9K_RXERR_DECRYPT) |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 847 | RX_STAT_INC(decrypt_crc_err); |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 848 | if (rs->rs_status & ATH9K_RXERR_MIC) |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 849 | RX_STAT_INC(mic_err); |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 850 | if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE) |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 851 | RX_STAT_INC(pre_delim_crc_err); |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 852 | if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST) |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 853 | RX_STAT_INC(post_delim_crc_err); |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 854 | if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY) |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 855 | RX_STAT_INC(decrypt_busy_err); |
| 856 | |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 857 | if (rs->rs_status & ATH9K_RXERR_PHY) { |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 858 | RX_STAT_INC(phy_err); |
Felix Fietkau | 8e6f5aa | 2010-03-29 20:09:27 -0700 | [diff] [blame] | 859 | phyerr = rs->rs_phyerr & 0x24; |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 860 | RX_PHY_ERR_INC(phyerr); |
| 861 | } |
| 862 | |
| 863 | #undef RX_STAT_INC |
| 864 | #undef RX_PHY_ERR_INC |
| 865 | } |
| 866 | |
| 867 | static const struct file_operations fops_recv = { |
| 868 | .read = read_file_recv, |
| 869 | .open = ath9k_debugfs_open, |
| 870 | .owner = THIS_MODULE |
| 871 | }; |
| 872 | |
Felix Fietkau | 9bff0bc | 2010-05-11 17:23:02 +0200 | [diff] [blame] | 873 | static ssize_t read_file_regidx(struct file *file, char __user *user_buf, |
| 874 | size_t count, loff_t *ppos) |
| 875 | { |
| 876 | struct ath_softc *sc = file->private_data; |
| 877 | char buf[32]; |
| 878 | unsigned int len; |
| 879 | |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 880 | len = sprintf(buf, "0x%08x\n", sc->debug.regidx); |
Felix Fietkau | 9bff0bc | 2010-05-11 17:23:02 +0200 | [diff] [blame] | 881 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 882 | } |
| 883 | |
| 884 | static ssize_t write_file_regidx(struct file *file, const char __user *user_buf, |
| 885 | size_t count, loff_t *ppos) |
| 886 | { |
| 887 | struct ath_softc *sc = file->private_data; |
| 888 | unsigned long regidx; |
| 889 | char buf[32]; |
| 890 | ssize_t len; |
| 891 | |
| 892 | len = min(count, sizeof(buf) - 1); |
| 893 | if (copy_from_user(buf, user_buf, len)) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 894 | return -EFAULT; |
Felix Fietkau | 9bff0bc | 2010-05-11 17:23:02 +0200 | [diff] [blame] | 895 | |
| 896 | buf[len] = '\0'; |
| 897 | if (strict_strtoul(buf, 0, ®idx)) |
| 898 | return -EINVAL; |
| 899 | |
| 900 | sc->debug.regidx = regidx; |
| 901 | return count; |
| 902 | } |
| 903 | |
| 904 | static const struct file_operations fops_regidx = { |
| 905 | .read = read_file_regidx, |
| 906 | .write = write_file_regidx, |
| 907 | .open = ath9k_debugfs_open, |
| 908 | .owner = THIS_MODULE |
| 909 | }; |
| 910 | |
| 911 | static ssize_t read_file_regval(struct file *file, char __user *user_buf, |
| 912 | size_t count, loff_t *ppos) |
| 913 | { |
| 914 | struct ath_softc *sc = file->private_data; |
| 915 | struct ath_hw *ah = sc->sc_ah; |
| 916 | char buf[32]; |
| 917 | unsigned int len; |
| 918 | u32 regval; |
| 919 | |
| 920 | regval = REG_READ_D(ah, sc->debug.regidx); |
Dan Carpenter | 2b87f3a | 2010-05-14 15:24:37 +0200 | [diff] [blame] | 921 | len = sprintf(buf, "0x%08x\n", regval); |
Felix Fietkau | 9bff0bc | 2010-05-11 17:23:02 +0200 | [diff] [blame] | 922 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| 923 | } |
| 924 | |
| 925 | static ssize_t write_file_regval(struct file *file, const char __user *user_buf, |
| 926 | size_t count, loff_t *ppos) |
| 927 | { |
| 928 | struct ath_softc *sc = file->private_data; |
| 929 | struct ath_hw *ah = sc->sc_ah; |
| 930 | unsigned long regval; |
| 931 | char buf[32]; |
| 932 | ssize_t len; |
| 933 | |
| 934 | len = min(count, sizeof(buf) - 1); |
| 935 | if (copy_from_user(buf, user_buf, len)) |
Dan Carpenter | 0423606 | 2010-05-14 15:25:39 +0200 | [diff] [blame] | 936 | return -EFAULT; |
Felix Fietkau | 9bff0bc | 2010-05-11 17:23:02 +0200 | [diff] [blame] | 937 | |
| 938 | buf[len] = '\0'; |
| 939 | if (strict_strtoul(buf, 0, ®val)) |
| 940 | return -EINVAL; |
| 941 | |
| 942 | REG_WRITE_D(ah, sc->debug.regidx, regval); |
| 943 | return count; |
| 944 | } |
| 945 | |
| 946 | static const struct file_operations fops_regval = { |
| 947 | .read = read_file_regval, |
| 948 | .write = write_file_regval, |
| 949 | .open = ath9k_debugfs_open, |
| 950 | .owner = THIS_MODULE |
| 951 | }; |
| 952 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 953 | int ath9k_init_debug(struct ath_hw *ah) |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 954 | { |
Luis R. Rodriguez | bc974f4 | 2009-09-28 02:54:40 -0400 | [diff] [blame] | 955 | struct ath_common *common = ath9k_hw_common(ah); |
| 956 | struct ath_softc *sc = (struct ath_softc *) common->priv; |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 957 | |
Sujith | 7dd5874 | 2009-03-30 15:28:42 +0530 | [diff] [blame] | 958 | if (!ath9k_debugfs_root) |
| 959 | return -ENOENT; |
| 960 | |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 961 | sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy), |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 962 | ath9k_debugfs_root); |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 963 | if (!sc->debug.debugfs_phy) |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 964 | return -ENOMEM; |
Sujith | 826d268 | 2008-11-28 22:20:23 +0530 | [diff] [blame] | 965 | |
Felix Fietkau | a830df0 | 2009-11-23 22:33:27 +0100 | [diff] [blame] | 966 | #ifdef CONFIG_ATH_DEBUG |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 967 | if (!debugfs_create_file("debug", S_IRUSR | S_IWUSR, |
| 968 | sc->debug.debugfs_phy, sc, &fops_debug)) |
Jeff Hansen | 2493928 | 2009-05-27 12:48:29 +0000 | [diff] [blame] | 969 | goto err; |
Felix Fietkau | a830df0 | 2009-11-23 22:33:27 +0100 | [diff] [blame] | 970 | #endif |
Jeff Hansen | 2493928 | 2009-05-27 12:48:29 +0000 | [diff] [blame] | 971 | |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 972 | if (!debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, |
| 973 | sc, &fops_dma)) |
Sujith | 2a163c6 | 2008-11-28 22:21:08 +0530 | [diff] [blame] | 974 | goto err; |
| 975 | |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 976 | if (!debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, |
| 977 | sc, &fops_interrupt)) |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 978 | goto err; |
| 979 | |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 980 | if (!debugfs_create_file("rcstat", S_IRUSR, sc->debug.debugfs_phy, |
| 981 | sc, &fops_rcstat)) |
Sujith | 7a7dec6 | 2009-01-30 14:32:09 +0530 | [diff] [blame] | 982 | goto err; |
| 983 | |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 984 | if (!debugfs_create_file("wiphy", S_IRUSR | S_IWUSR, |
| 985 | sc->debug.debugfs_phy, sc, &fops_wiphy)) |
Jouni Malinen | 39d89cd | 2009-03-03 19:23:40 +0200 | [diff] [blame] | 986 | goto err; |
| 987 | |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 988 | if (!debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, |
| 989 | sc, &fops_xmit)) |
Sujith | fec247c | 2009-07-27 12:08:16 +0530 | [diff] [blame] | 990 | goto err; |
| 991 | |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 992 | if (!debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, |
| 993 | sc, &fops_recv)) |
Sujith | 1395d3f | 2010-01-08 10:36:11 +0530 | [diff] [blame] | 994 | goto err; |
| 995 | |
Felix Fietkau | 1534069 | 2010-05-11 17:23:01 +0200 | [diff] [blame] | 996 | if (!debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR, |
| 997 | sc->debug.debugfs_phy, sc, &fops_rx_chainmask)) |
| 998 | goto err; |
| 999 | |
| 1000 | if (!debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR, |
| 1001 | sc->debug.debugfs_phy, sc, &fops_tx_chainmask)) |
| 1002 | goto err; |
| 1003 | |
Felix Fietkau | 9bff0bc | 2010-05-11 17:23:02 +0200 | [diff] [blame] | 1004 | if (!debugfs_create_file("regidx", S_IRUSR | S_IWUSR, |
| 1005 | sc->debug.debugfs_phy, sc, &fops_regidx)) |
| 1006 | goto err; |
| 1007 | |
| 1008 | if (!debugfs_create_file("regval", S_IRUSR | S_IWUSR, |
| 1009 | sc->debug.debugfs_phy, sc, &fops_regval)) |
| 1010 | goto err; |
| 1011 | |
Felix Fietkau | 41f3e54 | 2010-06-12 00:33:56 -0400 | [diff] [blame] | 1012 | if (!debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR, |
| 1013 | sc->debug.debugfs_phy, &ah->config.cwm_ignore_extcca)) |
| 1014 | goto err; |
| 1015 | |
Felix Fietkau | 9bff0bc | 2010-05-11 17:23:02 +0200 | [diff] [blame] | 1016 | sc->debug.regidx = 0; |
Sujith | 826d268 | 2008-11-28 22:20:23 +0530 | [diff] [blame] | 1017 | return 0; |
| 1018 | err: |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1019 | ath9k_exit_debug(ah); |
Sujith | 826d268 | 2008-11-28 22:20:23 +0530 | [diff] [blame] | 1020 | return -ENOMEM; |
| 1021 | } |
| 1022 | |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1023 | void ath9k_exit_debug(struct ath_hw *ah) |
Sujith | 826d268 | 2008-11-28 22:20:23 +0530 | [diff] [blame] | 1024 | { |
Luis R. Rodriguez | bc974f4 | 2009-09-28 02:54:40 -0400 | [diff] [blame] | 1025 | struct ath_common *common = ath9k_hw_common(ah); |
| 1026 | struct ath_softc *sc = (struct ath_softc *) common->priv; |
Luis R. Rodriguez | 4d6b228 | 2009-09-07 04:52:26 -0700 | [diff] [blame] | 1027 | |
Felix Fietkau | c8a72c0 | 2010-05-11 17:23:00 +0200 | [diff] [blame] | 1028 | debugfs_remove_recursive(sc->debug.debugfs_phy); |
Gabor Juhos | 19d8bc2 | 2009-03-05 16:55:18 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | int ath9k_debug_create_root(void) |
| 1032 | { |
| 1033 | ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL); |
| 1034 | if (!ath9k_debugfs_root) |
| 1035 | return -ENOENT; |
| 1036 | |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | void ath9k_debug_remove_root(void) |
| 1041 | { |
| 1042 | debugfs_remove(ath9k_debugfs_root); |
| 1043 | ath9k_debugfs_root = NULL; |
Sujith | 88b126a | 2008-11-28 22:19:02 +0530 | [diff] [blame] | 1044 | } |