Commit | Line | Data |
---|---|---|
f5fc0f86 LC |
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 | ||
00d20100 SL |
24 | #ifndef __DEBUGFS_H__ |
25 | #define __DEBUGFS_H__ | |
f5fc0f86 | 26 | |
c31be25a | 27 | #include "wlcore.h" |
f5fc0f86 | 28 | |
a3fa71c4 NI |
29 | __printf(4, 5) int wl1271_format_buffer(char __user *userbuf, size_t count, |
30 | loff_t *ppos, char *fmt, ...); | |
4987257c | 31 | |
f5fc0f86 LC |
32 | int wl1271_debugfs_init(struct wl1271 *wl); |
33 | void wl1271_debugfs_exit(struct wl1271 *wl); | |
34 | void wl1271_debugfs_reset(struct wl1271 *wl); | |
4987257c LC |
35 | void wl1271_debugfs_update_stats(struct wl1271 *wl); |
36 | ||
bcca1bbd LC |
37 | #define DEBUGFS_FORMAT_BUFFER_SIZE 256 |
38 | ||
4987257c LC |
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 | entry = debugfs_create_file(#name, 0400, parent, \ | |
57 | wl, &name## _ops); \ | |
58 | if (!entry || IS_ERR(entry)) \ | |
59 | goto err; \ | |
f8b8a47e | 60 | } while (0) |
4987257c LC |
61 | |
62 | ||
63 | #define DEBUGFS_ADD_PREFIX(prefix, name, parent) \ | |
64 | do { \ | |
65 | entry = debugfs_create_file(#name, 0400, parent, \ | |
66 | wl, &prefix## _## name## _ops); \ | |
67 | if (!entry || IS_ERR(entry)) \ | |
68 | goto err; \ | |
f8b8a47e | 69 | } while (0) |
4987257c LC |
70 | |
71 | #define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type) \ | |
72 | static ssize_t sub## _ ##name## _read(struct file *file, \ | |
73 | char __user *userbuf, \ | |
74 | size_t count, loff_t *ppos) \ | |
75 | { \ | |
76 | struct wl1271 *wl = file->private_data; \ | |
77 | struct struct_type *stats = wl->stats.fw_stats; \ | |
78 | \ | |
79 | wl1271_debugfs_update_stats(wl); \ | |
80 | \ | |
81 | return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \ | |
82 | stats->sub.name); \ | |
83 | } \ | |
84 | \ | |
85 | static const struct file_operations sub## _ ##name## _ops = { \ | |
86 | .read = sub## _ ##name## _read, \ | |
87 | .open = simple_open, \ | |
88 | .llseek = generic_file_llseek, \ | |
89 | }; | |
90 | ||
bcca1bbd LC |
91 | #define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type) \ |
92 | static ssize_t sub## _ ##name## _read(struct file *file, \ | |
93 | char __user *userbuf, \ | |
94 | size_t count, loff_t *ppos) \ | |
95 | { \ | |
96 | struct wl1271 *wl = file->private_data; \ | |
97 | struct struct_type *stats = wl->stats.fw_stats; \ | |
98 | char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = ""; \ | |
99 | int res, i; \ | |
100 | \ | |
101 | wl1271_debugfs_update_stats(wl); \ | |
102 | \ | |
103 | for (i = 0; i < len; i++) \ | |
104 | res = snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \ | |
105 | buf, i, stats->sub.name[i]); \ | |
106 | \ | |
107 | return wl1271_format_buffer(userbuf, count, ppos, "%s", buf); \ | |
108 | } \ | |
109 | \ | |
110 | static const struct file_operations sub## _ ##name## _ops = { \ | |
111 | .read = sub## _ ##name## _read, \ | |
112 | .open = simple_open, \ | |
113 | .llseek = generic_file_llseek, \ | |
114 | }; | |
115 | ||
4987257c LC |
116 | #define DEBUGFS_FWSTATS_ADD(sub, name) \ |
117 | DEBUGFS_ADD(sub## _ ##name, stats) | |
118 | ||
f5fc0f86 LC |
119 | |
120 | #endif /* WL1271_DEBUGFS_H */ |