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_FORMAT_BUFFER_SIZE 100
26 int mac80211_format_buffer(char __user
*userbuf
, size_t count
,
27 loff_t
*ppos
, char *fmt
, ...)
30 char buf
[DEBUGFS_FORMAT_BUFFER_SIZE
];
34 res
= vscnprintf(buf
, sizeof(buf
), fmt
, args
);
37 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
40 #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
41 static ssize_t name## _read(struct file *file, char __user *userbuf, \
42 size_t count, loff_t *ppos) \
44 struct ieee80211_local *local = file->private_data; \
46 return mac80211_format_buffer(userbuf, count, ppos, \
50 static const struct file_operations name## _ops = { \
51 .read = name## _read, \
52 .open = mac80211_open_file_generic, \
53 .llseek = generic_file_llseek, \
56 #define DEBUGFS_ADD(name) \
57 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
59 #define DEBUGFS_ADD_MODE(name, mode) \
60 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
63 DEBUGFS_READONLY_FILE(user_power
, "%d",
64 local
->user_power_level
);
65 DEBUGFS_READONLY_FILE(power
, "%d",
66 local
->hw
.conf
.power_level
);
67 DEBUGFS_READONLY_FILE(frequency
, "%d",
68 local
->hw
.conf
.channel
->center_freq
);
69 DEBUGFS_READONLY_FILE(total_ps_buffered
, "%d",
70 local
->total_ps_buffered
);
71 DEBUGFS_READONLY_FILE(wep_iv
, "%#08x",
72 local
->wep_iv
& 0xffffff);
73 DEBUGFS_READONLY_FILE(rate_ctrl_alg
, "%s",
74 local
->rate_ctrl
? local
->rate_ctrl
->ops
->name
: "hw/driver");
76 static ssize_t
tsf_read(struct file
*file
, char __user
*user_buf
,
77 size_t count
, loff_t
*ppos
)
79 struct ieee80211_local
*local
= file
->private_data
;
82 tsf
= drv_get_tsf(local
);
84 return mac80211_format_buffer(user_buf
, count
, ppos
, "0x%016llx\n",
85 (unsigned long long) tsf
);
88 static ssize_t
tsf_write(struct file
*file
,
89 const char __user
*user_buf
,
90 size_t count
, loff_t
*ppos
)
92 struct ieee80211_local
*local
= file
->private_data
;
93 unsigned long long tsf
;
97 len
= min(count
, sizeof(buf
) - 1);
98 if (copy_from_user(buf
, user_buf
, len
))
102 if (strncmp(buf
, "reset", 5) == 0) {
103 if (local
->ops
->reset_tsf
) {
104 drv_reset_tsf(local
);
105 wiphy_info(local
->hw
.wiphy
, "debugfs reset TSF\n");
108 tsf
= simple_strtoul(buf
, NULL
, 0);
109 if (local
->ops
->set_tsf
) {
110 drv_set_tsf(local
, tsf
);
111 wiphy_info(local
->hw
.wiphy
,
112 "debugfs set TSF to %#018llx\n", tsf
);
120 static const struct file_operations tsf_ops
= {
123 .open
= mac80211_open_file_generic
,
124 .llseek
= default_llseek
,
127 static ssize_t
reset_write(struct file
*file
, const char __user
*user_buf
,
128 size_t count
, loff_t
*ppos
)
130 struct ieee80211_local
*local
= file
->private_data
;
133 __ieee80211_suspend(&local
->hw
);
134 __ieee80211_resume(&local
->hw
);
140 static const struct file_operations reset_ops
= {
141 .write
= reset_write
,
142 .open
= mac80211_open_file_generic
,
143 .llseek
= noop_llseek
,
146 static ssize_t
noack_read(struct file
*file
, char __user
*user_buf
,
147 size_t count
, loff_t
*ppos
)
149 struct ieee80211_local
*local
= file
->private_data
;
151 return mac80211_format_buffer(user_buf
, count
, ppos
, "%d\n",
152 local
->wifi_wme_noack_test
);
155 static ssize_t
noack_write(struct file
*file
,
156 const char __user
*user_buf
,
157 size_t count
, loff_t
*ppos
)
159 struct ieee80211_local
*local
= file
->private_data
;
163 len
= min(count
, sizeof(buf
) - 1);
164 if (copy_from_user(buf
, user_buf
, len
))
168 local
->wifi_wme_noack_test
= !!simple_strtoul(buf
, NULL
, 0);
173 static const struct file_operations noack_ops
= {
175 .write
= noack_write
,
176 .open
= mac80211_open_file_generic
,
177 .llseek
= default_llseek
,
180 static ssize_t
uapsd_queues_read(struct file
*file
, char __user
*user_buf
,
181 size_t count
, loff_t
*ppos
)
183 struct ieee80211_local
*local
= file
->private_data
;
184 return mac80211_format_buffer(user_buf
, count
, ppos
, "0x%x\n",
185 local
->uapsd_queues
);
188 static ssize_t
uapsd_queues_write(struct file
*file
,
189 const char __user
*user_buf
,
190 size_t count
, loff_t
*ppos
)
192 struct ieee80211_local
*local
= file
->private_data
;
198 len
= min(count
, sizeof(buf
) - 1);
199 if (copy_from_user(buf
, user_buf
, len
))
203 ret
= strict_strtoul(buf
, 0, &val
);
208 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
211 local
->uapsd_queues
= val
;
216 static const struct file_operations uapsd_queues_ops
= {
217 .read
= uapsd_queues_read
,
218 .write
= uapsd_queues_write
,
219 .open
= mac80211_open_file_generic
,
220 .llseek
= default_llseek
,
223 static ssize_t
uapsd_max_sp_len_read(struct file
*file
, char __user
*user_buf
,
224 size_t count
, loff_t
*ppos
)
226 struct ieee80211_local
*local
= file
->private_data
;
228 return mac80211_format_buffer(user_buf
, count
, ppos
, "0x%x\n",
229 local
->uapsd_max_sp_len
);
232 static ssize_t
uapsd_max_sp_len_write(struct file
*file
,
233 const char __user
*user_buf
,
234 size_t count
, loff_t
*ppos
)
236 struct ieee80211_local
*local
= file
->private_data
;
242 len
= min(count
, sizeof(buf
) - 1);
243 if (copy_from_user(buf
, user_buf
, len
))
247 ret
= strict_strtoul(buf
, 0, &val
);
252 if (val
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
255 local
->uapsd_max_sp_len
= val
;
260 static const struct file_operations uapsd_max_sp_len_ops
= {
261 .read
= uapsd_max_sp_len_read
,
262 .write
= uapsd_max_sp_len_write
,
263 .open
= mac80211_open_file_generic
,
264 .llseek
= default_llseek
,
267 static ssize_t
channel_type_read(struct file
*file
, char __user
*user_buf
,
268 size_t count
, loff_t
*ppos
)
270 struct ieee80211_local
*local
= file
->private_data
;
273 switch (local
->hw
.conf
.channel_type
) {
274 case NL80211_CHAN_NO_HT
:
277 case NL80211_CHAN_HT20
:
280 case NL80211_CHAN_HT40MINUS
:
283 case NL80211_CHAN_HT40PLUS
:
291 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
294 static const struct file_operations channel_type_ops
= {
295 .read
= channel_type_read
,
296 .open
= mac80211_open_file_generic
,
297 .llseek
= default_llseek
,
300 static ssize_t
queues_read(struct file
*file
, char __user
*user_buf
,
301 size_t count
, loff_t
*ppos
)
303 struct ieee80211_local
*local
= file
->private_data
;
305 char buf
[IEEE80211_MAX_QUEUES
* 20];
308 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
309 for (q
= 0; q
< local
->hw
.queues
; q
++)
310 res
+= sprintf(buf
+ res
, "%02d: %#.8lx/%d\n", q
,
311 local
->queue_stop_reasons
[q
],
312 skb_queue_len(&local
->pending
[q
]));
313 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
315 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
318 static const struct file_operations queues_ops
= {
320 .open
= mac80211_open_file_generic
,
321 .llseek
= default_llseek
,
324 /* statistics stuff */
326 static ssize_t
format_devstat_counter(struct ieee80211_local
*local
,
327 char __user
*userbuf
,
328 size_t count
, loff_t
*ppos
,
329 int (*printvalue
)(struct ieee80211_low_level_stats
*stats
, char *buf
,
332 struct ieee80211_low_level_stats stats
;
337 res
= drv_get_stats(local
, &stats
);
341 res
= printvalue(&stats
, buf
, sizeof(buf
));
342 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
345 #define DEBUGFS_DEVSTATS_FILE(name) \
346 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
347 char *buf, int buflen) \
349 return scnprintf(buf, buflen, "%u\n", stats->name); \
351 static ssize_t stats_ ##name## _read(struct file *file, \
352 char __user *userbuf, \
353 size_t count, loff_t *ppos) \
355 return format_devstat_counter(file->private_data, \
359 print_devstats_##name); \
362 static const struct file_operations stats_ ##name## _ops = { \
363 .read = stats_ ##name## _read, \
364 .open = mac80211_open_file_generic, \
365 .llseek = generic_file_llseek, \
368 #define DEBUGFS_STATS_ADD(name, field) \
369 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
370 #define DEBUGFS_DEVSTATS_ADD(name) \
371 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
373 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount
);
374 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount
);
375 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount
);
376 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount
);
378 void debugfs_hw_add(struct ieee80211_local
*local
)
380 struct dentry
*phyd
= local
->hw
.wiphy
->debugfsdir
;
381 struct dentry
*statsd
;
386 local
->debugfs
.keys
= debugfs_create_dir("keys", phyd
);
388 DEBUGFS_ADD(frequency
);
389 DEBUGFS_ADD(total_ps_buffered
);
393 DEBUGFS_ADD_MODE(reset
, 0200);
395 DEBUGFS_ADD(uapsd_queues
);
396 DEBUGFS_ADD(uapsd_max_sp_len
);
397 DEBUGFS_ADD(channel_type
);
398 DEBUGFS_ADD(user_power
);
401 statsd
= debugfs_create_dir("statistics", phyd
);
403 /* if the dir failed, don't put all the other things into the root! */
407 DEBUGFS_STATS_ADD(transmitted_fragment_count
,
408 local
->dot11TransmittedFragmentCount
);
409 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count
,
410 local
->dot11MulticastTransmittedFrameCount
);
411 DEBUGFS_STATS_ADD(failed_count
, local
->dot11FailedCount
);
412 DEBUGFS_STATS_ADD(retry_count
, local
->dot11RetryCount
);
413 DEBUGFS_STATS_ADD(multiple_retry_count
,
414 local
->dot11MultipleRetryCount
);
415 DEBUGFS_STATS_ADD(frame_duplicate_count
,
416 local
->dot11FrameDuplicateCount
);
417 DEBUGFS_STATS_ADD(received_fragment_count
,
418 local
->dot11ReceivedFragmentCount
);
419 DEBUGFS_STATS_ADD(multicast_received_frame_count
,
420 local
->dot11MulticastReceivedFrameCount
);
421 DEBUGFS_STATS_ADD(transmitted_frame_count
,
422 local
->dot11TransmittedFrameCount
);
423 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
424 DEBUGFS_STATS_ADD(tx_handlers_drop
, local
->tx_handlers_drop
);
425 DEBUGFS_STATS_ADD(tx_handlers_queued
, local
->tx_handlers_queued
);
426 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted
,
427 local
->tx_handlers_drop_unencrypted
);
428 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment
,
429 local
->tx_handlers_drop_fragment
);
430 DEBUGFS_STATS_ADD(tx_handlers_drop_wep
,
431 local
->tx_handlers_drop_wep
);
432 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc
,
433 local
->tx_handlers_drop_not_assoc
);
434 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port
,
435 local
->tx_handlers_drop_unauth_port
);
436 DEBUGFS_STATS_ADD(rx_handlers_drop
, local
->rx_handlers_drop
);
437 DEBUGFS_STATS_ADD(rx_handlers_queued
, local
->rx_handlers_queued
);
438 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc
,
439 local
->rx_handlers_drop_nullfunc
);
440 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag
,
441 local
->rx_handlers_drop_defrag
);
442 DEBUGFS_STATS_ADD(rx_handlers_drop_short
,
443 local
->rx_handlers_drop_short
);
444 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan
,
445 local
->rx_handlers_drop_passive_scan
);
446 DEBUGFS_STATS_ADD(tx_expand_skb_head
,
447 local
->tx_expand_skb_head
);
448 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned
,
449 local
->tx_expand_skb_head_cloned
);
450 DEBUGFS_STATS_ADD(rx_expand_skb_head
,
451 local
->rx_expand_skb_head
);
452 DEBUGFS_STATS_ADD(rx_expand_skb_head2
,
453 local
->rx_expand_skb_head2
);
454 DEBUGFS_STATS_ADD(rx_handlers_fragments
,
455 local
->rx_handlers_fragments
);
456 DEBUGFS_STATS_ADD(tx_status_drop
,
457 local
->tx_status_drop
);
459 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount
);
460 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount
);
461 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount
);
462 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount
);