2 * Copyright (c) 2008-2009 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.
17 #include <linux/slab.h>
18 #include <asm/unaligned.h>
22 #define REG_WRITE_D(_ah, _reg, _val) \
23 ath9k_hw_common(_ah)->ops->write((_ah), (_val), (_reg))
24 #define REG_READ_D(_ah, _reg) \
25 ath9k_hw_common(_ah)->ops->read((_ah), (_reg))
27 static int ath9k_debugfs_open(struct inode
*inode
, struct file
*file
)
29 file
->private_data
= inode
->i_private
;
33 #ifdef CONFIG_ATH_DEBUG
35 static ssize_t
read_file_debug(struct file
*file
, char __user
*user_buf
,
36 size_t count
, loff_t
*ppos
)
38 struct ath_softc
*sc
= file
->private_data
;
39 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
43 len
= sprintf(buf
, "0x%08x\n", common
->debug_mask
);
44 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
47 static ssize_t
write_file_debug(struct file
*file
, const char __user
*user_buf
,
48 size_t count
, loff_t
*ppos
)
50 struct ath_softc
*sc
= file
->private_data
;
51 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
56 len
= min(count
, sizeof(buf
) - 1);
57 if (copy_from_user(buf
, user_buf
, len
))
61 if (strict_strtoul(buf
, 0, &mask
))
64 common
->debug_mask
= mask
;
68 static const struct file_operations fops_debug
= {
69 .read
= read_file_debug
,
70 .write
= write_file_debug
,
71 .open
= ath9k_debugfs_open
,
73 .llseek
= default_llseek
,
78 #define DMA_BUF_LEN 1024
80 static ssize_t
read_file_tx_chainmask(struct file
*file
, char __user
*user_buf
,
81 size_t count
, loff_t
*ppos
)
83 struct ath_softc
*sc
= file
->private_data
;
84 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
88 len
= sprintf(buf
, "0x%08x\n", common
->tx_chainmask
);
89 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
92 static ssize_t
write_file_tx_chainmask(struct file
*file
, const char __user
*user_buf
,
93 size_t count
, loff_t
*ppos
)
95 struct ath_softc
*sc
= file
->private_data
;
96 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
101 len
= min(count
, sizeof(buf
) - 1);
102 if (copy_from_user(buf
, user_buf
, len
))
106 if (strict_strtoul(buf
, 0, &mask
))
109 common
->tx_chainmask
= mask
;
110 sc
->sc_ah
->caps
.tx_chainmask
= mask
;
114 static const struct file_operations fops_tx_chainmask
= {
115 .read
= read_file_tx_chainmask
,
116 .write
= write_file_tx_chainmask
,
117 .open
= ath9k_debugfs_open
,
118 .owner
= THIS_MODULE
,
119 .llseek
= default_llseek
,
123 static ssize_t
read_file_rx_chainmask(struct file
*file
, char __user
*user_buf
,
124 size_t count
, loff_t
*ppos
)
126 struct ath_softc
*sc
= file
->private_data
;
127 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
131 len
= sprintf(buf
, "0x%08x\n", common
->rx_chainmask
);
132 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
135 static ssize_t
write_file_rx_chainmask(struct file
*file
, const char __user
*user_buf
,
136 size_t count
, loff_t
*ppos
)
138 struct ath_softc
*sc
= file
->private_data
;
139 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
144 len
= min(count
, sizeof(buf
) - 1);
145 if (copy_from_user(buf
, user_buf
, len
))
149 if (strict_strtoul(buf
, 0, &mask
))
152 common
->rx_chainmask
= mask
;
153 sc
->sc_ah
->caps
.rx_chainmask
= mask
;
157 static const struct file_operations fops_rx_chainmask
= {
158 .read
= read_file_rx_chainmask
,
159 .write
= write_file_rx_chainmask
,
160 .open
= ath9k_debugfs_open
,
161 .owner
= THIS_MODULE
,
162 .llseek
= default_llseek
,
166 static ssize_t
read_file_dma(struct file
*file
, char __user
*user_buf
,
167 size_t count
, loff_t
*ppos
)
169 struct ath_softc
*sc
= file
->private_data
;
170 struct ath_hw
*ah
= sc
->sc_ah
;
173 unsigned int len
= 0;
174 u32 val
[ATH9K_NUM_DMA_DEBUG_REGS
];
175 int i
, qcuOffset
= 0, dcuOffset
= 0;
176 u32
*qcuBase
= &val
[0], *dcuBase
= &val
[4];
178 buf
= kmalloc(DMA_BUF_LEN
, GFP_KERNEL
);
184 REG_WRITE_D(ah
, AR_MACMISC
,
185 ((AR_MACMISC_DMA_OBS_LINE_8
<< AR_MACMISC_DMA_OBS_S
) |
186 (AR_MACMISC_MISC_OBS_BUS_1
<<
187 AR_MACMISC_MISC_OBS_BUS_MSB_S
)));
189 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
190 "Raw DMA Debug values:\n");
192 for (i
= 0; i
< ATH9K_NUM_DMA_DEBUG_REGS
; i
++) {
194 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
, "\n");
196 val
[i
] = REG_READ_D(ah
, AR_DMADBG_0
+ (i
* sizeof(u32
)));
197 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
, "%d: %08x ",
201 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
, "\n\n");
202 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
203 "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
205 for (i
= 0; i
< ATH9K_NUM_QUEUES
; i
++, qcuOffset
+= 4, dcuOffset
+= 5) {
216 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
217 "%2d %2x %1x %2x %2x\n",
218 i
, (*qcuBase
& (0x7 << qcuOffset
)) >> qcuOffset
,
219 (*qcuBase
& (0x8 << qcuOffset
)) >> (qcuOffset
+ 3),
220 val
[2] & (0x7 << (i
* 3)) >> (i
* 3),
221 (*dcuBase
& (0x1f << dcuOffset
)) >> dcuOffset
);
224 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
, "\n");
226 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
227 "qcu_stitch state: %2x qcu_fetch state: %2x\n",
228 (val
[3] & 0x003c0000) >> 18, (val
[3] & 0x03c00000) >> 22);
229 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
230 "qcu_complete state: %2x dcu_complete state: %2x\n",
231 (val
[3] & 0x1c000000) >> 26, (val
[6] & 0x3));
232 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
233 "dcu_arb state: %2x dcu_fp state: %2x\n",
234 (val
[5] & 0x06000000) >> 25, (val
[5] & 0x38000000) >> 27);
235 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
236 "chan_idle_dur: %3d chan_idle_dur_valid: %1d\n",
237 (val
[6] & 0x000003fc) >> 2, (val
[6] & 0x00000400) >> 10);
238 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
239 "txfifo_valid_0: %1d txfifo_valid_1: %1d\n",
240 (val
[6] & 0x00000800) >> 11, (val
[6] & 0x00001000) >> 12);
241 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
242 "txfifo_dcu_num_0: %2d txfifo_dcu_num_1: %2d\n",
243 (val
[6] & 0x0001e000) >> 13, (val
[6] & 0x001e0000) >> 17);
245 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
, "pcu observe: 0x%x\n",
246 REG_READ_D(ah
, AR_OBS_BUS_1
));
247 len
+= snprintf(buf
+ len
, DMA_BUF_LEN
- len
,
248 "AR_CR: 0x%x\n", REG_READ_D(ah
, AR_CR
));
250 ath9k_ps_restore(sc
);
252 if (len
> DMA_BUF_LEN
)
255 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
260 static const struct file_operations fops_dma
= {
261 .read
= read_file_dma
,
262 .open
= ath9k_debugfs_open
,
263 .owner
= THIS_MODULE
,
264 .llseek
= default_llseek
,
268 void ath_debug_stat_interrupt(struct ath_softc
*sc
, enum ath9k_int status
)
271 sc
->debug
.stats
.istats
.total
++;
272 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) {
273 if (status
& ATH9K_INT_RXLP
)
274 sc
->debug
.stats
.istats
.rxlp
++;
275 if (status
& ATH9K_INT_RXHP
)
276 sc
->debug
.stats
.istats
.rxhp
++;
277 if (status
& ATH9K_INT_BB_WATCHDOG
)
278 sc
->debug
.stats
.istats
.bb_watchdog
++;
280 if (status
& ATH9K_INT_RX
)
281 sc
->debug
.stats
.istats
.rxok
++;
283 if (status
& ATH9K_INT_RXEOL
)
284 sc
->debug
.stats
.istats
.rxeol
++;
285 if (status
& ATH9K_INT_RXORN
)
286 sc
->debug
.stats
.istats
.rxorn
++;
287 if (status
& ATH9K_INT_TX
)
288 sc
->debug
.stats
.istats
.txok
++;
289 if (status
& ATH9K_INT_TXURN
)
290 sc
->debug
.stats
.istats
.txurn
++;
291 if (status
& ATH9K_INT_MIB
)
292 sc
->debug
.stats
.istats
.mib
++;
293 if (status
& ATH9K_INT_RXPHY
)
294 sc
->debug
.stats
.istats
.rxphyerr
++;
295 if (status
& ATH9K_INT_RXKCM
)
296 sc
->debug
.stats
.istats
.rx_keycache_miss
++;
297 if (status
& ATH9K_INT_SWBA
)
298 sc
->debug
.stats
.istats
.swba
++;
299 if (status
& ATH9K_INT_BMISS
)
300 sc
->debug
.stats
.istats
.bmiss
++;
301 if (status
& ATH9K_INT_BNR
)
302 sc
->debug
.stats
.istats
.bnr
++;
303 if (status
& ATH9K_INT_CST
)
304 sc
->debug
.stats
.istats
.cst
++;
305 if (status
& ATH9K_INT_GTT
)
306 sc
->debug
.stats
.istats
.gtt
++;
307 if (status
& ATH9K_INT_TIM
)
308 sc
->debug
.stats
.istats
.tim
++;
309 if (status
& ATH9K_INT_CABEND
)
310 sc
->debug
.stats
.istats
.cabend
++;
311 if (status
& ATH9K_INT_DTIMSYNC
)
312 sc
->debug
.stats
.istats
.dtimsync
++;
313 if (status
& ATH9K_INT_DTIM
)
314 sc
->debug
.stats
.istats
.dtim
++;
317 static ssize_t
read_file_interrupt(struct file
*file
, char __user
*user_buf
,
318 size_t count
, loff_t
*ppos
)
320 struct ath_softc
*sc
= file
->private_data
;
322 unsigned int len
= 0;
324 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) {
325 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
326 "%8s: %10u\n", "RXLP", sc
->debug
.stats
.istats
.rxlp
);
327 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
328 "%8s: %10u\n", "RXHP", sc
->debug
.stats
.istats
.rxhp
);
329 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
330 "%8s: %10u\n", "WATCHDOG",
331 sc
->debug
.stats
.istats
.bb_watchdog
);
333 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
334 "%8s: %10u\n", "RX", sc
->debug
.stats
.istats
.rxok
);
336 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
337 "%8s: %10u\n", "RXEOL", sc
->debug
.stats
.istats
.rxeol
);
338 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
339 "%8s: %10u\n", "RXORN", sc
->debug
.stats
.istats
.rxorn
);
340 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
341 "%8s: %10u\n", "TX", sc
->debug
.stats
.istats
.txok
);
342 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
343 "%8s: %10u\n", "TXURN", sc
->debug
.stats
.istats
.txurn
);
344 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
345 "%8s: %10u\n", "MIB", sc
->debug
.stats
.istats
.mib
);
346 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
347 "%8s: %10u\n", "RXPHY", sc
->debug
.stats
.istats
.rxphyerr
);
348 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
349 "%8s: %10u\n", "RXKCM", sc
->debug
.stats
.istats
.rx_keycache_miss
);
350 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
351 "%8s: %10u\n", "SWBA", sc
->debug
.stats
.istats
.swba
);
352 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
353 "%8s: %10u\n", "BMISS", sc
->debug
.stats
.istats
.bmiss
);
354 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
355 "%8s: %10u\n", "BNR", sc
->debug
.stats
.istats
.bnr
);
356 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
357 "%8s: %10u\n", "CST", sc
->debug
.stats
.istats
.cst
);
358 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
359 "%8s: %10u\n", "GTT", sc
->debug
.stats
.istats
.gtt
);
360 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
361 "%8s: %10u\n", "TIM", sc
->debug
.stats
.istats
.tim
);
362 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
363 "%8s: %10u\n", "CABEND", sc
->debug
.stats
.istats
.cabend
);
364 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
365 "%8s: %10u\n", "DTIMSYNC", sc
->debug
.stats
.istats
.dtimsync
);
366 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
367 "%8s: %10u\n", "DTIM", sc
->debug
.stats
.istats
.dtim
);
368 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
369 "%8s: %10u\n", "TOTAL", sc
->debug
.stats
.istats
.total
);
371 if (len
> sizeof(buf
))
374 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
377 static const struct file_operations fops_interrupt
= {
378 .read
= read_file_interrupt
,
379 .open
= ath9k_debugfs_open
,
380 .owner
= THIS_MODULE
,
381 .llseek
= default_llseek
,
384 static const char * ath_wiphy_state_str(enum ath_wiphy_state state
)
387 case ATH_WIPHY_INACTIVE
:
389 case ATH_WIPHY_ACTIVE
:
391 case ATH_WIPHY_PAUSING
:
393 case ATH_WIPHY_PAUSED
:
401 static ssize_t
read_file_wiphy(struct file
*file
, char __user
*user_buf
,
402 size_t count
, loff_t
*ppos
)
404 struct ath_softc
*sc
= file
->private_data
;
405 struct ath_wiphy
*aphy
= sc
->pri_wiphy
;
406 struct ieee80211_channel
*chan
= aphy
->hw
->conf
.channel
;
408 unsigned int len
= 0;
413 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
414 "primary: %s (%s chan=%d ht=%d)\n",
415 wiphy_name(sc
->pri_wiphy
->hw
->wiphy
),
416 ath_wiphy_state_str(sc
->pri_wiphy
->state
),
417 ieee80211_frequency_to_channel(chan
->center_freq
),
420 put_unaligned_le32(REG_READ_D(sc
->sc_ah
, AR_STA_ID0
), addr
);
421 put_unaligned_le16(REG_READ_D(sc
->sc_ah
, AR_STA_ID1
) & 0xffff, addr
+ 4);
422 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
423 "addr: %pM\n", addr
);
424 put_unaligned_le32(REG_READ_D(sc
->sc_ah
, AR_BSSMSKL
), addr
);
425 put_unaligned_le16(REG_READ_D(sc
->sc_ah
, AR_BSSMSKU
) & 0xffff, addr
+ 4);
426 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
427 "addrmask: %pM\n", addr
);
428 tmp
= ath9k_hw_getrxfilter(sc
->sc_ah
);
429 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
431 if (tmp
& ATH9K_RX_FILTER_UCAST
)
432 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " UCAST");
433 if (tmp
& ATH9K_RX_FILTER_MCAST
)
434 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " MCAST");
435 if (tmp
& ATH9K_RX_FILTER_BCAST
)
436 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " BCAST");
437 if (tmp
& ATH9K_RX_FILTER_CONTROL
)
438 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " CONTROL");
439 if (tmp
& ATH9K_RX_FILTER_BEACON
)
440 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " BEACON");
441 if (tmp
& ATH9K_RX_FILTER_PROM
)
442 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " PROM");
443 if (tmp
& ATH9K_RX_FILTER_PROBEREQ
)
444 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " PROBEREQ");
445 if (tmp
& ATH9K_RX_FILTER_PHYERR
)
446 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " PHYERR");
447 if (tmp
& ATH9K_RX_FILTER_MYBEACON
)
448 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " MYBEACON");
449 if (tmp
& ATH9K_RX_FILTER_COMP_BAR
)
450 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " COMP_BAR");
451 if (tmp
& ATH9K_RX_FILTER_PSPOLL
)
452 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " PSPOLL");
453 if (tmp
& ATH9K_RX_FILTER_PHYRADAR
)
454 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " PHYRADAR");
455 if (tmp
& ATH9K_RX_FILTER_MCAST_BCAST_ALL
)
456 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, " MCAST_BCAST_ALL\n");
458 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
, "\n");
460 /* Put variable-length stuff down here, and check for overflows. */
461 for (i
= 0; i
< sc
->num_sec_wiphy
; i
++) {
462 struct ath_wiphy
*aphy_tmp
= sc
->sec_wiphy
[i
];
463 if (aphy_tmp
== NULL
)
465 chan
= aphy_tmp
->hw
->conf
.channel
;
466 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
467 "secondary: %s (%s chan=%d ht=%d)\n",
468 wiphy_name(aphy_tmp
->hw
->wiphy
),
469 ath_wiphy_state_str(aphy_tmp
->state
),
470 ieee80211_frequency_to_channel(chan
->center_freq
),
471 aphy_tmp
->chan_is_ht
);
473 if (len
> sizeof(buf
))
476 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
479 static struct ath_wiphy
* get_wiphy(struct ath_softc
*sc
, const char *name
)
482 if (strcmp(name
, wiphy_name(sc
->pri_wiphy
->hw
->wiphy
)) == 0)
483 return sc
->pri_wiphy
;
484 for (i
= 0; i
< sc
->num_sec_wiphy
; i
++) {
485 struct ath_wiphy
*aphy
= sc
->sec_wiphy
[i
];
486 if (aphy
&& strcmp(name
, wiphy_name(aphy
->hw
->wiphy
)) == 0)
492 static int del_wiphy(struct ath_softc
*sc
, const char *name
)
494 struct ath_wiphy
*aphy
= get_wiphy(sc
, name
);
497 return ath9k_wiphy_del(aphy
);
500 static int pause_wiphy(struct ath_softc
*sc
, const char *name
)
502 struct ath_wiphy
*aphy
= get_wiphy(sc
, name
);
505 return ath9k_wiphy_pause(aphy
);
508 static int unpause_wiphy(struct ath_softc
*sc
, const char *name
)
510 struct ath_wiphy
*aphy
= get_wiphy(sc
, name
);
513 return ath9k_wiphy_unpause(aphy
);
516 static int select_wiphy(struct ath_softc
*sc
, const char *name
)
518 struct ath_wiphy
*aphy
= get_wiphy(sc
, name
);
521 return ath9k_wiphy_select(aphy
);
524 static int schedule_wiphy(struct ath_softc
*sc
, const char *msec
)
526 ath9k_wiphy_set_scheduler(sc
, simple_strtoul(msec
, NULL
, 0));
530 static ssize_t
write_file_wiphy(struct file
*file
, const char __user
*user_buf
,
531 size_t count
, loff_t
*ppos
)
533 struct ath_softc
*sc
= file
->private_data
;
537 len
= min(count
, sizeof(buf
) - 1);
538 if (copy_from_user(buf
, user_buf
, len
))
541 if (len
> 0 && buf
[len
- 1] == '\n')
544 if (strncmp(buf
, "add", 3) == 0) {
545 int res
= ath9k_wiphy_add(sc
);
548 } else if (strncmp(buf
, "del=", 4) == 0) {
549 int res
= del_wiphy(sc
, buf
+ 4);
552 } else if (strncmp(buf
, "pause=", 6) == 0) {
553 int res
= pause_wiphy(sc
, buf
+ 6);
556 } else if (strncmp(buf
, "unpause=", 8) == 0) {
557 int res
= unpause_wiphy(sc
, buf
+ 8);
560 } else if (strncmp(buf
, "select=", 7) == 0) {
561 int res
= select_wiphy(sc
, buf
+ 7);
564 } else if (strncmp(buf
, "schedule=", 9) == 0) {
565 int res
= schedule_wiphy(sc
, buf
+ 9);
574 static const struct file_operations fops_wiphy
= {
575 .read
= read_file_wiphy
,
576 .write
= write_file_wiphy
,
577 .open
= ath9k_debugfs_open
,
578 .owner
= THIS_MODULE
,
579 .llseek
= default_llseek
,
582 #define PR(str, elem) \
584 len += snprintf(buf + len, size - len, \
585 "%s%13u%11u%10u%10u\n", str, \
586 sc->debug.stats.txstats[WME_AC_BE].elem, \
587 sc->debug.stats.txstats[WME_AC_BK].elem, \
588 sc->debug.stats.txstats[WME_AC_VI].elem, \
589 sc->debug.stats.txstats[WME_AC_VO].elem); \
594 #define PRX(str, elem) \
596 len += snprintf(buf + len, size - len, \
597 "%s%13u%11u%10u%10u\n", str, \
598 (unsigned int)(sc->tx.txq[WME_AC_BE].elem), \
599 (unsigned int)(sc->tx.txq[WME_AC_BK].elem), \
600 (unsigned int)(sc->tx.txq[WME_AC_VI].elem), \
601 (unsigned int)(sc->tx.txq[WME_AC_VO].elem)); \
606 #define PRQLE(str, elem) \
608 len += snprintf(buf + len, size - len, \
609 "%s%13i%11i%10i%10i\n", str, \
610 list_empty(&sc->tx.txq[WME_AC_BE].elem), \
611 list_empty(&sc->tx.txq[WME_AC_BK].elem), \
612 list_empty(&sc->tx.txq[WME_AC_VI].elem), \
613 list_empty(&sc->tx.txq[WME_AC_VO].elem)); \
618 static ssize_t
read_file_xmit(struct file
*file
, char __user
*user_buf
,
619 size_t count
, loff_t
*ppos
)
621 struct ath_softc
*sc
= file
->private_data
;
623 unsigned int len
= 0, size
= 8000;
628 buf
= kzalloc(size
, GFP_KERNEL
);
632 len
+= sprintf(buf
, "Num-Tx-Queues: %i tx-queues-setup: 0x%x"
633 " poll-work-seen: %u\n"
634 "%30s %10s%10s%10s\n\n",
635 ATH9K_NUM_TX_QUEUES
, sc
->tx
.txqsetup
,
636 sc
->tx_complete_poll_work_seen
,
637 "BE", "BK", "VI", "VO");
639 PR("MPDUs Queued: ", queued
);
640 PR("MPDUs Completed: ", completed
);
641 PR("Aggregates: ", a_aggr
);
642 PR("AMPDUs Queued HW:", a_queued_hw
);
643 PR("AMPDUs Queued SW:", a_queued_sw
);
644 PR("AMPDUs Completed:", a_completed
);
645 PR("AMPDUs Retried: ", a_retries
);
646 PR("AMPDUs XRetried: ", a_xretries
);
647 PR("FIFO Underrun: ", fifo_underrun
);
648 PR("TXOP Exceeded: ", xtxop
);
649 PR("TXTIMER Expiry: ", timer_exp
);
650 PR("DESC CFG Error: ", desc_cfg_err
);
651 PR("DATA Underrun: ", data_underrun
);
652 PR("DELIM Underrun: ", delim_underrun
);
653 PR("TX-Pkts-All: ", tx_pkts_all
);
654 PR("TX-Bytes-All: ", tx_bytes_all
);
655 PR("hw-put-tx-buf: ", puttxbuf
);
656 PR("hw-tx-start: ", txstart
);
657 PR("hw-tx-proc-desc: ", txprocdesc
);
658 len
+= snprintf(buf
+ len
, size
- len
,
659 "%s%11p%11p%10p%10p\n", "txq-memory-address:",
660 &(sc
->tx
.txq
[WME_AC_BE
]),
661 &(sc
->tx
.txq
[WME_AC_BK
]),
662 &(sc
->tx
.txq
[WME_AC_VI
]),
663 &(sc
->tx
.txq
[WME_AC_VO
]));
667 PRX("axq-qnum: ", axq_qnum
);
668 PRX("axq-depth: ", axq_depth
);
669 PRX("axq-ampdu_depth: ", axq_ampdu_depth
);
670 PRX("axq-stopped ", stopped
);
671 PRX("tx-in-progress ", axq_tx_inprogress
);
672 PRX("pending-frames ", pending_frames
);
673 PRX("txq_headidx: ", txq_headidx
);
674 PRX("txq_tailidx: ", txq_headidx
);
676 PRQLE("axq_q empty: ", axq_q
);
677 PRQLE("axq_acq empty: ", axq_acq
);
678 PRQLE("txq_fifo_pending: ", txq_fifo_pending
);
679 for (i
= 0; i
< ATH_TXFIFO_DEPTH
; i
++) {
680 snprintf(tmp
, sizeof(tmp
) - 1, "txq_fifo[%i] empty: ", i
);
681 PRQLE(tmp
, txq_fifo
[i
]);
684 /* Print out more detailed queue-info */
685 for (i
= 0; i
<= WME_AC_BK
; i
++) {
686 struct ath_txq
*txq
= &(sc
->tx
.txq
[i
]);
687 struct ath_atx_ac
*ac
;
688 struct ath_atx_tid
*tid
;
691 spin_lock_bh(&txq
->axq_lock
);
692 if (!list_empty(&txq
->axq_acq
)) {
693 ac
= list_first_entry(&txq
->axq_acq
, struct ath_atx_ac
,
695 len
+= snprintf(buf
+ len
, size
- len
,
696 "txq[%i] first-ac: %p sched: %i\n",
698 if (list_empty(&ac
->tid_q
) || (len
>= size
))
700 tid
= list_first_entry(&ac
->tid_q
, struct ath_atx_tid
,
702 len
+= snprintf(buf
+ len
, size
- len
,
703 " first-tid: %p sched: %i paused: %i\n",
704 tid
, tid
->sched
, tid
->paused
);
707 spin_unlock_bh(&txq
->axq_lock
);
714 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
720 static ssize_t
read_file_stations(struct file
*file
, char __user
*user_buf
,
721 size_t count
, loff_t
*ppos
)
723 struct ath_softc
*sc
= file
->private_data
;
725 unsigned int len
= 0, size
= 64000;
726 struct ath_node
*an
= NULL
;
730 buf
= kzalloc(size
, GFP_KERNEL
);
734 len
+= snprintf(buf
+ len
, size
- len
,
736 " tid: addr sched paused buf_q-empty an ac\n"
737 " ac: addr sched tid_q-empty txq\n");
739 spin_lock(&sc
->nodes_lock
);
740 list_for_each_entry(an
, &sc
->nodes
, list
) {
741 len
+= snprintf(buf
+ len
, size
- len
,
742 "%pM\n", an
->sta
->addr
);
746 for (q
= 0; q
< WME_NUM_TID
; q
++) {
747 struct ath_atx_tid
*tid
= &(an
->tid
[q
]);
748 len
+= snprintf(buf
+ len
, size
- len
,
749 " tid: %p %s %s %i %p %p\n",
750 tid
, tid
->sched
? "sched" : "idle",
751 tid
->paused
? "paused" : "running",
752 list_empty(&tid
->buf_q
),
758 for (q
= 0; q
< WME_NUM_AC
; q
++) {
759 struct ath_atx_ac
*ac
= &(an
->ac
[q
]);
760 len
+= snprintf(buf
+ len
, size
- len
,
761 " ac: %p %s %i %p\n",
762 ac
, ac
->sched
? "sched" : "idle",
763 list_empty(&ac
->tid_q
), ac
->txq
);
770 spin_unlock(&sc
->nodes_lock
);
774 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
780 void ath_debug_stat_tx(struct ath_softc
*sc
, struct ath_buf
*bf
,
781 struct ath_tx_status
*ts
)
783 int qnum
= skb_get_queue_mapping(bf
->bf_mpdu
);
785 TX_STAT_INC(qnum
, tx_pkts_all
);
786 sc
->debug
.stats
.txstats
[qnum
].tx_bytes_all
+= bf
->bf_mpdu
->len
;
788 if (bf_isampdu(bf
)) {
789 if (bf_isxretried(bf
))
790 TX_STAT_INC(qnum
, a_xretries
);
792 TX_STAT_INC(qnum
, a_completed
);
794 TX_STAT_INC(qnum
, completed
);
797 if (ts
->ts_status
& ATH9K_TXERR_FIFO
)
798 TX_STAT_INC(qnum
, fifo_underrun
);
799 if (ts
->ts_status
& ATH9K_TXERR_XTXOP
)
800 TX_STAT_INC(qnum
, xtxop
);
801 if (ts
->ts_status
& ATH9K_TXERR_TIMER_EXPIRED
)
802 TX_STAT_INC(qnum
, timer_exp
);
803 if (ts
->ts_flags
& ATH9K_TX_DESC_CFG_ERR
)
804 TX_STAT_INC(qnum
, desc_cfg_err
);
805 if (ts
->ts_flags
& ATH9K_TX_DATA_UNDERRUN
)
806 TX_STAT_INC(qnum
, data_underrun
);
807 if (ts
->ts_flags
& ATH9K_TX_DELIM_UNDERRUN
)
808 TX_STAT_INC(qnum
, delim_underrun
);
811 static const struct file_operations fops_xmit
= {
812 .read
= read_file_xmit
,
813 .open
= ath9k_debugfs_open
,
814 .owner
= THIS_MODULE
,
815 .llseek
= default_llseek
,
818 static const struct file_operations fops_stations
= {
819 .read
= read_file_stations
,
820 .open
= ath9k_debugfs_open
,
821 .owner
= THIS_MODULE
,
822 .llseek
= default_llseek
,
825 static ssize_t
read_file_recv(struct file
*file
, char __user
*user_buf
,
826 size_t count
, loff_t
*ppos
)
828 #define PHY_ERR(s, p) \
829 len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
830 sc->debug.stats.rxstats.phy_err_stats[p]);
832 struct ath_softc
*sc
= file
->private_data
;
834 unsigned int len
= 0, size
= 1152;
837 buf
= kzalloc(size
, GFP_KERNEL
);
841 len
+= snprintf(buf
+ len
, size
- len
,
842 "%18s : %10u\n", "CRC ERR",
843 sc
->debug
.stats
.rxstats
.crc_err
);
844 len
+= snprintf(buf
+ len
, size
- len
,
845 "%18s : %10u\n", "DECRYPT CRC ERR",
846 sc
->debug
.stats
.rxstats
.decrypt_crc_err
);
847 len
+= snprintf(buf
+ len
, size
- len
,
848 "%18s : %10u\n", "PHY ERR",
849 sc
->debug
.stats
.rxstats
.phy_err
);
850 len
+= snprintf(buf
+ len
, size
- len
,
851 "%18s : %10u\n", "MIC ERR",
852 sc
->debug
.stats
.rxstats
.mic_err
);
853 len
+= snprintf(buf
+ len
, size
- len
,
854 "%18s : %10u\n", "PRE-DELIM CRC ERR",
855 sc
->debug
.stats
.rxstats
.pre_delim_crc_err
);
856 len
+= snprintf(buf
+ len
, size
- len
,
857 "%18s : %10u\n", "POST-DELIM CRC ERR",
858 sc
->debug
.stats
.rxstats
.post_delim_crc_err
);
859 len
+= snprintf(buf
+ len
, size
- len
,
860 "%18s : %10u\n", "DECRYPT BUSY ERR",
861 sc
->debug
.stats
.rxstats
.decrypt_busy_err
);
863 PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN
);
864 PHY_ERR("TIMING", ATH9K_PHYERR_TIMING
);
865 PHY_ERR("PARITY", ATH9K_PHYERR_PARITY
);
866 PHY_ERR("RATE", ATH9K_PHYERR_RATE
);
867 PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH
);
868 PHY_ERR("RADAR", ATH9K_PHYERR_RADAR
);
869 PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE
);
870 PHY_ERR("TOR", ATH9K_PHYERR_TOR
);
871 PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING
);
872 PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY
);
873 PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL
);
874 PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL
);
875 PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP
);
876 PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE
);
877 PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART
);
878 PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT
);
879 PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING
);
880 PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC
);
881 PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL
);
882 PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE
);
883 PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART
);
884 PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL
);
885 PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP
);
886 PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR
);
887 PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL
);
888 PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL
);
890 len
+= snprintf(buf
+ len
, size
- len
,
891 "%18s : %10u\n", "RX-Pkts-All",
892 sc
->debug
.stats
.rxstats
.rx_pkts_all
);
893 len
+= snprintf(buf
+ len
, size
- len
,
894 "%18s : %10u\n", "RX-Bytes-All",
895 sc
->debug
.stats
.rxstats
.rx_bytes_all
);
900 retval
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
908 void ath_debug_stat_rx(struct ath_softc
*sc
, struct ath_rx_status
*rs
)
910 #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
911 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
915 RX_STAT_INC(rx_pkts_all
);
916 sc
->debug
.stats
.rxstats
.rx_bytes_all
+= rs
->rs_datalen
;
918 if (rs
->rs_status
& ATH9K_RXERR_CRC
)
919 RX_STAT_INC(crc_err
);
920 if (rs
->rs_status
& ATH9K_RXERR_DECRYPT
)
921 RX_STAT_INC(decrypt_crc_err
);
922 if (rs
->rs_status
& ATH9K_RXERR_MIC
)
923 RX_STAT_INC(mic_err
);
924 if (rs
->rs_status
& ATH9K_RX_DELIM_CRC_PRE
)
925 RX_STAT_INC(pre_delim_crc_err
);
926 if (rs
->rs_status
& ATH9K_RX_DELIM_CRC_POST
)
927 RX_STAT_INC(post_delim_crc_err
);
928 if (rs
->rs_status
& ATH9K_RX_DECRYPT_BUSY
)
929 RX_STAT_INC(decrypt_busy_err
);
931 if (rs
->rs_status
& ATH9K_RXERR_PHY
) {
932 RX_STAT_INC(phy_err
);
933 phyerr
= rs
->rs_phyerr
& 0x24;
934 RX_PHY_ERR_INC(phyerr
);
938 #undef RX_PHY_ERR_INC
941 static const struct file_operations fops_recv
= {
942 .read
= read_file_recv
,
943 .open
= ath9k_debugfs_open
,
944 .owner
= THIS_MODULE
,
945 .llseek
= default_llseek
,
948 static ssize_t
read_file_regidx(struct file
*file
, char __user
*user_buf
,
949 size_t count
, loff_t
*ppos
)
951 struct ath_softc
*sc
= file
->private_data
;
955 len
= sprintf(buf
, "0x%08x\n", sc
->debug
.regidx
);
956 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
959 static ssize_t
write_file_regidx(struct file
*file
, const char __user
*user_buf
,
960 size_t count
, loff_t
*ppos
)
962 struct ath_softc
*sc
= file
->private_data
;
963 unsigned long regidx
;
967 len
= min(count
, sizeof(buf
) - 1);
968 if (copy_from_user(buf
, user_buf
, len
))
972 if (strict_strtoul(buf
, 0, ®idx
))
975 sc
->debug
.regidx
= regidx
;
979 static const struct file_operations fops_regidx
= {
980 .read
= read_file_regidx
,
981 .write
= write_file_regidx
,
982 .open
= ath9k_debugfs_open
,
983 .owner
= THIS_MODULE
,
984 .llseek
= default_llseek
,
987 static ssize_t
read_file_regval(struct file
*file
, char __user
*user_buf
,
988 size_t count
, loff_t
*ppos
)
990 struct ath_softc
*sc
= file
->private_data
;
991 struct ath_hw
*ah
= sc
->sc_ah
;
996 regval
= REG_READ_D(ah
, sc
->debug
.regidx
);
997 len
= sprintf(buf
, "0x%08x\n", regval
);
998 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
1001 static ssize_t
write_file_regval(struct file
*file
, const char __user
*user_buf
,
1002 size_t count
, loff_t
*ppos
)
1004 struct ath_softc
*sc
= file
->private_data
;
1005 struct ath_hw
*ah
= sc
->sc_ah
;
1006 unsigned long regval
;
1010 len
= min(count
, sizeof(buf
) - 1);
1011 if (copy_from_user(buf
, user_buf
, len
))
1015 if (strict_strtoul(buf
, 0, ®val
))
1018 REG_WRITE_D(ah
, sc
->debug
.regidx
, regval
);
1022 static const struct file_operations fops_regval
= {
1023 .read
= read_file_regval
,
1024 .write
= write_file_regval
,
1025 .open
= ath9k_debugfs_open
,
1026 .owner
= THIS_MODULE
,
1027 .llseek
= default_llseek
,
1030 int ath9k_init_debug(struct ath_hw
*ah
)
1032 struct ath_common
*common
= ath9k_hw_common(ah
);
1033 struct ath_softc
*sc
= (struct ath_softc
*) common
->priv
;
1035 sc
->debug
.debugfs_phy
= debugfs_create_dir("ath9k",
1036 sc
->hw
->wiphy
->debugfsdir
);
1037 if (!sc
->debug
.debugfs_phy
)
1040 #ifdef CONFIG_ATH_DEBUG
1041 if (!debugfs_create_file("debug", S_IRUSR
| S_IWUSR
,
1042 sc
->debug
.debugfs_phy
, sc
, &fops_debug
))
1046 if (!debugfs_create_file("dma", S_IRUSR
, sc
->debug
.debugfs_phy
,
1050 if (!debugfs_create_file("interrupt", S_IRUSR
, sc
->debug
.debugfs_phy
,
1051 sc
, &fops_interrupt
))
1054 if (!debugfs_create_file("wiphy", S_IRUSR
| S_IWUSR
,
1055 sc
->debug
.debugfs_phy
, sc
, &fops_wiphy
))
1058 if (!debugfs_create_file("xmit", S_IRUSR
, sc
->debug
.debugfs_phy
,
1062 if (!debugfs_create_file("stations", S_IRUSR
, sc
->debug
.debugfs_phy
,
1063 sc
, &fops_stations
))
1066 if (!debugfs_create_file("recv", S_IRUSR
, sc
->debug
.debugfs_phy
,
1070 if (!debugfs_create_file("rx_chainmask", S_IRUSR
| S_IWUSR
,
1071 sc
->debug
.debugfs_phy
, sc
, &fops_rx_chainmask
))
1074 if (!debugfs_create_file("tx_chainmask", S_IRUSR
| S_IWUSR
,
1075 sc
->debug
.debugfs_phy
, sc
, &fops_tx_chainmask
))
1078 if (!debugfs_create_file("regidx", S_IRUSR
| S_IWUSR
,
1079 sc
->debug
.debugfs_phy
, sc
, &fops_regidx
))
1082 if (!debugfs_create_file("regval", S_IRUSR
| S_IWUSR
,
1083 sc
->debug
.debugfs_phy
, sc
, &fops_regval
))
1086 if (!debugfs_create_bool("ignore_extcca", S_IRUSR
| S_IWUSR
,
1087 sc
->debug
.debugfs_phy
, &ah
->config
.cwm_ignore_extcca
))
1090 sc
->debug
.regidx
= 0;
1093 debugfs_remove_recursive(sc
->debug
.debugfs_phy
);
1094 sc
->debug
.debugfs_phy
= NULL
;