blob: b0e32d6281146231061d34f63088db6b90106fc1 [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 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
Ben Greear279daf62011-03-23 14:04:31 -070094static ssize_t hwflags_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 int mxln = 500;
99 ssize_t rv;
100 char *buf = kzalloc(mxln, GFP_KERNEL);
101 int sf = 0; /* how many written so far */
102
Joe Perchesd15b8452011-08-29 14:17:31 -0700103 if (!buf)
104 return 0;
105
Ben Greear279daf62011-03-23 14:04:31 -0700106 sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
107 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
108 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
109 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
110 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
111 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
112 sf += snprintf(buf + sf, mxln - sf,
113 "HOST_BCAST_PS_BUFFERING\n");
114 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
115 sf += snprintf(buf + sf, mxln - sf,
116 "2GHZ_SHORT_SLOT_INCAPABLE\n");
117 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
118 sf += snprintf(buf + sf, mxln - sf,
119 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
120 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
121 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
122 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
123 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
Emmanuel Grumbachc65dd142012-12-12 10:12:24 +0200124 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC)
125 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_BEFORE_ASSOC\n");
Ben Greear279daf62011-03-23 14:04:31 -0700126 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
127 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
128 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
129 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
130 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
131 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
132 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
133 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
134 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
135 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
136 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
137 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
Ben Greear279daf62011-03-23 14:04:31 -0700138 if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
139 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
140 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
141 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
142 if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
143 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
144 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
145 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
146 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
147 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
Ben Greear279daf62011-03-23 14:04:31 -0700148 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
149 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
150 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
151 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
Arik Nemtsovedf6b782011-08-30 09:32:38 +0300152 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
153 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
Ben Greear279daf62011-03-23 14:04:31 -0700154
155 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
156 kfree(buf);
157 return rv;
158}
Benoit Papillault199d69f2010-02-04 22:00:20 +0100159
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200160static ssize_t queues_read(struct file *file, char __user *user_buf,
161 size_t count, loff_t *ppos)
162{
163 struct ieee80211_local *local = file->private_data;
164 unsigned long flags;
165 char buf[IEEE80211_MAX_QUEUES * 20];
166 int q, res = 0;
167
168 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
169 for (q = 0; q < local->hw.queues; q++)
170 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
171 local->queue_stop_reasons[q],
Johannes Berg3b8d81e02009-06-17 17:43:56 +0200172 skb_queue_len(&local->pending[q]));
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200173 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
174
175 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
176}
177
Ben Greear279daf62011-03-23 14:04:31 -0700178DEBUGFS_READONLY_FILE_OPS(hwflags);
Ben Greear279daf62011-03-23 14:04:31 -0700179DEBUGFS_READONLY_FILE_OPS(queues);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200180
Jiri Bence9f207f2007-05-05 11:46:38 -0700181/* statistics stuff */
182
Jiri Bence9f207f2007-05-05 11:46:38 -0700183static ssize_t format_devstat_counter(struct ieee80211_local *local,
184 char __user *userbuf,
185 size_t count, loff_t *ppos,
186 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
187 int buflen))
188{
189 struct ieee80211_low_level_stats stats;
190 char buf[20];
191 int res;
192
Johannes Berg75636522008-07-09 14:40:35 +0200193 rtnl_lock();
Johannes Berg24487982009-04-23 18:52:52 +0200194 res = drv_get_stats(local, &stats);
Jiri Bence9f207f2007-05-05 11:46:38 -0700195 rtnl_unlock();
Johannes Berg24487982009-04-23 18:52:52 +0200196 if (res)
197 return res;
198 res = printvalue(&stats, buf, sizeof(buf));
Jiri Bence9f207f2007-05-05 11:46:38 -0700199 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
200}
201
202#define DEBUGFS_DEVSTATS_FILE(name) \
203static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
204 char *buf, int buflen) \
205{ \
206 return scnprintf(buf, buflen, "%u\n", stats->name); \
207} \
208static ssize_t stats_ ##name## _read(struct file *file, \
209 char __user *userbuf, \
210 size_t count, loff_t *ppos) \
211{ \
212 return format_devstat_counter(file->private_data, \
213 userbuf, \
214 count, \
215 ppos, \
216 print_devstats_##name); \
217} \
218 \
219static const struct file_operations stats_ ##name## _ops = { \
220 .read = stats_ ##name## _read, \
Stephen Boyd234e3402012-04-05 14:25:11 -0700221 .open = simple_open, \
Arnd Bergmann2b18ab362010-07-06 19:05:31 +0200222 .llseek = generic_file_llseek, \
Jiri Bence9f207f2007-05-05 11:46:38 -0700223};
224
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200225#define DEBUGFS_STATS_ADD(name, field) \
226 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
227#define DEBUGFS_DEVSTATS_ADD(name) \
Johannes Berg7bcfaf22009-10-27 12:59:03 +0100228 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
Jiri Bence9f207f2007-05-05 11:46:38 -0700229
Jiri Bence9f207f2007-05-05 11:46:38 -0700230DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
231DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
232DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
233DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
234
Jiri Bence9f207f2007-05-05 11:46:38 -0700235void debugfs_hw_add(struct ieee80211_local *local)
236{
237 struct dentry *phyd = local->hw.wiphy->debugfsdir;
238 struct dentry *statsd;
239
240 if (!phyd)
241 return;
242
Jiri Bence9f207f2007-05-05 11:46:38 -0700243 local->debugfs.keys = debugfs_create_dir("keys", phyd);
244
Jiri Bence9f207f2007-05-05 11:46:38 -0700245 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700246 DEBUGFS_ADD(wep_iv);
Johannes Bergdb2e6bd2009-06-14 17:37:39 +0200247 DEBUGFS_ADD(queues);
Johannes Berg2ad48142012-09-19 08:20:24 +0200248#ifdef CONFIG_PM
Johannes Berg827b1fb2009-03-13 11:44:18 +0100249 DEBUGFS_ADD_MODE(reset, 0200);
Johannes Berg2ad48142012-09-19 08:20:24 +0200250#endif
Ben Greear279daf62011-03-23 14:04:31 -0700251 DEBUGFS_ADD(hwflags);
Ben Greear83bdf2a2011-02-15 13:11:22 -0800252 DEBUGFS_ADD(user_power);
253 DEBUGFS_ADD(power);
Jiri Bence9f207f2007-05-05 11:46:38 -0700254
255 statsd = debugfs_create_dir("statistics", phyd);
Jiri Bence9f207f2007-05-05 11:46:38 -0700256
257 /* if the dir failed, don't put all the other things into the root! */
258 if (!statsd)
259 return;
260
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200261 DEBUGFS_STATS_ADD(transmitted_fragment_count,
262 local->dot11TransmittedFragmentCount);
263 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
264 local->dot11MulticastTransmittedFrameCount);
265 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
266 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
267 DEBUGFS_STATS_ADD(multiple_retry_count,
268 local->dot11MultipleRetryCount);
269 DEBUGFS_STATS_ADD(frame_duplicate_count,
270 local->dot11FrameDuplicateCount);
271 DEBUGFS_STATS_ADD(received_fragment_count,
272 local->dot11ReceivedFragmentCount);
273 DEBUGFS_STATS_ADD(multicast_received_frame_count,
274 local->dot11MulticastReceivedFrameCount);
275 DEBUGFS_STATS_ADD(transmitted_frame_count,
276 local->dot11TransmittedFrameCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700277#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200278 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
279 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
280 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
281 local->tx_handlers_drop_unencrypted);
282 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
283 local->tx_handlers_drop_fragment);
284 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
285 local->tx_handlers_drop_wep);
286 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
287 local->tx_handlers_drop_not_assoc);
288 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
289 local->tx_handlers_drop_unauth_port);
290 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
291 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
292 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
293 local->rx_handlers_drop_nullfunc);
294 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
295 local->rx_handlers_drop_defrag);
296 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
297 local->rx_handlers_drop_short);
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200298 DEBUGFS_STATS_ADD(tx_expand_skb_head,
299 local->tx_expand_skb_head);
300 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
301 local->tx_expand_skb_head_cloned);
302 DEBUGFS_STATS_ADD(rx_expand_skb_head,
303 local->rx_expand_skb_head);
304 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
305 local->rx_expand_skb_head2);
306 DEBUGFS_STATS_ADD(rx_handlers_fragments,
307 local->rx_handlers_fragments);
308 DEBUGFS_STATS_ADD(tx_status_drop,
309 local->tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700310#endif
Felix Fietkau2826bcd2010-06-02 02:57:34 +0200311 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
312 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
313 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
314 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
Jiri Bence9f207f2007-05-05 11:46:38 -0700315}