blob: e7682fe1c590fb68fa6d4e7a265848d3e747ca56 [file] [log] [blame]
Jiri Bence9f207f2007-05-05 11:46:38 -07001/*
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"
Johannes Berg24487982009-04-23 18:52:52 +020013#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040014#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070015#include "debugfs.h"
16
17int mac80211_open_file_generic(struct inode *inode, struct file *file)
18{
19 file->private_data = inode->i_private;
20 return 0;
21}
22
Jiri Bence9f207f2007-05-05 11:46:38 -070023#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
24static 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 \
35static const struct file_operations name## _ops = { \
36 .read = name## _read, \
37 .open = mac80211_open_file_generic, \
38};
39
40#define DEBUGFS_ADD(name) \
Johannes Bergbebb8a52008-04-04 23:33:37 +020041 local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \
Jiri Bence9f207f2007-05-05 11:46:38 -070042 local, &name## _ops);
43
Johannes Berg827b1fb2009-03-13 11:44:18 +010044#define DEBUGFS_ADD_MODE(name, mode) \
45 local->debugfs.name = debugfs_create_file(#name, mode, phyd, \
46 local, &name## _ops);
47
Jiri Bence9f207f2007-05-05 11:46:38 -070048#define DEBUGFS_DEL(name) \
49 debugfs_remove(local->debugfs.name); \
50 local->debugfs.name = NULL;
51
52
Jiri Bence9f207f2007-05-05 11:46:38 -070053DEBUGFS_READONLY_FILE(frequency, 20, "%d",
Johannes Berg8318d782008-01-24 19:38:38 +010054 local->hw.conf.channel->center_freq);
Jiri Bence9f207f2007-05-05 11:46:38 -070055DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020056 local->hw.wiphy->rts_threshold);
Jiri Bence9f207f2007-05-05 11:46:38 -070057DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020058 local->hw.wiphy->frag_threshold);
Jiri Bence9f207f2007-05-05 11:46:38 -070059DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020060 local->hw.wiphy->retry_short);
Jiri Bence9f207f2007-05-05 11:46:38 -070061DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020062 local->hw.wiphy->retry_long);
Jiri Bence9f207f2007-05-05 11:46:38 -070063DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
64 local->total_ps_buffered);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010065DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
Jiri Bence9f207f2007-05-05 11:46:38 -070066 local->wep_iv & 0xffffff);
Jiri Bence9f207f2007-05-05 11:46:38 -070067DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
68 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010069
70static 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;
Johannes Berg24487982009-04-23 18:52:52 +020074 u64 tsf;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010075 char buf[100];
76
Johannes Berg24487982009-04-23 18:52:52 +020077 tsf = drv_get_tsf(local);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010078
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
84static 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) {
Johannes Berg24487982009-04-23 18:52:52 +0200100 drv_reset_tsf(local);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +0100101 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) {
Johannes Berg24487982009-04-23 18:52:52 +0200106 drv_set_tsf(local, tsf);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +0100107 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
108 }
109 }
110
111 return count;
112}
113
114static const struct file_operations tsf_ops = {
115 .read = tsf_read,
116 .write = tsf_write,
117 .open = mac80211_open_file_generic
118};
Jiri Bence9f207f2007-05-05 11:46:38 -0700119
Johannes Berg827b1fb2009-03-13 11:44:18 +0100120static 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
133static const struct file_operations reset_ops = {
134 .write = reset_write,
135 .open = mac80211_open_file_generic,
136};
137
Johannes Bergd3707d92009-05-12 22:05:40 +0200138static ssize_t noack_read(struct file *file, char __user *user_buf,
139 size_t count, loff_t *ppos)
140{
141 struct ieee80211_local *local = file->private_data;
142 int res;
143 char buf[10];
144
145 res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
146
147 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
148}
149
150static ssize_t noack_write(struct file *file,
151 const char __user *user_buf,
152 size_t count, loff_t *ppos)
153{
154 struct ieee80211_local *local = file->private_data;
155 char buf[10];
156 size_t len;
157
158 len = min(count, sizeof(buf) - 1);
159 if (copy_from_user(buf, user_buf, len))
160 return -EFAULT;
161 buf[len] = '\0';
162
163 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
164
165 return count;
166}
167
168static const struct file_operations noack_ops = {
169 .read = noack_read,
170 .write = noack_write,
171 .open = mac80211_open_file_generic
172};
173
Jiri Bence9f207f2007-05-05 11:46:38 -0700174/* statistics stuff */
175
Jiri Bence9f207f2007-05-05 11:46:38 -0700176#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
177 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
178
179static ssize_t format_devstat_counter(struct ieee80211_local *local,
180 char __user *userbuf,
181 size_t count, loff_t *ppos,
182 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
183 int buflen))
184{
185 struct ieee80211_low_level_stats stats;
186 char buf[20];
187 int res;
188
Johannes Berg75636522008-07-09 14:40:35 +0200189 rtnl_lock();
Johannes Berg24487982009-04-23 18:52:52 +0200190 res = drv_get_stats(local, &stats);
Jiri Bence9f207f2007-05-05 11:46:38 -0700191 rtnl_unlock();
Johannes Berg24487982009-04-23 18:52:52 +0200192 if (res)
193 return res;
194 res = printvalue(&stats, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700195 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
196}
197
198#define DEBUGFS_DEVSTATS_FILE(name) \
199static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
200 char *buf, int buflen) \
201{ \
202 return scnprintf(buf, buflen, "%u\n", stats->name); \
203} \
204static ssize_t stats_ ##name## _read(struct file *file, \
205 char __user *userbuf, \
206 size_t count, loff_t *ppos) \
207{ \
208 return format_devstat_counter(file->private_data, \
209 userbuf, \
210 count, \
211 ppos, \
212 print_devstats_##name); \
213} \
214 \
215static const struct file_operations stats_ ##name## _ops = { \
216 .read = stats_ ##name## _read, \
217 .open = mac80211_open_file_generic, \
218};
219
220#define DEBUGFS_STATS_ADD(name) \
Johannes Bergbebb8a52008-04-04 23:33:37 +0200221 local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
Jiri Bence9f207f2007-05-05 11:46:38 -0700222 local, &stats_ ##name## _ops);
223
224#define DEBUGFS_STATS_DEL(name) \
225 debugfs_remove(local->debugfs.stats.name); \
226 local->debugfs.stats.name = NULL;
227
228DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
229 local->dot11TransmittedFragmentCount);
230DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
231 local->dot11MulticastTransmittedFrameCount);
232DEBUGFS_STATS_FILE(failed_count, 20, "%u",
233 local->dot11FailedCount);
234DEBUGFS_STATS_FILE(retry_count, 20, "%u",
235 local->dot11RetryCount);
236DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
237 local->dot11MultipleRetryCount);
238DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
239 local->dot11FrameDuplicateCount);
240DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
241 local->dot11ReceivedFragmentCount);
242DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
243 local->dot11MulticastReceivedFrameCount);
244DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
245 local->dot11TransmittedFrameCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700246#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
247DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
248 local->tx_handlers_drop);
249DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
250 local->tx_handlers_queued);
251DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
252 local->tx_handlers_drop_unencrypted);
253DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
254 local->tx_handlers_drop_fragment);
255DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
256 local->tx_handlers_drop_wep);
257DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
258 local->tx_handlers_drop_not_assoc);
259DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
260 local->tx_handlers_drop_unauth_port);
261DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
262 local->rx_handlers_drop);
263DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
264 local->rx_handlers_queued);
265DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
266 local->rx_handlers_drop_nullfunc);
267DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
268 local->rx_handlers_drop_defrag);
269DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
270 local->rx_handlers_drop_short);
271DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
272 local->rx_handlers_drop_passive_scan);
273DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
274 local->tx_expand_skb_head);
275DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
276 local->tx_expand_skb_head_cloned);
277DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
278 local->rx_expand_skb_head);
279DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
280 local->rx_expand_skb_head2);
281DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
282 local->rx_handlers_fragments);
283DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
284 local->tx_status_drop);
285
Jiri Bence9f207f2007-05-05 11:46:38 -0700286#endif
287
288DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
289DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
290DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
291DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
292
293
294void debugfs_hw_add(struct ieee80211_local *local)
295{
296 struct dentry *phyd = local->hw.wiphy->debugfsdir;
297 struct dentry *statsd;
298
299 if (!phyd)
300 return;
301
302 local->debugfs.stations = debugfs_create_dir("stations", phyd);
303 local->debugfs.keys = debugfs_create_dir("keys", phyd);
304
Jiri Bence9f207f2007-05-05 11:46:38 -0700305 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700306 DEBUGFS_ADD(rts_threshold);
307 DEBUGFS_ADD(fragmentation_threshold);
308 DEBUGFS_ADD(short_retry_limit);
309 DEBUGFS_ADD(long_retry_limit);
310 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700311 DEBUGFS_ADD(wep_iv);
Alina Friedrichsenae54c982009-01-23 05:33:37 +0100312 DEBUGFS_ADD(tsf);
Johannes Berg827b1fb2009-03-13 11:44:18 +0100313 DEBUGFS_ADD_MODE(reset, 0200);
Johannes Bergd3707d92009-05-12 22:05:40 +0200314 DEBUGFS_ADD(noack);
Jiri Bence9f207f2007-05-05 11:46:38 -0700315
316 statsd = debugfs_create_dir("statistics", phyd);
317 local->debugfs.statistics = statsd;
318
319 /* if the dir failed, don't put all the other things into the root! */
320 if (!statsd)
321 return;
322
323 DEBUGFS_STATS_ADD(transmitted_fragment_count);
324 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
325 DEBUGFS_STATS_ADD(failed_count);
326 DEBUGFS_STATS_ADD(retry_count);
327 DEBUGFS_STATS_ADD(multiple_retry_count);
328 DEBUGFS_STATS_ADD(frame_duplicate_count);
329 DEBUGFS_STATS_ADD(received_fragment_count);
330 DEBUGFS_STATS_ADD(multicast_received_frame_count);
331 DEBUGFS_STATS_ADD(transmitted_frame_count);
Jiri Bence9f207f2007-05-05 11:46:38 -0700332#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
333 DEBUGFS_STATS_ADD(tx_handlers_drop);
334 DEBUGFS_STATS_ADD(tx_handlers_queued);
335 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
336 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
337 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
338 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
339 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
340 DEBUGFS_STATS_ADD(rx_handlers_drop);
341 DEBUGFS_STATS_ADD(rx_handlers_queued);
342 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
343 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
344 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
345 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
346 DEBUGFS_STATS_ADD(tx_expand_skb_head);
347 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
348 DEBUGFS_STATS_ADD(rx_expand_skb_head);
349 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
350 DEBUGFS_STATS_ADD(rx_handlers_fragments);
351 DEBUGFS_STATS_ADD(tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700352#endif
353 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
354 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
355 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
356 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
357}
358
359void debugfs_hw_del(struct ieee80211_local *local)
360{
Jiri Bence9f207f2007-05-05 11:46:38 -0700361 DEBUGFS_DEL(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700362 DEBUGFS_DEL(rts_threshold);
363 DEBUGFS_DEL(fragmentation_threshold);
364 DEBUGFS_DEL(short_retry_limit);
365 DEBUGFS_DEL(long_retry_limit);
366 DEBUGFS_DEL(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700367 DEBUGFS_DEL(wep_iv);
Alina Friedrichsenae54c982009-01-23 05:33:37 +0100368 DEBUGFS_DEL(tsf);
Johannes Berg827b1fb2009-03-13 11:44:18 +0100369 DEBUGFS_DEL(reset);
Johannes Bergd3707d92009-05-12 22:05:40 +0200370 DEBUGFS_DEL(noack);
Jiri Bence9f207f2007-05-05 11:46:38 -0700371
372 DEBUGFS_STATS_DEL(transmitted_fragment_count);
373 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
374 DEBUGFS_STATS_DEL(failed_count);
375 DEBUGFS_STATS_DEL(retry_count);
376 DEBUGFS_STATS_DEL(multiple_retry_count);
377 DEBUGFS_STATS_DEL(frame_duplicate_count);
378 DEBUGFS_STATS_DEL(received_fragment_count);
379 DEBUGFS_STATS_DEL(multicast_received_frame_count);
380 DEBUGFS_STATS_DEL(transmitted_frame_count);
Jiri Bence9f207f2007-05-05 11:46:38 -0700381 DEBUGFS_STATS_DEL(num_scans);
382#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
383 DEBUGFS_STATS_DEL(tx_handlers_drop);
384 DEBUGFS_STATS_DEL(tx_handlers_queued);
385 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
386 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
387 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
388 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
389 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
390 DEBUGFS_STATS_DEL(rx_handlers_drop);
391 DEBUGFS_STATS_DEL(rx_handlers_queued);
392 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
393 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
394 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
395 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
396 DEBUGFS_STATS_DEL(tx_expand_skb_head);
397 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
398 DEBUGFS_STATS_DEL(rx_expand_skb_head);
399 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
400 DEBUGFS_STATS_DEL(rx_handlers_fragments);
401 DEBUGFS_STATS_DEL(tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700402#endif
403 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
404 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
405 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
406 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
407
408 debugfs_remove(local->debugfs.statistics);
409 local->debugfs.statistics = NULL;
410 debugfs_remove(local->debugfs.stations);
411 local->debugfs.stations = NULL;
412 debugfs_remove(local->debugfs.keys);
413 local->debugfs.keys = NULL;
414}