blob: ced6bf3be8d6cf5d3d9fc80b6c46f48c4e567aef [file] [log] [blame]
Jiri Bence9f207f2007-05-05 11:46:38 -07001/*
2 * mac80211 debugfs for wireless PHYs
3 *
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
Johannes Bergd98ad832014-09-03 15:24:57 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Jiri Bence9f207f2007-05-05 11:46:38 -07006 *
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
Eliad Peller07caf9d2010-10-27 14:58:29 +020018#define DEBUGFS_FORMAT_BUFFER_SIZE 100
19
20int mac80211_format_buffer(char __user *userbuf, size_t count,
21 loff_t *ppos, char *fmt, ...)
22{
23 va_list args;
24 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
25 int res;
26
27 va_start(args, fmt);
28 res = vscnprintf(buf, sizeof(buf), fmt, args);
29 va_end(args);
30
31 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
32}
33
Ben Greear279daf62011-03-23 14:04:31 -070034#define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
Jiri Bence9f207f2007-05-05 11:46:38 -070035static ssize_t name## _read(struct file *file, char __user *userbuf, \
36 size_t count, loff_t *ppos) \
37{ \
38 struct ieee80211_local *local = file->private_data; \
Jiri Bence9f207f2007-05-05 11:46:38 -070039 \
Eliad Peller07caf9d2010-10-27 14:58:29 +020040 return mac80211_format_buffer(userbuf, count, ppos, \
41 fmt "\n", ##value); \
Ben Greear279daf62011-03-23 14:04:31 -070042}
43
44#define DEBUGFS_READONLY_FILE_OPS(name) \
Jiri Bence9f207f2007-05-05 11:46:38 -070045static const struct file_operations name## _ops = { \
46 .read = name## _read, \
Stephen Boyd234e3402012-04-05 14:25:11 -070047 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +020048 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -070049};
50
Ben Greear279daf62011-03-23 14:04:31 -070051#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
52 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
53 DEBUGFS_READONLY_FILE_OPS(name)
54
Jiri Bence9f207f2007-05-05 11:46:38 -070055#define DEBUGFS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +010056 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -070057
Johannes Berg827b1fb2009-03-13 11:44:18 +010058#define DEBUGFS_ADD_MODE(name, mode) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +010059 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -070060
61
Ben Greear83bdf2a2011-02-15 13:11:22 -080062DEBUGFS_READONLY_FILE(user_power, "%d",
63 local->user_power_level);
64DEBUGFS_READONLY_FILE(power, "%d",
65 local->hw.conf.power_level);
Eliad Peller07caf9d2010-10-27 14:58:29 +020066DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
Jiri Bence9f207f2007-05-05 11:46:38 -070067 local->total_ps_buffered);
Eliad Peller07caf9d2010-10-27 14:58:29 +020068DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
Jiri Bence9f207f2007-05-05 11:46:38 -070069 local->wep_iv & 0xffffff);
Eliad Peller07caf9d2010-10-27 14:58:29 +020070DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
Johannes Bergaf65cd962009-11-17 18:18:36 +010071 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010072
Johannes Berg2ad48142012-09-19 08:20:24 +020073#ifdef CONFIG_PM
Johannes Berg827b1fb2009-03-13 11:44:18 +010074static ssize_t reset_write(struct file *file, const char __user *user_buf,
75 size_t count, loff_t *ppos)
76{
77 struct ieee80211_local *local = file->private_data;
78
79 rtnl_lock();
Johannes Bergeecc4802011-05-04 15:37:29 +020080 __ieee80211_suspend(&local->hw, NULL);
Johannes Berg827b1fb2009-03-13 11:44:18 +010081 __ieee80211_resume(&local->hw);
82 rtnl_unlock();
83
84 return count;
85}
86
87static const struct file_operations reset_ops = {
88 .write = reset_write,
Stephen Boyd234e3402012-04-05 14:25:11 -070089 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +020090 .llseek = noop_llseek,
Johannes Berg827b1fb2009-03-13 11:44:18 +010091};
Johannes Berg2ad48142012-09-19 08:20:24 +020092#endif
Johannes Berg827b1fb2009-03-13 11:44:18 +010093
Johannes Berg30686bf2015-06-02 21:39:54 +020094static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = {
95#define FLAG(F) [IEEE80211_HW_##F] = #F
96 FLAG(HAS_RATE_CONTROL),
97 FLAG(RX_INCLUDES_FCS),
98 FLAG(HOST_BROADCAST_PS_BUFFERING),
99 FLAG(SIGNAL_UNSPEC),
100 FLAG(SIGNAL_DBM),
101 FLAG(NEED_DTIM_BEFORE_ASSOC),
102 FLAG(SPECTRUM_MGMT),
103 FLAG(AMPDU_AGGREGATION),
104 FLAG(SUPPORTS_PS),
105 FLAG(PS_NULLFUNC_STACK),
106 FLAG(SUPPORTS_DYNAMIC_PS),
107 FLAG(MFP_CAPABLE),
108 FLAG(WANT_MONITOR_VIF),
109 FLAG(NO_AUTO_VIF),
110 FLAG(SW_CRYPTO_CONTROL),
111 FLAG(SUPPORT_FAST_XMIT),
112 FLAG(REPORTS_TX_ACK_STATUS),
113 FLAG(CONNECTION_MONITOR),
114 FLAG(QUEUE_CONTROL),
115 FLAG(SUPPORTS_PER_STA_GTK),
116 FLAG(AP_LINK_PS),
117 FLAG(TX_AMPDU_SETUP_IN_HW),
118 FLAG(SUPPORTS_RC_TABLE),
119 FLAG(P2P_DEV_ADDR_FOR_INTF),
120 FLAG(TIMING_BEACON_ONLY),
121 FLAG(SUPPORTS_HT_CCK_RATES),
122 FLAG(CHANCTX_STA_CSA),
123 FLAG(SUPPORTS_CLONED_SKBS),
124 FLAG(SINGLE_SCAN_ON_ALL_BANDS),
Arik Nemtsovb98fb442015-06-10 20:42:59 +0300125 FLAG(TDLS_WIDER_BW),
Johannes Berg30686bf2015-06-02 21:39:54 +0200126
127 /* keep last for the build bug below */
128 (void *)0x1
129#undef FLAG
130};
131
Ben Greear279daf62011-03-23 14:04:31 -0700132static ssize_t hwflags_read(struct file *file, char __user *user_buf,
133 size_t count, loff_t *ppos)
134{
135 struct ieee80211_local *local = file->private_data;
Johannes Berg30686bf2015-06-02 21:39:54 +0200136 size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS;
137 char *buf = kzalloc(bufsz, GFP_KERNEL);
138 char *pos = buf, *end = buf + bufsz - 1;
Ben Greear279daf62011-03-23 14:04:31 -0700139 ssize_t rv;
Johannes Berg30686bf2015-06-02 21:39:54 +0200140 int i;
Ben Greear279daf62011-03-23 14:04:31 -0700141
Joe Perchesd15b8452011-08-29 14:17:31 -0700142 if (!buf)
Johannes Berg30686bf2015-06-02 21:39:54 +0200143 return -ENOMEM;
Joe Perchesd15b8452011-08-29 14:17:31 -0700144
Johannes Berg30686bf2015-06-02 21:39:54 +0200145 /* fail compilation if somebody adds or removes
146 * a flag without updating the name array above
147 */
148 BUILD_BUG_ON(hw_flag_names[NUM_IEEE80211_HW_FLAGS] != (void *)0x1);
149
150 for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
151 if (test_bit(i, local->hw.flags))
152 pos += scnprintf(pos, end - pos, "%s",
153 hw_flag_names[i]);
154 }
Ben Greear279daf62011-03-23 14:04:31 -0700155
156 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
157 kfree(buf);
158 return rv;
159}
Benoit Papillault199d69f2010-02-04 22:00:20 +0100160
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200161static ssize_t 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 unsigned long flags;
166 char buf[IEEE80211_MAX_QUEUES * 20];
167 int q, res = 0;
168
169 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
170 for (q = 0; q < local->hw.queues; q++)
171 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
172 local->queue_stop_reasons[q],
Johannes Berg3b8d81e02009-06-17 17:43:56 +0200173 skb_queue_len(&local->pending[q]));
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200174 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
175
176 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
177}
178
Ben Greear279daf62011-03-23 14:04:31 -0700179DEBUGFS_READONLY_FILE_OPS(hwflags);
Ben Greear279daf62011-03-23 14:04:31 -0700180DEBUGFS_READONLY_FILE_OPS(queues);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200181
Jiri Bence9f207f2007-05-05 11:46:38 -0700182/* statistics stuff */
183
Jiri Bence9f207f2007-05-05 11:46:38 -0700184static ssize_t format_devstat_counter(struct ieee80211_local *local,
185 char __user *userbuf,
186 size_t count, loff_t *ppos,
187 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
188 int buflen))
189{
190 struct ieee80211_low_level_stats stats;
191 char buf[20];
192 int res;
193
Johannes Berg75636522008-07-09 14:40:35 +0200194 rtnl_lock();
Johannes Berg24487982009-04-23 18:52:52 +0200195 res = drv_get_stats(local, &stats);
Jiri Bence9f207f2007-05-05 11:46:38 -0700196 rtnl_unlock();
Johannes Berg24487982009-04-23 18:52:52 +0200197 if (res)
198 return res;
199 res = printvalue(&stats, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700200 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
201}
202
203#define DEBUGFS_DEVSTATS_FILE(name) \
204static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
205 char *buf, int buflen) \
206{ \
207 return scnprintf(buf, buflen, "%u\n", stats->name); \
208} \
209static ssize_t stats_ ##name## _read(struct file *file, \
210 char __user *userbuf, \
211 size_t count, loff_t *ppos) \
212{ \
213 return format_devstat_counter(file->private_data, \
214 userbuf, \
215 count, \
216 ppos, \
217 print_devstats_##name); \
218} \
219 \
220static const struct file_operations stats_ ##name## _ops = { \
221 .read = stats_ ##name## _read, \
Stephen Boyd234e3402012-04-05 14:25:11 -0700222 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200223 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -0700224};
225
Johannes Bergf1160432015-04-22 20:25:20 +0200226#define DEBUGFS_STATS_ADD(name) \
227 debugfs_create_u32(#name, 0400, statsd, &local->name);
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200228#define DEBUGFS_DEVSTATS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100229 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700230
Jiri Bence9f207f2007-05-05 11:46:38 -0700231DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
232DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
233DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
234DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
235
Jiri Bence9f207f2007-05-05 11:46:38 -0700236void debugfs_hw_add(struct ieee80211_local *local)
237{
238 struct dentry *phyd = local->hw.wiphy->debugfsdir;
239 struct dentry *statsd;
240
241 if (!phyd)
242 return;
243
Jiri Bence9f207f2007-05-05 11:46:38 -0700244 local->debugfs.keys = debugfs_create_dir("keys", phyd);
245
Jiri Bence9f207f2007-05-05 11:46:38 -0700246 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700247 DEBUGFS_ADD(wep_iv);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200248 DEBUGFS_ADD(queues);
Johannes Berg2ad48142012-09-19 08:20:24 +0200249#ifdef CONFIG_PM
Johannes Berg827b1fb2009-03-13 11:44:18 +0100250 DEBUGFS_ADD_MODE(reset, 0200);
Johannes Berg2ad48142012-09-19 08:20:24 +0200251#endif
Ben Greear279daf62011-03-23 14:04:31 -0700252 DEBUGFS_ADD(hwflags);
Ben Greear83bdf2a2011-02-15 13:11:22 -0800253 DEBUGFS_ADD(user_power);
254 DEBUGFS_ADD(power);
Jiri Bence9f207f2007-05-05 11:46:38 -0700255
256 statsd = debugfs_create_dir("statistics", phyd);
Jiri Bence9f207f2007-05-05 11:46:38 -0700257
258 /* if the dir failed, don't put all the other things into the root! */
259 if (!statsd)
260 return;
261
Johannes Bergc206ca62015-04-22 20:47:28 +0200262#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
Johannes Bergf1160432015-04-22 20:25:20 +0200263 DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
264 DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
265 DEBUGFS_STATS_ADD(dot11FailedCount);
266 DEBUGFS_STATS_ADD(dot11RetryCount);
267 DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
268 DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
269 DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
270 DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
271 DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
Johannes Bergf1160432015-04-22 20:25:20 +0200272 DEBUGFS_STATS_ADD(tx_handlers_drop);
273 DEBUGFS_STATS_ADD(tx_handlers_queued);
274 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
275 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
276 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
277 DEBUGFS_STATS_ADD(rx_handlers_drop);
278 DEBUGFS_STATS_ADD(rx_handlers_queued);
279 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
280 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
Johannes Bergf1160432015-04-22 20:25:20 +0200281 DEBUGFS_STATS_ADD(tx_expand_skb_head);
282 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
283 DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
284 DEBUGFS_STATS_ADD(rx_handlers_fragments);
285 DEBUGFS_STATS_ADD(tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700286#endif
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200287 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
288 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
289 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
290 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700291}