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_READONLY_FILE(name, buflen, fmt, value...) \
25 static ssize_t name## _read(struct file *file, char __user *userbuf, \
26 size_t count, loff_t *ppos) \
28 struct ieee80211_local *local = file->private_data; \
32 res = scnprintf(buf, buflen, fmt "\n", ##value); \
33 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
36 static const struct file_operations name## _ops = { \
37 .read = name## _read, \
38 .open = mac80211_open_file_generic, \
41 #define DEBUGFS_ADD(name) \
42 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
44 #define DEBUGFS_ADD_MODE(name, mode) \
45 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
48 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
49 local->hw.conf.channel->center_freq);
50 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
51 local->total_ps_buffered);
52 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
53 local->wep_iv & 0xffffff);
54 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
55 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
57 static ssize_t tsf_read(struct file *file, char __user *user_buf,
58 size_t count, loff_t *ppos)
60 struct ieee80211_local *local = file->private_data;
64 tsf = drv_get_tsf(local);
66 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
68 return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
71 static ssize_t tsf_write(struct file *file,
72 const char __user *user_buf,
73 size_t count, loff_t *ppos)
75 struct ieee80211_local *local = file->private_data;
76 unsigned long long tsf;
80 len = min(count, sizeof(buf) - 1);
81 if (copy_from_user(buf, user_buf, len))
85 if (strncmp(buf, "reset", 5) == 0) {
86 if (local->ops->reset_tsf) {
88 wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
91 tsf = simple_strtoul(buf, NULL, 0);
92 if (local->ops->set_tsf) {
93 drv_set_tsf(local, tsf);
94 wiphy_info(local->hw.wiphy,
95 "debugfs set TSF to %#018llx\n", tsf);
103 static const struct file_operations tsf_ops = {
106 .open = mac80211_open_file_generic
109 static ssize_t reset_write(struct file *file, const char __user *user_buf,
110 size_t count, loff_t *ppos)
112 struct ieee80211_local *local = file->private_data;
115 __ieee80211_suspend(&local->hw);
116 __ieee80211_resume(&local->hw);
122 static const struct file_operations reset_ops = {
123 .write = reset_write,
124 .open = mac80211_open_file_generic,
127 static ssize_t noack_read(struct file *file, char __user *user_buf,
128 size_t count, loff_t *ppos)
130 struct ieee80211_local *local = file->private_data;
134 res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
136 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
139 static ssize_t noack_write(struct file *file,
140 const char __user *user_buf,
141 size_t count, loff_t *ppos)
143 struct ieee80211_local *local = file->private_data;
147 len = min(count, sizeof(buf) - 1);
148 if (copy_from_user(buf, user_buf, len))
152 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
157 static const struct file_operations noack_ops = {
159 .write = noack_write,
160 .open = mac80211_open_file_generic
163 static ssize_t uapsd_queues_read(struct file *file, char __user *user_buf,
164 size_t count, loff_t *ppos)
166 struct ieee80211_local *local = file->private_data;
170 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_queues);
172 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
175 static ssize_t uapsd_queues_write(struct file *file,
176 const char __user *user_buf,
177 size_t count, loff_t *ppos)
179 struct ieee80211_local *local = file->private_data;
185 len = min(count, sizeof(buf) - 1);
186 if (copy_from_user(buf, user_buf, len))
190 ret = strict_strtoul(buf, 0, &val);
195 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
198 local->uapsd_queues = val;
203 static const struct file_operations uapsd_queues_ops = {
204 .read = uapsd_queues_read,
205 .write = uapsd_queues_write,
206 .open = mac80211_open_file_generic
209 static ssize_t uapsd_max_sp_len_read(struct file *file, char __user *user_buf,
210 size_t count, loff_t *ppos)
212 struct ieee80211_local *local = file->private_data;
216 res = scnprintf(buf, sizeof(buf), "0x%x\n", local->uapsd_max_sp_len);
218 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
221 static ssize_t uapsd_max_sp_len_write(struct file *file,
222 const char __user *user_buf,
223 size_t count, loff_t *ppos)
225 struct ieee80211_local *local = file->private_data;
231 len = min(count, sizeof(buf) - 1);
232 if (copy_from_user(buf, user_buf, len))
236 ret = strict_strtoul(buf, 0, &val);
241 if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
244 local->uapsd_max_sp_len = val;
249 static const struct file_operations uapsd_max_sp_len_ops = {
250 .read = uapsd_max_sp_len_read,
251 .write = uapsd_max_sp_len_write,
252 .open = mac80211_open_file_generic
255 static ssize_t channel_type_read(struct file *file, char __user *user_buf,
256 size_t count, loff_t *ppos)
258 struct ieee80211_local *local = file->private_data;
261 switch (local->hw.conf.channel_type) {
262 case NL80211_CHAN_NO_HT:
265 case NL80211_CHAN_HT20:
268 case NL80211_CHAN_HT40MINUS:
271 case NL80211_CHAN_HT40PLUS:
279 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
282 static const struct file_operations channel_type_ops = {
283 .read = channel_type_read,
284 .open = mac80211_open_file_generic
287 static ssize_t queues_read(struct file *file, char __user *user_buf,
288 size_t count, loff_t *ppos)
290 struct ieee80211_local *local = file->private_data;
292 char buf[IEEE80211_MAX_QUEUES * 20];
295 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
296 for (q = 0; q < local->hw.queues; q++)
297 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
298 local->queue_stop_reasons[q],
299 skb_queue_len(&local->pending[q]));
300 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
302 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
305 static const struct file_operations queues_ops = {
307 .open = mac80211_open_file_generic
310 /* statistics stuff */
312 static ssize_t format_devstat_counter(struct ieee80211_local *local,
313 char __user *userbuf,
314 size_t count, loff_t *ppos,
315 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
318 struct ieee80211_low_level_stats stats;
323 res = drv_get_stats(local, &stats);
327 res = printvalue(&stats, buf, sizeof(buf));
328 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
331 #define DEBUGFS_DEVSTATS_FILE(name) \
332 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
333 char *buf, int buflen) \
335 return scnprintf(buf, buflen, "%u\n", stats->name); \
337 static ssize_t stats_ ##name## _read(struct file *file, \
338 char __user *userbuf, \
339 size_t count, loff_t *ppos) \
341 return format_devstat_counter(file->private_data, \
345 print_devstats_##name); \
348 static const struct file_operations stats_ ##name## _ops = { \
349 .read = stats_ ##name## _read, \
350 .open = mac80211_open_file_generic, \
353 #define DEBUGFS_STATS_ADD(name, field) \
354 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
355 #define DEBUGFS_DEVSTATS_ADD(name) \
356 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
358 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
359 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
360 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
361 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
363 void debugfs_hw_add(struct ieee80211_local *local)
365 struct dentry *phyd = local->hw.wiphy->debugfsdir;
366 struct dentry *statsd;
371 local->debugfs.keys = debugfs_create_dir("keys", phyd);
373 DEBUGFS_ADD(frequency);
374 DEBUGFS_ADD(total_ps_buffered);
378 DEBUGFS_ADD_MODE(reset, 0200);
380 DEBUGFS_ADD(uapsd_queues);
381 DEBUGFS_ADD(uapsd_max_sp_len);
382 DEBUGFS_ADD(channel_type);
384 statsd = debugfs_create_dir("statistics", phyd);
386 /* if the dir failed, don't put all the other things into the root! */
390 DEBUGFS_STATS_ADD(transmitted_fragment_count,
391 local->dot11TransmittedFragmentCount);
392 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
393 local->dot11MulticastTransmittedFrameCount);
394 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
395 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
396 DEBUGFS_STATS_ADD(multiple_retry_count,
397 local->dot11MultipleRetryCount);
398 DEBUGFS_STATS_ADD(frame_duplicate_count,
399 local->dot11FrameDuplicateCount);
400 DEBUGFS_STATS_ADD(received_fragment_count,
401 local->dot11ReceivedFragmentCount);
402 DEBUGFS_STATS_ADD(multicast_received_frame_count,
403 local->dot11MulticastReceivedFrameCount);
404 DEBUGFS_STATS_ADD(transmitted_frame_count,
405 local->dot11TransmittedFrameCount);
406 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
407 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
408 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
409 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
410 local->tx_handlers_drop_unencrypted);
411 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
412 local->tx_handlers_drop_fragment);
413 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
414 local->tx_handlers_drop_wep);
415 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
416 local->tx_handlers_drop_not_assoc);
417 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
418 local->tx_handlers_drop_unauth_port);
419 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
420 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
421 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
422 local->rx_handlers_drop_nullfunc);
423 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
424 local->rx_handlers_drop_defrag);
425 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
426 local->rx_handlers_drop_short);
427 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan,
428 local->rx_handlers_drop_passive_scan);
429 DEBUGFS_STATS_ADD(tx_expand_skb_head,
430 local->tx_expand_skb_head);
431 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
432 local->tx_expand_skb_head_cloned);
433 DEBUGFS_STATS_ADD(rx_expand_skb_head,
434 local->rx_expand_skb_head);
435 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
436 local->rx_expand_skb_head2);
437 DEBUGFS_STATS_ADD(rx_handlers_fragments,
438 local->rx_handlers_fragments);
439 DEBUGFS_STATS_ADD(tx_status_drop,
440 local->tx_status_drop);
442 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
443 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
444 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
445 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);