mfd: twl-core: Don't specify regulator consumers by struct device
[linux-2.6/btrfs-unstable.git] / net / mac80211 / debugfs.c
blob90baea53e7c56572df7562d201237fed48ef49e9
2 /*
3 * mac80211 debugfs for wireless PHYs
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
7 * GPLv2
9 */
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"
18 int mac80211_open_file_generic(struct inode *inode, struct file *file)
20 file->private_data = inode->i_private;
21 return 0;
24 #define DEBUGFS_FORMAT_BUFFER_SIZE 100
26 int mac80211_format_buffer(char __user *userbuf, size_t count,
27 loff_t *ppos, char *fmt, ...)
29 va_list args;
30 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
31 int res;
33 va_start(args, fmt);
34 res = vscnprintf(buf, sizeof(buf), fmt, args);
35 va_end(args);
37 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
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; \
46 return mac80211_format_buffer(userbuf, count, ppos, \
47 fmt "\n", ##value); \
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, \
57 #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
58 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
59 DEBUGFS_READONLY_FILE_OPS(name)
61 #define DEBUGFS_ADD(name) \
62 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
64 #define DEBUGFS_ADD_MODE(name, mode) \
65 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
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");
81 static ssize_t reset_write(struct file *file, const char __user *user_buf,
82 size_t count, loff_t *ppos)
84 struct ieee80211_local *local = file->private_data;
86 rtnl_lock();
87 __ieee80211_suspend(&local->hw, NULL);
88 __ieee80211_resume(&local->hw);
89 rtnl_unlock();
91 return count;
94 static const struct file_operations reset_ops = {
95 .write = reset_write,
96 .open = mac80211_open_file_generic,
97 .llseek = noop_llseek,
100 static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
101 size_t count, loff_t *ppos)
103 struct ieee80211_local *local = file->private_data;
104 return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
105 local->uapsd_queues);
108 static ssize_t uapsd_queues_write(struct file *file,
109 const char __user *user_buf,
110 size_t count, loff_t *ppos)
112 struct ieee80211_local *local = file->private_data;
113 u8 val;
114 int ret;
116 ret = kstrtou8_from_user(user_buf, count, 0, &val);
117 if (ret)
118 return ret;
120 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
121 return -ERANGE;
123 local->uapsd_queues = val;
125 return count;
128 static const struct file_operations uapsd_queues_ops = {
129 .read = uapsd_queues_read,
130 .write = uapsd_queues_write,
131 .open = mac80211_open_file_generic,
132 .llseek = default_llseek,
135 static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
136 size_t count, loff_t *ppos)
138 struct ieee80211_local *local = file->private_data;
140 return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
141 local->uapsd_max_sp_len);
144 static ssize_t uapsd_max_sp_len_write(struct file *file,
145 const char __user *user_buf,
146 size_t count, loff_t *ppos)
148 struct ieee80211_local *local = file->private_data;
149 unsigned long val;
150 char buf[10];
151 size_t len;
152 int ret;
154 len = min(count, sizeof(buf) - 1);
155 if (copy_from_user(buf, user_buf, len))
156 return -EFAULT;
157 buf[len] = '\0';
159 ret = kstrtoul(buf, 0, &val);
161 if (ret)
162 return -EINVAL;
164 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
165 return -ERANGE;
167 local->uapsd_max_sp_len = val;
169 return count;
172 static const struct file_operations uapsd_max_sp_len_ops = {
173 .read = uapsd_max_sp_len_read,
174 .write = uapsd_max_sp_len_write,
175 .open = mac80211_open_file_generic,
176 .llseek = default_llseek,
179 static ssize_t channel_type_read(struct file *file, char __user *user_buf,
180 size_t count, loff_t *ppos)
182 struct ieee80211_local *local = file->private_data;
183 const char *buf;
185 switch (local->hw.conf.channel_type) {
186 case NL80211_CHAN_NO_HT:
187 buf = "no ht\n";
188 break;
189 case NL80211_CHAN_HT20:
190 buf = "ht20\n";
191 break;
192 case NL80211_CHAN_HT40MINUS:
193 buf = "ht40-\n";
194 break;
195 case NL80211_CHAN_HT40PLUS:
196 buf = "ht40+\n";
197 break;
198 default:
199 buf = "???";
200 break;
203 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
206 static ssize_t hwflags_read(struct file *file, char __user *user_buf,
207 size_t count, loff_t *ppos)
209 struct ieee80211_local *local = file->private_data;
210 int mxln = 500;
211 ssize_t rv;
212 char *buf = kzalloc(mxln, GFP_KERNEL);
213 int sf = 0; /* how many written so far */
215 if (!buf)
216 return 0;
218 sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
219 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
220 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
221 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
222 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
223 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
224 sf += snprintf(buf + sf, mxln - sf,
225 "HOST_BCAST_PS_BUFFERING\n");
226 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
227 sf += snprintf(buf + sf, mxln - sf,
228 "2GHZ_SHORT_SLOT_INCAPABLE\n");
229 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
230 sf += snprintf(buf + sf, mxln - sf,
231 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
232 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
233 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
234 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
235 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
236 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
237 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n");
238 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
239 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
240 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
241 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
242 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
243 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
244 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
245 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
246 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
247 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
248 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
249 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
250 if (local->hw.flags & IEEE80211_HW_BEACON_FILTER)
251 sf += snprintf(buf + sf, mxln - sf, "BEACON_FILTER\n");
252 if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
253 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
254 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
255 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
256 if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
257 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
258 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
259 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
260 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
261 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
262 if (local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)
263 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_CQM_RSSI\n");
264 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
265 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
266 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
267 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
268 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
269 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
271 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
272 kfree(buf);
273 return rv;
276 static ssize_t queues_read(struct file *file, char __user *user_buf,
277 size_t count, loff_t *ppos)
279 struct ieee80211_local *local = file->private_data;
280 unsigned long flags;
281 char buf[IEEE80211_MAX_QUEUES * 20];
282 int q, res = 0;
284 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
285 for (q = 0; q < local->hw.queues; q++)
286 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
287 local->queue_stop_reasons[q],
288 skb_queue_len(&local->pending[q]));
289 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
291 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
294 DEBUGFS_READONLY_FILE_OPS(hwflags);
295 DEBUGFS_READONLY_FILE_OPS(channel_type);
296 DEBUGFS_READONLY_FILE_OPS(queues);
298 /* statistics stuff */
300 static ssize_t format_devstat_counter(struct ieee80211_local *local,
301 char __user *userbuf,
302 size_t count, loff_t *ppos,
303 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
304 int buflen))
306 struct ieee80211_low_level_stats stats;
307 char buf[20];
308 int res;
310 rtnl_lock();
311 res = drv_get_stats(local, &stats);
312 rtnl_unlock();
313 if (res)
314 return res;
315 res = printvalue(&stats, buf, sizeof(buf));
316 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
319 #define DEBUGFS_DEVSTATS_FILE(name) \
320 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
321 char *buf, int buflen) \
323 return scnprintf(buf, buflen, "%u\n", stats->name); \
325 static ssize_t stats_ ##name## _read(struct file *file, \
326 char __user *userbuf, \
327 size_t count, loff_t *ppos) \
329 return format_devstat_counter(file->private_data, \
330 userbuf, \
331 count, \
332 ppos, \
333 print_devstats_##name); \
336 static const struct file_operations stats_ ##name## _ops = { \
337 .read = stats_ ##name## _read, \
338 .open = mac80211_open_file_generic, \
339 .llseek = generic_file_llseek, \
342 #define DEBUGFS_STATS_ADD(name, field) \
343 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
344 #define DEBUGFS_DEVSTATS_ADD(name) \
345 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
347 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
348 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
349 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
350 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
352 void debugfs_hw_add(struct ieee80211_local *local)
354 struct dentry *phyd = local->hw.wiphy->debugfsdir;
355 struct dentry *statsd;
357 if (!phyd)
358 return;
360 local->debugfs.keys = debugfs_create_dir("keys", phyd);
362 DEBUGFS_ADD(frequency);
363 DEBUGFS_ADD(total_ps_buffered);
364 DEBUGFS_ADD(wep_iv);
365 DEBUGFS_ADD(queues);
366 DEBUGFS_ADD_MODE(reset, 0200);
367 DEBUGFS_ADD(uapsd_queues);
368 DEBUGFS_ADD(uapsd_max_sp_len);
369 DEBUGFS_ADD(channel_type);
370 DEBUGFS_ADD(hwflags);
371 DEBUGFS_ADD(user_power);
372 DEBUGFS_ADD(power);
374 statsd = debugfs_create_dir("statistics", phyd);
376 /* if the dir failed, don't put all the other things into the root! */
377 if (!statsd)
378 return;
380 DEBUGFS_STATS_ADD(transmitted_fragment_count,
381 local->dot11TransmittedFragmentCount);
382 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
383 local->dot11MulticastTransmittedFrameCount);
384 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
385 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
386 DEBUGFS_STATS_ADD(multiple_retry_count,
387 local->dot11MultipleRetryCount);
388 DEBUGFS_STATS_ADD(frame_duplicate_count,
389 local->dot11FrameDuplicateCount);
390 DEBUGFS_STATS_ADD(received_fragment_count,
391 local->dot11ReceivedFragmentCount);
392 DEBUGFS_STATS_ADD(multicast_received_frame_count,
393 local->dot11MulticastReceivedFrameCount);
394 DEBUGFS_STATS_ADD(transmitted_frame_count,
395 local->dot11TransmittedFrameCount);
396 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
397 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
398 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
399 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
400 local->tx_handlers_drop_unencrypted);
401 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
402 local->tx_handlers_drop_fragment);
403 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
404 local->tx_handlers_drop_wep);
405 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
406 local->tx_handlers_drop_not_assoc);
407 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
408 local->tx_handlers_drop_unauth_port);
409 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
410 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
411 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
412 local->rx_handlers_drop_nullfunc);
413 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
414 local->rx_handlers_drop_defrag);
415 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
416 local->rx_handlers_drop_short);
417 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
418 local->rx_handlers_drop_passive_scan);
419 DEBUGFS_STATS_ADD(tx_expand_skb_head,
420 local->tx_expand_skb_head);
421 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
422 local->tx_expand_skb_head_cloned);
423 DEBUGFS_STATS_ADD(rx_expand_skb_head,
424 local->rx_expand_skb_head);
425 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
426 local->rx_expand_skb_head2);
427 DEBUGFS_STATS_ADD(rx_handlers_fragments,
428 local->rx_handlers_fragments);
429 DEBUGFS_STATS_ADD(tx_status_drop,
430 local->tx_status_drop);
431 #endif
432 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
433 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
434 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
435 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);