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 static inline int rtnl_lock_local(struct ieee80211_local *local)
19 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
26 int mac80211_open_file_generic(struct inode *inode, struct file *file)
28 file->private_data = inode->i_private;
32 static const char *ieee80211_mode_str(int mode)
36 return "IEEE 802.11a";
38 return "IEEE 802.11b";
40 return "IEEE 802.11g";
41 case MODE_ATHEROS_TURBO:
42 return "Atheros Turbo (5 GHz)";
48 static ssize_t modes_read(struct file *file, char __user *userbuf,
49 size_t count, loff_t *ppos)
51 struct ieee80211_local *local = file->private_data;
52 struct ieee80211_hw_mode *mode;
53 char buf[150], *p = buf;
56 list_for_each_entry(mode, &local->modes_list, list) {
57 p += scnprintf(p, sizeof(buf)+buf-p,
58 "%s\n", ieee80211_mode_str(mode->mode));
61 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
64 static const struct file_operations modes_ops = {
66 .open = mac80211_open_file_generic,
69 #define DEBUGFS_READ(name, buflen, fmt, value...) \
70 static ssize_t name## _read(struct file *file, char __user *userbuf, \
71 size_t count, loff_t *ppos) \
73 struct ieee80211_local *local = file->private_data; \
77 res = scnprintf(buf, buflen, fmt "\n", ##value); \
78 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
81 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
82 DEBUGFS_READ(name, buflen, fmt, ## value) \
83 static const struct file_operations name## _ops = { \
84 .read = name## _read, \
85 .open = mac80211_open_file_generic, \
88 #define DEBUGFS_ADD_MODE(name, mode) \
89 local->debugfs.name = debugfs_create_file(#name, mode, phyd, \
92 #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0444)
94 #define DEBUGFS_DEL(name) \
95 debugfs_remove(local->debugfs.name); \
96 local->debugfs.name = NULL;
99 DEBUGFS_READONLY_FILE(channel, 20, "%d",
100 local->hw.conf.channel);
101 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
102 local->hw.conf.freq);
103 DEBUGFS_READONLY_FILE(radar_detect, 20, "%d",
104 local->hw.conf.radar_detect);
105 DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
106 local->hw.conf.antenna_sel_tx);
107 DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
108 local->hw.conf.antenna_sel_rx);
109 DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
110 local->bridge_packets);
111 DEBUGFS_READONLY_FILE(key_tx_rx_threshold, 20, "%d",
112 local->key_tx_rx_threshold);
113 DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
114 local->rts_threshold);
115 DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
116 local->fragmentation_threshold);
117 DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
118 local->short_retry_limit);
119 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
120 local->long_retry_limit);
121 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
122 local->total_ps_buffered);
123 DEBUGFS_READONLY_FILE(mode, 20, "%s",
124 ieee80211_mode_str(local->hw.conf.phymode));
125 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
126 local->wep_iv & 0xffffff);
127 DEBUGFS_READONLY_FILE(tx_power_reduction, 20, "%d.%d dBm",
128 local->hw.conf.tx_power_reduction / 10,
129 local->hw.conf.tx_power_reduction & 10);
131 DEBUGFS_READ(rate_ctrl_alg, 100, "%s",
132 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
134 static ssize_t rate_ctrl_alg_write(struct file *file, const char __user *userbuf,
135 size_t count, loff_t *ppos)
137 struct ieee80211_local *local = file->private_data;
142 buf_size = min(count, ARRAY_SIZE(buf) - 1);
143 if (copy_from_user(buf, userbuf, buf_size))
145 buf[buf_size] = '\0';
146 res = rtnl_lock_local(local);
149 res = ieee80211_init_rate_ctrl_alg(local, buf);
151 return res < 0 ? res : buf_size;
154 static const struct file_operations rate_ctrl_alg_ops = {
155 .read = rate_ctrl_alg_read,
156 .write = rate_ctrl_alg_write,
157 .open = mac80211_open_file_generic,
160 /* statistics stuff */
162 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
163 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
165 static ssize_t format_devstat_counter(struct ieee80211_local *local,
166 char __user *userbuf,
167 size_t count, loff_t *ppos,
168 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
171 struct ieee80211_low_level_stats stats;
175 if (!local->ops->get_stats)
178 res = rtnl_lock_local(local);
182 res = local->ops->get_stats(local_to_hw(local), &stats);
185 res = printvalue(&stats, buf, sizeof(buf));
186 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
189 #define DEBUGFS_DEVSTATS_FILE(name) \
190 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
191 char *buf, int buflen) \
193 return scnprintf(buf, buflen, "%u\n", stats->name); \
195 static ssize_t stats_ ##name## _read(struct file *file, \
196 char __user *userbuf, \
197 size_t count, loff_t *ppos) \
199 return format_devstat_counter(file->private_data, \
203 print_devstats_##name); \
206 static const struct file_operations stats_ ##name## _ops = { \
207 .read = stats_ ##name## _read, \
208 .open = mac80211_open_file_generic, \
211 #define DEBUGFS_STATS_ADD(name) \
212 local->debugfs.stats.name = debugfs_create_file(#name, 0444, statsd,\
213 local, &stats_ ##name## _ops);
215 #define DEBUGFS_STATS_DEL(name) \
216 debugfs_remove(local->debugfs.stats.name); \
217 local->debugfs.stats.name = NULL;
219 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
220 local->dot11TransmittedFragmentCount);
221 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
222 local->dot11MulticastTransmittedFrameCount);
223 DEBUGFS_STATS_FILE(failed_count, 20, "%u",
224 local->dot11FailedCount);
225 DEBUGFS_STATS_FILE(retry_count, 20, "%u",
226 local->dot11RetryCount);
227 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
228 local->dot11MultipleRetryCount);
229 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
230 local->dot11FrameDuplicateCount);
231 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
232 local->dot11ReceivedFragmentCount);
233 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
234 local->dot11MulticastReceivedFrameCount);
235 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
236 local->dot11TransmittedFrameCount);
237 DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
238 local->dot11WEPUndecryptableCount);
239 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
240 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
241 local->tx_handlers_drop);
242 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
243 local->tx_handlers_queued);
244 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
245 local->tx_handlers_drop_unencrypted);
246 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
247 local->tx_handlers_drop_fragment);
248 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
249 local->tx_handlers_drop_wep);
250 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
251 local->tx_handlers_drop_not_assoc);
252 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
253 local->tx_handlers_drop_unauth_port);
254 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
255 local->rx_handlers_drop);
256 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
257 local->rx_handlers_queued);
258 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
259 local->rx_handlers_drop_nullfunc);
260 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
261 local->rx_handlers_drop_defrag);
262 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
263 local->rx_handlers_drop_short);
264 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
265 local->rx_handlers_drop_passive_scan);
266 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
267 local->tx_expand_skb_head);
268 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
269 local->tx_expand_skb_head_cloned);
270 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
271 local->rx_expand_skb_head);
272 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
273 local->rx_expand_skb_head2);
274 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
275 local->rx_handlers_fragments);
276 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
277 local->tx_status_drop);
279 static ssize_t stats_wme_rx_queue_read(struct file *file,
280 char __user *userbuf,
281 size_t count, loff_t *ppos)
283 struct ieee80211_local *local = file->private_data;
284 char buf[NUM_RX_DATA_QUEUES*15], *p = buf;
287 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
288 p += scnprintf(p, sizeof(buf)+buf-p,
289 "%u\n", local->wme_rx_queue[i]);
291 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
294 static const struct file_operations stats_wme_rx_queue_ops = {
295 .read = stats_wme_rx_queue_read,
296 .open = mac80211_open_file_generic,
299 static ssize_t stats_wme_tx_queue_read(struct file *file,
300 char __user *userbuf,
301 size_t count, loff_t *ppos)
303 struct ieee80211_local *local = file->private_data;
304 char buf[NUM_TX_DATA_QUEUES*15], *p = buf;
307 for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
308 p += scnprintf(p, sizeof(buf)+buf-p,
309 "%u\n", local->wme_tx_queue[i]);
311 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
314 static const struct file_operations stats_wme_tx_queue_ops = {
315 .read = stats_wme_tx_queue_read,
316 .open = mac80211_open_file_generic,
320 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
321 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
322 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
323 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
326 void debugfs_hw_add(struct ieee80211_local *local)
328 struct dentry *phyd = local->hw.wiphy->debugfsdir;
329 struct dentry *statsd;
334 local->debugfs.stations = debugfs_create_dir("stations", phyd);
335 local->debugfs.keys = debugfs_create_dir("keys", phyd);
337 DEBUGFS_ADD(channel);
338 DEBUGFS_ADD(frequency);
339 DEBUGFS_ADD(radar_detect);
340 DEBUGFS_ADD(antenna_sel_tx);
341 DEBUGFS_ADD(antenna_sel_rx);
342 DEBUGFS_ADD(bridge_packets);
343 DEBUGFS_ADD(key_tx_rx_threshold);
344 DEBUGFS_ADD(rts_threshold);
345 DEBUGFS_ADD(fragmentation_threshold);
346 DEBUGFS_ADD(short_retry_limit);
347 DEBUGFS_ADD(long_retry_limit);
348 DEBUGFS_ADD(total_ps_buffered);
351 DEBUGFS_ADD(tx_power_reduction);
352 DEBUGFS_ADD_MODE(rate_ctrl_alg, 0644);
355 statsd = debugfs_create_dir("statistics", phyd);
356 local->debugfs.statistics = statsd;
358 /* if the dir failed, don't put all the other things into the root! */
362 DEBUGFS_STATS_ADD(transmitted_fragment_count);
363 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
364 DEBUGFS_STATS_ADD(failed_count);
365 DEBUGFS_STATS_ADD(retry_count);
366 DEBUGFS_STATS_ADD(multiple_retry_count);
367 DEBUGFS_STATS_ADD(frame_duplicate_count);
368 DEBUGFS_STATS_ADD(received_fragment_count);
369 DEBUGFS_STATS_ADD(multicast_received_frame_count);
370 DEBUGFS_STATS_ADD(transmitted_frame_count);
371 DEBUGFS_STATS_ADD(wep_undecryptable_count);
372 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
373 DEBUGFS_STATS_ADD(tx_handlers_drop);
374 DEBUGFS_STATS_ADD(tx_handlers_queued);
375 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
376 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
377 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
378 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
379 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
380 DEBUGFS_STATS_ADD(rx_handlers_drop);
381 DEBUGFS_STATS_ADD(rx_handlers_queued);
382 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
383 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
384 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
385 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
386 DEBUGFS_STATS_ADD(tx_expand_skb_head);
387 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
388 DEBUGFS_STATS_ADD(rx_expand_skb_head);
389 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
390 DEBUGFS_STATS_ADD(rx_handlers_fragments);
391 DEBUGFS_STATS_ADD(tx_status_drop);
392 DEBUGFS_STATS_ADD(wme_tx_queue);
393 DEBUGFS_STATS_ADD(wme_rx_queue);
395 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
396 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
397 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
398 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
401 void debugfs_hw_del(struct ieee80211_local *local)
403 DEBUGFS_DEL(channel);
404 DEBUGFS_DEL(frequency);
405 DEBUGFS_DEL(radar_detect);
406 DEBUGFS_DEL(antenna_sel_tx);
407 DEBUGFS_DEL(antenna_sel_rx);
408 DEBUGFS_DEL(bridge_packets);
409 DEBUGFS_DEL(key_tx_rx_threshold);
410 DEBUGFS_DEL(rts_threshold);
411 DEBUGFS_DEL(fragmentation_threshold);
412 DEBUGFS_DEL(short_retry_limit);
413 DEBUGFS_DEL(long_retry_limit);
414 DEBUGFS_DEL(total_ps_buffered);
417 DEBUGFS_DEL(tx_power_reduction);
418 DEBUGFS_DEL(rate_ctrl_alg);
421 DEBUGFS_STATS_DEL(transmitted_fragment_count);
422 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
423 DEBUGFS_STATS_DEL(failed_count);
424 DEBUGFS_STATS_DEL(retry_count);
425 DEBUGFS_STATS_DEL(multiple_retry_count);
426 DEBUGFS_STATS_DEL(frame_duplicate_count);
427 DEBUGFS_STATS_DEL(received_fragment_count);
428 DEBUGFS_STATS_DEL(multicast_received_frame_count);
429 DEBUGFS_STATS_DEL(transmitted_frame_count);
430 DEBUGFS_STATS_DEL(wep_undecryptable_count);
431 DEBUGFS_STATS_DEL(num_scans);
432 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
433 DEBUGFS_STATS_DEL(tx_handlers_drop);
434 DEBUGFS_STATS_DEL(tx_handlers_queued);
435 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
436 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
437 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
438 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
439 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
440 DEBUGFS_STATS_DEL(rx_handlers_drop);
441 DEBUGFS_STATS_DEL(rx_handlers_queued);
442 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
443 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
444 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
445 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
446 DEBUGFS_STATS_DEL(tx_expand_skb_head);
447 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
448 DEBUGFS_STATS_DEL(rx_expand_skb_head);
449 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
450 DEBUGFS_STATS_DEL(rx_handlers_fragments);
451 DEBUGFS_STATS_DEL(tx_status_drop);
452 DEBUGFS_STATS_DEL(wme_tx_queue);
453 DEBUGFS_STATS_DEL(wme_rx_queue);
455 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
456 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
457 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
458 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
460 debugfs_remove(local->debugfs.statistics);
461 local->debugfs.statistics = NULL;
462 debugfs_remove(local->debugfs.stations);
463 local->debugfs.stations = NULL;
464 debugfs_remove(local->debugfs.keys);
465 local->debugfs.keys = NULL;