mac80211: Generic TSF debugging
[safe/jmp/linux-2.6] / net / mac80211 / debugfs.c
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"
13 #include "rate.h"
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
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)                                               \
40         local->debugfs.name = debugfs_create_file(#name, 0400, phyd,    \
41                                                   local, &name## _ops);
42
43 #define DEBUGFS_DEL(name)                                               \
44         debugfs_remove(local->debugfs.name);                            \
45         local->debugfs.name = NULL;
46
47
48 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
49                       local->hw.conf.channel->center_freq);
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",
55                       local->hw.conf.short_frame_max_tx_count);
56 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
57                       local->hw.conf.long_frame_max_tx_count);
58 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
59                       local->total_ps_buffered);
60 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
61                       local->wep_iv & 0xffffff);
62 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
63                       local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
64
65 static 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
80 static 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
110 static const struct file_operations tsf_ops = {
111         .read = tsf_read,
112         .write = tsf_write,
113         .open = mac80211_open_file_generic
114 };
115
116 /* statistics stuff */
117
118 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...)                 \
119         DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
120
121 static 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
134         rtnl_lock();
135         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)                                     \
143 static 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 }                                                                       \
148 static 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                                                                         \
159 static 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)                                         \
165         local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
166                 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
172 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
173                    local->dot11TransmittedFragmentCount);
174 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
175                    local->dot11MulticastTransmittedFrameCount);
176 DEBUGFS_STATS_FILE(failed_count, 20, "%u",
177                    local->dot11FailedCount);
178 DEBUGFS_STATS_FILE(retry_count, 20, "%u",
179                    local->dot11RetryCount);
180 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
181                    local->dot11MultipleRetryCount);
182 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
183                    local->dot11FrameDuplicateCount);
184 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
185                    local->dot11ReceivedFragmentCount);
186 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
187                    local->dot11MulticastReceivedFrameCount);
188 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
189                    local->dot11TransmittedFrameCount);
190 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
191 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
192                    local->tx_handlers_drop);
193 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
194                    local->tx_handlers_queued);
195 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
196                    local->tx_handlers_drop_unencrypted);
197 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
198                    local->tx_handlers_drop_fragment);
199 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
200                    local->tx_handlers_drop_wep);
201 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
202                    local->tx_handlers_drop_not_assoc);
203 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
204                    local->tx_handlers_drop_unauth_port);
205 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
206                    local->rx_handlers_drop);
207 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
208                    local->rx_handlers_queued);
209 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
210                    local->rx_handlers_drop_nullfunc);
211 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
212                    local->rx_handlers_drop_defrag);
213 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
214                    local->rx_handlers_drop_short);
215 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
216                    local->rx_handlers_drop_passive_scan);
217 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
218                    local->tx_expand_skb_head);
219 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
220                    local->tx_expand_skb_head_cloned);
221 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
222                    local->rx_expand_skb_head);
223 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
224                    local->rx_expand_skb_head2);
225 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
226                    local->rx_handlers_fragments);
227 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
228                    local->tx_status_drop);
229
230 #endif
231
232 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
233 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
234 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
235 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
236
237
238 void 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
249         DEBUGFS_ADD(frequency);
250         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);
255         DEBUGFS_ADD(wep_iv);
256         DEBUGFS_ADD(tsf);
257
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);
274 #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);
294 #endif
295         DEBUGFS_STATS_ADD(dot11ACKFailureCount);
296         DEBUGFS_STATS_ADD(dot11RTSFailureCount);
297         DEBUGFS_STATS_ADD(dot11FCSErrorCount);
298         DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
299 }
300
301 void debugfs_hw_del(struct ieee80211_local *local)
302 {
303         DEBUGFS_DEL(frequency);
304         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);
309         DEBUGFS_DEL(wep_iv);
310         DEBUGFS_DEL(tsf);
311
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);
321         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);
342 #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 }