debug.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <linux/netdevice.h>
  25. #include <net/mac80211.h>
  26. #include <defs.h>
  27. #include <brcmu_wifi.h>
  28. #include <brcmu_utils.h>
  29. #include "types.h"
  30. #include "main.h"
  31. #include "debug.h"
  32. #include "brcms_trace_events.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_RET(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. ssize_t brcms_debugfs_hardware_read(struct file *f, char __user *data,
  66. size_t count, loff_t *ppos)
  67. {
  68. char buf[128];
  69. int res;
  70. struct brcms_pub *drvr = f->private_data;
  71. /* only allow read from start */
  72. if (*ppos > 0)
  73. return 0;
  74. res = scnprintf(buf, sizeof(buf),
  75. "board vendor: %x\n"
  76. "board type: %x\n"
  77. "board revision: %x\n"
  78. "board flags: %x\n"
  79. "board flags2: %x\n"
  80. "firmware revision: %x\n",
  81. drvr->wlc->hw->d11core->bus->boardinfo.vendor,
  82. drvr->wlc->hw->d11core->bus->boardinfo.type,
  83. drvr->wlc->hw->boardrev,
  84. drvr->wlc->hw->boardflags,
  85. drvr->wlc->hw->boardflags2,
  86. drvr->wlc->ucode_rev
  87. );
  88. return simple_read_from_buffer(data, count, ppos, buf, res);
  89. }
  90. static const struct file_operations brcms_debugfs_hardware_ops = {
  91. .owner = THIS_MODULE,
  92. .open = simple_open,
  93. .read = brcms_debugfs_hardware_read
  94. };
  95. void brcms_debugfs_create_files(struct brcms_pub *drvr)
  96. {
  97. struct dentry *dentry = drvr->dbgfs_dir;
  98. if (!IS_ERR_OR_NULL(dentry))
  99. debugfs_create_file("hardware", S_IRUGO, dentry,
  100. drvr, &brcms_debugfs_hardware_ops);
  101. }
  102. #define __brcms_fn(fn) \
  103. void __brcms_ ##fn(struct device *dev, const char *fmt, ...) \
  104. { \
  105. struct va_format vaf = { \
  106. .fmt = fmt, \
  107. }; \
  108. va_list args; \
  109. \
  110. va_start(args, fmt); \
  111. vaf.va = &args; \
  112. dev_ ##fn(dev, "%pV", &vaf); \
  113. trace_brcms_ ##fn(&vaf); \
  114. va_end(args); \
  115. }
  116. __brcms_fn(info)
  117. __brcms_fn(warn)
  118. __brcms_fn(err)
  119. __brcms_fn(crit)
  120. #if defined(CONFIG_BRCMDBG) || defined(CONFIG_BRCM_TRACING)
  121. void __brcms_dbg(struct device *dev, u32 level, const char *func,
  122. const char *fmt, ...)
  123. {
  124. struct va_format vaf = {
  125. .fmt = fmt,
  126. };
  127. va_list args;
  128. va_start(args, fmt);
  129. vaf.va = &args;
  130. #ifdef CONFIG_BRCMDBG
  131. if ((brcm_msg_level & level) && net_ratelimit())
  132. dev_err(dev, "%s %pV", func, &vaf);
  133. #endif
  134. trace_brcms_dbg(level, func, &vaf);
  135. va_end(args);
  136. }
  137. #endif