qdf_debugfs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /*
  2. * Copyright (c) 2017-2021 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. typedef __qdf_debugfs_blob_wrap_t qdf_debugfs_blob_wrap_t;
  32. typedef __qdf_entry_t qdf_entry_t;
  33. typedef __qdf_file_ops_t qdf_file_ops_t;
  34. /* qdf file modes */
  35. #define QDF_FILE_USR_READ 00400
  36. #define QDF_FILE_USR_WRITE 00200
  37. #define QDF_FILE_GRP_READ 00040
  38. #define QDF_FILE_GRP_WRITE 00020
  39. #define QDF_FILE_OTH_READ 00004
  40. #define QDF_FILE_OTH_WRITE 00002
  41. /**
  42. * struct qdf_debugfs_fops - qdf debugfs operations
  43. * @show: Callback for show operation.
  44. * Following functions can be used to print data in the show function,
  45. * qdf_debugfs_print()
  46. * qdf_debugfs_hexdump()
  47. * qdf_debugfs_write()
  48. * @write: Callback for write operation.
  49. * @priv: Private pointer which will be passed in the registered callbacks.
  50. */
  51. struct qdf_debugfs_fops {
  52. QDF_STATUS(*show)(qdf_debugfs_file_t file, void *arg);
  53. QDF_STATUS(*write)(void *priv, const char *buf, qdf_size_t len);
  54. void *priv;
  55. };
  56. #ifdef WLAN_DEBUGFS
  57. /**
  58. * qdf_debugfs_init() - initialize debugfs
  59. *
  60. * Return: QDF_STATUS
  61. */
  62. QDF_STATUS qdf_debugfs_init(void);
  63. /**
  64. * qdf_debugfs_exit() - cleanup debugfs
  65. *
  66. * Return: None
  67. */
  68. void qdf_debugfs_exit(void);
  69. /**
  70. * qdf_debugfs_create_dir() - create a debugfs directory
  71. * @name: name of the new directory
  72. * @parent: parent node. If NULL, defaults to base qdf_debugfs_root
  73. *
  74. * Return: dentry structure pointer in case of success, otherwise NULL.
  75. *
  76. */
  77. qdf_dentry_t qdf_debugfs_create_dir(const char *name, qdf_dentry_t parent);
  78. /**
  79. * qdf_debugfs_create_file() - create a debugfs file
  80. * @name: name of the file
  81. * @mode: qdf file mode
  82. * @parent: parent node. If NULL, defaults to base qdf_debugfs_root
  83. * @fops: file operations { .read, .write ... }
  84. *
  85. * Return: dentry structure pointer in case of success, otherwise NULL.
  86. *
  87. */
  88. qdf_dentry_t qdf_debugfs_create_file(const char *name, uint16_t mode,
  89. qdf_dentry_t parent,
  90. struct qdf_debugfs_fops *fops);
  91. /**
  92. * qdf_debugfs_printf() - print formated string into debugfs file
  93. * @file: debugfs file handle passed in fops->show() function
  94. * @f: the format string to use
  95. * @...: arguments for the format string
  96. */
  97. void qdf_debugfs_printf(qdf_debugfs_file_t file, const char *f, ...);
  98. /**
  99. * qdf_debugfs_hexdump() - print hexdump into debugfs file
  100. * @file: debugfs file handle passed in fops->show() function.
  101. * @buf: data
  102. * @len: data length
  103. * @rowsize: row size in bytes to dump
  104. * @groupsize: group size in bytes to dump
  105. *
  106. */
  107. void qdf_debugfs_hexdump(qdf_debugfs_file_t file, const uint8_t *buf,
  108. qdf_size_t len, int rowsize, int groupsize);
  109. /**
  110. * qdf_debugfs_overflow() - check overflow occurrence in debugfs buffer
  111. * @file: debugfs file handle passed in fops->show() function.
  112. *
  113. * Return: 1 on overflow occurrence else 0
  114. *
  115. */
  116. bool qdf_debugfs_overflow(qdf_debugfs_file_t file);
  117. /**
  118. * qdf_debugfs_write() - write data into debugfs file
  119. * @file: debugfs file handle passed in fops->show() function.
  120. * @buf: data
  121. * @len: data length
  122. *
  123. */
  124. void qdf_debugfs_write(qdf_debugfs_file_t file, const uint8_t *buf,
  125. qdf_size_t len);
  126. /**
  127. * qdf_debugfs_create_u8() - create a debugfs file for a u8 variable
  128. * @name: name of the file
  129. * @mode: qdf file mode
  130. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  131. * @value: pointer to a u8 variable (global/static)
  132. *
  133. * Return: None
  134. */
  135. void qdf_debugfs_create_u8(const char *name, uint16_t mode,
  136. qdf_dentry_t parent, u8 *value);
  137. /**
  138. * qdf_debugfs_create_u16() - create a debugfs file for a u16 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 u16 variable (global/static)
  143. *
  144. * Return: None
  145. */
  146. void qdf_debugfs_create_u16(const char *name, uint16_t mode,
  147. qdf_dentry_t parent, u16 *value);
  148. /**
  149. * qdf_debugfs_create_u32() - create a debugfs file for a u32 variable
  150. * @name: name of the file
  151. * @mode: qdf file mode
  152. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  153. * @value: pointer to a u32 variable (global/static)
  154. *
  155. * Return: None
  156. */
  157. void 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: None
  167. */
  168. void qdf_debugfs_create_u64(const char *name, uint16_t mode,
  169. qdf_dentry_t parent, u64 *value);
  170. /**
  171. * qdf_debugfs_create_atomic() - create a debugfs file for an atomic variable
  172. * @name: name of the file
  173. * @mode: qdf file mode
  174. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  175. * @value: pointer to an atomic variable (global/static)
  176. *
  177. * Return: None
  178. */
  179. void qdf_debugfs_create_atomic(const char *name, uint16_t mode,
  180. qdf_dentry_t parent,
  181. qdf_atomic_t *value);
  182. /**
  183. * qdf_debugfs_create_string() - create a debugfs file for a string
  184. * @name: name of the file
  185. * @mode: qdf file mode
  186. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  187. * @str: a pointer to NULL terminated string (global/static).
  188. *
  189. * Return: dentry for the file; NULL in case of failure.
  190. *
  191. */
  192. qdf_dentry_t qdf_debugfs_create_string(const char *name, uint16_t mode,
  193. qdf_dentry_t parent, char *str);
  194. /**
  195. * qdf_debugfs_remove_dir_recursive() - remove directory recursively
  196. * @d: debugfs node
  197. *
  198. * This function will recursively removes a dreictory in debugfs that was
  199. * previously createed with a call to qdf_debugfs_create_file() or it's
  200. * variant functions.
  201. */
  202. void qdf_debugfs_remove_dir_recursive(qdf_dentry_t d);
  203. /**
  204. * qdf_debugfs_remove_dir() - remove debugfs directory
  205. * @d: debugfs node
  206. *
  207. */
  208. void qdf_debugfs_remove_dir(qdf_dentry_t d);
  209. /**
  210. * qdf_debugfs_remove_file() - remove debugfs file
  211. * @d: debugfs node
  212. *
  213. */
  214. void qdf_debugfs_remove_file(qdf_dentry_t d);
  215. /**
  216. * qdf_debugfs_create_file_simplified() - Create a simple debugfs file
  217. * where a single function call produces all the desired output
  218. * @name: name of the file
  219. * @mode: qdf file mode
  220. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  221. * @fops: file operations { .show, .write , .priv... }
  222. *
  223. * Users just have to define the show() function and pass it via @fops.show()
  224. * argument. When the output time comes, the show() will be called once.
  225. * The show() function must do everything that is needed to write the data,
  226. * all in one function call.
  227. * This is useful either for writing small amounts of data to debugfs or
  228. * for cases in which the output is not iterative.
  229. * The private data can be passed via @fops.priv, which will be available
  230. * inside the show() function as the 'private' filed of the qdf_debugfs_file_t.
  231. *
  232. * Return: dentry structure pointer in case of success, otherwise NULL.
  233. *
  234. */
  235. qdf_dentry_t qdf_debugfs_create_file_simplified(const char *name, uint16_t mode,
  236. qdf_dentry_t parent,
  237. struct qdf_debugfs_fops *fops);
  238. /**
  239. * qdf_debugfs_printer() - Print formated string into debugfs file
  240. * @priv: The private data
  241. * @fmt: Format string
  242. * @...: arguments for the format string
  243. *
  244. * This function prints a new line character after printing the formatted
  245. * string into the debugfs file.
  246. * This function can be passed when the argument is of type qdf_abstract_print
  247. */
  248. int qdf_debugfs_printer(void *priv, const char *fmt, ...);
  249. /**
  250. * qdf_debugfs_create_blob() - create a debugfs file that is used to read
  251. * a binary blob
  252. * @name: a pointer to a string containing the name of the file to create.
  253. * @mode: the permission that the file should have
  254. * @parent: a pointer to the parent dentry for this file. This should be a
  255. * directory dentry if set. If this parameter is %NULL, then the
  256. * file will be created in the root of the debugfs filesystem.
  257. * @blob: a pointer to a qdf_debugfs_blob_wrap_t which contains a pointer
  258. * to the blob data and the size of the data.
  259. *
  260. * Return: dentry structure pointer on success, NULL otherwise.
  261. */
  262. qdf_dentry_t qdf_debugfs_create_blob(const char *name, umode_t mode,
  263. qdf_dentry_t parent,
  264. qdf_debugfs_blob_wrap_t blob);
  265. /**
  266. * qdf_debugfs_create_entry() - create a debugfs file for read or write
  267. * something
  268. * @name: name of the file
  269. * @mode: qdf file mode
  270. * @parent: parent node. If NULL, defaults to base qdf_debugfs_root
  271. * @data: Something data that caller want to read or write
  272. * @fops: file operations { .read, .write ... }
  273. *
  274. * Return: dentry structure pointer on success, NULL otherwise.
  275. */
  276. qdf_dentry_t qdf_debugfs_create_entry(const char *name, uint16_t mode,
  277. qdf_dentry_t parent,
  278. qdf_entry_t data,
  279. const qdf_file_ops_t fops);
  280. #else /* WLAN_DEBUGFS */
  281. static inline QDF_STATUS qdf_debugfs_init(void)
  282. {
  283. return QDF_STATUS_SUCCESS;
  284. }
  285. static inline void qdf_debugfs_exit(void) { }
  286. static inline qdf_dentry_t qdf_debugfs_create_dir(const char *name,
  287. qdf_dentry_t parent)
  288. {
  289. return NULL;
  290. }
  291. static inline qdf_dentry_t
  292. qdf_debugfs_create_file(const char *name, uint16_t mode, qdf_dentry_t parent,
  293. struct qdf_debugfs_fops *fops)
  294. {
  295. return NULL;
  296. }
  297. static inline void qdf_debugfs_printf(qdf_debugfs_file_t file, const char *f,
  298. ...)
  299. {
  300. }
  301. static inline void qdf_debugfs_hexdump(qdf_debugfs_file_t file,
  302. const uint8_t *buf, qdf_size_t len,
  303. int rowsize, int groupsize)
  304. {
  305. }
  306. static inline bool qdf_debugfs_overflow(qdf_debugfs_file_t file)
  307. {
  308. return 0;
  309. }
  310. static inline void qdf_debugfs_write(qdf_debugfs_file_t file,
  311. const uint8_t *buf, qdf_size_t len)
  312. {
  313. }
  314. static inline void qdf_debugfs_create_u8(const char *name,
  315. uint16_t mode,
  316. qdf_dentry_t parent, u8 *value)
  317. {
  318. }
  319. static inline void qdf_debugfs_create_u16(const char *name,
  320. uint16_t mode,
  321. qdf_dentry_t parent,
  322. u16 *value)
  323. {
  324. }
  325. static inline void qdf_debugfs_create_u32(const char *name,
  326. uint16_t mode,
  327. qdf_dentry_t parent,
  328. u32 *value)
  329. {
  330. }
  331. static inline void qdf_debugfs_create_u64(const char *name,
  332. uint16_t mode,
  333. qdf_dentry_t parent,
  334. u64 *value)
  335. {
  336. }
  337. static inline void qdf_debugfs_create_atomic(const char *name,
  338. uint16_t mode,
  339. qdf_dentry_t parent,
  340. qdf_atomic_t *value)
  341. {
  342. }
  343. static inline qdf_dentry_t debugfs_create_string(const char *name,
  344. uint16_t mode,
  345. qdf_dentry_t parent, char *str)
  346. {
  347. return NULL;
  348. }
  349. static inline void qdf_debugfs_remove_dir_recursive(qdf_dentry_t d) {}
  350. static inline void qdf_debugfs_remove_dir(qdf_dentry_t d) {}
  351. static inline void qdf_debugfs_remove_file(qdf_dentry_t d) {}
  352. static inline
  353. qdf_dentry_t qdf_debugfs_create_file_simplified(const char *name, uint16_t mode,
  354. qdf_dentry_t parent,
  355. struct qdf_debugfs_fops *fops)
  356. {
  357. return NULL;
  358. }
  359. static inline
  360. int qdf_debugfs_printer(void *priv, const char *fmt, ...)
  361. {
  362. return 0;
  363. }
  364. static inline
  365. qdf_dentry_t qdf_debugfs_create_blob(const char *name, umode_t mode,
  366. qdf_dentry_t parent,
  367. qdf_debugfs_blob_wrap_t blob)
  368. {
  369. return NULL;
  370. }
  371. static inline
  372. qdf_dentry_t qdf_debugfs_create_entry(const char *name, uint16_t mode,
  373. qdf_dentry_t parent,
  374. qdf_entry_t data,
  375. const qdf_file_ops_t fops)
  376. {
  377. return NULL;
  378. }
  379. #endif /* WLAN_DEBUGFS */
  380. #endif /* _QDF_DEBUGFS_H */