[MAC80211]: remove unused ioctls (2)
[linux-2.6.git] / 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 "ieee80211_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 static const char *ieee80211_mode_str(int mode)
23 {
24         switch (mode) {
25         case MODE_IEEE80211A:
26                 return "IEEE 802.11a";
27         case MODE_IEEE80211B:
28                 return "IEEE 802.11b";
29         case MODE_IEEE80211G:
30                 return "IEEE 802.11g";
31         case MODE_ATHEROS_TURBO:
32                 return "Atheros Turbo (5 GHz)";
33         default:
34                 return "UNKNOWN";
35         }
36 }
37
38 static ssize_t modes_read(struct file *file, char __user *userbuf,
39                           size_t count, loff_t *ppos)
40 {
41         struct ieee80211_local *local = file->private_data;
42         struct ieee80211_hw_mode *mode;
43         char buf[150], *p = buf;
44
45         /* FIXME: locking! */
46         list_for_each_entry(mode, &local->modes_list, list) {
47                 p += scnprintf(p, sizeof(buf)+buf-p,
48                                "%s\n", ieee80211_mode_str(mode->mode));
49         }
50
51         return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
52 }
53
54 static const struct file_operations modes_ops = {
55         .read = modes_read,
56         .open = mac80211_open_file_generic,
57 };
58
59 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...)              \
60 static ssize_t name## _read(struct file *file, char __user *userbuf,    \
61                             size_t count, loff_t *ppos)                 \
62 {                                                                       \
63         struct ieee80211_local *local = file->private_data;             \
64         char buf[buflen];                                               \
65         int res;                                                        \
66                                                                         \
67         res = scnprintf(buf, buflen, fmt "\n", ##value);                \
68         return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
69 }                                                                       \
70                                                                         \
71 static const struct file_operations name## _ops = {                     \
72         .read = name## _read,                                           \
73         .open = mac80211_open_file_generic,                             \
74 };
75
76 #define DEBUGFS_ADD(name)                                               \
77         local->debugfs.name = debugfs_create_file(#name, 0444, phyd,    \
78                                                   local, &name## _ops);
79
80 #define DEBUGFS_DEL(name)                                               \
81         debugfs_remove(local->debugfs.name);                            \
82         local->debugfs.name = NULL;
83
84
85 DEBUGFS_READONLY_FILE(channel, 20, "%d",
86                       local->hw.conf.channel);
87 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
88                       local->hw.conf.freq);
89 DEBUGFS_READONLY_FILE(radar_detect, 20, "%d",
90                       local->hw.conf.radar_detect);
91 DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
92                       local->hw.conf.antenna_sel_tx);
93 DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
94                       local->hw.conf.antenna_sel_rx);
95 DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
96                       local->bridge_packets);
97 DEBUGFS_READONLY_FILE(key_tx_rx_threshold, 20, "%d",
98                       local->key_tx_rx_threshold);
99 DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
100                       local->rts_threshold);
101 DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
102                       local->fragmentation_threshold);
103 DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
104                       local->short_retry_limit);
105 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
106                       local->long_retry_limit);
107 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
108                       local->total_ps_buffered);
109 DEBUGFS_READONLY_FILE(mode, 20, "%s",
110                       ieee80211_mode_str(local->hw.conf.phymode));
111 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
112                       local->wep_iv & 0xffffff);
113 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
114                       local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
115
116 /* statistics stuff */
117
118 static inline int rtnl_lock_local(struct ieee80211_local *local)
119 {
120         rtnl_lock();
121         if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
122                 rtnl_unlock();
123                 return -ENODEV;
124         }
125         return 0;
126 }
127
128 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...)                 \
129         DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
130
131 static ssize_t format_devstat_counter(struct ieee80211_local *local,
132         char __user *userbuf,
133         size_t count, loff_t *ppos,
134         int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
135                           int buflen))
136 {
137         struct ieee80211_low_level_stats stats;
138         char buf[20];
139         int res;
140
141         if (!local->ops->get_stats)
142                 return -EOPNOTSUPP;
143
144         res = rtnl_lock_local(local);
145         if (res)
146                 return res;
147
148         res = local->ops->get_stats(local_to_hw(local), &stats);
149         rtnl_unlock();
150         if (!res)
151                 res = printvalue(&stats, buf, sizeof(buf));
152         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
153 }
154
155 #define DEBUGFS_DEVSTATS_FILE(name)                                     \
156 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
157                                  char *buf, int buflen)                 \
158 {                                                                       \
159         return scnprintf(buf, buflen, "%u\n", stats->name);             \
160 }                                                                       \
161 static ssize_t stats_ ##name## _read(struct file *file,                 \
162                                      char __user *userbuf,              \
163                                      size_t count, loff_t *ppos)        \
164 {                                                                       \
165         return format_devstat_counter(file->private_data,               \
166                                       userbuf,                          \
167                                       count,                            \
168                                       ppos,                             \
169                                       print_devstats_##name);           \
170 }                                                                       \
171                                                                         \
172 static const struct file_operations stats_ ##name## _ops = {            \
173         .read = stats_ ##name## _read,                                  \
174         .open = mac80211_open_file_generic,                             \
175 };
176
177 #define DEBUGFS_STATS_ADD(name)                                         \
178         local->debugfs.stats.name = debugfs_create_file(#name, 0444, statsd,\
179                 local, &stats_ ##name## _ops);
180
181 #define DEBUGFS_STATS_DEL(name)                                         \
182         debugfs_remove(local->debugfs.stats.name);                      \
183         local->debugfs.stats.name = NULL;
184
185 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
186                    local->dot11TransmittedFragmentCount);
187 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
188                    local->dot11MulticastTransmittedFrameCount);
189 DEBUGFS_STATS_FILE(failed_count, 20, "%u",
190                    local->dot11FailedCount);
191 DEBUGFS_STATS_FILE(retry_count, 20, "%u",
192                    local->dot11RetryCount);
193 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
194                    local->dot11MultipleRetryCount);
195 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
196                    local->dot11FrameDuplicateCount);
197 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
198                    local->dot11ReceivedFragmentCount);
199 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
200                    local->dot11MulticastReceivedFrameCount);
201 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
202                    local->dot11TransmittedFrameCount);
203 DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
204                    local->dot11WEPUndecryptableCount);
205 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
206 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
207                    local->tx_handlers_drop);
208 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
209                    local->tx_handlers_queued);
210 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
211                    local->tx_handlers_drop_unencrypted);
212 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
213                    local->tx_handlers_drop_fragment);
214 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
215                    local->tx_handlers_drop_wep);
216 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
217                    local->tx_handlers_drop_not_assoc);
218 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
219                    local->tx_handlers_drop_unauth_port);
220 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
221                    local->rx_handlers_drop);
222 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
223                    local->rx_handlers_queued);
224 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
225                    local->rx_handlers_drop_nullfunc);
226 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
227                    local->rx_handlers_drop_defrag);
228 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
229                    local->rx_handlers_drop_short);
230 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
231                    local->rx_handlers_drop_passive_scan);
232 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
233                    local->tx_expand_skb_head);
234 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
235                    local->tx_expand_skb_head_cloned);
236 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
237                    local->rx_expand_skb_head);
238 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
239                    local->rx_expand_skb_head2);
240 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
241                    local->rx_handlers_fragments);
242 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
243                    local->tx_status_drop);
244
245 static ssize_t stats_wme_rx_queue_read(struct file *file,
246                                        char __user *userbuf,
247                                        size_t count, loff_t *ppos)
248 {
249         struct ieee80211_local *local = file->private_data;
250         char buf[NUM_RX_DATA_QUEUES*15], *p = buf;
251         int i;
252
253         for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
254                 p += scnprintf(p, sizeof(buf)+buf-p,
255                                "%u\n", local->wme_rx_queue[i]);
256
257         return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
258 }
259
260 static const struct file_operations stats_wme_rx_queue_ops = {
261         .read = stats_wme_rx_queue_read,
262         .open = mac80211_open_file_generic,
263 };
264
265 static ssize_t stats_wme_tx_queue_read(struct file *file,
266                                        char __user *userbuf,
267                                        size_t count, loff_t *ppos)
268 {
269         struct ieee80211_local *local = file->private_data;
270         char buf[NUM_TX_DATA_QUEUES*15], *p = buf;
271         int i;
272
273         for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
274                 p += scnprintf(p, sizeof(buf)+buf-p,
275                                "%u\n", local->wme_tx_queue[i]);
276
277         return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
278 }
279
280 static const struct file_operations stats_wme_tx_queue_ops = {
281         .read = stats_wme_tx_queue_read,
282         .open = mac80211_open_file_generic,
283 };
284 #endif
285
286 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
287 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
288 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
289 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
290
291
292 void debugfs_hw_add(struct ieee80211_local *local)
293 {
294         struct dentry *phyd = local->hw.wiphy->debugfsdir;
295         struct dentry *statsd;
296
297         if (!phyd)
298                 return;
299
300         local->debugfs.stations = debugfs_create_dir("stations", phyd);
301         local->debugfs.keys = debugfs_create_dir("keys", phyd);
302
303         DEBUGFS_ADD(channel);
304         DEBUGFS_ADD(frequency);
305         DEBUGFS_ADD(radar_detect);
306         DEBUGFS_ADD(antenna_sel_tx);
307         DEBUGFS_ADD(antenna_sel_rx);
308         DEBUGFS_ADD(bridge_packets);
309         DEBUGFS_ADD(key_tx_rx_threshold);
310         DEBUGFS_ADD(rts_threshold);
311         DEBUGFS_ADD(fragmentation_threshold);
312         DEBUGFS_ADD(short_retry_limit);
313         DEBUGFS_ADD(long_retry_limit);
314         DEBUGFS_ADD(total_ps_buffered);
315         DEBUGFS_ADD(mode);
316         DEBUGFS_ADD(wep_iv);
317         DEBUGFS_ADD(modes);
318
319         statsd = debugfs_create_dir("statistics", phyd);
320         local->debugfs.statistics = statsd;
321
322         /* if the dir failed, don't put all the other things into the root! */
323         if (!statsd)
324                 return;
325
326         DEBUGFS_STATS_ADD(transmitted_fragment_count);
327         DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
328         DEBUGFS_STATS_ADD(failed_count);
329         DEBUGFS_STATS_ADD(retry_count);
330         DEBUGFS_STATS_ADD(multiple_retry_count);
331         DEBUGFS_STATS_ADD(frame_duplicate_count);
332         DEBUGFS_STATS_ADD(received_fragment_count);
333         DEBUGFS_STATS_ADD(multicast_received_frame_count);
334         DEBUGFS_STATS_ADD(transmitted_frame_count);
335         DEBUGFS_STATS_ADD(wep_undecryptable_count);
336 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
337         DEBUGFS_STATS_ADD(tx_handlers_drop);
338         DEBUGFS_STATS_ADD(tx_handlers_queued);
339         DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
340         DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
341         DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
342         DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
343         DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
344         DEBUGFS_STATS_ADD(rx_handlers_drop);
345         DEBUGFS_STATS_ADD(rx_handlers_queued);
346         DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
347         DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
348         DEBUGFS_STATS_ADD(rx_handlers_drop_short);
349         DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
350         DEBUGFS_STATS_ADD(tx_expand_skb_head);
351         DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
352         DEBUGFS_STATS_ADD(rx_expand_skb_head);
353         DEBUGFS_STATS_ADD(rx_expand_skb_head2);
354         DEBUGFS_STATS_ADD(rx_handlers_fragments);
355         DEBUGFS_STATS_ADD(tx_status_drop);
356         DEBUGFS_STATS_ADD(wme_tx_queue);
357         DEBUGFS_STATS_ADD(wme_rx_queue);
358 #endif
359         DEBUGFS_STATS_ADD(dot11ACKFailureCount);
360         DEBUGFS_STATS_ADD(dot11RTSFailureCount);
361         DEBUGFS_STATS_ADD(dot11FCSErrorCount);
362         DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
363 }
364
365 void debugfs_hw_del(struct ieee80211_local *local)
366 {
367         DEBUGFS_DEL(channel);
368         DEBUGFS_DEL(frequency);
369         DEBUGFS_DEL(radar_detect);
370         DEBUGFS_DEL(antenna_sel_tx);
371         DEBUGFS_DEL(antenna_sel_rx);
372         DEBUGFS_DEL(bridge_packets);
373         DEBUGFS_DEL(key_tx_rx_threshold);
374         DEBUGFS_DEL(rts_threshold);
375         DEBUGFS_DEL(fragmentation_threshold);
376         DEBUGFS_DEL(short_retry_limit);
377         DEBUGFS_DEL(long_retry_limit);
378         DEBUGFS_DEL(total_ps_buffered);
379         DEBUGFS_DEL(mode);
380         DEBUGFS_DEL(wep_iv);
381         DEBUGFS_DEL(modes);
382
383         DEBUGFS_STATS_DEL(transmitted_fragment_count);
384         DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
385         DEBUGFS_STATS_DEL(failed_count);
386         DEBUGFS_STATS_DEL(retry_count);
387         DEBUGFS_STATS_DEL(multiple_retry_count);
388         DEBUGFS_STATS_DEL(frame_duplicate_count);
389         DEBUGFS_STATS_DEL(received_fragment_count);
390         DEBUGFS_STATS_DEL(multicast_received_frame_count);
391         DEBUGFS_STATS_DEL(transmitted_frame_count);
392         DEBUGFS_STATS_DEL(wep_undecryptable_count);
393         DEBUGFS_STATS_DEL(num_scans);
394 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
395         DEBUGFS_STATS_DEL(tx_handlers_drop);
396         DEBUGFS_STATS_DEL(tx_handlers_queued);
397         DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
398         DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
399         DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
400         DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
401         DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
402         DEBUGFS_STATS_DEL(rx_handlers_drop);
403         DEBUGFS_STATS_DEL(rx_handlers_queued);
404         DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
405         DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
406         DEBUGFS_STATS_DEL(rx_handlers_drop_short);
407         DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
408         DEBUGFS_STATS_DEL(tx_expand_skb_head);
409         DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
410         DEBUGFS_STATS_DEL(rx_expand_skb_head);
411         DEBUGFS_STATS_DEL(rx_expand_skb_head2);
412         DEBUGFS_STATS_DEL(rx_handlers_fragments);
413         DEBUGFS_STATS_DEL(tx_status_drop);
414         DEBUGFS_STATS_DEL(wme_tx_queue);
415         DEBUGFS_STATS_DEL(wme_rx_queue);
416 #endif
417         DEBUGFS_STATS_DEL(dot11ACKFailureCount);
418         DEBUGFS_STATS_DEL(dot11RTSFailureCount);
419         DEBUGFS_STATS_DEL(dot11FCSErrorCount);
420         DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
421
422         debugfs_remove(local->debugfs.statistics);
423         local->debugfs.statistics = NULL;
424         debugfs_remove(local->debugfs.stations);
425         local->debugfs.stations = NULL;
426         debugfs_remove(local->debugfs.keys);
427         local->debugfs.keys = NULL;
428 }