blob: e81ef4e8cb323eeca8ea32492a23cdb96f7a4b43 [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
Jiri Bence9f207f2007-05-05 11:46:38 -070024#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) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +010042 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -070043
Johannes Berg827b1fb2009-03-13 11:44:18 +010044#define DEBUGFS_ADD_MODE(name, mode) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +010045 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -070046
47
Jiri Bence9f207f2007-05-05 11:46:38 -070048DEBUGFS_READONLY_FILE(frequency, 20, "%d",
Johannes Berg8318d782008-01-24 19:38:38 +010049 local->hw.conf.channel->center_freq);
Jiri Bence9f207f2007-05-05 11:46:38 -070050DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
51 local->total_ps_buffered);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010052DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
Jiri Bence9f207f2007-05-05 11:46:38 -070053 local->wep_iv & 0xffffff);
Jiri Bence9f207f2007-05-05 11:46:38 -070054DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
Johannes Bergaf65cd962009-11-17 18:18:36 +010055 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010056
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;
Johannes Berg24487982009-04-23 18:52:52 +020061 u64 tsf;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010062 char buf[100];
63
Johannes Berg24487982009-04-23 18:52:52 +020064 tsf = drv_get_tsf(local);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010065
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) {
Johannes Berg24487982009-04-23 18:52:52 +020087 drv_reset_tsf(local);
Joe Perches0fb9a9e2010-08-20 16:25:38 -070088 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010089 }
90 } else {
91 tsf = simple_strtoul(buf, NULL, 0);
92 if (local->ops->set_tsf) {
Johannes Berg24487982009-04-23 18:52:52 +020093 drv_set_tsf(local, tsf);
Joe Perches0fb9a9e2010-08-20 16:25:38 -070094 wiphy_info(local->hw.wiphy,
95 "debugfs set TSF to %#018llx\n", tsf);
96
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010097 }
98 }
99
100 return count;
101}
102
103static const struct file_operations tsf_ops = {
104 .read = tsf_read,
105 .write = tsf_write,
106 .open = mac80211_open_file_generic
107};
Jiri Bence9f207f2007-05-05 11:46:38 -0700108
Johannes Berg827b1fb2009-03-13 11:44:18 +0100109static ssize_t reset_write(struct file *file, const char __user *user_buf,
110 size_t count, loff_t *ppos)
111{
112 struct ieee80211_local *local = file->private_data;
113
114 rtnl_lock();
115 __ieee80211_suspend(&local->hw);
116 __ieee80211_resume(&local->hw);
117 rtnl_unlock();
118
119 return count;
120}
121
122static const struct file_operations reset_ops = {
123 .write = reset_write,
124 .open = mac80211_open_file_generic,
125};
126
Johannes Bergd3707d92009-05-12 22:05:40 +0200127static ssize_t noack_read(struct file *file, char __user *user_buf,
128 size_t count, loff_t *ppos)
129{
130 struct ieee80211_local *local = file->private_data;
131 int res;
132 char buf[10];
133
134 res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
135
136 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
137}
138
139static ssize_t noack_write(struct file *file,
140 const char __user *user_buf,
141 size_t count, loff_t *ppos)
142{
143 struct ieee80211_local *local = file->private_data;
144 char buf[10];
145 size_t len;
146
147 len = min(count, sizeof(buf) - 1);
148 if (copy_from_user(buf, user_buf, len))
149 return -EFAULT;
150 buf[len] = '\0';
151
152 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
153
154 return count;
155}
156
157static const struct file_operations noack_ops = {
158 .read = noack_read,
159 .write = noack_write,
160 .open = mac80211_open_file_generic
161};
162
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200163static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
164 size_t count, loff_t *ppos)
165{
166 struct ieee80211_local *local = file->private_data;
167 int res;
168 char buf[10];
169
170 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_queues);
171
172 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
173}
174
175static ssize_t uapsd_queues_write(struct file *file,
176 const char __user *user_buf,
177 size_t count, loff_t *ppos)
178{
179 struct ieee80211_local *local = file->private_data;
180 unsigned long val;
181 char buf[10];
182 size_t len;
183 int ret;
184
185 len = min(count, sizeof(buf) - 1);
186 if (copy_from_user(buf, user_buf, len))
187 return -EFAULT;
188 buf[len] = '\0';
189
190 ret = strict_strtoul(buf, 0, &val);
191
192 if (ret)
193 return -EINVAL;
194
195 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
196 return -ERANGE;
197
198 local->uapsd_queues = val;
199
200 return count;
201}
202
203static const struct file_operations uapsd_queues_ops = {
204 .read = uapsd_queues_read,
205 .write = uapsd_queues_write,
206 .open = mac80211_open_file_generic
207};
208
209static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
210 size_t count, loff_t *ppos)
211{
212 struct ieee80211_local *local = file->private_data;
213 int res;
214 char buf[10];
215
216 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_max_sp_len);
217
218 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
219}
220
221static ssize_t uapsd_max_sp_len_write(struct file *file,
222 const char __user *user_buf,
223 size_t count, loff_t *ppos)
224{
225 struct ieee80211_local *local = file->private_data;
226 unsigned long val;
227 char buf[10];
228 size_t len;
229 int ret;
230
231 len = min(count, sizeof(buf) - 1);
232 if (copy_from_user(buf, user_buf, len))
233 return -EFAULT;
234 buf[len] = '\0';
235
236 ret = strict_strtoul(buf, 0, &val);
237
238 if (ret)
239 return -EINVAL;
240
241 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
242 return -ERANGE;
243
244 local->uapsd_max_sp_len = val;
245
246 return count;
247}
248
249static const struct file_operations uapsd_max_sp_len_ops = {
250 .read = uapsd_max_sp_len_read,
251 .write = uapsd_max_sp_len_write,
252 .open = mac80211_open_file_generic
253};
254
Benoit Papillault199d69f2010-02-04 22:00:20 +0100255static ssize_t channel_type_read(struct file *file, char __user *user_buf,
256 size_t count, loff_t *ppos)
257{
258 struct ieee80211_local *local = file->private_data;
259 const char *buf;
260
261 switch (local->hw.conf.channel_type) {
262 case NL80211_CHAN_NO_HT:
263 buf = "no ht\n";
264 break;
265 case NL80211_CHAN_HT20:
266 buf = "ht20\n";
267 break;
268 case NL80211_CHAN_HT40MINUS:
269 buf = "ht40-\n";
270 break;
271 case NL80211_CHAN_HT40PLUS:
272 buf = "ht40+\n";
273 break;
274 default:
275 buf = "???";
276 break;
277 }
278
279 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
280}
281
282static const struct file_operations channel_type_ops = {
283 .read = channel_type_read,
284 .open = mac80211_open_file_generic
285};
286
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200287static ssize_t queues_read(struct file *file, char __user *user_buf,
288 size_t count, loff_t *ppos)
289{
290 struct ieee80211_local *local = file->private_data;
291 unsigned long flags;
292 char buf[IEEE80211_MAX_QUEUES * 20];
293 int q, res = 0;
294
295 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
296 for (q = 0; q < local->hw.queues; q++)
297 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
298 local->queue_stop_reasons[q],
Johannes Berg3b8d81e02009-06-17 17:43:56 +0200299 skb_queue_len(&local->pending[q]));
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200300 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
301
302 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
303}
304
305static const struct file_operations queues_ops = {
306 .read = queues_read,
307 .open = mac80211_open_file_generic
308};
309
Jiri Bence9f207f2007-05-05 11:46:38 -0700310/* statistics stuff */
311
Jiri Bence9f207f2007-05-05 11:46:38 -0700312static ssize_t format_devstat_counter(struct ieee80211_local *local,
313 char __user *userbuf,
314 size_t count, loff_t *ppos,
315 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
316 int buflen))
317{
318 struct ieee80211_low_level_stats stats;
319 char buf[20];
320 int res;
321
Johannes Berg75636522008-07-09 14:40:35 +0200322 rtnl_lock();
Johannes Berg24487982009-04-23 18:52:52 +0200323 res = drv_get_stats(local, &stats);
Jiri Bence9f207f2007-05-05 11:46:38 -0700324 rtnl_unlock();
Johannes Berg24487982009-04-23 18:52:52 +0200325 if (res)
326 return res;
327 res = printvalue(&stats, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700328 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
329}
330
331#define DEBUGFS_DEVSTATS_FILE(name) \
332static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
333 char *buf, int buflen) \
334{ \
335 return scnprintf(buf, buflen, "%u\n", stats->name); \
336} \
337static ssize_t stats_ ##name## _read(struct file *file, \
338 char __user *userbuf, \
339 size_t count, loff_t *ppos) \
340{ \
341 return format_devstat_counter(file->private_data, \
342 userbuf, \
343 count, \
344 ppos, \
345 print_devstats_##name); \
346} \
347 \
348static const struct file_operations stats_ ##name## _ops = { \
349 .read = stats_ ##name## _read, \
350 .open = mac80211_open_file_generic, \
351};
352
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200353#define DEBUGFS_STATS_ADD(name, field) \
354 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
355#define DEBUGFS_DEVSTATS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100356 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700357
Jiri Bence9f207f2007-05-05 11:46:38 -0700358DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
359DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
360DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
361DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
362
Jiri Bence9f207f2007-05-05 11:46:38 -0700363void 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
Jiri Bence9f207f2007-05-05 11:46:38 -0700374 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700375 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700376 DEBUGFS_ADD(wep_iv);
Alina Friedrichsenae54c982009-01-23 05:33:37 +0100377 DEBUGFS_ADD(tsf);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200378 DEBUGFS_ADD(queues);
Johannes Berg827b1fb2009-03-13 11:44:18 +0100379 DEBUGFS_ADD_MODE(reset, 0200);
Johannes Bergd3707d92009-05-12 22:05:40 +0200380 DEBUGFS_ADD(noack);
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200381 DEBUGFS_ADD(uapsd_queues);
382 DEBUGFS_ADD(uapsd_max_sp_len);
Benoit Papillault199d69f2010-02-04 22:00:20 +0100383 DEBUGFS_ADD(channel_type);
Jiri Bence9f207f2007-05-05 11:46:38 -0700384
385 statsd = debugfs_create_dir("statistics", phyd);
Jiri Bence9f207f2007-05-05 11:46:38 -0700386
387 /* if the dir failed, don't put all the other things into the root! */
388 if (!statsd)
389 return;
390
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200391 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);
Jiri Bence9f207f2007-05-05 11:46:38 -0700407#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200408 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);
Jiri Bence9f207f2007-05-05 11:46:38 -0700442#endif
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200443 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
444 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
445 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
446 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700447}