]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/mac80211/debugfs.c
Merge branch 'kbuild' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
[mirror_ubuntu-artful-kernel.git] / net / mac80211 / debugfs.c
1
2 /*
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"
14 #include "driver-ops.h"
15 #include "rate.h"
16 #include "debugfs.h"
17
18 int mac80211_open_file_generic(struct inode *inode, struct file *file)
19 {
20 file->private_data = inode->i_private;
21 return 0;
22 }
23
24 #define DEBUGFS_FORMAT_BUFFER_SIZE 100
25
26 int mac80211_format_buffer(char __user *userbuf, size_t count,
27 loff_t *ppos, char *fmt, ...)
28 {
29 va_list args;
30 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
31 int res;
32
33 va_start(args, fmt);
34 res = vscnprintf(buf, sizeof(buf), fmt, args);
35 va_end(args);
36
37 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
38 }
39
40 #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
41 static ssize_t name## _read(struct file *file, char __user *userbuf, \
42 size_t count, loff_t *ppos) \
43 { \
44 struct ieee80211_local *local = file->private_data; \
45 \
46 return mac80211_format_buffer(userbuf, count, ppos, \
47 fmt "\n", ##value); \
48 }
49
50 #define DEBUGFS_READONLY_FILE_OPS(name) \
51 static const struct file_operations name## _ops = { \
52 .read = name## _read, \
53 .open = mac80211_open_file_generic, \
54 .llseek = generic_file_llseek, \
55 };
56
57 #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
58 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
59 DEBUGFS_READONLY_FILE_OPS(name)
60
61 #define DEBUGFS_ADD(name) \
62 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
63
64 #define DEBUGFS_ADD_MODE(name, mode) \
65 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
66
67
68 DEBUGFS_READONLY_FILE(user_power, "%d",
69 local->user_power_level);
70 DEBUGFS_READONLY_FILE(power, "%d",
71 local->hw.conf.power_level);
72 DEBUGFS_READONLY_FILE(frequency, "%d",
73 local->hw.conf.channel->center_freq);
74 DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
75 local->total_ps_buffered);
76 DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
77 local->wep_iv & 0xffffff);
78 DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
79 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
80
81 static ssize_t reset_write(struct file *file, const char __user *user_buf,
82 size_t count, loff_t *ppos)
83 {
84 struct ieee80211_local *local = file->private_data;
85
86 rtnl_lock();
87 __ieee80211_suspend(&local->hw, NULL);
88 __ieee80211_resume(&local->hw);
89 rtnl_unlock();
90
91 return count;
92 }
93
94 static const struct file_operations reset_ops = {
95 .write = reset_write,
96 .open = mac80211_open_file_generic,
97 .llseek = noop_llseek,
98 };
99
100 static ssize_t channel_type_read(struct file *file, char __user *user_buf,
101 size_t count, loff_t *ppos)
102 {
103 struct ieee80211_local *local = file->private_data;
104 const char *buf;
105
106 switch (local->hw.conf.channel_type) {
107 case NL80211_CHAN_NO_HT:
108 buf = "no ht\n";
109 break;
110 case NL80211_CHAN_HT20:
111 buf = "ht20\n";
112 break;
113 case NL80211_CHAN_HT40MINUS:
114 buf = "ht40-\n";
115 break;
116 case NL80211_CHAN_HT40PLUS:
117 buf = "ht40+\n";
118 break;
119 default:
120 buf = "???";
121 break;
122 }
123
124 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
125 }
126
127 static ssize_t hwflags_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 mxln = 500;
132 ssize_t rv;
133 char *buf = kzalloc(mxln, GFP_KERNEL);
134 int sf = 0; /* how many written so far */
135
136 if (!buf)
137 return 0;
138
139 sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
140 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
141 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
142 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
143 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
144 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
145 sf += snprintf(buf + sf, mxln - sf,
146 "HOST_BCAST_PS_BUFFERING\n");
147 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
148 sf += snprintf(buf + sf, mxln - sf,
149 "2GHZ_SHORT_SLOT_INCAPABLE\n");
150 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
151 sf += snprintf(buf + sf, mxln - sf,
152 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
153 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
154 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
155 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
156 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
157 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
158 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n");
159 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
160 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
161 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
162 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
163 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
164 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
165 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
166 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
167 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
168 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
169 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
170 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
171 if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
172 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
173 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
174 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
175 if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
176 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
177 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
178 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
179 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
180 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
181 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
182 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
183 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
184 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
185 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
186 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
187 if (local->hw.flags & IEEE80211_HW_SCAN_WHILE_IDLE)
188 sf += snprintf(buf + sf, mxln - sf, "SCAN_WHILE_IDLE\n");
189
190 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
191 kfree(buf);
192 return rv;
193 }
194
195 static ssize_t queues_read(struct file *file, char __user *user_buf,
196 size_t count, loff_t *ppos)
197 {
198 struct ieee80211_local *local = file->private_data;
199 unsigned long flags;
200 char buf[IEEE80211_MAX_QUEUES * 20];
201 int q, res = 0;
202
203 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
204 for (q = 0; q < local->hw.queues; q++)
205 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
206 local->queue_stop_reasons[q],
207 skb_queue_len(&local->pending[q]));
208 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
209
210 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
211 }
212
213 DEBUGFS_READONLY_FILE_OPS(hwflags);
214 DEBUGFS_READONLY_FILE_OPS(channel_type);
215 DEBUGFS_READONLY_FILE_OPS(queues);
216
217 /* statistics stuff */
218
219 static ssize_t format_devstat_counter(struct ieee80211_local *local,
220 char __user *userbuf,
221 size_t count, loff_t *ppos,
222 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
223 int buflen))
224 {
225 struct ieee80211_low_level_stats stats;
226 char buf[20];
227 int res;
228
229 rtnl_lock();
230 res = drv_get_stats(local, &stats);
231 rtnl_unlock();
232 if (res)
233 return res;
234 res = printvalue(&stats, buf, sizeof(buf));
235 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
236 }
237
238 #define DEBUGFS_DEVSTATS_FILE(name) \
239 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
240 char *buf, int buflen) \
241 { \
242 return scnprintf(buf, buflen, "%u\n", stats->name); \
243 } \
244 static ssize_t stats_ ##name## _read(struct file *file, \
245 char __user *userbuf, \
246 size_t count, loff_t *ppos) \
247 { \
248 return format_devstat_counter(file->private_data, \
249 userbuf, \
250 count, \
251 ppos, \
252 print_devstats_##name); \
253 } \
254 \
255 static const struct file_operations stats_ ##name## _ops = { \
256 .read = stats_ ##name## _read, \
257 .open = mac80211_open_file_generic, \
258 .llseek = generic_file_llseek, \
259 };
260
261 #define DEBUGFS_STATS_ADD(name, field) \
262 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
263 #define DEBUGFS_DEVSTATS_ADD(name) \
264 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
265
266 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
267 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
268 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
269 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
270
271 void debugfs_hw_add(struct ieee80211_local *local)
272 {
273 struct dentry *phyd = local->hw.wiphy->debugfsdir;
274 struct dentry *statsd;
275
276 if (!phyd)
277 return;
278
279 local->debugfs.keys = debugfs_create_dir("keys", phyd);
280
281 DEBUGFS_ADD(frequency);
282 DEBUGFS_ADD(total_ps_buffered);
283 DEBUGFS_ADD(wep_iv);
284 DEBUGFS_ADD(queues);
285 DEBUGFS_ADD_MODE(reset, 0200);
286 DEBUGFS_ADD(channel_type);
287 DEBUGFS_ADD(hwflags);
288 DEBUGFS_ADD(user_power);
289 DEBUGFS_ADD(power);
290
291 statsd = debugfs_create_dir("statistics", phyd);
292
293 /* if the dir failed, don't put all the other things into the root! */
294 if (!statsd)
295 return;
296
297 DEBUGFS_STATS_ADD(transmitted_fragment_count,
298 local->dot11TransmittedFragmentCount);
299 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
300 local->dot11MulticastTransmittedFrameCount);
301 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
302 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
303 DEBUGFS_STATS_ADD(multiple_retry_count,
304 local->dot11MultipleRetryCount);
305 DEBUGFS_STATS_ADD(frame_duplicate_count,
306 local->dot11FrameDuplicateCount);
307 DEBUGFS_STATS_ADD(received_fragment_count,
308 local->dot11ReceivedFragmentCount);
309 DEBUGFS_STATS_ADD(multicast_received_frame_count,
310 local->dot11MulticastReceivedFrameCount);
311 DEBUGFS_STATS_ADD(transmitted_frame_count,
312 local->dot11TransmittedFrameCount);
313 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
314 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
315 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
316 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
317 local->tx_handlers_drop_unencrypted);
318 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
319 local->tx_handlers_drop_fragment);
320 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
321 local->tx_handlers_drop_wep);
322 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
323 local->tx_handlers_drop_not_assoc);
324 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
325 local->tx_handlers_drop_unauth_port);
326 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
327 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
328 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
329 local->rx_handlers_drop_nullfunc);
330 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
331 local->rx_handlers_drop_defrag);
332 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
333 local->rx_handlers_drop_short);
334 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
335 local->rx_handlers_drop_passive_scan);
336 DEBUGFS_STATS_ADD(tx_expand_skb_head,
337 local->tx_expand_skb_head);
338 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
339 local->tx_expand_skb_head_cloned);
340 DEBUGFS_STATS_ADD(rx_expand_skb_head,
341 local->rx_expand_skb_head);
342 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
343 local->rx_expand_skb_head2);
344 DEBUGFS_STATS_ADD(rx_handlers_fragments,
345 local->rx_handlers_fragments);
346 DEBUGFS_STATS_ADD(tx_status_drop,
347 local->tx_status_drop);
348 #endif
349 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
350 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
351 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
352 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
353 }