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