]> Git Repo - linux.git/blob - drivers/net/wireless/ath/ath9k/debug.c
Merge branch 'master' into for-davem
[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 <linux/slab.h>
18 #include <asm/unaligned.h>
19
20 #include "ath9k.h"
21
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))
26
27 static struct dentry *ath9k_debugfs_root;
28
29 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
30 {
31         file->private_data = inode->i_private;
32         return 0;
33 }
34
35 #ifdef CONFIG_ATH_DEBUG
36
37 static ssize_t read_file_debug(struct file *file, char __user *user_buf,
38                              size_t count, loff_t *ppos)
39 {
40         struct ath_softc *sc = file->private_data;
41         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
42         char buf[32];
43         unsigned int len;
44
45         len = snprintf(buf, sizeof(buf), "0x%08x\n", common->debug_mask);
46         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
47 }
48
49 static ssize_t write_file_debug(struct file *file, const char __user *user_buf,
50                              size_t count, loff_t *ppos)
51 {
52         struct ath_softc *sc = file->private_data;
53         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
54         unsigned long mask;
55         char buf[32];
56         ssize_t len;
57
58         len = min(count, sizeof(buf) - 1);
59         if (copy_from_user(buf, user_buf, len))
60                 return -EINVAL;
61
62         buf[len] = '\0';
63         if (strict_strtoul(buf, 0, &mask))
64                 return -EINVAL;
65
66         common->debug_mask = mask;
67         return count;
68 }
69
70 static const struct file_operations fops_debug = {
71         .read = read_file_debug,
72         .write = write_file_debug,
73         .open = ath9k_debugfs_open,
74         .owner = THIS_MODULE
75 };
76
77 #endif
78
79 #define DMA_BUF_LEN 1024
80
81 static ssize_t read_file_dma(struct file *file, char __user *user_buf,
82                              size_t count, loff_t *ppos)
83 {
84         struct ath_softc *sc = file->private_data;
85         struct ath_hw *ah = sc->sc_ah;
86         char *buf;
87         int retval;
88         unsigned int len = 0;
89         u32 val[ATH9K_NUM_DMA_DEBUG_REGS];
90         int i, qcuOffset = 0, dcuOffset = 0;
91         u32 *qcuBase = &val[0], *dcuBase = &val[4];
92
93         buf = kmalloc(DMA_BUF_LEN, GFP_KERNEL);
94         if (!buf)
95                 return 0;
96
97         ath9k_ps_wakeup(sc);
98
99         REG_WRITE_D(ah, AR_MACMISC,
100                   ((AR_MACMISC_DMA_OBS_LINE_8 << AR_MACMISC_DMA_OBS_S) |
101                    (AR_MACMISC_MISC_OBS_BUS_1 <<
102                     AR_MACMISC_MISC_OBS_BUS_MSB_S)));
103
104         len += snprintf(buf + len, DMA_BUF_LEN - len,
105                         "Raw DMA Debug values:\n");
106
107         for (i = 0; i < ATH9K_NUM_DMA_DEBUG_REGS; i++) {
108                 if (i % 4 == 0)
109                         len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
110
111                 val[i] = REG_READ_D(ah, AR_DMADBG_0 + (i * sizeof(u32)));
112                 len += snprintf(buf + len, DMA_BUF_LEN - len, "%d: %08x ",
113                                 i, val[i]);
114         }
115
116         len += snprintf(buf + len, DMA_BUF_LEN - len, "\n\n");
117         len += snprintf(buf + len, DMA_BUF_LEN - len,
118                         "Num QCU: chain_st fsp_ok fsp_st DCU: chain_st\n");
119
120         for (i = 0; i < ATH9K_NUM_QUEUES; i++, qcuOffset += 4, dcuOffset += 5) {
121                 if (i == 8) {
122                         qcuOffset = 0;
123                         qcuBase++;
124                 }
125
126                 if (i == 6) {
127                         dcuOffset = 0;
128                         dcuBase++;
129                 }
130
131                 len += snprintf(buf + len, DMA_BUF_LEN - len,
132                         "%2d          %2x      %1x     %2x           %2x\n",
133                         i, (*qcuBase & (0x7 << qcuOffset)) >> qcuOffset,
134                         (*qcuBase & (0x8 << qcuOffset)) >> (qcuOffset + 3),
135                         val[2] & (0x7 << (i * 3)) >> (i * 3),
136                         (*dcuBase & (0x1f << dcuOffset)) >> dcuOffset);
137         }
138
139         len += snprintf(buf + len, DMA_BUF_LEN - len, "\n");
140
141         len += snprintf(buf + len, DMA_BUF_LEN - len,
142                 "qcu_stitch state:   %2x    qcu_fetch state:        %2x\n",
143                 (val[3] & 0x003c0000) >> 18, (val[3] & 0x03c00000) >> 22);
144         len += snprintf(buf + len, DMA_BUF_LEN - len,
145                 "qcu_complete state: %2x    dcu_complete state:     %2x\n",
146                 (val[3] & 0x1c000000) >> 26, (val[6] & 0x3));
147         len += snprintf(buf + len, DMA_BUF_LEN - len,
148                 "dcu_arb state:      %2x    dcu_fp state:           %2x\n",
149                 (val[5] & 0x06000000) >> 25, (val[5] & 0x38000000) >> 27);
150         len += snprintf(buf + len, DMA_BUF_LEN - len,
151                 "chan_idle_dur:     %3d    chan_idle_dur_valid:     %1d\n",
152                 (val[6] & 0x000003fc) >> 2, (val[6] & 0x00000400) >> 10);
153         len += snprintf(buf + len, DMA_BUF_LEN - len,
154                 "txfifo_valid_0:      %1d    txfifo_valid_1:          %1d\n",
155                 (val[6] & 0x00000800) >> 11, (val[6] & 0x00001000) >> 12);
156         len += snprintf(buf + len, DMA_BUF_LEN - len,
157                 "txfifo_dcu_num_0:   %2d    txfifo_dcu_num_1:       %2d\n",
158                 (val[6] & 0x0001e000) >> 13, (val[6] & 0x001e0000) >> 17);
159
160         len += snprintf(buf + len, DMA_BUF_LEN - len, "pcu observe: 0x%x\n",
161                         REG_READ_D(ah, AR_OBS_BUS_1));
162         len += snprintf(buf + len, DMA_BUF_LEN - len,
163                         "AR_CR: 0x%x\n", REG_READ_D(ah, AR_CR));
164
165         ath9k_ps_restore(sc);
166
167         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
168         kfree(buf);
169         return retval;
170 }
171
172 static const struct file_operations fops_dma = {
173         .read = read_file_dma,
174         .open = ath9k_debugfs_open,
175         .owner = THIS_MODULE
176 };
177
178
179 void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
180 {
181         if (status)
182                 sc->debug.stats.istats.total++;
183         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
184                 if (status & ATH9K_INT_RXLP)
185                         sc->debug.stats.istats.rxlp++;
186                 if (status & ATH9K_INT_RXHP)
187                         sc->debug.stats.istats.rxhp++;
188         } else {
189                 if (status & ATH9K_INT_RX)
190                         sc->debug.stats.istats.rxok++;
191         }
192         if (status & ATH9K_INT_RXEOL)
193                 sc->debug.stats.istats.rxeol++;
194         if (status & ATH9K_INT_RXORN)
195                 sc->debug.stats.istats.rxorn++;
196         if (status & ATH9K_INT_TX)
197                 sc->debug.stats.istats.txok++;
198         if (status & ATH9K_INT_TXURN)
199                 sc->debug.stats.istats.txurn++;
200         if (status & ATH9K_INT_MIB)
201                 sc->debug.stats.istats.mib++;
202         if (status & ATH9K_INT_RXPHY)
203                 sc->debug.stats.istats.rxphyerr++;
204         if (status & ATH9K_INT_RXKCM)
205                 sc->debug.stats.istats.rx_keycache_miss++;
206         if (status & ATH9K_INT_SWBA)
207                 sc->debug.stats.istats.swba++;
208         if (status & ATH9K_INT_BMISS)
209                 sc->debug.stats.istats.bmiss++;
210         if (status & ATH9K_INT_BNR)
211                 sc->debug.stats.istats.bnr++;
212         if (status & ATH9K_INT_CST)
213                 sc->debug.stats.istats.cst++;
214         if (status & ATH9K_INT_GTT)
215                 sc->debug.stats.istats.gtt++;
216         if (status & ATH9K_INT_TIM)
217                 sc->debug.stats.istats.tim++;
218         if (status & ATH9K_INT_CABEND)
219                 sc->debug.stats.istats.cabend++;
220         if (status & ATH9K_INT_DTIMSYNC)
221                 sc->debug.stats.istats.dtimsync++;
222         if (status & ATH9K_INT_DTIM)
223                 sc->debug.stats.istats.dtim++;
224 }
225
226 static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
227                                    size_t count, loff_t *ppos)
228 {
229         struct ath_softc *sc = file->private_data;
230         char buf[512];
231         unsigned int len = 0;
232
233         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
234                 len += snprintf(buf + len, sizeof(buf) - len,
235                         "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
236                 len += snprintf(buf + len, sizeof(buf) - len,
237                         "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
238         } else {
239                 len += snprintf(buf + len, sizeof(buf) - len,
240                         "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
241         }
242         len += snprintf(buf + len, sizeof(buf) - len,
243                 "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
244         len += snprintf(buf + len, sizeof(buf) - len,
245                 "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
246         len += snprintf(buf + len, sizeof(buf) - len,
247                 "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
248         len += snprintf(buf + len, sizeof(buf) - len,
249                 "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
250         len += snprintf(buf + len, sizeof(buf) - len,
251                 "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
252         len += snprintf(buf + len, sizeof(buf) - len,
253                 "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
254         len += snprintf(buf + len, sizeof(buf) - len,
255                 "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
256         len += snprintf(buf + len, sizeof(buf) - len,
257                 "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
258         len += snprintf(buf + len, sizeof(buf) - len,
259                 "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
260         len += snprintf(buf + len, sizeof(buf) - len,
261                 "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
262         len += snprintf(buf + len, sizeof(buf) - len,
263                 "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
264         len += snprintf(buf + len, sizeof(buf) - len,
265                 "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
266         len += snprintf(buf + len, sizeof(buf) - len,
267                 "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
268         len += snprintf(buf + len, sizeof(buf) - len,
269                 "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
270         len += snprintf(buf + len, sizeof(buf) - len,
271                 "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
272         len += snprintf(buf + len, sizeof(buf) - len,
273                 "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
274         len += snprintf(buf + len, sizeof(buf) - len,
275                 "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
276
277         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
278 }
279
280 static const struct file_operations fops_interrupt = {
281         .read = read_file_interrupt,
282         .open = ath9k_debugfs_open,
283         .owner = THIS_MODULE
284 };
285
286 void ath_debug_stat_rc(struct ath_softc *sc, int final_rate)
287 {
288         struct ath_rc_stats *stats;
289
290         stats = &sc->debug.stats.rcstats[final_rate];
291         stats->success++;
292 }
293
294 void ath_debug_stat_retries(struct ath_softc *sc, int rix,
295                             int xretries, int retries, u8 per)
296 {
297         struct ath_rc_stats *stats = &sc->debug.stats.rcstats[rix];
298
299         stats->xretries += xretries;
300         stats->retries += retries;
301         stats->per = per;
302 }
303
304 static ssize_t read_file_rcstat(struct file *file, char __user *user_buf,
305                                 size_t count, loff_t *ppos)
306 {
307         struct ath_softc *sc = file->private_data;
308         char *buf;
309         unsigned int len = 0, max;
310         int i = 0;
311         ssize_t retval;
312
313         if (sc->cur_rate_table == NULL)
314                 return 0;
315
316         max = 80 + sc->cur_rate_table->rate_cnt * 1024;
317         buf = kmalloc(max + 1, GFP_KERNEL);
318         if (buf == NULL)
319                 return 0;
320         buf[max] = 0;
321
322         len += sprintf(buf, "%6s %6s %6s "
323                        "%10s %10s %10s %10s\n",
324                        "HT", "MCS", "Rate",
325                        "Success", "Retries", "XRetries", "PER");
326
327         for (i = 0; i < sc->cur_rate_table->rate_cnt; i++) {
328                 u32 ratekbps = sc->cur_rate_table->info[i].ratekbps;
329                 struct ath_rc_stats *stats = &sc->debug.stats.rcstats[i];
330                 char mcs[5];
331                 char htmode[5];
332                 int used_mcs = 0, used_htmode = 0;
333
334                 if (WLAN_RC_PHY_HT(sc->cur_rate_table->info[i].phy)) {
335                         used_mcs = snprintf(mcs, 5, "%d",
336                                 sc->cur_rate_table->info[i].ratecode);
337
338                         if (WLAN_RC_PHY_40(sc->cur_rate_table->info[i].phy))
339                                 used_htmode = snprintf(htmode, 5, "HT40");
340                         else if (WLAN_RC_PHY_20(sc->cur_rate_table->info[i].phy))
341                                 used_htmode = snprintf(htmode, 5, "HT20");
342                         else
343                                 used_htmode = snprintf(htmode, 5, "????");
344                 }
345
346                 mcs[used_mcs] = '\0';
347                 htmode[used_htmode] = '\0';
348
349                 len += snprintf(buf + len, max - len,
350                         "%6s %6s %3u.%d: "
351                         "%10u %10u %10u %10u\n",
352                         htmode,
353                         mcs,
354                         ratekbps / 1000,
355                         (ratekbps % 1000) / 100,
356                         stats->success,
357                         stats->retries,
358                         stats->xretries,
359                         stats->per);
360         }
361
362         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
363         kfree(buf);
364         return retval;
365 }
366
367 static const struct file_operations fops_rcstat = {
368         .read = read_file_rcstat,
369         .open = ath9k_debugfs_open,
370         .owner = THIS_MODULE
371 };
372
373 static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
374 {
375         switch (state) {
376         case ATH_WIPHY_INACTIVE:
377                 return "INACTIVE";
378         case ATH_WIPHY_ACTIVE:
379                 return "ACTIVE";
380         case ATH_WIPHY_PAUSING:
381                 return "PAUSING";
382         case ATH_WIPHY_PAUSED:
383                 return "PAUSED";
384         case ATH_WIPHY_SCAN:
385                 return "SCAN";
386         }
387         return "?";
388 }
389
390 static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
391                                size_t count, loff_t *ppos)
392 {
393         struct ath_softc *sc = file->private_data;
394         char buf[512];
395         unsigned int len = 0;
396         int i;
397         u8 addr[ETH_ALEN];
398
399         len += snprintf(buf + len, sizeof(buf) - len,
400                         "primary: %s (%s chan=%d ht=%d)\n",
401                         wiphy_name(sc->pri_wiphy->hw->wiphy),
402                         ath_wiphy_state_str(sc->pri_wiphy->state),
403                         sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
404         for (i = 0; i < sc->num_sec_wiphy; i++) {
405                 struct ath_wiphy *aphy = sc->sec_wiphy[i];
406                 if (aphy == NULL)
407                         continue;
408                 len += snprintf(buf + len, sizeof(buf) - len,
409                                 "secondary: %s (%s chan=%d ht=%d)\n",
410                                 wiphy_name(aphy->hw->wiphy),
411                                 ath_wiphy_state_str(aphy->state),
412                                 aphy->chan_idx, aphy->chan_is_ht);
413         }
414
415         put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_STA_ID0), addr);
416         put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
417         len += snprintf(buf + len, sizeof(buf) - len,
418                         "addr: %pM\n", addr);
419         put_unaligned_le32(REG_READ_D(sc->sc_ah, AR_BSSMSKL), addr);
420         put_unaligned_le16(REG_READ_D(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
421         len += snprintf(buf + len, sizeof(buf) - len,
422                         "addrmask: %pM\n", addr);
423
424         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
425 }
426
427 static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
428 {
429         int i;
430         if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
431                 return sc->pri_wiphy;
432         for (i = 0; i < sc->num_sec_wiphy; i++) {
433                 struct ath_wiphy *aphy = sc->sec_wiphy[i];
434                 if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
435                         return aphy;
436         }
437         return NULL;
438 }
439
440 static int del_wiphy(struct ath_softc *sc, const char *name)
441 {
442         struct ath_wiphy *aphy = get_wiphy(sc, name);
443         if (!aphy)
444                 return -ENOENT;
445         return ath9k_wiphy_del(aphy);
446 }
447
448 static int pause_wiphy(struct ath_softc *sc, const char *name)
449 {
450         struct ath_wiphy *aphy = get_wiphy(sc, name);
451         if (!aphy)
452                 return -ENOENT;
453         return ath9k_wiphy_pause(aphy);
454 }
455
456 static int unpause_wiphy(struct ath_softc *sc, const char *name)
457 {
458         struct ath_wiphy *aphy = get_wiphy(sc, name);
459         if (!aphy)
460                 return -ENOENT;
461         return ath9k_wiphy_unpause(aphy);
462 }
463
464 static int select_wiphy(struct ath_softc *sc, const char *name)
465 {
466         struct ath_wiphy *aphy = get_wiphy(sc, name);
467         if (!aphy)
468                 return -ENOENT;
469         return ath9k_wiphy_select(aphy);
470 }
471
472 static int schedule_wiphy(struct ath_softc *sc, const char *msec)
473 {
474         ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
475         return 0;
476 }
477
478 static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
479                                 size_t count, loff_t *ppos)
480 {
481         struct ath_softc *sc = file->private_data;
482         char buf[50];
483         size_t len;
484
485         len = min(count, sizeof(buf) - 1);
486         if (copy_from_user(buf, user_buf, len))
487                 return -EFAULT;
488         buf[len] = '\0';
489         if (len > 0 && buf[len - 1] == '\n')
490                 buf[len - 1] = '\0';
491
492         if (strncmp(buf, "add", 3) == 0) {
493                 int res = ath9k_wiphy_add(sc);
494                 if (res < 0)
495                         return res;
496         } else if (strncmp(buf, "del=", 4) == 0) {
497                 int res = del_wiphy(sc, buf + 4);
498                 if (res < 0)
499                         return res;
500         } else if (strncmp(buf, "pause=", 6) == 0) {
501                 int res = pause_wiphy(sc, buf + 6);
502                 if (res < 0)
503                         return res;
504         } else if (strncmp(buf, "unpause=", 8) == 0) {
505                 int res = unpause_wiphy(sc, buf + 8);
506                 if (res < 0)
507                         return res;
508         } else if (strncmp(buf, "select=", 7) == 0) {
509                 int res = select_wiphy(sc, buf + 7);
510                 if (res < 0)
511                         return res;
512         } else if (strncmp(buf, "schedule=", 9) == 0) {
513                 int res = schedule_wiphy(sc, buf + 9);
514                 if (res < 0)
515                         return res;
516         } else
517                 return -EOPNOTSUPP;
518
519         return count;
520 }
521
522 static const struct file_operations fops_wiphy = {
523         .read = read_file_wiphy,
524         .write = write_file_wiphy,
525         .open = ath9k_debugfs_open,
526         .owner = THIS_MODULE
527 };
528
529 #define PR(str, elem)                                                   \
530         do {                                                            \
531                 len += snprintf(buf + len, size - len,                  \
532                                 "%s%13u%11u%10u%10u\n", str,            \
533                 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BE]].elem, \
534                 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_BK]].elem, \
535                 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VI]].elem, \
536                 sc->debug.stats.txstats[sc->tx.hwq_map[ATH9K_WME_AC_VO]].elem); \
537 } while(0)
538
539 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
540                               size_t count, loff_t *ppos)
541 {
542         struct ath_softc *sc = file->private_data;
543         char *buf;
544         unsigned int len = 0, size = 2048;
545         ssize_t retval = 0;
546
547         buf = kzalloc(size, GFP_KERNEL);
548         if (buf == NULL)
549                 return 0;
550
551         len += sprintf(buf, "%30s %10s%10s%10s\n\n", "BE", "BK", "VI", "VO");
552
553         PR("MPDUs Queued:    ", queued);
554         PR("MPDUs Completed: ", completed);
555         PR("Aggregates:      ", a_aggr);
556         PR("AMPDUs Queued:   ", a_queued);
557         PR("AMPDUs Completed:", a_completed);
558         PR("AMPDUs Retried:  ", a_retries);
559         PR("AMPDUs XRetried: ", a_xretries);
560         PR("FIFO Underrun:   ", fifo_underrun);
561         PR("TXOP Exceeded:   ", xtxop);
562         PR("TXTIMER Expiry:  ", timer_exp);
563         PR("DESC CFG Error:  ", desc_cfg_err);
564         PR("DATA Underrun:   ", data_underrun);
565         PR("DELIM Underrun:  ", delim_underrun);
566
567         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
568         kfree(buf);
569
570         return retval;
571 }
572
573 void ath_debug_stat_tx(struct ath_softc *sc, struct ath_txq *txq,
574                        struct ath_buf *bf, struct ath_tx_status *ts)
575 {
576         if (bf_isampdu(bf)) {
577                 if (bf_isxretried(bf))
578                         TX_STAT_INC(txq->axq_qnum, a_xretries);
579                 else
580                         TX_STAT_INC(txq->axq_qnum, a_completed);
581         } else {
582                 TX_STAT_INC(txq->axq_qnum, completed);
583         }
584
585         if (ts->ts_status & ATH9K_TXERR_FIFO)
586                 TX_STAT_INC(txq->axq_qnum, fifo_underrun);
587         if (ts->ts_status & ATH9K_TXERR_XTXOP)
588                 TX_STAT_INC(txq->axq_qnum, xtxop);
589         if (ts->ts_status & ATH9K_TXERR_TIMER_EXPIRED)
590                 TX_STAT_INC(txq->axq_qnum, timer_exp);
591         if (ts->ts_flags & ATH9K_TX_DESC_CFG_ERR)
592                 TX_STAT_INC(txq->axq_qnum, desc_cfg_err);
593         if (ts->ts_flags & ATH9K_TX_DATA_UNDERRUN)
594                 TX_STAT_INC(txq->axq_qnum, data_underrun);
595         if (ts->ts_flags & ATH9K_TX_DELIM_UNDERRUN)
596                 TX_STAT_INC(txq->axq_qnum, delim_underrun);
597 }
598
599 static const struct file_operations fops_xmit = {
600         .read = read_file_xmit,
601         .open = ath9k_debugfs_open,
602         .owner = THIS_MODULE
603 };
604
605 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
606                               size_t count, loff_t *ppos)
607 {
608 #define PHY_ERR(s, p) \
609         len += snprintf(buf + len, size - len, "%18s : %10u\n", s, \
610                         sc->debug.stats.rxstats.phy_err_stats[p]);
611
612         struct ath_softc *sc = file->private_data;
613         char *buf;
614         unsigned int len = 0, size = 1152;
615         ssize_t retval = 0;
616
617         buf = kzalloc(size, GFP_KERNEL);
618         if (buf == NULL)
619                 return 0;
620
621         len += snprintf(buf + len, size - len,
622                         "%18s : %10u\n", "CRC ERR",
623                         sc->debug.stats.rxstats.crc_err);
624         len += snprintf(buf + len, size - len,
625                         "%18s : %10u\n", "DECRYPT CRC ERR",
626                         sc->debug.stats.rxstats.decrypt_crc_err);
627         len += snprintf(buf + len, size - len,
628                         "%18s : %10u\n", "PHY ERR",
629                         sc->debug.stats.rxstats.phy_err);
630         len += snprintf(buf + len, size - len,
631                         "%18s : %10u\n", "MIC ERR",
632                         sc->debug.stats.rxstats.mic_err);
633         len += snprintf(buf + len, size - len,
634                         "%18s : %10u\n", "PRE-DELIM CRC ERR",
635                         sc->debug.stats.rxstats.pre_delim_crc_err);
636         len += snprintf(buf + len, size - len,
637                         "%18s : %10u\n", "POST-DELIM CRC ERR",
638                         sc->debug.stats.rxstats.post_delim_crc_err);
639         len += snprintf(buf + len, size - len,
640                         "%18s : %10u\n", "DECRYPT BUSY ERR",
641                         sc->debug.stats.rxstats.decrypt_busy_err);
642
643         PHY_ERR("UNDERRUN", ATH9K_PHYERR_UNDERRUN);
644         PHY_ERR("TIMING", ATH9K_PHYERR_TIMING);
645         PHY_ERR("PARITY", ATH9K_PHYERR_PARITY);
646         PHY_ERR("RATE", ATH9K_PHYERR_RATE);
647         PHY_ERR("LENGTH", ATH9K_PHYERR_LENGTH);
648         PHY_ERR("RADAR", ATH9K_PHYERR_RADAR);
649         PHY_ERR("SERVICE", ATH9K_PHYERR_SERVICE);
650         PHY_ERR("TOR", ATH9K_PHYERR_TOR);
651         PHY_ERR("OFDM-TIMING", ATH9K_PHYERR_OFDM_TIMING);
652         PHY_ERR("OFDM-SIGNAL-PARITY", ATH9K_PHYERR_OFDM_SIGNAL_PARITY);
653         PHY_ERR("OFDM-RATE", ATH9K_PHYERR_OFDM_RATE_ILLEGAL);
654         PHY_ERR("OFDM-LENGTH", ATH9K_PHYERR_OFDM_LENGTH_ILLEGAL);
655         PHY_ERR("OFDM-POWER-DROP", ATH9K_PHYERR_OFDM_POWER_DROP);
656         PHY_ERR("OFDM-SERVICE", ATH9K_PHYERR_OFDM_SERVICE);
657         PHY_ERR("OFDM-RESTART", ATH9K_PHYERR_OFDM_RESTART);
658         PHY_ERR("FALSE-RADAR-EXT", ATH9K_PHYERR_FALSE_RADAR_EXT);
659         PHY_ERR("CCK-TIMING", ATH9K_PHYERR_CCK_TIMING);
660         PHY_ERR("CCK-HEADER-CRC", ATH9K_PHYERR_CCK_HEADER_CRC);
661         PHY_ERR("CCK-RATE", ATH9K_PHYERR_CCK_RATE_ILLEGAL);
662         PHY_ERR("CCK-SERVICE", ATH9K_PHYERR_CCK_SERVICE);
663         PHY_ERR("CCK-RESTART", ATH9K_PHYERR_CCK_RESTART);
664         PHY_ERR("CCK-LENGTH", ATH9K_PHYERR_CCK_LENGTH_ILLEGAL);
665         PHY_ERR("CCK-POWER-DROP", ATH9K_PHYERR_CCK_POWER_DROP);
666         PHY_ERR("HT-CRC", ATH9K_PHYERR_HT_CRC_ERROR);
667         PHY_ERR("HT-LENGTH", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
668         PHY_ERR("HT-RATE", ATH9K_PHYERR_HT_RATE_ILLEGAL);
669
670         retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
671         kfree(buf);
672
673         return retval;
674
675 #undef PHY_ERR
676 }
677
678 void ath_debug_stat_rx(struct ath_softc *sc, struct ath_rx_status *rs)
679 {
680 #define RX_STAT_INC(c) sc->debug.stats.rxstats.c++
681 #define RX_PHY_ERR_INC(c) sc->debug.stats.rxstats.phy_err_stats[c]++
682
683         u32 phyerr;
684
685         if (rs->rs_status & ATH9K_RXERR_CRC)
686                 RX_STAT_INC(crc_err);
687         if (rs->rs_status & ATH9K_RXERR_DECRYPT)
688                 RX_STAT_INC(decrypt_crc_err);
689         if (rs->rs_status & ATH9K_RXERR_MIC)
690                 RX_STAT_INC(mic_err);
691         if (rs->rs_status & ATH9K_RX_DELIM_CRC_PRE)
692                 RX_STAT_INC(pre_delim_crc_err);
693         if (rs->rs_status & ATH9K_RX_DELIM_CRC_POST)
694                 RX_STAT_INC(post_delim_crc_err);
695         if (rs->rs_status & ATH9K_RX_DECRYPT_BUSY)
696                 RX_STAT_INC(decrypt_busy_err);
697
698         if (rs->rs_status & ATH9K_RXERR_PHY) {
699                 RX_STAT_INC(phy_err);
700                 phyerr = rs->rs_phyerr & 0x24;
701                 RX_PHY_ERR_INC(phyerr);
702         }
703
704 #undef RX_STAT_INC
705 #undef RX_PHY_ERR_INC
706 }
707
708 static const struct file_operations fops_recv = {
709         .read = read_file_recv,
710         .open = ath9k_debugfs_open,
711         .owner = THIS_MODULE
712 };
713
714 int ath9k_init_debug(struct ath_hw *ah)
715 {
716         struct ath_common *common = ath9k_hw_common(ah);
717         struct ath_softc *sc = (struct ath_softc *) common->priv;
718
719         if (!ath9k_debugfs_root)
720                 return -ENOENT;
721
722         sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
723                                                       ath9k_debugfs_root);
724         if (!sc->debug.debugfs_phy)
725                 goto err;
726
727 #ifdef CONFIG_ATH_DEBUG
728         sc->debug.debugfs_debug = debugfs_create_file("debug",
729                 S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc, &fops_debug);
730         if (!sc->debug.debugfs_debug)
731                 goto err;
732 #endif
733
734         sc->debug.debugfs_dma = debugfs_create_file("dma", S_IRUSR,
735                                        sc->debug.debugfs_phy, sc, &fops_dma);
736         if (!sc->debug.debugfs_dma)
737                 goto err;
738
739         sc->debug.debugfs_interrupt = debugfs_create_file("interrupt",
740                                                      S_IRUSR,
741                                                      sc->debug.debugfs_phy,
742                                                      sc, &fops_interrupt);
743         if (!sc->debug.debugfs_interrupt)
744                 goto err;
745
746         sc->debug.debugfs_rcstat = debugfs_create_file("rcstat",
747                                                   S_IRUSR,
748                                                   sc->debug.debugfs_phy,
749                                                   sc, &fops_rcstat);
750         if (!sc->debug.debugfs_rcstat)
751                 goto err;
752
753         sc->debug.debugfs_wiphy = debugfs_create_file(
754                 "wiphy", S_IRUSR | S_IWUSR, sc->debug.debugfs_phy, sc,
755                 &fops_wiphy);
756         if (!sc->debug.debugfs_wiphy)
757                 goto err;
758
759         sc->debug.debugfs_xmit = debugfs_create_file("xmit",
760                                                      S_IRUSR,
761                                                      sc->debug.debugfs_phy,
762                                                      sc, &fops_xmit);
763         if (!sc->debug.debugfs_xmit)
764                 goto err;
765
766         sc->debug.debugfs_recv = debugfs_create_file("recv",
767                                                      S_IRUSR,
768                                                      sc->debug.debugfs_phy,
769                                                      sc, &fops_recv);
770         if (!sc->debug.debugfs_recv)
771                 goto err;
772
773         return 0;
774 err:
775         ath9k_exit_debug(ah);
776         return -ENOMEM;
777 }
778
779 void ath9k_exit_debug(struct ath_hw *ah)
780 {
781         struct ath_common *common = ath9k_hw_common(ah);
782         struct ath_softc *sc = (struct ath_softc *) common->priv;
783
784         debugfs_remove(sc->debug.debugfs_recv);
785         debugfs_remove(sc->debug.debugfs_xmit);
786         debugfs_remove(sc->debug.debugfs_wiphy);
787         debugfs_remove(sc->debug.debugfs_rcstat);
788         debugfs_remove(sc->debug.debugfs_interrupt);
789         debugfs_remove(sc->debug.debugfs_dma);
790         debugfs_remove(sc->debug.debugfs_debug);
791         debugfs_remove(sc->debug.debugfs_phy);
792 }
793
794 int ath9k_debug_create_root(void)
795 {
796         ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
797         if (!ath9k_debugfs_root)
798                 return -ENOENT;
799
800         return 0;
801 }
802
803 void ath9k_debug_remove_root(void)
804 {
805         debugfs_remove(ath9k_debugfs_root);
806         ath9k_debugfs_root = NULL;
807 }
This page took 0.085039 seconds and 4 git commands to generate.