blob: 778e5916d7c3e140ccc3cb98012b39204e3003c7 [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
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 Bergmann2b18ab32010-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(frequency, "%d",
Johannes Berg8318d782008-01-24 19:38:38 +010067 local->hw.conf.channel->center_freq);
Eliad Peller07caf9d2010-10-27 14:58:29 +020068DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
Jiri Bence9f207f2007-05-05 11:46:38 -070069 local->total_ps_buffered);
Eliad Peller07caf9d2010-10-27 14:58:29 +020070DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
Jiri Bence9f207f2007-05-05 11:46:38 -070071 local->wep_iv & 0xffffff);
Eliad Peller07caf9d2010-10-27 14:58:29 +020072DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
Johannes Bergaf65cd92009-11-17 18:18:36 +010073 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +010074
Johannes Berg827b1fb2009-03-13 11:44:18 +010075static ssize_t reset_write(struct file *file, const char __user *user_buf,
76 size_t count, loff_t *ppos)
77{
78 struct ieee80211_local *local = file->private_data;
79
80 rtnl_lock();
Johannes Bergeecc4802011-05-04 15:37:29 +020081 __ieee80211_suspend(&local->hw, NULL);
Johannes Berg827b1fb2009-03-13 11:44:18 +010082 __ieee80211_resume(&local->hw);
83 rtnl_unlock();
84
85 return count;
86}
87
88static const struct file_operations reset_ops = {
89 .write = reset_write,
Stephen Boyd234e3402012-04-05 14:25:11 -070090 .open = simple_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +020091 .llseek = noop_llseek,
Johannes Berg827b1fb2009-03-13 11:44:18 +010092};
93
Benoit Papillault199d69f2010-02-04 22:00:20 +010094static ssize_t channel_type_read(struct file *file, char __user *user_buf,
95 size_t count, loff_t *ppos)
96{
97 struct ieee80211_local *local = file->private_data;
98 const char *buf;
99
100 switch (local->hw.conf.channel_type) {
101 case NL80211_CHAN_NO_HT:
102 buf = "no ht\n";
103 break;
104 case NL80211_CHAN_HT20:
105 buf = "ht20\n";
106 break;
107 case NL80211_CHAN_HT40MINUS:
108 buf = "ht40-\n";
109 break;
110 case NL80211_CHAN_HT40PLUS:
111 buf = "ht40+\n";
112 break;
113 default:
114 buf = "???";
115 break;
116 }
117
118 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
119}
120
Ben Greear279daf62011-03-23 14:04:31 -0700121static ssize_t hwflags_read(struct file *file, char __user *user_buf,
122 size_t count, loff_t *ppos)
123{
124 struct ieee80211_local *local = file->private_data;
125 int mxln = 500;
126 ssize_t rv;
127 char *buf = kzalloc(mxln, GFP_KERNEL);
128 int sf = 0; /* how many written so far */
129
Joe Perchesd15b8452011-08-29 14:17:31 -0700130 if (!buf)
131 return 0;
132
Ben Greear279daf62011-03-23 14:04:31 -0700133 sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
134 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
135 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
136 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
137 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
138 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
139 sf += snprintf(buf + sf, mxln - sf,
140 "HOST_BCAST_PS_BUFFERING\n");
141 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
142 sf += snprintf(buf + sf, mxln - sf,
143 "2GHZ_SHORT_SLOT_INCAPABLE\n");
144 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
145 sf += snprintf(buf + sf, mxln - sf,
146 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
147 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
148 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
149 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
150 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
151 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
152 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n");
153 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
154 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
155 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
156 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
157 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
158 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
159 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
160 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
161 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
162 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
163 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
164 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
Ben Greear279daf62011-03-23 14:04:31 -0700165 if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
166 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
167 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
168 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
169 if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
170 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
171 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
172 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
173 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
174 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
Ben Greear279daf62011-03-23 14:04:31 -0700175 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
176 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
177 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
178 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
Arik Nemtsovedf6b782011-08-30 09:32:38 +0300179 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
180 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
Eliad Peller885bd8e2012-02-02 17:44:55 +0200181 if (local->hw.flags & IEEE80211_HW_SCAN_WHILE_IDLE)
182 sf += snprintf(buf + sf, mxln - sf, "SCAN_WHILE_IDLE\n");
Ben Greear279daf62011-03-23 14:04:31 -0700183
184 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
185 kfree(buf);
186 return rv;
187}
Benoit Papillault199d69f2010-02-04 22:00:20 +0100188
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200189static ssize_t queues_read(struct file *file, char __user *user_buf,
190 size_t count, loff_t *ppos)
191{
192 struct ieee80211_local *local = file->private_data;
193 unsigned long flags;
194 char buf[IEEE80211_MAX_QUEUES * 20];
195 int q, res = 0;
196
197 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
198 for (q = 0; q < local->hw.queues; q++)
199 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
200 local->queue_stop_reasons[q],
Johannes Berg3b8d81e2009-06-17 17:43:56 +0200201 skb_queue_len(&local->pending[q]));
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200202 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
203
204 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
205}
206
Ben Greear279daf62011-03-23 14:04:31 -0700207DEBUGFS_READONLY_FILE_OPS(hwflags);
208DEBUGFS_READONLY_FILE_OPS(channel_type);
209DEBUGFS_READONLY_FILE_OPS(queues);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200210
Jiri Bence9f207f2007-05-05 11:46:38 -0700211/* statistics stuff */
212
Jiri Bence9f207f2007-05-05 11:46:38 -0700213static ssize_t format_devstat_counter(struct ieee80211_local *local,
214 char __user *userbuf,
215 size_t count, loff_t *ppos,
216 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
217 int buflen))
218{
219 struct ieee80211_low_level_stats stats;
220 char buf[20];
221 int res;
222
Johannes Berg75636522008-07-09 14:40:35 +0200223 rtnl_lock();
Johannes Berg24487982009-04-23 18:52:52 +0200224 res = drv_get_stats(local, &stats);
Jiri Bence9f207f2007-05-05 11:46:38 -0700225 rtnl_unlock();
Johannes Berg24487982009-04-23 18:52:52 +0200226 if (res)
227 return res;
228 res = printvalue(&stats, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700229 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
230}
231
232#define DEBUGFS_DEVSTATS_FILE(name) \
233static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
234 char *buf, int buflen) \
235{ \
236 return scnprintf(buf, buflen, "%u\n", stats->name); \
237} \
238static ssize_t stats_ ##name## _read(struct file *file, \
239 char __user *userbuf, \
240 size_t count, loff_t *ppos) \
241{ \
242 return format_devstat_counter(file->private_data, \
243 userbuf, \
244 count, \
245 ppos, \
246 print_devstats_##name); \
247} \
248 \
249static const struct file_operations stats_ ##name## _ops = { \
250 .read = stats_ ##name## _read, \
Stephen Boyd234e3402012-04-05 14:25:11 -0700251 .open = simple_open, \
Arnd Bergmann2b18ab32010-07-06 19:05:31 +0200252 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -0700253};
254
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200255#define DEBUGFS_STATS_ADD(name, field) \
256 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
257#define DEBUGFS_DEVSTATS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100258 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700259
Jiri Bence9f207f2007-05-05 11:46:38 -0700260DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
261DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
262DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
263DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
264
Jiri Bence9f207f2007-05-05 11:46:38 -0700265void debugfs_hw_add(struct ieee80211_local *local)
266{
267 struct dentry *phyd = local->hw.wiphy->debugfsdir;
268 struct dentry *statsd;
269
270 if (!phyd)
271 return;
272
Jiri Bence9f207f2007-05-05 11:46:38 -0700273 local->debugfs.keys = debugfs_create_dir("keys", phyd);
274
Jiri Bence9f207f2007-05-05 11:46:38 -0700275 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700276 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700277 DEBUGFS_ADD(wep_iv);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200278 DEBUGFS_ADD(queues);
Johannes Berg827b1fb2009-03-13 11:44:18 +0100279 DEBUGFS_ADD_MODE(reset, 0200);
Benoit Papillault199d69f2010-02-04 22:00:20 +0100280 DEBUGFS_ADD(channel_type);
Ben Greear279daf62011-03-23 14:04:31 -0700281 DEBUGFS_ADD(hwflags);
Ben Greear83bdf2a2011-02-15 13:11:22 -0800282 DEBUGFS_ADD(user_power);
283 DEBUGFS_ADD(power);
Jiri Bence9f207f2007-05-05 11:46:38 -0700284
285 statsd = debugfs_create_dir("statistics", phyd);
Jiri Bence9f207f2007-05-05 11:46:38 -0700286
287 /* if the dir failed, don't put all the other things into the root! */
288 if (!statsd)
289 return;
290
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200291 DEBUGFS_STATS_ADD(transmitted_fragment_count,
292 local->dot11TransmittedFragmentCount);
293 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
294 local->dot11MulticastTransmittedFrameCount);
295 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
296 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
297 DEBUGFS_STATS_ADD(multiple_retry_count,
298 local->dot11MultipleRetryCount);
299 DEBUGFS_STATS_ADD(frame_duplicate_count,
300 local->dot11FrameDuplicateCount);
301 DEBUGFS_STATS_ADD(received_fragment_count,
302 local->dot11ReceivedFragmentCount);
303 DEBUGFS_STATS_ADD(multicast_received_frame_count,
304 local->dot11MulticastReceivedFrameCount);
305 DEBUGFS_STATS_ADD(transmitted_frame_count,
306 local->dot11TransmittedFrameCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700307#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200308 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
309 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
310 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
311 local->tx_handlers_drop_unencrypted);
312 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
313 local->tx_handlers_drop_fragment);
314 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
315 local->tx_handlers_drop_wep);
316 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
317 local->tx_handlers_drop_not_assoc);
318 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
319 local->tx_handlers_drop_unauth_port);
320 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
321 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
322 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
323 local->rx_handlers_drop_nullfunc);
324 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
325 local->rx_handlers_drop_defrag);
326 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
327 local->rx_handlers_drop_short);
328 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
329 local->rx_handlers_drop_passive_scan);
330 DEBUGFS_STATS_ADD(tx_expand_skb_head,
331 local->tx_expand_skb_head);
332 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
333 local->tx_expand_skb_head_cloned);
334 DEBUGFS_STATS_ADD(rx_expand_skb_head,
335 local->rx_expand_skb_head);
336 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
337 local->rx_expand_skb_head2);
338 DEBUGFS_STATS_ADD(rx_handlers_fragments,
339 local->rx_handlers_fragments);
340 DEBUGFS_STATS_ADD(tx_status_drop,
341 local->tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700342#endif
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200343 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
344 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
345 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
346 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700347}