libertas: don't retry commands
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / mac80211 / debugfs.c
CommitLineData
7bcfaf2f 1
e9f207f0
JB
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"
24487981 14#include "driver-ops.h"
2c8dccc7 15#include "rate.h"
e9f207f0
JB
16#include "debugfs.h"
17
18int mac80211_open_file_generic(struct inode *inode, struct file *file)
19{
20 file->private_data = inode->i_private;
21 return 0;
22}
23
e9f207f0
JB
24#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
25static 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 \
36static const struct file_operations name## _ops = { \
37 .read = name## _read, \
38 .open = mac80211_open_file_generic, \
39};
40
41#define DEBUGFS_ADD(name) \
7bcfaf2f 42 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
e9f207f0 43
827b1fb4 44#define DEBUGFS_ADD_MODE(name, mode) \
7bcfaf2f 45 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
e9f207f0
JB
46
47
e9f207f0 48DEBUGFS_READONLY_FILE(frequency, 20, "%d",
8318d78a 49 local->hw.conf.channel->center_freq);
e9f207f0
JB
50DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
51 local->total_ps_buffered);
3b5d665b 52DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
e9f207f0 53 local->wep_iv & 0xffffff);
e9f207f0 54DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
af65cd96 55 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
3b5d665b
AF
56
57static 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;
24487981 61 u64 tsf;
3b5d665b
AF
62 char buf[100];
63
24487981 64 tsf = drv_get_tsf(local);
3b5d665b
AF
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
71static 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) {
24487981 87 drv_reset_tsf(local);
3b5d665b
AF
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) {
24487981 93 drv_set_tsf(local, tsf);
3b5d665b
AF
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
101static const struct file_operations tsf_ops = {
102 .read = tsf_read,
103 .write = tsf_write,
104 .open = mac80211_open_file_generic
105};
e9f207f0 106
827b1fb4
JB
107static 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
120static const struct file_operations reset_ops = {
121 .write = reset_write,
122 .open = mac80211_open_file_generic,
123};
124
d3707d99
JB
125static 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
137static 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
155static const struct file_operations noack_ops = {
156 .read = noack_read,
157 .write = noack_write,
158 .open = mac80211_open_file_generic
159};
160
50ae0cf1
KV
161static ssize_t uapsd_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 int res;
166 char buf[10];
167
168 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_queues);
169
170 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
171}
172
173static ssize_t uapsd_queues_write(struct file *file,
174 const char __user *user_buf,
175 size_t count, loff_t *ppos)
176{
177 struct ieee80211_local *local = file->private_data;
178 unsigned long val;
179 char buf[10];
180 size_t len;
181 int ret;
182
183 len = min(count, sizeof(buf) - 1);
184 if (copy_from_user(buf, user_buf, len))
185 return -EFAULT;
186 buf[len] = '\0';
187
188 ret = strict_strtoul(buf, 0, &val);
189
190 if (ret)
191 return -EINVAL;
192
193 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
194 return -ERANGE;
195
196 local->uapsd_queues = val;
197
198 return count;
199}
200
201static const struct file_operations uapsd_queues_ops = {
202 .read = uapsd_queues_read,
203 .write = uapsd_queues_write,
204 .open = mac80211_open_file_generic
205};
206
207static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
208 size_t count, loff_t *ppos)
209{
210 struct ieee80211_local *local = file->private_data;
211 int res;
212 char buf[10];
213
214 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_max_sp_len);
215
216 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
217}
218
219static ssize_t uapsd_max_sp_len_write(struct file *file,
220 const char __user *user_buf,
221 size_t count, loff_t *ppos)
222{
223 struct ieee80211_local *local = file->private_data;
224 unsigned long val;
225 char buf[10];
226 size_t len;
227 int ret;
228
229 len = min(count, sizeof(buf) - 1);
230 if (copy_from_user(buf, user_buf, len))
231 return -EFAULT;
232 buf[len] = '\0';
233
234 ret = strict_strtoul(buf, 0, &val);
235
236 if (ret)
237 return -EINVAL;
238
239 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
240 return -ERANGE;
241
242 local->uapsd_max_sp_len = val;
243
244 return count;
245}
246
247static const struct file_operations uapsd_max_sp_len_ops = {
248 .read = uapsd_max_sp_len_read,
249 .write = uapsd_max_sp_len_write,
250 .open = mac80211_open_file_generic
251};
252
db2e6bd4
JB
253static ssize_t queues_read(struct file *file, char __user *user_buf,
254 size_t count, loff_t *ppos)
255{
256 struct ieee80211_local *local = file->private_data;
257 unsigned long flags;
258 char buf[IEEE80211_MAX_QUEUES * 20];
259 int q, res = 0;
260
261 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
262 for (q = 0; q < local->hw.queues; q++)
263 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
264 local->queue_stop_reasons[q],
3b8d81e0 265 skb_queue_len(&local->pending[q]));
db2e6bd4
JB
266 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
267
268 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
269}
270
271static const struct file_operations queues_ops = {
272 .read = queues_read,
273 .open = mac80211_open_file_generic
274};
275
e9f207f0
JB
276/* statistics stuff */
277
e9f207f0
JB
278#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
279 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
280
281static ssize_t format_devstat_counter(struct ieee80211_local *local,
282 char __user *userbuf,
283 size_t count, loff_t *ppos,
284 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
285 int buflen))
286{
287 struct ieee80211_low_level_stats stats;
288 char buf[20];
289 int res;
290
75636525 291 rtnl_lock();
24487981 292 res = drv_get_stats(local, &stats);
e9f207f0 293 rtnl_unlock();
24487981
JB
294 if (res)
295 return res;
296 res = printvalue(&stats, buf, sizeof(buf));
e9f207f0
JB
297 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
298}
299
300#define DEBUGFS_DEVSTATS_FILE(name) \
301static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
302 char *buf, int buflen) \
303{ \
304 return scnprintf(buf, buflen, "%u\n", stats->name); \
305} \
306static ssize_t stats_ ##name## _read(struct file *file, \
307 char __user *userbuf, \
308 size_t count, loff_t *ppos) \
309{ \
310 return format_devstat_counter(file->private_data, \
311 userbuf, \
312 count, \
313 ppos, \
314 print_devstats_##name); \
315} \
316 \
317static const struct file_operations stats_ ##name## _ops = { \
318 .read = stats_ ##name## _read, \
319 .open = mac80211_open_file_generic, \
320};
321
322#define DEBUGFS_STATS_ADD(name) \
7bcfaf2f 323 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
e9f207f0
JB
324
325DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
326 local->dot11TransmittedFragmentCount);
327DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
328 local->dot11MulticastTransmittedFrameCount);
329DEBUGFS_STATS_FILE(failed_count, 20, "%u",
330 local->dot11FailedCount);
331DEBUGFS_STATS_FILE(retry_count, 20, "%u",
332 local->dot11RetryCount);
333DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
334 local->dot11MultipleRetryCount);
335DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
336 local->dot11FrameDuplicateCount);
337DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
338 local->dot11ReceivedFragmentCount);
339DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
340 local->dot11MulticastReceivedFrameCount);
341DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
342 local->dot11TransmittedFrameCount);
e9f207f0
JB
343#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
344DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
345 local->tx_handlers_drop);
346DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
347 local->tx_handlers_queued);
348DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
349 local->tx_handlers_drop_unencrypted);
350DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
351 local->tx_handlers_drop_fragment);
352DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
353 local->tx_handlers_drop_wep);
354DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
355 local->tx_handlers_drop_not_assoc);
356DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
357 local->tx_handlers_drop_unauth_port);
358DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
359 local->rx_handlers_drop);
360DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
361 local->rx_handlers_queued);
362DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
363 local->rx_handlers_drop_nullfunc);
364DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
365 local->rx_handlers_drop_defrag);
366DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
367 local->rx_handlers_drop_short);
368DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
369 local->rx_handlers_drop_passive_scan);
370DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
371 local->tx_expand_skb_head);
372DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
373 local->tx_expand_skb_head_cloned);
374DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
375 local->rx_expand_skb_head);
376DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
377 local->rx_expand_skb_head2);
378DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
379 local->rx_handlers_fragments);
380DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
381 local->tx_status_drop);
382
e9f207f0
JB
383#endif
384
385DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
386DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
387DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
388DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
389
390
391void debugfs_hw_add(struct ieee80211_local *local)
392{
393 struct dentry *phyd = local->hw.wiphy->debugfsdir;
394 struct dentry *statsd;
395
396 if (!phyd)
397 return;
398
399 local->debugfs.stations = debugfs_create_dir("stations", phyd);
400 local->debugfs.keys = debugfs_create_dir("keys", phyd);
401
e9f207f0 402 DEBUGFS_ADD(frequency);
e9f207f0 403 DEBUGFS_ADD(total_ps_buffered);
e9f207f0 404 DEBUGFS_ADD(wep_iv);
ae54c985 405 DEBUGFS_ADD(tsf);
db2e6bd4 406 DEBUGFS_ADD(queues);
827b1fb4 407 DEBUGFS_ADD_MODE(reset, 0200);
d3707d99 408 DEBUGFS_ADD(noack);
50ae0cf1
KV
409 DEBUGFS_ADD(uapsd_queues);
410 DEBUGFS_ADD(uapsd_max_sp_len);
e9f207f0
JB
411
412 statsd = debugfs_create_dir("statistics", phyd);
e9f207f0
JB
413
414 /* if the dir failed, don't put all the other things into the root! */
415 if (!statsd)
416 return;
417
418 DEBUGFS_STATS_ADD(transmitted_fragment_count);
419 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
420 DEBUGFS_STATS_ADD(failed_count);
421 DEBUGFS_STATS_ADD(retry_count);
422 DEBUGFS_STATS_ADD(multiple_retry_count);
423 DEBUGFS_STATS_ADD(frame_duplicate_count);
424 DEBUGFS_STATS_ADD(received_fragment_count);
425 DEBUGFS_STATS_ADD(multicast_received_frame_count);
426 DEBUGFS_STATS_ADD(transmitted_frame_count);
e9f207f0
JB
427#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
428 DEBUGFS_STATS_ADD(tx_handlers_drop);
429 DEBUGFS_STATS_ADD(tx_handlers_queued);
430 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
431 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
432 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
433 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
434 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
435 DEBUGFS_STATS_ADD(rx_handlers_drop);
436 DEBUGFS_STATS_ADD(rx_handlers_queued);
437 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
438 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
439 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
440 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
441 DEBUGFS_STATS_ADD(tx_expand_skb_head);
442 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
443 DEBUGFS_STATS_ADD(rx_expand_skb_head);
444 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
445 DEBUGFS_STATS_ADD(rx_handlers_fragments);
446 DEBUGFS_STATS_ADD(tx_status_drop);
e9f207f0
JB
447#endif
448 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
449 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
450 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
451 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
452}