1 /*
2  * This file is part of wl1271
3  *
4  * Copyright (C) 2009 Nokia Corporation
5  *
6  * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 
24 #ifndef __DEBUGFS_H__
25 #define __DEBUGFS_H__
26 
27 #include "wlcore.h"
28 
29 __printf(4, 5) int wl1271_format_buffer(char __user *userbuf, size_t count,
30 					loff_t *ppos, char *fmt, ...);
31 
32 int wl1271_debugfs_init(struct wl1271 *wl);
33 void wl1271_debugfs_exit(struct wl1271 *wl);
34 void wl1271_debugfs_reset(struct wl1271 *wl);
35 void wl1271_debugfs_update_stats(struct wl1271 *wl);
36 
37 #define DEBUGFS_FORMAT_BUFFER_SIZE 256
38 
39 #define DEBUGFS_READONLY_FILE(name, fmt, value...)			\
40 static ssize_t name## _read(struct file *file, char __user *userbuf,	\
41 			    size_t count, loff_t *ppos)			\
42 {									\
43 	struct wl1271 *wl = file->private_data;				\
44 	return wl1271_format_buffer(userbuf, count, ppos,		\
45 				    fmt "\n", ##value);			\
46 }									\
47 									\
48 static const struct file_operations name## _ops = {			\
49 	.read = name## _read,						\
50 	.open = simple_open,						\
51 	.llseek	= generic_file_llseek,					\
52 };
53 
54 #define DEBUGFS_ADD(name, parent)					\
55 	do {								\
56 		debugfs_create_file(#name, 0400, parent,		\
57 				    wl, &name## _ops);			\
58 	} while (0)
59 
60 
61 #define DEBUGFS_ADD_PREFIX(prefix, name, parent)			\
62 	do {								\
63 		debugfs_create_file(#name, 0400, parent,		\
64 				    wl, &prefix## _## name## _ops);	\
65 	} while (0)
66 
67 #define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type)		\
68 static ssize_t sub## _ ##name## _read(struct file *file,		\
69 				      char __user *userbuf,		\
70 				      size_t count, loff_t *ppos)	\
71 {									\
72 	struct wl1271 *wl = file->private_data;				\
73 	struct struct_type *stats = wl->stats.fw_stats;			\
74 									\
75 	wl1271_debugfs_update_stats(wl);				\
76 									\
77 	return wl1271_format_buffer(userbuf, count, ppos, fmt "\n",	\
78 				    stats->sub.name);			\
79 }									\
80 									\
81 static const struct file_operations sub## _ ##name## _ops = {		\
82 	.read = sub## _ ##name## _read,					\
83 	.open = simple_open,						\
84 	.llseek	= generic_file_llseek,					\
85 };
86 
87 #define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type)		\
88 static ssize_t sub## _ ##name## _read(struct file *file,		\
89 				      char __user *userbuf,		\
90 				      size_t count, loff_t *ppos)	\
91 {									\
92 	struct wl1271 *wl = file->private_data;				\
93 	struct struct_type *stats = wl->stats.fw_stats;			\
94 	char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = "";			\
95 	int res, i;							\
96 									\
97 	wl1271_debugfs_update_stats(wl);				\
98 									\
99 	for (i = 0; i < len; i++)					\
100 		res = snprintf(buf, sizeof(buf), "%s[%d] = %d\n",	\
101 			       buf, i, stats->sub.name[i]);		\
102 									\
103 	return wl1271_format_buffer(userbuf, count, ppos, "%s", buf);	\
104 }									\
105 									\
106 static const struct file_operations sub## _ ##name## _ops = {		\
107 	.read = sub## _ ##name## _read,					\
108 	.open = simple_open,						\
109 	.llseek	= generic_file_llseek,					\
110 };
111 
112 #define DEBUGFS_FWSTATS_ADD(sub, name)					\
113 	DEBUGFS_ADD(sub## _ ##name, stats)
114 
115 
116 #endif /* WL1271_DEBUGFS_H */
117