blob: 1f02e599a3185c06de0b214711eece19ff82c136 [file] [log] [blame]
Johannes Berg7bcfaf22009-10-27 12:59:03 +01001
Jiri Bence9f207f2007-05-05 11:46:38 -07002/*
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"
Johannes Berg24487982009-04-23 18:52:52 +020014#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040015#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070016#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
Eliad Peller07caf9d2010-10-27 14:58:29 +020024#define DEBUGFS_FORMAT_BUFFER_SIZE 100
25
26int mac80211_format_buffer(char __user *userbuf, size_t count,
27 loff_t *ppos, char *fmt, ...)
28{
29 va_list args;
30 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
31 int res;
32
33 va_start(args, fmt);
34 res = vscnprintf(buf, sizeof(buf), fmt, args);
35 va_end(args);
36
37 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
38}
39
40#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
Jiri Bence9f207f2007-05-05 11:46:38 -070041static ssize_t name## _read(struct file *file, char __user *userbuf, \
42 size_t count, loff_t *ppos) \
43{ \
44 struct ieee80211_local *local = file->private_data; \
Jiri Bence9f207f2007-05-05 11:46:38 -070045 \
Eliad Peller07caf9d2010-10-27 14:58:29 +020046 return mac80211_format_buffer(userbuf, count, ppos, \
47 fmt "\n", ##value); \
Jiri Bence9f207f2007-05-05 11:46:38 -070048} \
49 \
50static const struct file_operations name## _ops = { \
51 .read = name## _read, \
52 .open = mac80211_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020053 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -070054};
55
56#define DEBUGFS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +010057 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -070058
Johannes Berg827b1fb2009-03-13 11:44:18 +010059#define DEBUGFS_ADD_MODE(name, mode) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +010060 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -070061
62
Eliad Peller07caf9d2010-10-27 14:58:29 +020063DEBUGFS_READONLY_FILE(frequency, "%d",
Johannes Berg8318d782008-01-24 19:38:38 +010064 local->hw.conf.channel->center_freq);
Eliad Peller07caf9d2010-10-27 14:58:29 +020065DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
Jiri Bence9f207f2007-05-05 11:46:38 -070066 local->total_ps_buffered);
Eliad Peller07caf9d2010-10-27 14:58:29 +020067DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
Jiri Bence9f207f2007-05-05 11:46:38 -070068 local->wep_iv & 0xffffff);
Eliad Peller07caf9d2010-10-27 14:58:29 +020069DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
Johannes Bergaf65cd962009-11-17 18:18:36 +010070 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010071
72static ssize_t tsf_read(struct file *file, char __user *user_buf,
73 size_t count, loff_t *ppos)
74{
75 struct ieee80211_local *local = file->private_data;
Johannes Berg24487982009-04-23 18:52:52 +020076 u64 tsf;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010077
Johannes Berg24487982009-04-23 18:52:52 +020078 tsf = drv_get_tsf(local);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010079
Eliad Peller07caf9d2010-10-27 14:58:29 +020080 return mac80211_format_buffer(user_buf, count, ppos, "0x%016llx\n",
81 (unsigned long long) tsf);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010082}
83
84static ssize_t tsf_write(struct file *file,
85 const char __user *user_buf,
86 size_t count, loff_t *ppos)
87{
88 struct ieee80211_local *local = file->private_data;
89 unsigned long long tsf;
90 char buf[100];
91 size_t len;
92
93 len = min(count, sizeof(buf) - 1);
94 if (copy_from_user(buf, user_buf, len))
95 return -EFAULT;
96 buf[len] = '\0';
97
98 if (strncmp(buf, "reset", 5) == 0) {
99 if (local->ops->reset_tsf) {
Johannes Berg24487982009-04-23 18:52:52 +0200100 drv_reset_tsf(local);
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700101 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +0100102 }
103 } else {
104 tsf = simple_strtoul(buf, NULL, 0);
105 if (local->ops->set_tsf) {
Johannes Berg24487982009-04-23 18:52:52 +0200106 drv_set_tsf(local, tsf);
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700107 wiphy_info(local->hw.wiphy,
108 "debugfs set TSF to %#018llx\n", tsf);
109
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +0100110 }
111 }
112
113 return count;
114}
115
116static const struct file_operations tsf_ops = {
117 .read = tsf_read,
118 .write = tsf_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200119 .open = mac80211_open_file_generic,
120 .llseek = default_llseek,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +0100121};
Jiri Bence9f207f2007-05-05 11:46:38 -0700122
Johannes Berg827b1fb2009-03-13 11:44:18 +0100123static ssize_t reset_write(struct file *file, const char __user *user_buf,
124 size_t count, loff_t *ppos)
125{
126 struct ieee80211_local *local = file->private_data;
127
128 rtnl_lock();
129 __ieee80211_suspend(&local->hw);
130 __ieee80211_resume(&local->hw);
131 rtnl_unlock();
132
133 return count;
134}
135
136static const struct file_operations reset_ops = {
137 .write = reset_write,
138 .open = mac80211_open_file_generic,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200139 .llseek = noop_llseek,
Johannes Berg827b1fb2009-03-13 11:44:18 +0100140};
141
Johannes Bergd3707d92009-05-12 22:05:40 +0200142static ssize_t noack_read(struct file *file, char __user *user_buf,
143 size_t count, loff_t *ppos)
144{
145 struct ieee80211_local *local = file->private_data;
Johannes Bergd3707d92009-05-12 22:05:40 +0200146
Eliad Peller07caf9d2010-10-27 14:58:29 +0200147 return mac80211_format_buffer(user_buf, count, ppos, "%d\n",
148 local->wifi_wme_noack_test);
Johannes Bergd3707d92009-05-12 22:05:40 +0200149}
150
151static ssize_t noack_write(struct file *file,
152 const char __user *user_buf,
153 size_t count, loff_t *ppos)
154{
155 struct ieee80211_local *local = file->private_data;
156 char buf[10];
157 size_t len;
158
159 len = min(count, sizeof(buf) - 1);
160 if (copy_from_user(buf, user_buf, len))
161 return -EFAULT;
162 buf[len] = '\0';
163
164 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
165
166 return count;
167}
168
169static const struct file_operations noack_ops = {
170 .read = noack_read,
171 .write = noack_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200172 .open = mac80211_open_file_generic,
173 .llseek = default_llseek,
Johannes Bergd3707d92009-05-12 22:05:40 +0200174};
175
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200176static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
177 size_t count, loff_t *ppos)
178{
179 struct ieee80211_local *local = file->private_data;
Eliad Peller07caf9d2010-10-27 14:58:29 +0200180 return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
181 local->uapsd_queues);
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200182}
183
184static ssize_t uapsd_queues_write(struct file *file,
185 const char __user *user_buf,
186 size_t count, loff_t *ppos)
187{
188 struct ieee80211_local *local = file->private_data;
189 unsigned long val;
190 char buf[10];
191 size_t len;
192 int ret;
193
194 len = min(count, sizeof(buf) - 1);
195 if (copy_from_user(buf, user_buf, len))
196 return -EFAULT;
197 buf[len] = '\0';
198
199 ret = strict_strtoul(buf, 0, &val);
200
201 if (ret)
202 return -EINVAL;
203
204 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
205 return -ERANGE;
206
207 local->uapsd_queues = val;
208
209 return count;
210}
211
212static const struct file_operations uapsd_queues_ops = {
213 .read = uapsd_queues_read,
214 .write = uapsd_queues_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200215 .open = mac80211_open_file_generic,
216 .llseek = default_llseek,
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200217};
218
219static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
220 size_t count, loff_t *ppos)
221{
222 struct ieee80211_local *local = file->private_data;
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200223
Eliad Peller07caf9d2010-10-27 14:58:29 +0200224 return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
225 local->uapsd_max_sp_len);
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200226}
227
228static ssize_t uapsd_max_sp_len_write(struct file *file,
229 const char __user *user_buf,
230 size_t count, loff_t *ppos)
231{
232 struct ieee80211_local *local = file->private_data;
233 unsigned long val;
234 char buf[10];
235 size_t len;
236 int ret;
237
238 len = min(count, sizeof(buf) - 1);
239 if (copy_from_user(buf, user_buf, len))
240 return -EFAULT;
241 buf[len] = '\0';
242
243 ret = strict_strtoul(buf, 0, &val);
244
245 if (ret)
246 return -EINVAL;
247
248 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
249 return -ERANGE;
250
251 local->uapsd_max_sp_len = val;
252
253 return count;
254}
255
256static const struct file_operations uapsd_max_sp_len_ops = {
257 .read = uapsd_max_sp_len_read,
258 .write = uapsd_max_sp_len_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200259 .open = mac80211_open_file_generic,
260 .llseek = default_llseek,
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200261};
262
Benoit Papillault199d69f2010-02-04 22:00:20 +0100263static ssize_t channel_type_read(struct file *file, char __user *user_buf,
264 size_t count, loff_t *ppos)
265{
266 struct ieee80211_local *local = file->private_data;
267 const char *buf;
268
269 switch (local->hw.conf.channel_type) {
270 case NL80211_CHAN_NO_HT:
271 buf = "no ht\n";
272 break;
273 case NL80211_CHAN_HT20:
274 buf = "ht20\n";
275 break;
276 case NL80211_CHAN_HT40MINUS:
277 buf = "ht40-\n";
278 break;
279 case NL80211_CHAN_HT40PLUS:
280 buf = "ht40+\n";
281 break;
282 default:
283 buf = "???";
284 break;
285 }
286
287 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
288}
289
290static const struct file_operations channel_type_ops = {
291 .read = channel_type_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200292 .open = mac80211_open_file_generic,
293 .llseek = default_llseek,
Benoit Papillault199d69f2010-02-04 22:00:20 +0100294};
295
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200296static ssize_t queues_read(struct file *file, char __user *user_buf,
297 size_t count, loff_t *ppos)
298{
299 struct ieee80211_local *local = file->private_data;
300 unsigned long flags;
301 char buf[IEEE80211_MAX_QUEUES * 20];
302 int q, res = 0;
303
304 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
305 for (q = 0; q < local->hw.queues; q++)
306 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
307 local->queue_stop_reasons[q],
Johannes Berg3b8d81e02009-06-17 17:43:56 +0200308 skb_queue_len(&local->pending[q]));
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200309 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
310
311 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
312}
313
314static const struct file_operations queues_ops = {
315 .read = queues_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200316 .open = mac80211_open_file_generic,
317 .llseek = default_llseek,
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200318};
319
Jiri Bence9f207f2007-05-05 11:46:38 -0700320/* statistics stuff */
321
Jiri Bence9f207f2007-05-05 11:46:38 -0700322static ssize_t format_devstat_counter(struct ieee80211_local *local,
323 char __user *userbuf,
324 size_t count, loff_t *ppos,
325 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
326 int buflen))
327{
328 struct ieee80211_low_level_stats stats;
329 char buf[20];
330 int res;
331
Johannes Berg75636522008-07-09 14:40:35 +0200332 rtnl_lock();
Johannes Berg24487982009-04-23 18:52:52 +0200333 res = drv_get_stats(local, &stats);
Jiri Bence9f207f2007-05-05 11:46:38 -0700334 rtnl_unlock();
Johannes Berg24487982009-04-23 18:52:52 +0200335 if (res)
336 return res;
337 res = printvalue(&stats, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700338 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
339}
340
341#define DEBUGFS_DEVSTATS_FILE(name) \
342static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
343 char *buf, int buflen) \
344{ \
345 return scnprintf(buf, buflen, "%u\n", stats->name); \
346} \
347static ssize_t stats_ ##name## _read(struct file *file, \
348 char __user *userbuf, \
349 size_t count, loff_t *ppos) \
350{ \
351 return format_devstat_counter(file->private_data, \
352 userbuf, \
353 count, \
354 ppos, \
355 print_devstats_##name); \
356} \
357 \
358static const struct file_operations stats_ ##name## _ops = { \
359 .read = stats_ ##name## _read, \
360 .open = mac80211_open_file_generic, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200361 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -0700362};
363
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200364#define DEBUGFS_STATS_ADD(name, field) \
365 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
366#define DEBUGFS_DEVSTATS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100367 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700368
Jiri Bence9f207f2007-05-05 11:46:38 -0700369DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
370DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
371DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
372DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
373
Jiri Bence9f207f2007-05-05 11:46:38 -0700374void debugfs_hw_add(struct ieee80211_local *local)
375{
376 struct dentry *phyd = local->hw.wiphy->debugfsdir;
377 struct dentry *statsd;
378
379 if (!phyd)
380 return;
381
Jiri Bence9f207f2007-05-05 11:46:38 -0700382 local->debugfs.keys = debugfs_create_dir("keys", phyd);
383
Jiri Bence9f207f2007-05-05 11:46:38 -0700384 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700385 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700386 DEBUGFS_ADD(wep_iv);
Alina Friedrichsenae54c982009-01-23 05:33:37 +0100387 DEBUGFS_ADD(tsf);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200388 DEBUGFS_ADD(queues);
Johannes Berg827b1fb2009-03-13 11:44:18 +0100389 DEBUGFS_ADD_MODE(reset, 0200);
Johannes Bergd3707d92009-05-12 22:05:40 +0200390 DEBUGFS_ADD(noack);
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200391 DEBUGFS_ADD(uapsd_queues);
392 DEBUGFS_ADD(uapsd_max_sp_len);
Benoit Papillault199d69f2010-02-04 22:00:20 +0100393 DEBUGFS_ADD(channel_type);
Jiri Bence9f207f2007-05-05 11:46:38 -0700394
395 statsd = debugfs_create_dir("statistics", phyd);
Jiri Bence9f207f2007-05-05 11:46:38 -0700396
397 /* if the dir failed, don't put all the other things into the root! */
398 if (!statsd)
399 return;
400
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200401 DEBUGFS_STATS_ADD(transmitted_fragment_count,
402 local->dot11TransmittedFragmentCount);
403 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
404 local->dot11MulticastTransmittedFrameCount);
405 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
406 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
407 DEBUGFS_STATS_ADD(multiple_retry_count,
408 local->dot11MultipleRetryCount);
409 DEBUGFS_STATS_ADD(frame_duplicate_count,
410 local->dot11FrameDuplicateCount);
411 DEBUGFS_STATS_ADD(received_fragment_count,
412 local->dot11ReceivedFragmentCount);
413 DEBUGFS_STATS_ADD(multicast_received_frame_count,
414 local->dot11MulticastReceivedFrameCount);
415 DEBUGFS_STATS_ADD(transmitted_frame_count,
416 local->dot11TransmittedFrameCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700417#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200418 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
419 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
420 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
421 local->tx_handlers_drop_unencrypted);
422 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
423 local->tx_handlers_drop_fragment);
424 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
425 local->tx_handlers_drop_wep);
426 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
427 local->tx_handlers_drop_not_assoc);
428 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
429 local->tx_handlers_drop_unauth_port);
430 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
431 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
432 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
433 local->rx_handlers_drop_nullfunc);
434 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
435 local->rx_handlers_drop_defrag);
436 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
437 local->rx_handlers_drop_short);
438 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
439 local->rx_handlers_drop_passive_scan);
440 DEBUGFS_STATS_ADD(tx_expand_skb_head,
441 local->tx_expand_skb_head);
442 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
443 local->tx_expand_skb_head_cloned);
444 DEBUGFS_STATS_ADD(rx_expand_skb_head,
445 local->rx_expand_skb_head);
446 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
447 local->rx_expand_skb_head2);
448 DEBUGFS_STATS_ADD(rx_handlers_fragments,
449 local->rx_handlers_fragments);
450 DEBUGFS_STATS_ADD(tx_status_drop,
451 local->tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700452#endif
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200453 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
454 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
455 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
456 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700457}