qdf_debugfs.h 11 KB

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