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 21203c4805SLuis R. Rodriguez static unsigned int ath9k_debug = DBG_DEFAULT; 22203c4805SLuis R. Rodriguez module_param_named(debug, ath9k_debug, uint, 0); 23203c4805SLuis R. Rodriguez 24203c4805SLuis R. Rodriguez static struct dentry *ath9k_debugfs_root; 25203c4805SLuis R. Rodriguez 26203c4805SLuis R. Rodriguez void DPRINTF(struct ath_softc *sc, int dbg_mask, const char *fmt, ...) 27203c4805SLuis R. Rodriguez { 28203c4805SLuis R. Rodriguez if (!sc) 29203c4805SLuis R. Rodriguez return; 30203c4805SLuis R. Rodriguez 31203c4805SLuis R. Rodriguez if (sc->debug.debug_mask & dbg_mask) { 32203c4805SLuis R. Rodriguez va_list args; 33203c4805SLuis R. Rodriguez 34203c4805SLuis R. Rodriguez va_start(args, fmt); 35203c4805SLuis R. Rodriguez printk(KERN_DEBUG "ath9k: "); 36203c4805SLuis R. Rodriguez vprintk(fmt, args); 37203c4805SLuis R. Rodriguez va_end(args); 38203c4805SLuis R. Rodriguez } 39203c4805SLuis R. Rodriguez } 40203c4805SLuis R. Rodriguez 41203c4805SLuis R. Rodriguez static int ath9k_debugfs_open(struct inode *inode, struct file *file) 42203c4805SLuis R. Rodriguez { 43203c4805SLuis R. Rodriguez file->private_data = inode->i_private; 44203c4805SLuis R. Rodriguez return 0; 45203c4805SLuis R. Rodriguez } 46203c4805SLuis R. Rodriguez 47203c4805SLuis R. Rodriguez static ssize_t read_file_dma(struct file *file, char __user *user_buf, 48203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 49203c4805SLuis R. Rodriguez { 50203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 51203c4805SLuis R. Rodriguez struct ath_hw *ah = sc->sc_ah; 52203c4805SLuis R. Rodriguez char buf[1024]; 53203c4805SLuis R. Rodriguez unsigned int len = 0; 54203c4805SLuis R. Rodriguez u32 val[ATH9K_NUM_DMA_DEBUG_REGS]; 55203c4805SLuis R. Rodriguez int i, qcuOffset = 0, dcuOffset = 0; 56203c4805SLuis R. Rodriguez u32 *qcuBase = &val[0], *dcuBase = &val[4]; 57203c4805SLuis R. Rodriguez 58203c4805SLuis R. Rodriguez REG_WRITE(ah, AR_MACMISC, 59203c4805SLuis R. Rodriguez ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) | 60203c4805SLuis R. Rodriguez (AR_MACMISC_MISC_OBS_BUS_1 << 61203c4805SLuis R. Rodriguez AR_MACMISC_MISC_OBS_BUS_MSB_S))); 62203c4805SLuis R. Rodriguez 63203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 64203c4805SLuis R. Rodriguez "Raw DMA Debug values:\n"); 65203c4805SLuis R. Rodriguez 66203c4805SLuis R. Rodriguez for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) { 67203c4805SLuis R. Rodriguez if (i % 4 == 0) 68203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "\n"); 69203c4805SLuis R. Rodriguez 70203c4805SLuis R. Rodriguez val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32))); 71203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ", 72203c4805SLuis R. Rodriguez i, val[i]); 73203c4805SLuis R. Rodriguez } 74203c4805SLuis R. Rodriguez 75203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "\n\n"); 76203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 77203c4805SLuis R. Rodriguez "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n"); 78203c4805SLuis R. Rodriguez 79203c4805SLuis R. Rodriguez for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) { 80203c4805SLuis R. Rodriguez if (i == 8) { 81203c4805SLuis R. Rodriguez qcuOffset = 0; 82203c4805SLuis R. Rodriguez qcuBase++; 83203c4805SLuis R. Rodriguez } 84203c4805SLuis R. Rodriguez 85203c4805SLuis R. Rodriguez if (i == 6) { 86203c4805SLuis R. Rodriguez dcuOffset = 0; 87203c4805SLuis R. Rodriguez dcuBase++; 88203c4805SLuis R. Rodriguez } 89203c4805SLuis R. Rodriguez 90203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 91203c4805SLuis R. Rodriguez "%2d %2x %1x %2x %2x\n", 92203c4805SLuis R. Rodriguez i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset, 93203c4805SLuis R. Rodriguez (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3), 94203c4805SLuis R. Rodriguez val[2] & (0x7 << (i * 3)) >> (i * 3), 95203c4805SLuis R. Rodriguez (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset); 96203c4805SLuis R. Rodriguez } 97203c4805SLuis R. Rodriguez 98203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "\n"); 99203c4805SLuis R. Rodriguez 100203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 101203c4805SLuis R. Rodriguez "qcu_stitch state: %2x qcu_fetch state: %2x\n", 102203c4805SLuis R. Rodriguez (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22); 103203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 104203c4805SLuis R. Rodriguez "qcu_complete state: %2x dcu_complete state: %2x\n", 105203c4805SLuis R. Rodriguez (val[3] & 0x1c000000) >> 26, (val[6] & 0x3)); 106203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 107203c4805SLuis R. Rodriguez "dcu_arb state: %2x dcu_fp state: %2x\n", 108203c4805SLuis R. Rodriguez (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27); 109203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 110203c4805SLuis R. Rodriguez "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n", 111203c4805SLuis R. Rodriguez (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10); 112203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 113203c4805SLuis R. Rodriguez "txfifo_valid_0: %1d txfifo_valid_1: %1d\n", 114203c4805SLuis R. Rodriguez (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12); 115203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 116203c4805SLuis R. Rodriguez "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n", 117203c4805SLuis R. Rodriguez (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17); 118203c4805SLuis R. Rodriguez 119203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n", 120203c4805SLuis R. Rodriguez REG_READ(ah, AR_OBS_BUS_1)); 121203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 122203c4805SLuis R. Rodriguez "AR_CR: 0x%x \n", REG_READ(ah, AR_CR)); 123203c4805SLuis R. Rodriguez 124203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 125203c4805SLuis R. Rodriguez } 126203c4805SLuis R. Rodriguez 127203c4805SLuis R. Rodriguez static const struct file_operations fops_dma = { 128203c4805SLuis R. Rodriguez .read = read_file_dma, 129203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 130203c4805SLuis R. Rodriguez .owner = THIS_MODULE 131203c4805SLuis R. Rodriguez }; 132203c4805SLuis R. Rodriguez 133203c4805SLuis R. Rodriguez 134203c4805SLuis R. Rodriguez void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status) 135203c4805SLuis R. Rodriguez { 136203c4805SLuis R. Rodriguez if (status) 137203c4805SLuis R. Rodriguez sc->debug.stats.istats.total++; 138203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RX) 139203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxok++; 140203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXEOL) 141203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxeol++; 142203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXORN) 143203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxorn++; 144203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TX) 145203c4805SLuis R. Rodriguez sc->debug.stats.istats.txok++; 146203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TXURN) 147203c4805SLuis R. Rodriguez sc->debug.stats.istats.txurn++; 148203c4805SLuis R. Rodriguez if (status & ATH9K_INT_MIB) 149203c4805SLuis R. Rodriguez sc->debug.stats.istats.mib++; 150203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXPHY) 151203c4805SLuis R. Rodriguez sc->debug.stats.istats.rxphyerr++; 152203c4805SLuis R. Rodriguez if (status & ATH9K_INT_RXKCM) 153203c4805SLuis R. Rodriguez sc->debug.stats.istats.rx_keycache_miss++; 154203c4805SLuis R. Rodriguez if (status & ATH9K_INT_SWBA) 155203c4805SLuis R. Rodriguez sc->debug.stats.istats.swba++; 156203c4805SLuis R. Rodriguez if (status & ATH9K_INT_BMISS) 157203c4805SLuis R. Rodriguez sc->debug.stats.istats.bmiss++; 158203c4805SLuis R. Rodriguez if (status & ATH9K_INT_BNR) 159203c4805SLuis R. Rodriguez sc->debug.stats.istats.bnr++; 160203c4805SLuis R. Rodriguez if (status & ATH9K_INT_CST) 161203c4805SLuis R. Rodriguez sc->debug.stats.istats.cst++; 162203c4805SLuis R. Rodriguez if (status & ATH9K_INT_GTT) 163203c4805SLuis R. Rodriguez sc->debug.stats.istats.gtt++; 164203c4805SLuis R. Rodriguez if (status & ATH9K_INT_TIM) 165203c4805SLuis R. Rodriguez sc->debug.stats.istats.tim++; 166203c4805SLuis R. Rodriguez if (status & ATH9K_INT_CABEND) 167203c4805SLuis R. Rodriguez sc->debug.stats.istats.cabend++; 168203c4805SLuis R. Rodriguez if (status & ATH9K_INT_DTIMSYNC) 169203c4805SLuis R. Rodriguez sc->debug.stats.istats.dtimsync++; 170203c4805SLuis R. Rodriguez if (status & ATH9K_INT_DTIM) 171203c4805SLuis R. Rodriguez sc->debug.stats.istats.dtim++; 172203c4805SLuis R. Rodriguez } 173203c4805SLuis R. Rodriguez 174203c4805SLuis R. Rodriguez static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, 175203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 176203c4805SLuis R. Rodriguez { 177203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 178203c4805SLuis R. Rodriguez char buf[512]; 179203c4805SLuis R. Rodriguez unsigned int len = 0; 180203c4805SLuis R. Rodriguez 181203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 182203c4805SLuis R. Rodriguez "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok); 183203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 184203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol); 185203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 186203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn); 187203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 188203c4805SLuis R. Rodriguez "%8s: %10u\n", "TX", sc->debug.stats.istats.txok); 189203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 190203c4805SLuis R. Rodriguez "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn); 191203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 192203c4805SLuis R. Rodriguez "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib); 193203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 194203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr); 195203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 196203c4805SLuis R. Rodriguez "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss); 197203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 198203c4805SLuis R. Rodriguez "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba); 199203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 200203c4805SLuis R. Rodriguez "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss); 201203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 202203c4805SLuis R. Rodriguez "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr); 203203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 204203c4805SLuis R. Rodriguez "%8s: %10u\n", "CST", sc->debug.stats.istats.cst); 205203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 206203c4805SLuis R. Rodriguez "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt); 207203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 208203c4805SLuis R. Rodriguez "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim); 209203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 210203c4805SLuis R. Rodriguez "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend); 211203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 212203c4805SLuis R. Rodriguez "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync); 213203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 214203c4805SLuis R. Rodriguez "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim); 215203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 216203c4805SLuis R. Rodriguez "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total); 217203c4805SLuis R. Rodriguez 218203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 219203c4805SLuis R. Rodriguez } 220203c4805SLuis R. Rodriguez 221203c4805SLuis R. Rodriguez static const struct file_operations fops_interrupt = { 222203c4805SLuis R. Rodriguez .read = read_file_interrupt, 223203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 224203c4805SLuis R. Rodriguez .owner = THIS_MODULE 225203c4805SLuis R. Rodriguez }; 226203c4805SLuis R. Rodriguez 227*bedf087aSJeff Hansen void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb) 228203c4805SLuis R. Rodriguez { 229203c4805SLuis R. Rodriguez struct ath_tx_info_priv *tx_info_priv = NULL; 230203c4805SLuis R. Rodriguez struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 231203c4805SLuis R. Rodriguez struct ieee80211_tx_rate *rates = tx_info->status.rates; 232203c4805SLuis R. Rodriguez int final_ts_idx, idx; 233*bedf087aSJeff Hansen struct ath_rc_stats *stats; 234203c4805SLuis R. Rodriguez 235203c4805SLuis R. Rodriguez tx_info_priv = ATH_TX_INFO_PRIV(tx_info); 236203c4805SLuis R. Rodriguez final_ts_idx = tx_info_priv->tx.ts_rateindex; 237203c4805SLuis R. Rodriguez idx = rates[final_ts_idx].idx; 238*bedf087aSJeff Hansen stats = &sc->debug.stats.rcstats[idx]; 239*bedf087aSJeff Hansen stats->success++; 240203c4805SLuis R. Rodriguez } 241203c4805SLuis R. Rodriguez 242203c4805SLuis R. Rodriguez void ath_debug_stat_retries(struct ath_softc *sc, int rix, 243203c4805SLuis R. Rodriguez int xretries, int retries, u8 per) 244203c4805SLuis R. Rodriguez { 245*bedf087aSJeff Hansen struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix]; 246203c4805SLuis R. Rodriguez 247*bedf087aSJeff Hansen stats->xretries += xretries; 248*bedf087aSJeff Hansen stats->retries += retries; 249*bedf087aSJeff Hansen stats->per = per; 250203c4805SLuis R. Rodriguez } 251203c4805SLuis R. Rodriguez 252203c4805SLuis R. Rodriguez static ssize_t read_file_rcstat(struct file *file, char __user *user_buf, 253203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 254203c4805SLuis R. Rodriguez { 255203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 256*bedf087aSJeff Hansen char *buf; 257*bedf087aSJeff Hansen unsigned int len = 0, max; 258*bedf087aSJeff Hansen int i = 0; 259*bedf087aSJeff Hansen ssize_t retval; 260203c4805SLuis R. Rodriguez 261203c4805SLuis R. Rodriguez if (sc->cur_rate_table == NULL) 262203c4805SLuis R. Rodriguez return 0; 263203c4805SLuis R. Rodriguez 264*bedf087aSJeff Hansen max = 80 + sc->cur_rate_table->rate_cnt * 64; 265*bedf087aSJeff Hansen buf = kmalloc(max + 1, GFP_KERNEL); 266*bedf087aSJeff Hansen if (buf == NULL) 267*bedf087aSJeff Hansen return 0; 268*bedf087aSJeff Hansen buf[max] = 0; 269*bedf087aSJeff Hansen 270*bedf087aSJeff Hansen len += sprintf(buf, "%5s %15s %8s %9s %3s\n\n", "Rate", "Success", 271*bedf087aSJeff Hansen "Retries", "XRetries", "PER"); 272*bedf087aSJeff Hansen 273*bedf087aSJeff Hansen for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) { 274*bedf087aSJeff Hansen u32 ratekbps = sc->cur_rate_table->info[i].ratekbps; 275*bedf087aSJeff Hansen struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i]; 276*bedf087aSJeff Hansen 277*bedf087aSJeff Hansen len += snprintf(buf + len, max - len, 278*bedf087aSJeff Hansen "%3u.%d: %8u %8u %8u %8u\n", ratekbps / 1000, 279*bedf087aSJeff Hansen (ratekbps % 1000) / 100, stats->success, 280*bedf087aSJeff Hansen stats->retries, stats->xretries, 281*bedf087aSJeff Hansen stats->per); 282*bedf087aSJeff Hansen } 283*bedf087aSJeff Hansen 284*bedf087aSJeff Hansen retval = simple_read_from_buffer(user_buf, count, ppos, buf, len); 285*bedf087aSJeff Hansen kfree(buf); 286*bedf087aSJeff Hansen return retval; 287203c4805SLuis R. Rodriguez } 288203c4805SLuis R. Rodriguez 289203c4805SLuis R. Rodriguez static const struct file_operations fops_rcstat = { 290203c4805SLuis R. Rodriguez .read = read_file_rcstat, 291203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 292203c4805SLuis R. Rodriguez .owner = THIS_MODULE 293203c4805SLuis R. Rodriguez }; 294203c4805SLuis R. Rodriguez 295203c4805SLuis R. Rodriguez static const char * ath_wiphy_state_str(enum ath_wiphy_state state) 296203c4805SLuis R. Rodriguez { 297203c4805SLuis R. Rodriguez switch (state) { 298203c4805SLuis R. Rodriguez case ATH_WIPHY_INACTIVE: 299203c4805SLuis R. Rodriguez return "INACTIVE"; 300203c4805SLuis R. Rodriguez case ATH_WIPHY_ACTIVE: 301203c4805SLuis R. Rodriguez return "ACTIVE"; 302203c4805SLuis R. Rodriguez case ATH_WIPHY_PAUSING: 303203c4805SLuis R. Rodriguez return "PAUSING"; 304203c4805SLuis R. Rodriguez case ATH_WIPHY_PAUSED: 305203c4805SLuis R. Rodriguez return "PAUSED"; 306203c4805SLuis R. Rodriguez case ATH_WIPHY_SCAN: 307203c4805SLuis R. Rodriguez return "SCAN"; 308203c4805SLuis R. Rodriguez } 309203c4805SLuis R. Rodriguez return "?"; 310203c4805SLuis R. Rodriguez } 311203c4805SLuis R. Rodriguez 312203c4805SLuis R. Rodriguez static ssize_t read_file_wiphy(struct file *file, char __user *user_buf, 313203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 314203c4805SLuis R. Rodriguez { 315203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 316203c4805SLuis R. Rodriguez char buf[512]; 317203c4805SLuis R. Rodriguez unsigned int len = 0; 318203c4805SLuis R. Rodriguez int i; 319203c4805SLuis R. Rodriguez u8 addr[ETH_ALEN]; 320203c4805SLuis R. Rodriguez 321203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 322203c4805SLuis R. Rodriguez "primary: %s (%s chan=%d ht=%d)\n", 323203c4805SLuis R. Rodriguez wiphy_name(sc->pri_wiphy->hw->wiphy), 324203c4805SLuis R. Rodriguez ath_wiphy_state_str(sc->pri_wiphy->state), 325203c4805SLuis R. Rodriguez sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht); 326203c4805SLuis R. Rodriguez for (i = 0; i < sc->num_sec_wiphy; i++) { 327203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = sc->sec_wiphy[i]; 328203c4805SLuis R. Rodriguez if (aphy == NULL) 329203c4805SLuis R. Rodriguez continue; 330203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 331203c4805SLuis R. Rodriguez "secondary: %s (%s chan=%d ht=%d)\n", 332203c4805SLuis R. Rodriguez wiphy_name(aphy->hw->wiphy), 333203c4805SLuis R. Rodriguez ath_wiphy_state_str(aphy->state), 334203c4805SLuis R. Rodriguez aphy->chan_idx, aphy->chan_is_ht); 335203c4805SLuis R. Rodriguez } 336203c4805SLuis R. Rodriguez 337203c4805SLuis R. Rodriguez put_unaligned_le32(REG_READ(sc->sc_ah, AR_STA_ID0), addr); 338203c4805SLuis R. Rodriguez put_unaligned_le16(REG_READ(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4); 339203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 340203c4805SLuis R. Rodriguez "addr: %pM\n", addr); 341203c4805SLuis R. Rodriguez put_unaligned_le32(REG_READ(sc->sc_ah, AR_BSSMSKL), addr); 342203c4805SLuis R. Rodriguez put_unaligned_le16(REG_READ(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4); 343203c4805SLuis R. Rodriguez len += snprintf(buf + len, sizeof(buf) - len, 344203c4805SLuis R. Rodriguez "addrmask: %pM\n", addr); 345203c4805SLuis R. Rodriguez 346203c4805SLuis R. Rodriguez return simple_read_from_buffer(user_buf, count, ppos, buf, len); 347203c4805SLuis R. Rodriguez } 348203c4805SLuis R. Rodriguez 349203c4805SLuis R. Rodriguez static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name) 350203c4805SLuis R. Rodriguez { 351203c4805SLuis R. Rodriguez int i; 352203c4805SLuis R. Rodriguez if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0) 353203c4805SLuis R. Rodriguez return sc->pri_wiphy; 354203c4805SLuis R. Rodriguez for (i = 0; i < sc->num_sec_wiphy; i++) { 355203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = sc->sec_wiphy[i]; 356203c4805SLuis R. Rodriguez if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0) 357203c4805SLuis R. Rodriguez return aphy; 358203c4805SLuis R. Rodriguez } 359203c4805SLuis R. Rodriguez return NULL; 360203c4805SLuis R. Rodriguez } 361203c4805SLuis R. Rodriguez 362203c4805SLuis R. Rodriguez static int del_wiphy(struct ath_softc *sc, const char *name) 363203c4805SLuis R. Rodriguez { 364203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 365203c4805SLuis R. Rodriguez if (!aphy) 366203c4805SLuis R. Rodriguez return -ENOENT; 367203c4805SLuis R. Rodriguez return ath9k_wiphy_del(aphy); 368203c4805SLuis R. Rodriguez } 369203c4805SLuis R. Rodriguez 370203c4805SLuis R. Rodriguez static int pause_wiphy(struct ath_softc *sc, const char *name) 371203c4805SLuis R. Rodriguez { 372203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 373203c4805SLuis R. Rodriguez if (!aphy) 374203c4805SLuis R. Rodriguez return -ENOENT; 375203c4805SLuis R. Rodriguez return ath9k_wiphy_pause(aphy); 376203c4805SLuis R. Rodriguez } 377203c4805SLuis R. Rodriguez 378203c4805SLuis R. Rodriguez static int unpause_wiphy(struct ath_softc *sc, const char *name) 379203c4805SLuis R. Rodriguez { 380203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 381203c4805SLuis R. Rodriguez if (!aphy) 382203c4805SLuis R. Rodriguez return -ENOENT; 383203c4805SLuis R. Rodriguez return ath9k_wiphy_unpause(aphy); 384203c4805SLuis R. Rodriguez } 385203c4805SLuis R. Rodriguez 386203c4805SLuis R. Rodriguez static int select_wiphy(struct ath_softc *sc, const char *name) 387203c4805SLuis R. Rodriguez { 388203c4805SLuis R. Rodriguez struct ath_wiphy *aphy = get_wiphy(sc, name); 389203c4805SLuis R. Rodriguez if (!aphy) 390203c4805SLuis R. Rodriguez return -ENOENT; 391203c4805SLuis R. Rodriguez return ath9k_wiphy_select(aphy); 392203c4805SLuis R. Rodriguez } 393203c4805SLuis R. Rodriguez 394203c4805SLuis R. Rodriguez static int schedule_wiphy(struct ath_softc *sc, const char *msec) 395203c4805SLuis R. Rodriguez { 396203c4805SLuis R. Rodriguez ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0)); 397203c4805SLuis R. Rodriguez return 0; 398203c4805SLuis R. Rodriguez } 399203c4805SLuis R. Rodriguez 400203c4805SLuis R. Rodriguez static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf, 401203c4805SLuis R. Rodriguez size_t count, loff_t *ppos) 402203c4805SLuis R. Rodriguez { 403203c4805SLuis R. Rodriguez struct ath_softc *sc = file->private_data; 404203c4805SLuis R. Rodriguez char buf[50]; 405203c4805SLuis R. Rodriguez size_t len; 406203c4805SLuis R. Rodriguez 407203c4805SLuis R. Rodriguez len = min(count, sizeof(buf) - 1); 408203c4805SLuis R. Rodriguez if (copy_from_user(buf, user_buf, len)) 409203c4805SLuis R. Rodriguez return -EFAULT; 410203c4805SLuis R. Rodriguez buf[len] = '\0'; 411203c4805SLuis R. Rodriguez if (len > 0 && buf[len - 1] == '\n') 412203c4805SLuis R. Rodriguez buf[len - 1] = '\0'; 413203c4805SLuis R. Rodriguez 414203c4805SLuis R. Rodriguez if (strncmp(buf, "add", 3) == 0) { 415203c4805SLuis R. Rodriguez int res = ath9k_wiphy_add(sc); 416203c4805SLuis R. Rodriguez if (res < 0) 417203c4805SLuis R. Rodriguez return res; 418203c4805SLuis R. Rodriguez } else if (strncmp(buf, "del=", 4) == 0) { 419203c4805SLuis R. Rodriguez int res = del_wiphy(sc, buf + 4); 420203c4805SLuis R. Rodriguez if (res < 0) 421203c4805SLuis R. Rodriguez return res; 422203c4805SLuis R. Rodriguez } else if (strncmp(buf, "pause=", 6) == 0) { 423203c4805SLuis R. Rodriguez int res = pause_wiphy(sc, buf + 6); 424203c4805SLuis R. Rodriguez if (res < 0) 425203c4805SLuis R. Rodriguez return res; 426203c4805SLuis R. Rodriguez } else if (strncmp(buf, "unpause=", 8) == 0) { 427203c4805SLuis R. Rodriguez int res = unpause_wiphy(sc, buf + 8); 428203c4805SLuis R. Rodriguez if (res < 0) 429203c4805SLuis R. Rodriguez return res; 430203c4805SLuis R. Rodriguez } else if (strncmp(buf, "select=", 7) == 0) { 431203c4805SLuis R. Rodriguez int res = select_wiphy(sc, buf + 7); 432203c4805SLuis R. Rodriguez if (res < 0) 433203c4805SLuis R. Rodriguez return res; 434203c4805SLuis R. Rodriguez } else if (strncmp(buf, "schedule=", 9) == 0) { 435203c4805SLuis R. Rodriguez int res = schedule_wiphy(sc, buf + 9); 436203c4805SLuis R. Rodriguez if (res < 0) 437203c4805SLuis R. Rodriguez return res; 438203c4805SLuis R. Rodriguez } else 439203c4805SLuis R. Rodriguez return -EOPNOTSUPP; 440203c4805SLuis R. Rodriguez 441203c4805SLuis R. Rodriguez return count; 442203c4805SLuis R. Rodriguez } 443203c4805SLuis R. Rodriguez 444203c4805SLuis R. Rodriguez static const struct file_operations fops_wiphy = { 445203c4805SLuis R. Rodriguez .read = read_file_wiphy, 446203c4805SLuis R. Rodriguez .write = write_file_wiphy, 447203c4805SLuis R. Rodriguez .open = ath9k_debugfs_open, 448203c4805SLuis R. Rodriguez .owner = THIS_MODULE 449203c4805SLuis R. Rodriguez }; 450203c4805SLuis R. Rodriguez 451203c4805SLuis R. Rodriguez 452203c4805SLuis R. Rodriguez int ath9k_init_debug(struct ath_softc *sc) 453203c4805SLuis R. Rodriguez { 454203c4805SLuis R. Rodriguez sc->debug.debug_mask = ath9k_debug; 455203c4805SLuis R. Rodriguez 456203c4805SLuis R. Rodriguez if (!ath9k_debugfs_root) 457203c4805SLuis R. Rodriguez return -ENOENT; 458203c4805SLuis R. Rodriguez 459203c4805SLuis R. Rodriguez sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy), 460203c4805SLuis R. Rodriguez ath9k_debugfs_root); 461203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_phy) 462203c4805SLuis R. Rodriguez goto err; 463203c4805SLuis R. Rodriguez 464203c4805SLuis R. Rodriguez sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUGO, 465203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, sc, &fops_dma); 466203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_dma) 467203c4805SLuis R. Rodriguez goto err; 468203c4805SLuis R. Rodriguez 469203c4805SLuis R. Rodriguez sc->debug.debugfs_interrupt = debugfs_create_file("interrupt", 470203c4805SLuis R. Rodriguez S_IRUGO, 471203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, 472203c4805SLuis R. Rodriguez sc, &fops_interrupt); 473203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_interrupt) 474203c4805SLuis R. Rodriguez goto err; 475203c4805SLuis R. Rodriguez 476203c4805SLuis R. Rodriguez sc->debug.debugfs_rcstat = debugfs_create_file("rcstat", 477203c4805SLuis R. Rodriguez S_IRUGO, 478203c4805SLuis R. Rodriguez sc->debug.debugfs_phy, 479203c4805SLuis R. Rodriguez sc, &fops_rcstat); 480203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_rcstat) 481203c4805SLuis R. Rodriguez goto err; 482203c4805SLuis R. Rodriguez 483203c4805SLuis R. Rodriguez sc->debug.debugfs_wiphy = debugfs_create_file( 484203c4805SLuis R. Rodriguez "wiphy", S_IRUGO | S_IWUSR, sc->debug.debugfs_phy, sc, 485203c4805SLuis R. Rodriguez &fops_wiphy); 486203c4805SLuis R. Rodriguez if (!sc->debug.debugfs_wiphy) 487203c4805SLuis R. Rodriguez goto err; 488203c4805SLuis R. Rodriguez 489203c4805SLuis R. Rodriguez return 0; 490203c4805SLuis R. Rodriguez err: 491203c4805SLuis R. Rodriguez ath9k_exit_debug(sc); 492203c4805SLuis R. Rodriguez return -ENOMEM; 493203c4805SLuis R. Rodriguez } 494203c4805SLuis R. Rodriguez 495203c4805SLuis R. Rodriguez void ath9k_exit_debug(struct ath_softc *sc) 496203c4805SLuis R. Rodriguez { 497203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_wiphy); 498203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_rcstat); 499203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_interrupt); 500203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_dma); 501203c4805SLuis R. Rodriguez debugfs_remove(sc->debug.debugfs_phy); 502203c4805SLuis R. Rodriguez } 503203c4805SLuis R. Rodriguez 504203c4805SLuis R. Rodriguez int ath9k_debug_create_root(void) 505203c4805SLuis R. Rodriguez { 506203c4805SLuis R. Rodriguez ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL); 507203c4805SLuis R. Rodriguez if (!ath9k_debugfs_root) 508203c4805SLuis R. Rodriguez return -ENOENT; 509203c4805SLuis R. Rodriguez 510203c4805SLuis R. Rodriguez return 0; 511203c4805SLuis R. Rodriguez } 512203c4805SLuis R. Rodriguez 513203c4805SLuis R. Rodriguez void ath9k_debug_remove_root(void) 514203c4805SLuis R. Rodriguez { 515203c4805SLuis R. Rodriguez debugfs_remove(ath9k_debugfs_root); 516203c4805SLuis R. Rodriguez ath9k_debugfs_root = NULL; 517203c4805SLuis R. Rodriguez } 518