2 * Copyright (c) 2008 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 static unsigned int ath9k_debug = DBG_DEFAULT;
22 module_param_named(debug, ath9k_debug, uint, 0);
24 void DPRINTF(struct ath_softc *sc, int dbg_mask, const char *fmt, ...)
29 if (sc->sc_debug.debug_mask & dbg_mask) {
33 printk(KERN_DEBUG "ath9k: ");
39 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
41 file->private_data = inode->i_private;
45 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
46 size_t count, loff_t *ppos)
48 struct ath_softc *sc = file->private_data;
49 struct ath_hal *ah = sc->sc_ah;
52 u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
53 int i, qcuOffset = 0, dcuOffset = 0;
54 u32 *qcuBase = &val[0], *dcuBase = &val[4];
56 REG_WRITE(ah, AR_MACMISC,
57 ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
58 (AR_MACMISC_MISC_OBS_BUS_1 <<
59 AR_MACMISC_MISC_OBS_BUS_MSB_S)));
61 len += snprintf(buf + len, sizeof(buf) - len,
62 "Raw DMA Debug values:\n");
64 for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
66 len += snprintf(buf + len, sizeof(buf) - len, "\n");
68 val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32)));
69 len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ",
73 len += snprintf(buf + len, sizeof(buf) - len, "\n\n");
74 len += snprintf(buf + len, sizeof(buf) - len,
75 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
77 for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
88 len += snprintf(buf + len, sizeof(buf) - len,
89 "%2d %2x %1x %2x %2x\n",
90 i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
91 (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
92 val[2] & (0x7 << (i * 3)) >> (i * 3),
93 (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
96 len += snprintf(buf + len, sizeof(buf) - len, "\n");
98 len += snprintf(buf + len, sizeof(buf) - len,
99 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
100 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
101 len += snprintf(buf + len, sizeof(buf) - len,
102 "qcu_complete state: %2x dcu_complete state: %2x\n",
103 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
104 len += snprintf(buf + len, sizeof(buf) - len,
105 "dcu_arb state: %2x dcu_fp state: %2x\n",
106 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
107 len += snprintf(buf + len, sizeof(buf) - len,
108 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
109 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
110 len += snprintf(buf + len, sizeof(buf) - len,
111 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
112 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
113 len += snprintf(buf + len, sizeof(buf) - len,
114 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
115 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
117 len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n",
118 REG_READ(ah, AR_OBS_BUS_1));
119 len += snprintf(buf + len, sizeof(buf) - len,
120 "AR_CR: 0x%x \n", REG_READ(ah, AR_CR));
122 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
125 static const struct file_operations fops_dma = {
126 .read = read_file_dma,
127 .open = ath9k_debugfs_open,
132 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
135 sc->sc_debug.stats.istats.total++;
136 if (status & ATH9K_INT_RX)
137 sc->sc_debug.stats.istats.rxok++;
138 if (status & ATH9K_INT_RXEOL)
139 sc->sc_debug.stats.istats.rxeol++;
140 if (status & ATH9K_INT_RXORN)
141 sc->sc_debug.stats.istats.rxorn++;
142 if (status & ATH9K_INT_TX)
143 sc->sc_debug.stats.istats.txok++;
144 if (status & ATH9K_INT_TXURN)
145 sc->sc_debug.stats.istats.txurn++;
146 if (status & ATH9K_INT_MIB)
147 sc->sc_debug.stats.istats.mib++;
148 if (status & ATH9K_INT_RXPHY)
149 sc->sc_debug.stats.istats.rxphyerr++;
150 if (status & ATH9K_INT_RXKCM)
151 sc->sc_debug.stats.istats.rx_keycache_miss++;
152 if (status & ATH9K_INT_SWBA)
153 sc->sc_debug.stats.istats.swba++;
154 if (status & ATH9K_INT_BMISS)
155 sc->sc_debug.stats.istats.bmiss++;
156 if (status & ATH9K_INT_BNR)
157 sc->sc_debug.stats.istats.bnr++;
158 if (status & ATH9K_INT_CST)
159 sc->sc_debug.stats.istats.cst++;
160 if (status & ATH9K_INT_GTT)
161 sc->sc_debug.stats.istats.gtt++;
162 if (status & ATH9K_INT_TIM)
163 sc->sc_debug.stats.istats.tim++;
164 if (status & ATH9K_INT_CABEND)
165 sc->sc_debug.stats.istats.cabend++;
166 if (status & ATH9K_INT_DTIMSYNC)
167 sc->sc_debug.stats.istats.dtimsync++;
168 if (status & ATH9K_INT_DTIM)
169 sc->sc_debug.stats.istats.dtim++;
172 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
173 size_t count, loff_t *ppos)
175 struct ath_softc *sc = file->private_data;
177 unsigned int len = 0;
179 len += snprintf(buf + len, sizeof(buf) - len,
180 "%8s: %10u\n", "RX", sc->sc_debug.stats.istats.rxok);
181 len += snprintf(buf + len, sizeof(buf) - len,
182 "%8s: %10u\n", "RXEOL", sc->sc_debug.stats.istats.rxeol);
183 len += snprintf(buf + len, sizeof(buf) - len,
184 "%8s: %10u\n", "RXORN", sc->sc_debug.stats.istats.rxorn);
185 len += snprintf(buf + len, sizeof(buf) - len,
186 "%8s: %10u\n", "TX", sc->sc_debug.stats.istats.txok);
187 len += snprintf(buf + len, sizeof(buf) - len,
188 "%8s: %10u\n", "TXURN", sc->sc_debug.stats.istats.txurn);
189 len += snprintf(buf + len, sizeof(buf) - len,
190 "%8s: %10u\n", "MIB", sc->sc_debug.stats.istats.mib);
191 len += snprintf(buf + len, sizeof(buf) - len,
192 "%8s: %10u\n", "RXPHY", sc->sc_debug.stats.istats.rxphyerr);
193 len += snprintf(buf + len, sizeof(buf) - len,
194 "%8s: %10u\n", "RXKCM", sc->sc_debug.stats.istats.rx_keycache_miss);
195 len += snprintf(buf + len, sizeof(buf) - len,
196 "%8s: %10u\n", "SWBA", sc->sc_debug.stats.istats.swba);
197 len += snprintf(buf + len, sizeof(buf) - len,
198 "%8s: %10u\n", "BMISS", sc->sc_debug.stats.istats.bmiss);
199 len += snprintf(buf + len, sizeof(buf) - len,
200 "%8s: %10u\n", "BNR", sc->sc_debug.stats.istats.bnr);
201 len += snprintf(buf + len, sizeof(buf) - len,
202 "%8s: %10u\n", "CST", sc->sc_debug.stats.istats.cst);
203 len += snprintf(buf + len, sizeof(buf) - len,
204 "%8s: %10u\n", "GTT", sc->sc_debug.stats.istats.gtt);
205 len += snprintf(buf + len, sizeof(buf) - len,
206 "%8s: %10u\n", "TIM", sc->sc_debug.stats.istats.tim);
207 len += snprintf(buf + len, sizeof(buf) - len,
208 "%8s: %10u\n", "CABEND", sc->sc_debug.stats.istats.cabend);
209 len += snprintf(buf + len, sizeof(buf) - len,
210 "%8s: %10u\n", "DTIMSYNC", sc->sc_debug.stats.istats.dtimsync);
211 len += snprintf(buf + len, sizeof(buf) - len,
212 "%8s: %10u\n", "DTIM", sc->sc_debug.stats.istats.dtim);
213 len += snprintf(buf + len, sizeof(buf) - len,
214 "%8s: %10u\n", "TOTAL", sc->sc_debug.stats.istats.total);
216 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
219 static const struct file_operations fops_interrupt = {
220 .read = read_file_interrupt,
221 .open = ath9k_debugfs_open,
226 int ath9k_init_debug(struct ath_softc *sc)
228 sc->sc_debug.debug_mask = ath9k_debug;
230 sc->sc_debug.debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
231 if (!sc->sc_debug.debugfs_root)
234 sc->sc_debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
235 sc->sc_debug.debugfs_root);
236 if (!sc->sc_debug.debugfs_phy)
239 sc->sc_debug.debugfs_dma = debugfs_create_file("dma", S_IRUGO,
240 sc->sc_debug.debugfs_phy, sc, &fops_dma);
241 if (!sc->sc_debug.debugfs_dma)
244 sc->sc_debug.debugfs_interrupt = debugfs_create_file("interrupt",
246 sc->sc_debug.debugfs_phy,
247 sc, &fops_interrupt);
248 if (!sc->sc_debug.debugfs_interrupt)
253 ath9k_exit_debug(sc);
257 void ath9k_exit_debug(struct ath_softc *sc)
259 debugfs_remove(sc->sc_debug.debugfs_interrupt);
260 debugfs_remove(sc->sc_debug.debugfs_dma);
261 debugfs_remove(sc->sc_debug.debugfs_phy);
262 debugfs_remove(sc->sc_debug.debugfs_root);