- patches.suse/slab-handle-memoryless-nodes-v2a.patch: Refresh.
[linux-flexiantxendom0-3.2.10.git] / net / mac80211 / debugfs.c
1
2 /*
3  * mac80211 debugfs for wireless PHYs
4  *
5  * Copyright 2007       Johannes Berg <johannes@sipsolutions.net>
6  *
7  * GPLv2
8  *
9  */
10
11 #include <linux/debugfs.h>
12 #include <linux/rtnetlink.h>
13 #include "ieee80211_i.h"
14 #include "driver-ops.h"
15 #include "rate.h"
16 #include "debugfs.h"
17
18 int mac80211_open_file_generic(struct inode *inode, struct file *file)
19 {
20         file->private_data = inode->i_private;
21         return 0;
22 }
23
24 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...)              \
25 static ssize_t name## _read(struct file *file, char __user *userbuf,    \
26                             size_t count, loff_t *ppos)                 \
27 {                                                                       \
28         struct ieee80211_local *local = file->private_data;             \
29         char buf[buflen];                                               \
30         int res;                                                        \
31                                                                         \
32         res = scnprintf(buf, buflen, fmt "\n", ##value);                \
33         return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
34 }                                                                       \
35                                                                         \
36 static const struct file_operations name## _ops = {                     \
37         .read = name## _read,                                           \
38         .open = mac80211_open_file_generic,                             \
39 };
40
41 #define DEBUGFS_ADD(name)                                               \
42         debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
43
44 #define DEBUGFS_ADD_MODE(name, mode)                                    \
45         debugfs_create_file(#name, mode, phyd, local, &name## _ops);
46
47
48 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
49                       local->hw.conf.channel->center_freq);
50 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
51                       local->total_ps_buffered);
52 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
53                       local->wep_iv & 0xffffff);
54 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
55         local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
56
57 static ssize_t tsf_read(struct file *file, char __user *user_buf,
58                              size_t count, loff_t *ppos)
59 {
60         struct ieee80211_local *local = file->private_data;
61         u64 tsf;
62         char buf[100];
63
64         tsf = drv_get_tsf(local);
65
66         snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
67
68         return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
69 }
70
71 static ssize_t tsf_write(struct file *file,
72                          const char __user *user_buf,
73                          size_t count, loff_t *ppos)
74 {
75         struct ieee80211_local *local = file->private_data;
76         unsigned long long tsf;
77         char buf[100];
78         size_t len;
79
80         len = min(count, sizeof(buf) - 1);
81         if (copy_from_user(buf, user_buf, len))
82                 return -EFAULT;
83         buf[len] = '\0';
84
85         if (strncmp(buf, "reset", 5) == 0) {
86                 if (local->ops->reset_tsf) {
87                         drv_reset_tsf(local);
88                         printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy));
89                 }
90         } else {
91                 tsf = simple_strtoul(buf, NULL, 0);
92                 if (local->ops->set_tsf) {
93                         drv_set_tsf(local, tsf);
94                         printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
95                 }
96         }
97
98         return count;
99 }
100
101 static const struct file_operations tsf_ops = {
102         .read = tsf_read,
103         .write = tsf_write,
104         .open = mac80211_open_file_generic
105 };
106
107 static ssize_t reset_write(struct file *file, const char __user *user_buf,
108                            size_t count, loff_t *ppos)
109 {
110         struct ieee80211_local *local = file->private_data;
111
112         rtnl_lock();
113         __ieee80211_suspend(&local->hw);
114         __ieee80211_resume(&local->hw);
115         rtnl_unlock();
116
117         return count;
118 }
119
120 static const struct file_operations reset_ops = {
121         .write = reset_write,
122         .open = mac80211_open_file_generic,
123 };
124
125 static ssize_t noack_read(struct file *file, char __user *user_buf,
126                           size_t count, loff_t *ppos)
127 {
128         struct ieee80211_local *local = file->private_data;
129         int res;
130         char buf[10];
131
132         res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
133
134         return simple_read_from_buffer(user_buf, count, ppos, buf, res);
135 }
136
137 static ssize_t noack_write(struct file *file,
138                            const char __user *user_buf,
139                            size_t count, loff_t *ppos)
140 {
141         struct ieee80211_local *local = file->private_data;
142         char buf[10];
143         size_t len;
144
145         len = min(count, sizeof(buf) - 1);
146         if (copy_from_user(buf, user_buf, len))
147                 return -EFAULT;
148         buf[len] = '\0';
149
150         local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
151
152         return count;
153 }
154
155 static const struct file_operations noack_ops = {
156         .read = noack_read,
157         .write = noack_write,
158         .open = mac80211_open_file_generic
159 };
160
161 static ssize_t queues_read(struct file *file, char __user *user_buf,
162                            size_t count, loff_t *ppos)
163 {
164         struct ieee80211_local *local = file->private_data;
165         unsigned long flags;
166         char buf[IEEE80211_MAX_QUEUES * 20];
167         int q, res = 0;
168
169         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
170         for (q = 0; q < local->hw.queues; q++)
171                 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
172                                 local->queue_stop_reasons[q],
173                                 skb_queue_len(&local->pending[q]));
174         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
175
176         return simple_read_from_buffer(user_buf, count, ppos, buf, res);
177 }
178
179 static const struct file_operations queues_ops = {
180         .read = queues_read,
181         .open = mac80211_open_file_generic
182 };
183
184 /* statistics stuff */
185
186 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...)                 \
187         DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
188
189 static ssize_t format_devstat_counter(struct ieee80211_local *local,
190         char __user *userbuf,
191         size_t count, loff_t *ppos,
192         int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
193                           int buflen))
194 {
195         struct ieee80211_low_level_stats stats;
196         char buf[20];
197         int res;
198
199         rtnl_lock();
200         res = drv_get_stats(local, &stats);
201         rtnl_unlock();
202         if (res)
203                 return res;
204         res = printvalue(&stats, buf, sizeof(buf));
205         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
206 }
207
208 #define DEBUGFS_DEVSTATS_FILE(name)                                     \
209 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
210                                  char *buf, int buflen)                 \
211 {                                                                       \
212         return scnprintf(buf, buflen, "%u\n", stats->name);             \
213 }                                                                       \
214 static ssize_t stats_ ##name## _read(struct file *file,                 \
215                                      char __user *userbuf,              \
216                                      size_t count, loff_t *ppos)        \
217 {                                                                       \
218         return format_devstat_counter(file->private_data,               \
219                                       userbuf,                          \
220                                       count,                            \
221                                       ppos,                             \
222                                       print_devstats_##name);           \
223 }                                                                       \
224                                                                         \
225 static const struct file_operations stats_ ##name## _ops = {            \
226         .read = stats_ ##name## _read,                                  \
227         .open = mac80211_open_file_generic,                             \
228 };
229
230 #define DEBUGFS_STATS_ADD(name)                                         \
231         debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
232
233 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
234                    local->dot11TransmittedFragmentCount);
235 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
236                    local->dot11MulticastTransmittedFrameCount);
237 DEBUGFS_STATS_FILE(failed_count, 20, "%u",
238                    local->dot11FailedCount);
239 DEBUGFS_STATS_FILE(retry_count, 20, "%u",
240                    local->dot11RetryCount);
241 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
242                    local->dot11MultipleRetryCount);
243 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
244                    local->dot11FrameDuplicateCount);
245 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
246                    local->dot11ReceivedFragmentCount);
247 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
248                    local->dot11MulticastReceivedFrameCount);
249 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
250                    local->dot11TransmittedFrameCount);
251 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
252 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
253                    local->tx_handlers_drop);
254 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
255                    local->tx_handlers_queued);
256 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
257                    local->tx_handlers_drop_unencrypted);
258 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
259                    local->tx_handlers_drop_fragment);
260 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
261                    local->tx_handlers_drop_wep);
262 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
263                    local->tx_handlers_drop_not_assoc);
264 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
265                    local->tx_handlers_drop_unauth_port);
266 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
267                    local->rx_handlers_drop);
268 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
269                    local->rx_handlers_queued);
270 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
271                    local->rx_handlers_drop_nullfunc);
272 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
273                    local->rx_handlers_drop_defrag);
274 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
275                    local->rx_handlers_drop_short);
276 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
277                    local->rx_handlers_drop_passive_scan);
278 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
279                    local->tx_expand_skb_head);
280 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
281                    local->tx_expand_skb_head_cloned);
282 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
283                    local->rx_expand_skb_head);
284 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
285                    local->rx_expand_skb_head2);
286 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
287                    local->rx_handlers_fragments);
288 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
289                    local->tx_status_drop);
290
291 #endif
292
293 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
294 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
295 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
296 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
297
298
299 void debugfs_hw_add(struct ieee80211_local *local)
300 {
301         struct dentry *phyd = local->hw.wiphy->debugfsdir;
302         struct dentry *statsd;
303
304         if (!phyd)
305                 return;
306
307         local->debugfs.stations = debugfs_create_dir("stations", phyd);
308         local->debugfs.keys = debugfs_create_dir("keys", phyd);
309
310         DEBUGFS_ADD(frequency);
311         DEBUGFS_ADD(total_ps_buffered);
312         DEBUGFS_ADD(wep_iv);
313         DEBUGFS_ADD(tsf);
314         DEBUGFS_ADD(queues);
315         DEBUGFS_ADD_MODE(reset, 0200);
316         DEBUGFS_ADD(noack);
317
318         statsd = debugfs_create_dir("statistics", phyd);
319
320         /* if the dir failed, don't put all the other things into the root! */
321         if (!statsd)
322                 return;
323
324         DEBUGFS_STATS_ADD(transmitted_fragment_count);
325         DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
326         DEBUGFS_STATS_ADD(failed_count);
327         DEBUGFS_STATS_ADD(retry_count);
328         DEBUGFS_STATS_ADD(multiple_retry_count);
329         DEBUGFS_STATS_ADD(frame_duplicate_count);
330         DEBUGFS_STATS_ADD(received_fragment_count);
331         DEBUGFS_STATS_ADD(multicast_received_frame_count);
332         DEBUGFS_STATS_ADD(transmitted_frame_count);
333 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
334         DEBUGFS_STATS_ADD(tx_handlers_drop);
335         DEBUGFS_STATS_ADD(tx_handlers_queued);
336         DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
337         DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
338         DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
339         DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
340         DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
341         DEBUGFS_STATS_ADD(rx_handlers_drop);
342         DEBUGFS_STATS_ADD(rx_handlers_queued);
343         DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
344         DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
345         DEBUGFS_STATS_ADD(rx_handlers_drop_short);
346         DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
347         DEBUGFS_STATS_ADD(tx_expand_skb_head);
348         DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
349         DEBUGFS_STATS_ADD(rx_expand_skb_head);
350         DEBUGFS_STATS_ADD(rx_expand_skb_head2);
351         DEBUGFS_STATS_ADD(rx_handlers_fragments);
352         DEBUGFS_STATS_ADD(tx_status_drop);
353 #endif
354         DEBUGFS_STATS_ADD(dot11ACKFailureCount);
355         DEBUGFS_STATS_ADD(dot11RTSFailureCount);
356         DEBUGFS_STATS_ADD(dot11FCSErrorCount);
357         DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
358 }