mac80211: QoS related cleanups
[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(antenna_sel_tx, 20, "%d",
51                       local->hw.conf.antenna_sel_tx);
52 DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
53                       local->hw.conf.antenna_sel_rx);
54 DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
55                       local->bridge_packets);
56 DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
57                       local->rts_threshold);
58 DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
59                       local->fragmentation_threshold);
60 DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
61                       local->short_retry_limit);
62 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
63                       local->long_retry_limit);
64 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
65                       local->total_ps_buffered);
66 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
67                       local->wep_iv & 0xffffff);
68 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
69                       local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
70
71 /* statistics stuff */
72
73 static inline int rtnl_lock_local(struct ieee80211_local *local)
74 {
75         rtnl_lock();
76         if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
77                 rtnl_unlock();
78                 return -ENODEV;
79         }
80         return 0;
81 }
82
83 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...)                 \
84         DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
85
86 static ssize_t format_devstat_counter(struct ieee80211_local *local,
87         char __user *userbuf,
88         size_t count, loff_t *ppos,
89         int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
90                           int buflen))
91 {
92         struct ieee80211_low_level_stats stats;
93         char buf[20];
94         int res;
95
96         if (!local->ops->get_stats)
97                 return -EOPNOTSUPP;
98
99         res = rtnl_lock_local(local);
100         if (res)
101                 return res;
102
103         res = local->ops->get_stats(local_to_hw(local), &stats);
104         rtnl_unlock();
105         if (!res)
106                 res = printvalue(&stats, buf, sizeof(buf));
107         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
108 }
109
110 #define DEBUGFS_DEVSTATS_FILE(name)                                     \
111 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
112                                  char *buf, int buflen)                 \
113 {                                                                       \
114         return scnprintf(buf, buflen, "%u\n", stats->name);             \
115 }                                                                       \
116 static ssize_t stats_ ##name## _read(struct file *file,                 \
117                                      char __user *userbuf,              \
118                                      size_t count, loff_t *ppos)        \
119 {                                                                       \
120         return format_devstat_counter(file->private_data,               \
121                                       userbuf,                          \
122                                       count,                            \
123                                       ppos,                             \
124                                       print_devstats_##name);           \
125 }                                                                       \
126                                                                         \
127 static const struct file_operations stats_ ##name## _ops = {            \
128         .read = stats_ ##name## _read,                                  \
129         .open = mac80211_open_file_generic,                             \
130 };
131
132 #define DEBUGFS_STATS_ADD(name)                                         \
133         local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
134                 local, &stats_ ##name## _ops);
135
136 #define DEBUGFS_STATS_DEL(name)                                         \
137         debugfs_remove(local->debugfs.stats.name);                      \
138         local->debugfs.stats.name = NULL;
139
140 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
141                    local->dot11TransmittedFragmentCount);
142 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
143                    local->dot11MulticastTransmittedFrameCount);
144 DEBUGFS_STATS_FILE(failed_count, 20, "%u",
145                    local->dot11FailedCount);
146 DEBUGFS_STATS_FILE(retry_count, 20, "%u",
147                    local->dot11RetryCount);
148 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
149                    local->dot11MultipleRetryCount);
150 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
151                    local->dot11FrameDuplicateCount);
152 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
153                    local->dot11ReceivedFragmentCount);
154 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
155                    local->dot11MulticastReceivedFrameCount);
156 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
157                    local->dot11TransmittedFrameCount);
158 DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
159                    local->dot11WEPUndecryptableCount);
160 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
161 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
162                    local->tx_handlers_drop);
163 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
164                    local->tx_handlers_queued);
165 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
166                    local->tx_handlers_drop_unencrypted);
167 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
168                    local->tx_handlers_drop_fragment);
169 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
170                    local->tx_handlers_drop_wep);
171 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
172                    local->tx_handlers_drop_not_assoc);
173 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
174                    local->tx_handlers_drop_unauth_port);
175 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
176                    local->rx_handlers_drop);
177 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
178                    local->rx_handlers_queued);
179 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
180                    local->rx_handlers_drop_nullfunc);
181 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
182                    local->rx_handlers_drop_defrag);
183 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
184                    local->rx_handlers_drop_short);
185 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
186                    local->rx_handlers_drop_passive_scan);
187 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
188                    local->tx_expand_skb_head);
189 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
190                    local->tx_expand_skb_head_cloned);
191 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
192                    local->rx_expand_skb_head);
193 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
194                    local->rx_expand_skb_head2);
195 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
196                    local->rx_handlers_fragments);
197 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
198                    local->tx_status_drop);
199
200 #endif
201
202 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
203 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
204 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
205 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
206
207
208 void debugfs_hw_add(struct ieee80211_local *local)
209 {
210         struct dentry *phyd = local->hw.wiphy->debugfsdir;
211         struct dentry *statsd;
212
213         if (!phyd)
214                 return;
215
216         local->debugfs.stations = debugfs_create_dir("stations", phyd);
217         local->debugfs.keys = debugfs_create_dir("keys", phyd);
218
219         DEBUGFS_ADD(frequency);
220         DEBUGFS_ADD(antenna_sel_tx);
221         DEBUGFS_ADD(antenna_sel_rx);
222         DEBUGFS_ADD(bridge_packets);
223         DEBUGFS_ADD(rts_threshold);
224         DEBUGFS_ADD(fragmentation_threshold);
225         DEBUGFS_ADD(short_retry_limit);
226         DEBUGFS_ADD(long_retry_limit);
227         DEBUGFS_ADD(total_ps_buffered);
228         DEBUGFS_ADD(wep_iv);
229
230         statsd = debugfs_create_dir("statistics", phyd);
231         local->debugfs.statistics = statsd;
232
233         /* if the dir failed, don't put all the other things into the root! */
234         if (!statsd)
235                 return;
236
237         DEBUGFS_STATS_ADD(transmitted_fragment_count);
238         DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
239         DEBUGFS_STATS_ADD(failed_count);
240         DEBUGFS_STATS_ADD(retry_count);
241         DEBUGFS_STATS_ADD(multiple_retry_count);
242         DEBUGFS_STATS_ADD(frame_duplicate_count);
243         DEBUGFS_STATS_ADD(received_fragment_count);
244         DEBUGFS_STATS_ADD(multicast_received_frame_count);
245         DEBUGFS_STATS_ADD(transmitted_frame_count);
246         DEBUGFS_STATS_ADD(wep_undecryptable_count);
247 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
248         DEBUGFS_STATS_ADD(tx_handlers_drop);
249         DEBUGFS_STATS_ADD(tx_handlers_queued);
250         DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
251         DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
252         DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
253         DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
254         DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
255         DEBUGFS_STATS_ADD(rx_handlers_drop);
256         DEBUGFS_STATS_ADD(rx_handlers_queued);
257         DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
258         DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
259         DEBUGFS_STATS_ADD(rx_handlers_drop_short);
260         DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
261         DEBUGFS_STATS_ADD(tx_expand_skb_head);
262         DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
263         DEBUGFS_STATS_ADD(rx_expand_skb_head);
264         DEBUGFS_STATS_ADD(rx_expand_skb_head2);
265         DEBUGFS_STATS_ADD(rx_handlers_fragments);
266         DEBUGFS_STATS_ADD(tx_status_drop);
267 #endif
268         DEBUGFS_STATS_ADD(dot11ACKFailureCount);
269         DEBUGFS_STATS_ADD(dot11RTSFailureCount);
270         DEBUGFS_STATS_ADD(dot11FCSErrorCount);
271         DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
272 }
273
274 void debugfs_hw_del(struct ieee80211_local *local)
275 {
276         DEBUGFS_DEL(frequency);
277         DEBUGFS_DEL(antenna_sel_tx);
278         DEBUGFS_DEL(antenna_sel_rx);
279         DEBUGFS_DEL(bridge_packets);
280         DEBUGFS_DEL(rts_threshold);
281         DEBUGFS_DEL(fragmentation_threshold);
282         DEBUGFS_DEL(short_retry_limit);
283         DEBUGFS_DEL(long_retry_limit);
284         DEBUGFS_DEL(total_ps_buffered);
285         DEBUGFS_DEL(wep_iv);
286
287         DEBUGFS_STATS_DEL(transmitted_fragment_count);
288         DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
289         DEBUGFS_STATS_DEL(failed_count);
290         DEBUGFS_STATS_DEL(retry_count);
291         DEBUGFS_STATS_DEL(multiple_retry_count);
292         DEBUGFS_STATS_DEL(frame_duplicate_count);
293         DEBUGFS_STATS_DEL(received_fragment_count);
294         DEBUGFS_STATS_DEL(multicast_received_frame_count);
295         DEBUGFS_STATS_DEL(transmitted_frame_count);
296         DEBUGFS_STATS_DEL(wep_undecryptable_count);
297         DEBUGFS_STATS_DEL(num_scans);
298 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
299         DEBUGFS_STATS_DEL(tx_handlers_drop);
300         DEBUGFS_STATS_DEL(tx_handlers_queued);
301         DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
302         DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
303         DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
304         DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
305         DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
306         DEBUGFS_STATS_DEL(rx_handlers_drop);
307         DEBUGFS_STATS_DEL(rx_handlers_queued);
308         DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
309         DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
310         DEBUGFS_STATS_DEL(rx_handlers_drop_short);
311         DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
312         DEBUGFS_STATS_DEL(tx_expand_skb_head);
313         DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
314         DEBUGFS_STATS_DEL(rx_expand_skb_head);
315         DEBUGFS_STATS_DEL(rx_expand_skb_head2);
316         DEBUGFS_STATS_DEL(rx_handlers_fragments);
317         DEBUGFS_STATS_DEL(tx_status_drop);
318 #endif
319         DEBUGFS_STATS_DEL(dot11ACKFailureCount);
320         DEBUGFS_STATS_DEL(dot11RTSFailureCount);
321         DEBUGFS_STATS_DEL(dot11FCSErrorCount);
322         DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
323
324         debugfs_remove(local->debugfs.statistics);
325         local->debugfs.statistics = NULL;
326         debugfs_remove(local->debugfs.stations);
327         local->debugfs.stations = NULL;
328         debugfs_remove(local->debugfs.keys);
329         local->debugfs.keys = NULL;
330 }