qdf_debugfs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: qdf_debugfs.h
  21. * This file provides OS abstraction for debug filesystem APIs.
  22. */
  23. #ifndef _QDF_DEBUGFS_H
  24. #define _QDF_DEBUGFS_H
  25. #include <qdf_status.h>
  26. #include <i_qdf_debugfs.h>
  27. #include <qdf_atomic.h>
  28. #include <qdf_types.h>
  29. /* representation of qdf dentry */
  30. typedef __qdf_dentry_t qdf_dentry_t;
  31. typedef __qdf_debugfs_file_t qdf_debugfs_file_t;
  32. typedef __qdf_debugfs_blob_wrap_t qdf_debugfs_blob_wrap_t;
  33. typedef __qdf_entry_t qdf_entry_t;
  34. typedef __qdf_file_ops_t qdf_file_ops_t;
  35. /* qdf file modes */
  36. #define QDF_FILE_USR_READ 00400
  37. #define QDF_FILE_USR_WRITE 00200
  38. #define QDF_FILE_GRP_READ 00040
  39. #define QDF_FILE_GRP_WRITE 00020
  40. #define QDF_FILE_OTH_READ 00004
  41. #define QDF_FILE_OTH_WRITE 00002
  42. /**
  43. * struct qdf_debugfs_fops - qdf debugfs operations
  44. * @show: Callback for show operation.
  45. * Following functions can be used to print data in the show function,
  46. * qdf_debugfs_print()
  47. * qdf_debugfs_hexdump()
  48. * qdf_debugfs_write()
  49. * @write: Callback for write operation.
  50. * @priv: Private pointer which will be passed in the registered callbacks.
  51. */
  52. struct qdf_debugfs_fops {
  53. QDF_STATUS(*show)(qdf_debugfs_file_t file, void *arg);
  54. QDF_STATUS(*write)(void *priv, const char *buf, qdf_size_t len);
  55. void *priv;
  56. };
  57. #ifdef WLAN_DEBUGFS
  58. /**
  59. * qdf_debugfs_init() - initialize debugfs
  60. *
  61. * Return: QDF_STATUS
  62. */
  63. QDF_STATUS qdf_debugfs_init(void);
  64. /**
  65. * qdf_debugfs_exit() - cleanup debugfs
  66. *
  67. * Return: None
  68. */
  69. void qdf_debugfs_exit(void);
  70. /**
  71. * qdf_debugfs_create_dir() - create a debugfs directory
  72. * @name: name of the new directory
  73. * @parent: parent node. If NULL, defaults to base qdf_debugfs_root
  74. *
  75. * Return: dentry structure pointer in case of success, otherwise NULL.
  76. *
  77. */
  78. qdf_dentry_t qdf_debugfs_create_dir(const char *name, qdf_dentry_t parent);
  79. /**
  80. * qdf_debugfs_create_file() - create a debugfs file
  81. * @name: name of the file
  82. * @mode: qdf file mode
  83. * @parent: parent node. If NULL, defaults to base qdf_debugfs_root
  84. * @fops: file operations { .read, .write ... }
  85. *
  86. * Return: dentry structure pointer in case of success, otherwise NULL.
  87. *
  88. */
  89. qdf_dentry_t qdf_debugfs_create_file(const char *name, uint16_t mode,
  90. qdf_dentry_t parent,
  91. struct qdf_debugfs_fops *fops);
  92. /**
  93. * qdf_debugfs_printf() - print formatted string into debugfs file
  94. * @file: debugfs file handle passed in fops->show() function
  95. * @f: the format string to use
  96. * @...: arguments for the format string
  97. */
  98. void qdf_debugfs_printf(qdf_debugfs_file_t file, const char *f, ...);
  99. /**
  100. * qdf_debugfs_hexdump() - print hexdump into debugfs file
  101. * @file: debugfs file handle passed in fops->show() function.
  102. * @buf: data
  103. * @len: data length
  104. * @rowsize: row size in bytes to dump
  105. * @groupsize: group size in bytes to dump
  106. *
  107. */
  108. void qdf_debugfs_hexdump(qdf_debugfs_file_t file, const uint8_t *buf,
  109. qdf_size_t len, int rowsize, int groupsize);
  110. /**
  111. * qdf_debugfs_overflow() - check overflow occurrence in debugfs buffer
  112. * @file: debugfs file handle passed in fops->show() function.
  113. *
  114. * Return: 1 on overflow occurrence else 0
  115. *
  116. */
  117. bool qdf_debugfs_overflow(qdf_debugfs_file_t file);
  118. /**
  119. * qdf_debugfs_write() - write data into debugfs file
  120. * @file: debugfs file handle passed in fops->show() function.
  121. * @buf: data
  122. * @len: data length
  123. *
  124. */
  125. void qdf_debugfs_write(qdf_debugfs_file_t file, const uint8_t *buf,
  126. qdf_size_t len);
  127. /**
  128. * qdf_debugfs_create_u8() - create a debugfs file for a u8 variable
  129. * @name: name of the file
  130. * @mode: qdf file mode
  131. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  132. * @value: pointer to a u8 variable (global/static)
  133. *
  134. * Return: None
  135. */
  136. void qdf_debugfs_create_u8(const char *name, uint16_t mode,
  137. qdf_dentry_t parent, u8 *value);
  138. /**
  139. * qdf_debugfs_create_u16() - create a debugfs file for a u16 variable
  140. * @name: name of the file
  141. * @mode: qdf file mode
  142. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  143. * @value: pointer to a u16 variable (global/static)
  144. *
  145. * Return: None
  146. */
  147. void qdf_debugfs_create_u16(const char *name, uint16_t mode,
  148. qdf_dentry_t parent, u16 *value);
  149. /**
  150. * qdf_debugfs_create_u32() - create a debugfs file for a u32 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 u32 variable (global/static)
  155. *
  156. * Return: None
  157. */
  158. void qdf_debugfs_create_u32(const char *name, uint16_t mode,
  159. qdf_dentry_t parent, u32 *value);
  160. /**
  161. * qdf_debugfs_create_u64() - create a debugfs file for a u64 variable
  162. * @name: name of the file
  163. * @mode: qdf file mode
  164. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  165. * @value: pointer to a u64 variable (global/static)
  166. *
  167. * Return: None
  168. */
  169. void 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: None
  179. */
  180. void qdf_debugfs_create_atomic(const char *name, uint16_t mode,
  181. qdf_dentry_t parent,
  182. qdf_atomic_t *value);
  183. /**
  184. * qdf_debugfs_create_string() - create a debugfs file for a string
  185. * @name: name of the file
  186. * @mode: qdf file mode
  187. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  188. * @str: a pointer to NULL terminated string (global/static).
  189. *
  190. * Return: dentry for the file; NULL in case of failure.
  191. *
  192. */
  193. qdf_dentry_t qdf_debugfs_create_string(const char *name, uint16_t mode,
  194. qdf_dentry_t parent, char *str);
  195. /**
  196. * qdf_debugfs_remove_dir_recursive() - remove directory recursively
  197. * @d: debugfs node
  198. *
  199. * This function will recursively removes a dreictory in debugfs that was
  200. * previously createed with a call to qdf_debugfs_create_file() or it's
  201. * variant functions.
  202. */
  203. void qdf_debugfs_remove_dir_recursive(qdf_dentry_t d);
  204. /**
  205. * qdf_debugfs_remove_dir() - remove debugfs directory
  206. * @d: debugfs node
  207. *
  208. */
  209. void qdf_debugfs_remove_dir(qdf_dentry_t d);
  210. /**
  211. * qdf_debugfs_remove_file() - remove debugfs file
  212. * @d: debugfs node
  213. *
  214. */
  215. void qdf_debugfs_remove_file(qdf_dentry_t d);
  216. /**
  217. * qdf_debugfs_create_file_simplified() - Create a simple debugfs file
  218. * where a single function call produces all the desired output
  219. * @name: name of the file
  220. * @mode: qdf file mode
  221. * @parent: parent node. If NULL, defaults to base 'qdf_debugfs_root'
  222. * @fops: file operations { .show, .write , .priv... }
  223. *
  224. * Users just have to define the show() function and pass it via @fops.show()
  225. * argument. When the output time comes, the show() will be called once.
  226. * The show() function must do everything that is needed to write the data,
  227. * all in one function call.
  228. * This is useful either for writing small amounts of data to debugfs or
  229. * for cases in which the output is not iterative.
  230. * The private data can be passed via @fops.priv, which will be available
  231. * inside the show() function as the 'private' filed of the qdf_debugfs_file_t.
  232. *
  233. * Return: dentry structure pointer in case of success, otherwise NULL.
  234. *
  235. */
  236. qdf_dentry_t qdf_debugfs_create_file_simplified(const char *name, uint16_t mode,
  237. qdf_dentry_t parent,
  238. struct qdf_debugfs_fops *fops);
  239. /**
  240. * qdf_debugfs_printer() - Print formatted string into debugfs file
  241. * @priv: The private data
  242. * @fmt: Format string
  243. * @...: arguments for the format string
  244. *
  245. * This function prints a new line character after printing the formatted
  246. * string into the debugfs file.
  247. * This function can be passed when the argument is of type qdf_abstract_print
  248. */
  249. int qdf_debugfs_printer(void *priv, const char *fmt, ...);
  250. /**
  251. * qdf_debugfs_create_blob() - create a debugfs file that is used to read
  252. * a binary blob
  253. * @name: a pointer to a string containing the name of the file to create.
  254. * @mode: the permission that the file should have
  255. * @parent: a pointer to the parent dentry for this file. This should be a
  256. * directory dentry if set. If this parameter is %NULL, then the
  257. * file will be created in the root of the debugfs filesystem.
  258. * @blob: a pointer to a qdf_debugfs_blob_wrap_t which contains a pointer
  259. * to the blob data and the size of the data.
  260. *
  261. * Return: dentry structure pointer on success, NULL otherwise.
  262. */
  263. qdf_dentry_t qdf_debugfs_create_blob(const char *name, umode_t mode,
  264. qdf_dentry_t parent,
  265. qdf_debugfs_blob_wrap_t blob);
  266. /**
  267. * qdf_debugfs_create_entry() - create a debugfs file for read or write
  268. * something
  269. * @name: name of the file
  270. * @mode: qdf file mode
  271. * @parent: parent node. If NULL, defaults to base qdf_debugfs_root
  272. * @data: Something data that caller want to read or write
  273. * @fops: file operations { .read, .write ... }
  274. *
  275. * Return: dentry structure pointer on success, NULL otherwise.
  276. */
  277. qdf_dentry_t qdf_debugfs_create_entry(const char *name, uint16_t mode,
  278. qdf_dentry_t parent,
  279. qdf_entry_t data,
  280. const qdf_file_ops_t fops);
  281. #else /* WLAN_DEBUGFS */
  282. static inline QDF_STATUS qdf_debugfs_init(void)
  283. {
  284. return QDF_STATUS_SUCCESS;
  285. }
  286. static inline void qdf_debugfs_exit(void) { }
  287. static inline qdf_dentry_t qdf_debugfs_create_dir(const char *name,
  288. qdf_dentry_t parent)
  289. {
  290. return NULL;
  291. }
  292. static inline qdf_dentry_t
  293. qdf_debugfs_create_file(const char *name, uint16_t mode, qdf_dentry_t parent,
  294. struct qdf_debugfs_fops *fops)
  295. {
  296. return NULL;
  297. }
  298. static inline void qdf_debugfs_printf(qdf_debugfs_file_t file, const char *f,
  299. ...)
  300. {
  301. }
  302. static inline void qdf_debugfs_hexdump(qdf_debugfs_file_t file,
  303. const uint8_t *buf, qdf_size_t len,
  304. int rowsize, int groupsize)
  305. {
  306. }
  307. static inline bool qdf_debugfs_overflow(qdf_debugfs_file_t file)
  308. {
  309. return 0;
  310. }
  311. static inline void qdf_debugfs_write(qdf_debugfs_file_t file,
  312. const uint8_t *buf, qdf_size_t len)
  313. {
  314. }
  315. static inline void qdf_debugfs_create_u8(const char *name,
  316. uint16_t mode,
  317. qdf_dentry_t parent, u8 *value)
  318. {
  319. }
  320. static inline void qdf_debugfs_create_u16(const char *name,
  321. uint16_t mode,
  322. qdf_dentry_t parent,
  323. u16 *value)
  324. {
  325. }
  326. static inline void qdf_debugfs_create_u32(const char *name,
  327. uint16_t mode,
  328. qdf_dentry_t parent,
  329. u32 *value)
  330. {
  331. }
  332. static inline void qdf_debugfs_create_u64(const char *name,
  333. uint16_t mode,
  334. qdf_dentry_t parent,
  335. u64 *value)
  336. {
  337. }
  338. static inline void qdf_debugfs_create_atomic(const char *name,
  339. uint16_t mode,
  340. qdf_dentry_t parent,
  341. qdf_atomic_t *value)
  342. {
  343. }
  344. static inline qdf_dentry_t debugfs_create_string(const char *name,
  345. uint16_t mode,
  346. qdf_dentry_t parent, char *str)
  347. {
  348. return NULL;
  349. }
  350. static inline void qdf_debugfs_remove_dir_recursive(qdf_dentry_t d) {}
  351. static inline void qdf_debugfs_remove_dir(qdf_dentry_t d) {}
  352. static inline void qdf_debugfs_remove_file(qdf_dentry_t d) {}
  353. static inline
  354. qdf_dentry_t qdf_debugfs_create_file_simplified(const char *name, uint16_t mode,
  355. qdf_dentry_t parent,
  356. struct qdf_debugfs_fops *fops)
  357. {
  358. return NULL;
  359. }
  360. static inline
  361. int qdf_debugfs_printer(void *priv, const char *fmt, ...)
  362. {
  363. return 0;
  364. }
  365. static inline
  366. qdf_dentry_t qdf_debugfs_create_blob(const char *name, umode_t mode,
  367. qdf_dentry_t parent,
  368. qdf_debugfs_blob_wrap_t blob)
  369. {
  370. return NULL;
  371. }
  372. static inline
  373. qdf_dentry_t qdf_debugfs_create_entry(const char *name, uint16_t mode,
  374. qdf_dentry_t parent,
  375. qdf_entry_t data,
  376. const qdf_file_ops_t fops)
  377. {
  378. return NULL;
  379. }
  380. #endif /* WLAN_DEBUGFS */
  381. #endif /* _QDF_DEBUGFS_H */