1203c4805SLuis R. Rodriguez /* 2203c4805SLuis R. Rodriguez * Copyright (c) 2008-2009 Atheros Communications Inc. 3203c4805SLuis R. Rodriguez * 4203c4805SLuis R. Rodriguez * Permission to use, copy, modify, and/or distribute this software for any 5203c4805SLuis R. Rodriguez * purpose with or without fee is hereby granted, provided that the above 6203c4805SLuis R. Rodriguez * copyright notice and this permission notice appear in all copies. 7203c4805SLuis R. Rodriguez * 8203c4805SLuis R. Rodriguez * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9203c4805SLuis R. Rodriguez * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10203c4805SLuis R. Rodriguez * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11203c4805SLuis R. Rodriguez * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12203c4805SLuis R. Rodriguez * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13203c4805SLuis R. Rodriguez * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14203c4805SLuis R. Rodriguez * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15203c4805SLuis R. Rodriguez */ 16203c4805SLuis R. Rodriguez 17203c4805SLuis R. Rodriguez #include <asm/unaligned.h> 18203c4805SLuis R. Rodriguez 19203c4805SLuis R. Rodriguez #include "ath9k.h" 20203c4805SLuis R. Rodriguez 21475a6e4dSLuis R. Rodriguez #define REG_WRITE_D(_ah, _reg, _val) \ 22475a6e4dSLuis R. Rodriguez ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg)) 23475a6e4dSLuis R. Rodriguez #define REG_READ_D(_ah, _reg) \ 24475a6e4dSLuis R. Rodriguez ath9k_hw_common(_ah)->ops->read((_ah), (_reg)) 25475a6e4dSLuis R. Rodriguez 26203c4805SLuis R. Rodriguez static struct dentry *ath9k_debugfs_root; 27203c4805SLuis R. Rodriguez 28203c4805SLuis R. Rodriguez static int ath9k_debugfs_open(struct inode *inode, struct file *file) 29203c4805SLuis R. Rodriguez { 30203c4805SLuis R. Rodriguez file->private_data = inode->i_private; 31203c4805SLuis R. Rodriguez return 0; 32203c4805SLuis R. Rodriguez } 33203c4805SLuis R. Rodriguez 34a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG 35a830df07SFelix Fietkau 362493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf, 372493928eSJeff Hansen size_t count, loff_t *ppos) 382493928eSJeff Hansen { 392493928eSJeff Hansen struct ath_softc *sc = file->private_data; 40c46917bbSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(sc->sc_ah); 412493928eSJeff Hansen char buf[32]; 42581f725cSVasanthakumar Thiagarajan unsigned int len; 43581f725cSVasanthakumar Thiagarajan 44c46917bbSLuis R. Rodriguez len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask); 452493928eSJeff Hansen return simple_read_from_buffer(user_buf, count, ppos, buf, len); 462493928eSJeff Hansen } 472493928eSJeff Hansen 482493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf, 492493928eSJeff Hansen size_t count, loff_t *ppos) 502493928eSJeff Hansen { 512493928eSJeff Hansen struct ath_softc *sc = file->private_data; 52c46917bbSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(sc->sc_ah); 532493928eSJeff Hansen unsigned long mask; 542493928eSJeff Hansen char buf[32]; 55581f725cSVasanthakumar Thiagarajan ssize_t len; 56581f725cSVasanthakumar Thiagarajan 57581f725cSVasanthakumar Thiagarajan len = min(count, sizeof(buf) - 1); 58581f725cSVasanthakumar Thiagarajan if (copy_from_user(buf, user_buf, len)) 59581f725cSVasanthakumar Thiagarajan return -EINVAL; 60581f725cSVasanthakumar Thiagarajan 61581f725cSVasanthakumar Thiagarajan buf[len] = '\0'; 62581f725cSVasanthakumar Thiagarajan if (strict_strtoul(buf, 0, &mask)) 63581f725cSVasanthakumar Thiagarajan return -EINVAL; 64581f725cSVasanthakumar Thiagarajan 65c46917bbSLuis R. Rodriguez common->debug_mask = mask; 662493928eSJeff Hansen return count; 672493928eSJeff Hansen } 682493928eSJeff Hansen 692493928eSJeff Hansen static const struct file_operations fops_debug = { 702493928eSJeff Hansen .read = read_file_debug, 712493928eSJeff Hansen .write = write_file_debug, 722493928eSJeff Hansen .open = ath9k_debugfs_open, 732493928eSJeff Hansen .owner = THIS_MODULE 742493928eSJeff Hansen }; 752493928eSJeff Hansen 76a830df07SFelix Fietkau #endif 77a830df07SFelix Fietkau 78203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf, 79203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 80203c4805SLuis R. Rodriguez { 81203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 82203c4805SLuis R. Rodriguez struct ath_hw *ah = sc->sc_ah; 83203c4805SLuis R. Rodriguez char buf[1024]; 84203c4805SLuis R. Rodriguez unsigned int len = 0; 85203c4805SLuis R. Rodriguez u32 val[ATH9K_NUM_DMA_DEBUG_REGS]; 86203c4805SLuis R. Rodriguez int i, qcuOffset = 0, dcuOffset = 0; 87203c4805SLuis R. Rodriguez u32 *qcuBase = &val[0], *dcuBase = &val[4]; 88203c4805SLuis R. Rodriguez 897cf4a2e7SSujith ath9k_ps_wakeup(sc); 907cf4a2e7SSujith 91475a6e4dSLuis R. Rodriguez REG_WRITE_D(ah, AR_MACMISC, 92203c4805SLuis R. Rodriguez ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | 93203c4805SLuis R. Rodriguez (AR_MACMISC_MISC_OBS_BUS_1 << 94203c4805SLuis R. Rodriguez AR_MACMISC_MISC_OBS_BUS_MSB_S))); 95203c4805SLuis R. Rodriguez 96203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 97203c4805SLuis R. Rodriguez "Raw DMA Debug values:\n"); 98203c4805SLuis R. Rodriguez 99203c4805SLuis R. Rodriguez for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { 100203c4805SLuis R. Rodriguez if (i % 4 == 0) 101203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "\n"); 102203c4805SLuis R. Rodriguez 103475a6e4dSLuis R. Rodriguez val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32))); 104203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ", 105203c4805SLuis R. Rodriguez i, val[i]); 106203c4805SLuis R. Rodriguez } 107203c4805SLuis R. Rodriguez 108203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "\n\n"); 109203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 110203c4805SLuis R. Rodriguez "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); 111203c4805SLuis R. Rodriguez 112203c4805SLuis R. Rodriguez for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { 113203c4805SLuis R. Rodriguez if (i == 8) { 114203c4805SLuis R. Rodriguez qcuOffset = 0; 115203c4805SLuis R. Rodriguez qcuBase++; 116203c4805SLuis R. Rodriguez } 117203c4805SLuis R. Rodriguez 118203c4805SLuis R. Rodriguez if (i == 6) { 119203c4805SLuis R. Rodriguez dcuOffset = 0; 120203c4805SLuis R. Rodriguez dcuBase++; 121203c4805SLuis R. Rodriguez } 122203c4805SLuis R. Rodriguez 123203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 124203c4805SLuis R. Rodriguez "%2d %2x %1x %2x %2x\n", 125203c4805SLuis R. Rodriguez i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset, 126203c4805SLuis R. Rodriguez (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3), 127203c4805SLuis R. Rodriguez val[2] & (0x7 << (i * 3)) >> (i * 3), 128203c4805SLuis R. Rodriguez (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset); 129203c4805SLuis R. Rodriguez } 130203c4805SLuis R. Rodriguez 131203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "\n"); 132203c4805SLuis R. Rodriguez 133203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 134203c4805SLuis R. Rodriguez "qcu_stitch state: %2x qcu_fetch state: %2x\n", 135203c4805SLuis R. Rodriguez (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); 136203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 137203c4805SLuis R. Rodriguez "qcu_complete state: %2x dcu_complete state: %2x\n", 138203c4805SLuis R. Rodriguez (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); 139203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 140203c4805SLuis R. Rodriguez "dcu_arb state: %2x dcu_fp state: %2x\n", 141203c4805SLuis R. Rodriguez (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); 142203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 143203c4805SLuis R. Rodriguez "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", 144203c4805SLuis R. Rodriguez (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); 145203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 146203c4805SLuis R. Rodriguez "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", 147203c4805SLuis R. Rodriguez (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); 148203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 149203c4805SLuis R. Rodriguez "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", 150203c4805SLuis R. Rodriguez (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); 151203c4805SLuis R. Rodriguez 152203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n", 153475a6e4dSLuis R. Rodriguez REG_READ_D(ah, AR_OBS_BUS_1)); 154203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 155475a6e4dSLuis R. Rodriguez "AR_CR: 0x%x \n", REG_READ_D(ah, AR_CR)); 156203c4805SLuis R. Rodriguez 1577cf4a2e7SSujith ath9k_ps_restore(sc); 1587cf4a2e7SSujith 159203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 160203c4805SLuis R. Rodriguez } 161203c4805SLuis R. Rodriguez 162203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = { 163203c4805SLuis R. Rodriguez .read = read_file_dma, 164203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 165203c4805SLuis R. Rodriguez .owner = THIS_MODULE 166203c4805SLuis R. Rodriguez }; 167203c4805SLuis R. Rodriguez 168203c4805SLuis R. Rodriguez 169203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status) 170203c4805SLuis R. Rodriguez { 171203c4805SLuis R. Rodriguez if (status) 172203c4805SLuis R. Rodriguez sc->debug.stats.istats.total++; 173203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RX) 174203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxok++; 175203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXEOL) 176203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxeol++; 177203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXORN) 178203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxorn++; 179203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TX) 180203c4805SLuis R. Rodriguez sc->debug.stats.istats.txok++; 181203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TXURN) 182203c4805SLuis R. Rodriguez sc->debug.stats.istats.txurn++; 183203c4805SLuis R. Rodriguez if (status & ATH9K_INT_MIB) 184203c4805SLuis R. Rodriguez sc->debug.stats.istats.mib++; 185203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXPHY) 186203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxphyerr++; 187203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXKCM) 188203c4805SLuis R. Rodriguez sc->debug.stats.istats.rx_keycache_miss++; 189203c4805SLuis R. Rodriguez if (status & ATH9K_INT_SWBA) 190203c4805SLuis R. Rodriguez sc->debug.stats.istats.swba++; 191203c4805SLuis R. Rodriguez if (status & ATH9K_INT_BMISS) 192203c4805SLuis R. Rodriguez sc->debug.stats.istats.bmiss++; 193203c4805SLuis R. Rodriguez if (status & ATH9K_INT_BNR) 194203c4805SLuis R. Rodriguez sc->debug.stats.istats.bnr++; 195203c4805SLuis R. Rodriguez if (status & ATH9K_INT_CST) 196203c4805SLuis R. Rodriguez sc->debug.stats.istats.cst++; 197203c4805SLuis R. Rodriguez if (status & ATH9K_INT_GTT) 198203c4805SLuis R. Rodriguez sc->debug.stats.istats.gtt++; 199203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TIM) 200203c4805SLuis R. Rodriguez sc->debug.stats.istats.tim++; 201203c4805SLuis R. Rodriguez if (status & ATH9K_INT_CABEND) 202203c4805SLuis R. Rodriguez sc->debug.stats.istats.cabend++; 203203c4805SLuis R. Rodriguez if (status & ATH9K_INT_DTIMSYNC) 204203c4805SLuis R. Rodriguez sc->debug.stats.istats.dtimsync++; 205203c4805SLuis R. Rodriguez if (status & ATH9K_INT_DTIM) 206203c4805SLuis R. Rodriguez sc->debug.stats.istats.dtim++; 207203c4805SLuis R. Rodriguez } 208203c4805SLuis R. Rodriguez 209203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, 210203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 211203c4805SLuis R. Rodriguez { 212203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 213203c4805SLuis R. Rodriguez char buf[512]; 214203c4805SLuis R. Rodriguez unsigned int len = 0; 215203c4805SLuis R. Rodriguez 216203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 217203c4805SLuis R. Rodriguez "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok); 218203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 219203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol); 220203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 221203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn); 222203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 223203c4805SLuis R. Rodriguez "%8s: %10u\n", "TX", sc->debug.stats.istats.txok); 224203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 225203c4805SLuis R. Rodriguez "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn); 226203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 227203c4805SLuis R. Rodriguez "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib); 228203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 229203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr); 230203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 231203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss); 232203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 233203c4805SLuis R. Rodriguez "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba); 234203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 235203c4805SLuis R. Rodriguez "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss); 236203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 237203c4805SLuis R. Rodriguez "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr); 238203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 239203c4805SLuis R. Rodriguez "%8s: %10u\n", "CST", sc->debug.stats.istats.cst); 240203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 241203c4805SLuis R. Rodriguez "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt); 242203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 243203c4805SLuis R. Rodriguez "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim); 244203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 245203c4805SLuis R. Rodriguez "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend); 246203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 247203c4805SLuis R. Rodriguez "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync); 248203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 249203c4805SLuis R. Rodriguez "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim); 250203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 251203c4805SLuis R. Rodriguez "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total); 252203c4805SLuis R. Rodriguez 253203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 254203c4805SLuis R. Rodriguez } 255203c4805SLuis R. Rodriguez 256203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = { 257203c4805SLuis R. Rodriguez .read = read_file_interrupt, 258203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 259203c4805SLuis R. Rodriguez .owner = THIS_MODULE 260203c4805SLuis R. Rodriguez }; 261203c4805SLuis R. Rodriguez 262545750d3SFelix Fietkau void ath_debug_stat_rc(struct ath_softc *sc, int final_rate) 263203c4805SLuis R. Rodriguez { 264bedf087aSJeff Hansen struct ath_rc_stats *stats; 265203c4805SLuis R. Rodriguez 266545750d3SFelix Fietkau stats = &sc->debug.stats.rcstats[final_rate]; 267bedf087aSJeff Hansen stats->success++; 268203c4805SLuis R. Rodriguez } 269203c4805SLuis R. Rodriguez 270203c4805SLuis R. Rodriguez void ath_debug_stat_retries(struct ath_softc *sc, int rix, 271203c4805SLuis R. Rodriguez int xretries, int retries, u8 per) 272203c4805SLuis R. Rodriguez { 273bedf087aSJeff Hansen struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix]; 274203c4805SLuis R. Rodriguez 275bedf087aSJeff Hansen stats->xretries += xretries; 276bedf087aSJeff Hansen stats->retries += retries; 277bedf087aSJeff Hansen stats->per = per; 278203c4805SLuis R. Rodriguez } 279203c4805SLuis R. Rodriguez 280203c4805SLuis R. Rodriguez static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, 281203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 282203c4805SLuis R. Rodriguez { 283203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 284bedf087aSJeff Hansen char *buf; 285bedf087aSJeff Hansen unsigned int len = 0, max; 286bedf087aSJeff Hansen int i = 0; 287bedf087aSJeff Hansen ssize_t retval; 288203c4805SLuis R. Rodriguez 289203c4805SLuis R. Rodriguez if (sc->cur_rate_table == NULL) 290203c4805SLuis R. Rodriguez return 0; 291203c4805SLuis R. Rodriguez 292c755ad34SLuis R. Rodriguez max = 80 + sc->cur_rate_table->rate_cnt * 1024; 293bedf087aSJeff Hansen buf = kmalloc(max + 1, GFP_KERNEL); 294bedf087aSJeff Hansen if (buf == NULL) 295bedf087aSJeff Hansen return 0; 296bedf087aSJeff Hansen buf[max] = 0; 297bedf087aSJeff Hansen 298c755ad34SLuis R. Rodriguez len += sprintf(buf, "%6s %6s %6s " 299c755ad34SLuis R. Rodriguez "%10s %10s %10s %10s\n", 300c755ad34SLuis R. Rodriguez "HT", "MCS", "Rate", 301c755ad34SLuis R. Rodriguez "Success", "Retries", "XRetries", "PER"); 302bedf087aSJeff Hansen 303bedf087aSJeff Hansen for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) { 304bedf087aSJeff Hansen u32 ratekbps = sc->cur_rate_table->info[i].ratekbps; 305bedf087aSJeff Hansen struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i]; 306c755ad34SLuis R. Rodriguez char mcs[5]; 307c755ad34SLuis R. Rodriguez char htmode[5]; 308c755ad34SLuis R. Rodriguez int used_mcs = 0, used_htmode = 0; 309c755ad34SLuis R. Rodriguez 310c755ad34SLuis R. Rodriguez if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) { 311c755ad34SLuis R. Rodriguez used_mcs = snprintf(mcs, 5, "%d", 312c755ad34SLuis R. Rodriguez sc->cur_rate_table->info[i].ratecode); 313c755ad34SLuis R. Rodriguez 314c755ad34SLuis R. Rodriguez if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy)) 315c755ad34SLuis R. Rodriguez used_htmode = snprintf(htmode, 5, "HT40"); 316c755ad34SLuis R. Rodriguez else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy)) 317c755ad34SLuis R. Rodriguez used_htmode = snprintf(htmode, 5, "HT20"); 318c755ad34SLuis R. Rodriguez else 319c755ad34SLuis R. Rodriguez used_htmode = snprintf(htmode, 5, "????"); 320c755ad34SLuis R. Rodriguez } 321c755ad34SLuis R. Rodriguez 322c755ad34SLuis R. Rodriguez mcs[used_mcs] = '\0'; 323c755ad34SLuis R. Rodriguez htmode[used_htmode] = '\0'; 324bedf087aSJeff Hansen 325bedf087aSJeff Hansen len += snprintf(buf + len, max - len, 326c755ad34SLuis R. Rodriguez "%6s %6s %3u.%d: " 327c755ad34SLuis R. Rodriguez "%10u %10u %10u %10u\n", 328c755ad34SLuis R. Rodriguez htmode, 329c755ad34SLuis R. Rodriguez mcs, 330c755ad34SLuis R. Rodriguez ratekbps / 1000, 331c755ad34SLuis R. Rodriguez (ratekbps % 1000) / 100, 332c755ad34SLuis R. Rodriguez stats->success, 333c755ad34SLuis R. Rodriguez stats->retries, 334c755ad34SLuis R. Rodriguez stats->xretries, 335bedf087aSJeff Hansen stats->per); 336bedf087aSJeff Hansen } 337bedf087aSJeff Hansen 338bedf087aSJeff Hansen retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 339bedf087aSJeff Hansen kfree(buf); 340bedf087aSJeff Hansen return retval; 341203c4805SLuis R. Rodriguez } 342203c4805SLuis R. Rodriguez 343203c4805SLuis R. Rodriguez static const struct file_operations fops_rcstat = { 344203c4805SLuis R. Rodriguez .read = read_file_rcstat, 345203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 346203c4805SLuis R. Rodriguez .owner = THIS_MODULE 347203c4805SLuis R. Rodriguez }; 348203c4805SLuis R. Rodriguez 349203c4805SLuis R. Rodriguez static const char * ath_wiphy_state_str(enum ath_wiphy_state state) 350203c4805SLuis R. Rodriguez { 351203c4805SLuis R. Rodriguez switch (state) { 352203c4805SLuis R. Rodriguez case ATH_WIPHY_INACTIVE: 353203c4805SLuis R. Rodriguez return "INACTIVE"; 354203c4805SLuis R. Rodriguez case ATH_WIPHY_ACTIVE: 355203c4805SLuis R. Rodriguez return "ACTIVE"; 356203c4805SLuis R. Rodriguez case ATH_WIPHY_PAUSING: 357203c4805SLuis R. Rodriguez return "PAUSING"; 358203c4805SLuis R. Rodriguez case ATH_WIPHY_PAUSED: 359203c4805SLuis R. Rodriguez return "PAUSED"; 360203c4805SLuis R. Rodriguez case ATH_WIPHY_SCAN: 361203c4805SLuis R. Rodriguez return "SCAN"; 362203c4805SLuis R. Rodriguez } 363203c4805SLuis R. Rodriguez return "?"; 364203c4805SLuis R. Rodriguez } 365203c4805SLuis R. Rodriguez 366203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf, 367203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 368203c4805SLuis R. Rodriguez { 369203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 370203c4805SLuis R. Rodriguez char buf[512]; 371203c4805SLuis R. Rodriguez unsigned int len = 0; 372203c4805SLuis R. Rodriguez int i; 373203c4805SLuis R. Rodriguez u8 addr[ETH_ALEN]; 374203c4805SLuis R. Rodriguez 375203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 376203c4805SLuis R. Rodriguez "primary: %s (%s chan=%d ht=%d)\n", 377203c4805SLuis R. Rodriguez wiphy_name(sc->pri_wiphy->hw->wiphy), 378203c4805SLuis R. Rodriguez ath_wiphy_state_str(sc->pri_wiphy->state), 379203c4805SLuis R. Rodriguez sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht); 380203c4805SLuis R. Rodriguez for (i = 0; i < sc->num_sec_wiphy; i++) { 381203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = sc->sec_wiphy[i]; 382203c4805SLuis R. Rodriguez if (aphy == NULL) 383203c4805SLuis R. Rodriguez continue; 384203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 385203c4805SLuis R. Rodriguez "secondary: %s (%s chan=%d ht=%d)\n", 386203c4805SLuis R. Rodriguez wiphy_name(aphy->hw->wiphy), 387203c4805SLuis R. Rodriguez ath_wiphy_state_str(aphy->state), 388203c4805SLuis R. Rodriguez aphy->chan_idx, aphy->chan_is_ht); 389203c4805SLuis R. Rodriguez } 390203c4805SLuis R. Rodriguez 391475a6e4dSLuis R. Rodriguez put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr); 392475a6e4dSLuis R. Rodriguez put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4); 393203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 394203c4805SLuis R. Rodriguez "addr: %pM\n", addr); 395475a6e4dSLuis R. Rodriguez put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr); 396475a6e4dSLuis R. Rodriguez put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4); 397203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 398203c4805SLuis R. Rodriguez "addrmask: %pM\n", addr); 399203c4805SLuis R. Rodriguez 400203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 401203c4805SLuis R. Rodriguez } 402203c4805SLuis R. Rodriguez 403203c4805SLuis R. Rodriguez static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name) 404203c4805SLuis R. Rodriguez { 405203c4805SLuis R. Rodriguez int i; 406203c4805SLuis R. Rodriguez if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0) 407203c4805SLuis R. Rodriguez return sc->pri_wiphy; 408203c4805SLuis R. Rodriguez for (i = 0; i < sc->num_sec_wiphy; i++) { 409203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = sc->sec_wiphy[i]; 410203c4805SLuis R. Rodriguez if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0) 411203c4805SLuis R. Rodriguez return aphy; 412203c4805SLuis R. Rodriguez } 413203c4805SLuis R. Rodriguez return NULL; 414203c4805SLuis R. Rodriguez } 415203c4805SLuis R. Rodriguez 416203c4805SLuis R. Rodriguez static int del_wiphy(struct ath_softc *sc, const char *name) 417203c4805SLuis R. Rodriguez { 418203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 419203c4805SLuis R. Rodriguez if (!aphy) 420203c4805SLuis R. Rodriguez return -ENOENT; 421203c4805SLuis R. Rodriguez return ath9k_wiphy_del(aphy); 422203c4805SLuis R. Rodriguez } 423203c4805SLuis R. Rodriguez 424203c4805SLuis R. Rodriguez static int pause_wiphy(struct ath_softc *sc, const char *name) 425203c4805SLuis R. Rodriguez { 426203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 427203c4805SLuis R. Rodriguez if (!aphy) 428203c4805SLuis R. Rodriguez return -ENOENT; 429203c4805SLuis R. Rodriguez return ath9k_wiphy_pause(aphy); 430203c4805SLuis R. Rodriguez } 431203c4805SLuis R. Rodriguez 432203c4805SLuis R. Rodriguez static int unpause_wiphy(struct ath_softc *sc, const char *name) 433203c4805SLuis R. Rodriguez { 434203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 435203c4805SLuis R. Rodriguez if (!aphy) 436203c4805SLuis R. Rodriguez return -ENOENT; 437203c4805SLuis R. Rodriguez return ath9k_wiphy_unpause(aphy); 438203c4805SLuis R. Rodriguez } 439203c4805SLuis R. Rodriguez 440203c4805SLuis R. Rodriguez static int select_wiphy(struct ath_softc *sc, const char *name) 441203c4805SLuis R. Rodriguez { 442203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 443203c4805SLuis R. Rodriguez if (!aphy) 444203c4805SLuis R. Rodriguez return -ENOENT; 445203c4805SLuis R. Rodriguez return ath9k_wiphy_select(aphy); 446203c4805SLuis R. Rodriguez } 447203c4805SLuis R. Rodriguez 448203c4805SLuis R. Rodriguez static int schedule_wiphy(struct ath_softc *sc, const char *msec) 449203c4805SLuis R. Rodriguez { 450203c4805SLuis R. Rodriguez ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0)); 451203c4805SLuis R. Rodriguez return 0; 452203c4805SLuis R. Rodriguez } 453203c4805SLuis R. Rodriguez 454203c4805SLuis R. Rodriguez static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf, 455203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 456203c4805SLuis R. Rodriguez { 457203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 458203c4805SLuis R. Rodriguez char buf[50]; 459203c4805SLuis R. Rodriguez size_t len; 460203c4805SLuis R. Rodriguez 461203c4805SLuis R. Rodriguez len = min(count, sizeof(buf) - 1); 462203c4805SLuis R. Rodriguez if (copy_from_user(buf, user_buf, len)) 463203c4805SLuis R. Rodriguez return -EFAULT; 464203c4805SLuis R. Rodriguez buf[len] = '\0'; 465203c4805SLuis R. Rodriguez if (len > 0 && buf[len - 1] == '\n') 466203c4805SLuis R. Rodriguez buf[len - 1] = '\0'; 467203c4805SLuis R. Rodriguez 468203c4805SLuis R. Rodriguez if (strncmp(buf, "add", 3) == 0) { 469203c4805SLuis R. Rodriguez int res = ath9k_wiphy_add(sc); 470203c4805SLuis R. Rodriguez if (res < 0) 471203c4805SLuis R. Rodriguez return res; 472203c4805SLuis R. Rodriguez } else if (strncmp(buf, "del=", 4) == 0) { 473203c4805SLuis R. Rodriguez int res = del_wiphy(sc, buf + 4); 474203c4805SLuis R. Rodriguez if (res < 0) 475203c4805SLuis R. Rodriguez return res; 476203c4805SLuis R. Rodriguez } else if (strncmp(buf, "pause=", 6) == 0) { 477203c4805SLuis R. Rodriguez int res = pause_wiphy(sc, buf + 6); 478203c4805SLuis R. Rodriguez if (res < 0) 479203c4805SLuis R. Rodriguez return res; 480203c4805SLuis R. Rodriguez } else if (strncmp(buf, "unpause=", 8) == 0) { 481203c4805SLuis R. Rodriguez int res = unpause_wiphy(sc, buf + 8); 482203c4805SLuis R. Rodriguez if (res < 0) 483203c4805SLuis R. Rodriguez return res; 484203c4805SLuis R. Rodriguez } else if (strncmp(buf, "select=", 7) == 0) { 485203c4805SLuis R. Rodriguez int res = select_wiphy(sc, buf + 7); 486203c4805SLuis R. Rodriguez if (res < 0) 487203c4805SLuis R. Rodriguez return res; 488203c4805SLuis R. Rodriguez } else if (strncmp(buf, "schedule=", 9) == 0) { 489203c4805SLuis R. Rodriguez int res = schedule_wiphy(sc, buf + 9); 490203c4805SLuis R. Rodriguez if (res < 0) 491203c4805SLuis R. Rodriguez return res; 492203c4805SLuis R. Rodriguez } else 493203c4805SLuis R. Rodriguez return -EOPNOTSUPP; 494203c4805SLuis R. Rodriguez 495203c4805SLuis R. Rodriguez return count; 496203c4805SLuis R. Rodriguez } 497203c4805SLuis R. Rodriguez 498203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = { 499203c4805SLuis R. Rodriguez .read = read_file_wiphy, 500203c4805SLuis R. Rodriguez .write = write_file_wiphy, 501203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 502203c4805SLuis R. Rodriguez .owner = THIS_MODULE 503203c4805SLuis R. Rodriguez }; 504203c4805SLuis R. Rodriguez 505fec247c0SSujith #define PR(str, elem) \ 506fec247c0SSujith do { \ 507fec247c0SSujith len += snprintf(buf + len, size - len, \ 508fec247c0SSujith "%s%13u%11u%10u%10u\n", str, \ 509fec247c0SSujith sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \ 510fec247c0SSujith sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \ 511fec247c0SSujith sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \ 512fec247c0SSujith sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \ 513fec247c0SSujith } while(0) 514fec247c0SSujith 515fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf, 516fec247c0SSujith size_t count, loff_t *ppos) 517fec247c0SSujith { 518fec247c0SSujith struct ath_softc *sc = file->private_data; 519fec247c0SSujith char *buf; 520fec247c0SSujith unsigned int len = 0, size = 2048; 521fec247c0SSujith ssize_t retval = 0; 522fec247c0SSujith 523fec247c0SSujith buf = kzalloc(size, GFP_KERNEL); 524fec247c0SSujith if (buf == NULL) 525fec247c0SSujith return 0; 526fec247c0SSujith 527fec247c0SSujith len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO"); 528fec247c0SSujith 529fec247c0SSujith PR("MPDUs Queued: ", queued); 530fec247c0SSujith PR("MPDUs Completed: ", completed); 531fec247c0SSujith PR("Aggregates: ", a_aggr); 532fec247c0SSujith PR("AMPDUs Queued: ", a_queued); 533fec247c0SSujith PR("AMPDUs Completed:", a_completed); 534fec247c0SSujith PR("AMPDUs Retried: ", a_retries); 535fec247c0SSujith PR("AMPDUs XRetried: ", a_xretries); 536fec247c0SSujith PR("FIFO Underrun: ", fifo_underrun); 537fec247c0SSujith PR("TXOP Exceeded: ", xtxop); 538fec247c0SSujith PR("TXTIMER Expiry: ", timer_exp); 539fec247c0SSujith PR("DESC CFG Error: ", desc_cfg_err); 540fec247c0SSujith PR("DATA Underrun: ", data_underrun); 541fec247c0SSujith PR("DELIM Underrun: ", delim_underrun); 542fec247c0SSujith 543fec247c0SSujith retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 544fec247c0SSujith kfree(buf); 545fec247c0SSujith 546fec247c0SSujith return retval; 547fec247c0SSujith } 548fec247c0SSujith 549fec247c0SSujith void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq, 550fec247c0SSujith struct ath_buf *bf) 551fec247c0SSujith { 552fec247c0SSujith struct ath_desc *ds = bf->bf_desc; 553fec247c0SSujith 554fec247c0SSujith if (bf_isampdu(bf)) { 555fec247c0SSujith if (bf_isxretried(bf)) 556fec247c0SSujith TX_STAT_INC(txq->axq_qnum, a_xretries); 557fec247c0SSujith else 558fec247c0SSujith TX_STAT_INC(txq->axq_qnum, a_completed); 559fec247c0SSujith } else { 560fec247c0SSujith TX_STAT_INC(txq->axq_qnum, completed); 561fec247c0SSujith } 562fec247c0SSujith 563fec247c0SSujith if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO) 564fec247c0SSujith TX_STAT_INC(txq->axq_qnum, fifo_underrun); 565fec247c0SSujith if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP) 566fec247c0SSujith TX_STAT_INC(txq->axq_qnum, xtxop); 567fec247c0SSujith if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED) 568fec247c0SSujith TX_STAT_INC(txq->axq_qnum, timer_exp); 569fec247c0SSujith if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR) 570fec247c0SSujith TX_STAT_INC(txq->axq_qnum, desc_cfg_err); 571fec247c0SSujith if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN) 572fec247c0SSujith TX_STAT_INC(txq->axq_qnum, data_underrun); 573fec247c0SSujith if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN) 574fec247c0SSujith TX_STAT_INC(txq->axq_qnum, delim_underrun); 575fec247c0SSujith } 576fec247c0SSujith 577fec247c0SSujith static const struct file_operations fops_xmit = { 578fec247c0SSujith .read = read_file_xmit, 579fec247c0SSujith .open = ath9k_debugfs_open, 580fec247c0SSujith .owner = THIS_MODULE 581fec247c0SSujith }; 582203c4805SLuis R. Rodriguez 583*1395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf, 584*1395d3f0SSujith size_t count, loff_t *ppos) 585*1395d3f0SSujith { 586*1395d3f0SSujith #define PHY_ERR(s, p) \ 587*1395d3f0SSujith len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \ 588*1395d3f0SSujith sc->debug.stats.rxstats.phy_err_stats[p]); 589*1395d3f0SSujith 590*1395d3f0SSujith struct ath_softc *sc = file->private_data; 591*1395d3f0SSujith char *buf; 592*1395d3f0SSujith unsigned int len = 0, size = 1152; 593*1395d3f0SSujith ssize_t retval = 0; 594*1395d3f0SSujith 595*1395d3f0SSujith buf = kzalloc(size, GFP_KERNEL); 596*1395d3f0SSujith if (buf == NULL) 597*1395d3f0SSujith return 0; 598*1395d3f0SSujith 599*1395d3f0SSujith len += snprintf(buf + len, size - len, 600*1395d3f0SSujith "%18s : %10u\n", "CRC ERR", 601*1395d3f0SSujith sc->debug.stats.rxstats.crc_err); 602*1395d3f0SSujith len += snprintf(buf + len, size - len, 603*1395d3f0SSujith "%18s : %10u\n", "DECRYPT CRC ERR", 604*1395d3f0SSujith sc->debug.stats.rxstats.decrypt_crc_err); 605*1395d3f0SSujith len += snprintf(buf + len, size - len, 606*1395d3f0SSujith "%18s : %10u\n", "PHY ERR", 607*1395d3f0SSujith sc->debug.stats.rxstats.phy_err); 608*1395d3f0SSujith len += snprintf(buf + len, size - len, 609*1395d3f0SSujith "%18s : %10u\n", "MIC ERR", 610*1395d3f0SSujith sc->debug.stats.rxstats.mic_err); 611*1395d3f0SSujith len += snprintf(buf + len, size - len, 612*1395d3f0SSujith "%18s : %10u\n", "PRE-DELIM CRC ERR", 613*1395d3f0SSujith sc->debug.stats.rxstats.pre_delim_crc_err); 614*1395d3f0SSujith len += snprintf(buf + len, size - len, 615*1395d3f0SSujith "%18s : %10u\n", "POST-DELIM CRC ERR", 616*1395d3f0SSujith sc->debug.stats.rxstats.post_delim_crc_err); 617*1395d3f0SSujith len += snprintf(buf + len, size - len, 618*1395d3f0SSujith "%18s : %10u\n", "DECRYPT BUSY ERR", 619*1395d3f0SSujith sc->debug.stats.rxstats.decrypt_busy_err); 620*1395d3f0SSujith 621*1395d3f0SSujith PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN); 622*1395d3f0SSujith PHY_ERR("TIMING", ATH9K_PHYERR_TIMING); 623*1395d3f0SSujith PHY_ERR("PARITY", ATH9K_PHYERR_PARITY); 624*1395d3f0SSujith PHY_ERR("RATE", ATH9K_PHYERR_RATE); 625*1395d3f0SSujith PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH); 626*1395d3f0SSujith PHY_ERR("RADAR", ATH9K_PHYERR_RADAR); 627*1395d3f0SSujith PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE); 628*1395d3f0SSujith PHY_ERR("TOR", ATH9K_PHYERR_TOR); 629*1395d3f0SSujith PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING); 630*1395d3f0SSujith PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY); 631*1395d3f0SSujith PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL); 632*1395d3f0SSujith PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL); 633*1395d3f0SSujith PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP); 634*1395d3f0SSujith PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE); 635*1395d3f0SSujith PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART); 636*1395d3f0SSujith PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT); 637*1395d3f0SSujith PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING); 638*1395d3f0SSujith PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC); 639*1395d3f0SSujith PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL); 640*1395d3f0SSujith PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE); 641*1395d3f0SSujith PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART); 642*1395d3f0SSujith PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL); 643*1395d3f0SSujith PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP); 644*1395d3f0SSujith PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR); 645*1395d3f0SSujith PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL); 646*1395d3f0SSujith PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL); 647*1395d3f0SSujith 648*1395d3f0SSujith retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 649*1395d3f0SSujith kfree(buf); 650*1395d3f0SSujith 651*1395d3f0SSujith return retval; 652*1395d3f0SSujith 653*1395d3f0SSujith #undef PHY_ERR 654*1395d3f0SSujith } 655*1395d3f0SSujith 656*1395d3f0SSujith void ath_debug_stat_rx(struct ath_softc *sc, struct ath_buf *bf) 657*1395d3f0SSujith { 658*1395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++ 659*1395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++ 660*1395d3f0SSujith 661*1395d3f0SSujith struct ath_desc *ds = bf->bf_desc; 662*1395d3f0SSujith u32 phyerr; 663*1395d3f0SSujith 664*1395d3f0SSujith if (ds->ds_rxstat.rs_status & ATH9K_RXERR_CRC) 665*1395d3f0SSujith RX_STAT_INC(crc_err); 666*1395d3f0SSujith if (ds->ds_rxstat.rs_status & ATH9K_RXERR_DECRYPT) 667*1395d3f0SSujith RX_STAT_INC(decrypt_crc_err); 668*1395d3f0SSujith if (ds->ds_rxstat.rs_status & ATH9K_RXERR_MIC) 669*1395d3f0SSujith RX_STAT_INC(mic_err); 670*1395d3f0SSujith if (ds->ds_rxstat.rs_status & ATH9K_RX_DELIM_CRC_PRE) 671*1395d3f0SSujith RX_STAT_INC(pre_delim_crc_err); 672*1395d3f0SSujith if (ds->ds_rxstat.rs_status & ATH9K_RX_DELIM_CRC_POST) 673*1395d3f0SSujith RX_STAT_INC(post_delim_crc_err); 674*1395d3f0SSujith if (ds->ds_rxstat.rs_status & ATH9K_RX_DECRYPT_BUSY) 675*1395d3f0SSujith RX_STAT_INC(decrypt_busy_err); 676*1395d3f0SSujith 677*1395d3f0SSujith if (ds->ds_rxstat.rs_status & ATH9K_RXERR_PHY) { 678*1395d3f0SSujith RX_STAT_INC(phy_err); 679*1395d3f0SSujith phyerr = ds->ds_rxstat.rs_phyerr & 0x24; 680*1395d3f0SSujith RX_PHY_ERR_INC(phyerr); 681*1395d3f0SSujith } 682*1395d3f0SSujith 683*1395d3f0SSujith #undef RX_STAT_INC 684*1395d3f0SSujith #undef RX_PHY_ERR_INC 685*1395d3f0SSujith } 686*1395d3f0SSujith 687*1395d3f0SSujith static const struct file_operations fops_recv = { 688*1395d3f0SSujith .read = read_file_recv, 689*1395d3f0SSujith .open = ath9k_debugfs_open, 690*1395d3f0SSujith .owner = THIS_MODULE 691*1395d3f0SSujith }; 692*1395d3f0SSujith 6934d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah) 694203c4805SLuis R. Rodriguez { 695bc974f4aSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(ah); 696bc974f4aSLuis R. Rodriguez struct ath_softc *sc = (struct ath_softc *) common->priv; 6974d6b228dSLuis R. Rodriguez 698203c4805SLuis R. Rodriguez if (!ath9k_debugfs_root) 699203c4805SLuis R. Rodriguez return -ENOENT; 700203c4805SLuis R. Rodriguez 701203c4805SLuis R. Rodriguez sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy), 702203c4805SLuis R. Rodriguez ath9k_debugfs_root); 703203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_phy) 704203c4805SLuis R. Rodriguez goto err; 705203c4805SLuis R. Rodriguez 706a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG 7072493928eSJeff Hansen sc->debug.debugfs_debug = debugfs_create_file("debug", 7089d49e861SJiri Slaby S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug); 7092493928eSJeff Hansen if (!sc->debug.debugfs_debug) 7102493928eSJeff Hansen goto err; 711a830df07SFelix Fietkau #endif 7122493928eSJeff Hansen 7139d49e861SJiri Slaby sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR, 714203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, sc, &fops_dma); 715203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_dma) 716203c4805SLuis R. Rodriguez goto err; 717203c4805SLuis R. Rodriguez 718203c4805SLuis R. Rodriguez sc->debug.debugfs_interrupt = debugfs_create_file("interrupt", 7199d49e861SJiri Slaby S_IRUSR, 720203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, 721203c4805SLuis R. Rodriguez sc, &fops_interrupt); 722203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_interrupt) 723203c4805SLuis R. Rodriguez goto err; 724203c4805SLuis R. Rodriguez 725203c4805SLuis R. Rodriguez sc->debug.debugfs_rcstat = debugfs_create_file("rcstat", 7269d49e861SJiri Slaby S_IRUSR, 727203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, 728203c4805SLuis R. Rodriguez sc, &fops_rcstat); 729203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_rcstat) 730203c4805SLuis R. Rodriguez goto err; 731203c4805SLuis R. Rodriguez 732203c4805SLuis R. Rodriguez sc->debug.debugfs_wiphy = debugfs_create_file( 7339d49e861SJiri Slaby "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, 734203c4805SLuis R. Rodriguez &fops_wiphy); 735203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_wiphy) 736203c4805SLuis R. Rodriguez goto err; 737203c4805SLuis R. Rodriguez 738fec247c0SSujith sc->debug.debugfs_xmit = debugfs_create_file("xmit", 739fec247c0SSujith S_IRUSR, 740fec247c0SSujith sc->debug.debugfs_phy, 741fec247c0SSujith sc, &fops_xmit); 742fec247c0SSujith if (!sc->debug.debugfs_xmit) 743fec247c0SSujith goto err; 744fec247c0SSujith 745*1395d3f0SSujith sc->debug.debugfs_recv = debugfs_create_file("recv", 746*1395d3f0SSujith S_IRUSR, 747*1395d3f0SSujith sc->debug.debugfs_phy, 748*1395d3f0SSujith sc, &fops_recv); 749*1395d3f0SSujith if (!sc->debug.debugfs_recv) 750*1395d3f0SSujith goto err; 751*1395d3f0SSujith 752203c4805SLuis R. Rodriguez return 0; 753203c4805SLuis R. Rodriguez err: 7544d6b228dSLuis R. Rodriguez ath9k_exit_debug(ah); 755203c4805SLuis R. Rodriguez return -ENOMEM; 756203c4805SLuis R. Rodriguez } 757203c4805SLuis R. Rodriguez 7584d6b228dSLuis R. Rodriguez void ath9k_exit_debug(struct ath_hw *ah) 759203c4805SLuis R. Rodriguez { 760bc974f4aSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(ah); 761bc974f4aSLuis R. Rodriguez struct ath_softc *sc = (struct ath_softc *) common->priv; 7624d6b228dSLuis R. Rodriguez 763*1395d3f0SSujith debugfs_remove(sc->debug.debugfs_recv); 764fec247c0SSujith debugfs_remove(sc->debug.debugfs_xmit); 765203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_wiphy); 766203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_rcstat); 767203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_interrupt); 768203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_dma); 7692493928eSJeff Hansen debugfs_remove(sc->debug.debugfs_debug); 770203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_phy); 771203c4805SLuis R. Rodriguez } 772203c4805SLuis R. Rodriguez 773203c4805SLuis R. Rodriguez int ath9k_debug_create_root(void) 774203c4805SLuis R. Rodriguez { 775203c4805SLuis R. Rodriguez ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL); 776203c4805SLuis R. Rodriguez if (!ath9k_debugfs_root) 777203c4805SLuis R. Rodriguez return -ENOENT; 778203c4805SLuis R. Rodriguez 779203c4805SLuis R. Rodriguez return 0; 780203c4805SLuis R. Rodriguez } 781203c4805SLuis R. Rodriguez 782203c4805SLuis R. Rodriguez void ath9k_debug_remove_root(void) 783203c4805SLuis R. Rodriguez { 784203c4805SLuis R. Rodriguez debugfs_remove(ath9k_debugfs_root); 785203c4805SLuis R. Rodriguez ath9k_debugfs_root = NULL; 786203c4805SLuis R. Rodriguez } 787