debugfs.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * iwmc3200top - Intel Wireless MultiCom 3200 Top Driver
  3. * drivers/misc/iwmc3200top/debufs.c
  4. *
  5. * Copyright (C) 2009 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301, USA.
  20. *
  21. *
  22. * Author Name: Maxim Grabarnik <maxim.grabarnink@intel.com>
  23. * -
  24. *
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/slab.h>
  28. #include <linux/string.h>
  29. #include <linux/ctype.h>
  30. #include <linux/mmc/sdio_func.h>
  31. #include <linux/mmc/sdio.h>
  32. #include <linux/debugfs.h>
  33. #include "iwmc3200top.h"
  34. #include "fw-msg.h"
  35. #include "log.h"
  36. #include "debugfs.h"
  37. /* Constants definition */
  38. #define HEXADECIMAL_RADIX 16
  39. /* Functions definition */
  40. #define DEBUGFS_ADD(name, parent) do { \
  41. dbgfs->dbgfs_##parent##_files.file_##name = \
  42. debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \
  43. &iwmct_dbgfs_##name##_ops); \
  44. } while (0)
  45. #define DEBUGFS_RM(name) do { \
  46. debugfs_remove(name); \
  47. name = NULL; \
  48. } while (0)
  49. #define DEBUGFS_READ_FUNC(name) \
  50. ssize_t iwmct_dbgfs_##name##_read(struct file *file, \
  51. char __user *user_buf, \
  52. size_t count, loff_t *ppos);
  53. #define DEBUGFS_WRITE_FUNC(name) \
  54. ssize_t iwmct_dbgfs_##name##_write(struct file *file, \
  55. const char __user *user_buf, \
  56. size_t count, loff_t *ppos);
  57. #define DEBUGFS_READ_FILE_OPS(name) \
  58. DEBUGFS_READ_FUNC(name) \
  59. static const struct file_operations iwmct_dbgfs_##name##_ops = { \
  60. .read = iwmct_dbgfs_##name##_read, \
  61. .open = iwmct_dbgfs_open_file_generic, \
  62. .llseek = generic_file_llseek, \
  63. };
  64. #define DEBUGFS_WRITE_FILE_OPS(name) \
  65. DEBUGFS_WRITE_FUNC(name) \
  66. static const struct file_operations iwmct_dbgfs_##name##_ops = { \
  67. .write = iwmct_dbgfs_##name##_write, \
  68. .open = iwmct_dbgfs_open_file_generic, \
  69. .llseek = generic_file_llseek, \
  70. };
  71. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  72. DEBUGFS_READ_FUNC(name) \
  73. DEBUGFS_WRITE_FUNC(name) \
  74. static const struct file_operations iwmct_dbgfs_##name##_ops = {\
  75. .write = iwmct_dbgfs_##name##_write, \
  76. .read = iwmct_dbgfs_##name##_read, \
  77. .open = iwmct_dbgfs_open_file_generic, \
  78. .llseek = generic_file_llseek, \
  79. };
  80. /* Debugfs file ops definitions */
  81. /*
  82. * Create the debugfs files and directories
  83. *
  84. */
  85. void iwmct_dbgfs_register(struct iwmct_priv *priv, const char *name)
  86. {
  87. struct iwmct_debugfs *dbgfs;
  88. dbgfs = kzalloc(sizeof(struct iwmct_debugfs), GFP_KERNEL);
  89. if (!dbgfs) {
  90. LOG_ERROR(priv, DEBUGFS, "failed to allocate %zd bytes\n",
  91. sizeof(struct iwmct_debugfs));
  92. return;
  93. }
  94. priv->dbgfs = dbgfs;
  95. dbgfs->name = name;
  96. dbgfs->dir_drv = debugfs_create_dir(name, NULL);
  97. if (!dbgfs->dir_drv) {
  98. LOG_ERROR(priv, DEBUGFS, "failed to create debugfs dir\n");
  99. return;
  100. }
  101. return;
  102. }
  103. /**
  104. * Remove the debugfs files and directories
  105. *
  106. */
  107. void iwmct_dbgfs_unregister(struct iwmct_debugfs *dbgfs)
  108. {
  109. if (!dbgfs)
  110. return;
  111. DEBUGFS_RM(dbgfs->dir_drv);
  112. kfree(dbgfs);
  113. dbgfs = NULL;
  114. }