debug.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. static struct dentry *root_folder;
  33. void brcms_debugfs_init(void)
  34. {
  35. root_folder = debugfs_create_dir(KBUILD_MODNAME, NULL);
  36. if (IS_ERR(root_folder))
  37. root_folder = NULL;
  38. }
  39. void brcms_debugfs_exit(void)
  40. {
  41. if (!root_folder)
  42. return;
  43. debugfs_remove_recursive(root_folder);
  44. root_folder = NULL;
  45. }
  46. int brcms_debugfs_attach(struct brcms_pub *drvr)
  47. {
  48. if (!root_folder)
  49. return -ENODEV;
  50. drvr->dbgfs_dir = debugfs_create_dir(
  51. dev_name(&drvr->wlc->hw->d11core->dev), root_folder);
  52. return PTR_RET(drvr->dbgfs_dir);
  53. }
  54. void brcms_debugfs_detach(struct brcms_pub *drvr)
  55. {
  56. if (!IS_ERR_OR_NULL(drvr->dbgfs_dir))
  57. debugfs_remove_recursive(drvr->dbgfs_dir);
  58. }
  59. struct dentry *brcms_debugfs_get_devdir(struct brcms_pub *drvr)
  60. {
  61. return drvr->dbgfs_dir;
  62. }
  63. static
  64. ssize_t brcms_debugfs_hardware_read(struct file *f, char __user *data,
  65. size_t count, loff_t *ppos)
  66. {
  67. char buf[128];
  68. int res;
  69. struct brcms_pub *drvr = f->private_data;
  70. /* only allow read from start */
  71. if (*ppos > 0)
  72. return 0;
  73. res = scnprintf(buf, sizeof(buf),
  74. "board vendor: %x\n"
  75. "board type: %x\n"
  76. "board revision: %x\n"
  77. "board flags: %x\n"
  78. "board flags2: %x\n"
  79. "firmware revision: %x\n",
  80. drvr->wlc->hw->d11core->bus->boardinfo.vendor,
  81. drvr->wlc->hw->d11core->bus->boardinfo.type,
  82. drvr->wlc->hw->boardrev,
  83. drvr->wlc->hw->boardflags,
  84. drvr->wlc->hw->boardflags2,
  85. drvr->wlc->ucode_rev
  86. );
  87. return simple_read_from_buffer(data, count, ppos, buf, res);
  88. }
  89. static const struct file_operations brcms_debugfs_hardware_ops = {
  90. .owner = THIS_MODULE,
  91. .open = simple_open,
  92. .read = brcms_debugfs_hardware_read
  93. };
  94. void brcms_debugfs_create_files(struct brcms_pub *drvr)
  95. {
  96. struct dentry *dentry = drvr->dbgfs_dir;
  97. if (!IS_ERR_OR_NULL(dentry))
  98. debugfs_create_file("hardware", S_IRUGO, dentry,
  99. drvr, &brcms_debugfs_hardware_ops);
  100. }
  101. #define __brcms_fn(fn) \
  102. void __brcms_ ##fn(struct device *dev, const char *fmt, ...) \
  103. { \
  104. struct va_format vaf = { \
  105. .fmt = fmt, \
  106. }; \
  107. va_list args; \
  108. \
  109. va_start(args, fmt); \
  110. vaf.va = &args; \
  111. dev_ ##fn(dev, "%pV", &vaf); \
  112. trace_brcms_ ##fn(&vaf); \
  113. va_end(args); \
  114. }
  115. __brcms_fn(info)
  116. __brcms_fn(warn)
  117. __brcms_fn(err)
  118. __brcms_fn(crit)
  119. #if defined(CONFIG_BRCMDBG) || defined(CONFIG_BRCM_TRACING)
  120. void __brcms_dbg(struct device *dev, u32 level, const char *func,
  121. const char *fmt, ...)
  122. {
  123. struct va_format vaf = {
  124. .fmt = fmt,
  125. };
  126. va_list args;
  127. va_start(args, fmt);
  128. vaf.va = &args;
  129. #ifdef CONFIG_BRCMDBG
  130. if ((brcm_msg_level & level) && net_ratelimit())
  131. dev_err(dev, "%s %pV", func, &vaf);
  132. #endif
  133. trace_brcms_dbg(level, func, &vaf);
  134. va_end(args);
  135. }
  136. #endif