2 * mac80211 debugfs for wireless PHYs
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
11 #include <linux/debugfs.h>
12 #include <linux/rtnetlink.h>
13 #include "ieee80211_i.h"
14 #include "driver-ops.h"
18 #define DEBUGFS_FORMAT_BUFFER_SIZE 100
20 int mac80211_format_buffer(char __user *userbuf, size_t count,
21 loff_t *ppos, char *fmt, ...)
24 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
28 res = vscnprintf(buf, sizeof(buf), fmt, args);
31 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
34 #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
35 static ssize_t name## _read(struct file *file, char __user *userbuf, \
36 size_t count, loff_t *ppos) \
38 struct ieee80211_local *local = file->private_data; \
40 return mac80211_format_buffer(userbuf, count, ppos, \
44 #define DEBUGFS_READONLY_FILE_OPS(name) \
45 static const struct file_operations name## _ops = { \
46 .read = name## _read, \
47 .open = simple_open, \
48 .llseek = generic_file_llseek, \
51 #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
52 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
53 DEBUGFS_READONLY_FILE_OPS(name)
55 #define DEBUGFS_ADD(name) \
56 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
58 #define DEBUGFS_ADD_MODE(name, mode) \
59 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
62 DEBUGFS_READONLY_FILE(user_power, "%d",
63 local->user_power_level);
64 DEBUGFS_READONLY_FILE(power, "%d",
65 local->hw.conf.power_level);
66 DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
67 local->total_ps_buffered);
68 DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
69 local->wep_iv & 0xffffff);
70 DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
71 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
74 static ssize_t reset_write(struct file *file, const char __user *user_buf,
75 size_t count, loff_t *ppos)
77 struct ieee80211_local *local = file->private_data;
80 __ieee80211_suspend(&local->hw, NULL);
81 __ieee80211_resume(&local->hw);
87 static const struct file_operations reset_ops = {
90 .llseek = noop_llseek,
94 static ssize_t hwflags_read(struct file *file, char __user *user_buf,
95 size_t count, loff_t *ppos)
97 struct ieee80211_local *local = file->private_data;
100 char *buf = kzalloc(mxln, GFP_KERNEL);
101 int sf = 0; /* how many written so far */
106 sf += scnprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
107 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
108 sf += scnprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
109 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
110 sf += scnprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
111 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
112 sf += scnprintf(buf + sf, mxln - sf,
113 "HOST_BCAST_PS_BUFFERING\n");
114 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
115 sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
116 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
117 sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
118 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC)
119 sf += scnprintf(buf + sf, mxln - sf,
120 "NEED_DTIM_BEFORE_ASSOC\n");
121 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
122 sf += scnprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
123 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
124 sf += scnprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
125 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
126 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
127 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
128 sf += scnprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
129 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
130 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
131 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
132 sf += scnprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
133 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
134 sf += scnprintf(buf + sf, mxln - sf,
135 "REPORTS_TX_ACK_STATUS\n");
136 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
137 sf += scnprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
138 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
139 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
140 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
141 sf += scnprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
142 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
143 sf += scnprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
145 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
150 static ssize_t queues_read(struct file *file, char __user *user_buf,
151 size_t count, loff_t *ppos)
153 struct ieee80211_local *local = file->private_data;
155 char buf[IEEE80211_MAX_QUEUES * 20];
158 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
159 for (q = 0; q < local->hw.queues; q++)
160 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
161 local->queue_stop_reasons[q],
162 skb_queue_len(&local->pending[q]));
163 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
165 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
168 DEBUGFS_READONLY_FILE_OPS(hwflags);
169 DEBUGFS_READONLY_FILE_OPS(queues);
171 /* statistics stuff */
173 static ssize_t format_devstat_counter(struct ieee80211_local *local,
174 char __user *userbuf,
175 size_t count, loff_t *ppos,
176 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
179 struct ieee80211_low_level_stats stats;
184 res = drv_get_stats(local, &stats);
188 res = printvalue(&stats, buf, sizeof(buf));
189 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
192 #define DEBUGFS_DEVSTATS_FILE(name) \
193 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
194 char *buf, int buflen) \
196 return scnprintf(buf, buflen, "%u\n", stats->name); \
198 static ssize_t stats_ ##name## _read(struct file *file, \
199 char __user *userbuf, \
200 size_t count, loff_t *ppos) \
202 return format_devstat_counter(file->private_data, \
206 print_devstats_##name); \
209 static const struct file_operations stats_ ##name## _ops = { \
210 .read = stats_ ##name## _read, \
211 .open = simple_open, \
212 .llseek = generic_file_llseek, \
215 #define DEBUGFS_STATS_ADD(name) \
216 debugfs_create_u32(#name, 0400, statsd, &local->name);
217 #define DEBUGFS_DEVSTATS_ADD(name) \
218 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
220 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
221 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
222 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
223 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
225 void debugfs_hw_add(struct ieee80211_local *local)
227 struct dentry *phyd = local->hw.wiphy->debugfsdir;
228 struct dentry *statsd;
233 local->debugfs.keys = debugfs_create_dir("keys", phyd);
235 DEBUGFS_ADD(total_ps_buffered);
239 DEBUGFS_ADD_MODE(reset, 0200);
241 DEBUGFS_ADD(hwflags);
242 DEBUGFS_ADD(user_power);
245 statsd = debugfs_create_dir("statistics", phyd);
247 /* if the dir failed, don't put all the other things into the root! */
251 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
252 DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
253 DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
254 DEBUGFS_STATS_ADD(dot11FailedCount);
255 DEBUGFS_STATS_ADD(dot11RetryCount);
256 DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
257 DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
258 DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
259 DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
260 DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
261 DEBUGFS_STATS_ADD(tx_handlers_drop);
262 DEBUGFS_STATS_ADD(tx_handlers_queued);
263 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
264 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
265 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
266 DEBUGFS_STATS_ADD(rx_handlers_drop);
267 DEBUGFS_STATS_ADD(rx_handlers_queued);
268 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
269 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
270 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
271 DEBUGFS_STATS_ADD(tx_expand_skb_head);
272 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
273 DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
274 DEBUGFS_STATS_ADD(rx_handlers_fragments);
275 DEBUGFS_STATS_ADD(tx_status_drop);
277 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
278 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
279 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
280 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);