2 * mac80211 debugfs for wireless PHYs
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
10 #include <linux/debugfs.h>
11 #include <linux/rtnetlink.h>
12 #include "ieee80211_i.h"
13 #include "ieee80211_rate.h"
16 int mac80211_open_file_generic(struct inode *inode, struct file *file)
18 file->private_data = inode->i_private;
22 static const char *ieee80211_mode_str(int mode)
26 return "IEEE 802.11a";
28 return "IEEE 802.11b";
30 return "IEEE 802.11g";
31 case MODE_ATHEROS_TURBO:
32 return "Atheros Turbo (5 GHz)";
38 static ssize_t modes_read(struct file *file, char __user *userbuf,
39 size_t count, loff_t *ppos)
41 struct ieee80211_local *local = file->private_data;
42 struct ieee80211_hw_mode *mode;
43 char buf[150], *p = buf;
46 list_for_each_entry(mode, &local->modes_list, list) {
47 p += scnprintf(p, sizeof(buf)+buf-p,
48 "%s\n", ieee80211_mode_str(mode->mode));
51 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
54 static const struct file_operations modes_ops = {
56 .open = mac80211_open_file_generic,
59 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
60 static ssize_t name## _read(struct file *file, char __user *userbuf, \
61 size_t count, loff_t *ppos) \
63 struct ieee80211_local *local = file->private_data; \
67 res = scnprintf(buf, buflen, fmt "\n", ##value); \
68 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
71 static const struct file_operations name## _ops = { \
72 .read = name## _read, \
73 .open = mac80211_open_file_generic, \
76 #define DEBUGFS_ADD(name) \
77 local->debugfs.name = debugfs_create_file(#name, 0444, phyd, \
80 #define DEBUGFS_DEL(name) \
81 debugfs_remove(local->debugfs.name); \
82 local->debugfs.name = NULL;
85 DEBUGFS_READONLY_FILE(channel, 20, "%d",
86 local->hw.conf.channel);
87 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
89 DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
90 local->hw.conf.antenna_sel_tx);
91 DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
92 local->hw.conf.antenna_sel_rx);
93 DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
94 local->bridge_packets);
95 DEBUGFS_READONLY_FILE(key_tx_rx_threshold, 20, "%d",
96 local->key_tx_rx_threshold);
97 DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
98 local->rts_threshold);
99 DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
100 local->fragmentation_threshold);
101 DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
102 local->short_retry_limit);
103 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
104 local->long_retry_limit);
105 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
106 local->total_ps_buffered);
107 DEBUGFS_READONLY_FILE(mode, 20, "%s",
108 ieee80211_mode_str(local->hw.conf.phymode));
109 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
110 local->wep_iv & 0xffffff);
111 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
112 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
114 /* statistics stuff */
116 static inline int rtnl_lock_local(struct ieee80211_local *local)
119 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
126 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
127 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
129 static ssize_t format_devstat_counter(struct ieee80211_local *local,
130 char __user *userbuf,
131 size_t count, loff_t *ppos,
132 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
135 struct ieee80211_low_level_stats stats;
139 if (!local->ops->get_stats)
142 res = rtnl_lock_local(local);
146 res = local->ops->get_stats(local_to_hw(local), &stats);
149 res = printvalue(&stats, buf, sizeof(buf));
150 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
153 #define DEBUGFS_DEVSTATS_FILE(name) \
154 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
155 char *buf, int buflen) \
157 return scnprintf(buf, buflen, "%u\n", stats->name); \
159 static ssize_t stats_ ##name## _read(struct file *file, \
160 char __user *userbuf, \
161 size_t count, loff_t *ppos) \
163 return format_devstat_counter(file->private_data, \
167 print_devstats_##name); \
170 static const struct file_operations stats_ ##name## _ops = { \
171 .read = stats_ ##name## _read, \
172 .open = mac80211_open_file_generic, \
175 #define DEBUGFS_STATS_ADD(name) \
176 local->debugfs.stats.name = debugfs_create_file(#name, 0444, statsd,\
177 local, &stats_ ##name## _ops);
179 #define DEBUGFS_STATS_DEL(name) \
180 debugfs_remove(local->debugfs.stats.name); \
181 local->debugfs.stats.name = NULL;
183 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
184 local->dot11TransmittedFragmentCount);
185 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
186 local->dot11MulticastTransmittedFrameCount);
187 DEBUGFS_STATS_FILE(failed_count, 20, "%u",
188 local->dot11FailedCount);
189 DEBUGFS_STATS_FILE(retry_count, 20, "%u",
190 local->dot11RetryCount);
191 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
192 local->dot11MultipleRetryCount);
193 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
194 local->dot11FrameDuplicateCount);
195 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
196 local->dot11ReceivedFragmentCount);
197 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
198 local->dot11MulticastReceivedFrameCount);
199 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
200 local->dot11TransmittedFrameCount);
201 DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
202 local->dot11WEPUndecryptableCount);
203 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
204 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
205 local->tx_handlers_drop);
206 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
207 local->tx_handlers_queued);
208 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
209 local->tx_handlers_drop_unencrypted);
210 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
211 local->tx_handlers_drop_fragment);
212 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
213 local->tx_handlers_drop_wep);
214 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
215 local->tx_handlers_drop_not_assoc);
216 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
217 local->tx_handlers_drop_unauth_port);
218 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
219 local->rx_handlers_drop);
220 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
221 local->rx_handlers_queued);
222 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
223 local->rx_handlers_drop_nullfunc);
224 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
225 local->rx_handlers_drop_defrag);
226 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
227 local->rx_handlers_drop_short);
228 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
229 local->rx_handlers_drop_passive_scan);
230 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
231 local->tx_expand_skb_head);
232 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
233 local->tx_expand_skb_head_cloned);
234 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
235 local->rx_expand_skb_head);
236 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
237 local->rx_expand_skb_head2);
238 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
239 local->rx_handlers_fragments);
240 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
241 local->tx_status_drop);
243 static ssize_t stats_wme_rx_queue_read(struct file *file,
244 char __user *userbuf,
245 size_t count, loff_t *ppos)
247 struct ieee80211_local *local = file->private_data;
248 char buf[NUM_RX_DATA_QUEUES*15], *p = buf;
251 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
252 p += scnprintf(p, sizeof(buf)+buf-p,
253 "%u\n", local->wme_rx_queue[i]);
255 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
258 static const struct file_operations stats_wme_rx_queue_ops = {
259 .read = stats_wme_rx_queue_read,
260 .open = mac80211_open_file_generic,
263 static ssize_t stats_wme_tx_queue_read(struct file *file,
264 char __user *userbuf,
265 size_t count, loff_t *ppos)
267 struct ieee80211_local *local = file->private_data;
268 char buf[NUM_TX_DATA_QUEUES*15], *p = buf;
271 for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
272 p += scnprintf(p, sizeof(buf)+buf-p,
273 "%u\n", local->wme_tx_queue[i]);
275 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
278 static const struct file_operations stats_wme_tx_queue_ops = {
279 .read = stats_wme_tx_queue_read,
280 .open = mac80211_open_file_generic,
284 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
285 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
286 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
287 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
290 void debugfs_hw_add(struct ieee80211_local *local)
292 struct dentry *phyd = local->hw.wiphy->debugfsdir;
293 struct dentry *statsd;
298 local->debugfs.stations = debugfs_create_dir("stations", phyd);
299 local->debugfs.keys = debugfs_create_dir("keys", phyd);
301 DEBUGFS_ADD(channel);
302 DEBUGFS_ADD(frequency);
303 DEBUGFS_ADD(antenna_sel_tx);
304 DEBUGFS_ADD(antenna_sel_rx);
305 DEBUGFS_ADD(bridge_packets);
306 DEBUGFS_ADD(key_tx_rx_threshold);
307 DEBUGFS_ADD(rts_threshold);
308 DEBUGFS_ADD(fragmentation_threshold);
309 DEBUGFS_ADD(short_retry_limit);
310 DEBUGFS_ADD(long_retry_limit);
311 DEBUGFS_ADD(total_ps_buffered);
316 statsd = debugfs_create_dir("statistics", phyd);
317 local->debugfs.statistics = statsd;
319 /* if the dir failed, don't put all the other things into the root! */
323 DEBUGFS_STATS_ADD(transmitted_fragment_count);
324 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
325 DEBUGFS_STATS_ADD(failed_count);
326 DEBUGFS_STATS_ADD(retry_count);
327 DEBUGFS_STATS_ADD(multiple_retry_count);
328 DEBUGFS_STATS_ADD(frame_duplicate_count);
329 DEBUGFS_STATS_ADD(received_fragment_count);
330 DEBUGFS_STATS_ADD(multicast_received_frame_count);
331 DEBUGFS_STATS_ADD(transmitted_frame_count);
332 DEBUGFS_STATS_ADD(wep_undecryptable_count);
333 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
334 DEBUGFS_STATS_ADD(tx_handlers_drop);
335 DEBUGFS_STATS_ADD(tx_handlers_queued);
336 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
337 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
338 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
339 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
340 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
341 DEBUGFS_STATS_ADD(rx_handlers_drop);
342 DEBUGFS_STATS_ADD(rx_handlers_queued);
343 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
344 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
345 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
346 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
347 DEBUGFS_STATS_ADD(tx_expand_skb_head);
348 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
349 DEBUGFS_STATS_ADD(rx_expand_skb_head);
350 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
351 DEBUGFS_STATS_ADD(rx_handlers_fragments);
352 DEBUGFS_STATS_ADD(tx_status_drop);
353 DEBUGFS_STATS_ADD(wme_tx_queue);
354 DEBUGFS_STATS_ADD(wme_rx_queue);
356 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
357 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
358 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
359 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
362 void debugfs_hw_del(struct ieee80211_local *local)
364 DEBUGFS_DEL(channel);
365 DEBUGFS_DEL(frequency);
366 DEBUGFS_DEL(antenna_sel_tx);
367 DEBUGFS_DEL(antenna_sel_rx);
368 DEBUGFS_DEL(bridge_packets);
369 DEBUGFS_DEL(key_tx_rx_threshold);
370 DEBUGFS_DEL(rts_threshold);
371 DEBUGFS_DEL(fragmentation_threshold);
372 DEBUGFS_DEL(short_retry_limit);
373 DEBUGFS_DEL(long_retry_limit);
374 DEBUGFS_DEL(total_ps_buffered);
379 DEBUGFS_STATS_DEL(transmitted_fragment_count);
380 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
381 DEBUGFS_STATS_DEL(failed_count);
382 DEBUGFS_STATS_DEL(retry_count);
383 DEBUGFS_STATS_DEL(multiple_retry_count);
384 DEBUGFS_STATS_DEL(frame_duplicate_count);
385 DEBUGFS_STATS_DEL(received_fragment_count);
386 DEBUGFS_STATS_DEL(multicast_received_frame_count);
387 DEBUGFS_STATS_DEL(transmitted_frame_count);
388 DEBUGFS_STATS_DEL(wep_undecryptable_count);
389 DEBUGFS_STATS_DEL(num_scans);
390 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
391 DEBUGFS_STATS_DEL(tx_handlers_drop);
392 DEBUGFS_STATS_DEL(tx_handlers_queued);
393 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
394 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
395 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
396 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
397 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
398 DEBUGFS_STATS_DEL(rx_handlers_drop);
399 DEBUGFS_STATS_DEL(rx_handlers_queued);
400 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
401 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
402 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
403 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
404 DEBUGFS_STATS_DEL(tx_expand_skb_head);
405 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
406 DEBUGFS_STATS_DEL(rx_expand_skb_head);
407 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
408 DEBUGFS_STATS_DEL(rx_handlers_fragments);
409 DEBUGFS_STATS_DEL(tx_status_drop);
410 DEBUGFS_STATS_DEL(wme_tx_queue);
411 DEBUGFS_STATS_DEL(wme_rx_queue);
413 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
414 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
415 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
416 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
418 debugfs_remove(local->debugfs.statistics);
419 local->debugfs.statistics = NULL;
420 debugfs_remove(local->debugfs.stations);
421 local->debugfs.stations = NULL;
422 debugfs_remove(local->debugfs.keys);
423 local->debugfs.keys = NULL;