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, \
39 .llseek = generic_file_llseek, \
42 #define DEBUGFS_ADD(name) \
43 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
45 #define DEBUGFS_ADD_MODE(name, mode) \
46 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
49 DEBUGFS_READONLY_FILE(frequency
, 20, "%d",
50 local
->hw
.conf
.channel
->center_freq
);
51 DEBUGFS_READONLY_FILE(total_ps_buffered
, 20, "%d",
52 local
->total_ps_buffered
);
53 DEBUGFS_READONLY_FILE(wep_iv
, 20, "%#08x",
54 local
->wep_iv
& 0xffffff);
55 DEBUGFS_READONLY_FILE(rate_ctrl_alg
, 100, "%s",
56 local
->rate_ctrl
? local
->rate_ctrl
->ops
->name
: "hw/driver");
58 static ssize_t
tsf_read(struct file
*file
, char __user
*user_buf
,
59 size_t count
, loff_t
*ppos
)
61 struct ieee80211_local
*local
= file
->private_data
;
65 tsf
= drv_get_tsf(local
);
67 snprintf(buf
, sizeof(buf
), "0x%016llx\n", (unsigned long long) tsf
);
69 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, 19);
72 static ssize_t
tsf_write(struct file
*file
,
73 const char __user
*user_buf
,
74 size_t count
, loff_t
*ppos
)
76 struct ieee80211_local
*local
= file
->private_data
;
77 unsigned long long tsf
;
81 len
= min(count
, sizeof(buf
) - 1);
82 if (copy_from_user(buf
, user_buf
, len
))
86 if (strncmp(buf
, "reset", 5) == 0) {
87 if (local
->ops
->reset_tsf
) {
89 printk(KERN_INFO
"%s: debugfs reset TSF\n", wiphy_name(local
->hw
.wiphy
));
92 tsf
= simple_strtoul(buf
, NULL
, 0);
93 if (local
->ops
->set_tsf
) {
94 drv_set_tsf(local
, tsf
);
95 printk(KERN_INFO
"%s: debugfs set TSF to %#018llx\n", wiphy_name(local
->hw
.wiphy
), tsf
);
102 static const struct file_operations tsf_ops
= {
105 .open
= mac80211_open_file_generic
108 static ssize_t
reset_write(struct file
*file
, const char __user
*user_buf
,
109 size_t count
, loff_t
*ppos
)
111 struct ieee80211_local
*local
= file
->private_data
;
114 __ieee80211_suspend(&local
->hw
);
115 __ieee80211_resume(&local
->hw
);
121 static const struct file_operations reset_ops
= {
122 .write
= reset_write
,
123 .open
= mac80211_open_file_generic
,
126 static ssize_t
noack_read(struct file
*file
, char __user
*user_buf
,
127 size_t count
, loff_t
*ppos
)
129 struct ieee80211_local
*local
= file
->private_data
;
133 res
= scnprintf(buf
, sizeof(buf
), "%d\n", local
->wifi_wme_noack_test
);
135 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
138 static ssize_t
noack_write(struct file
*file
,
139 const char __user
*user_buf
,
140 size_t count
, loff_t
*ppos
)
142 struct ieee80211_local
*local
= file
->private_data
;
146 len
= min(count
, sizeof(buf
) - 1);
147 if (copy_from_user(buf
, user_buf
, len
))
151 local
->wifi_wme_noack_test
= !!simple_strtoul(buf
, NULL
, 0);
156 static const struct file_operations noack_ops
= {
158 .write
= noack_write
,
159 .open
= mac80211_open_file_generic
162 static ssize_t
uapsd_queues_read(struct file
*file
, char __user
*user_buf
,
163 size_t count
, loff_t
*ppos
)
165 struct ieee80211_local
*local
= file
->private_data
;
169 res
= scnprintf(buf
, sizeof(buf
), "0x%x\n", local
->uapsd_queues
);
171 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
174 static ssize_t
uapsd_queues_write(struct file
*file
,
175 const char __user
*user_buf
,
176 size_t count
, loff_t
*ppos
)
178 struct ieee80211_local
*local
= file
->private_data
;
184 len
= min(count
, sizeof(buf
) - 1);
185 if (copy_from_user(buf
, user_buf
, len
))
189 ret
= strict_strtoul(buf
, 0, &val
);
194 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
197 local
->uapsd_queues
= val
;
202 static const struct file_operations uapsd_queues_ops
= {
203 .read
= uapsd_queues_read
,
204 .write
= uapsd_queues_write
,
205 .open
= mac80211_open_file_generic
208 static ssize_t
uapsd_max_sp_len_read(struct file
*file
, char __user
*user_buf
,
209 size_t count
, loff_t
*ppos
)
211 struct ieee80211_local
*local
= file
->private_data
;
215 res
= scnprintf(buf
, sizeof(buf
), "0x%x\n", local
->uapsd_max_sp_len
);
217 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
220 static ssize_t
uapsd_max_sp_len_write(struct file
*file
,
221 const char __user
*user_buf
,
222 size_t count
, loff_t
*ppos
)
224 struct ieee80211_local
*local
= file
->private_data
;
230 len
= min(count
, sizeof(buf
) - 1);
231 if (copy_from_user(buf
, user_buf
, len
))
235 ret
= strict_strtoul(buf
, 0, &val
);
240 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
243 local
->uapsd_max_sp_len
= val
;
248 static const struct file_operations uapsd_max_sp_len_ops
= {
249 .read
= uapsd_max_sp_len_read
,
250 .write
= uapsd_max_sp_len_write
,
251 .open
= mac80211_open_file_generic
254 static ssize_t
channel_type_read(struct file
*file
, char __user
*user_buf
,
255 size_t count
, loff_t
*ppos
)
257 struct ieee80211_local
*local
= file
->private_data
;
260 switch (local
->hw
.conf
.channel_type
) {
261 case NL80211_CHAN_NO_HT
:
264 case NL80211_CHAN_HT20
:
267 case NL80211_CHAN_HT40MINUS
:
270 case NL80211_CHAN_HT40PLUS
:
278 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
281 static const struct file_operations channel_type_ops
= {
282 .read
= channel_type_read
,
283 .open
= mac80211_open_file_generic
286 static ssize_t
queues_read(struct file
*file
, char __user
*user_buf
,
287 size_t count
, loff_t
*ppos
)
289 struct ieee80211_local
*local
= file
->private_data
;
291 char buf
[IEEE80211_MAX_QUEUES
* 20];
294 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
295 for (q
= 0; q
< local
->hw
.queues
; q
++)
296 res
+= sprintf(buf
+ res
, "%02d: %#.8lx/%d\n", q
,
297 local
->queue_stop_reasons
[q
],
298 skb_queue_len(&local
->pending
[q
]));
299 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
301 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
304 static const struct file_operations queues_ops
= {
306 .open
= mac80211_open_file_generic
309 /* statistics stuff */
311 static ssize_t
format_devstat_counter(struct ieee80211_local
*local
,
312 char __user
*userbuf
,
313 size_t count
, loff_t
*ppos
,
314 int (*printvalue
)(struct ieee80211_low_level_stats
*stats
, char *buf
,
317 struct ieee80211_low_level_stats stats
;
322 res
= drv_get_stats(local
, &stats
);
326 res
= printvalue(&stats
, buf
, sizeof(buf
));
327 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
330 #define DEBUGFS_DEVSTATS_FILE(name) \
331 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
332 char *buf, int buflen) \
334 return scnprintf(buf, buflen, "%u\n", stats->name); \
336 static ssize_t stats_ ##name## _read(struct file *file, \
337 char __user *userbuf, \
338 size_t count, loff_t *ppos) \
340 return format_devstat_counter(file->private_data, \
344 print_devstats_##name); \
347 static const struct file_operations stats_ ##name## _ops = { \
348 .read = stats_ ##name## _read, \
349 .open = mac80211_open_file_generic, \
350 .llseek = generic_file_llseek, \
353 #define DEBUGFS_STATS_ADD(name, field) \
354 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
355 #define DEBUGFS_DEVSTATS_ADD(name) \
356 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
358 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount
);
359 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount
);
360 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount
);
361 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount
);
363 void debugfs_hw_add(struct ieee80211_local
*local
)
365 struct dentry
*phyd
= local
->hw
.wiphy
->debugfsdir
;
366 struct dentry
*statsd
;
371 local
->debugfs
.stations
= debugfs_create_dir("stations", phyd
);
372 local
->debugfs
.keys
= debugfs_create_dir("keys", phyd
);
374 DEBUGFS_ADD(frequency
);
375 DEBUGFS_ADD(total_ps_buffered
);
379 DEBUGFS_ADD_MODE(reset
, 0200);
381 DEBUGFS_ADD(uapsd_queues
);
382 DEBUGFS_ADD(uapsd_max_sp_len
);
383 DEBUGFS_ADD(channel_type
);
385 statsd
= debugfs_create_dir("statistics", phyd
);
387 /* if the dir failed, don't put all the other things into the root! */
391 DEBUGFS_STATS_ADD(transmitted_fragment_count
,
392 local
->dot11TransmittedFragmentCount
);
393 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count
,
394 local
->dot11MulticastTransmittedFrameCount
);
395 DEBUGFS_STATS_ADD(failed_count
, local
->dot11FailedCount
);
396 DEBUGFS_STATS_ADD(retry_count
, local
->dot11RetryCount
);
397 DEBUGFS_STATS_ADD(multiple_retry_count
,
398 local
->dot11MultipleRetryCount
);
399 DEBUGFS_STATS_ADD(frame_duplicate_count
,
400 local
->dot11FrameDuplicateCount
);
401 DEBUGFS_STATS_ADD(received_fragment_count
,
402 local
->dot11ReceivedFragmentCount
);
403 DEBUGFS_STATS_ADD(multicast_received_frame_count
,
404 local
->dot11MulticastReceivedFrameCount
);
405 DEBUGFS_STATS_ADD(transmitted_frame_count
,
406 local
->dot11TransmittedFrameCount
);
407 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
408 DEBUGFS_STATS_ADD(tx_handlers_drop
, local
->tx_handlers_drop
);
409 DEBUGFS_STATS_ADD(tx_handlers_queued
, local
->tx_handlers_queued
);
410 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted
,
411 local
->tx_handlers_drop_unencrypted
);
412 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment
,
413 local
->tx_handlers_drop_fragment
);
414 DEBUGFS_STATS_ADD(tx_handlers_drop_wep
,
415 local
->tx_handlers_drop_wep
);
416 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc
,
417 local
->tx_handlers_drop_not_assoc
);
418 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port
,
419 local
->tx_handlers_drop_unauth_port
);
420 DEBUGFS_STATS_ADD(rx_handlers_drop
, local
->rx_handlers_drop
);
421 DEBUGFS_STATS_ADD(rx_handlers_queued
, local
->rx_handlers_queued
);
422 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc
,
423 local
->rx_handlers_drop_nullfunc
);
424 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag
,
425 local
->rx_handlers_drop_defrag
);
426 DEBUGFS_STATS_ADD(rx_handlers_drop_short
,
427 local
->rx_handlers_drop_short
);
428 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan
,
429 local
->rx_handlers_drop_passive_scan
);
430 DEBUGFS_STATS_ADD(tx_expand_skb_head
,
431 local
->tx_expand_skb_head
);
432 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned
,
433 local
->tx_expand_skb_head_cloned
);
434 DEBUGFS_STATS_ADD(rx_expand_skb_head
,
435 local
->rx_expand_skb_head
);
436 DEBUGFS_STATS_ADD(rx_expand_skb_head2
,
437 local
->rx_expand_skb_head2
);
438 DEBUGFS_STATS_ADD(rx_handlers_fragments
,
439 local
->rx_handlers_fragments
);
440 DEBUGFS_STATS_ADD(tx_status_drop
,
441 local
->tx_status_drop
);
443 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount
);
444 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount
);
445 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount
);
446 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount
);