qdf_debugfs.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * Copyright (c) 2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: qdf_debugfs.h
  20. * This file provides OS abstraction for debug filesystem APIs.
  21. */
  22. #ifndef _QDF_DEBUGFS_H
  23. #define _QDF_DEBUGFS_H
  24. #include <qdf_status.h>
  25. #include <i_qdf_debugfs.h>
  26. #include <qdf_atomic.h>
  27. #include <qdf_types.h>
  28. /* representation of qdf dentry */
  29. typedef __qdf_dentry_t qdf_dentry_t;
  30. typedef __qdf_debugfs_file_t qdf_debugfs_file_t;
  31. /* qdf file modes */
  32. #define QDF_FILE_USR_READ 00400
  33. #define QDF_FILE_USR_WRITE 00200
  34. #define QDF_FILE_GRP_READ 00040
  35. #define QDF_FILE_GRP_WRITE 00020
  36. #define QDF_FILE_OTH_READ 00004
  37. #define QDF_FILE_OTH_WRITE 00002
  38. /**
  39. * struct qdf_debugfs_fops - qdf debugfs operations
  40. * @show: Callback for show operation.
  41. * Following functions can be used to print data in the show function,
  42. * qdf_debugfs_print()
  43. * qdf_debugfs_hexdump()
  44. * qdf_debugfs_write()
  45. * @write: Callback for write operation.
  46. * @priv: Private pointer which will be passed in the registered callbacks.
  47. */
  48. struct qdf_debugfs_fops {
  49. QDF_STATUS(*show)(qdf_debugfs_file_t file, void *arg);
  50. QDF_STATUS(*write)(void *priv, const char *buf, qdf_size_t len);
  51. void *priv;
  52. };
  53. #ifdef WLAN_DEBUGFS
  54. /**
  55. * qdf_debugfs_init() - initialize debugfs
  56. *
  57. * Return: QDF_STATUS
  58. */
  59. QDF_STATUS qdf_debugfs_init(void);
  60. /**
  61. * qdf_debugfs_exit() - cleanup debugfs
  62. *
  63. * Return: QDF_STATUS
  64. */
  65. QDF_STATUS qdf_debugfs_exit(void);
  66. /**
  67. * qdf_debugfs_create_dir() - create a debugfs directory
  68. * @name: name of the new directory
  69. * @parent: parent node. If NULL, defaults to base qdf_debugfs_root
  70. *
  71. * Return: dentry structure pointer in case of success, otherwise NULL.
  72. *
  73. */
  74. qdf_dentry_t qdf_debugfs_create_dir(const char *name, qdf_dentry_t parent);
  75. /**
  76. * qdf_debugfs_create_file() - create a debugfs file
  77. * @name: name of the file
  78. * @mode: qdf file mode
  79. * @parent: parent node. If NULL, defaults to base qdf_debugfs_root
  80. * @fops: file operations { .read, .write ... }
  81. *
  82. * Return: dentry structure pointer in case of success, otherwise NULL.
  83. *
  84. */
  85. qdf_dentry_t qdf_debugfs_create_file(const char *name, uint16_t mode,
  86. qdf_dentry_t parent,
  87. struct qdf_debugfs_fops *fops);
  88. /**
  89. * qdf_debugfs_printf() - print formated string into debugfs file
  90. * @file: debugfs file handle passed in fops->show() function
  91. * @f: the format string to use
  92. * @...: arguments for the format string
  93. */
  94. void qdf_debugfs_printf(qdf_debugfs_file_t file, const char *f, ...);
  95. /**
  96. * qdf_debugfs_hexdump() - print hexdump into debugfs file
  97. * @file: debugfs file handle passed in fops->show() function.
  98. * @buf: data
  99. * @len: data length
  100. *
  101. */
  102. void qdf_debugfs_hexdump(qdf_debugfs_file_t file, const uint8_t *buf,
  103. qdf_size_t len);
  104. /**
  105. * qdf_debugfs_write() - write data into debugfs file
  106. * @file: debugfs file handle passed in fops->show() function.
  107. * @buf: data
  108. * @len: data length
  109. *
  110. */
  111. void qdf_debugfs_write(qdf_debugfs_file_t file, const uint8_t *buf,
  112. qdf_size_t len);
  113. /**
  114. * qdf_debugfs_create_u8() - create a debugfs file for a u8 variable
  115. * @name: name of the file
  116. * @mode: qdf file mode
  117. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  118. * @value: pointer to a u8 variable (global/static)
  119. *
  120. * Return: dentry for the file; NULL in case of failure.
  121. *
  122. */
  123. qdf_dentry_t qdf_debugfs_create_u8(const char *name, uint16_t mode,
  124. qdf_dentry_t parent, u8 *value);
  125. /**
  126. * qdf_debugfs_create_u16() - create a debugfs file for a u16 variable
  127. * @name: name of the file
  128. * @mode: qdf file mode
  129. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  130. * @value: pointer to a u16 variable (global/static)
  131. *
  132. * Return: dentry for the file; NULL in case of failure.
  133. *
  134. */
  135. qdf_dentry_t qdf_debugfs_create_u16(const char *name, uint16_t mode,
  136. qdf_dentry_t parent, u16 *value);
  137. /**
  138. * qdf_debugfs_create_u32() - create a debugfs file for a u32 variable
  139. * @name: name of the file
  140. * @mode: qdf file mode
  141. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  142. * @value: pointer to a u32 variable (global/static)
  143. *
  144. * Return: dentry for the file; NULL in case of failure.
  145. *
  146. */
  147. qdf_dentry_t qdf_debugfs_create_u32(const char *name, uint16_t mode,
  148. qdf_dentry_t parent, u32 *value);
  149. /**
  150. * qdf_debugfs_create_u64() - create a debugfs file for a u64 variable
  151. * @name: name of the file
  152. * @mode: qdf file mode
  153. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  154. * @value: pointer to a u64 variable (global/static)
  155. *
  156. * Return: dentry for the file; NULL in case of failure.
  157. *
  158. */
  159. qdf_dentry_t qdf_debugfs_create_u64(const char *name, uint16_t mode,
  160. qdf_dentry_t parent, u64 *value);
  161. /**
  162. * qdf_debugfs_create_atomic() - create a debugfs file for an atomic variable
  163. * @name: name of the file
  164. * @mode: qdf file mode
  165. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  166. * @value: pointer to an atomic variable (global/static)
  167. *
  168. * Return: dentry for the file; NULL in case of failure.
  169. *
  170. */
  171. qdf_dentry_t qdf_debugfs_create_atomic(const char *name, uint16_t mode,
  172. qdf_dentry_t parent,
  173. qdf_atomic_t *value);
  174. /**
  175. * qdf_debugfs_create_string() - create a debugfs file for a string
  176. * @name: name of the file
  177. * @mode: qdf file mode
  178. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  179. * @str: a pointer to NULL terminated string (global/static).
  180. *
  181. * Return: dentry for the file; NULL in case of failure.
  182. *
  183. */
  184. qdf_dentry_t qdf_debugfs_create_string(const char *name, uint16_t mode,
  185. qdf_dentry_t parent, char *str);
  186. /**
  187. * qdf_debugfs_remove_dir_recursive() - remove directory recursively
  188. * @d: debugfs node
  189. *
  190. * This function will recursively removes a dreictory in debugfs that was
  191. * previously createed with a call to qdf_debugfs_create_file() or it's
  192. * variant functions.
  193. */
  194. void qdf_debugfs_remove_dir_recursive(qdf_dentry_t d);
  195. /**
  196. * qdf_debugfs_remove_dir() - remove debugfs directory
  197. * @d: debugfs node
  198. *
  199. */
  200. void qdf_debugfs_remove_dir(qdf_dentry_t d);
  201. /**
  202. * qdf_debugfs_remove_file() - remove debugfs file
  203. * @d: debugfs node
  204. *
  205. */
  206. void qdf_debugfs_remove_file(qdf_dentry_t d);
  207. #else /* WLAN_DEBUGFS */
  208. static inline QDF_STATUS qdf_debugfs_init(void)
  209. {
  210. return QDF_STATUS_E_NOSUPPORT;
  211. }
  212. static inline QDF_STATUS qdf_debugfs_exit(void)
  213. {
  214. return QDF_STATUS_E_NOSUPPORT;
  215. }
  216. static inline qdf_dentry_t qdf_debugfs_create_dir(const char *name,
  217. qdf_dentry_t parent)
  218. {
  219. return NULL;
  220. }
  221. static inline qdf_dentry_t
  222. qdf_debugfs_create_file(const char *name, uint16_t mode, qdf_dentry_t parent,
  223. struct qdf_debugfs_fops *fops)
  224. {
  225. return NULL;
  226. }
  227. static inline void qdf_debugfs_printf(qdf_debugfs_file_t file, const char *f,
  228. ...)
  229. {
  230. }
  231. static inline void qdf_debugfs_hexdump(qdf_debugfs_file_t file,
  232. const uint8_t *buf, qdf_size_t len)
  233. {
  234. }
  235. static inline void qdf_debugfs_write(qdf_debugfs_file_t file,
  236. const uint8_t *buf, qdf_size_t len)
  237. {
  238. }
  239. static inline qdf_dentry_t qdf_debugfs_create_u8(const char *name,
  240. uint16_t mode,
  241. qdf_dentry_t parent, u8 *value)
  242. {
  243. return NULL;
  244. }
  245. static inline qdf_dentry_t qdf_debugfs_create_u16(const char *name,
  246. uint16_t mode,
  247. qdf_dentry_t parent,
  248. u16 *value)
  249. {
  250. return NULL;
  251. }
  252. static inline qdf_dentry_t qdf_debugfs_create_u32(const char *name,
  253. uint16_t mode,
  254. qdf_dentry_t parent,
  255. u32 *value)
  256. {
  257. return NULL;
  258. }
  259. static inline qdf_dentry_t qdf_debugfs_create_u64(const char *name,
  260. uint16_t mode,
  261. qdf_dentry_t parent,
  262. u64 *value)
  263. {
  264. return NULL;
  265. }
  266. static inline qdf_dentry_t qdf_debugfs_create_atomic(const char *name,
  267. uint16_t mode,
  268. qdf_dentry_t parent,
  269. qdf_atomic_t *value)
  270. {
  271. return NULL;
  272. }
  273. static inline qdf_dentry_t debugfs_create_string(const char *name,
  274. uint16_t mode,
  275. qdf_dentry_t parent, char *str)
  276. {
  277. return NULL;
  278. }
  279. static inline void qdf_debugfs_remove_dir_recursive(qdf_dentry_t d) {}
  280. static inline void qdf_debugfs_remove_dir(qdf_dentry_t d) {}
  281. static inline void qdf_debugfs_remove_file(qdf_dentry_t d) {}
  282. #endif /* WLAN_DEBUGFS */
  283. #endif /* _QDF_DEBUGFS_H */