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" | |
24487981 | 13 | #include "driver-ops.h" |
2c8dccc7 | 14 | #include "rate.h" |
e9f207f0 JB |
15 | #include "debugfs.h" |
16 | ||
17 | int mac80211_open_file_generic(struct inode *inode, struct file *file) | |
18 | { | |
19 | file->private_data = inode->i_private; | |
20 | return 0; | |
21 | } | |
22 | ||
e9f207f0 JB |
23 | #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ |
24 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ | |
25 | size_t count, loff_t *ppos) \ | |
26 | { \ | |
27 | struct ieee80211_local *local = file->private_data; \ | |
28 | char buf[buflen]; \ | |
29 | int res; \ | |
30 | \ | |
31 | res = scnprintf(buf, buflen, fmt "\n", ##value); \ | |
32 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); \ | |
33 | } \ | |
34 | \ | |
35 | static const struct file_operations name## _ops = { \ | |
36 | .read = name## _read, \ | |
37 | .open = mac80211_open_file_generic, \ | |
38 | }; | |
39 | ||
40 | #define DEBUGFS_ADD(name) \ | |
bebb8a5e | 41 | local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \ |
e9f207f0 JB |
42 | local, &name## _ops); |
43 | ||
827b1fb4 JB |
44 | #define DEBUGFS_ADD_MODE(name, mode) \ |
45 | local->debugfs.name = debugfs_create_file(#name, mode, phyd, \ | |
46 | local, &name## _ops); | |
47 | ||
e9f207f0 JB |
48 | #define DEBUGFS_DEL(name) \ |
49 | debugfs_remove(local->debugfs.name); \ | |
50 | local->debugfs.name = NULL; | |
51 | ||
52 | ||
e9f207f0 | 53 | DEBUGFS_READONLY_FILE(frequency, 20, "%d", |
8318d78a | 54 | local->hw.conf.channel->center_freq); |
e9f207f0 | 55 | DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d", |
b9a5f8ca | 56 | local->hw.wiphy->rts_threshold); |
e9f207f0 | 57 | DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d", |
b9a5f8ca | 58 | local->hw.wiphy->frag_threshold); |
e9f207f0 | 59 | DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d", |
b9a5f8ca | 60 | local->hw.wiphy->retry_short); |
e9f207f0 | 61 | DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d", |
b9a5f8ca | 62 | local->hw.wiphy->retry_long); |
e9f207f0 JB |
63 | DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", |
64 | local->total_ps_buffered); | |
3b5d665b | 65 | DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x", |
e9f207f0 | 66 | local->wep_iv & 0xffffff); |
e9f207f0 JB |
67 | DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", |
68 | local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>"); | |
3b5d665b AF |
69 | |
70 | static ssize_t tsf_read(struct file *file, char __user *user_buf, | |
71 | size_t count, loff_t *ppos) | |
72 | { | |
73 | struct ieee80211_local *local = file->private_data; | |
24487981 | 74 | u64 tsf; |
3b5d665b AF |
75 | char buf[100]; |
76 | ||
24487981 | 77 | tsf = drv_get_tsf(local); |
3b5d665b AF |
78 | |
79 | snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf); | |
80 | ||
81 | return simple_read_from_buffer(user_buf, count, ppos, buf, 19); | |
82 | } | |
83 | ||
84 | static ssize_t tsf_write(struct file *file, | |
85 | const char __user *user_buf, | |
86 | size_t count, loff_t *ppos) | |
87 | { | |
88 | struct ieee80211_local *local = file->private_data; | |
89 | unsigned long long tsf; | |
90 | char buf[100]; | |
91 | size_t len; | |
92 | ||
93 | len = min(count, sizeof(buf) - 1); | |
94 | if (copy_from_user(buf, user_buf, len)) | |
95 | return -EFAULT; | |
96 | buf[len] = '\0'; | |
97 | ||
98 | if (strncmp(buf, "reset", 5) == 0) { | |
99 | if (local->ops->reset_tsf) { | |
24487981 | 100 | drv_reset_tsf(local); |
3b5d665b AF |
101 | printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy)); |
102 | } | |
103 | } else { | |
104 | tsf = simple_strtoul(buf, NULL, 0); | |
105 | if (local->ops->set_tsf) { | |
24487981 | 106 | drv_set_tsf(local, tsf); |
3b5d665b AF |
107 | printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf); |
108 | } | |
109 | } | |
110 | ||
111 | return count; | |
112 | } | |
113 | ||
114 | static const struct file_operations tsf_ops = { | |
115 | .read = tsf_read, | |
116 | .write = tsf_write, | |
117 | .open = mac80211_open_file_generic | |
118 | }; | |
e9f207f0 | 119 | |
827b1fb4 JB |
120 | static ssize_t reset_write(struct file *file, const char __user *user_buf, |
121 | size_t count, loff_t *ppos) | |
122 | { | |
123 | struct ieee80211_local *local = file->private_data; | |
124 | ||
125 | rtnl_lock(); | |
126 | __ieee80211_suspend(&local->hw); | |
127 | __ieee80211_resume(&local->hw); | |
128 | rtnl_unlock(); | |
129 | ||
130 | return count; | |
131 | } | |
132 | ||
133 | static const struct file_operations reset_ops = { | |
134 | .write = reset_write, | |
135 | .open = mac80211_open_file_generic, | |
136 | }; | |
137 | ||
e9f207f0 JB |
138 | /* statistics stuff */ |
139 | ||
e9f207f0 JB |
140 | #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \ |
141 | DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value) | |
142 | ||
143 | static ssize_t format_devstat_counter(struct ieee80211_local *local, | |
144 | char __user *userbuf, | |
145 | size_t count, loff_t *ppos, | |
146 | int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, | |
147 | int buflen)) | |
148 | { | |
149 | struct ieee80211_low_level_stats stats; | |
150 | char buf[20]; | |
151 | int res; | |
152 | ||
75636525 | 153 | rtnl_lock(); |
24487981 | 154 | res = drv_get_stats(local, &stats); |
e9f207f0 | 155 | rtnl_unlock(); |
24487981 JB |
156 | if (res) |
157 | return res; | |
158 | res = printvalue(&stats, buf, sizeof(buf)); | |
e9f207f0 JB |
159 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); |
160 | } | |
161 | ||
162 | #define DEBUGFS_DEVSTATS_FILE(name) \ | |
163 | static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ | |
164 | char *buf, int buflen) \ | |
165 | { \ | |
166 | return scnprintf(buf, buflen, "%u\n", stats->name); \ | |
167 | } \ | |
168 | static ssize_t stats_ ##name## _read(struct file *file, \ | |
169 | char __user *userbuf, \ | |
170 | size_t count, loff_t *ppos) \ | |
171 | { \ | |
172 | return format_devstat_counter(file->private_data, \ | |
173 | userbuf, \ | |
174 | count, \ | |
175 | ppos, \ | |
176 | print_devstats_##name); \ | |
177 | } \ | |
178 | \ | |
179 | static const struct file_operations stats_ ##name## _ops = { \ | |
180 | .read = stats_ ##name## _read, \ | |
181 | .open = mac80211_open_file_generic, \ | |
182 | }; | |
183 | ||
184 | #define DEBUGFS_STATS_ADD(name) \ | |
bebb8a5e | 185 | local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\ |
e9f207f0 JB |
186 | local, &stats_ ##name## _ops); |
187 | ||
188 | #define DEBUGFS_STATS_DEL(name) \ | |
189 | debugfs_remove(local->debugfs.stats.name); \ | |
190 | local->debugfs.stats.name = NULL; | |
191 | ||
192 | DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u", | |
193 | local->dot11TransmittedFragmentCount); | |
194 | DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u", | |
195 | local->dot11MulticastTransmittedFrameCount); | |
196 | DEBUGFS_STATS_FILE(failed_count, 20, "%u", | |
197 | local->dot11FailedCount); | |
198 | DEBUGFS_STATS_FILE(retry_count, 20, "%u", | |
199 | local->dot11RetryCount); | |
200 | DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u", | |
201 | local->dot11MultipleRetryCount); | |
202 | DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u", | |
203 | local->dot11FrameDuplicateCount); | |
204 | DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u", | |
205 | local->dot11ReceivedFragmentCount); | |
206 | DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u", | |
207 | local->dot11MulticastReceivedFrameCount); | |
208 | DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u", | |
209 | local->dot11TransmittedFrameCount); | |
e9f207f0 JB |
210 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS |
211 | DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u", | |
212 | local->tx_handlers_drop); | |
213 | DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u", | |
214 | local->tx_handlers_queued); | |
215 | DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u", | |
216 | local->tx_handlers_drop_unencrypted); | |
217 | DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u", | |
218 | local->tx_handlers_drop_fragment); | |
219 | DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u", | |
220 | local->tx_handlers_drop_wep); | |
221 | DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u", | |
222 | local->tx_handlers_drop_not_assoc); | |
223 | DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u", | |
224 | local->tx_handlers_drop_unauth_port); | |
225 | DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u", | |
226 | local->rx_handlers_drop); | |
227 | DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u", | |
228 | local->rx_handlers_queued); | |
229 | DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u", | |
230 | local->rx_handlers_drop_nullfunc); | |
231 | DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u", | |
232 | local->rx_handlers_drop_defrag); | |
233 | DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u", | |
234 | local->rx_handlers_drop_short); | |
235 | DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u", | |
236 | local->rx_handlers_drop_passive_scan); | |
237 | DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u", | |
238 | local->tx_expand_skb_head); | |
239 | DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u", | |
240 | local->tx_expand_skb_head_cloned); | |
241 | DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u", | |
242 | local->rx_expand_skb_head); | |
243 | DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u", | |
244 | local->rx_expand_skb_head2); | |
245 | DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u", | |
246 | local->rx_handlers_fragments); | |
247 | DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u", | |
248 | local->tx_status_drop); | |
249 | ||
e9f207f0 JB |
250 | #endif |
251 | ||
252 | DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); | |
253 | DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); | |
254 | DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); | |
255 | DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); | |
256 | ||
257 | ||
258 | void debugfs_hw_add(struct ieee80211_local *local) | |
259 | { | |
260 | struct dentry *phyd = local->hw.wiphy->debugfsdir; | |
261 | struct dentry *statsd; | |
262 | ||
263 | if (!phyd) | |
264 | return; | |
265 | ||
266 | local->debugfs.stations = debugfs_create_dir("stations", phyd); | |
267 | local->debugfs.keys = debugfs_create_dir("keys", phyd); | |
268 | ||
e9f207f0 | 269 | DEBUGFS_ADD(frequency); |
e9f207f0 JB |
270 | DEBUGFS_ADD(rts_threshold); |
271 | DEBUGFS_ADD(fragmentation_threshold); | |
272 | DEBUGFS_ADD(short_retry_limit); | |
273 | DEBUGFS_ADD(long_retry_limit); | |
274 | DEBUGFS_ADD(total_ps_buffered); | |
e9f207f0 | 275 | DEBUGFS_ADD(wep_iv); |
ae54c985 | 276 | DEBUGFS_ADD(tsf); |
827b1fb4 | 277 | DEBUGFS_ADD_MODE(reset, 0200); |
e9f207f0 JB |
278 | |
279 | statsd = debugfs_create_dir("statistics", phyd); | |
280 | local->debugfs.statistics = statsd; | |
281 | ||
282 | /* if the dir failed, don't put all the other things into the root! */ | |
283 | if (!statsd) | |
284 | return; | |
285 | ||
286 | DEBUGFS_STATS_ADD(transmitted_fragment_count); | |
287 | DEBUGFS_STATS_ADD(multicast_transmitted_frame_count); | |
288 | DEBUGFS_STATS_ADD(failed_count); | |
289 | DEBUGFS_STATS_ADD(retry_count); | |
290 | DEBUGFS_STATS_ADD(multiple_retry_count); | |
291 | DEBUGFS_STATS_ADD(frame_duplicate_count); | |
292 | DEBUGFS_STATS_ADD(received_fragment_count); | |
293 | DEBUGFS_STATS_ADD(multicast_received_frame_count); | |
294 | DEBUGFS_STATS_ADD(transmitted_frame_count); | |
e9f207f0 JB |
295 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS |
296 | DEBUGFS_STATS_ADD(tx_handlers_drop); | |
297 | DEBUGFS_STATS_ADD(tx_handlers_queued); | |
298 | DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted); | |
299 | DEBUGFS_STATS_ADD(tx_handlers_drop_fragment); | |
300 | DEBUGFS_STATS_ADD(tx_handlers_drop_wep); | |
301 | DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc); | |
302 | DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port); | |
303 | DEBUGFS_STATS_ADD(rx_handlers_drop); | |
304 | DEBUGFS_STATS_ADD(rx_handlers_queued); | |
305 | DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc); | |
306 | DEBUGFS_STATS_ADD(rx_handlers_drop_defrag); | |
307 | DEBUGFS_STATS_ADD(rx_handlers_drop_short); | |
308 | DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan); | |
309 | DEBUGFS_STATS_ADD(tx_expand_skb_head); | |
310 | DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned); | |
311 | DEBUGFS_STATS_ADD(rx_expand_skb_head); | |
312 | DEBUGFS_STATS_ADD(rx_expand_skb_head2); | |
313 | DEBUGFS_STATS_ADD(rx_handlers_fragments); | |
314 | DEBUGFS_STATS_ADD(tx_status_drop); | |
e9f207f0 JB |
315 | #endif |
316 | DEBUGFS_STATS_ADD(dot11ACKFailureCount); | |
317 | DEBUGFS_STATS_ADD(dot11RTSFailureCount); | |
318 | DEBUGFS_STATS_ADD(dot11FCSErrorCount); | |
319 | DEBUGFS_STATS_ADD(dot11RTSSuccessCount); | |
320 | } | |
321 | ||
322 | void debugfs_hw_del(struct ieee80211_local *local) | |
323 | { | |
e9f207f0 | 324 | DEBUGFS_DEL(frequency); |
e9f207f0 JB |
325 | DEBUGFS_DEL(rts_threshold); |
326 | DEBUGFS_DEL(fragmentation_threshold); | |
327 | DEBUGFS_DEL(short_retry_limit); | |
328 | DEBUGFS_DEL(long_retry_limit); | |
329 | DEBUGFS_DEL(total_ps_buffered); | |
e9f207f0 | 330 | DEBUGFS_DEL(wep_iv); |
ae54c985 | 331 | DEBUGFS_DEL(tsf); |
827b1fb4 | 332 | DEBUGFS_DEL(reset); |
e9f207f0 JB |
333 | |
334 | DEBUGFS_STATS_DEL(transmitted_fragment_count); | |
335 | DEBUGFS_STATS_DEL(multicast_transmitted_frame_count); | |
336 | DEBUGFS_STATS_DEL(failed_count); | |
337 | DEBUGFS_STATS_DEL(retry_count); | |
338 | DEBUGFS_STATS_DEL(multiple_retry_count); | |
339 | DEBUGFS_STATS_DEL(frame_duplicate_count); | |
340 | DEBUGFS_STATS_DEL(received_fragment_count); | |
341 | DEBUGFS_STATS_DEL(multicast_received_frame_count); | |
342 | DEBUGFS_STATS_DEL(transmitted_frame_count); | |
e9f207f0 JB |
343 | DEBUGFS_STATS_DEL(num_scans); |
344 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS | |
345 | DEBUGFS_STATS_DEL(tx_handlers_drop); | |
346 | DEBUGFS_STATS_DEL(tx_handlers_queued); | |
347 | DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted); | |
348 | DEBUGFS_STATS_DEL(tx_handlers_drop_fragment); | |
349 | DEBUGFS_STATS_DEL(tx_handlers_drop_wep); | |
350 | DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc); | |
351 | DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port); | |
352 | DEBUGFS_STATS_DEL(rx_handlers_drop); | |
353 | DEBUGFS_STATS_DEL(rx_handlers_queued); | |
354 | DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc); | |
355 | DEBUGFS_STATS_DEL(rx_handlers_drop_defrag); | |
356 | DEBUGFS_STATS_DEL(rx_handlers_drop_short); | |
357 | DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan); | |
358 | DEBUGFS_STATS_DEL(tx_expand_skb_head); | |
359 | DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned); | |
360 | DEBUGFS_STATS_DEL(rx_expand_skb_head); | |
361 | DEBUGFS_STATS_DEL(rx_expand_skb_head2); | |
362 | DEBUGFS_STATS_DEL(rx_handlers_fragments); | |
363 | DEBUGFS_STATS_DEL(tx_status_drop); | |
e9f207f0 JB |
364 | #endif |
365 | DEBUGFS_STATS_DEL(dot11ACKFailureCount); | |
366 | DEBUGFS_STATS_DEL(dot11RTSFailureCount); | |
367 | DEBUGFS_STATS_DEL(dot11FCSErrorCount); | |
368 | DEBUGFS_STATS_DEL(dot11RTSSuccessCount); | |
369 | ||
370 | debugfs_remove(local->debugfs.statistics); | |
371 | local->debugfs.statistics = NULL; | |
372 | debugfs_remove(local->debugfs.stations); | |
373 | local->debugfs.stations = NULL; | |
374 | debugfs_remove(local->debugfs.keys); | |
375 | local->debugfs.keys = NULL; | |
376 | } |