qdf_debugfs.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * Copyright (c) 2017-2020 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: None
  64. */
  65. void 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. * @rowsize: row size in bytes to dump
  101. * @groupsize: group size in bytes to dump
  102. *
  103. */
  104. void qdf_debugfs_hexdump(qdf_debugfs_file_t file, const uint8_t *buf,
  105. qdf_size_t len, int rowsize, int groupsize);
  106. /**
  107. * qdf_debugfs_overflow() - check overflow occurrence in debugfs buffer
  108. * @file: debugfs file handle passed in fops->show() function.
  109. *
  110. * Return: 1 on overflow occurrence else 0
  111. *
  112. */
  113. bool qdf_debugfs_overflow(qdf_debugfs_file_t file);
  114. /**
  115. * qdf_debugfs_write() - write data into debugfs file
  116. * @file: debugfs file handle passed in fops->show() function.
  117. * @buf: data
  118. * @len: data length
  119. *
  120. */
  121. void qdf_debugfs_write(qdf_debugfs_file_t file, const uint8_t *buf,
  122. qdf_size_t len);
  123. /**
  124. * qdf_debugfs_create_u8() - create a debugfs file for a u8 variable
  125. * @name: name of the file
  126. * @mode: qdf file mode
  127. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  128. * @value: pointer to a u8 variable (global/static)
  129. *
  130. * Return: None
  131. */
  132. void qdf_debugfs_create_u8(const char *name, uint16_t mode,
  133. qdf_dentry_t parent, u8 *value);
  134. /**
  135. * qdf_debugfs_create_u16() - create a debugfs file for a u16 variable
  136. * @name: name of the file
  137. * @mode: qdf file mode
  138. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  139. * @value: pointer to a u16 variable (global/static)
  140. *
  141. * Return: None
  142. */
  143. void qdf_debugfs_create_u16(const char *name, uint16_t mode,
  144. qdf_dentry_t parent, u16 *value);
  145. /**
  146. * qdf_debugfs_create_u32() - create a debugfs file for a u32 variable
  147. * @name: name of the file
  148. * @mode: qdf file mode
  149. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  150. * @value: pointer to a u32 variable (global/static)
  151. *
  152. * Return: None
  153. */
  154. void qdf_debugfs_create_u32(const char *name, uint16_t mode,
  155. qdf_dentry_t parent, u32 *value);
  156. /**
  157. * qdf_debugfs_create_u64() - create a debugfs file for a u64 variable
  158. * @name: name of the file
  159. * @mode: qdf file mode
  160. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  161. * @value: pointer to a u64 variable (global/static)
  162. *
  163. * Return: None
  164. */
  165. void qdf_debugfs_create_u64(const char *name, uint16_t mode,
  166. qdf_dentry_t parent, u64 *value);
  167. /**
  168. * qdf_debugfs_create_atomic() - create a debugfs file for an atomic variable
  169. * @name: name of the file
  170. * @mode: qdf file mode
  171. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  172. * @value: pointer to an atomic variable (global/static)
  173. *
  174. * Return: None
  175. */
  176. void qdf_debugfs_create_atomic(const char *name, uint16_t mode,
  177. qdf_dentry_t parent,
  178. qdf_atomic_t *value);
  179. /**
  180. * qdf_debugfs_create_string() - create a debugfs file for a string
  181. * @name: name of the file
  182. * @mode: qdf file mode
  183. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  184. * @str: a pointer to NULL terminated string (global/static).
  185. *
  186. * Return: dentry for the file; NULL in case of failure.
  187. *
  188. */
  189. qdf_dentry_t qdf_debugfs_create_string(const char *name, uint16_t mode,
  190. qdf_dentry_t parent, char *str);
  191. /**
  192. * qdf_debugfs_remove_dir_recursive() - remove directory recursively
  193. * @d: debugfs node
  194. *
  195. * This function will recursively removes a dreictory in debugfs that was
  196. * previously createed with a call to qdf_debugfs_create_file() or it's
  197. * variant functions.
  198. */
  199. void qdf_debugfs_remove_dir_recursive(qdf_dentry_t d);
  200. /**
  201. * qdf_debugfs_remove_dir() - remove debugfs directory
  202. * @d: debugfs node
  203. *
  204. */
  205. void qdf_debugfs_remove_dir(qdf_dentry_t d);
  206. /**
  207. * qdf_debugfs_remove_file() - remove debugfs file
  208. * @d: debugfs node
  209. *
  210. */
  211. void qdf_debugfs_remove_file(qdf_dentry_t d);
  212. /**
  213. * qdf_debugfs_create_file_simplified() - Create a simple debugfs file
  214. * where a single function call produces all the desired output
  215. * @name: name of the file
  216. * @mode: qdf file mode
  217. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  218. * @fops: file operations { .show, .write , .priv... }
  219. *
  220. * Users just have to define the show() function and pass it via @fops.show()
  221. * argument. When the output time comes, the show() will be called once.
  222. * The show() function must do everything that is needed to write the data,
  223. * all in one function call.
  224. * This is useful either for writing small amounts of data to debugfs or
  225. * for cases in which the output is not iterative.
  226. * The private data can be passed via @fops.priv, which will be available
  227. * inside the show() function as the 'private' filed of the qdf_debugfs_file_t.
  228. *
  229. * Return: dentry structure pointer in case of success, otherwise NULL.
  230. *
  231. */
  232. qdf_dentry_t qdf_debugfs_create_file_simplified(const char *name, uint16_t mode,
  233. qdf_dentry_t parent,
  234. struct qdf_debugfs_fops *fops);
  235. /**
  236. * qdf_debugfs_printer() - Print formated string into debugfs file
  237. * @priv: The private data
  238. * @fmt: Format string
  239. * @...: arguments for the format string
  240. *
  241. * This function prints a new line character after printing the formatted
  242. * string into the debugfs file.
  243. * This function can be passed when the argument is of type qdf_abstract_print
  244. */
  245. int qdf_debugfs_printer(void *priv, const char *fmt, ...);
  246. #else /* WLAN_DEBUGFS */
  247. static inline QDF_STATUS qdf_debugfs_init(void)
  248. {
  249. return QDF_STATUS_SUCCESS;
  250. }
  251. static inline void qdf_debugfs_exit(void) { }
  252. static inline qdf_dentry_t qdf_debugfs_create_dir(const char *name,
  253. qdf_dentry_t parent)
  254. {
  255. return NULL;
  256. }
  257. static inline qdf_dentry_t
  258. qdf_debugfs_create_file(const char *name, uint16_t mode, qdf_dentry_t parent,
  259. struct qdf_debugfs_fops *fops)
  260. {
  261. return NULL;
  262. }
  263. static inline void qdf_debugfs_printf(qdf_debugfs_file_t file, const char *f,
  264. ...)
  265. {
  266. }
  267. static inline void qdf_debugfs_hexdump(qdf_debugfs_file_t file,
  268. const uint8_t *buf, qdf_size_t len,
  269. int rowsize, int groupsize)
  270. {
  271. }
  272. static inline bool qdf_debugfs_overflow(qdf_debugfs_file_t file)
  273. {
  274. return 0;
  275. }
  276. static inline void qdf_debugfs_write(qdf_debugfs_file_t file,
  277. const uint8_t *buf, qdf_size_t len)
  278. {
  279. }
  280. static inline void qdf_debugfs_create_u8(const char *name,
  281. uint16_t mode,
  282. qdf_dentry_t parent, u8 *value)
  283. {
  284. }
  285. static inline void qdf_debugfs_create_u16(const char *name,
  286. uint16_t mode,
  287. qdf_dentry_t parent,
  288. u16 *value)
  289. {
  290. }
  291. static inline void qdf_debugfs_create_u32(const char *name,
  292. uint16_t mode,
  293. qdf_dentry_t parent,
  294. u32 *value)
  295. {
  296. }
  297. static inline void qdf_debugfs_create_u64(const char *name,
  298. uint16_t mode,
  299. qdf_dentry_t parent,
  300. u64 *value)
  301. {
  302. }
  303. static inline void qdf_debugfs_create_atomic(const char *name,
  304. uint16_t mode,
  305. qdf_dentry_t parent,
  306. qdf_atomic_t *value)
  307. {
  308. }
  309. static inline qdf_dentry_t debugfs_create_string(const char *name,
  310. uint16_t mode,
  311. qdf_dentry_t parent, char *str)
  312. {
  313. return NULL;
  314. }
  315. static inline void qdf_debugfs_remove_dir_recursive(qdf_dentry_t d) {}
  316. static inline void qdf_debugfs_remove_dir(qdf_dentry_t d) {}
  317. static inline void qdf_debugfs_remove_file(qdf_dentry_t d) {}
  318. static inline
  319. qdf_dentry_t qdf_debugfs_create_file_simplified(const char *name, uint16_t mode,
  320. qdf_dentry_t parent,
  321. struct qdf_debugfs_fops *fops)
  322. {
  323. return NULL;
  324. }
  325. static inline
  326. int qdf_debugfs_printer(void *priv, const char *fmt, ...)
  327. {
  328. return 0;
  329. }
  330. #endif /* WLAN_DEBUGFS */
  331. #endif /* _QDF_DEBUGFS_H */