debug.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * Copyright (c) 2012 Broadcom Corporation
  3. * Copyright (c) 2012 Canonical Ltd.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  12. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  14. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  15. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/debugfs.h>
  18. #include <linux/if_ether.h>
  19. #include <linux/if.h>
  20. #include <linux/net.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/ieee80211.h>
  23. #include <linux/module.h>
  24. #include <net/mac80211.h>
  25. #include <defs.h>
  26. #include <brcmu_wifi.h>
  27. #include <brcmu_utils.h>
  28. #include "types.h"
  29. #include "main.h"
  30. #include "debug.h"
  31. #include "brcms_trace_events.h"
  32. #include "phy/phy_int.h"
  33. static struct dentry *root_folder;
  34. void brcms_debugfs_init(void)
  35. {
  36. root_folder = debugfs_create_dir(KBUILD_MODNAME, NULL);
  37. if (IS_ERR(root_folder))
  38. root_folder = NULL;
  39. }
  40. void brcms_debugfs_exit(void)
  41. {
  42. if (!root_folder)
  43. return;
  44. debugfs_remove_recursive(root_folder);
  45. root_folder = NULL;
  46. }
  47. int brcms_debugfs_attach(struct brcms_pub *drvr)
  48. {
  49. if (!root_folder)
  50. return -ENODEV;
  51. drvr->dbgfs_dir = debugfs_create_dir(
  52. dev_name(&drvr->wlc->hw->d11core->dev), root_folder);
  53. return PTR_ERR_OR_ZERO(drvr->dbgfs_dir);
  54. }
  55. void brcms_debugfs_detach(struct brcms_pub *drvr)
  56. {
  57. if (!IS_ERR_OR_NULL(drvr->dbgfs_dir))
  58. debugfs_remove_recursive(drvr->dbgfs_dir);
  59. }
  60. struct dentry *brcms_debugfs_get_devdir(struct brcms_pub *drvr)
  61. {
  62. return drvr->dbgfs_dir;
  63. }
  64. static
  65. int brcms_debugfs_hardware_read(struct seq_file *s, void *data)
  66. {
  67. struct brcms_pub *drvr = s->private;
  68. struct brcms_hardware *hw = drvr->wlc->hw;
  69. struct bcma_device *core = hw->d11core;
  70. struct bcma_bus *bus = core->bus;
  71. char boardrev[BRCMU_BOARDREV_LEN];
  72. seq_printf(s, "chipnum 0x%x\n"
  73. "chiprev 0x%x\n"
  74. "chippackage 0x%x\n"
  75. "corerev 0x%x\n"
  76. "boardid 0x%x\n"
  77. "boardvendor 0x%x\n"
  78. "boardrev %s\n"
  79. "boardflags 0x%x\n"
  80. "boardflags2 0x%x\n"
  81. "ucoderev 0x%x\n"
  82. "radiorev 0x%x\n"
  83. "phytype 0x%x\n"
  84. "phyrev 0x%x\n"
  85. "anarev 0x%x\n"
  86. "nvramrev %d\n",
  87. bus->chipinfo.id, bus->chipinfo.rev, bus->chipinfo.pkg,
  88. core->id.rev, bus->boardinfo.type, bus->boardinfo.vendor,
  89. brcmu_boardrev_str(hw->boardrev, boardrev),
  90. drvr->wlc->hw->boardflags, drvr->wlc->hw->boardflags2,
  91. drvr->wlc->ucode_rev, hw->band->radiorev,
  92. hw->band->phytype, hw->band->phyrev, hw->band->pi->ana_rev,
  93. hw->sromrev);
  94. return 0;
  95. }
  96. static int brcms_debugfs_macstat_read(struct seq_file *s, void *data)
  97. {
  98. struct brcms_pub *drvr = s->private;
  99. struct brcms_info *wl = drvr->ieee_hw->priv;
  100. struct macstat stats;
  101. int i;
  102. spin_lock_bh(&wl->lock);
  103. stats = *(drvr->wlc->core->macstat_snapshot);
  104. spin_unlock_bh(&wl->lock);
  105. seq_printf(s, "txallfrm: %d\n", stats.txallfrm);
  106. seq_printf(s, "txrtsfrm: %d\n", stats.txrtsfrm);
  107. seq_printf(s, "txctsfrm: %d\n", stats.txctsfrm);
  108. seq_printf(s, "txackfrm: %d\n", stats.txackfrm);
  109. seq_printf(s, "txdnlfrm: %d\n", stats.txdnlfrm);
  110. seq_printf(s, "txbcnfrm: %d\n", stats.txbcnfrm);
  111. seq_printf(s, "txfunfl[8]:");
  112. for (i = 0; i < ARRAY_SIZE(stats.txfunfl); i++)
  113. seq_printf(s, " %d", stats.txfunfl[i]);
  114. seq_printf(s, "\ntxtplunfl: %d\n", stats.txtplunfl);
  115. seq_printf(s, "txphyerr: %d\n", stats.txphyerr);
  116. seq_printf(s, "pktengrxducast: %d\n", stats.pktengrxducast);
  117. seq_printf(s, "pktengrxdmcast: %d\n", stats.pktengrxdmcast);
  118. seq_printf(s, "rxfrmtoolong: %d\n", stats.rxfrmtoolong);
  119. seq_printf(s, "rxfrmtooshrt: %d\n", stats.rxfrmtooshrt);
  120. seq_printf(s, "rxinvmachdr: %d\n", stats.rxinvmachdr);
  121. seq_printf(s, "rxbadfcs: %d\n", stats.rxbadfcs);
  122. seq_printf(s, "rxbadplcp: %d\n", stats.rxbadplcp);
  123. seq_printf(s, "rxcrsglitch: %d\n", stats.rxcrsglitch);
  124. seq_printf(s, "rxstrt: %d\n", stats.rxstrt);
  125. seq_printf(s, "rxdfrmucastmbss: %d\n", stats.rxdfrmucastmbss);
  126. seq_printf(s, "rxmfrmucastmbss: %d\n", stats.rxmfrmucastmbss);
  127. seq_printf(s, "rxcfrmucast: %d\n", stats.rxcfrmucast);
  128. seq_printf(s, "rxrtsucast: %d\n", stats.rxrtsucast);
  129. seq_printf(s, "rxctsucast: %d\n", stats.rxctsucast);
  130. seq_printf(s, "rxackucast: %d\n", stats.rxackucast);
  131. seq_printf(s, "rxdfrmocast: %d\n", stats.rxdfrmocast);
  132. seq_printf(s, "rxmfrmocast: %d\n", stats.rxmfrmocast);
  133. seq_printf(s, "rxcfrmocast: %d\n", stats.rxcfrmocast);
  134. seq_printf(s, "rxrtsocast: %d\n", stats.rxrtsocast);
  135. seq_printf(s, "rxctsocast: %d\n", stats.rxctsocast);
  136. seq_printf(s, "rxdfrmmcast: %d\n", stats.rxdfrmmcast);
  137. seq_printf(s, "rxmfrmmcast: %d\n", stats.rxmfrmmcast);
  138. seq_printf(s, "rxcfrmmcast: %d\n", stats.rxcfrmmcast);
  139. seq_printf(s, "rxbeaconmbss: %d\n", stats.rxbeaconmbss);
  140. seq_printf(s, "rxdfrmucastobss: %d\n", stats.rxdfrmucastobss);
  141. seq_printf(s, "rxbeaconobss: %d\n", stats.rxbeaconobss);
  142. seq_printf(s, "rxrsptmout: %d\n", stats.rxrsptmout);
  143. seq_printf(s, "bcntxcancl: %d\n", stats.bcntxcancl);
  144. seq_printf(s, "rxf0ovfl: %d\n", stats.rxf0ovfl);
  145. seq_printf(s, "rxf1ovfl: %d\n", stats.rxf1ovfl);
  146. seq_printf(s, "rxf2ovfl: %d\n", stats.rxf2ovfl);
  147. seq_printf(s, "txsfovfl: %d\n", stats.txsfovfl);
  148. seq_printf(s, "pmqovfl: %d\n", stats.pmqovfl);
  149. seq_printf(s, "rxcgprqfrm: %d\n", stats.rxcgprqfrm);
  150. seq_printf(s, "rxcgprsqovfl: %d\n", stats.rxcgprsqovfl);
  151. seq_printf(s, "txcgprsfail: %d\n", stats.txcgprsfail);
  152. seq_printf(s, "txcgprssuc: %d\n", stats.txcgprssuc);
  153. seq_printf(s, "prs_timeout: %d\n", stats.prs_timeout);
  154. seq_printf(s, "rxnack: %d\n", stats.rxnack);
  155. seq_printf(s, "frmscons: %d\n", stats.frmscons);
  156. seq_printf(s, "txnack: %d\n", stats.txnack);
  157. seq_printf(s, "txglitch_nack: %d\n", stats.txglitch_nack);
  158. seq_printf(s, "txburst: %d\n", stats.txburst);
  159. seq_printf(s, "bphy_rxcrsglitch: %d\n", stats.bphy_rxcrsglitch);
  160. seq_printf(s, "phywatchdog: %d\n", stats.phywatchdog);
  161. seq_printf(s, "bphy_badplcp: %d\n", stats.bphy_badplcp);
  162. return 0;
  163. }
  164. struct brcms_debugfs_entry {
  165. int (*read)(struct seq_file *seq, void *data);
  166. struct brcms_pub *drvr;
  167. };
  168. static int brcms_debugfs_entry_open(struct inode *inode, struct file *f)
  169. {
  170. struct brcms_debugfs_entry *entry = inode->i_private;
  171. return single_open(f, entry->read, entry->drvr);
  172. }
  173. static const struct file_operations brcms_debugfs_def_ops = {
  174. .owner = THIS_MODULE,
  175. .open = brcms_debugfs_entry_open,
  176. .release = single_release,
  177. .read = seq_read,
  178. .llseek = seq_lseek
  179. };
  180. static int
  181. brcms_debugfs_add_entry(struct brcms_pub *drvr, const char *fn,
  182. int (*read_fn)(struct seq_file *seq, void *data))
  183. {
  184. struct device *dev = &drvr->wlc->hw->d11core->dev;
  185. struct dentry *dentry = drvr->dbgfs_dir;
  186. struct brcms_debugfs_entry *entry;
  187. if (IS_ERR_OR_NULL(dentry))
  188. return -ENOENT;
  189. entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
  190. if (!entry)
  191. return -ENOMEM;
  192. entry->read = read_fn;
  193. entry->drvr = drvr;
  194. dentry = debugfs_create_file(fn, 0444, dentry, entry,
  195. &brcms_debugfs_def_ops);
  196. return PTR_ERR_OR_ZERO(dentry);
  197. }
  198. void brcms_debugfs_create_files(struct brcms_pub *drvr)
  199. {
  200. if (IS_ERR_OR_NULL(drvr->dbgfs_dir))
  201. return;
  202. brcms_debugfs_add_entry(drvr, "hardware", brcms_debugfs_hardware_read);
  203. brcms_debugfs_add_entry(drvr, "macstat", brcms_debugfs_macstat_read);
  204. }
  205. #define __brcms_fn(fn) \
  206. void __brcms_ ##fn(struct device *dev, const char *fmt, ...) \
  207. { \
  208. struct va_format vaf = { \
  209. .fmt = fmt, \
  210. }; \
  211. va_list args; \
  212. \
  213. va_start(args, fmt); \
  214. vaf.va = &args; \
  215. dev_ ##fn(dev, "%pV", &vaf); \
  216. trace_brcms_ ##fn(&vaf); \
  217. va_end(args); \
  218. }
  219. __brcms_fn(info)
  220. __brcms_fn(warn)
  221. __brcms_fn(err)
  222. __brcms_fn(crit)
  223. #if defined(CONFIG_BRCMDBG) || defined(CONFIG_BRCM_TRACING)
  224. void __brcms_dbg(struct device *dev, u32 level, const char *func,
  225. const char *fmt, ...)
  226. {
  227. struct va_format vaf = {
  228. .fmt = fmt,
  229. };
  230. va_list args;
  231. va_start(args, fmt);
  232. vaf.va = &args;
  233. #ifdef CONFIG_BRCMDBG
  234. if ((brcm_msg_level & level) && net_ratelimit())
  235. dev_err(dev, "%s %pV", func, &vaf);
  236. #endif
  237. trace_brcms_dbg(level, func, &vaf);
  238. va_end(args);
  239. }
  240. #endif