net/wireless: use generic_file_llseek in debugfs
[deliverable/linux.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 .llseek = generic_file_llseek, \
40 };
41
42 #define DEBUGFS_ADD(name) \
43 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
44
45 #define DEBUGFS_ADD_MODE(name, mode) \
46 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
47
48
49 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
50 local->hw.conf.channel->center_freq);
51 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
52 local->total_ps_buffered);
53 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
54 local->wep_iv & 0xffffff);
55 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
56 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
57
58 static ssize_t tsf_read(struct file *file, char __user *user_buf,
59 size_t count, loff_t *ppos)
60 {
61 struct ieee80211_local *local = file->private_data;
62 u64 tsf;
63 char buf[100];
64
65 tsf = drv_get_tsf(local);
66
67 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
68
69 return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
70 }
71
72 static ssize_t tsf_write(struct file *file,
73 const char __user *user_buf,
74 size_t count, loff_t *ppos)
75 {
76 struct ieee80211_local *local = file->private_data;
77 unsigned long long tsf;
78 char buf[100];
79 size_t len;
80
81 len = min(count, sizeof(buf) - 1);
82 if (copy_from_user(buf, user_buf, len))
83 return -EFAULT;
84 buf[len] = '\0';
85
86 if (strncmp(buf, "reset", 5) == 0) {
87 if (local->ops->reset_tsf) {
88 drv_reset_tsf(local);
89 printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy));
90 }
91 } else {
92 tsf = simple_strtoul(buf, NULL, 0);
93 if (local->ops->set_tsf) {
94 drv_set_tsf(local, tsf);
95 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
96 }
97 }
98
99 return count;
100 }
101
102 static const struct file_operations tsf_ops = {
103 .read = tsf_read,
104 .write = tsf_write,
105 .open = mac80211_open_file_generic
106 };
107
108 static ssize_t reset_write(struct file *file, const char __user *user_buf,
109 size_t count, loff_t *ppos)
110 {
111 struct ieee80211_local *local = file->private_data;
112
113 rtnl_lock();
114 __ieee80211_suspend(&local->hw);
115 __ieee80211_resume(&local->hw);
116 rtnl_unlock();
117
118 return count;
119 }
120
121 static const struct file_operations reset_ops = {
122 .write = reset_write,
123 .open = mac80211_open_file_generic,
124 };
125
126 static ssize_t noack_read(struct file *file, char __user *user_buf,
127 size_t count, loff_t *ppos)
128 {
129 struct ieee80211_local *local = file->private_data;
130 int res;
131 char buf[10];
132
133 res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
134
135 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
136 }
137
138 static ssize_t noack_write(struct file *file,
139 const char __user *user_buf,
140 size_t count, loff_t *ppos)
141 {
142 struct ieee80211_local *local = file->private_data;
143 char buf[10];
144 size_t len;
145
146 len = min(count, sizeof(buf) - 1);
147 if (copy_from_user(buf, user_buf, len))
148 return -EFAULT;
149 buf[len] = '\0';
150
151 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
152
153 return count;
154 }
155
156 static const struct file_operations noack_ops = {
157 .read = noack_read,
158 .write = noack_write,
159 .open = mac80211_open_file_generic
160 };
161
162 static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
163 size_t count, loff_t *ppos)
164 {
165 struct ieee80211_local *local = file->private_data;
166 int res;
167 char buf[10];
168
169 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_queues);
170
171 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
172 }
173
174 static ssize_t uapsd_queues_write(struct file *file,
175 const char __user *user_buf,
176 size_t count, loff_t *ppos)
177 {
178 struct ieee80211_local *local = file->private_data;
179 unsigned long val;
180 char buf[10];
181 size_t len;
182 int ret;
183
184 len = min(count, sizeof(buf) - 1);
185 if (copy_from_user(buf, user_buf, len))
186 return -EFAULT;
187 buf[len] = '\0';
188
189 ret = strict_strtoul(buf, 0, &val);
190
191 if (ret)
192 return -EINVAL;
193
194 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
195 return -ERANGE;
196
197 local->uapsd_queues = val;
198
199 return count;
200 }
201
202 static const struct file_operations uapsd_queues_ops = {
203 .read = uapsd_queues_read,
204 .write = uapsd_queues_write,
205 .open = mac80211_open_file_generic
206 };
207
208 static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
209 size_t count, loff_t *ppos)
210 {
211 struct ieee80211_local *local = file->private_data;
212 int res;
213 char buf[10];
214
215 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_max_sp_len);
216
217 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
218 }
219
220 static ssize_t uapsd_max_sp_len_write(struct file *file,
221 const char __user *user_buf,
222 size_t count, loff_t *ppos)
223 {
224 struct ieee80211_local *local = file->private_data;
225 unsigned long val;
226 char buf[10];
227 size_t len;
228 int ret;
229
230 len = min(count, sizeof(buf) - 1);
231 if (copy_from_user(buf, user_buf, len))
232 return -EFAULT;
233 buf[len] = '\0';
234
235 ret = strict_strtoul(buf, 0, &val);
236
237 if (ret)
238 return -EINVAL;
239
240 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
241 return -ERANGE;
242
243 local->uapsd_max_sp_len = val;
244
245 return count;
246 }
247
248 static const struct file_operations uapsd_max_sp_len_ops = {
249 .read = uapsd_max_sp_len_read,
250 .write = uapsd_max_sp_len_write,
251 .open = mac80211_open_file_generic
252 };
253
254 static ssize_t channel_type_read(struct file *file, char __user *user_buf,
255 size_t count, loff_t *ppos)
256 {
257 struct ieee80211_local *local = file->private_data;
258 const char *buf;
259
260 switch (local->hw.conf.channel_type) {
261 case NL80211_CHAN_NO_HT:
262 buf = "no ht\n";
263 break;
264 case NL80211_CHAN_HT20:
265 buf = "ht20\n";
266 break;
267 case NL80211_CHAN_HT40MINUS:
268 buf = "ht40-\n";
269 break;
270 case NL80211_CHAN_HT40PLUS:
271 buf = "ht40+\n";
272 break;
273 default:
274 buf = "???";
275 break;
276 }
277
278 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
279 }
280
281 static const struct file_operations channel_type_ops = {
282 .read = channel_type_read,
283 .open = mac80211_open_file_generic
284 };
285
286 static ssize_t queues_read(struct file *file, char __user *user_buf,
287 size_t count, loff_t *ppos)
288 {
289 struct ieee80211_local *local = file->private_data;
290 unsigned long flags;
291 char buf[IEEE80211_MAX_QUEUES * 20];
292 int q, res = 0;
293
294 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
295 for (q = 0; q < local->hw.queues; q++)
296 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
297 local->queue_stop_reasons[q],
298 skb_queue_len(&local->pending[q]));
299 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
300
301 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
302 }
303
304 static const struct file_operations queues_ops = {
305 .read = queues_read,
306 .open = mac80211_open_file_generic
307 };
308
309 /* statistics stuff */
310
311 static ssize_t format_devstat_counter(struct ieee80211_local *local,
312 char __user *userbuf,
313 size_t count, loff_t *ppos,
314 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
315 int buflen))
316 {
317 struct ieee80211_low_level_stats stats;
318 char buf[20];
319 int res;
320
321 rtnl_lock();
322 res = drv_get_stats(local, &stats);
323 rtnl_unlock();
324 if (res)
325 return res;
326 res = printvalue(&stats, buf, sizeof(buf));
327 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
328 }
329
330 #define DEBUGFS_DEVSTATS_FILE(name) \
331 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
332 char *buf, int buflen) \
333 { \
334 return scnprintf(buf, buflen, "%u\n", stats->name); \
335 } \
336 static ssize_t stats_ ##name## _read(struct file *file, \
337 char __user *userbuf, \
338 size_t count, loff_t *ppos) \
339 { \
340 return format_devstat_counter(file->private_data, \
341 userbuf, \
342 count, \
343 ppos, \
344 print_devstats_##name); \
345 } \
346 \
347 static const struct file_operations stats_ ##name## _ops = { \
348 .read = stats_ ##name## _read, \
349 .open = mac80211_open_file_generic, \
350 .llseek = generic_file_llseek, \
351 };
352
353 #define DEBUGFS_STATS_ADD(name, field) \
354 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
355 #define DEBUGFS_DEVSTATS_ADD(name) \
356 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
357
358 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
359 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
360 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
361 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
362
363 void debugfs_hw_add(struct ieee80211_local *local)
364 {
365 struct dentry *phyd = local->hw.wiphy->debugfsdir;
366 struct dentry *statsd;
367
368 if (!phyd)
369 return;
370
371 local->debugfs.stations = debugfs_create_dir("stations", phyd);
372 local->debugfs.keys = debugfs_create_dir("keys", phyd);
373
374 DEBUGFS_ADD(frequency);
375 DEBUGFS_ADD(total_ps_buffered);
376 DEBUGFS_ADD(wep_iv);
377 DEBUGFS_ADD(tsf);
378 DEBUGFS_ADD(queues);
379 DEBUGFS_ADD_MODE(reset, 0200);
380 DEBUGFS_ADD(noack);
381 DEBUGFS_ADD(uapsd_queues);
382 DEBUGFS_ADD(uapsd_max_sp_len);
383 DEBUGFS_ADD(channel_type);
384
385 statsd = debugfs_create_dir("statistics", phyd);
386
387 /* if the dir failed, don't put all the other things into the root! */
388 if (!statsd)
389 return;
390
391 DEBUGFS_STATS_ADD(transmitted_fragment_count,
392 local->dot11TransmittedFragmentCount);
393 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
394 local->dot11MulticastTransmittedFrameCount);
395 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
396 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
397 DEBUGFS_STATS_ADD(multiple_retry_count,
398 local->dot11MultipleRetryCount);
399 DEBUGFS_STATS_ADD(frame_duplicate_count,
400 local->dot11FrameDuplicateCount);
401 DEBUGFS_STATS_ADD(received_fragment_count,
402 local->dot11ReceivedFragmentCount);
403 DEBUGFS_STATS_ADD(multicast_received_frame_count,
404 local->dot11MulticastReceivedFrameCount);
405 DEBUGFS_STATS_ADD(transmitted_frame_count,
406 local->dot11TransmittedFrameCount);
407 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
408 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
409 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
410 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
411 local->tx_handlers_drop_unencrypted);
412 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
413 local->tx_handlers_drop_fragment);
414 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
415 local->tx_handlers_drop_wep);
416 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
417 local->tx_handlers_drop_not_assoc);
418 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
419 local->tx_handlers_drop_unauth_port);
420 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
421 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
422 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
423 local->rx_handlers_drop_nullfunc);
424 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
425 local->rx_handlers_drop_defrag);
426 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
427 local->rx_handlers_drop_short);
428 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
429 local->rx_handlers_drop_passive_scan);
430 DEBUGFS_STATS_ADD(tx_expand_skb_head,
431 local->tx_expand_skb_head);
432 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
433 local->tx_expand_skb_head_cloned);
434 DEBUGFS_STATS_ADD(rx_expand_skb_head,
435 local->rx_expand_skb_head);
436 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
437 local->rx_expand_skb_head2);
438 DEBUGFS_STATS_ADD(rx_handlers_fragments,
439 local->rx_handlers_fragments);
440 DEBUGFS_STATS_ADD(tx_status_drop,
441 local->tx_status_drop);
442 #endif
443 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
444 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
445 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
446 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
447 }
This page took 0.060321 seconds and 5 git commands to generate.