Merge tag 'powerpc-3.19-2' of git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux
[deliverable/linux.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>
d98ad83e 6 * Copyright 2013-2014 Intel Mobile Communications GmbH
e9f207f0
JB
7 *
8 * GPLv2
9 *
10 */
11
12#include <linux/debugfs.h>
13#include <linux/rtnetlink.h>
14#include "ieee80211_i.h"
24487981 15#include "driver-ops.h"
2c8dccc7 16#include "rate.h"
e9f207f0
JB
17#include "debugfs.h"
18
07caf9d6
EP
19#define DEBUGFS_FORMAT_BUFFER_SIZE 100
20
ad38bfc9
MG
21#define TX_LATENCY_BIN_DELIMTER_C ','
22#define TX_LATENCY_BIN_DELIMTER_S ","
23#define TX_LATENCY_BINS_DISABLED "enable(bins disabled)\n"
24#define TX_LATENCY_DISABLED "disable\n"
25
26
27/*
28 * Display if Tx latency statistics & bins are enabled/disabled
29 */
30static ssize_t sta_tx_latency_stat_read(struct file *file,
31 char __user *userbuf,
32 size_t count, loff_t *ppos)
33{
34 struct ieee80211_local *local = file->private_data;
35 struct ieee80211_tx_latency_bin_ranges *tx_latency;
36 char *buf;
37 int bufsz, i, ret;
38 int pos = 0;
39
40 rcu_read_lock();
41
42 tx_latency = rcu_dereference(local->tx_latency);
43
44 if (tx_latency && tx_latency->n_ranges) {
45 bufsz = tx_latency->n_ranges * 15;
46 buf = kzalloc(bufsz, GFP_ATOMIC);
47 if (!buf)
48 goto err;
49
50 for (i = 0; i < tx_latency->n_ranges; i++)
51 pos += scnprintf(buf + pos, bufsz - pos, "%d,",
52 tx_latency->ranges[i]);
53 pos += scnprintf(buf + pos, bufsz - pos, "\n");
54 } else if (tx_latency) {
55 bufsz = sizeof(TX_LATENCY_BINS_DISABLED) + 1;
56 buf = kzalloc(bufsz, GFP_ATOMIC);
57 if (!buf)
58 goto err;
59
60 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
61 TX_LATENCY_BINS_DISABLED);
62 } else {
63 bufsz = sizeof(TX_LATENCY_DISABLED) + 1;
64 buf = kzalloc(bufsz, GFP_ATOMIC);
65 if (!buf)
66 goto err;
67
68 pos += scnprintf(buf + pos, bufsz - pos, "%s\n",
69 TX_LATENCY_DISABLED);
70 }
71
72 rcu_read_unlock();
73
74 ret = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
75 kfree(buf);
76
77 return ret;
78err:
79 rcu_read_unlock();
80 return -ENOMEM;
81}
82
83/*
84 * Receive input from user regarding Tx latency statistics
85 * The input should indicate if Tx latency statistics and bins are
86 * enabled/disabled.
87 * If bins are enabled input should indicate the amount of different bins and
88 * their ranges. Each bin will count how many Tx frames transmitted within the
89 * appropriate latency.
90 * Legal input is:
91 * a) "enable(bins disabled)" - to enable only general statistics
92 * b) "a,b,c,d,...z" - to enable general statistics and bins, where all are
93 * numbers and a < b < c < d.. < z
94 * c) "disable" - disable all statistics
95 * NOTE: must configure Tx latency statistics bins before stations connected.
96 */
97
98static ssize_t sta_tx_latency_stat_write(struct file *file,
99 const char __user *userbuf,
100 size_t count, loff_t *ppos)
101{
102 struct ieee80211_local *local = file->private_data;
103 char buf[128] = {};
104 char *bins = buf;
105 char *token;
106 int buf_size, i, alloc_size;
107 int prev_bin = 0;
108 int n_ranges = 0;
109 int ret = count;
110 struct ieee80211_tx_latency_bin_ranges *tx_latency;
111
112 if (sizeof(buf) <= count)
113 return -EINVAL;
114 buf_size = count;
115 if (copy_from_user(buf, userbuf, buf_size))
116 return -EFAULT;
117
118 mutex_lock(&local->sta_mtx);
119
120 /* cannot change config once we have stations */
121 if (local->num_sta)
122 goto unlock;
123
124 tx_latency =
125 rcu_dereference_protected(local->tx_latency,
126 lockdep_is_held(&local->sta_mtx));
127
128 /* disable Tx statistics */
129 if (!strcmp(buf, TX_LATENCY_DISABLED)) {
130 if (!tx_latency)
131 goto unlock;
0c2bef46 132 RCU_INIT_POINTER(local->tx_latency, NULL);
ad38bfc9
MG
133 synchronize_rcu();
134 kfree(tx_latency);
135 goto unlock;
136 }
137
138 /* Tx latency already enabled */
139 if (tx_latency)
140 goto unlock;
141
142 if (strcmp(TX_LATENCY_BINS_DISABLED, buf)) {
143 /* check how many bins and between what ranges user requested */
144 token = buf;
145 while (*token != '\0') {
146 if (*token == TX_LATENCY_BIN_DELIMTER_C)
147 n_ranges++;
148 token++;
149 }
150 n_ranges++;
151 }
152
153 alloc_size = sizeof(struct ieee80211_tx_latency_bin_ranges) +
154 n_ranges * sizeof(u32);
155 tx_latency = kzalloc(alloc_size, GFP_ATOMIC);
156 if (!tx_latency) {
157 ret = -ENOMEM;
158 goto unlock;
159 }
160 tx_latency->n_ranges = n_ranges;
161 for (i = 0; i < n_ranges; i++) { /* setting bin ranges */
162 token = strsep(&bins, TX_LATENCY_BIN_DELIMTER_S);
163 sscanf(token, "%d", &tx_latency->ranges[i]);
164 /* bins values should be in ascending order */
165 if (prev_bin >= tx_latency->ranges[i]) {
166 ret = -EINVAL;
167 kfree(tx_latency);
168 goto unlock;
169 }
170 prev_bin = tx_latency->ranges[i];
171 }
172 rcu_assign_pointer(local->tx_latency, tx_latency);
173
174unlock:
175 mutex_unlock(&local->sta_mtx);
176
177 return ret;
178}
179
180static const struct file_operations stats_tx_latency_ops = {
181 .write = sta_tx_latency_stat_write,
182 .read = sta_tx_latency_stat_read,
183 .open = simple_open,
184 .llseek = generic_file_llseek,
185};
186
07caf9d6
EP
187int mac80211_format_buffer(char __user *userbuf, size_t count,
188 loff_t *ppos, char *fmt, ...)
189{
190 va_list args;
191 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
192 int res;
193
194 va_start(args, fmt);
195 res = vscnprintf(buf, sizeof(buf), fmt, args);
196 va_end(args);
197
198 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
199}
200
279daf64 201#define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
e9f207f0
JB
202static ssize_t name## _read(struct file *file, char __user *userbuf, \
203 size_t count, loff_t *ppos) \
204{ \
205 struct ieee80211_local *local = file->private_data; \
e9f207f0 206 \
07caf9d6
EP
207 return mac80211_format_buffer(userbuf, count, ppos, \
208 fmt "\n", ##value); \
279daf64
BG
209}
210
211#define DEBUGFS_READONLY_FILE_OPS(name) \
e9f207f0
JB
212static const struct file_operations name## _ops = { \
213 .read = name## _read, \
234e3405 214 .open = simple_open, \
2b18ab36 215 .llseek = generic_file_llseek, \
e9f207f0
JB
216};
217
279daf64
BG
218#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
219 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
220 DEBUGFS_READONLY_FILE_OPS(name)
221
e9f207f0 222#define DEBUGFS_ADD(name) \
7bcfaf2f 223 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
e9f207f0 224
827b1fb4 225#define DEBUGFS_ADD_MODE(name, mode) \
7bcfaf2f 226 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
e9f207f0
JB
227
228
83bdf2a1
BG
229DEBUGFS_READONLY_FILE(user_power, "%d",
230 local->user_power_level);
231DEBUGFS_READONLY_FILE(power, "%d",
232 local->hw.conf.power_level);
07caf9d6 233DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
e9f207f0 234 local->total_ps_buffered);
07caf9d6 235DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
e9f207f0 236 local->wep_iv & 0xffffff);
07caf9d6 237DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
af65cd96 238 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
3b5d665b 239
2ad4814f 240#ifdef CONFIG_PM
827b1fb4
JB
241static ssize_t reset_write(struct file *file, const char __user *user_buf,
242 size_t count, loff_t *ppos)
243{
244 struct ieee80211_local *local = file->private_data;
245
246 rtnl_lock();
eecc4800 247 __ieee80211_suspend(&local->hw, NULL);
827b1fb4
JB
248 __ieee80211_resume(&local->hw);
249 rtnl_unlock();
250
251 return count;
252}
253
254static const struct file_operations reset_ops = {
255 .write = reset_write,
234e3405 256 .open = simple_open,
6038f373 257 .llseek = noop_llseek,
827b1fb4 258};
2ad4814f 259#endif
827b1fb4 260
279daf64
BG
261static ssize_t hwflags_read(struct file *file, char __user *user_buf,
262 size_t count, loff_t *ppos)
263{
264 struct ieee80211_local *local = file->private_data;
265 int mxln = 500;
266 ssize_t rv;
267 char *buf = kzalloc(mxln, GFP_KERNEL);
268 int sf = 0; /* how many written so far */
269
d15b8459
JP
270 if (!buf)
271 return 0;
272
f364ef99 273 sf += scnprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
279daf64 274 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
f364ef99 275 sf += scnprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
279daf64 276 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
f364ef99 277 sf += scnprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
279daf64 278 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
f364ef99
EP
279 sf += scnprintf(buf + sf, mxln - sf,
280 "HOST_BCAST_PS_BUFFERING\n");
279daf64 281 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
f364ef99
EP
282 sf += scnprintf(buf + sf, mxln - sf,
283 "2GHZ_SHORT_SLOT_INCAPABLE\n");
279daf64 284 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
f364ef99
EP
285 sf += scnprintf(buf + sf, mxln - sf,
286 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
279daf64 287 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
f364ef99 288 sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
279daf64 289 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
f364ef99 290 sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
c65dd147 291 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC)
f364ef99
EP
292 sf += scnprintf(buf + sf, mxln - sf,
293 "NEED_DTIM_BEFORE_ASSOC\n");
279daf64 294 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
f364ef99 295 sf += scnprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
279daf64 296 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
f364ef99 297 sf += scnprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
279daf64 298 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
f364ef99 299 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
279daf64 300 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
f364ef99 301 sf += scnprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
279daf64 302 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
f364ef99 303 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
279daf64 304 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
f364ef99 305 sf += scnprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
279daf64 306 if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
f364ef99 307 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
279daf64 308 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
f364ef99
EP
309 sf += scnprintf(buf + sf, mxln - sf,
310 "REPORTS_TX_ACK_STATUS\n");
279daf64 311 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
f364ef99 312 sf += scnprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
279daf64 313 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
f364ef99 314 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
279daf64 315 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
f364ef99 316 sf += scnprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
edf6b784 317 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
f364ef99 318 sf += scnprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
279daf64
BG
319
320 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
321 kfree(buf);
322 return rv;
323}
199d69f2 324
db2e6bd4
JB
325static ssize_t queues_read(struct file *file, char __user *user_buf,
326 size_t count, loff_t *ppos)
327{
328 struct ieee80211_local *local = file->private_data;
329 unsigned long flags;
330 char buf[IEEE80211_MAX_QUEUES * 20];
331 int q, res = 0;
332
333 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
334 for (q = 0; q < local->hw.queues; q++)
335 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
336 local->queue_stop_reasons[q],
3b8d81e0 337 skb_queue_len(&local->pending[q]));
db2e6bd4
JB
338 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
339
340 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
341}
342
279daf64 343DEBUGFS_READONLY_FILE_OPS(hwflags);
279daf64 344DEBUGFS_READONLY_FILE_OPS(queues);
db2e6bd4 345
e9f207f0
JB
346/* statistics stuff */
347
e9f207f0
JB
348static ssize_t format_devstat_counter(struct ieee80211_local *local,
349 char __user *userbuf,
350 size_t count, loff_t *ppos,
351 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
352 int buflen))
353{
354 struct ieee80211_low_level_stats stats;
355 char buf[20];
356 int res;
357
75636525 358 rtnl_lock();
24487981 359 res = drv_get_stats(local, &stats);
e9f207f0 360 rtnl_unlock();
24487981
JB
361 if (res)
362 return res;
363 res = printvalue(&stats, buf, sizeof(buf));
e9f207f0
JB
364 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
365}
366
367#define DEBUGFS_DEVSTATS_FILE(name) \
368static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
369 char *buf, int buflen) \
370{ \
371 return scnprintf(buf, buflen, "%u\n", stats->name); \
372} \
373static ssize_t stats_ ##name## _read(struct file *file, \
374 char __user *userbuf, \
375 size_t count, loff_t *ppos) \
376{ \
377 return format_devstat_counter(file->private_data, \
378 userbuf, \
379 count, \
380 ppos, \
381 print_devstats_##name); \
382} \
383 \
384static const struct file_operations stats_ ##name## _ops = { \
385 .read = stats_ ##name## _read, \
234e3405 386 .open = simple_open, \
2b18ab36 387 .llseek = generic_file_llseek, \
e9f207f0
JB
388};
389
2826bcd8
FF
390#define DEBUGFS_STATS_ADD(name, field) \
391 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
392#define DEBUGFS_DEVSTATS_ADD(name) \
7bcfaf2f 393 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
e9f207f0 394
e9f207f0
JB
395DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
396DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
397DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
398DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
399
e9f207f0
JB
400void debugfs_hw_add(struct ieee80211_local *local)
401{
402 struct dentry *phyd = local->hw.wiphy->debugfsdir;
403 struct dentry *statsd;
404
405 if (!phyd)
406 return;
407
e9f207f0
JB
408 local->debugfs.keys = debugfs_create_dir("keys", phyd);
409
e9f207f0 410 DEBUGFS_ADD(total_ps_buffered);
e9f207f0 411 DEBUGFS_ADD(wep_iv);
db2e6bd4 412 DEBUGFS_ADD(queues);
2ad4814f 413#ifdef CONFIG_PM
827b1fb4 414 DEBUGFS_ADD_MODE(reset, 0200);
2ad4814f 415#endif
279daf64 416 DEBUGFS_ADD(hwflags);
83bdf2a1
BG
417 DEBUGFS_ADD(user_power);
418 DEBUGFS_ADD(power);
e9f207f0
JB
419
420 statsd = debugfs_create_dir("statistics", phyd);
e9f207f0
JB
421
422 /* if the dir failed, don't put all the other things into the root! */
423 if (!statsd)
424 return;
425
2826bcd8
FF
426 DEBUGFS_STATS_ADD(transmitted_fragment_count,
427 local->dot11TransmittedFragmentCount);
428 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
429 local->dot11MulticastTransmittedFrameCount);
430 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
431 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
432 DEBUGFS_STATS_ADD(multiple_retry_count,
433 local->dot11MultipleRetryCount);
434 DEBUGFS_STATS_ADD(frame_duplicate_count,
435 local->dot11FrameDuplicateCount);
436 DEBUGFS_STATS_ADD(received_fragment_count,
437 local->dot11ReceivedFragmentCount);
438 DEBUGFS_STATS_ADD(multicast_received_frame_count,
439 local->dot11MulticastReceivedFrameCount);
440 DEBUGFS_STATS_ADD(transmitted_frame_count,
441 local->dot11TransmittedFrameCount);
e9f207f0 442#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
2826bcd8
FF
443 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
444 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
445 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
446 local->tx_handlers_drop_unencrypted);
447 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
448 local->tx_handlers_drop_fragment);
449 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
450 local->tx_handlers_drop_wep);
451 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
452 local->tx_handlers_drop_not_assoc);
453 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
454 local->tx_handlers_drop_unauth_port);
455 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
456 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
457 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
458 local->rx_handlers_drop_nullfunc);
459 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
460 local->rx_handlers_drop_defrag);
461 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
462 local->rx_handlers_drop_short);
2826bcd8
FF
463 DEBUGFS_STATS_ADD(tx_expand_skb_head,
464 local->tx_expand_skb_head);
465 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
466 local->tx_expand_skb_head_cloned);
467 DEBUGFS_STATS_ADD(rx_expand_skb_head,
468 local->rx_expand_skb_head);
469 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
470 local->rx_expand_skb_head2);
471 DEBUGFS_STATS_ADD(rx_handlers_fragments,
472 local->rx_handlers_fragments);
473 DEBUGFS_STATS_ADD(tx_status_drop,
474 local->tx_status_drop);
e9f207f0 475#endif
2826bcd8
FF
476 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
477 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
478 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
479 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
ad38bfc9
MG
480
481 DEBUGFS_DEVSTATS_ADD(tx_latency);
e9f207f0 482}
This page took 0.548028 seconds and 5 git commands to generate.