debugfs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #ifndef __DEBUGFS_H__
  24. #define __DEBUGFS_H__
  25. #include "wlcore.h"
  26. int wl1271_format_buffer(char __user *userbuf, size_t count,
  27. loff_t *ppos, char *fmt, ...);
  28. int wl1271_debugfs_init(struct wl1271 *wl);
  29. void wl1271_debugfs_exit(struct wl1271 *wl);
  30. void wl1271_debugfs_reset(struct wl1271 *wl);
  31. void wl1271_debugfs_update_stats(struct wl1271 *wl);
  32. #define DEBUGFS_FORMAT_BUFFER_SIZE 256
  33. #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
  34. static ssize_t name## _read(struct file *file, char __user *userbuf, \
  35. size_t count, loff_t *ppos) \
  36. { \
  37. struct wl1271 *wl = file->private_data; \
  38. return wl1271_format_buffer(userbuf, count, ppos, \
  39. fmt "\n", ##value); \
  40. } \
  41. \
  42. static const struct file_operations name## _ops = { \
  43. .read = name## _read, \
  44. .open = simple_open, \
  45. .llseek = generic_file_llseek, \
  46. };
  47. #define DEBUGFS_ADD(name, parent) \
  48. do { \
  49. entry = debugfs_create_file(#name, 0400, parent, \
  50. wl, &name## _ops); \
  51. if (!entry || IS_ERR(entry)) \
  52. goto err; \
  53. } while (0);
  54. #define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
  55. do { \
  56. entry = debugfs_create_file(#name, 0400, parent, \
  57. wl, &prefix## _## name## _ops); \
  58. if (!entry || IS_ERR(entry)) \
  59. goto err; \
  60. } while (0);
  61. #define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type) \
  62. static ssize_t sub## _ ##name## _read(struct file *file, \
  63. char __user *userbuf, \
  64. size_t count, loff_t *ppos) \
  65. { \
  66. struct wl1271 *wl = file->private_data; \
  67. struct struct_type *stats = wl->stats.fw_stats; \
  68. \
  69. wl1271_debugfs_update_stats(wl); \
  70. \
  71. return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
  72. stats->sub.name); \
  73. } \
  74. \
  75. static const struct file_operations sub## _ ##name## _ops = { \
  76. .read = sub## _ ##name## _read, \
  77. .open = simple_open, \
  78. .llseek = generic_file_llseek, \
  79. };
  80. #define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type) \
  81. static ssize_t sub## _ ##name## _read(struct file *file, \
  82. char __user *userbuf, \
  83. size_t count, loff_t *ppos) \
  84. { \
  85. struct wl1271 *wl = file->private_data; \
  86. struct struct_type *stats = wl->stats.fw_stats; \
  87. char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = ""; \
  88. int res, i; \
  89. \
  90. wl1271_debugfs_update_stats(wl); \
  91. \
  92. for (i = 0; i < len; i++) \
  93. res = snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \
  94. buf, i, stats->sub.name[i]); \
  95. \
  96. return wl1271_format_buffer(userbuf, count, ppos, "%s", buf); \
  97. } \
  98. \
  99. static const struct file_operations sub## _ ##name## _ops = { \
  100. .read = sub## _ ##name## _read, \
  101. .open = simple_open, \
  102. .llseek = generic_file_llseek, \
  103. };
  104. #define DEBUGFS_FWSTATS_ADD(sub, name) \
  105. DEBUGFS_ADD(sub## _ ##name, stats)
  106. #endif /* WL1271_DEBUGFS_H */