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 printk(KERN_INFO
"%s: debugfs reset TSF\n", wiphy_name(local
->hw
.wiphy
));
91 tsf
= simple_strtoul(buf
, NULL
, 0);
92 if (local
->ops
->set_tsf
) {
93 drv_set_tsf(local
, tsf
);
94 printk(KERN_INFO
"%s: debugfs set TSF to %#018llx\n", wiphy_name(local
->hw
.wiphy
), tsf
);
101 static const struct file_operations tsf_ops
= {
104 .open
= mac80211_open_file_generic
107 static ssize_t
reset_write(struct file
*file
, const char __user
*user_buf
,
108 size_t count
, loff_t
*ppos
)
110 struct ieee80211_local
*local
= file
->private_data
;
113 __ieee80211_suspend(&local
->hw
);
114 __ieee80211_resume(&local
->hw
);
120 static const struct file_operations reset_ops
= {
121 .write
= reset_write
,
122 .open
= mac80211_open_file_generic
,
125 static ssize_t
noack_read(struct file
*file
, char __user
*user_buf
,
126 size_t count
, loff_t
*ppos
)
128 struct ieee80211_local
*local
= file
->private_data
;
132 res
= scnprintf(buf
, sizeof(buf
), "%d\n", local
->wifi_wme_noack_test
);
134 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
137 static ssize_t
noack_write(struct file
*file
,
138 const char __user
*user_buf
,
139 size_t count
, loff_t
*ppos
)
141 struct ieee80211_local
*local
= file
->private_data
;
145 len
= min(count
, sizeof(buf
) - 1);
146 if (copy_from_user(buf
, user_buf
, len
))
150 local
->wifi_wme_noack_test
= !!simple_strtoul(buf
, NULL
, 0);
155 static const struct file_operations noack_ops
= {
157 .write
= noack_write
,
158 .open
= mac80211_open_file_generic
161 static ssize_t
uapsd_queues_read(struct file
*file
, char __user
*user_buf
,
162 size_t count
, loff_t
*ppos
)
164 struct ieee80211_local
*local
= file
->private_data
;
168 res
= scnprintf(buf
, sizeof(buf
), "0x%x\n", local
->uapsd_queues
);
170 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
173 static ssize_t
uapsd_queues_write(struct file
*file
,
174 const char __user
*user_buf
,
175 size_t count
, loff_t
*ppos
)
177 struct ieee80211_local
*local
= file
->private_data
;
183 len
= min(count
, sizeof(buf
) - 1);
184 if (copy_from_user(buf
, user_buf
, len
))
188 ret
= strict_strtoul(buf
, 0, &val
);
193 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
196 local
->uapsd_queues
= val
;
201 static const struct file_operations uapsd_queues_ops
= {
202 .read
= uapsd_queues_read
,
203 .write
= uapsd_queues_write
,
204 .open
= mac80211_open_file_generic
207 static ssize_t
uapsd_max_sp_len_read(struct file
*file
, char __user
*user_buf
,
208 size_t count
, loff_t
*ppos
)
210 struct ieee80211_local
*local
= file
->private_data
;
214 res
= scnprintf(buf
, sizeof(buf
), "0x%x\n", local
->uapsd_max_sp_len
);
216 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
219 static ssize_t
uapsd_max_sp_len_write(struct file
*file
,
220 const char __user
*user_buf
,
221 size_t count
, loff_t
*ppos
)
223 struct ieee80211_local
*local
= file
->private_data
;
229 len
= min(count
, sizeof(buf
) - 1);
230 if (copy_from_user(buf
, user_buf
, len
))
234 ret
= strict_strtoul(buf
, 0, &val
);
239 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
242 local
->uapsd_max_sp_len
= val
;
247 static const struct file_operations uapsd_max_sp_len_ops
= {
248 .read
= uapsd_max_sp_len_read
,
249 .write
= uapsd_max_sp_len_write
,
250 .open
= mac80211_open_file_generic
253 static ssize_t
channel_type_read(struct file
*file
, char __user
*user_buf
,
254 size_t count
, loff_t
*ppos
)
256 struct ieee80211_local
*local
= file
->private_data
;
259 switch (local
->hw
.conf
.channel_type
) {
260 case NL80211_CHAN_NO_HT
:
263 case NL80211_CHAN_HT20
:
266 case NL80211_CHAN_HT40MINUS
:
269 case NL80211_CHAN_HT40PLUS
:
277 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
280 static const struct file_operations channel_type_ops
= {
281 .read
= channel_type_read
,
282 .open
= mac80211_open_file_generic
285 static ssize_t
queues_read(struct file
*file
, char __user
*user_buf
,
286 size_t count
, loff_t
*ppos
)
288 struct ieee80211_local
*local
= file
->private_data
;
290 char buf
[IEEE80211_MAX_QUEUES
* 20];
293 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
294 for (q
= 0; q
< local
->hw
.queues
; q
++)
295 res
+= sprintf(buf
+ res
, "%02d: %#.8lx/%d\n", q
,
296 local
->queue_stop_reasons
[q
],
297 skb_queue_len(&local
->pending
[q
]));
298 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
300 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
303 static const struct file_operations queues_ops
= {
305 .open
= mac80211_open_file_generic
308 /* statistics stuff */
310 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
311 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
313 static ssize_t
format_devstat_counter(struct ieee80211_local
*local
,
314 char __user
*userbuf
,
315 size_t count
, loff_t
*ppos
,
316 int (*printvalue
)(struct ieee80211_low_level_stats
*stats
, char *buf
,
319 struct ieee80211_low_level_stats stats
;
324 res
= drv_get_stats(local
, &stats
);
328 res
= printvalue(&stats
, buf
, sizeof(buf
));
329 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
332 #define DEBUGFS_DEVSTATS_FILE(name) \
333 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
334 char *buf, int buflen) \
336 return scnprintf(buf, buflen, "%u\n", stats->name); \
338 static ssize_t stats_ ##name## _read(struct file *file, \
339 char __user *userbuf, \
340 size_t count, loff_t *ppos) \
342 return format_devstat_counter(file->private_data, \
346 print_devstats_##name); \
349 static const struct file_operations stats_ ##name## _ops = { \
350 .read = stats_ ##name## _read, \
351 .open = mac80211_open_file_generic, \
354 #define DEBUGFS_STATS_ADD(name) \
355 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
357 DEBUGFS_STATS_FILE(transmitted_fragment_count
, 20, "%u",
358 local
->dot11TransmittedFragmentCount
);
359 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count
, 20, "%u",
360 local
->dot11MulticastTransmittedFrameCount
);
361 DEBUGFS_STATS_FILE(failed_count
, 20, "%u",
362 local
->dot11FailedCount
);
363 DEBUGFS_STATS_FILE(retry_count
, 20, "%u",
364 local
->dot11RetryCount
);
365 DEBUGFS_STATS_FILE(multiple_retry_count
, 20, "%u",
366 local
->dot11MultipleRetryCount
);
367 DEBUGFS_STATS_FILE(frame_duplicate_count
, 20, "%u",
368 local
->dot11FrameDuplicateCount
);
369 DEBUGFS_STATS_FILE(received_fragment_count
, 20, "%u",
370 local
->dot11ReceivedFragmentCount
);
371 DEBUGFS_STATS_FILE(multicast_received_frame_count
, 20, "%u",
372 local
->dot11MulticastReceivedFrameCount
);
373 DEBUGFS_STATS_FILE(transmitted_frame_count
, 20, "%u",
374 local
->dot11TransmittedFrameCount
);
375 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
376 DEBUGFS_STATS_FILE(tx_handlers_drop
, 20, "%u",
377 local
->tx_handlers_drop
);
378 DEBUGFS_STATS_FILE(tx_handlers_queued
, 20, "%u",
379 local
->tx_handlers_queued
);
380 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted
, 20, "%u",
381 local
->tx_handlers_drop_unencrypted
);
382 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment
, 20, "%u",
383 local
->tx_handlers_drop_fragment
);
384 DEBUGFS_STATS_FILE(tx_handlers_drop_wep
, 20, "%u",
385 local
->tx_handlers_drop_wep
);
386 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc
, 20, "%u",
387 local
->tx_handlers_drop_not_assoc
);
388 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port
, 20, "%u",
389 local
->tx_handlers_drop_unauth_port
);
390 DEBUGFS_STATS_FILE(rx_handlers_drop
, 20, "%u",
391 local
->rx_handlers_drop
);
392 DEBUGFS_STATS_FILE(rx_handlers_queued
, 20, "%u",
393 local
->rx_handlers_queued
);
394 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc
, 20, "%u",
395 local
->rx_handlers_drop_nullfunc
);
396 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag
, 20, "%u",
397 local
->rx_handlers_drop_defrag
);
398 DEBUGFS_STATS_FILE(rx_handlers_drop_short
, 20, "%u",
399 local
->rx_handlers_drop_short
);
400 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan
, 20, "%u",
401 local
->rx_handlers_drop_passive_scan
);
402 DEBUGFS_STATS_FILE(tx_expand_skb_head
, 20, "%u",
403 local
->tx_expand_skb_head
);
404 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned
, 20, "%u",
405 local
->tx_expand_skb_head_cloned
);
406 DEBUGFS_STATS_FILE(rx_expand_skb_head
, 20, "%u",
407 local
->rx_expand_skb_head
);
408 DEBUGFS_STATS_FILE(rx_expand_skb_head2
, 20, "%u",
409 local
->rx_expand_skb_head2
);
410 DEBUGFS_STATS_FILE(rx_handlers_fragments
, 20, "%u",
411 local
->rx_handlers_fragments
);
412 DEBUGFS_STATS_FILE(tx_status_drop
, 20, "%u",
413 local
->tx_status_drop
);
417 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount
);
418 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount
);
419 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount
);
420 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount
);
423 void debugfs_hw_add(struct ieee80211_local
*local
)
425 struct dentry
*phyd
= local
->hw
.wiphy
->debugfsdir
;
426 struct dentry
*statsd
;
431 local
->debugfs
.stations
= debugfs_create_dir("stations", phyd
);
432 local
->debugfs
.keys
= debugfs_create_dir("keys", phyd
);
434 DEBUGFS_ADD(frequency
);
435 DEBUGFS_ADD(total_ps_buffered
);
439 DEBUGFS_ADD_MODE(reset
, 0200);
441 DEBUGFS_ADD(uapsd_queues
);
442 DEBUGFS_ADD(uapsd_max_sp_len
);
443 DEBUGFS_ADD(channel_type
);
445 statsd
= debugfs_create_dir("statistics", phyd
);
447 /* if the dir failed, don't put all the other things into the root! */
451 DEBUGFS_STATS_ADD(transmitted_fragment_count
);
452 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count
);
453 DEBUGFS_STATS_ADD(failed_count
);
454 DEBUGFS_STATS_ADD(retry_count
);
455 DEBUGFS_STATS_ADD(multiple_retry_count
);
456 DEBUGFS_STATS_ADD(frame_duplicate_count
);
457 DEBUGFS_STATS_ADD(received_fragment_count
);
458 DEBUGFS_STATS_ADD(multicast_received_frame_count
);
459 DEBUGFS_STATS_ADD(transmitted_frame_count
);
460 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
461 DEBUGFS_STATS_ADD(tx_handlers_drop
);
462 DEBUGFS_STATS_ADD(tx_handlers_queued
);
463 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted
);
464 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment
);
465 DEBUGFS_STATS_ADD(tx_handlers_drop_wep
);
466 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc
);
467 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port
);
468 DEBUGFS_STATS_ADD(rx_handlers_drop
);
469 DEBUGFS_STATS_ADD(rx_handlers_queued
);
470 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc
);
471 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag
);
472 DEBUGFS_STATS_ADD(rx_handlers_drop_short
);
473 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan
);
474 DEBUGFS_STATS_ADD(tx_expand_skb_head
);
475 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned
);
476 DEBUGFS_STATS_ADD(rx_expand_skb_head
);
477 DEBUGFS_STATS_ADD(rx_expand_skb_head2
);
478 DEBUGFS_STATS_ADD(rx_handlers_fragments
);
479 DEBUGFS_STATS_ADD(tx_status_drop
);
481 DEBUGFS_STATS_ADD(dot11ACKFailureCount
);
482 DEBUGFS_STATS_ADD(dot11RTSFailureCount
);
483 DEBUGFS_STATS_ADD(dot11FCSErrorCount
);
484 DEBUGFS_STATS_ADD(dot11RTSSuccessCount
);