Commit | Line | Data |
---|---|---|
e9f207f0 JB |
1 | /* |
2 | * mac80211 debugfs for wireless PHYs | |
3 | * | |
4 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> | |
5 | * | |
6 | * GPLv2 | |
7 | * | |
8 | */ | |
9 | ||
10 | #include <linux/debugfs.h> | |
11 | #include <linux/rtnetlink.h> | |
12 | #include "ieee80211_i.h" | |
2c8dccc7 | 13 | #include "rate.h" |
e9f207f0 JB |
14 | #include "debugfs.h" |
15 | ||
16 | int mac80211_open_file_generic(struct inode *inode, struct file *file) | |
17 | { | |
18 | file->private_data = inode->i_private; | |
19 | return 0; | |
20 | } | |
21 | ||
e9f207f0 JB |
22 | #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ |
23 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ | |
24 | size_t count, loff_t *ppos) \ | |
25 | { \ | |
26 | struct ieee80211_local *local = file->private_data; \ | |
27 | char buf[buflen]; \ | |
28 | int res; \ | |
29 | \ | |
30 | res = scnprintf(buf, buflen, fmt "\n", ##value); \ | |
31 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ | |
32 | } \ | |
33 | \ | |
34 | static const struct file_operations name## _ops = { \ | |
35 | .read = name## _read, \ | |
36 | .open = mac80211_open_file_generic, \ | |
37 | }; | |
38 | ||
39 | #define DEBUGFS_ADD(name) \ | |
bebb8a5e | 40 | local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \ |
e9f207f0 JB |
41 | local, &name## _ops); |
42 | ||
43 | #define DEBUGFS_DEL(name) \ | |
44 | debugfs_remove(local->debugfs.name); \ | |
45 | local->debugfs.name = NULL; | |
46 | ||
47 | ||
e9f207f0 | 48 | DEBUGFS_READONLY_FILE(frequency, 20, "%d", |
8318d78a | 49 | local->hw.conf.channel->center_freq); |
e9f207f0 JB |
50 | DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d", |
51 | local->rts_threshold); | |
52 | DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d", | |
53 | local->fragmentation_threshold); | |
54 | DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d", | |
9124b077 | 55 | local->hw.conf.short_frame_max_tx_count); |
e9f207f0 | 56 | DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d", |
9124b077 | 57 | local->hw.conf.long_frame_max_tx_count); |
e9f207f0 JB |
58 | DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", |
59 | local->total_ps_buffered); | |
e9f207f0 JB |
60 | DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x", |
61 | local->wep_iv & 0xffffff); | |
e9f207f0 JB |
62 | DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", |
63 | local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>"); | |
ae54c985 AF |
64 | DEBUGFS_READONLY_FILE(tsf, 20, "%#018llx", |
65 | (unsigned long long) (local->ops->get_tsf ? local->ops->get_tsf(local_to_hw(local)) : 0)); | |
e9f207f0 JB |
66 | |
67 | /* statistics stuff */ | |
68 | ||
e9f207f0 JB |
69 | #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \ |
70 | DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value) | |
71 | ||
72 | static ssize_t format_devstat_counter(struct ieee80211_local *local, | |
73 | char __user *userbuf, | |
74 | size_t count, loff_t *ppos, | |
75 | int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, | |
76 | int buflen)) | |
77 | { | |
78 | struct ieee80211_low_level_stats stats; | |
79 | char buf[20]; | |
80 | int res; | |
81 | ||
82 | if (!local->ops->get_stats) | |
83 | return -EOPNOTSUPP; | |
84 | ||
75636525 | 85 | rtnl_lock(); |
e9f207f0 JB |
86 | res = local->ops->get_stats(local_to_hw(local), &stats); |
87 | rtnl_unlock(); | |
88 | if (!res) | |
89 | res = printvalue(&stats, buf, sizeof(buf)); | |
90 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | |
91 | } | |
92 | ||
93 | #define DEBUGFS_DEVSTATS_FILE(name) \ | |
94 | static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ | |
95 | char *buf, int buflen) \ | |
96 | { \ | |
97 | return scnprintf(buf, buflen, "%u\n", stats->name); \ | |
98 | } \ | |
99 | static ssize_t stats_ ##name## _read(struct file *file, \ | |
100 | char __user *userbuf, \ | |
101 | size_t count, loff_t *ppos) \ | |
102 | { \ | |
103 | return format_devstat_counter(file->private_data, \ | |
104 | userbuf, \ | |
105 | count, \ | |
106 | ppos, \ | |
107 | print_devstats_##name); \ | |
108 | } \ | |
109 | \ | |
110 | static const struct file_operations stats_ ##name## _ops = { \ | |
111 | .read = stats_ ##name## _read, \ | |
112 | .open = mac80211_open_file_generic, \ | |
113 | }; | |
114 | ||
115 | #define DEBUGFS_STATS_ADD(name) \ | |
bebb8a5e | 116 | local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\ |
e9f207f0 JB |
117 | local, &stats_ ##name## _ops); |
118 | ||
119 | #define DEBUGFS_STATS_DEL(name) \ | |
120 | debugfs_remove(local->debugfs.stats.name); \ | |
121 | local->debugfs.stats.name = NULL; | |
122 | ||
123 | DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u", | |
124 | local->dot11TransmittedFragmentCount); | |
125 | DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u", | |
126 | local->dot11MulticastTransmittedFrameCount); | |
127 | DEBUGFS_STATS_FILE(failed_count, 20, "%u", | |
128 | local->dot11FailedCount); | |
129 | DEBUGFS_STATS_FILE(retry_count, 20, "%u", | |
130 | local->dot11RetryCount); | |
131 | DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u", | |
132 | local->dot11MultipleRetryCount); | |
133 | DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u", | |
134 | local->dot11FrameDuplicateCount); | |
135 | DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u", | |
136 | local->dot11ReceivedFragmentCount); | |
137 | DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u", | |
138 | local->dot11MulticastReceivedFrameCount); | |
139 | DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u", | |
140 | local->dot11TransmittedFrameCount); | |
e9f207f0 JB |
141 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS |
142 | DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u", | |
143 | local->tx_handlers_drop); | |
144 | DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u", | |
145 | local->tx_handlers_queued); | |
146 | DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u", | |
147 | local->tx_handlers_drop_unencrypted); | |
148 | DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u", | |
149 | local->tx_handlers_drop_fragment); | |
150 | DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u", | |
151 | local->tx_handlers_drop_wep); | |
152 | DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u", | |
153 | local->tx_handlers_drop_not_assoc); | |
154 | DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u", | |
155 | local->tx_handlers_drop_unauth_port); | |
156 | DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u", | |
157 | local->rx_handlers_drop); | |
158 | DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u", | |
159 | local->rx_handlers_queued); | |
160 | DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u", | |
161 | local->rx_handlers_drop_nullfunc); | |
162 | DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u", | |
163 | local->rx_handlers_drop_defrag); | |
164 | DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u", | |
165 | local->rx_handlers_drop_short); | |
166 | DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u", | |
167 | local->rx_handlers_drop_passive_scan); | |
168 | DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u", | |
169 | local->tx_expand_skb_head); | |
170 | DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u", | |
171 | local->tx_expand_skb_head_cloned); | |
172 | DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u", | |
173 | local->rx_expand_skb_head); | |
174 | DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u", | |
175 | local->rx_expand_skb_head2); | |
176 | DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u", | |
177 | local->rx_handlers_fragments); | |
178 | DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u", | |
179 | local->tx_status_drop); | |
180 | ||
e9f207f0 JB |
181 | #endif |
182 | ||
183 | DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); | |
184 | DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); | |
185 | DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); | |
186 | DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); | |
187 | ||
188 | ||
189 | void debugfs_hw_add(struct ieee80211_local *local) | |
190 | { | |
191 | struct dentry *phyd = local->hw.wiphy->debugfsdir; | |
192 | struct dentry *statsd; | |
193 | ||
194 | if (!phyd) | |
195 | return; | |
196 | ||
197 | local->debugfs.stations = debugfs_create_dir("stations", phyd); | |
198 | local->debugfs.keys = debugfs_create_dir("keys", phyd); | |
199 | ||
e9f207f0 | 200 | DEBUGFS_ADD(frequency); |
e9f207f0 JB |
201 | DEBUGFS_ADD(rts_threshold); |
202 | DEBUGFS_ADD(fragmentation_threshold); | |
203 | DEBUGFS_ADD(short_retry_limit); | |
204 | DEBUGFS_ADD(long_retry_limit); | |
205 | DEBUGFS_ADD(total_ps_buffered); | |
e9f207f0 | 206 | DEBUGFS_ADD(wep_iv); |
ae54c985 | 207 | DEBUGFS_ADD(tsf); |
e9f207f0 JB |
208 | |
209 | statsd = debugfs_create_dir("statistics", phyd); | |
210 | local->debugfs.statistics = statsd; | |
211 | ||
212 | /* if the dir failed, don't put all the other things into the root! */ | |
213 | if (!statsd) | |
214 | return; | |
215 | ||
216 | DEBUGFS_STATS_ADD(transmitted_fragment_count); | |
217 | DEBUGFS_STATS_ADD(multicast_transmitted_frame_count); | |
218 | DEBUGFS_STATS_ADD(failed_count); | |
219 | DEBUGFS_STATS_ADD(retry_count); | |
220 | DEBUGFS_STATS_ADD(multiple_retry_count); | |
221 | DEBUGFS_STATS_ADD(frame_duplicate_count); | |
222 | DEBUGFS_STATS_ADD(received_fragment_count); | |
223 | DEBUGFS_STATS_ADD(multicast_received_frame_count); | |
224 | DEBUGFS_STATS_ADD(transmitted_frame_count); | |
e9f207f0 JB |
225 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS |
226 | DEBUGFS_STATS_ADD(tx_handlers_drop); | |
227 | DEBUGFS_STATS_ADD(tx_handlers_queued); | |
228 | DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted); | |
229 | DEBUGFS_STATS_ADD(tx_handlers_drop_fragment); | |
230 | DEBUGFS_STATS_ADD(tx_handlers_drop_wep); | |
231 | DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc); | |
232 | DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port); | |
233 | DEBUGFS_STATS_ADD(rx_handlers_drop); | |
234 | DEBUGFS_STATS_ADD(rx_handlers_queued); | |
235 | DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc); | |
236 | DEBUGFS_STATS_ADD(rx_handlers_drop_defrag); | |
237 | DEBUGFS_STATS_ADD(rx_handlers_drop_short); | |
238 | DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan); | |
239 | DEBUGFS_STATS_ADD(tx_expand_skb_head); | |
240 | DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned); | |
241 | DEBUGFS_STATS_ADD(rx_expand_skb_head); | |
242 | DEBUGFS_STATS_ADD(rx_expand_skb_head2); | |
243 | DEBUGFS_STATS_ADD(rx_handlers_fragments); | |
244 | DEBUGFS_STATS_ADD(tx_status_drop); | |
e9f207f0 JB |
245 | #endif |
246 | DEBUGFS_STATS_ADD(dot11ACKFailureCount); | |
247 | DEBUGFS_STATS_ADD(dot11RTSFailureCount); | |
248 | DEBUGFS_STATS_ADD(dot11FCSErrorCount); | |
249 | DEBUGFS_STATS_ADD(dot11RTSSuccessCount); | |
250 | } | |
251 | ||
252 | void debugfs_hw_del(struct ieee80211_local *local) | |
253 | { | |
e9f207f0 | 254 | DEBUGFS_DEL(frequency); |
e9f207f0 JB |
255 | DEBUGFS_DEL(rts_threshold); |
256 | DEBUGFS_DEL(fragmentation_threshold); | |
257 | DEBUGFS_DEL(short_retry_limit); | |
258 | DEBUGFS_DEL(long_retry_limit); | |
259 | DEBUGFS_DEL(total_ps_buffered); | |
e9f207f0 | 260 | DEBUGFS_DEL(wep_iv); |
ae54c985 | 261 | DEBUGFS_DEL(tsf); |
e9f207f0 JB |
262 | |
263 | DEBUGFS_STATS_DEL(transmitted_fragment_count); | |
264 | DEBUGFS_STATS_DEL(multicast_transmitted_frame_count); | |
265 | DEBUGFS_STATS_DEL(failed_count); | |
266 | DEBUGFS_STATS_DEL(retry_count); | |
267 | DEBUGFS_STATS_DEL(multiple_retry_count); | |
268 | DEBUGFS_STATS_DEL(frame_duplicate_count); | |
269 | DEBUGFS_STATS_DEL(received_fragment_count); | |
270 | DEBUGFS_STATS_DEL(multicast_received_frame_count); | |
271 | DEBUGFS_STATS_DEL(transmitted_frame_count); | |
e9f207f0 JB |
272 | DEBUGFS_STATS_DEL(num_scans); |
273 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS | |
274 | DEBUGFS_STATS_DEL(tx_handlers_drop); | |
275 | DEBUGFS_STATS_DEL(tx_handlers_queued); | |
276 | DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted); | |
277 | DEBUGFS_STATS_DEL(tx_handlers_drop_fragment); | |
278 | DEBUGFS_STATS_DEL(tx_handlers_drop_wep); | |
279 | DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc); | |
280 | DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port); | |
281 | DEBUGFS_STATS_DEL(rx_handlers_drop); | |
282 | DEBUGFS_STATS_DEL(rx_handlers_queued); | |
283 | DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc); | |
284 | DEBUGFS_STATS_DEL(rx_handlers_drop_defrag); | |
285 | DEBUGFS_STATS_DEL(rx_handlers_drop_short); | |
286 | DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan); | |
287 | DEBUGFS_STATS_DEL(tx_expand_skb_head); | |
288 | DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned); | |
289 | DEBUGFS_STATS_DEL(rx_expand_skb_head); | |
290 | DEBUGFS_STATS_DEL(rx_expand_skb_head2); | |
291 | DEBUGFS_STATS_DEL(rx_handlers_fragments); | |
292 | DEBUGFS_STATS_DEL(tx_status_drop); | |
e9f207f0 JB |
293 | #endif |
294 | DEBUGFS_STATS_DEL(dot11ACKFailureCount); | |
295 | DEBUGFS_STATS_DEL(dot11RTSFailureCount); | |
296 | DEBUGFS_STATS_DEL(dot11FCSErrorCount); | |
297 | DEBUGFS_STATS_DEL(dot11RTSSuccessCount); | |
298 | ||
299 | debugfs_remove(local->debugfs.statistics); | |
300 | local->debugfs.statistics = NULL; | |
301 | debugfs_remove(local->debugfs.stations); | |
302 | local->debugfs.stations = NULL; | |
303 | debugfs_remove(local->debugfs.keys); | |
304 | local->debugfs.keys = NULL; | |
305 | } |