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 #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(frequency, "%d",
67 local->hw.conf.channel->center_freq);
68 DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
69 local->total_ps_buffered);
70 DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
71 local->wep_iv & 0xffffff);
72 DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
73 local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
75 static ssize_t reset_write(struct file *file, const char __user *user_buf,
76 size_t count, loff_t *ppos)
78 struct ieee80211_local *local = file->private_data;
81 __ieee80211_suspend(&local->hw, NULL);
82 __ieee80211_resume(&local->hw);
88 static const struct file_operations reset_ops = {
91 .llseek = noop_llseek,
94 static ssize_t channel_type_read(struct file *file, char __user *user_buf,
95 size_t count, loff_t *ppos)
97 struct ieee80211_local *local = file->private_data;
100 switch (local->hw.conf.channel_type) {
101 case NL80211_CHAN_NO_HT:
104 case NL80211_CHAN_HT20:
107 case NL80211_CHAN_HT40MINUS:
110 case NL80211_CHAN_HT40PLUS:
118 return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
121 static ssize_t hwflags_read(struct file *file, char __user *user_buf,
122 size_t count, loff_t *ppos)
124 struct ieee80211_local *local = file->private_data;
127 char *buf = kzalloc(mxln, GFP_KERNEL);
128 int sf = 0; /* how many written so far */
133 sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
134 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
135 sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
136 if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
137 sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
138 if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
139 sf += snprintf(buf + sf, mxln - sf,
140 "HOST_BCAST_PS_BUFFERING\n");
141 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)
142 sf += snprintf(buf + sf, mxln - sf,
143 "2GHZ_SHORT_SLOT_INCAPABLE\n");
144 if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)
145 sf += snprintf(buf + sf, mxln - sf,
146 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
147 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
148 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
149 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
150 sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
151 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
152 sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n");
153 if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
154 sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
155 if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
156 sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
157 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
158 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
159 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
160 sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
161 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
162 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
163 if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
164 sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
165 if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS)
166 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n");
167 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
168 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n");
169 if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
170 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n");
171 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
172 sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n");
173 if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
174 sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
175 if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
176 sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
177 if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
178 sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
179 if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
180 sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
181 if (local->hw.flags & IEEE80211_HW_SCAN_WHILE_IDLE)
182 sf += snprintf(buf + sf, mxln - sf, "SCAN_WHILE_IDLE\n");
184 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
189 static ssize_t queues_read(struct file *file, char __user *user_buf,
190 size_t count, loff_t *ppos)
192 struct ieee80211_local *local = file->private_data;
194 char buf[IEEE80211_MAX_QUEUES * 20];
197 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
198 for (q = 0; q < local->hw.queues; q++)
199 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
200 local->queue_stop_reasons[q],
201 skb_queue_len(&local->pending[q]));
202 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
204 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
207 DEBUGFS_READONLY_FILE_OPS(hwflags);
208 DEBUGFS_READONLY_FILE_OPS(channel_type);
209 DEBUGFS_READONLY_FILE_OPS(queues);
211 /* statistics stuff */
213 static ssize_t format_devstat_counter(struct ieee80211_local *local,
214 char __user *userbuf,
215 size_t count, loff_t *ppos,
216 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
219 struct ieee80211_low_level_stats stats;
224 res = drv_get_stats(local, &stats);
228 res = printvalue(&stats, buf, sizeof(buf));
229 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
232 #define DEBUGFS_DEVSTATS_FILE(name) \
233 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
234 char *buf, int buflen) \
236 return scnprintf(buf, buflen, "%u\n", stats->name); \
238 static ssize_t stats_ ##name## _read(struct file *file, \
239 char __user *userbuf, \
240 size_t count, loff_t *ppos) \
242 return format_devstat_counter(file->private_data, \
246 print_devstats_##name); \
249 static const struct file_operations stats_ ##name## _ops = { \
250 .read = stats_ ##name## _read, \
251 .open = simple_open, \
252 .llseek = generic_file_llseek, \
255 #define DEBUGFS_STATS_ADD(name, field) \
256 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
257 #define DEBUGFS_DEVSTATS_ADD(name) \
258 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
260 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
261 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
262 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
263 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
265 void debugfs_hw_add(struct ieee80211_local *local)
267 struct dentry *phyd = local->hw.wiphy->debugfsdir;
268 struct dentry *statsd;
273 local->debugfs.keys = debugfs_create_dir("keys", phyd);
275 DEBUGFS_ADD(frequency);
276 DEBUGFS_ADD(total_ps_buffered);
279 DEBUGFS_ADD_MODE(reset, 0200);
280 DEBUGFS_ADD(channel_type);
281 DEBUGFS_ADD(hwflags);
282 DEBUGFS_ADD(user_power);
285 statsd = debugfs_create_dir("statistics", phyd);
287 /* if the dir failed, don't put all the other things into the root! */
291 DEBUGFS_STATS_ADD(transmitted_fragment_count,
292 local->dot11TransmittedFragmentCount);
293 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count,
294 local->dot11MulticastTransmittedFrameCount);
295 DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount);
296 DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount);
297 DEBUGFS_STATS_ADD(multiple_retry_count,
298 local->dot11MultipleRetryCount);
299 DEBUGFS_STATS_ADD(frame_duplicate_count,
300 local->dot11FrameDuplicateCount);
301 DEBUGFS_STATS_ADD(received_fragment_count,
302 local->dot11ReceivedFragmentCount);
303 DEBUGFS_STATS_ADD(multicast_received_frame_count,
304 local->dot11MulticastReceivedFrameCount);
305 DEBUGFS_STATS_ADD(transmitted_frame_count,
306 local->dot11TransmittedFrameCount);
307 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
308 DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop);
309 DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued);
310 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted,
311 local->tx_handlers_drop_unencrypted);
312 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment,
313 local->tx_handlers_drop_fragment);
314 DEBUGFS_STATS_ADD(tx_handlers_drop_wep,
315 local->tx_handlers_drop_wep);
316 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc,
317 local->tx_handlers_drop_not_assoc);
318 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port,
319 local->tx_handlers_drop_unauth_port);
320 DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop);
321 DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued);
322 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc,
323 local->rx_handlers_drop_nullfunc);
324 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag,
325 local->rx_handlers_drop_defrag);
326 DEBUGFS_STATS_ADD(rx_handlers_drop_short,
327 local->rx_handlers_drop_short);
328 DEBUGFS_STATS_ADD(tx_expand_skb_head,
329 local->tx_expand_skb_head);
330 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned,
331 local->tx_expand_skb_head_cloned);
332 DEBUGFS_STATS_ADD(rx_expand_skb_head,
333 local->rx_expand_skb_head);
334 DEBUGFS_STATS_ADD(rx_expand_skb_head2,
335 local->rx_expand_skb_head2);
336 DEBUGFS_STATS_ADD(rx_handlers_fragments,
337 local->rx_handlers_fragments);
338 DEBUGFS_STATS_ADD(tx_status_drop,
339 local->tx_status_drop);
341 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
342 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
343 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
344 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);