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 78991a0987SPavel Roskin #define DMA_BUF_LEN 1024 79991a0987SPavel Roskin 80203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf, 81203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 82203c4805SLuis R. Rodriguez { 83203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 84203c4805SLuis R. Rodriguez struct ath_hw *ah = sc->sc_ah; 85991a0987SPavel Roskin char *buf; 86991a0987SPavel Roskin int retval; 87203c4805SLuis R. Rodriguez unsigned int len = 0; 88203c4805SLuis R. Rodriguez u32 val[ATH9K_NUM_DMA_DEBUG_REGS]; 89203c4805SLuis R. Rodriguez int i, qcuOffset = 0, dcuOffset = 0; 90203c4805SLuis R. Rodriguez u32 *qcuBase = &val[0], *dcuBase = &val[4]; 91203c4805SLuis R. Rodriguez 92991a0987SPavel Roskin buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL); 93991a0987SPavel Roskin if (!buf) 94991a0987SPavel Roskin return 0; 95991a0987SPavel Roskin 967cf4a2e7SSujith ath9k_ps_wakeup(sc); 977cf4a2e7SSujith 98475a6e4dSLuis R. Rodriguez REG_WRITE_D(ah, AR_MACMISC, 99203c4805SLuis R. Rodriguez ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | 100203c4805SLuis R. Rodriguez (AR_MACMISC_MISC_OBS_BUS_1 << 101203c4805SLuis R. Rodriguez AR_MACMISC_MISC_OBS_BUS_MSB_S))); 102203c4805SLuis R. Rodriguez 103991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 104203c4805SLuis R. Rodriguez "Raw DMA Debug values:\n"); 105203c4805SLuis R. Rodriguez 106203c4805SLuis R. Rodriguez for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { 107203c4805SLuis R. Rodriguez if (i % 4 == 0) 108991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); 109203c4805SLuis R. Rodriguez 110475a6e4dSLuis R. Rodriguez val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32))); 111991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ", 112203c4805SLuis R. Rodriguez i, val[i]); 113203c4805SLuis R. Rodriguez } 114203c4805SLuis R. Rodriguez 115991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n"); 116991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 117203c4805SLuis R. Rodriguez "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); 118203c4805SLuis R. Rodriguez 119203c4805SLuis R. Rodriguez for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { 120203c4805SLuis R. Rodriguez if (i == 8) { 121203c4805SLuis R. Rodriguez qcuOffset = 0; 122203c4805SLuis R. Rodriguez qcuBase++; 123203c4805SLuis R. Rodriguez } 124203c4805SLuis R. Rodriguez 125203c4805SLuis R. Rodriguez if (i == 6) { 126203c4805SLuis R. Rodriguez dcuOffset = 0; 127203c4805SLuis R. Rodriguez dcuBase++; 128203c4805SLuis R. Rodriguez } 129203c4805SLuis R. Rodriguez 130991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 131203c4805SLuis R. Rodriguez "%2d %2x %1x %2x %2x\n", 132203c4805SLuis R. Rodriguez i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset, 133203c4805SLuis R. Rodriguez (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3), 134203c4805SLuis R. Rodriguez val[2] & (0x7 << (i * 3)) >> (i * 3), 135203c4805SLuis R. Rodriguez (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset); 136203c4805SLuis R. Rodriguez } 137203c4805SLuis R. Rodriguez 138991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); 139203c4805SLuis R. Rodriguez 140991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 141203c4805SLuis R. Rodriguez "qcu_stitch state: %2x qcu_fetch state: %2x\n", 142203c4805SLuis R. Rodriguez (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); 143991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 144203c4805SLuis R. Rodriguez "qcu_complete state: %2x dcu_complete state: %2x\n", 145203c4805SLuis R. Rodriguez (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); 146991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 147203c4805SLuis R. Rodriguez "dcu_arb state: %2x dcu_fp state: %2x\n", 148203c4805SLuis R. Rodriguez (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); 149991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 150203c4805SLuis R. Rodriguez "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", 151203c4805SLuis R. Rodriguez (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); 152991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 153203c4805SLuis R. Rodriguez "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", 154203c4805SLuis R. Rodriguez (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); 155991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 156203c4805SLuis R. Rodriguez "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", 157203c4805SLuis R. Rodriguez (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); 158203c4805SLuis R. Rodriguez 159991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x \n", 160475a6e4dSLuis R. Rodriguez REG_READ_D(ah, AR_OBS_BUS_1)); 161991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 162475a6e4dSLuis R. Rodriguez "AR_CR: 0x%x \n", REG_READ_D(ah, AR_CR)); 163203c4805SLuis R. Rodriguez 1647cf4a2e7SSujith ath9k_ps_restore(sc); 1657cf4a2e7SSujith 166991a0987SPavel Roskin retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 167991a0987SPavel Roskin kfree(buf); 168991a0987SPavel Roskin return retval; 169203c4805SLuis R. Rodriguez } 170203c4805SLuis R. Rodriguez 171203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = { 172203c4805SLuis R. Rodriguez .read = read_file_dma, 173203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 174203c4805SLuis R. Rodriguez .owner = THIS_MODULE 175203c4805SLuis R. Rodriguez }; 176203c4805SLuis R. Rodriguez 177203c4805SLuis R. Rodriguez 178203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status) 179203c4805SLuis R. Rodriguez { 180203c4805SLuis R. Rodriguez if (status) 181203c4805SLuis R. Rodriguez sc->debug.stats.istats.total++; 182203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RX) 183203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxok++; 184203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXEOL) 185203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxeol++; 186203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXORN) 187203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxorn++; 188203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TX) 189203c4805SLuis R. Rodriguez sc->debug.stats.istats.txok++; 190203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TXURN) 191203c4805SLuis R. Rodriguez sc->debug.stats.istats.txurn++; 192203c4805SLuis R. Rodriguez if (status & ATH9K_INT_MIB) 193203c4805SLuis R. Rodriguez sc->debug.stats.istats.mib++; 194203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXPHY) 195203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxphyerr++; 196203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXKCM) 197203c4805SLuis R. Rodriguez sc->debug.stats.istats.rx_keycache_miss++; 198203c4805SLuis R. Rodriguez if (status & ATH9K_INT_SWBA) 199203c4805SLuis R. Rodriguez sc->debug.stats.istats.swba++; 200203c4805SLuis R. Rodriguez if (status & ATH9K_INT_BMISS) 201203c4805SLuis R. Rodriguez sc->debug.stats.istats.bmiss++; 202203c4805SLuis R. Rodriguez if (status & ATH9K_INT_BNR) 203203c4805SLuis R. Rodriguez sc->debug.stats.istats.bnr++; 204203c4805SLuis R. Rodriguez if (status & ATH9K_INT_CST) 205203c4805SLuis R. Rodriguez sc->debug.stats.istats.cst++; 206203c4805SLuis R. Rodriguez if (status & ATH9K_INT_GTT) 207203c4805SLuis R. Rodriguez sc->debug.stats.istats.gtt++; 208203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TIM) 209203c4805SLuis R. Rodriguez sc->debug.stats.istats.tim++; 210203c4805SLuis R. Rodriguez if (status & ATH9K_INT_CABEND) 211203c4805SLuis R. Rodriguez sc->debug.stats.istats.cabend++; 212203c4805SLuis R. Rodriguez if (status & ATH9K_INT_DTIMSYNC) 213203c4805SLuis R. Rodriguez sc->debug.stats.istats.dtimsync++; 214203c4805SLuis R. Rodriguez if (status & ATH9K_INT_DTIM) 215203c4805SLuis R. Rodriguez sc->debug.stats.istats.dtim++; 216203c4805SLuis R. Rodriguez } 217203c4805SLuis R. Rodriguez 218203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, 219203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 220203c4805SLuis R. Rodriguez { 221203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 222203c4805SLuis R. Rodriguez char buf[512]; 223203c4805SLuis R. Rodriguez unsigned int len = 0; 224203c4805SLuis R. Rodriguez 225203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 226203c4805SLuis R. Rodriguez "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok); 227203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 228203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol); 229203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 230203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn); 231203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 232203c4805SLuis R. Rodriguez "%8s: %10u\n", "TX", sc->debug.stats.istats.txok); 233203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 234203c4805SLuis R. Rodriguez "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn); 235203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 236203c4805SLuis R. Rodriguez "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib); 237203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 238203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr); 239203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 240203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss); 241203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 242203c4805SLuis R. Rodriguez "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba); 243203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 244203c4805SLuis R. Rodriguez "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss); 245203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 246203c4805SLuis R. Rodriguez "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr); 247203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 248203c4805SLuis R. Rodriguez "%8s: %10u\n", "CST", sc->debug.stats.istats.cst); 249203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 250203c4805SLuis R. Rodriguez "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt); 251203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 252203c4805SLuis R. Rodriguez "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim); 253203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 254203c4805SLuis R. Rodriguez "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend); 255203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 256203c4805SLuis R. Rodriguez "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync); 257203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 258203c4805SLuis R. Rodriguez "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim); 259203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 260203c4805SLuis R. Rodriguez "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total); 261203c4805SLuis R. Rodriguez 262203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 263203c4805SLuis R. Rodriguez } 264203c4805SLuis R. Rodriguez 265203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = { 266203c4805SLuis R. Rodriguez .read = read_file_interrupt, 267203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 268203c4805SLuis R. Rodriguez .owner = THIS_MODULE 269203c4805SLuis R. Rodriguez }; 270203c4805SLuis R. Rodriguez 271545750d3SFelix Fietkau void ath_debug_stat_rc(struct ath_softc *sc, int final_rate) 272203c4805SLuis R. Rodriguez { 273bedf087aSJeff Hansen struct ath_rc_stats *stats; 274203c4805SLuis R. Rodriguez 275545750d3SFelix Fietkau stats = &sc->debug.stats.rcstats[final_rate]; 276bedf087aSJeff Hansen stats->success++; 277203c4805SLuis R. Rodriguez } 278203c4805SLuis R. Rodriguez 279203c4805SLuis R. Rodriguez void ath_debug_stat_retries(struct ath_softc *sc, int rix, 280203c4805SLuis R. Rodriguez int xretries, int retries, u8 per) 281203c4805SLuis R. Rodriguez { 282bedf087aSJeff Hansen struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix]; 283203c4805SLuis R. Rodriguez 284bedf087aSJeff Hansen stats->xretries += xretries; 285bedf087aSJeff Hansen stats->retries += retries; 286bedf087aSJeff Hansen stats->per = per; 287203c4805SLuis R. Rodriguez } 288203c4805SLuis R. Rodriguez 289203c4805SLuis R. Rodriguez static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, 290203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 291203c4805SLuis R. Rodriguez { 292203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 293bedf087aSJeff Hansen char *buf; 294bedf087aSJeff Hansen unsigned int len = 0, max; 295bedf087aSJeff Hansen int i = 0; 296bedf087aSJeff Hansen ssize_t retval; 297203c4805SLuis R. Rodriguez 298203c4805SLuis R. Rodriguez if (sc->cur_rate_table == NULL) 299203c4805SLuis R. Rodriguez return 0; 300203c4805SLuis R. Rodriguez 301c755ad34SLuis R. Rodriguez max = 80 + sc->cur_rate_table->rate_cnt * 1024; 302bedf087aSJeff Hansen buf = kmalloc(max + 1, GFP_KERNEL); 303bedf087aSJeff Hansen if (buf == NULL) 304bedf087aSJeff Hansen return 0; 305bedf087aSJeff Hansen buf[max] = 0; 306bedf087aSJeff Hansen 307c755ad34SLuis R. Rodriguez len += sprintf(buf, "%6s %6s %6s " 308c755ad34SLuis R. Rodriguez "%10s %10s %10s %10s\n", 309c755ad34SLuis R. Rodriguez "HT", "MCS", "Rate", 310c755ad34SLuis R. Rodriguez "Success", "Retries", "XRetries", "PER"); 311bedf087aSJeff Hansen 312bedf087aSJeff Hansen for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) { 313bedf087aSJeff Hansen u32 ratekbps = sc->cur_rate_table->info[i].ratekbps; 314bedf087aSJeff Hansen struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i]; 315c755ad34SLuis R. Rodriguez char mcs[5]; 316c755ad34SLuis R. Rodriguez char htmode[5]; 317c755ad34SLuis R. Rodriguez int used_mcs = 0, used_htmode = 0; 318c755ad34SLuis R. Rodriguez 319c755ad34SLuis R. Rodriguez if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) { 320c755ad34SLuis R. Rodriguez used_mcs = snprintf(mcs, 5, "%d", 321c755ad34SLuis R. Rodriguez sc->cur_rate_table->info[i].ratecode); 322c755ad34SLuis R. Rodriguez 323c755ad34SLuis R. Rodriguez if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy)) 324c755ad34SLuis R. Rodriguez used_htmode = snprintf(htmode, 5, "HT40"); 325c755ad34SLuis R. Rodriguez else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy)) 326c755ad34SLuis R. Rodriguez used_htmode = snprintf(htmode, 5, "HT20"); 327c755ad34SLuis R. Rodriguez else 328c755ad34SLuis R. Rodriguez used_htmode = snprintf(htmode, 5, "????"); 329c755ad34SLuis R. Rodriguez } 330c755ad34SLuis R. Rodriguez 331c755ad34SLuis R. Rodriguez mcs[used_mcs] = '\0'; 332c755ad34SLuis R. Rodriguez htmode[used_htmode] = '\0'; 333bedf087aSJeff Hansen 334bedf087aSJeff Hansen len += snprintf(buf + len, max - len, 335c755ad34SLuis R. Rodriguez "%6s %6s %3u.%d: " 336c755ad34SLuis R. Rodriguez "%10u %10u %10u %10u\n", 337c755ad34SLuis R. Rodriguez htmode, 338c755ad34SLuis R. Rodriguez mcs, 339c755ad34SLuis R. Rodriguez ratekbps / 1000, 340c755ad34SLuis R. Rodriguez (ratekbps % 1000) / 100, 341c755ad34SLuis R. Rodriguez stats->success, 342c755ad34SLuis R. Rodriguez stats->retries, 343c755ad34SLuis R. Rodriguez stats->xretries, 344bedf087aSJeff Hansen stats->per); 345bedf087aSJeff Hansen } 346bedf087aSJeff Hansen 347bedf087aSJeff Hansen retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 348bedf087aSJeff Hansen kfree(buf); 349bedf087aSJeff Hansen return retval; 350203c4805SLuis R. Rodriguez } 351203c4805SLuis R. Rodriguez 352203c4805SLuis R. Rodriguez static const struct file_operations fops_rcstat = { 353203c4805SLuis R. Rodriguez .read = read_file_rcstat, 354203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 355203c4805SLuis R. Rodriguez .owner = THIS_MODULE 356203c4805SLuis R. Rodriguez }; 357203c4805SLuis R. Rodriguez 358203c4805SLuis R. Rodriguez static const char * ath_wiphy_state_str(enum ath_wiphy_state state) 359203c4805SLuis R. Rodriguez { 360203c4805SLuis R. Rodriguez switch (state) { 361203c4805SLuis R. Rodriguez case ATH_WIPHY_INACTIVE: 362203c4805SLuis R. Rodriguez return "INACTIVE"; 363203c4805SLuis R. Rodriguez case ATH_WIPHY_ACTIVE: 364203c4805SLuis R. Rodriguez return "ACTIVE"; 365203c4805SLuis R. Rodriguez case ATH_WIPHY_PAUSING: 366203c4805SLuis R. Rodriguez return "PAUSING"; 367203c4805SLuis R. Rodriguez case ATH_WIPHY_PAUSED: 368203c4805SLuis R. Rodriguez return "PAUSED"; 369203c4805SLuis R. Rodriguez case ATH_WIPHY_SCAN: 370203c4805SLuis R. Rodriguez return "SCAN"; 371203c4805SLuis R. Rodriguez } 372203c4805SLuis R. Rodriguez return "?"; 373203c4805SLuis R. Rodriguez } 374203c4805SLuis R. Rodriguez 375203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf, 376203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 377203c4805SLuis R. Rodriguez { 378203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 379203c4805SLuis R. Rodriguez char buf[512]; 380203c4805SLuis R. Rodriguez unsigned int len = 0; 381203c4805SLuis R. Rodriguez int i; 382203c4805SLuis R. Rodriguez u8 addr[ETH_ALEN]; 383203c4805SLuis R. Rodriguez 384203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 385203c4805SLuis R. Rodriguez "primary: %s (%s chan=%d ht=%d)\n", 386203c4805SLuis R. Rodriguez wiphy_name(sc->pri_wiphy->hw->wiphy), 387203c4805SLuis R. Rodriguez ath_wiphy_state_str(sc->pri_wiphy->state), 388203c4805SLuis R. Rodriguez sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht); 389203c4805SLuis R. Rodriguez for (i = 0; i < sc->num_sec_wiphy; i++) { 390203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = sc->sec_wiphy[i]; 391203c4805SLuis R. Rodriguez if (aphy == NULL) 392203c4805SLuis R. Rodriguez continue; 393203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 394203c4805SLuis R. Rodriguez "secondary: %s (%s chan=%d ht=%d)\n", 395203c4805SLuis R. Rodriguez wiphy_name(aphy->hw->wiphy), 396203c4805SLuis R. Rodriguez ath_wiphy_state_str(aphy->state), 397203c4805SLuis R. Rodriguez aphy->chan_idx, aphy->chan_is_ht); 398203c4805SLuis R. Rodriguez } 399203c4805SLuis R. Rodriguez 400475a6e4dSLuis R. Rodriguez put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr); 401475a6e4dSLuis R. Rodriguez put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4); 402203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 403203c4805SLuis R. Rodriguez "addr: %pM\n", addr); 404475a6e4dSLuis R. Rodriguez put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr); 405475a6e4dSLuis R. Rodriguez put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4); 406203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 407203c4805SLuis R. Rodriguez "addrmask: %pM\n", addr); 408203c4805SLuis R. Rodriguez 409203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 410203c4805SLuis R. Rodriguez } 411203c4805SLuis R. Rodriguez 412203c4805SLuis R. Rodriguez static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name) 413203c4805SLuis R. Rodriguez { 414203c4805SLuis R. Rodriguez int i; 415203c4805SLuis R. Rodriguez if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0) 416203c4805SLuis R. Rodriguez return sc->pri_wiphy; 417203c4805SLuis R. Rodriguez for (i = 0; i < sc->num_sec_wiphy; i++) { 418203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = sc->sec_wiphy[i]; 419203c4805SLuis R. Rodriguez if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0) 420203c4805SLuis R. Rodriguez return aphy; 421203c4805SLuis R. Rodriguez } 422203c4805SLuis R. Rodriguez return NULL; 423203c4805SLuis R. Rodriguez } 424203c4805SLuis R. Rodriguez 425203c4805SLuis R. Rodriguez static int del_wiphy(struct ath_softc *sc, const char *name) 426203c4805SLuis R. Rodriguez { 427203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 428203c4805SLuis R. Rodriguez if (!aphy) 429203c4805SLuis R. Rodriguez return -ENOENT; 430203c4805SLuis R. Rodriguez return ath9k_wiphy_del(aphy); 431203c4805SLuis R. Rodriguez } 432203c4805SLuis R. Rodriguez 433203c4805SLuis R. Rodriguez static int pause_wiphy(struct ath_softc *sc, const char *name) 434203c4805SLuis R. Rodriguez { 435203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 436203c4805SLuis R. Rodriguez if (!aphy) 437203c4805SLuis R. Rodriguez return -ENOENT; 438203c4805SLuis R. Rodriguez return ath9k_wiphy_pause(aphy); 439203c4805SLuis R. Rodriguez } 440203c4805SLuis R. Rodriguez 441203c4805SLuis R. Rodriguez static int unpause_wiphy(struct ath_softc *sc, const char *name) 442203c4805SLuis R. Rodriguez { 443203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 444203c4805SLuis R. Rodriguez if (!aphy) 445203c4805SLuis R. Rodriguez return -ENOENT; 446203c4805SLuis R. Rodriguez return ath9k_wiphy_unpause(aphy); 447203c4805SLuis R. Rodriguez } 448203c4805SLuis R. Rodriguez 449203c4805SLuis R. Rodriguez static int select_wiphy(struct ath_softc *sc, const char *name) 450203c4805SLuis R. Rodriguez { 451203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 452203c4805SLuis R. Rodriguez if (!aphy) 453203c4805SLuis R. Rodriguez return -ENOENT; 454203c4805SLuis R. Rodriguez return ath9k_wiphy_select(aphy); 455203c4805SLuis R. Rodriguez } 456203c4805SLuis R. Rodriguez 457203c4805SLuis R. Rodriguez static int schedule_wiphy(struct ath_softc *sc, const char *msec) 458203c4805SLuis R. Rodriguez { 459203c4805SLuis R. Rodriguez ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0)); 460203c4805SLuis R. Rodriguez return 0; 461203c4805SLuis R. Rodriguez } 462203c4805SLuis R. Rodriguez 463203c4805SLuis R. Rodriguez static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf, 464203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 465203c4805SLuis R. Rodriguez { 466203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 467203c4805SLuis R. Rodriguez char buf[50]; 468203c4805SLuis R. Rodriguez size_t len; 469203c4805SLuis R. Rodriguez 470203c4805SLuis R. Rodriguez len = min(count, sizeof(buf) - 1); 471203c4805SLuis R. Rodriguez if (copy_from_user(buf, user_buf, len)) 472203c4805SLuis R. Rodriguez return -EFAULT; 473203c4805SLuis R. Rodriguez buf[len] = '\0'; 474203c4805SLuis R. Rodriguez if (len > 0 && buf[len - 1] == '\n') 475203c4805SLuis R. Rodriguez buf[len - 1] = '\0'; 476203c4805SLuis R. Rodriguez 477203c4805SLuis R. Rodriguez if (strncmp(buf, "add", 3) == 0) { 478203c4805SLuis R. Rodriguez int res = ath9k_wiphy_add(sc); 479203c4805SLuis R. Rodriguez if (res < 0) 480203c4805SLuis R. Rodriguez return res; 481203c4805SLuis R. Rodriguez } else if (strncmp(buf, "del=", 4) == 0) { 482203c4805SLuis R. Rodriguez int res = del_wiphy(sc, buf + 4); 483203c4805SLuis R. Rodriguez if (res < 0) 484203c4805SLuis R. Rodriguez return res; 485203c4805SLuis R. Rodriguez } else if (strncmp(buf, "pause=", 6) == 0) { 486203c4805SLuis R. Rodriguez int res = pause_wiphy(sc, buf + 6); 487203c4805SLuis R. Rodriguez if (res < 0) 488203c4805SLuis R. Rodriguez return res; 489203c4805SLuis R. Rodriguez } else if (strncmp(buf, "unpause=", 8) == 0) { 490203c4805SLuis R. Rodriguez int res = unpause_wiphy(sc, buf + 8); 491203c4805SLuis R. Rodriguez if (res < 0) 492203c4805SLuis R. Rodriguez return res; 493203c4805SLuis R. Rodriguez } else if (strncmp(buf, "select=", 7) == 0) { 494203c4805SLuis R. Rodriguez int res = select_wiphy(sc, buf + 7); 495203c4805SLuis R. Rodriguez if (res < 0) 496203c4805SLuis R. Rodriguez return res; 497203c4805SLuis R. Rodriguez } else if (strncmp(buf, "schedule=", 9) == 0) { 498203c4805SLuis R. Rodriguez int res = schedule_wiphy(sc, buf + 9); 499203c4805SLuis R. Rodriguez if (res < 0) 500203c4805SLuis R. Rodriguez return res; 501203c4805SLuis R. Rodriguez } else 502203c4805SLuis R. Rodriguez return -EOPNOTSUPP; 503203c4805SLuis R. Rodriguez 504203c4805SLuis R. Rodriguez return count; 505203c4805SLuis R. Rodriguez } 506203c4805SLuis R. Rodriguez 507203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = { 508203c4805SLuis R. Rodriguez .read = read_file_wiphy, 509203c4805SLuis R. Rodriguez .write = write_file_wiphy, 510203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 511203c4805SLuis R. Rodriguez .owner = THIS_MODULE 512203c4805SLuis R. Rodriguez }; 513203c4805SLuis R. Rodriguez 514fec247c0SSujith #define PR(str, elem) \ 515fec247c0SSujith do { \ 516fec247c0SSujith len += snprintf(buf + len, size - len, \ 517fec247c0SSujith "%s%13u%11u%10u%10u\n", str, \ 518fec247c0SSujith sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \ 519fec247c0SSujith sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \ 520fec247c0SSujith sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \ 521fec247c0SSujith sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \ 522fec247c0SSujith } while(0) 523fec247c0SSujith 524fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf, 525fec247c0SSujith size_t count, loff_t *ppos) 526fec247c0SSujith { 527fec247c0SSujith struct ath_softc *sc = file->private_data; 528fec247c0SSujith char *buf; 529fec247c0SSujith unsigned int len = 0, size = 2048; 530fec247c0SSujith ssize_t retval = 0; 531fec247c0SSujith 532fec247c0SSujith buf = kzalloc(size, GFP_KERNEL); 533fec247c0SSujith if (buf == NULL) 534fec247c0SSujith return 0; 535fec247c0SSujith 536fec247c0SSujith len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO"); 537fec247c0SSujith 538fec247c0SSujith PR("MPDUs Queued: ", queued); 539fec247c0SSujith PR("MPDUs Completed: ", completed); 540fec247c0SSujith PR("Aggregates: ", a_aggr); 541fec247c0SSujith PR("AMPDUs Queued: ", a_queued); 542fec247c0SSujith PR("AMPDUs Completed:", a_completed); 543fec247c0SSujith PR("AMPDUs Retried: ", a_retries); 544fec247c0SSujith PR("AMPDUs XRetried: ", a_xretries); 545fec247c0SSujith PR("FIFO Underrun: ", fifo_underrun); 546fec247c0SSujith PR("TXOP Exceeded: ", xtxop); 547fec247c0SSujith PR("TXTIMER Expiry: ", timer_exp); 548fec247c0SSujith PR("DESC CFG Error: ", desc_cfg_err); 549fec247c0SSujith PR("DATA Underrun: ", data_underrun); 550fec247c0SSujith PR("DELIM Underrun: ", delim_underrun); 551fec247c0SSujith 552fec247c0SSujith retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 553fec247c0SSujith kfree(buf); 554fec247c0SSujith 555fec247c0SSujith return retval; 556fec247c0SSujith } 557fec247c0SSujith 558fec247c0SSujith void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq, 559db1a052bSFelix Fietkau struct ath_buf *bf, struct ath_tx_status *ts) 560fec247c0SSujith { 561fec247c0SSujith if (bf_isampdu(bf)) { 562fec247c0SSujith if (bf_isxretried(bf)) 563fec247c0SSujith TX_STAT_INC(txq->axq_qnum, a_xretries); 564fec247c0SSujith else 565fec247c0SSujith TX_STAT_INC(txq->axq_qnum, a_completed); 566fec247c0SSujith } else { 567fec247c0SSujith TX_STAT_INC(txq->axq_qnum, completed); 568fec247c0SSujith } 569fec247c0SSujith 570db1a052bSFelix Fietkau if (ts->ts_status & ATH9K_TXERR_FIFO) 571fec247c0SSujith TX_STAT_INC(txq->axq_qnum, fifo_underrun); 572db1a052bSFelix Fietkau if (ts->ts_status & ATH9K_TXERR_XTXOP) 573fec247c0SSujith TX_STAT_INC(txq->axq_qnum, xtxop); 574db1a052bSFelix Fietkau if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED) 575fec247c0SSujith TX_STAT_INC(txq->axq_qnum, timer_exp); 576db1a052bSFelix Fietkau if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR) 577fec247c0SSujith TX_STAT_INC(txq->axq_qnum, desc_cfg_err); 578db1a052bSFelix Fietkau if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN) 579fec247c0SSujith TX_STAT_INC(txq->axq_qnum, data_underrun); 580db1a052bSFelix Fietkau if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN) 581fec247c0SSujith TX_STAT_INC(txq->axq_qnum, delim_underrun); 582fec247c0SSujith } 583fec247c0SSujith 584fec247c0SSujith static const struct file_operations fops_xmit = { 585fec247c0SSujith .read = read_file_xmit, 586fec247c0SSujith .open = ath9k_debugfs_open, 587fec247c0SSujith .owner = THIS_MODULE 588fec247c0SSujith }; 589203c4805SLuis R. Rodriguez 5901395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf, 5911395d3f0SSujith size_t count, loff_t *ppos) 5921395d3f0SSujith { 5931395d3f0SSujith #define PHY_ERR(s, p) \ 5941395d3f0SSujith len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \ 5951395d3f0SSujith sc->debug.stats.rxstats.phy_err_stats[p]); 5961395d3f0SSujith 5971395d3f0SSujith struct ath_softc *sc = file->private_data; 5981395d3f0SSujith char *buf; 5991395d3f0SSujith unsigned int len = 0, size = 1152; 6001395d3f0SSujith ssize_t retval = 0; 6011395d3f0SSujith 6021395d3f0SSujith buf = kzalloc(size, GFP_KERNEL); 6031395d3f0SSujith if (buf == NULL) 6041395d3f0SSujith return 0; 6051395d3f0SSujith 6061395d3f0SSujith len += snprintf(buf + len, size - len, 6071395d3f0SSujith "%18s : %10u\n", "CRC ERR", 6081395d3f0SSujith sc->debug.stats.rxstats.crc_err); 6091395d3f0SSujith len += snprintf(buf + len, size - len, 6101395d3f0SSujith "%18s : %10u\n", "DECRYPT CRC ERR", 6111395d3f0SSujith sc->debug.stats.rxstats.decrypt_crc_err); 6121395d3f0SSujith len += snprintf(buf + len, size - len, 6131395d3f0SSujith "%18s : %10u\n", "PHY ERR", 6141395d3f0SSujith sc->debug.stats.rxstats.phy_err); 6151395d3f0SSujith len += snprintf(buf + len, size - len, 6161395d3f0SSujith "%18s : %10u\n", "MIC ERR", 6171395d3f0SSujith sc->debug.stats.rxstats.mic_err); 6181395d3f0SSujith len += snprintf(buf + len, size - len, 6191395d3f0SSujith "%18s : %10u\n", "PRE-DELIM CRC ERR", 6201395d3f0SSujith sc->debug.stats.rxstats.pre_delim_crc_err); 6211395d3f0SSujith len += snprintf(buf + len, size - len, 6221395d3f0SSujith "%18s : %10u\n", "POST-DELIM CRC ERR", 6231395d3f0SSujith sc->debug.stats.rxstats.post_delim_crc_err); 6241395d3f0SSujith len += snprintf(buf + len, size - len, 6251395d3f0SSujith "%18s : %10u\n", "DECRYPT BUSY ERR", 6261395d3f0SSujith sc->debug.stats.rxstats.decrypt_busy_err); 6271395d3f0SSujith 6281395d3f0SSujith PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN); 6291395d3f0SSujith PHY_ERR("TIMING", ATH9K_PHYERR_TIMING); 6301395d3f0SSujith PHY_ERR("PARITY", ATH9K_PHYERR_PARITY); 6311395d3f0SSujith PHY_ERR("RATE", ATH9K_PHYERR_RATE); 6321395d3f0SSujith PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH); 6331395d3f0SSujith PHY_ERR("RADAR", ATH9K_PHYERR_RADAR); 6341395d3f0SSujith PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE); 6351395d3f0SSujith PHY_ERR("TOR", ATH9K_PHYERR_TOR); 6361395d3f0SSujith PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING); 6371395d3f0SSujith PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY); 6381395d3f0SSujith PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL); 6391395d3f0SSujith PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL); 6401395d3f0SSujith PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP); 6411395d3f0SSujith PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE); 6421395d3f0SSujith PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART); 6431395d3f0SSujith PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT); 6441395d3f0SSujith PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING); 6451395d3f0SSujith PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC); 6461395d3f0SSujith PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL); 6471395d3f0SSujith PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE); 6481395d3f0SSujith PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART); 6491395d3f0SSujith PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL); 6501395d3f0SSujith PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP); 6511395d3f0SSujith PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR); 6521395d3f0SSujith PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL); 6531395d3f0SSujith PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL); 6541395d3f0SSujith 6551395d3f0SSujith retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 6561395d3f0SSujith kfree(buf); 6571395d3f0SSujith 6581395d3f0SSujith return retval; 6591395d3f0SSujith 6601395d3f0SSujith #undef PHY_ERR 6611395d3f0SSujith } 6621395d3f0SSujith 663*8e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs) 6641395d3f0SSujith { 6651395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++ 6661395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++ 6671395d3f0SSujith 6681395d3f0SSujith u32 phyerr; 6691395d3f0SSujith 670*8e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RXERR_CRC) 6711395d3f0SSujith RX_STAT_INC(crc_err); 672*8e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RXERR_DECRYPT) 6731395d3f0SSujith RX_STAT_INC(decrypt_crc_err); 674*8e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RXERR_MIC) 6751395d3f0SSujith RX_STAT_INC(mic_err); 676*8e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE) 6771395d3f0SSujith RX_STAT_INC(pre_delim_crc_err); 678*8e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST) 6791395d3f0SSujith RX_STAT_INC(post_delim_crc_err); 680*8e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY) 6811395d3f0SSujith RX_STAT_INC(decrypt_busy_err); 6821395d3f0SSujith 683*8e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RXERR_PHY) { 6841395d3f0SSujith RX_STAT_INC(phy_err); 685*8e6f5aa2SFelix Fietkau phyerr = rs->rs_phyerr & 0x24; 6861395d3f0SSujith RX_PHY_ERR_INC(phyerr); 6871395d3f0SSujith } 6881395d3f0SSujith 6891395d3f0SSujith #undef RX_STAT_INC 6901395d3f0SSujith #undef RX_PHY_ERR_INC 6911395d3f0SSujith } 6921395d3f0SSujith 6931395d3f0SSujith static const struct file_operations fops_recv = { 6941395d3f0SSujith .read = read_file_recv, 6951395d3f0SSujith .open = ath9k_debugfs_open, 6961395d3f0SSujith .owner = THIS_MODULE 6971395d3f0SSujith }; 6981395d3f0SSujith 6994d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah) 700203c4805SLuis R. Rodriguez { 701bc974f4aSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(ah); 702bc974f4aSLuis R. Rodriguez struct ath_softc *sc = (struct ath_softc *) common->priv; 7034d6b228dSLuis R. Rodriguez 704203c4805SLuis R. Rodriguez if (!ath9k_debugfs_root) 705203c4805SLuis R. Rodriguez return -ENOENT; 706203c4805SLuis R. Rodriguez 707203c4805SLuis R. Rodriguez sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy), 708203c4805SLuis R. Rodriguez ath9k_debugfs_root); 709203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_phy) 710203c4805SLuis R. Rodriguez goto err; 711203c4805SLuis R. Rodriguez 712a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG 7132493928eSJeff Hansen sc->debug.debugfs_debug = debugfs_create_file("debug", 7149d49e861SJiri Slaby S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug); 7152493928eSJeff Hansen if (!sc->debug.debugfs_debug) 7162493928eSJeff Hansen goto err; 717a830df07SFelix Fietkau #endif 7182493928eSJeff Hansen 7199d49e861SJiri Slaby sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR, 720203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, sc, &fops_dma); 721203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_dma) 722203c4805SLuis R. Rodriguez goto err; 723203c4805SLuis R. Rodriguez 724203c4805SLuis R. Rodriguez sc->debug.debugfs_interrupt = debugfs_create_file("interrupt", 7259d49e861SJiri Slaby S_IRUSR, 726203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, 727203c4805SLuis R. Rodriguez sc, &fops_interrupt); 728203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_interrupt) 729203c4805SLuis R. Rodriguez goto err; 730203c4805SLuis R. Rodriguez 731203c4805SLuis R. Rodriguez sc->debug.debugfs_rcstat = debugfs_create_file("rcstat", 7329d49e861SJiri Slaby S_IRUSR, 733203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, 734203c4805SLuis R. Rodriguez sc, &fops_rcstat); 735203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_rcstat) 736203c4805SLuis R. Rodriguez goto err; 737203c4805SLuis R. Rodriguez 738203c4805SLuis R. Rodriguez sc->debug.debugfs_wiphy = debugfs_create_file( 7399d49e861SJiri Slaby "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, 740203c4805SLuis R. Rodriguez &fops_wiphy); 741203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_wiphy) 742203c4805SLuis R. Rodriguez goto err; 743203c4805SLuis R. Rodriguez 744fec247c0SSujith sc->debug.debugfs_xmit = debugfs_create_file("xmit", 745fec247c0SSujith S_IRUSR, 746fec247c0SSujith sc->debug.debugfs_phy, 747fec247c0SSujith sc, &fops_xmit); 748fec247c0SSujith if (!sc->debug.debugfs_xmit) 749fec247c0SSujith goto err; 750fec247c0SSujith 7511395d3f0SSujith sc->debug.debugfs_recv = debugfs_create_file("recv", 7521395d3f0SSujith S_IRUSR, 7531395d3f0SSujith sc->debug.debugfs_phy, 7541395d3f0SSujith sc, &fops_recv); 7551395d3f0SSujith if (!sc->debug.debugfs_recv) 7561395d3f0SSujith goto err; 7571395d3f0SSujith 758203c4805SLuis R. Rodriguez return 0; 759203c4805SLuis R. Rodriguez err: 7604d6b228dSLuis R. Rodriguez ath9k_exit_debug(ah); 761203c4805SLuis R. Rodriguez return -ENOMEM; 762203c4805SLuis R. Rodriguez } 763203c4805SLuis R. Rodriguez 7644d6b228dSLuis R. Rodriguez void ath9k_exit_debug(struct ath_hw *ah) 765203c4805SLuis R. Rodriguez { 766bc974f4aSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(ah); 767bc974f4aSLuis R. Rodriguez struct ath_softc *sc = (struct ath_softc *) common->priv; 7684d6b228dSLuis R. Rodriguez 7691395d3f0SSujith debugfs_remove(sc->debug.debugfs_recv); 770fec247c0SSujith debugfs_remove(sc->debug.debugfs_xmit); 771203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_wiphy); 772203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_rcstat); 773203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_interrupt); 774203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_dma); 7752493928eSJeff Hansen debugfs_remove(sc->debug.debugfs_debug); 776203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_phy); 777203c4805SLuis R. Rodriguez } 778203c4805SLuis R. Rodriguez 779203c4805SLuis R. Rodriguez int ath9k_debug_create_root(void) 780203c4805SLuis R. Rodriguez { 781203c4805SLuis R. Rodriguez ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL); 782203c4805SLuis R. Rodriguez if (!ath9k_debugfs_root) 783203c4805SLuis R. Rodriguez return -ENOENT; 784203c4805SLuis R. Rodriguez 785203c4805SLuis R. Rodriguez return 0; 786203c4805SLuis R. Rodriguez } 787203c4805SLuis R. Rodriguez 788203c4805SLuis R. Rodriguez void ath9k_debug_remove_root(void) 789203c4805SLuis R. Rodriguez { 790203c4805SLuis R. Rodriguez debugfs_remove(ath9k_debugfs_root); 791203c4805SLuis R. Rodriguez ath9k_debugfs_root = NULL; 792203c4805SLuis R. Rodriguez } 793