3 * mac80211 debugfs for wireless PHYs
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
11 #include <linux/debugfs.h>
12 #include <linux/rtnetlink.h>
13 #include "ieee80211_i.h"
14 #include "driver-ops.h"
18 int mac80211_open_file_generic(struct inode *inode, struct file *file)
20 file->private_data = inode->i_private;
24 #define DEBUGFS_FORMAT_BUFFER_SIZE 100
26 int mac80211_format_buffer(char __user *userbuf, size_t count,
27 loff_t *ppos, char *fmt, ...)
30 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
34 res = vscnprintf(buf, sizeof(buf), fmt, 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) \
44 struct ieee80211_local *local = file->private_data; \
46 return mac80211_format_buffer(userbuf, count, ppos, \
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 tsf_read(struct file *file, char __user *user_buf,
82 size_t count, loff_t *ppos)
84 struct ieee80211_local *local = file->private_data;
87 tsf = drv_get_tsf(local);
89 return mac80211_format_buffer(user_buf, count, ppos, "0x%016llx\n",
90 (unsigned long long) tsf);
93 static ssize_t tsf_write(struct file *file,
94 const char __user *user_buf,
95 size_t count, loff_t *ppos)
97 struct ieee80211_local *local = file->private_data;
98 unsigned long long tsf;
102 len = min(count, sizeof(buf) - 1);
103 if (copy_from_user(buf, user_buf, len))
107 if (strncmp(buf, "reset", 5) == 0) {
108 if (local->ops->reset_tsf) {
109 drv_reset_tsf(local);
110 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
113 tsf = simple_strtoul(buf, NULL, 0);
114 if (local->ops->set_tsf) {
115 drv_set_tsf(local, tsf);
116 wiphy_info(local->hw.wiphy,
117 "debugfs set TSF to %#018llx\n", tsf);
125 static const struct file_operations tsf_ops = {
128 .open = mac80211_open_file_generic,
129 .llseek = default_llseek,
132 static ssize_t reset_write(struct file *file, const char __user *user_buf,
133 size_t count, loff_t *ppos)
135 struct ieee80211_local *local = file->private_data;
138 __ieee80211_suspend(&local->hw, NULL);
139 __ieee80211_resume(&local->hw);
145 static const struct file_operations reset_ops = {
146 .write = reset_write,
147 .open = mac80211_open_file_generic,
148 .llseek = noop_llseek,
151 static ssize_t noack_read(struct file *file, char __user *user_buf,
152 size_t count, loff_t *ppos)
154 struct ieee80211_local *local = file->private_data;
156 return mac80211_format_buffer(user_buf, count, ppos, "%d\n",
157 local->wifi_wme_noack_test);
160 static ssize_t noack_write(struct file *file,
161 const char __user *user_buf,
162 size_t count, loff_t *ppos)
164 struct ieee80211_local *local = file->private_data;
168 len = min(count, sizeof(buf) - 1);
169 if (copy_from_user(buf, user_buf, len))
173 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
178 static const struct file_operations noack_ops = {
180 .write = noack_write,
181 .open = mac80211_open_file_generic,
182 .llseek = default_llseek,
185 static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
186 size_t count, loff_t *ppos)
188 struct ieee80211_local *local = file->private_data;
189 return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
190 local->uapsd_queues);
193 static ssize_t uapsd_queues_write(struct file *file,
194 const char __user *user_buf,
195 size_t count, loff_t *ppos)
197 struct ieee80211_local *local = file->private_data;
201 ret = kstrtou8_from_user(user_buf, count, 0, &val);
205 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
208 local->uapsd_queues = val;
213 static const struct file_operations uapsd_queues_ops = {
214 .read = uapsd_queues_read,
215 .write = uapsd_queues_write,
216 .open = mac80211_open_file_generic,
217 .llseek = default_llseek,
220 static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
221 size_t count, loff_t *ppos)
223 struct ieee80211_local *local = file->private_data;
225 return mac80211_format_buffer(user_buf, count, ppos, "0x%x\n",
226 local->uapsd_max_sp_len);
229 static ssize_t uapsd_max_sp_len_write(struct file *file,
230 const char __user *user_buf,
231 size_t count, loff_t *ppos)
233 struct ieee80211_local *local = file->private_data;
239 len = min(count, sizeof(buf) - 1);
240 if (copy_from_user(buf, user_buf, len))
244 ret = strict_strtoul(buf, 0, &val);
249 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
252 local->uapsd_max_sp_len = val;
257 static const struct file_operations uapsd_max_sp_len_ops = {
258 .read = uapsd_max_sp_len_read,
259 .write = uapsd_max_sp_len_write,
260 .open = mac80211_open_file_generic,
261 .llseek = default_llseek,
264 static ssize_t channel_type_read(struct file *file, char __user *user_buf,
265 size_t count, loff_t *ppos)
267 struct ieee80211_local *local = file->private_data;
270 switch (local->hw.conf.channel_type) {
271 case NL80211_CHAN_NO_HT:
274 case NL80211_CHAN_HT20:
277 case NL80211_CHAN_HT40MINUS:
280 case NL80211_CHAN_HT40PLUS:
288 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
291 static ssize_t hwflags_read(struct file *file, char __user *user_buf,
292 size_t count, loff_t *ppos)
294 struct ieee80211_local *local = file->private_data;
297 char *buf = kzalloc(mxln, GFP_KERNEL);
298 int sf = 0; /* how many written so far */
303 sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
304 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
305 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
306 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
307 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
308 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
309 sf += snprintf(buf + sf, mxln - sf,
310 "HOST_BCAST_PS_BUFFERING\n");
311 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
312 sf += snprintf(buf + sf, mxln - sf,
313 "2GHZ_SHORT_SLOT_INCAPABLE\n");
314 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
315 sf += snprintf(buf + sf, mxln - sf,
316 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
317 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
318 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
319 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
320 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
321 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
322 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n");
323 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
324 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
325 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
326 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
327 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
328 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
329 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
330 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
331 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
332 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
333 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
334 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
335 if (local->hw.flags & IEEE80211_HW_BEACON_FILTER)
336 sf += snprintf(buf + sf, mxln - sf, "BEACON_FILTER\n");
337 if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
338 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
339 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
340 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
341 if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
342 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
343 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
344 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
345 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
346 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
347 if (local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)
348 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_CQM_RSSI\n");
349 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
350 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
351 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
352 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
353 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
354 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
356 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
361 static ssize_t queues_read(struct file *file, char __user *user_buf,
362 size_t count, loff_t *ppos)
364 struct ieee80211_local *local = file->private_data;
366 char buf[IEEE80211_MAX_QUEUES * 20];
369 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
370 for (q = 0; q < local->hw.queues; q++)
371 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
372 local->queue_stop_reasons[q],
373 skb_queue_len(&local->pending[q]));
374 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
376 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
379 DEBUGFS_READONLY_FILE_OPS(hwflags);
380 DEBUGFS_READONLY_FILE_OPS(channel_type);
381 DEBUGFS_READONLY_FILE_OPS(queues);
383 /* statistics stuff */
385 static ssize_t format_devstat_counter(struct ieee80211_local *local,
386 char __user *userbuf,
387 size_t count, loff_t *ppos,
388 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
391 struct ieee80211_low_level_stats stats;
396 res = drv_get_stats(local, &stats);
400 res = printvalue(&stats, buf, sizeof(buf));
401 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
404 #define DEBUGFS_DEVSTATS_FILE(name) \
405 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
406 char *buf, int buflen) \
408 return scnprintf(buf, buflen, "%u\n", stats->name); \
410 static ssize_t stats_ ##name## _read(struct file *file, \
411 char __user *userbuf, \
412 size_t count, loff_t *ppos) \
414 return format_devstat_counter(file->private_data, \
418 print_devstats_##name); \
421 static const struct file_operations stats_ ##name## _ops = { \
422 .read = stats_ ##name## _read, \
423 .open = mac80211_open_file_generic, \
424 .llseek = generic_file_llseek, \
427 #define DEBUGFS_STATS_ADD(name, field) \
428 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
429 #define DEBUGFS_DEVSTATS_ADD(name) \
430 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
432 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
433 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
434 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
435 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
437 void debugfs_hw_add(struct ieee80211_local *local)
439 struct dentry *phyd = local->hw.wiphy->debugfsdir;
440 struct dentry *statsd;
445 local->debugfs.keys = debugfs_create_dir("keys", phyd);
447 DEBUGFS_ADD(frequency);
448 DEBUGFS_ADD(total_ps_buffered);
452 DEBUGFS_ADD_MODE(reset, 0200);
454 DEBUGFS_ADD(uapsd_queues);
455 DEBUGFS_ADD(uapsd_max_sp_len);
456 DEBUGFS_ADD(channel_type);
457 DEBUGFS_ADD(hwflags);
458 DEBUGFS_ADD(user_power);
461 statsd = debugfs_create_dir("statistics", phyd);
463 /* if the dir failed, don't put all the other things into the root! */
467 DEBUGFS_STATS_ADD(transmitted_fragment_count,
468 local->dot11TransmittedFragmentCount);
469 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
470 local->dot11MulticastTransmittedFrameCount);
471 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
472 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
473 DEBUGFS_STATS_ADD(multiple_retry_count,
474 local->dot11MultipleRetryCount);
475 DEBUGFS_STATS_ADD(frame_duplicate_count,
476 local->dot11FrameDuplicateCount);
477 DEBUGFS_STATS_ADD(received_fragment_count,
478 local->dot11ReceivedFragmentCount);
479 DEBUGFS_STATS_ADD(multicast_received_frame_count,
480 local->dot11MulticastReceivedFrameCount);
481 DEBUGFS_STATS_ADD(transmitted_frame_count,
482 local->dot11TransmittedFrameCount);
483 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
484 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
485 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
486 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
487 local->tx_handlers_drop_unencrypted);
488 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
489 local->tx_handlers_drop_fragment);
490 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
491 local->tx_handlers_drop_wep);
492 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
493 local->tx_handlers_drop_not_assoc);
494 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
495 local->tx_handlers_drop_unauth_port);
496 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
497 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
498 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
499 local->rx_handlers_drop_nullfunc);
500 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
501 local->rx_handlers_drop_defrag);
502 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
503 local->rx_handlers_drop_short);
504 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
505 local->rx_handlers_drop_passive_scan);
506 DEBUGFS_STATS_ADD(tx_expand_skb_head,
507 local->tx_expand_skb_head);
508 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
509 local->tx_expand_skb_head_cloned);
510 DEBUGFS_STATS_ADD(rx_expand_skb_head,
511 local->rx_expand_skb_head);
512 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
513 local->rx_expand_skb_head2);
514 DEBUGFS_STATS_ADD(rx_handlers_fragments,
515 local->rx_handlers_fragments);
516 DEBUGFS_STATS_ADD(tx_status_drop,
517 local->tx_status_drop);
519 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
520 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
521 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
522 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);