atheros: add common debug printing
[cascardo/linux.git] / drivers / net / wireless / ath / ath9k / debug.c
1 /*
2  * Copyright (c) 2008-2009 Atheros Communications Inc.
3  *
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.
7  *
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.
15  */
16
17 #include <asm/unaligned.h>
18
19 #include "ath9k.h"
20
21 static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
22 module_param_named(debug, ath9k_debug, uint, 0);
23
24 static struct dentry *ath9k_debugfs_root;
25
26 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
27 {
28         file->private_data = inode->i_private;
29         return 0;
30 }
31
32 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
33                              size_t count, loff_t *ppos)
34 {
35         struct ath_softc *sc = file->private_data;
36         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
37         char buf[32];
38         unsigned int len;
39
40         len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask);
41         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
42 }
43
44 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
45                              size_t count, loff_t *ppos)
46 {
47         struct ath_softc *sc = file->private_data;
48         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
49         unsigned long mask;
50         char buf[32];
51         ssize_t len;
52
53         len = min(count, sizeof(buf) - 1);
54         if (copy_from_user(buf, user_buf, len))
55                 return -EINVAL;
56
57         buf[len] = '\0';
58         if (strict_strtoul(buf, 0, &mask))
59                 return -EINVAL;
60
61         common->debug_mask = mask;
62         return count;
63 }
64
65 static const struct file_operations fops_debug = {
66         .read = read_file_debug,
67         .write = write_file_debug,
68         .open = ath9k_debugfs_open,
69         .owner = THIS_MODULE
70 };
71
72 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
73                              size_t count, loff_t *ppos)
74 {
75         struct ath_softc *sc = file->private_data;
76         struct ath_hw *ah = sc->sc_ah;
77         char buf[1024];
78         unsigned int len = 0;
79         u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
80         int i, qcuOffset = 0, dcuOffset = 0;
81         u32 *qcuBase = &val[0], *dcuBase = &val[4];
82
83         ath9k_ps_wakeup(sc);
84
85         REG_WRITE(ah, AR_MACMISC,
86                   ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
87                    (AR_MACMISC_MISC_OBS_BUS_1 <<
88                     AR_MACMISC_MISC_OBS_BUS_MSB_S)));
89
90         len += snprintf(buf + len, sizeof(buf) - len,
91                         "Raw DMA Debug values:\n");
92
93         for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
94                 if (i % 4 == 0)
95                         len += snprintf(buf + len, sizeof(buf) - len, "\n");
96
97                 val[i] = REG_READ(ah, AR_DMADBG_0 + (i * sizeof(u32)));
98                 len += snprintf(buf + len, sizeof(buf) - len, "%d: %08x ",
99                                 i, val[i]);
100         }
101
102         len += snprintf(buf + len, sizeof(buf) - len, "\n\n");
103         len += snprintf(buf + len, sizeof(buf) - len,
104                         "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
105
106         for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
107                 if (i == 8) {
108                         qcuOffset = 0;
109                         qcuBase++;
110                 }
111
112                 if (i == 6) {
113                         dcuOffset = 0;
114                         dcuBase++;
115                 }
116
117                 len += snprintf(buf + len, sizeof(buf) - len,
118                         "%2d          %2x      %1x     %2x           %2x\n",
119                         i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
120                         (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
121                         val[2] & (0x7 << (i * 3)) >> (i * 3),
122                         (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
123         }
124
125         len += snprintf(buf + len, sizeof(buf) - len, "\n");
126
127         len += snprintf(buf + len, sizeof(buf) - len,
128                 "qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
129                 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
130         len += snprintf(buf + len, sizeof(buf) - len,
131                 "qcu_complete state: %2x    dcu_complete state:     %2x\n",
132                 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
133         len += snprintf(buf + len, sizeof(buf) - len,
134                 "dcu_arb state:      %2x    dcu_fp state:           %2x\n",
135                 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
136         len += snprintf(buf + len, sizeof(buf) - len,
137                 "chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
138                 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
139         len += snprintf(buf + len, sizeof(buf) - len,
140                 "txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
141                 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
142         len += snprintf(buf + len, sizeof(buf) - len,
143                 "txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
144                 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
145
146         len += snprintf(buf + len, sizeof(buf) - len, "pcu observe: 0x%x \n",
147                         REG_READ(ah, AR_OBS_BUS_1));
148         len += snprintf(buf + len, sizeof(buf) - len,
149                         "AR_CR: 0x%x \n", REG_READ(ah, AR_CR));
150
151         ath9k_ps_restore(sc);
152
153         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
154 }
155
156 static const struct file_operations fops_dma = {
157         .read = read_file_dma,
158         .open = ath9k_debugfs_open,
159         .owner = THIS_MODULE
160 };
161
162
163 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
164 {
165         if (status)
166                 sc->debug.stats.istats.total++;
167         if (status & ATH9K_INT_RX)
168                 sc->debug.stats.istats.rxok++;
169         if (status & ATH9K_INT_RXEOL)
170                 sc->debug.stats.istats.rxeol++;
171         if (status & ATH9K_INT_RXORN)
172                 sc->debug.stats.istats.rxorn++;
173         if (status & ATH9K_INT_TX)
174                 sc->debug.stats.istats.txok++;
175         if (status & ATH9K_INT_TXURN)
176                 sc->debug.stats.istats.txurn++;
177         if (status & ATH9K_INT_MIB)
178                 sc->debug.stats.istats.mib++;
179         if (status & ATH9K_INT_RXPHY)
180                 sc->debug.stats.istats.rxphyerr++;
181         if (status & ATH9K_INT_RXKCM)
182                 sc->debug.stats.istats.rx_keycache_miss++;
183         if (status & ATH9K_INT_SWBA)
184                 sc->debug.stats.istats.swba++;
185         if (status & ATH9K_INT_BMISS)
186                 sc->debug.stats.istats.bmiss++;
187         if (status & ATH9K_INT_BNR)
188                 sc->debug.stats.istats.bnr++;
189         if (status & ATH9K_INT_CST)
190                 sc->debug.stats.istats.cst++;
191         if (status & ATH9K_INT_GTT)
192                 sc->debug.stats.istats.gtt++;
193         if (status & ATH9K_INT_TIM)
194                 sc->debug.stats.istats.tim++;
195         if (status & ATH9K_INT_CABEND)
196                 sc->debug.stats.istats.cabend++;
197         if (status & ATH9K_INT_DTIMSYNC)
198                 sc->debug.stats.istats.dtimsync++;
199         if (status & ATH9K_INT_DTIM)
200                 sc->debug.stats.istats.dtim++;
201 }
202
203 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
204                                    size_t count, loff_t *ppos)
205 {
206         struct ath_softc *sc = file->private_data;
207         char buf[512];
208         unsigned int len = 0;
209
210         len += snprintf(buf + len, sizeof(buf) - len,
211                 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
212         len += snprintf(buf + len, sizeof(buf) - len,
213                 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
214         len += snprintf(buf + len, sizeof(buf) - len,
215                 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
216         len += snprintf(buf + len, sizeof(buf) - len,
217                 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
218         len += snprintf(buf + len, sizeof(buf) - len,
219                 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
220         len += snprintf(buf + len, sizeof(buf) - len,
221                 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
222         len += snprintf(buf + len, sizeof(buf) - len,
223                 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
224         len += snprintf(buf + len, sizeof(buf) - len,
225                 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
226         len += snprintf(buf + len, sizeof(buf) - len,
227                 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
228         len += snprintf(buf + len, sizeof(buf) - len,
229                 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
230         len += snprintf(buf + len, sizeof(buf) - len,
231                 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
232         len += snprintf(buf + len, sizeof(buf) - len,
233                 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
234         len += snprintf(buf + len, sizeof(buf) - len,
235                 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
236         len += snprintf(buf + len, sizeof(buf) - len,
237                 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
238         len += snprintf(buf + len, sizeof(buf) - len,
239                 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
240         len += snprintf(buf + len, sizeof(buf) - len,
241                 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
242         len += snprintf(buf + len, sizeof(buf) - len,
243                 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
244         len += snprintf(buf + len, sizeof(buf) - len,
245                 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
246
247         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
248 }
249
250 static const struct file_operations fops_interrupt = {
251         .read = read_file_interrupt,
252         .open = ath9k_debugfs_open,
253         .owner = THIS_MODULE
254 };
255
256 void ath_debug_stat_rc(struct ath_softc *sc, struct sk_buff *skb)
257 {
258         struct ath_tx_info_priv *tx_info_priv = NULL;
259         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
260         struct ieee80211_tx_rate *rates = tx_info->status.rates;
261         int final_ts_idx, idx;
262         struct ath_rc_stats *stats;
263
264         tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
265         final_ts_idx = tx_info_priv->tx.ts_rateindex;
266         idx = rates[final_ts_idx].idx;
267         stats = &sc->debug.stats.rcstats[idx];
268         stats->success++;
269 }
270
271 void ath_debug_stat_retries(struct ath_softc *sc, int rix,
272                             int xretries, int retries, u8 per)
273 {
274         struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
275
276         stats->xretries += xretries;
277         stats->retries += retries;
278         stats->per = per;
279 }
280
281 static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
282                                 size_t count, loff_t *ppos)
283 {
284         struct ath_softc *sc = file->private_data;
285         char *buf;
286         unsigned int len = 0, max;
287         int i = 0;
288         ssize_t retval;
289
290         if (sc->cur_rate_table == NULL)
291                 return 0;
292
293         max = 80 + sc->cur_rate_table->rate_cnt * 64;
294         buf = kmalloc(max + 1, GFP_KERNEL);
295         if (buf == NULL)
296                 return 0;
297         buf[max] = 0;
298
299         len += sprintf(buf, "%5s %15s %8s %9s %3s\n\n", "Rate", "Success",
300                        "Retries", "XRetries", "PER");
301
302         for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
303                 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
304                 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
305
306                 len += snprintf(buf + len, max - len,
307                         "%3u.%d: %8u %8u %8u %8u\n", ratekbps / 1000,
308                         (ratekbps % 1000) / 100, stats->success,
309                         stats->retries, stats->xretries,
310                         stats->per);
311         }
312
313         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
314         kfree(buf);
315         return retval;
316 }
317
318 static const struct file_operations fops_rcstat = {
319         .read = read_file_rcstat,
320         .open = ath9k_debugfs_open,
321         .owner = THIS_MODULE
322 };
323
324 static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
325 {
326         switch (state) {
327         case ATH_WIPHY_INACTIVE:
328                 return "INACTIVE";
329         case ATH_WIPHY_ACTIVE:
330                 return "ACTIVE";
331         case ATH_WIPHY_PAUSING:
332                 return "PAUSING";
333         case ATH_WIPHY_PAUSED:
334                 return "PAUSED";
335         case ATH_WIPHY_SCAN:
336                 return "SCAN";
337         }
338         return "?";
339 }
340
341 static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
342                                size_t count, loff_t *ppos)
343 {
344         struct ath_softc *sc = file->private_data;
345         char buf[512];
346         unsigned int len = 0;
347         int i;
348         u8 addr[ETH_ALEN];
349
350         len += snprintf(buf + len, sizeof(buf) - len,
351                         "primary: %s (%s chan=%d ht=%d)\n",
352                         wiphy_name(sc->pri_wiphy->hw->wiphy),
353                         ath_wiphy_state_str(sc->pri_wiphy->state),
354                         sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
355         for (i = 0; i < sc->num_sec_wiphy; i++) {
356                 struct ath_wiphy *aphy = sc->sec_wiphy[i];
357                 if (aphy == NULL)
358                         continue;
359                 len += snprintf(buf + len, sizeof(buf) - len,
360                                 "secondary: %s (%s chan=%d ht=%d)\n",
361                                 wiphy_name(aphy->hw->wiphy),
362                                 ath_wiphy_state_str(aphy->state),
363                                 aphy->chan_idx, aphy->chan_is_ht);
364         }
365
366         put_unaligned_le32(REG_READ(sc->sc_ah, AR_STA_ID0), addr);
367         put_unaligned_le16(REG_READ(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
368         len += snprintf(buf + len, sizeof(buf) - len,
369                         "addr: %pM\n", addr);
370         put_unaligned_le32(REG_READ(sc->sc_ah, AR_BSSMSKL), addr);
371         put_unaligned_le16(REG_READ(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
372         len += snprintf(buf + len, sizeof(buf) - len,
373                         "addrmask: %pM\n", addr);
374
375         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
376 }
377
378 static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
379 {
380         int i;
381         if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
382                 return sc->pri_wiphy;
383         for (i = 0; i < sc->num_sec_wiphy; i++) {
384                 struct ath_wiphy *aphy = sc->sec_wiphy[i];
385                 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
386                         return aphy;
387         }
388         return NULL;
389 }
390
391 static int del_wiphy(struct ath_softc *sc, const char *name)
392 {
393         struct ath_wiphy *aphy = get_wiphy(sc, name);
394         if (!aphy)
395                 return -ENOENT;
396         return ath9k_wiphy_del(aphy);
397 }
398
399 static int pause_wiphy(struct ath_softc *sc, const char *name)
400 {
401         struct ath_wiphy *aphy = get_wiphy(sc, name);
402         if (!aphy)
403                 return -ENOENT;
404         return ath9k_wiphy_pause(aphy);
405 }
406
407 static int unpause_wiphy(struct ath_softc *sc, const char *name)
408 {
409         struct ath_wiphy *aphy = get_wiphy(sc, name);
410         if (!aphy)
411                 return -ENOENT;
412         return ath9k_wiphy_unpause(aphy);
413 }
414
415 static int select_wiphy(struct ath_softc *sc, const char *name)
416 {
417         struct ath_wiphy *aphy = get_wiphy(sc, name);
418         if (!aphy)
419                 return -ENOENT;
420         return ath9k_wiphy_select(aphy);
421 }
422
423 static int schedule_wiphy(struct ath_softc *sc, const char *msec)
424 {
425         ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
426         return 0;
427 }
428
429 static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
430                                 size_t count, loff_t *ppos)
431 {
432         struct ath_softc *sc = file->private_data;
433         char buf[50];
434         size_t len;
435
436         len = min(count, sizeof(buf) - 1);
437         if (copy_from_user(buf, user_buf, len))
438                 return -EFAULT;
439         buf[len] = '\0';
440         if (len > 0 && buf[len - 1] == '\n')
441                 buf[len - 1] = '\0';
442
443         if (strncmp(buf, "add", 3) == 0) {
444                 int res = ath9k_wiphy_add(sc);
445                 if (res < 0)
446                         return res;
447         } else if (strncmp(buf, "del=", 4) == 0) {
448                 int res = del_wiphy(sc, buf + 4);
449                 if (res < 0)
450                         return res;
451         } else if (strncmp(buf, "pause=", 6) == 0) {
452                 int res = pause_wiphy(sc, buf + 6);
453                 if (res < 0)
454                         return res;
455         } else if (strncmp(buf, "unpause=", 8) == 0) {
456                 int res = unpause_wiphy(sc, buf + 8);
457                 if (res < 0)
458                         return res;
459         } else if (strncmp(buf, "select=", 7) == 0) {
460                 int res = select_wiphy(sc, buf + 7);
461                 if (res < 0)
462                         return res;
463         } else if (strncmp(buf, "schedule=", 9) == 0) {
464                 int res = schedule_wiphy(sc, buf + 9);
465                 if (res < 0)
466                         return res;
467         } else
468                 return -EOPNOTSUPP;
469
470         return count;
471 }
472
473 static const struct file_operations fops_wiphy = {
474         .read = read_file_wiphy,
475         .write = write_file_wiphy,
476         .open = ath9k_debugfs_open,
477         .owner = THIS_MODULE
478 };
479
480 #define PR(str, elem)                                                   \
481         do {                                                            \
482                 len += snprintf(buf + len, size - len,                  \
483                                 "%s%13u%11u%10u%10u\n", str,            \
484                 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
485                 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
486                 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
487                 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
488 } while(0)
489
490 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
491                               size_t count, loff_t *ppos)
492 {
493         struct ath_softc *sc = file->private_data;
494         char *buf;
495         unsigned int len = 0, size = 2048;
496         ssize_t retval = 0;
497
498         buf = kzalloc(size, GFP_KERNEL);
499         if (buf == NULL)
500                 return 0;
501
502         len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
503
504         PR("MPDUs Queued:    ", queued);
505         PR("MPDUs Completed: ", completed);
506         PR("Aggregates:      ", a_aggr);
507         PR("AMPDUs Queued:   ", a_queued);
508         PR("AMPDUs Completed:", a_completed);
509         PR("AMPDUs Retried:  ", a_retries);
510         PR("AMPDUs XRetried: ", a_xretries);
511         PR("FIFO Underrun:   ", fifo_underrun);
512         PR("TXOP Exceeded:   ", xtxop);
513         PR("TXTIMER Expiry:  ", timer_exp);
514         PR("DESC CFG Error:  ", desc_cfg_err);
515         PR("DATA Underrun:   ", data_underrun);
516         PR("DELIM Underrun:  ", delim_underrun);
517
518         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
519         kfree(buf);
520
521         return retval;
522 }
523
524 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
525                        struct ath_buf *bf)
526 {
527         struct ath_desc *ds = bf->bf_desc;
528
529         if (bf_isampdu(bf)) {
530                 if (bf_isxretried(bf))
531                         TX_STAT_INC(txq->axq_qnum, a_xretries);
532                 else
533                         TX_STAT_INC(txq->axq_qnum, a_completed);
534         } else {
535                 TX_STAT_INC(txq->axq_qnum, completed);
536         }
537
538         if (ds->ds_txstat.ts_status & ATH9K_TXERR_FIFO)
539                 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
540         if (ds->ds_txstat.ts_status & ATH9K_TXERR_XTXOP)
541                 TX_STAT_INC(txq->axq_qnum, xtxop);
542         if (ds->ds_txstat.ts_status & ATH9K_TXERR_TIMER_EXPIRED)
543                 TX_STAT_INC(txq->axq_qnum, timer_exp);
544         if (ds->ds_txstat.ts_flags & ATH9K_TX_DESC_CFG_ERR)
545                 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
546         if (ds->ds_txstat.ts_flags & ATH9K_TX_DATA_UNDERRUN)
547                 TX_STAT_INC(txq->axq_qnum, data_underrun);
548         if (ds->ds_txstat.ts_flags & ATH9K_TX_DELIM_UNDERRUN)
549                 TX_STAT_INC(txq->axq_qnum, delim_underrun);
550 }
551
552 static const struct file_operations fops_xmit = {
553         .read = read_file_xmit,
554         .open = ath9k_debugfs_open,
555         .owner = THIS_MODULE
556 };
557
558 int ath9k_init_debug(struct ath_hw *ah)
559 {
560         struct ath_softc *sc = ah->ah_sc;
561         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
562
563         common->debug_mask = ath9k_debug;
564
565         if (!ath9k_debugfs_root)
566                 return -ENOENT;
567
568         sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
569                                                       ath9k_debugfs_root);
570         if (!sc->debug.debugfs_phy)
571                 goto err;
572
573         sc->debug.debugfs_debug = debugfs_create_file("debug",
574                 S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
575         if (!sc->debug.debugfs_debug)
576                 goto err;
577
578         sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
579                                        sc->debug.debugfs_phy, sc, &fops_dma);
580         if (!sc->debug.debugfs_dma)
581                 goto err;
582
583         sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
584                                                      S_IRUSR,
585                                                      sc->debug.debugfs_phy,
586                                                      sc, &fops_interrupt);
587         if (!sc->debug.debugfs_interrupt)
588                 goto err;
589
590         sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
591                                                   S_IRUSR,
592                                                   sc->debug.debugfs_phy,
593                                                   sc, &fops_rcstat);
594         if (!sc->debug.debugfs_rcstat)
595                 goto err;
596
597         sc->debug.debugfs_wiphy = debugfs_create_file(
598                 "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
599                 &fops_wiphy);
600         if (!sc->debug.debugfs_wiphy)
601                 goto err;
602
603         sc->debug.debugfs_xmit = debugfs_create_file("xmit",
604                                                      S_IRUSR,
605                                                      sc->debug.debugfs_phy,
606                                                      sc, &fops_xmit);
607         if (!sc->debug.debugfs_xmit)
608                 goto err;
609
610         return 0;
611 err:
612         ath9k_exit_debug(ah);
613         return -ENOMEM;
614 }
615
616 void ath9k_exit_debug(struct ath_hw *ah)
617 {
618         struct ath_softc *sc = ah->ah_sc;
619
620         debugfs_remove(sc->debug.debugfs_xmit);
621         debugfs_remove(sc->debug.debugfs_wiphy);
622         debugfs_remove(sc->debug.debugfs_rcstat);
623         debugfs_remove(sc->debug.debugfs_interrupt);
624         debugfs_remove(sc->debug.debugfs_dma);
625         debugfs_remove(sc->debug.debugfs_debug);
626         debugfs_remove(sc->debug.debugfs_phy);
627 }
628
629 int ath9k_debug_create_root(void)
630 {
631         ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
632         if (!ath9k_debugfs_root)
633                 return -ENOENT;
634
635         return 0;
636 }
637
638 void ath9k_debug_remove_root(void)
639 {
640         debugfs_remove(ath9k_debugfs_root);
641         ath9k_debugfs_root = NULL;
642 }