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