debugfs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/string.h>
  28. #include <linux/ctype.h>
  29. #include <linux/mmc/sdio_func.h>
  30. #include <linux/mmc/sdio.h>
  31. #include <linux/debugfs.h>
  32. #include "iwmc3200top.h"
  33. #include "fw-msg.h"
  34. #include "log.h"
  35. #include "debugfs.h"
  36. /* Constants definition */
  37. #define HEXADECIMAL_RADIX 16
  38. /* Functions definition */
  39. #define DEBUGFS_ADD(name, parent) do { \
  40. dbgfs->dbgfs_##parent##_files.file_##name = \
  41. debugfs_create_file(#name, 0644, dbgfs->dir_##parent, priv, \
  42. &iwmct_dbgfs_##name##_ops); \
  43. } while (0)
  44. #define DEBUGFS_RM(name) do { \
  45. debugfs_remove(name); \
  46. name = NULL; \
  47. } while (0)
  48. #define DEBUGFS_READ_FUNC(name) \
  49. ssize_t iwmct_dbgfs_##name##_read(struct file *file, \
  50. char __user *user_buf, \
  51. size_t count, loff_t *ppos);
  52. #define DEBUGFS_WRITE_FUNC(name) \
  53. ssize_t iwmct_dbgfs_##name##_write(struct file *file, \
  54. const char __user *user_buf, \
  55. size_t count, loff_t *ppos);
  56. #define DEBUGFS_READ_FILE_OPS(name) \
  57. DEBUGFS_READ_FUNC(name) \
  58. static const struct file_operations iwmct_dbgfs_##name##_ops = { \
  59. .read = iwmct_dbgfs_##name##_read, \
  60. .open = iwmct_dbgfs_open_file_generic, \
  61. };
  62. #define DEBUGFS_WRITE_FILE_OPS(name) \
  63. DEBUGFS_WRITE_FUNC(name) \
  64. static const struct file_operations iwmct_dbgfs_##name##_ops = { \
  65. .write = iwmct_dbgfs_##name##_write, \
  66. .open = iwmct_dbgfs_open_file_generic, \
  67. };
  68. #define DEBUGFS_READ_WRITE_FILE_OPS(name) \
  69. DEBUGFS_READ_FUNC(name) \
  70. DEBUGFS_WRITE_FUNC(name) \
  71. static const struct file_operations iwmct_dbgfs_##name##_ops = {\
  72. .write = iwmct_dbgfs_##name##_write, \
  73. .read = iwmct_dbgfs_##name##_read, \
  74. .open = iwmct_dbgfs_open_file_generic, \
  75. };
  76. /* Debugfs file ops definitions */
  77. /*
  78. * Create the debugfs files and directories
  79. *
  80. */
  81. void iwmct_dbgfs_register(struct iwmct_priv *priv, const char *name)
  82. {
  83. struct iwmct_debugfs *dbgfs;
  84. dbgfs = kzalloc(sizeof(struct iwmct_debugfs), GFP_KERNEL);
  85. if (!dbgfs) {
  86. LOG_ERROR(priv, DEBUGFS, "failed to allocate %zd bytes\n",
  87. sizeof(struct iwmct_debugfs));
  88. return;
  89. }
  90. priv->dbgfs = dbgfs;
  91. dbgfs->name = name;
  92. dbgfs->dir_drv = debugfs_create_dir(name, NULL);
  93. if (!dbgfs->dir_drv) {
  94. LOG_ERROR(priv, DEBUGFS, "failed to create debugfs dir\n");
  95. return;
  96. }
  97. return;
  98. }
  99. /**
  100. * Remove the debugfs files and directories
  101. *
  102. */
  103. void iwmct_dbgfs_unregister(struct iwmct_debugfs *dbgfs)
  104. {
  105. if (!dbgfs)
  106. return;
  107. DEBUGFS_RM(dbgfs->dir_drv);
  108. kfree(dbgfs);
  109. dbgfs = NULL;
  110. }