blob: 51f0d780dafadfd300719a3b2f19514940824383 [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 Bergmann2b18ab32010-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
Ben Greear83bdf2a2011-02-15 13:11:22 -080063DEBUGFS_READONLY_FILE(user_power, "%d",
64 local->user_power_level);
65DEBUGFS_READONLY_FILE(power, "%d",
66 local->hw.conf.power_level);
Eliad Peller07caf9d2010-10-27 14:58:29 +020067DEBUGFS_READONLY_FILE(frequency, "%d",
Johannes Berg8318d782008-01-24 19:38:38 +010068 local->hw.conf.channel->center_freq);
Eliad Peller07caf9d2010-10-27 14:58:29 +020069DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
Jiri Bence9f207f2007-05-05 11:46:38 -070070 local->total_ps_buffered);
Eliad Peller07caf9d2010-10-27 14:58:29 +020071DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
Jiri Bence9f207f2007-05-05 11:46:38 -070072 local->wep_iv & 0xffffff);
Eliad Peller07caf9d2010-10-27 14:58:29 +020073DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
Johannes Bergaf65cd92009-11-17 18:18:36 +010074 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010075
76static ssize_t tsf_read(struct file *file, char __user *user_buf,
77 size_t count, loff_t *ppos)
78{
79 struct ieee80211_local *local = file->private_data;
Johannes Berg24487982009-04-23 18:52:52 +020080 u64 tsf;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010081
Johannes Berg24487982009-04-23 18:52:52 +020082 tsf = drv_get_tsf(local);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010083
Eliad Peller07caf9d2010-10-27 14:58:29 +020084 return mac80211_format_buffer(user_buf, count, ppos, "0x%016llx\n",
85 (unsigned long long) tsf);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010086}
87
88static ssize_t tsf_write(struct file *file,
89 const char __user *user_buf,
90 size_t count, loff_t *ppos)
91{
92 struct ieee80211_local *local = file->private_data;
93 unsigned long long tsf;
94 char buf[100];
95 size_t len;
96
97 len = min(count, sizeof(buf) - 1);
98 if (copy_from_user(buf, user_buf, len))
99 return -EFAULT;
100 buf[len] = '\0';
101
102 if (strncmp(buf, "reset", 5) == 0) {
103 if (local->ops->reset_tsf) {
Johannes Berg24487982009-04-23 18:52:52 +0200104 drv_reset_tsf(local);
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700105 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +0100106 }
107 } else {
108 tsf = simple_strtoul(buf, NULL, 0);
109 if (local->ops->set_tsf) {
Johannes Berg24487982009-04-23 18:52:52 +0200110 drv_set_tsf(local, tsf);
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700111 wiphy_info(local->hw.wiphy,
112 "debugfs set TSF to %#018llx\n", tsf);
113
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +0100114 }
115 }
116
117 return count;
118}
119
120static const struct file_operations tsf_ops = {
121 .read = tsf_read,
122 .write = tsf_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200123 .open = mac80211_open_file_generic,
124 .llseek = default_llseek,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +0100125};
Jiri Bence9f207f2007-05-05 11:46:38 -0700126
Johannes Berg827b1fb2009-03-13 11:44:18 +0100127static ssize_t reset_write(struct file *file, const char __user *user_buf,
128 size_t count, loff_t *ppos)
129{
130 struct ieee80211_local *local = file->private_data;
131
132 rtnl_lock();
133 __ieee80211_suspend(&local->hw);
134 __ieee80211_resume(&local->hw);
135 rtnl_unlock();
136
137 return count;
138}
139
140static const struct file_operations reset_ops = {
141 .write = reset_write,
142 .open = mac80211_open_file_generic,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200143 .llseek = noop_llseek,
Johannes Berg827b1fb2009-03-13 11:44:18 +0100144};
145
Johannes Bergd3707d92009-05-12 22:05:40 +0200146static ssize_t noack_read(struct file *file, char __user *user_buf,
147 size_t count, loff_t *ppos)
148{
149 struct ieee80211_local *local = file->private_data;
Johannes Bergd3707d92009-05-12 22:05:40 +0200150
Eliad Peller07caf9d2010-10-27 14:58:29 +0200151 return mac80211_format_buffer(user_buf, count, ppos, "%d\n",
152 local->wifi_wme_noack_test);
Johannes Bergd3707d92009-05-12 22:05:40 +0200153}
154
155static ssize_t noack_write(struct file *file,
156 const char __user *user_buf,
157 size_t count, loff_t *ppos)
158{
159 struct ieee80211_local *local = file->private_data;
160 char buf[10];
161 size_t len;
162
163 len = min(count, sizeof(buf) - 1);
164 if (copy_from_user(buf, user_buf, len))
165 return -EFAULT;
166 buf[len] = '\0';
167
168 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
169
170 return count;
171}
172
173static const struct file_operations noack_ops = {
174 .read = noack_read,
175 .write = noack_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200176 .open = mac80211_open_file_generic,
177 .llseek = default_llseek,
Johannes Bergd3707d92009-05-12 22:05:40 +0200178};
179
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200180static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
181 size_t count, loff_t *ppos)
182{
183 struct ieee80211_local *local = file->private_data;
Eliad Peller07caf9d2010-10-27 14:58:29 +0200184 return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
185 local->uapsd_queues);
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200186}
187
188static ssize_t uapsd_queues_write(struct file *file,
189 const char __user *user_buf,
190 size_t count, loff_t *ppos)
191{
192 struct ieee80211_local *local = file->private_data;
193 unsigned long val;
194 char buf[10];
195 size_t len;
196 int ret;
197
198 len = min(count, sizeof(buf) - 1);
199 if (copy_from_user(buf, user_buf, len))
200 return -EFAULT;
201 buf[len] = '\0';
202
203 ret = strict_strtoul(buf, 0, &val);
204
205 if (ret)
206 return -EINVAL;
207
208 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
209 return -ERANGE;
210
211 local->uapsd_queues = val;
212
213 return count;
214}
215
216static const struct file_operations uapsd_queues_ops = {
217 .read = uapsd_queues_read,
218 .write = uapsd_queues_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200219 .open = mac80211_open_file_generic,
220 .llseek = default_llseek,
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200221};
222
223static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
224 size_t count, loff_t *ppos)
225{
226 struct ieee80211_local *local = file->private_data;
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200227
Eliad Peller07caf9d2010-10-27 14:58:29 +0200228 return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
229 local->uapsd_max_sp_len);
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200230}
231
232static ssize_t uapsd_max_sp_len_write(struct file *file,
233 const char __user *user_buf,
234 size_t count, loff_t *ppos)
235{
236 struct ieee80211_local *local = file->private_data;
237 unsigned long val;
238 char buf[10];
239 size_t len;
240 int ret;
241
242 len = min(count, sizeof(buf) - 1);
243 if (copy_from_user(buf, user_buf, len))
244 return -EFAULT;
245 buf[len] = '\0';
246
247 ret = strict_strtoul(buf, 0, &val);
248
249 if (ret)
250 return -EINVAL;
251
252 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
253 return -ERANGE;
254
255 local->uapsd_max_sp_len = val;
256
257 return count;
258}
259
260static const struct file_operations uapsd_max_sp_len_ops = {
261 .read = uapsd_max_sp_len_read,
262 .write = uapsd_max_sp_len_write,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200263 .open = mac80211_open_file_generic,
264 .llseek = default_llseek,
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200265};
266
Benoit Papillault199d69f2010-02-04 22:00:20 +0100267static ssize_t channel_type_read(struct file *file, char __user *user_buf,
268 size_t count, loff_t *ppos)
269{
270 struct ieee80211_local *local = file->private_data;
271 const char *buf;
272
273 switch (local->hw.conf.channel_type) {
274 case NL80211_CHAN_NO_HT:
275 buf = "no ht\n";
276 break;
277 case NL80211_CHAN_HT20:
278 buf = "ht20\n";
279 break;
280 case NL80211_CHAN_HT40MINUS:
281 buf = "ht40-\n";
282 break;
283 case NL80211_CHAN_HT40PLUS:
284 buf = "ht40+\n";
285 break;
286 default:
287 buf = "???";
288 break;
289 }
290
291 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
292}
293
294static const struct file_operations channel_type_ops = {
295 .read = channel_type_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200296 .open = mac80211_open_file_generic,
297 .llseek = default_llseek,
Benoit Papillault199d69f2010-02-04 22:00:20 +0100298};
299
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200300static ssize_t queues_read(struct file *file, char __user *user_buf,
301 size_t count, loff_t *ppos)
302{
303 struct ieee80211_local *local = file->private_data;
304 unsigned long flags;
305 char buf[IEEE80211_MAX_QUEUES * 20];
306 int q, res = 0;
307
308 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
309 for (q = 0; q < local->hw.queues; q++)
310 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
311 local->queue_stop_reasons[q],
Johannes Berg3b8d81e2009-06-17 17:43:56 +0200312 skb_queue_len(&local->pending[q]));
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200313 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
314
315 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
316}
317
318static const struct file_operations queues_ops = {
319 .read = queues_read,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200320 .open = mac80211_open_file_generic,
321 .llseek = default_llseek,
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200322};
323
Jiri Bence9f207f2007-05-05 11:46:38 -0700324/* statistics stuff */
325
Jiri Bence9f207f2007-05-05 11:46:38 -0700326static ssize_t format_devstat_counter(struct ieee80211_local *local,
327 char __user *userbuf,
328 size_t count, loff_t *ppos,
329 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
330 int buflen))
331{
332 struct ieee80211_low_level_stats stats;
333 char buf[20];
334 int res;
335
Johannes Berg75636522008-07-09 14:40:35 +0200336 rtnl_lock();
Johannes Berg24487982009-04-23 18:52:52 +0200337 res = drv_get_stats(local, &stats);
Jiri Bence9f207f2007-05-05 11:46:38 -0700338 rtnl_unlock();
Johannes Berg24487982009-04-23 18:52:52 +0200339 if (res)
340 return res;
341 res = printvalue(&stats, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700342 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
343}
344
345#define DEBUGFS_DEVSTATS_FILE(name) \
346static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
347 char *buf, int buflen) \
348{ \
349 return scnprintf(buf, buflen, "%u\n", stats->name); \
350} \
351static ssize_t stats_ ##name## _read(struct file *file, \
352 char __user *userbuf, \
353 size_t count, loff_t *ppos) \
354{ \
355 return format_devstat_counter(file->private_data, \
356 userbuf, \
357 count, \
358 ppos, \
359 print_devstats_##name); \
360} \
361 \
362static const struct file_operations stats_ ##name## _ops = { \
363 .read = stats_ ##name## _read, \
364 .open = mac80211_open_file_generic, \
Arnd Bergmann2b18ab32010-07-06 19:05:31 +0200365 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -0700366};
367
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200368#define DEBUGFS_STATS_ADD(name, field) \
369 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
370#define DEBUGFS_DEVSTATS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100371 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700372
Jiri Bence9f207f2007-05-05 11:46:38 -0700373DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
374DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
375DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
376DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
377
Jiri Bence9f207f2007-05-05 11:46:38 -0700378void debugfs_hw_add(struct ieee80211_local *local)
379{
380 struct dentry *phyd = local->hw.wiphy->debugfsdir;
381 struct dentry *statsd;
382
383 if (!phyd)
384 return;
385
Jiri Bence9f207f2007-05-05 11:46:38 -0700386 local->debugfs.keys = debugfs_create_dir("keys", phyd);
387
Jiri Bence9f207f2007-05-05 11:46:38 -0700388 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700389 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700390 DEBUGFS_ADD(wep_iv);
Alina Friedrichsenae54c982009-01-23 05:33:37 +0100391 DEBUGFS_ADD(tsf);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200392 DEBUGFS_ADD(queues);
Johannes Berg827b1fb2009-03-13 11:44:18 +0100393 DEBUGFS_ADD_MODE(reset, 0200);
Johannes Bergd3707d92009-05-12 22:05:40 +0200394 DEBUGFS_ADD(noack);
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200395 DEBUGFS_ADD(uapsd_queues);
396 DEBUGFS_ADD(uapsd_max_sp_len);
Benoit Papillault199d69f2010-02-04 22:00:20 +0100397 DEBUGFS_ADD(channel_type);
Ben Greear83bdf2a2011-02-15 13:11:22 -0800398 DEBUGFS_ADD(user_power);
399 DEBUGFS_ADD(power);
Jiri Bence9f207f2007-05-05 11:46:38 -0700400
401 statsd = debugfs_create_dir("statistics", phyd);
Jiri Bence9f207f2007-05-05 11:46:38 -0700402
403 /* if the dir failed, don't put all the other things into the root! */
404 if (!statsd)
405 return;
406
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200407 DEBUGFS_STATS_ADD(transmitted_fragment_count,
408 local->dot11TransmittedFragmentCount);
409 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
410 local->dot11MulticastTransmittedFrameCount);
411 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
412 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
413 DEBUGFS_STATS_ADD(multiple_retry_count,
414 local->dot11MultipleRetryCount);
415 DEBUGFS_STATS_ADD(frame_duplicate_count,
416 local->dot11FrameDuplicateCount);
417 DEBUGFS_STATS_ADD(received_fragment_count,
418 local->dot11ReceivedFragmentCount);
419 DEBUGFS_STATS_ADD(multicast_received_frame_count,
420 local->dot11MulticastReceivedFrameCount);
421 DEBUGFS_STATS_ADD(transmitted_frame_count,
422 local->dot11TransmittedFrameCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700423#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200424 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
425 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
426 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
427 local->tx_handlers_drop_unencrypted);
428 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
429 local->tx_handlers_drop_fragment);
430 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
431 local->tx_handlers_drop_wep);
432 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
433 local->tx_handlers_drop_not_assoc);
434 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
435 local->tx_handlers_drop_unauth_port);
436 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
437 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
438 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
439 local->rx_handlers_drop_nullfunc);
440 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
441 local->rx_handlers_drop_defrag);
442 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
443 local->rx_handlers_drop_short);
444 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
445 local->rx_handlers_drop_passive_scan);
446 DEBUGFS_STATS_ADD(tx_expand_skb_head,
447 local->tx_expand_skb_head);
448 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
449 local->tx_expand_skb_head_cloned);
450 DEBUGFS_STATS_ADD(rx_expand_skb_head,
451 local->rx_expand_skb_head);
452 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
453 local->rx_expand_skb_head2);
454 DEBUGFS_STATS_ADD(rx_handlers_fragments,
455 local->rx_handlers_fragments);
456 DEBUGFS_STATS_ADD(tx_status_drop,
457 local->tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700458#endif
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200459 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
460 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
461 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
462 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700463}