1203c4805SLuis R. Rodriguez /* 25b68138eSSujith Manoharan * Copyright (c) 2008-2011 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 175a0e3ad6STejun Heo #include <linux/slab.h> 18582d0064SVasanthakumar Thiagarajan #include <linux/vmalloc.h> 19203c4805SLuis R. Rodriguez #include <asm/unaligned.h> 20203c4805SLuis R. Rodriguez 21203c4805SLuis R. Rodriguez #include "ath9k.h" 22203c4805SLuis R. Rodriguez 23475a6e4dSLuis R. Rodriguez #define REG_WRITE_D(_ah, _reg, _val) \ 24475a6e4dSLuis R. Rodriguez ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg)) 25475a6e4dSLuis R. Rodriguez #define REG_READ_D(_ah, _reg) \ 26475a6e4dSLuis R. Rodriguez ath9k_hw_common(_ah)->ops->read((_ah), (_reg)) 27475a6e4dSLuis 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 34582d0064SVasanthakumar Thiagarajan static ssize_t ath9k_debugfs_read_buf(struct file *file, char __user *user_buf, 35582d0064SVasanthakumar Thiagarajan size_t count, loff_t *ppos) 36582d0064SVasanthakumar Thiagarajan { 37582d0064SVasanthakumar Thiagarajan u8 *buf = file->private_data; 38582d0064SVasanthakumar Thiagarajan return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); 39582d0064SVasanthakumar Thiagarajan } 40582d0064SVasanthakumar Thiagarajan 41582d0064SVasanthakumar Thiagarajan static int ath9k_debugfs_release_buf(struct inode *inode, struct file *file) 42582d0064SVasanthakumar Thiagarajan { 43582d0064SVasanthakumar Thiagarajan vfree(file->private_data); 44582d0064SVasanthakumar Thiagarajan return 0; 45582d0064SVasanthakumar Thiagarajan } 46582d0064SVasanthakumar Thiagarajan 47a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG 48a830df07SFelix Fietkau 492493928eSJeff Hansen static ssize_t read_file_debug(struct file *file, char __user *user_buf, 502493928eSJeff Hansen size_t count, loff_t *ppos) 512493928eSJeff Hansen { 522493928eSJeff Hansen struct ath_softc *sc = file->private_data; 53c46917bbSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(sc->sc_ah); 542493928eSJeff Hansen char buf[32]; 55581f725cSVasanthakumar Thiagarajan unsigned int len; 56581f725cSVasanthakumar Thiagarajan 572b87f3aaSDan Carpenter len = sprintf(buf, "0x%08x\n", common->debug_mask); 582493928eSJeff Hansen return simple_read_from_buffer(user_buf, count, ppos, buf, len); 592493928eSJeff Hansen } 602493928eSJeff Hansen 612493928eSJeff Hansen static ssize_t write_file_debug(struct file *file, const char __user *user_buf, 622493928eSJeff Hansen size_t count, loff_t *ppos) 632493928eSJeff Hansen { 642493928eSJeff Hansen struct ath_softc *sc = file->private_data; 65c46917bbSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(sc->sc_ah); 662493928eSJeff Hansen unsigned long mask; 672493928eSJeff Hansen char buf[32]; 68581f725cSVasanthakumar Thiagarajan ssize_t len; 69581f725cSVasanthakumar Thiagarajan 70581f725cSVasanthakumar Thiagarajan len = min(count, sizeof(buf) - 1); 71581f725cSVasanthakumar Thiagarajan if (copy_from_user(buf, user_buf, len)) 7204236066SDan Carpenter return -EFAULT; 73581f725cSVasanthakumar Thiagarajan 74581f725cSVasanthakumar Thiagarajan buf[len] = '\0'; 75581f725cSVasanthakumar Thiagarajan if (strict_strtoul(buf, 0, &mask)) 76581f725cSVasanthakumar Thiagarajan return -EINVAL; 77581f725cSVasanthakumar Thiagarajan 78c46917bbSLuis R. Rodriguez common->debug_mask = mask; 792493928eSJeff Hansen return count; 802493928eSJeff Hansen } 812493928eSJeff Hansen 822493928eSJeff Hansen static const struct file_operations fops_debug = { 832493928eSJeff Hansen .read = read_file_debug, 842493928eSJeff Hansen .write = write_file_debug, 852493928eSJeff Hansen .open = ath9k_debugfs_open, 866038f373SArnd Bergmann .owner = THIS_MODULE, 876038f373SArnd Bergmann .llseek = default_llseek, 882493928eSJeff Hansen }; 892493928eSJeff Hansen 90a830df07SFelix Fietkau #endif 91a830df07SFelix Fietkau 92991a0987SPavel Roskin #define DMA_BUF_LEN 1024 93991a0987SPavel Roskin 9415340694SFelix Fietkau static ssize_t read_file_tx_chainmask(struct file *file, char __user *user_buf, 9515340694SFelix Fietkau size_t count, loff_t *ppos) 9615340694SFelix Fietkau { 9715340694SFelix Fietkau struct ath_softc *sc = file->private_data; 9815340694SFelix Fietkau struct ath_common *common = ath9k_hw_common(sc->sc_ah); 9915340694SFelix Fietkau char buf[32]; 10015340694SFelix Fietkau unsigned int len; 10115340694SFelix Fietkau 1022b87f3aaSDan Carpenter len = sprintf(buf, "0x%08x\n", common->tx_chainmask); 10315340694SFelix Fietkau return simple_read_from_buffer(user_buf, count, ppos, buf, len); 10415340694SFelix Fietkau } 10515340694SFelix Fietkau 10615340694SFelix Fietkau static ssize_t write_file_tx_chainmask(struct file *file, const char __user *user_buf, 10715340694SFelix Fietkau size_t count, loff_t *ppos) 10815340694SFelix Fietkau { 10915340694SFelix Fietkau struct ath_softc *sc = file->private_data; 11015340694SFelix Fietkau struct ath_common *common = ath9k_hw_common(sc->sc_ah); 11115340694SFelix Fietkau unsigned long mask; 11215340694SFelix Fietkau char buf[32]; 11315340694SFelix Fietkau ssize_t len; 11415340694SFelix Fietkau 11515340694SFelix Fietkau len = min(count, sizeof(buf) - 1); 11615340694SFelix Fietkau if (copy_from_user(buf, user_buf, len)) 11704236066SDan Carpenter return -EFAULT; 11815340694SFelix Fietkau 11915340694SFelix Fietkau buf[len] = '\0'; 12015340694SFelix Fietkau if (strict_strtoul(buf, 0, &mask)) 12115340694SFelix Fietkau return -EINVAL; 12215340694SFelix Fietkau 12315340694SFelix Fietkau common->tx_chainmask = mask; 12415340694SFelix Fietkau sc->sc_ah->caps.tx_chainmask = mask; 12515340694SFelix Fietkau return count; 12615340694SFelix Fietkau } 12715340694SFelix Fietkau 12815340694SFelix Fietkau static const struct file_operations fops_tx_chainmask = { 12915340694SFelix Fietkau .read = read_file_tx_chainmask, 13015340694SFelix Fietkau .write = write_file_tx_chainmask, 13115340694SFelix Fietkau .open = ath9k_debugfs_open, 1326038f373SArnd Bergmann .owner = THIS_MODULE, 1336038f373SArnd Bergmann .llseek = default_llseek, 13415340694SFelix Fietkau }; 13515340694SFelix Fietkau 13615340694SFelix Fietkau 13715340694SFelix Fietkau static ssize_t read_file_rx_chainmask(struct file *file, char __user *user_buf, 13815340694SFelix Fietkau size_t count, loff_t *ppos) 13915340694SFelix Fietkau { 14015340694SFelix Fietkau struct ath_softc *sc = file->private_data; 14115340694SFelix Fietkau struct ath_common *common = ath9k_hw_common(sc->sc_ah); 14215340694SFelix Fietkau char buf[32]; 14315340694SFelix Fietkau unsigned int len; 14415340694SFelix Fietkau 1452b87f3aaSDan Carpenter len = sprintf(buf, "0x%08x\n", common->rx_chainmask); 14615340694SFelix Fietkau return simple_read_from_buffer(user_buf, count, ppos, buf, len); 14715340694SFelix Fietkau } 14815340694SFelix Fietkau 14915340694SFelix Fietkau static ssize_t write_file_rx_chainmask(struct file *file, const char __user *user_buf, 15015340694SFelix Fietkau size_t count, loff_t *ppos) 15115340694SFelix Fietkau { 15215340694SFelix Fietkau struct ath_softc *sc = file->private_data; 15315340694SFelix Fietkau struct ath_common *common = ath9k_hw_common(sc->sc_ah); 15415340694SFelix Fietkau unsigned long mask; 15515340694SFelix Fietkau char buf[32]; 15615340694SFelix Fietkau ssize_t len; 15715340694SFelix Fietkau 15815340694SFelix Fietkau len = min(count, sizeof(buf) - 1); 15915340694SFelix Fietkau if (copy_from_user(buf, user_buf, len)) 16004236066SDan Carpenter return -EFAULT; 16115340694SFelix Fietkau 16215340694SFelix Fietkau buf[len] = '\0'; 16315340694SFelix Fietkau if (strict_strtoul(buf, 0, &mask)) 16415340694SFelix Fietkau return -EINVAL; 16515340694SFelix Fietkau 16615340694SFelix Fietkau common->rx_chainmask = mask; 16715340694SFelix Fietkau sc->sc_ah->caps.rx_chainmask = mask; 16815340694SFelix Fietkau return count; 16915340694SFelix Fietkau } 17015340694SFelix Fietkau 17115340694SFelix Fietkau static const struct file_operations fops_rx_chainmask = { 17215340694SFelix Fietkau .read = read_file_rx_chainmask, 17315340694SFelix Fietkau .write = write_file_rx_chainmask, 17415340694SFelix Fietkau .open = ath9k_debugfs_open, 1756038f373SArnd Bergmann .owner = THIS_MODULE, 1766038f373SArnd Bergmann .llseek = default_llseek, 17715340694SFelix Fietkau }; 17815340694SFelix Fietkau 17905c0be2fSMohammed Shafi Shajakhan static ssize_t read_file_disable_ani(struct file *file, char __user *user_buf, 18005c0be2fSMohammed Shafi Shajakhan size_t count, loff_t *ppos) 18105c0be2fSMohammed Shafi Shajakhan { 18205c0be2fSMohammed Shafi Shajakhan struct ath_softc *sc = file->private_data; 18305c0be2fSMohammed Shafi Shajakhan struct ath_common *common = ath9k_hw_common(sc->sc_ah); 18405c0be2fSMohammed Shafi Shajakhan char buf[32]; 18505c0be2fSMohammed Shafi Shajakhan unsigned int len; 18605c0be2fSMohammed Shafi Shajakhan 18705c0be2fSMohammed Shafi Shajakhan len = sprintf(buf, "%d\n", common->disable_ani); 18805c0be2fSMohammed Shafi Shajakhan return simple_read_from_buffer(user_buf, count, ppos, buf, len); 18905c0be2fSMohammed Shafi Shajakhan } 19005c0be2fSMohammed Shafi Shajakhan 19105c0be2fSMohammed Shafi Shajakhan static ssize_t write_file_disable_ani(struct file *file, 19205c0be2fSMohammed Shafi Shajakhan const char __user *user_buf, 19305c0be2fSMohammed Shafi Shajakhan size_t count, loff_t *ppos) 19405c0be2fSMohammed Shafi Shajakhan { 19505c0be2fSMohammed Shafi Shajakhan struct ath_softc *sc = file->private_data; 19605c0be2fSMohammed Shafi Shajakhan struct ath_common *common = ath9k_hw_common(sc->sc_ah); 19705c0be2fSMohammed Shafi Shajakhan unsigned long disable_ani; 19805c0be2fSMohammed Shafi Shajakhan char buf[32]; 19905c0be2fSMohammed Shafi Shajakhan ssize_t len; 20005c0be2fSMohammed Shafi Shajakhan 20105c0be2fSMohammed Shafi Shajakhan len = min(count, sizeof(buf) - 1); 20205c0be2fSMohammed Shafi Shajakhan if (copy_from_user(buf, user_buf, len)) 20305c0be2fSMohammed Shafi Shajakhan return -EFAULT; 20405c0be2fSMohammed Shafi Shajakhan 20505c0be2fSMohammed Shafi Shajakhan buf[len] = '\0'; 20605c0be2fSMohammed Shafi Shajakhan if (strict_strtoul(buf, 0, &disable_ani)) 20705c0be2fSMohammed Shafi Shajakhan return -EINVAL; 20805c0be2fSMohammed Shafi Shajakhan 20905c0be2fSMohammed Shafi Shajakhan common->disable_ani = !!disable_ani; 21005c0be2fSMohammed Shafi Shajakhan 21105c0be2fSMohammed Shafi Shajakhan if (disable_ani) { 21205c0be2fSMohammed Shafi Shajakhan sc->sc_flags &= ~SC_OP_ANI_RUN; 21305c0be2fSMohammed Shafi Shajakhan del_timer_sync(&common->ani.timer); 21405c0be2fSMohammed Shafi Shajakhan } else { 21505c0be2fSMohammed Shafi Shajakhan sc->sc_flags |= SC_OP_ANI_RUN; 21605c0be2fSMohammed Shafi Shajakhan ath_start_ani(common); 21705c0be2fSMohammed Shafi Shajakhan } 21805c0be2fSMohammed Shafi Shajakhan 21905c0be2fSMohammed Shafi Shajakhan return count; 22005c0be2fSMohammed Shafi Shajakhan } 22105c0be2fSMohammed Shafi Shajakhan 22205c0be2fSMohammed Shafi Shajakhan static const struct file_operations fops_disable_ani = { 22305c0be2fSMohammed Shafi Shajakhan .read = read_file_disable_ani, 22405c0be2fSMohammed Shafi Shajakhan .write = write_file_disable_ani, 22505c0be2fSMohammed Shafi Shajakhan .open = ath9k_debugfs_open, 22605c0be2fSMohammed Shafi Shajakhan .owner = THIS_MODULE, 22705c0be2fSMohammed Shafi Shajakhan .llseek = default_llseek, 22805c0be2fSMohammed Shafi Shajakhan }; 22915340694SFelix Fietkau 230203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf, 231203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 232203c4805SLuis R. Rodriguez { 233203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 234203c4805SLuis R. Rodriguez struct ath_hw *ah = sc->sc_ah; 235991a0987SPavel Roskin char *buf; 236991a0987SPavel Roskin int retval; 237203c4805SLuis R. Rodriguez unsigned int len = 0; 238203c4805SLuis R. Rodriguez u32 val[ATH9K_NUM_DMA_DEBUG_REGS]; 239203c4805SLuis R. Rodriguez int i, qcuOffset = 0, dcuOffset = 0; 240203c4805SLuis R. Rodriguez u32 *qcuBase = &val[0], *dcuBase = &val[4]; 241203c4805SLuis R. Rodriguez 242991a0987SPavel Roskin buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL); 243991a0987SPavel Roskin if (!buf) 24404236066SDan Carpenter return -ENOMEM; 245991a0987SPavel Roskin 2467cf4a2e7SSujith ath9k_ps_wakeup(sc); 2477cf4a2e7SSujith 248475a6e4dSLuis R. Rodriguez REG_WRITE_D(ah, AR_MACMISC, 249203c4805SLuis R. Rodriguez ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | 250203c4805SLuis R. Rodriguez (AR_MACMISC_MISC_OBS_BUS_1 << 251203c4805SLuis R. Rodriguez AR_MACMISC_MISC_OBS_BUS_MSB_S))); 252203c4805SLuis R. Rodriguez 253991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 254203c4805SLuis R. Rodriguez "Raw DMA Debug values:\n"); 255203c4805SLuis R. Rodriguez 256203c4805SLuis R. Rodriguez for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { 257203c4805SLuis R. Rodriguez if (i % 4 == 0) 258991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); 259203c4805SLuis R. Rodriguez 260475a6e4dSLuis R. Rodriguez val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32))); 261991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ", 262203c4805SLuis R. Rodriguez i, val[i]); 263203c4805SLuis R. Rodriguez } 264203c4805SLuis R. Rodriguez 265991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n"); 266991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 267203c4805SLuis R. Rodriguez "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); 268203c4805SLuis R. Rodriguez 269203c4805SLuis R. Rodriguez for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { 270203c4805SLuis R. Rodriguez if (i == 8) { 271203c4805SLuis R. Rodriguez qcuOffset = 0; 272203c4805SLuis R. Rodriguez qcuBase++; 273203c4805SLuis R. Rodriguez } 274203c4805SLuis R. Rodriguez 275203c4805SLuis R. Rodriguez if (i == 6) { 276203c4805SLuis R. Rodriguez dcuOffset = 0; 277203c4805SLuis R. Rodriguez dcuBase++; 278203c4805SLuis R. Rodriguez } 279203c4805SLuis R. Rodriguez 280991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 281203c4805SLuis R. Rodriguez "%2d %2x %1x %2x %2x\n", 282203c4805SLuis R. Rodriguez i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset, 283203c4805SLuis R. Rodriguez (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3), 284203c4805SLuis R. Rodriguez val[2] & (0x7 << (i * 3)) >> (i * 3), 285203c4805SLuis R. Rodriguez (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset); 286203c4805SLuis R. Rodriguez } 287203c4805SLuis R. Rodriguez 288991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "\n"); 289203c4805SLuis R. Rodriguez 290991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 291203c4805SLuis R. Rodriguez "qcu_stitch state: %2x qcu_fetch state: %2x\n", 292203c4805SLuis R. Rodriguez (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); 293991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 294203c4805SLuis R. Rodriguez "qcu_complete state: %2x dcu_complete state: %2x\n", 295203c4805SLuis R. Rodriguez (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); 296991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 297203c4805SLuis R. Rodriguez "dcu_arb state: %2x dcu_fp state: %2x\n", 298203c4805SLuis R. Rodriguez (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); 299991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 300203c4805SLuis R. Rodriguez "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", 301203c4805SLuis R. Rodriguez (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); 302991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 303203c4805SLuis R. Rodriguez "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", 304203c4805SLuis R. Rodriguez (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); 305991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 306203c4805SLuis R. Rodriguez "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", 307203c4805SLuis R. Rodriguez (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); 308203c4805SLuis R. Rodriguez 309991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n", 310475a6e4dSLuis R. Rodriguez REG_READ_D(ah, AR_OBS_BUS_1)); 311991a0987SPavel Roskin len += snprintf(buf + len, DMA_BUF_LEN - len, 312475a6e4dSLuis R. Rodriguez "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR)); 313203c4805SLuis R. Rodriguez 3147cf4a2e7SSujith ath9k_ps_restore(sc); 3157cf4a2e7SSujith 3162b87f3aaSDan Carpenter if (len > DMA_BUF_LEN) 3172b87f3aaSDan Carpenter len = DMA_BUF_LEN; 3182b87f3aaSDan Carpenter 319991a0987SPavel Roskin retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 320991a0987SPavel Roskin kfree(buf); 321991a0987SPavel Roskin return retval; 322203c4805SLuis R. Rodriguez } 323203c4805SLuis R. Rodriguez 324203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = { 325203c4805SLuis R. Rodriguez .read = read_file_dma, 326203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 3276038f373SArnd Bergmann .owner = THIS_MODULE, 3286038f373SArnd Bergmann .llseek = default_llseek, 329203c4805SLuis R. Rodriguez }; 330203c4805SLuis R. Rodriguez 331203c4805SLuis R. Rodriguez 332203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status) 333203c4805SLuis R. Rodriguez { 334203c4805SLuis R. Rodriguez if (status) 335203c4805SLuis R. Rodriguez sc->debug.stats.istats.total++; 336a9616f41SLuis R. Rodriguez if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { 337a9616f41SLuis R. Rodriguez if (status & ATH9K_INT_RXLP) 338a9616f41SLuis R. Rodriguez sc->debug.stats.istats.rxlp++; 339a9616f41SLuis R. Rodriguez if (status & ATH9K_INT_RXHP) 340a9616f41SLuis R. Rodriguez sc->debug.stats.istats.rxhp++; 34108578b8fSLuis R. Rodriguez if (status & ATH9K_INT_BB_WATCHDOG) 34208578b8fSLuis R. Rodriguez sc->debug.stats.istats.bb_watchdog++; 343a9616f41SLuis R. Rodriguez } else { 344203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RX) 345203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxok++; 346a9616f41SLuis R. Rodriguez } 347203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXEOL) 348203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxeol++; 349203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXORN) 350203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxorn++; 351203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TX) 352203c4805SLuis R. Rodriguez sc->debug.stats.istats.txok++; 353203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TXURN) 354203c4805SLuis R. Rodriguez sc->debug.stats.istats.txurn++; 355203c4805SLuis R. Rodriguez if (status & ATH9K_INT_MIB) 356203c4805SLuis R. Rodriguez sc->debug.stats.istats.mib++; 357203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXPHY) 358203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxphyerr++; 359203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXKCM) 360203c4805SLuis R. Rodriguez sc->debug.stats.istats.rx_keycache_miss++; 361203c4805SLuis R. Rodriguez if (status & ATH9K_INT_SWBA) 362203c4805SLuis R. Rodriguez sc->debug.stats.istats.swba++; 363203c4805SLuis R. Rodriguez if (status & ATH9K_INT_BMISS) 364203c4805SLuis R. Rodriguez sc->debug.stats.istats.bmiss++; 365203c4805SLuis R. Rodriguez if (status & ATH9K_INT_BNR) 366203c4805SLuis R. Rodriguez sc->debug.stats.istats.bnr++; 367203c4805SLuis R. Rodriguez if (status & ATH9K_INT_CST) 368203c4805SLuis R. Rodriguez sc->debug.stats.istats.cst++; 369203c4805SLuis R. Rodriguez if (status & ATH9K_INT_GTT) 370203c4805SLuis R. Rodriguez sc->debug.stats.istats.gtt++; 371203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TIM) 372203c4805SLuis R. Rodriguez sc->debug.stats.istats.tim++; 373203c4805SLuis R. Rodriguez if (status & ATH9K_INT_CABEND) 374203c4805SLuis R. Rodriguez sc->debug.stats.istats.cabend++; 375203c4805SLuis R. Rodriguez if (status & ATH9K_INT_DTIMSYNC) 376203c4805SLuis R. Rodriguez sc->debug.stats.istats.dtimsync++; 377203c4805SLuis R. Rodriguez if (status & ATH9K_INT_DTIM) 378203c4805SLuis R. Rodriguez sc->debug.stats.istats.dtim++; 3796dde1aabSMohammed Shafi Shajakhan if (status & ATH9K_INT_TSFOOR) 3806dde1aabSMohammed Shafi Shajakhan sc->debug.stats.istats.tsfoor++; 381203c4805SLuis R. Rodriguez } 382203c4805SLuis R. Rodriguez 383203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, 384203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 385203c4805SLuis R. Rodriguez { 386203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 387203c4805SLuis R. Rodriguez char buf[512]; 388203c4805SLuis R. Rodriguez unsigned int len = 0; 389203c4805SLuis R. Rodriguez 390a9616f41SLuis R. Rodriguez if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { 391a9616f41SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 392a9616f41SLuis R. Rodriguez "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp); 393a9616f41SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 394a9616f41SLuis R. Rodriguez "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp); 39508578b8fSLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 39608578b8fSLuis R. Rodriguez "%8s: %10u\n", "WATCHDOG", 39708578b8fSLuis R. Rodriguez sc->debug.stats.istats.bb_watchdog); 398a9616f41SLuis R. Rodriguez } else { 399203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 400203c4805SLuis R. Rodriguez "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok); 401a9616f41SLuis R. Rodriguez } 402203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 403203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol); 404203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 405203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn); 406203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 407203c4805SLuis R. Rodriguez "%8s: %10u\n", "TX", sc->debug.stats.istats.txok); 408203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 409203c4805SLuis R. Rodriguez "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn); 410203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 411203c4805SLuis R. Rodriguez "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib); 412203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 413203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr); 414203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 415203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss); 416203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 417203c4805SLuis R. Rodriguez "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba); 418203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 419203c4805SLuis R. Rodriguez "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss); 420203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 421203c4805SLuis R. Rodriguez "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr); 422203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 423203c4805SLuis R. Rodriguez "%8s: %10u\n", "CST", sc->debug.stats.istats.cst); 424203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 425203c4805SLuis R. Rodriguez "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt); 426203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 427203c4805SLuis R. Rodriguez "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim); 428203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 429203c4805SLuis R. Rodriguez "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend); 430203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 431203c4805SLuis R. Rodriguez "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync); 432203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 433203c4805SLuis R. Rodriguez "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim); 434203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 4356dde1aabSMohammed Shafi Shajakhan "%8s: %10u\n", "TSFOOR", sc->debug.stats.istats.tsfoor); 4366dde1aabSMohammed Shafi Shajakhan len += snprintf(buf + len, sizeof(buf) - len, 437203c4805SLuis R. Rodriguez "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total); 438203c4805SLuis R. Rodriguez 4396dde1aabSMohammed Shafi Shajakhan 4402b87f3aaSDan Carpenter if (len > sizeof(buf)) 4412b87f3aaSDan Carpenter len = sizeof(buf); 4422b87f3aaSDan Carpenter 443203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 444203c4805SLuis R. Rodriguez } 445203c4805SLuis R. Rodriguez 446203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = { 447203c4805SLuis R. Rodriguez .read = read_file_interrupt, 448203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 4496038f373SArnd Bergmann .owner = THIS_MODULE, 4506038f373SArnd Bergmann .llseek = default_llseek, 451203c4805SLuis R. Rodriguez }; 452203c4805SLuis R. Rodriguez 4534e6975f7SBen Greear static const char *channel_type_str(enum nl80211_channel_type t) 4544e6975f7SBen Greear { 4554e6975f7SBen Greear switch (t) { 4564e6975f7SBen Greear case NL80211_CHAN_NO_HT: 4574e6975f7SBen Greear return "no ht"; 4584e6975f7SBen Greear case NL80211_CHAN_HT20: 4594e6975f7SBen Greear return "ht20"; 4604e6975f7SBen Greear case NL80211_CHAN_HT40MINUS: 4614e6975f7SBen Greear return "ht40-"; 4624e6975f7SBen Greear case NL80211_CHAN_HT40PLUS: 4634e6975f7SBen Greear return "ht40+"; 4644e6975f7SBen Greear default: 4654e6975f7SBen Greear return "???"; 4664e6975f7SBen Greear } 4674e6975f7SBen Greear } 4684e6975f7SBen Greear 469203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf, 470203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 471203c4805SLuis R. Rodriguez { 472203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 47334302397SFelix Fietkau struct ieee80211_channel *chan = sc->hw->conf.channel; 4744e6975f7SBen Greear struct ieee80211_conf *conf = &(sc->hw->conf); 475203c4805SLuis R. Rodriguez char buf[512]; 476203c4805SLuis R. Rodriguez unsigned int len = 0; 477203c4805SLuis R. Rodriguez u8 addr[ETH_ALEN]; 47839057512SBen Greear u32 tmp; 479203c4805SLuis R. Rodriguez 480203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 4814e6975f7SBen Greear "%s (chan=%d center-freq: %d MHz channel-type: %d (%s))\n", 48234302397SFelix Fietkau wiphy_name(sc->hw->wiphy), 4838e0167a4SMohammed Shafi Shajakhan ieee80211_frequency_to_channel(chan->center_freq), 4844e6975f7SBen Greear chan->center_freq, 4854e6975f7SBen Greear conf->channel_type, 4864e6975f7SBen Greear channel_type_str(conf->channel_type)); 487203c4805SLuis R. Rodriguez 488c6e38c06SMohammed Shafi Shajakhan ath9k_ps_wakeup(sc); 489475a6e4dSLuis R. Rodriguez put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr); 490475a6e4dSLuis R. Rodriguez put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4); 491203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 492203c4805SLuis R. Rodriguez "addr: %pM\n", addr); 493475a6e4dSLuis R. Rodriguez put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr); 494475a6e4dSLuis R. Rodriguez put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4); 495203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 496203c4805SLuis R. Rodriguez "addrmask: %pM\n", addr); 49739057512SBen Greear tmp = ath9k_hw_getrxfilter(sc->sc_ah); 49879d2b157SRajkumar Manoharan ath9k_ps_restore(sc); 49939057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, 50039057512SBen Greear "rfilt: 0x%x", tmp); 50139057512SBen Greear if (tmp & ATH9K_RX_FILTER_UCAST) 50239057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " UCAST"); 50339057512SBen Greear if (tmp & ATH9K_RX_FILTER_MCAST) 50439057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " MCAST"); 50539057512SBen Greear if (tmp & ATH9K_RX_FILTER_BCAST) 50639057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " BCAST"); 50739057512SBen Greear if (tmp & ATH9K_RX_FILTER_CONTROL) 50839057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " CONTROL"); 50939057512SBen Greear if (tmp & ATH9K_RX_FILTER_BEACON) 51039057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " BEACON"); 51139057512SBen Greear if (tmp & ATH9K_RX_FILTER_PROM) 51239057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " PROM"); 51339057512SBen Greear if (tmp & ATH9K_RX_FILTER_PROBEREQ) 51439057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " PROBEREQ"); 51539057512SBen Greear if (tmp & ATH9K_RX_FILTER_PHYERR) 51639057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " PHYERR"); 51739057512SBen Greear if (tmp & ATH9K_RX_FILTER_MYBEACON) 51839057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " MYBEACON"); 51939057512SBen Greear if (tmp & ATH9K_RX_FILTER_COMP_BAR) 52039057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " COMP_BAR"); 52139057512SBen Greear if (tmp & ATH9K_RX_FILTER_PSPOLL) 52239057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " PSPOLL"); 52339057512SBen Greear if (tmp & ATH9K_RX_FILTER_PHYRADAR) 52439057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " PHYRADAR"); 52539057512SBen Greear if (tmp & ATH9K_RX_FILTER_MCAST_BCAST_ALL) 52639057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, " MCAST_BCAST_ALL\n"); 52739057512SBen Greear else 52839057512SBen Greear len += snprintf(buf + len, sizeof(buf) - len, "\n"); 529203c4805SLuis R. Rodriguez 5302b87f3aaSDan Carpenter if (len > sizeof(buf)) 5312b87f3aaSDan Carpenter len = sizeof(buf); 5322b87f3aaSDan Carpenter 533203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 534203c4805SLuis R. Rodriguez } 535203c4805SLuis R. Rodriguez 536203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = { 537203c4805SLuis R. Rodriguez .read = read_file_wiphy, 538203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 5396038f373SArnd Bergmann .owner = THIS_MODULE, 5406038f373SArnd Bergmann .llseek = default_llseek, 541203c4805SLuis R. Rodriguez }; 542203c4805SLuis R. Rodriguez 5435bec3e5aSFelix Fietkau #define PR_QNUM(_n) sc->tx.txq_map[_n]->axq_qnum 544fec247c0SSujith #define PR(str, elem) \ 545fec247c0SSujith do { \ 546fec247c0SSujith len += snprintf(buf + len, size - len, \ 547fec247c0SSujith "%s%13u%11u%10u%10u\n", str, \ 5485bec3e5aSFelix Fietkau sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem, \ 5495bec3e5aSFelix Fietkau sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem, \ 5505bec3e5aSFelix Fietkau sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem, \ 5515bec3e5aSFelix Fietkau sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem); \ 5527f010c93SBen Greear if (len >= size) \ 5537f010c93SBen Greear goto done; \ 554fec247c0SSujith } while(0) 555fec247c0SSujith 5561f427dd9SBen Greear #define PRX(str, elem) \ 5571f427dd9SBen Greear do { \ 5581f427dd9SBen Greear len += snprintf(buf + len, size - len, \ 5591f427dd9SBen Greear "%s%13u%11u%10u%10u\n", str, \ 5605bec3e5aSFelix Fietkau (unsigned int)(sc->tx.txq_map[WME_AC_BE]->elem), \ 5615bec3e5aSFelix Fietkau (unsigned int)(sc->tx.txq_map[WME_AC_BK]->elem), \ 5625bec3e5aSFelix Fietkau (unsigned int)(sc->tx.txq_map[WME_AC_VI]->elem), \ 5635bec3e5aSFelix Fietkau (unsigned int)(sc->tx.txq_map[WME_AC_VO]->elem)); \ 5647f010c93SBen Greear if (len >= size) \ 5657f010c93SBen Greear goto done; \ 5661f427dd9SBen Greear } while(0) 5671f427dd9SBen Greear 5682dac4fb9SBen Greear #define PRQLE(str, elem) \ 5692dac4fb9SBen Greear do { \ 5702dac4fb9SBen Greear len += snprintf(buf + len, size - len, \ 5712dac4fb9SBen Greear "%s%13i%11i%10i%10i\n", str, \ 5725bec3e5aSFelix Fietkau list_empty(&sc->tx.txq_map[WME_AC_BE]->elem), \ 5735bec3e5aSFelix Fietkau list_empty(&sc->tx.txq_map[WME_AC_BK]->elem), \ 5745bec3e5aSFelix Fietkau list_empty(&sc->tx.txq_map[WME_AC_VI]->elem), \ 5755bec3e5aSFelix Fietkau list_empty(&sc->tx.txq_map[WME_AC_VO]->elem)); \ 5767f010c93SBen Greear if (len >= size) \ 5777f010c93SBen Greear goto done; \ 5782dac4fb9SBen Greear } while (0) 5792dac4fb9SBen Greear 580fec247c0SSujith static ssize_t read_file_xmit(struct file *file, char __user *user_buf, 581fec247c0SSujith size_t count, loff_t *ppos) 582fec247c0SSujith { 583fec247c0SSujith struct ath_softc *sc = file->private_data; 584fec247c0SSujith char *buf; 5857f010c93SBen Greear unsigned int len = 0, size = 8000; 5862dac4fb9SBen Greear int i; 587fec247c0SSujith ssize_t retval = 0; 5882dac4fb9SBen Greear char tmp[32]; 589fec247c0SSujith 590fec247c0SSujith buf = kzalloc(size, GFP_KERNEL); 591fec247c0SSujith if (buf == NULL) 59204236066SDan Carpenter return -ENOMEM; 593fec247c0SSujith 59460f2d1d5SBen Greear len += sprintf(buf, "Num-Tx-Queues: %i tx-queues-setup: 0x%x" 59560f2d1d5SBen Greear " poll-work-seen: %u\n" 5967f010c93SBen Greear "%30s %10s%10s%10s\n\n", 5977f010c93SBen Greear ATH9K_NUM_TX_QUEUES, sc->tx.txqsetup, 59860f2d1d5SBen Greear sc->tx_complete_poll_work_seen, 5997f010c93SBen Greear "BE", "BK", "VI", "VO"); 600fec247c0SSujith 601fec247c0SSujith PR("MPDUs Queued: ", queued); 602fec247c0SSujith PR("MPDUs Completed: ", completed); 603*5a6f78afSFelix Fietkau PR("MPDUs XRetried: ", xretries); 604fec247c0SSujith PR("Aggregates: ", a_aggr); 605bda8addaSBen Greear PR("AMPDUs Queued HW:", a_queued_hw); 606bda8addaSBen Greear PR("AMPDUs Queued SW:", a_queued_sw); 607fec247c0SSujith PR("AMPDUs Completed:", a_completed); 608fec247c0SSujith PR("AMPDUs Retried: ", a_retries); 609fec247c0SSujith PR("AMPDUs XRetried: ", a_xretries); 610fec247c0SSujith PR("FIFO Underrun: ", fifo_underrun); 611fec247c0SSujith PR("TXOP Exceeded: ", xtxop); 612fec247c0SSujith PR("TXTIMER Expiry: ", timer_exp); 613fec247c0SSujith PR("DESC CFG Error: ", desc_cfg_err); 614fec247c0SSujith PR("DATA Underrun: ", data_underrun); 615fec247c0SSujith PR("DELIM Underrun: ", delim_underrun); 61699c15bf5SBen Greear PR("TX-Pkts-All: ", tx_pkts_all); 61799c15bf5SBen Greear PR("TX-Bytes-All: ", tx_bytes_all); 6182dac4fb9SBen Greear PR("hw-put-tx-buf: ", puttxbuf); 6192dac4fb9SBen Greear PR("hw-tx-start: ", txstart); 6202dac4fb9SBen Greear PR("hw-tx-proc-desc: ", txprocdesc); 6217f010c93SBen Greear len += snprintf(buf + len, size - len, 6227f010c93SBen Greear "%s%11p%11p%10p%10p\n", "txq-memory-address:", 623db7889cdSBen Greear sc->tx.txq_map[WME_AC_BE], 624db7889cdSBen Greear sc->tx.txq_map[WME_AC_BK], 625db7889cdSBen Greear sc->tx.txq_map[WME_AC_VI], 626db7889cdSBen Greear sc->tx.txq_map[WME_AC_VO]); 6277f010c93SBen Greear if (len >= size) 6287f010c93SBen Greear goto done; 629fec247c0SSujith 6301f427dd9SBen Greear PRX("axq-qnum: ", axq_qnum); 6311f427dd9SBen Greear PRX("axq-depth: ", axq_depth); 6322dac4fb9SBen Greear PRX("axq-ampdu_depth: ", axq_ampdu_depth); 6331f427dd9SBen Greear PRX("axq-stopped ", stopped); 6341f427dd9SBen Greear PRX("tx-in-progress ", axq_tx_inprogress); 6351f427dd9SBen Greear PRX("pending-frames ", pending_frames); 6362dac4fb9SBen Greear PRX("txq_headidx: ", txq_headidx); 6372dac4fb9SBen Greear PRX("txq_tailidx: ", txq_headidx); 6381f427dd9SBen Greear 6392dac4fb9SBen Greear PRQLE("axq_q empty: ", axq_q); 6402dac4fb9SBen Greear PRQLE("axq_acq empty: ", axq_acq); 6412dac4fb9SBen Greear for (i = 0; i < ATH_TXFIFO_DEPTH; i++) { 6422dac4fb9SBen Greear snprintf(tmp, sizeof(tmp) - 1, "txq_fifo[%i] empty: ", i); 6432dac4fb9SBen Greear PRQLE(tmp, txq_fifo[i]); 6442dac4fb9SBen Greear } 6457f010c93SBen Greear 64671e025a5SBen Greear /* Print out more detailed queue-info */ 64771e025a5SBen Greear for (i = 0; i <= WME_AC_BK; i++) { 64871e025a5SBen Greear struct ath_txq *txq = &(sc->tx.txq[i]); 64971e025a5SBen Greear struct ath_atx_ac *ac; 65071e025a5SBen Greear struct ath_atx_tid *tid; 65171e025a5SBen Greear if (len >= size) 65271e025a5SBen Greear goto done; 65371e025a5SBen Greear spin_lock_bh(&txq->axq_lock); 65471e025a5SBen Greear if (!list_empty(&txq->axq_acq)) { 65571e025a5SBen Greear ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, 65671e025a5SBen Greear list); 65771e025a5SBen Greear len += snprintf(buf + len, size - len, 65871e025a5SBen Greear "txq[%i] first-ac: %p sched: %i\n", 65971e025a5SBen Greear i, ac, ac->sched); 66071e025a5SBen Greear if (list_empty(&ac->tid_q) || (len >= size)) 66171e025a5SBen Greear goto done_for; 66271e025a5SBen Greear tid = list_first_entry(&ac->tid_q, struct ath_atx_tid, 66371e025a5SBen Greear list); 66471e025a5SBen Greear len += snprintf(buf + len, size - len, 66571e025a5SBen Greear " first-tid: %p sched: %i paused: %i\n", 66671e025a5SBen Greear tid, tid->sched, tid->paused); 66771e025a5SBen Greear } 66871e025a5SBen Greear done_for: 66971e025a5SBen Greear spin_unlock_bh(&txq->axq_lock); 67071e025a5SBen Greear } 67171e025a5SBen Greear 6727f010c93SBen Greear done: 6737f010c93SBen Greear if (len > size) 6747f010c93SBen Greear len = size; 6757f010c93SBen Greear 6767f010c93SBen Greear retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 6777f010c93SBen Greear kfree(buf); 6787f010c93SBen Greear 6797f010c93SBen Greear return retval; 6807f010c93SBen Greear } 6817f010c93SBen Greear 6827f010c93SBen Greear static ssize_t read_file_stations(struct file *file, char __user *user_buf, 6837f010c93SBen Greear size_t count, loff_t *ppos) 6847f010c93SBen Greear { 6857f010c93SBen Greear struct ath_softc *sc = file->private_data; 6867f010c93SBen Greear char *buf; 6877f010c93SBen Greear unsigned int len = 0, size = 64000; 6887f010c93SBen Greear struct ath_node *an = NULL; 6897f010c93SBen Greear ssize_t retval = 0; 6907f010c93SBen Greear int q; 6917f010c93SBen Greear 6927f010c93SBen Greear buf = kzalloc(size, GFP_KERNEL); 6937f010c93SBen Greear if (buf == NULL) 6947f010c93SBen Greear return -ENOMEM; 6957f010c93SBen Greear 6967f010c93SBen Greear len += snprintf(buf + len, size - len, 6977f010c93SBen Greear "Stations:\n" 6987f010c93SBen Greear " tid: addr sched paused buf_q-empty an ac\n" 6997f010c93SBen Greear " ac: addr sched tid_q-empty txq\n"); 7007f010c93SBen Greear 7017f010c93SBen Greear spin_lock(&sc->nodes_lock); 7027f010c93SBen Greear list_for_each_entry(an, &sc->nodes, list) { 7037f010c93SBen Greear len += snprintf(buf + len, size - len, 7047f010c93SBen Greear "%pM\n", an->sta->addr); 7057f010c93SBen Greear if (len >= size) 7067f010c93SBen Greear goto done; 7077f010c93SBen Greear 7087f010c93SBen Greear for (q = 0; q < WME_NUM_TID; q++) { 7097f010c93SBen Greear struct ath_atx_tid *tid = &(an->tid[q]); 7107f010c93SBen Greear len += snprintf(buf + len, size - len, 7117f010c93SBen Greear " tid: %p %s %s %i %p %p\n", 7127f010c93SBen Greear tid, tid->sched ? "sched" : "idle", 7137f010c93SBen Greear tid->paused ? "paused" : "running", 7147f010c93SBen Greear list_empty(&tid->buf_q), 7157f010c93SBen Greear tid->an, tid->ac); 7167f010c93SBen Greear if (len >= size) 7177f010c93SBen Greear goto done; 7187f010c93SBen Greear } 7197f010c93SBen Greear 7207f010c93SBen Greear for (q = 0; q < WME_NUM_AC; q++) { 7217f010c93SBen Greear struct ath_atx_ac *ac = &(an->ac[q]); 7227f010c93SBen Greear len += snprintf(buf + len, size - len, 7237f010c93SBen Greear " ac: %p %s %i %p\n", 7247f010c93SBen Greear ac, ac->sched ? "sched" : "idle", 7257f010c93SBen Greear list_empty(&ac->tid_q), ac->txq); 7267f010c93SBen Greear if (len >= size) 7277f010c93SBen Greear goto done; 7287f010c93SBen Greear } 7297f010c93SBen Greear } 7307f010c93SBen Greear 7317f010c93SBen Greear done: 7327f010c93SBen Greear spin_unlock(&sc->nodes_lock); 7332b87f3aaSDan Carpenter if (len > size) 7342b87f3aaSDan Carpenter len = size; 7352b87f3aaSDan Carpenter 736fec247c0SSujith retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 737fec247c0SSujith kfree(buf); 738fec247c0SSujith 739fec247c0SSujith return retval; 740fec247c0SSujith } 741fec247c0SSujith 74255f6d0ffSBen Greear static ssize_t read_file_misc(struct file *file, char __user *user_buf, 74355f6d0ffSBen Greear size_t count, loff_t *ppos) 74455f6d0ffSBen Greear { 74555f6d0ffSBen Greear struct ath_softc *sc = file->private_data; 74655f6d0ffSBen Greear struct ath_common *common = ath9k_hw_common(sc->sc_ah); 74755f6d0ffSBen Greear struct ath_hw *ah = sc->sc_ah; 74855f6d0ffSBen Greear struct ieee80211_hw *hw = sc->hw; 74955f6d0ffSBen Greear char *buf; 75055f6d0ffSBen Greear unsigned int len = 0, size = 8000; 75155f6d0ffSBen Greear ssize_t retval = 0; 75255f6d0ffSBen Greear const char *tmp; 75355f6d0ffSBen Greear unsigned int reg; 75455f6d0ffSBen Greear struct ath9k_vif_iter_data iter_data; 75555f6d0ffSBen Greear 75655f6d0ffSBen Greear ath9k_calculate_iter_data(hw, NULL, &iter_data); 75755f6d0ffSBen Greear 75855f6d0ffSBen Greear buf = kzalloc(size, GFP_KERNEL); 75955f6d0ffSBen Greear if (buf == NULL) 76055f6d0ffSBen Greear return -ENOMEM; 76155f6d0ffSBen Greear 76255f6d0ffSBen Greear switch (sc->sc_ah->opmode) { 76355f6d0ffSBen Greear case NL80211_IFTYPE_ADHOC: 76455f6d0ffSBen Greear tmp = "ADHOC"; 76555f6d0ffSBen Greear break; 76655f6d0ffSBen Greear case NL80211_IFTYPE_MESH_POINT: 76755f6d0ffSBen Greear tmp = "MESH"; 76855f6d0ffSBen Greear break; 76955f6d0ffSBen Greear case NL80211_IFTYPE_AP: 77055f6d0ffSBen Greear tmp = "AP"; 77155f6d0ffSBen Greear break; 77255f6d0ffSBen Greear case NL80211_IFTYPE_STATION: 77355f6d0ffSBen Greear tmp = "STATION"; 77455f6d0ffSBen Greear break; 77555f6d0ffSBen Greear default: 77655f6d0ffSBen Greear tmp = "???"; 77755f6d0ffSBen Greear break; 77855f6d0ffSBen Greear } 77955f6d0ffSBen Greear 78079d2b157SRajkumar Manoharan ath9k_ps_wakeup(sc); 78155f6d0ffSBen Greear len += snprintf(buf + len, size - len, 78255f6d0ffSBen Greear "curbssid: %pM\n" 78355f6d0ffSBen Greear "OP-Mode: %s(%i)\n" 78455f6d0ffSBen Greear "Beacon-Timer-Register: 0x%x\n", 78555f6d0ffSBen Greear common->curbssid, 78655f6d0ffSBen Greear tmp, (int)(sc->sc_ah->opmode), 78755f6d0ffSBen Greear REG_READ(ah, AR_BEACON_PERIOD)); 78855f6d0ffSBen Greear 78955f6d0ffSBen Greear reg = REG_READ(ah, AR_TIMER_MODE); 79079d2b157SRajkumar Manoharan ath9k_ps_restore(sc); 79155f6d0ffSBen Greear len += snprintf(buf + len, size - len, "Timer-Mode-Register: 0x%x (", 79255f6d0ffSBen Greear reg); 79355f6d0ffSBen Greear if (reg & AR_TBTT_TIMER_EN) 79455f6d0ffSBen Greear len += snprintf(buf + len, size - len, "TBTT "); 79555f6d0ffSBen Greear if (reg & AR_DBA_TIMER_EN) 79655f6d0ffSBen Greear len += snprintf(buf + len, size - len, "DBA "); 79755f6d0ffSBen Greear if (reg & AR_SWBA_TIMER_EN) 79855f6d0ffSBen Greear len += snprintf(buf + len, size - len, "SWBA "); 79955f6d0ffSBen Greear if (reg & AR_HCF_TIMER_EN) 80055f6d0ffSBen Greear len += snprintf(buf + len, size - len, "HCF "); 80155f6d0ffSBen Greear if (reg & AR_TIM_TIMER_EN) 80255f6d0ffSBen Greear len += snprintf(buf + len, size - len, "TIM "); 80355f6d0ffSBen Greear if (reg & AR_DTIM_TIMER_EN) 80455f6d0ffSBen Greear len += snprintf(buf + len, size - len, "DTIM "); 80555f6d0ffSBen Greear len += snprintf(buf + len, size - len, ")\n"); 80655f6d0ffSBen Greear 80755f6d0ffSBen Greear reg = sc->sc_ah->imask; 80855f6d0ffSBen Greear len += snprintf(buf + len, size - len, "imask: 0x%x (", reg); 80955f6d0ffSBen Greear if (reg & ATH9K_INT_SWBA) 81055f6d0ffSBen Greear len += snprintf(buf + len, size - len, "SWBA "); 81155f6d0ffSBen Greear if (reg & ATH9K_INT_BMISS) 81255f6d0ffSBen Greear len += snprintf(buf + len, size - len, "BMISS "); 81355f6d0ffSBen Greear if (reg & ATH9K_INT_CST) 81455f6d0ffSBen Greear len += snprintf(buf + len, size - len, "CST "); 81555f6d0ffSBen Greear if (reg & ATH9K_INT_RX) 81655f6d0ffSBen Greear len += snprintf(buf + len, size - len, "RX "); 81755f6d0ffSBen Greear if (reg & ATH9K_INT_RXHP) 81855f6d0ffSBen Greear len += snprintf(buf + len, size - len, "RXHP "); 81955f6d0ffSBen Greear if (reg & ATH9K_INT_RXLP) 82055f6d0ffSBen Greear len += snprintf(buf + len, size - len, "RXLP "); 82155f6d0ffSBen Greear if (reg & ATH9K_INT_BB_WATCHDOG) 82255f6d0ffSBen Greear len += snprintf(buf + len, size - len, "BB_WATCHDOG "); 82355f6d0ffSBen Greear /* there are other IRQs if one wanted to add them. */ 82455f6d0ffSBen Greear len += snprintf(buf + len, size - len, ")\n"); 82555f6d0ffSBen Greear 82655f6d0ffSBen Greear len += snprintf(buf + len, size - len, 82755f6d0ffSBen Greear "VIF Counts: AP: %i STA: %i MESH: %i WDS: %i" 82855f6d0ffSBen Greear " ADHOC: %i OTHER: %i nvifs: %hi beacon-vifs: %hi\n", 82955f6d0ffSBen Greear iter_data.naps, iter_data.nstations, iter_data.nmeshes, 83055f6d0ffSBen Greear iter_data.nwds, iter_data.nadhocs, iter_data.nothers, 83155f6d0ffSBen Greear sc->nvifs, sc->nbcnvifs); 83255f6d0ffSBen Greear 83355f6d0ffSBen Greear len += snprintf(buf + len, size - len, 83455f6d0ffSBen Greear "Calculated-BSSID-Mask: %pM\n", 83555f6d0ffSBen Greear iter_data.mask); 83655f6d0ffSBen Greear 83755f6d0ffSBen Greear if (len > size) 83855f6d0ffSBen Greear len = size; 83955f6d0ffSBen Greear 84055f6d0ffSBen Greear retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 84155f6d0ffSBen Greear kfree(buf); 84255f6d0ffSBen Greear 84355f6d0ffSBen Greear return retval; 84455f6d0ffSBen Greear } 84555f6d0ffSBen Greear 846066dae93SFelix Fietkau void ath_debug_stat_tx(struct ath_softc *sc, struct ath_buf *bf, 8475bec3e5aSFelix Fietkau struct ath_tx_status *ts, struct ath_txq *txq) 848fec247c0SSujith { 8495bec3e5aSFelix Fietkau int qnum = txq->axq_qnum; 850066dae93SFelix Fietkau 851066dae93SFelix Fietkau TX_STAT_INC(qnum, tx_pkts_all); 852066dae93SFelix Fietkau sc->debug.stats.txstats[qnum].tx_bytes_all += bf->bf_mpdu->len; 85399c15bf5SBen Greear 854fec247c0SSujith if (bf_isampdu(bf)) { 855fec247c0SSujith if (bf_isxretried(bf)) 856066dae93SFelix Fietkau TX_STAT_INC(qnum, a_xretries); 857fec247c0SSujith else 858066dae93SFelix Fietkau TX_STAT_INC(qnum, a_completed); 859fec247c0SSujith } else { 860*5a6f78afSFelix Fietkau if (bf_isxretried(bf)) 861*5a6f78afSFelix Fietkau TX_STAT_INC(qnum, xretries); 862*5a6f78afSFelix Fietkau else 863066dae93SFelix Fietkau TX_STAT_INC(qnum, completed); 864fec247c0SSujith } 865fec247c0SSujith 866db1a052bSFelix Fietkau if (ts->ts_status & ATH9K_TXERR_FIFO) 867066dae93SFelix Fietkau TX_STAT_INC(qnum, fifo_underrun); 868db1a052bSFelix Fietkau if (ts->ts_status & ATH9K_TXERR_XTXOP) 869066dae93SFelix Fietkau TX_STAT_INC(qnum, xtxop); 870db1a052bSFelix Fietkau if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED) 871066dae93SFelix Fietkau TX_STAT_INC(qnum, timer_exp); 872db1a052bSFelix Fietkau if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR) 873066dae93SFelix Fietkau TX_STAT_INC(qnum, desc_cfg_err); 874db1a052bSFelix Fietkau if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN) 875066dae93SFelix Fietkau TX_STAT_INC(qnum, data_underrun); 876db1a052bSFelix Fietkau if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN) 877066dae93SFelix Fietkau TX_STAT_INC(qnum, delim_underrun); 878fec247c0SSujith } 879fec247c0SSujith 880fec247c0SSujith static const struct file_operations fops_xmit = { 881fec247c0SSujith .read = read_file_xmit, 882fec247c0SSujith .open = ath9k_debugfs_open, 8836038f373SArnd Bergmann .owner = THIS_MODULE, 8846038f373SArnd Bergmann .llseek = default_llseek, 885fec247c0SSujith }; 886203c4805SLuis R. Rodriguez 8877f010c93SBen Greear static const struct file_operations fops_stations = { 8887f010c93SBen Greear .read = read_file_stations, 8897f010c93SBen Greear .open = ath9k_debugfs_open, 8907f010c93SBen Greear .owner = THIS_MODULE, 8917f010c93SBen Greear .llseek = default_llseek, 8927f010c93SBen Greear }; 8937f010c93SBen Greear 89455f6d0ffSBen Greear static const struct file_operations fops_misc = { 89555f6d0ffSBen Greear .read = read_file_misc, 89655f6d0ffSBen Greear .open = ath9k_debugfs_open, 89755f6d0ffSBen Greear .owner = THIS_MODULE, 89855f6d0ffSBen Greear .llseek = default_llseek, 89955f6d0ffSBen Greear }; 90055f6d0ffSBen Greear 9011395d3f0SSujith static ssize_t read_file_recv(struct file *file, char __user *user_buf, 9021395d3f0SSujith size_t count, loff_t *ppos) 9031395d3f0SSujith { 9041395d3f0SSujith #define PHY_ERR(s, p) \ 9051395d3f0SSujith len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \ 9061395d3f0SSujith sc->debug.stats.rxstats.phy_err_stats[p]); 9071395d3f0SSujith 9081395d3f0SSujith struct ath_softc *sc = file->private_data; 9091395d3f0SSujith char *buf; 9107d755414SSenthil Balasubramanian unsigned int len = 0, size = 1400; 9111395d3f0SSujith ssize_t retval = 0; 9121395d3f0SSujith 9131395d3f0SSujith buf = kzalloc(size, GFP_KERNEL); 9141395d3f0SSujith if (buf == NULL) 91504236066SDan Carpenter return -ENOMEM; 9161395d3f0SSujith 9171395d3f0SSujith len += snprintf(buf + len, size - len, 9181395d3f0SSujith "%18s : %10u\n", "CRC ERR", 9191395d3f0SSujith sc->debug.stats.rxstats.crc_err); 9201395d3f0SSujith len += snprintf(buf + len, size - len, 9211395d3f0SSujith "%18s : %10u\n", "DECRYPT CRC ERR", 9221395d3f0SSujith sc->debug.stats.rxstats.decrypt_crc_err); 9231395d3f0SSujith len += snprintf(buf + len, size - len, 9241395d3f0SSujith "%18s : %10u\n", "PHY ERR", 9251395d3f0SSujith sc->debug.stats.rxstats.phy_err); 9261395d3f0SSujith len += snprintf(buf + len, size - len, 9271395d3f0SSujith "%18s : %10u\n", "MIC ERR", 9281395d3f0SSujith sc->debug.stats.rxstats.mic_err); 9291395d3f0SSujith len += snprintf(buf + len, size - len, 9301395d3f0SSujith "%18s : %10u\n", "PRE-DELIM CRC ERR", 9311395d3f0SSujith sc->debug.stats.rxstats.pre_delim_crc_err); 9321395d3f0SSujith len += snprintf(buf + len, size - len, 9331395d3f0SSujith "%18s : %10u\n", "POST-DELIM CRC ERR", 9341395d3f0SSujith sc->debug.stats.rxstats.post_delim_crc_err); 9351395d3f0SSujith len += snprintf(buf + len, size - len, 9361395d3f0SSujith "%18s : %10u\n", "DECRYPT BUSY ERR", 9371395d3f0SSujith sc->debug.stats.rxstats.decrypt_busy_err); 9381395d3f0SSujith 9397d755414SSenthil Balasubramanian len += snprintf(buf + len, size - len, 9407d755414SSenthil Balasubramanian "%18s : %10d\n", "RSSI-CTL0", 9417d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ctl0); 9427d755414SSenthil Balasubramanian 9437d755414SSenthil Balasubramanian len += snprintf(buf + len, size - len, 9447d755414SSenthil Balasubramanian "%18s : %10d\n", "RSSI-CTL1", 9457d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ctl1); 9467d755414SSenthil Balasubramanian 9477d755414SSenthil Balasubramanian len += snprintf(buf + len, size - len, 9487d755414SSenthil Balasubramanian "%18s : %10d\n", "RSSI-CTL2", 9497d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ctl2); 9507d755414SSenthil Balasubramanian 9517d755414SSenthil Balasubramanian len += snprintf(buf + len, size - len, 9527d755414SSenthil Balasubramanian "%18s : %10d\n", "RSSI-EXT0", 9537d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ext0); 9547d755414SSenthil Balasubramanian 9557d755414SSenthil Balasubramanian len += snprintf(buf + len, size - len, 9567d755414SSenthil Balasubramanian "%18s : %10d\n", "RSSI-EXT1", 9577d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ext1); 9587d755414SSenthil Balasubramanian 9597d755414SSenthil Balasubramanian len += snprintf(buf + len, size - len, 9607d755414SSenthil Balasubramanian "%18s : %10d\n", "RSSI-EXT2", 9617d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ext2); 9627d755414SSenthil Balasubramanian 9637d755414SSenthil Balasubramanian len += snprintf(buf + len, size - len, 9647d755414SSenthil Balasubramanian "%18s : %10d\n", "Rx Antenna", 9657d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_antenna); 9667d755414SSenthil Balasubramanian 9671395d3f0SSujith PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN); 9681395d3f0SSujith PHY_ERR("TIMING", ATH9K_PHYERR_TIMING); 9691395d3f0SSujith PHY_ERR("PARITY", ATH9K_PHYERR_PARITY); 9701395d3f0SSujith PHY_ERR("RATE", ATH9K_PHYERR_RATE); 9711395d3f0SSujith PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH); 9721395d3f0SSujith PHY_ERR("RADAR", ATH9K_PHYERR_RADAR); 9731395d3f0SSujith PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE); 9741395d3f0SSujith PHY_ERR("TOR", ATH9K_PHYERR_TOR); 9751395d3f0SSujith PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING); 9761395d3f0SSujith PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY); 9771395d3f0SSujith PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL); 9781395d3f0SSujith PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL); 9791395d3f0SSujith PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP); 9801395d3f0SSujith PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE); 9811395d3f0SSujith PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART); 9821395d3f0SSujith PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT); 9831395d3f0SSujith PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING); 9841395d3f0SSujith PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC); 9851395d3f0SSujith PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL); 9861395d3f0SSujith PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE); 9871395d3f0SSujith PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART); 9881395d3f0SSujith PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL); 9891395d3f0SSujith PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP); 9901395d3f0SSujith PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR); 9911395d3f0SSujith PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL); 9921395d3f0SSujith PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL); 9931395d3f0SSujith 99499c15bf5SBen Greear len += snprintf(buf + len, size - len, 99599c15bf5SBen Greear "%18s : %10u\n", "RX-Pkts-All", 99699c15bf5SBen Greear sc->debug.stats.rxstats.rx_pkts_all); 99799c15bf5SBen Greear len += snprintf(buf + len, size - len, 99899c15bf5SBen Greear "%18s : %10u\n", "RX-Bytes-All", 99999c15bf5SBen Greear sc->debug.stats.rxstats.rx_bytes_all); 100099c15bf5SBen Greear 10012b87f3aaSDan Carpenter if (len > size) 10022b87f3aaSDan Carpenter len = size; 10032b87f3aaSDan Carpenter 10041395d3f0SSujith retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 10051395d3f0SSujith kfree(buf); 10061395d3f0SSujith 10071395d3f0SSujith return retval; 10081395d3f0SSujith 10091395d3f0SSujith #undef PHY_ERR 10101395d3f0SSujith } 10111395d3f0SSujith 10128e6f5aa2SFelix Fietkau void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs) 10131395d3f0SSujith { 10141395d3f0SSujith #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++ 10151395d3f0SSujith #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++ 10161395d3f0SSujith 10171395d3f0SSujith u32 phyerr; 10181395d3f0SSujith 101999c15bf5SBen Greear RX_STAT_INC(rx_pkts_all); 102099c15bf5SBen Greear sc->debug.stats.rxstats.rx_bytes_all += rs->rs_datalen; 102199c15bf5SBen Greear 10228e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RXERR_CRC) 10231395d3f0SSujith RX_STAT_INC(crc_err); 10248e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RXERR_DECRYPT) 10251395d3f0SSujith RX_STAT_INC(decrypt_crc_err); 10268e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RXERR_MIC) 10271395d3f0SSujith RX_STAT_INC(mic_err); 10288e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE) 10291395d3f0SSujith RX_STAT_INC(pre_delim_crc_err); 10308e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST) 10311395d3f0SSujith RX_STAT_INC(post_delim_crc_err); 10328e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY) 10331395d3f0SSujith RX_STAT_INC(decrypt_busy_err); 10341395d3f0SSujith 10358e6f5aa2SFelix Fietkau if (rs->rs_status & ATH9K_RXERR_PHY) { 10361395d3f0SSujith RX_STAT_INC(phy_err); 10378e6f5aa2SFelix Fietkau phyerr = rs->rs_phyerr & 0x24; 10381395d3f0SSujith RX_PHY_ERR_INC(phyerr); 10391395d3f0SSujith } 10401395d3f0SSujith 10417d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ctl0 = rs->rs_rssi_ctl0; 10427d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ctl1 = rs->rs_rssi_ctl1; 10437d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ctl2 = rs->rs_rssi_ctl2; 10447d755414SSenthil Balasubramanian 10457d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ext0 = rs->rs_rssi_ext0; 10467d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ext1 = rs->rs_rssi_ext1; 10477d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_rssi_ext2 = rs->rs_rssi_ext2; 10487d755414SSenthil Balasubramanian 10497d755414SSenthil Balasubramanian sc->debug.stats.rxstats.rs_antenna = rs->rs_antenna; 10507d755414SSenthil Balasubramanian 10511395d3f0SSujith #undef RX_STAT_INC 10521395d3f0SSujith #undef RX_PHY_ERR_INC 10531395d3f0SSujith } 10541395d3f0SSujith 10551395d3f0SSujith static const struct file_operations fops_recv = { 10561395d3f0SSujith .read = read_file_recv, 10571395d3f0SSujith .open = ath9k_debugfs_open, 10586038f373SArnd Bergmann .owner = THIS_MODULE, 10596038f373SArnd Bergmann .llseek = default_llseek, 10601395d3f0SSujith }; 10611395d3f0SSujith 10629bff0bc4SFelix Fietkau static ssize_t read_file_regidx(struct file *file, char __user *user_buf, 10639bff0bc4SFelix Fietkau size_t count, loff_t *ppos) 10649bff0bc4SFelix Fietkau { 10659bff0bc4SFelix Fietkau struct ath_softc *sc = file->private_data; 10669bff0bc4SFelix Fietkau char buf[32]; 10679bff0bc4SFelix Fietkau unsigned int len; 10689bff0bc4SFelix Fietkau 10692b87f3aaSDan Carpenter len = sprintf(buf, "0x%08x\n", sc->debug.regidx); 10709bff0bc4SFelix Fietkau return simple_read_from_buffer(user_buf, count, ppos, buf, len); 10719bff0bc4SFelix Fietkau } 10729bff0bc4SFelix Fietkau 10739bff0bc4SFelix Fietkau static ssize_t write_file_regidx(struct file *file, const char __user *user_buf, 10749bff0bc4SFelix Fietkau size_t count, loff_t *ppos) 10759bff0bc4SFelix Fietkau { 10769bff0bc4SFelix Fietkau struct ath_softc *sc = file->private_data; 10779bff0bc4SFelix Fietkau unsigned long regidx; 10789bff0bc4SFelix Fietkau char buf[32]; 10799bff0bc4SFelix Fietkau ssize_t len; 10809bff0bc4SFelix Fietkau 10819bff0bc4SFelix Fietkau len = min(count, sizeof(buf) - 1); 10829bff0bc4SFelix Fietkau if (copy_from_user(buf, user_buf, len)) 108304236066SDan Carpenter return -EFAULT; 10849bff0bc4SFelix Fietkau 10859bff0bc4SFelix Fietkau buf[len] = '\0'; 10869bff0bc4SFelix Fietkau if (strict_strtoul(buf, 0, ®idx)) 10879bff0bc4SFelix Fietkau return -EINVAL; 10889bff0bc4SFelix Fietkau 10899bff0bc4SFelix Fietkau sc->debug.regidx = regidx; 10909bff0bc4SFelix Fietkau return count; 10919bff0bc4SFelix Fietkau } 10929bff0bc4SFelix Fietkau 10939bff0bc4SFelix Fietkau static const struct file_operations fops_regidx = { 10949bff0bc4SFelix Fietkau .read = read_file_regidx, 10959bff0bc4SFelix Fietkau .write = write_file_regidx, 10969bff0bc4SFelix Fietkau .open = ath9k_debugfs_open, 10976038f373SArnd Bergmann .owner = THIS_MODULE, 10986038f373SArnd Bergmann .llseek = default_llseek, 10999bff0bc4SFelix Fietkau }; 11009bff0bc4SFelix Fietkau 11019bff0bc4SFelix Fietkau static ssize_t read_file_regval(struct file *file, char __user *user_buf, 11029bff0bc4SFelix Fietkau size_t count, loff_t *ppos) 11039bff0bc4SFelix Fietkau { 11049bff0bc4SFelix Fietkau struct ath_softc *sc = file->private_data; 11059bff0bc4SFelix Fietkau struct ath_hw *ah = sc->sc_ah; 11069bff0bc4SFelix Fietkau char buf[32]; 11079bff0bc4SFelix Fietkau unsigned int len; 11089bff0bc4SFelix Fietkau u32 regval; 11099bff0bc4SFelix Fietkau 111079d2b157SRajkumar Manoharan ath9k_ps_wakeup(sc); 11119bff0bc4SFelix Fietkau regval = REG_READ_D(ah, sc->debug.regidx); 111279d2b157SRajkumar Manoharan ath9k_ps_restore(sc); 11132b87f3aaSDan Carpenter len = sprintf(buf, "0x%08x\n", regval); 11149bff0bc4SFelix Fietkau return simple_read_from_buffer(user_buf, count, ppos, buf, len); 11159bff0bc4SFelix Fietkau } 11169bff0bc4SFelix Fietkau 11179bff0bc4SFelix Fietkau static ssize_t write_file_regval(struct file *file, const char __user *user_buf, 11189bff0bc4SFelix Fietkau size_t count, loff_t *ppos) 11199bff0bc4SFelix Fietkau { 11209bff0bc4SFelix Fietkau struct ath_softc *sc = file->private_data; 11219bff0bc4SFelix Fietkau struct ath_hw *ah = sc->sc_ah; 11229bff0bc4SFelix Fietkau unsigned long regval; 11239bff0bc4SFelix Fietkau char buf[32]; 11249bff0bc4SFelix Fietkau ssize_t len; 11259bff0bc4SFelix Fietkau 11269bff0bc4SFelix Fietkau len = min(count, sizeof(buf) - 1); 11279bff0bc4SFelix Fietkau if (copy_from_user(buf, user_buf, len)) 112804236066SDan Carpenter return -EFAULT; 11299bff0bc4SFelix Fietkau 11309bff0bc4SFelix Fietkau buf[len] = '\0'; 11319bff0bc4SFelix Fietkau if (strict_strtoul(buf, 0, ®val)) 11329bff0bc4SFelix Fietkau return -EINVAL; 11339bff0bc4SFelix Fietkau 113479d2b157SRajkumar Manoharan ath9k_ps_wakeup(sc); 11359bff0bc4SFelix Fietkau REG_WRITE_D(ah, sc->debug.regidx, regval); 113679d2b157SRajkumar Manoharan ath9k_ps_restore(sc); 11379bff0bc4SFelix Fietkau return count; 11389bff0bc4SFelix Fietkau } 11399bff0bc4SFelix Fietkau 11409bff0bc4SFelix Fietkau static const struct file_operations fops_regval = { 11419bff0bc4SFelix Fietkau .read = read_file_regval, 11429bff0bc4SFelix Fietkau .write = write_file_regval, 11439bff0bc4SFelix Fietkau .open = ath9k_debugfs_open, 11446038f373SArnd Bergmann .owner = THIS_MODULE, 11456038f373SArnd Bergmann .llseek = default_llseek, 11469bff0bc4SFelix Fietkau }; 11479bff0bc4SFelix Fietkau 1148582d0064SVasanthakumar Thiagarajan #define REGDUMP_LINE_SIZE 20 1149582d0064SVasanthakumar Thiagarajan 1150582d0064SVasanthakumar Thiagarajan static int open_file_regdump(struct inode *inode, struct file *file) 1151582d0064SVasanthakumar Thiagarajan { 1152582d0064SVasanthakumar Thiagarajan struct ath_softc *sc = inode->i_private; 1153582d0064SVasanthakumar Thiagarajan unsigned int len = 0; 1154582d0064SVasanthakumar Thiagarajan u8 *buf; 1155582d0064SVasanthakumar Thiagarajan int i; 1156582d0064SVasanthakumar Thiagarajan unsigned long num_regs, regdump_len, max_reg_offset; 1157582d0064SVasanthakumar Thiagarajan 1158582d0064SVasanthakumar Thiagarajan max_reg_offset = AR_SREV_9300_20_OR_LATER(sc->sc_ah) ? 0x16bd4 : 0xb500; 1159582d0064SVasanthakumar Thiagarajan num_regs = max_reg_offset / 4 + 1; 1160582d0064SVasanthakumar Thiagarajan regdump_len = num_regs * REGDUMP_LINE_SIZE + 1; 1161582d0064SVasanthakumar Thiagarajan buf = vmalloc(regdump_len); 1162582d0064SVasanthakumar Thiagarajan if (!buf) 1163582d0064SVasanthakumar Thiagarajan return -ENOMEM; 1164582d0064SVasanthakumar Thiagarajan 1165582d0064SVasanthakumar Thiagarajan ath9k_ps_wakeup(sc); 1166582d0064SVasanthakumar Thiagarajan for (i = 0; i < num_regs; i++) 1167582d0064SVasanthakumar Thiagarajan len += scnprintf(buf + len, regdump_len - len, 1168582d0064SVasanthakumar Thiagarajan "0x%06x 0x%08x\n", i << 2, REG_READ(sc->sc_ah, i << 2)); 1169582d0064SVasanthakumar Thiagarajan ath9k_ps_restore(sc); 1170582d0064SVasanthakumar Thiagarajan 1171582d0064SVasanthakumar Thiagarajan file->private_data = buf; 1172582d0064SVasanthakumar Thiagarajan 1173582d0064SVasanthakumar Thiagarajan return 0; 1174582d0064SVasanthakumar Thiagarajan } 1175582d0064SVasanthakumar Thiagarajan 1176582d0064SVasanthakumar Thiagarajan static const struct file_operations fops_regdump = { 1177582d0064SVasanthakumar Thiagarajan .open = open_file_regdump, 1178582d0064SVasanthakumar Thiagarajan .read = ath9k_debugfs_read_buf, 1179582d0064SVasanthakumar Thiagarajan .release = ath9k_debugfs_release_buf, 1180582d0064SVasanthakumar Thiagarajan .owner = THIS_MODULE, 1181582d0064SVasanthakumar Thiagarajan .llseek = default_llseek,/* read accesses f_pos */ 1182582d0064SVasanthakumar Thiagarajan }; 1183582d0064SVasanthakumar Thiagarajan 11844d6b228dSLuis R. Rodriguez int ath9k_init_debug(struct ath_hw *ah) 1185203c4805SLuis R. Rodriguez { 1186bc974f4aSLuis R. Rodriguez struct ath_common *common = ath9k_hw_common(ah); 1187bc974f4aSLuis R. Rodriguez struct ath_softc *sc = (struct ath_softc *) common->priv; 11884d6b228dSLuis R. Rodriguez 1189eb272441SBen Greear sc->debug.debugfs_phy = debugfs_create_dir("ath9k", 1190eb272441SBen Greear sc->hw->wiphy->debugfsdir); 1191203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_phy) 1192c8a72c00SFelix Fietkau return -ENOMEM; 1193203c4805SLuis R. Rodriguez 1194a830df07SFelix Fietkau #ifdef CONFIG_ATH_DEBUG 1195c70cab1aSFelix Fietkau debugfs_create_file("debug", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1196c70cab1aSFelix Fietkau sc, &fops_debug); 1197a830df07SFelix Fietkau #endif 1198c70cab1aSFelix Fietkau debugfs_create_file("dma", S_IRUSR, sc->debug.debugfs_phy, sc, 1199c70cab1aSFelix Fietkau &fops_dma); 1200c70cab1aSFelix Fietkau debugfs_create_file("interrupt", S_IRUSR, sc->debug.debugfs_phy, sc, 1201c70cab1aSFelix Fietkau &fops_interrupt); 1202c70cab1aSFelix Fietkau debugfs_create_file("wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1203c70cab1aSFelix Fietkau sc, &fops_wiphy); 1204c70cab1aSFelix Fietkau debugfs_create_file("xmit", S_IRUSR, sc->debug.debugfs_phy, sc, 1205c70cab1aSFelix Fietkau &fops_xmit); 1206c70cab1aSFelix Fietkau debugfs_create_file("stations", S_IRUSR, sc->debug.debugfs_phy, sc, 1207c70cab1aSFelix Fietkau &fops_stations); 1208c70cab1aSFelix Fietkau debugfs_create_file("misc", S_IRUSR, sc->debug.debugfs_phy, sc, 1209c70cab1aSFelix Fietkau &fops_misc); 1210c70cab1aSFelix Fietkau debugfs_create_file("recv", S_IRUSR, sc->debug.debugfs_phy, sc, 1211c70cab1aSFelix Fietkau &fops_recv); 1212c70cab1aSFelix Fietkau debugfs_create_file("rx_chainmask", S_IRUSR | S_IWUSR, 1213c70cab1aSFelix Fietkau sc->debug.debugfs_phy, sc, &fops_rx_chainmask); 1214c70cab1aSFelix Fietkau debugfs_create_file("tx_chainmask", S_IRUSR | S_IWUSR, 1215c70cab1aSFelix Fietkau sc->debug.debugfs_phy, sc, &fops_tx_chainmask); 121605c0be2fSMohammed Shafi Shajakhan debugfs_create_file("disable_ani", S_IRUSR | S_IWUSR, 121705c0be2fSMohammed Shafi Shajakhan sc->debug.debugfs_phy, sc, &fops_disable_ani); 1218c70cab1aSFelix Fietkau debugfs_create_file("regidx", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1219c70cab1aSFelix Fietkau sc, &fops_regidx); 1220c70cab1aSFelix Fietkau debugfs_create_file("regval", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, 1221c70cab1aSFelix Fietkau sc, &fops_regval); 1222c70cab1aSFelix Fietkau debugfs_create_bool("ignore_extcca", S_IRUSR | S_IWUSR, 1223c70cab1aSFelix Fietkau sc->debug.debugfs_phy, 1224c70cab1aSFelix Fietkau &ah->config.cwm_ignore_extcca); 1225c70cab1aSFelix Fietkau debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc, 1226c70cab1aSFelix Fietkau &fops_regdump); 1227582d0064SVasanthakumar Thiagarajan 1228691680b8SFelix Fietkau debugfs_create_u32("gpio_mask", S_IRUSR | S_IWUSR, 1229691680b8SFelix Fietkau sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask); 1230691680b8SFelix Fietkau 1231691680b8SFelix Fietkau debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR, 1232691680b8SFelix Fietkau sc->debug.debugfs_phy, &sc->sc_ah->gpio_val); 1233691680b8SFelix Fietkau 12349bff0bc4SFelix Fietkau sc->debug.regidx = 0; 1235203c4805SLuis R. Rodriguez return 0; 1236203c4805SLuis R. Rodriguez } 1237