blob: e37f557de3f33e5178ccaeb9fdc0f01689b8fc29 [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 Berg2c8dccc2008-04-08 15:14:40 -040013#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070014#include "debugfs.h"
15
16int mac80211_open_file_generic(struct inode *inode, struct file *file)
17{
18 file->private_data = inode->i_private;
19 return 0;
20}
21
Jiri Bence9f207f2007-05-05 11:46:38 -070022#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
23static 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 \
34static const struct file_operations name## _ops = { \
35 .read = name## _read, \
36 .open = mac80211_open_file_generic, \
37};
38
39#define DEBUGFS_ADD(name) \
Johannes Bergbebb8a52008-04-04 23:33:37 +020040 local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \
Jiri Bence9f207f2007-05-05 11:46:38 -070041 local, &name## _ops);
42
43#define DEBUGFS_DEL(name) \
44 debugfs_remove(local->debugfs.name); \
45 local->debugfs.name = NULL;
46
47
Jiri Bence9f207f2007-05-05 11:46:38 -070048DEBUGFS_READONLY_FILE(frequency, 20, "%d",
Johannes Berg8318d782008-01-24 19:38:38 +010049 local->hw.conf.channel->center_freq);
Jiri Bence9f207f2007-05-05 11:46:38 -070050DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
51 local->rts_threshold);
52DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
53 local->fragmentation_threshold);
54DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
Johannes Berg9124b072008-10-14 19:17:54 +020055 local->hw.conf.short_frame_max_tx_count);
Jiri Bence9f207f2007-05-05 11:46:38 -070056DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
Johannes Berg9124b072008-10-14 19:17:54 +020057 local->hw.conf.long_frame_max_tx_count);
Jiri Bence9f207f2007-05-05 11:46:38 -070058DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
59 local->total_ps_buffered);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010060DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
Jiri Bence9f207f2007-05-05 11:46:38 -070061 local->wep_iv & 0xffffff);
Jiri Bence9f207f2007-05-05 11:46:38 -070062DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
63 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010064
65static ssize_t tsf_read(struct file *file, char __user *user_buf,
66 size_t count, loff_t *ppos)
67{
68 struct ieee80211_local *local = file->private_data;
69 u64 tsf = 0;
70 char buf[100];
71
72 if (local->ops->get_tsf)
73 tsf = local->ops->get_tsf(local_to_hw(local));
74
75 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
76
77 return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
78}
79
80static ssize_t tsf_write(struct file *file,
81 const char __user *user_buf,
82 size_t count, loff_t *ppos)
83{
84 struct ieee80211_local *local = file->private_data;
85 unsigned long long tsf;
86 char buf[100];
87 size_t len;
88
89 len = min(count, sizeof(buf) - 1);
90 if (copy_from_user(buf, user_buf, len))
91 return -EFAULT;
92 buf[len] = '\0';
93
94 if (strncmp(buf, "reset", 5) == 0) {
95 if (local->ops->reset_tsf) {
96 local->ops->reset_tsf(local_to_hw(local));
97 printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy));
98 }
99 } else {
100 tsf = simple_strtoul(buf, NULL, 0);
101 if (local->ops->set_tsf) {
102 local->ops->set_tsf(local_to_hw(local), tsf);
103 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
104 }
105 }
106
107 return count;
108}
109
110static const struct file_operations tsf_ops = {
111 .read = tsf_read,
112 .write = tsf_write,
113 .open = mac80211_open_file_generic
114};
Jiri Bence9f207f2007-05-05 11:46:38 -0700115
116/* statistics stuff */
117
Jiri Bence9f207f2007-05-05 11:46:38 -0700118#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
119 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
120
121static ssize_t format_devstat_counter(struct ieee80211_local *local,
122 char __user *userbuf,
123 size_t count, loff_t *ppos,
124 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
125 int buflen))
126{
127 struct ieee80211_low_level_stats stats;
128 char buf[20];
129 int res;
130
131 if (!local->ops->get_stats)
132 return -EOPNOTSUPP;
133
Johannes Berg75636522008-07-09 14:40:35 +0200134 rtnl_lock();
Jiri Bence9f207f2007-05-05 11:46:38 -0700135 res = local->ops->get_stats(local_to_hw(local), &stats);
136 rtnl_unlock();
137 if (!res)
138 res = printvalue(&stats, buf, sizeof(buf));
139 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
140}
141
142#define DEBUGFS_DEVSTATS_FILE(name) \
143static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
144 char *buf, int buflen) \
145{ \
146 return scnprintf(buf, buflen, "%u\n", stats->name); \
147} \
148static ssize_t stats_ ##name## _read(struct file *file, \
149 char __user *userbuf, \
150 size_t count, loff_t *ppos) \
151{ \
152 return format_devstat_counter(file->private_data, \
153 userbuf, \
154 count, \
155 ppos, \
156 print_devstats_##name); \
157} \
158 \
159static const struct file_operations stats_ ##name## _ops = { \
160 .read = stats_ ##name## _read, \
161 .open = mac80211_open_file_generic, \
162};
163
164#define DEBUGFS_STATS_ADD(name) \
Johannes Bergbebb8a52008-04-04 23:33:37 +0200165 local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
Jiri Bence9f207f2007-05-05 11:46:38 -0700166 local, &stats_ ##name## _ops);
167
168#define DEBUGFS_STATS_DEL(name) \
169 debugfs_remove(local->debugfs.stats.name); \
170 local->debugfs.stats.name = NULL;
171
172DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
173 local->dot11TransmittedFragmentCount);
174DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
175 local->dot11MulticastTransmittedFrameCount);
176DEBUGFS_STATS_FILE(failed_count, 20, "%u",
177 local->dot11FailedCount);
178DEBUGFS_STATS_FILE(retry_count, 20, "%u",
179 local->dot11RetryCount);
180DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
181 local->dot11MultipleRetryCount);
182DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
183 local->dot11FrameDuplicateCount);
184DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
185 local->dot11ReceivedFragmentCount);
186DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
187 local->dot11MulticastReceivedFrameCount);
188DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
189 local->dot11TransmittedFrameCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700190#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
191DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
192 local->tx_handlers_drop);
193DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
194 local->tx_handlers_queued);
195DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
196 local->tx_handlers_drop_unencrypted);
197DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
198 local->tx_handlers_drop_fragment);
199DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
200 local->tx_handlers_drop_wep);
201DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
202 local->tx_handlers_drop_not_assoc);
203DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
204 local->tx_handlers_drop_unauth_port);
205DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
206 local->rx_handlers_drop);
207DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
208 local->rx_handlers_queued);
209DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
210 local->rx_handlers_drop_nullfunc);
211DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
212 local->rx_handlers_drop_defrag);
213DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
214 local->rx_handlers_drop_short);
215DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
216 local->rx_handlers_drop_passive_scan);
217DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
218 local->tx_expand_skb_head);
219DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
220 local->tx_expand_skb_head_cloned);
221DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
222 local->rx_expand_skb_head);
223DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
224 local->rx_expand_skb_head2);
225DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
226 local->rx_handlers_fragments);
227DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
228 local->tx_status_drop);
229
Jiri Bence9f207f2007-05-05 11:46:38 -0700230#endif
231
232DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
233DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
234DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
235DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
236
237
238void debugfs_hw_add(struct ieee80211_local *local)
239{
240 struct dentry *phyd = local->hw.wiphy->debugfsdir;
241 struct dentry *statsd;
242
243 if (!phyd)
244 return;
245
246 local->debugfs.stations = debugfs_create_dir("stations", phyd);
247 local->debugfs.keys = debugfs_create_dir("keys", phyd);
248
Jiri Bence9f207f2007-05-05 11:46:38 -0700249 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700250 DEBUGFS_ADD(rts_threshold);
251 DEBUGFS_ADD(fragmentation_threshold);
252 DEBUGFS_ADD(short_retry_limit);
253 DEBUGFS_ADD(long_retry_limit);
254 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700255 DEBUGFS_ADD(wep_iv);
Alina Friedrichsenae54c982009-01-23 05:33:37 +0100256 DEBUGFS_ADD(tsf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700257
258 statsd = debugfs_create_dir("statistics", phyd);
259 local->debugfs.statistics = statsd;
260
261 /* if the dir failed, don't put all the other things into the root! */
262 if (!statsd)
263 return;
264
265 DEBUGFS_STATS_ADD(transmitted_fragment_count);
266 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
267 DEBUGFS_STATS_ADD(failed_count);
268 DEBUGFS_STATS_ADD(retry_count);
269 DEBUGFS_STATS_ADD(multiple_retry_count);
270 DEBUGFS_STATS_ADD(frame_duplicate_count);
271 DEBUGFS_STATS_ADD(received_fragment_count);
272 DEBUGFS_STATS_ADD(multicast_received_frame_count);
273 DEBUGFS_STATS_ADD(transmitted_frame_count);
Jiri Bence9f207f2007-05-05 11:46:38 -0700274#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
275 DEBUGFS_STATS_ADD(tx_handlers_drop);
276 DEBUGFS_STATS_ADD(tx_handlers_queued);
277 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
278 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
279 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
280 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
281 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
282 DEBUGFS_STATS_ADD(rx_handlers_drop);
283 DEBUGFS_STATS_ADD(rx_handlers_queued);
284 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
285 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
286 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
287 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
288 DEBUGFS_STATS_ADD(tx_expand_skb_head);
289 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
290 DEBUGFS_STATS_ADD(rx_expand_skb_head);
291 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
292 DEBUGFS_STATS_ADD(rx_handlers_fragments);
293 DEBUGFS_STATS_ADD(tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700294#endif
295 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
296 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
297 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
298 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
299}
300
301void debugfs_hw_del(struct ieee80211_local *local)
302{
Jiri Bence9f207f2007-05-05 11:46:38 -0700303 DEBUGFS_DEL(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700304 DEBUGFS_DEL(rts_threshold);
305 DEBUGFS_DEL(fragmentation_threshold);
306 DEBUGFS_DEL(short_retry_limit);
307 DEBUGFS_DEL(long_retry_limit);
308 DEBUGFS_DEL(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700309 DEBUGFS_DEL(wep_iv);
Alina Friedrichsenae54c982009-01-23 05:33:37 +0100310 DEBUGFS_DEL(tsf);
Jiri Bence9f207f2007-05-05 11:46:38 -0700311
312 DEBUGFS_STATS_DEL(transmitted_fragment_count);
313 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
314 DEBUGFS_STATS_DEL(failed_count);
315 DEBUGFS_STATS_DEL(retry_count);
316 DEBUGFS_STATS_DEL(multiple_retry_count);
317 DEBUGFS_STATS_DEL(frame_duplicate_count);
318 DEBUGFS_STATS_DEL(received_fragment_count);
319 DEBUGFS_STATS_DEL(multicast_received_frame_count);
320 DEBUGFS_STATS_DEL(transmitted_frame_count);
Jiri Bence9f207f2007-05-05 11:46:38 -0700321 DEBUGFS_STATS_DEL(num_scans);
322#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
323 DEBUGFS_STATS_DEL(tx_handlers_drop);
324 DEBUGFS_STATS_DEL(tx_handlers_queued);
325 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
326 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
327 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
328 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
329 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
330 DEBUGFS_STATS_DEL(rx_handlers_drop);
331 DEBUGFS_STATS_DEL(rx_handlers_queued);
332 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
333 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
334 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
335 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
336 DEBUGFS_STATS_DEL(tx_expand_skb_head);
337 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
338 DEBUGFS_STATS_DEL(rx_expand_skb_head);
339 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
340 DEBUGFS_STATS_DEL(rx_handlers_fragments);
341 DEBUGFS_STATS_DEL(tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700342#endif
343 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
344 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
345 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
346 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
347
348 debugfs_remove(local->debugfs.statistics);
349 local->debugfs.statistics = NULL;
350 debugfs_remove(local->debugfs.stations);
351 local->debugfs.stations = NULL;
352 debugfs_remove(local->debugfs.keys);
353 local->debugfs.keys = NULL;
354}