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_FN(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 #define DEBUGFS_READONLY_FILE_OPS(name) \
51 static const struct file_operations name## _ops = { \
52 .read = name## _read, \
53 .open = mac80211_open_file_generic, \
54 .llseek = generic_file_llseek, \
57 #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
58 DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
59 DEBUGFS_READONLY_FILE_OPS(name)
61 #define DEBUGFS_ADD(name) \
62 debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
64 #define DEBUGFS_ADD_MODE(name, mode) \
65 debugfs_create_file(#name, mode, phyd, local, &name## _ops);
68 DEBUGFS_READONLY_FILE(user_power
, "%d",
69 local
->user_power_level
);
70 DEBUGFS_READONLY_FILE(power
, "%d",
71 local
->hw
.conf
.power_level
);
72 DEBUGFS_READONLY_FILE(frequency
, "%d",
73 local
->hw
.conf
.channel
->center_freq
);
74 DEBUGFS_READONLY_FILE(total_ps_buffered
, "%d",
75 local
->total_ps_buffered
);
76 DEBUGFS_READONLY_FILE(wep_iv
, "%#08x",
77 local
->wep_iv
& 0xffffff);
78 DEBUGFS_READONLY_FILE(rate_ctrl_alg
, "%s",
79 local
->rate_ctrl
? local
->rate_ctrl
->ops
->name
: "hw/driver");
81 static ssize_t
reset_write(struct file
*file
, const char __user
*user_buf
,
82 size_t count
, loff_t
*ppos
)
84 struct ieee80211_local
*local
= file
->private_data
;
87 __ieee80211_suspend(&local
->hw
, NULL
);
88 __ieee80211_resume(&local
->hw
);
94 static const struct file_operations reset_ops
= {
96 .open
= mac80211_open_file_generic
,
97 .llseek
= noop_llseek
,
100 static ssize_t
channel_type_read(struct file
*file
, char __user
*user_buf
,
101 size_t count
, loff_t
*ppos
)
103 struct ieee80211_local
*local
= file
->private_data
;
106 switch (local
->hw
.conf
.channel_type
) {
107 case NL80211_CHAN_NO_HT
:
110 case NL80211_CHAN_HT20
:
113 case NL80211_CHAN_HT40MINUS
:
116 case NL80211_CHAN_HT40PLUS
:
124 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
127 static ssize_t
hwflags_read(struct file
*file
, char __user
*user_buf
,
128 size_t count
, loff_t
*ppos
)
130 struct ieee80211_local
*local
= file
->private_data
;
133 char *buf
= kzalloc(mxln
, GFP_KERNEL
);
134 int sf
= 0; /* how many written so far */
139 sf
+= snprintf(buf
, mxln
- sf
, "0x%x\n", local
->hw
.flags
);
140 if (local
->hw
.flags
& IEEE80211_HW_HAS_RATE_CONTROL
)
141 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "HAS_RATE_CONTROL\n");
142 if (local
->hw
.flags
& IEEE80211_HW_RX_INCLUDES_FCS
)
143 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "RX_INCLUDES_FCS\n");
144 if (local
->hw
.flags
& IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
)
145 sf
+= snprintf(buf
+ sf
, mxln
- sf
,
146 "HOST_BCAST_PS_BUFFERING\n");
147 if (local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
)
148 sf
+= snprintf(buf
+ sf
, mxln
- sf
,
149 "2GHZ_SHORT_SLOT_INCAPABLE\n");
150 if (local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
)
151 sf
+= snprintf(buf
+ sf
, mxln
- sf
,
152 "2GHZ_SHORT_PREAMBLE_INCAPABLE\n");
153 if (local
->hw
.flags
& IEEE80211_HW_SIGNAL_UNSPEC
)
154 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SIGNAL_UNSPEC\n");
155 if (local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
)
156 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SIGNAL_DBM\n");
157 if (local
->hw
.flags
& IEEE80211_HW_NEED_DTIM_PERIOD
)
158 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "NEED_DTIM_PERIOD\n");
159 if (local
->hw
.flags
& IEEE80211_HW_SPECTRUM_MGMT
)
160 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SPECTRUM_MGMT\n");
161 if (local
->hw
.flags
& IEEE80211_HW_AMPDU_AGGREGATION
)
162 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "AMPDU_AGGREGATION\n");
163 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
)
164 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SUPPORTS_PS\n");
165 if (local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
)
166 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "PS_NULLFUNC_STACK\n");
167 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
)
168 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SUPPORTS_DYNAMIC_PS\n");
169 if (local
->hw
.flags
& IEEE80211_HW_MFP_CAPABLE
)
170 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "MFP_CAPABLE\n");
171 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_STATIC_SMPS
)
172 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SUPPORTS_STATIC_SMPS\n");
173 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
)
174 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SUPPORTS_DYNAMIC_SMPS\n");
175 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_UAPSD
)
176 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SUPPORTS_UAPSD\n");
177 if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)
178 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "REPORTS_TX_ACK_STATUS\n");
179 if (local
->hw
.flags
& IEEE80211_HW_CONNECTION_MONITOR
)
180 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "CONNECTION_MONITOR\n");
181 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PER_STA_GTK
)
182 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SUPPORTS_PER_STA_GTK\n");
183 if (local
->hw
.flags
& IEEE80211_HW_AP_LINK_PS
)
184 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "AP_LINK_PS\n");
185 if (local
->hw
.flags
& IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
)
186 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "TX_AMPDU_SETUP_IN_HW\n");
187 if (local
->hw
.flags
& IEEE80211_HW_SCAN_WHILE_IDLE
)
188 sf
+= snprintf(buf
+ sf
, mxln
- sf
, "SCAN_WHILE_IDLE\n");
190 rv
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, strlen(buf
));
195 static ssize_t
queues_read(struct file
*file
, char __user
*user_buf
,
196 size_t count
, loff_t
*ppos
)
198 struct ieee80211_local
*local
= file
->private_data
;
200 char buf
[IEEE80211_MAX_QUEUES
* 20];
203 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
204 for (q
= 0; q
< local
->hw
.queues
; q
++)
205 res
+= sprintf(buf
+ res
, "%02d: %#.8lx/%d\n", q
,
206 local
->queue_stop_reasons
[q
],
207 skb_queue_len(&local
->pending
[q
]));
208 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
210 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, res
);
213 DEBUGFS_READONLY_FILE_OPS(hwflags
);
214 DEBUGFS_READONLY_FILE_OPS(channel_type
);
215 DEBUGFS_READONLY_FILE_OPS(queues
);
217 /* statistics stuff */
219 static ssize_t
format_devstat_counter(struct ieee80211_local
*local
,
220 char __user
*userbuf
,
221 size_t count
, loff_t
*ppos
,
222 int (*printvalue
)(struct ieee80211_low_level_stats
*stats
, char *buf
,
225 struct ieee80211_low_level_stats stats
;
230 res
= drv_get_stats(local
, &stats
);
234 res
= printvalue(&stats
, buf
, sizeof(buf
));
235 return simple_read_from_buffer(userbuf
, count
, ppos
, buf
, res
);
238 #define DEBUGFS_DEVSTATS_FILE(name) \
239 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
240 char *buf, int buflen) \
242 return scnprintf(buf, buflen, "%u\n", stats->name); \
244 static ssize_t stats_ ##name## _read(struct file *file, \
245 char __user *userbuf, \
246 size_t count, loff_t *ppos) \
248 return format_devstat_counter(file->private_data, \
252 print_devstats_##name); \
255 static const struct file_operations stats_ ##name## _ops = { \
256 .read = stats_ ##name## _read, \
257 .open = mac80211_open_file_generic, \
258 .llseek = generic_file_llseek, \
261 #define DEBUGFS_STATS_ADD(name, field) \
262 debugfs_create_u32(#name, 0400, statsd, (u32 *) &field);
263 #define DEBUGFS_DEVSTATS_ADD(name) \
264 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
266 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount
);
267 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount
);
268 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount
);
269 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount
);
271 void debugfs_hw_add(struct ieee80211_local
*local
)
273 struct dentry
*phyd
= local
->hw
.wiphy
->debugfsdir
;
274 struct dentry
*statsd
;
279 local
->debugfs
.keys
= debugfs_create_dir("keys", phyd
);
281 DEBUGFS_ADD(frequency
);
282 DEBUGFS_ADD(total_ps_buffered
);
285 DEBUGFS_ADD_MODE(reset
, 0200);
286 DEBUGFS_ADD(channel_type
);
287 DEBUGFS_ADD(hwflags
);
288 DEBUGFS_ADD(user_power
);
291 statsd
= debugfs_create_dir("statistics", phyd
);
293 /* if the dir failed, don't put all the other things into the root! */
297 DEBUGFS_STATS_ADD(transmitted_fragment_count
,
298 local
->dot11TransmittedFragmentCount
);
299 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count
,
300 local
->dot11MulticastTransmittedFrameCount
);
301 DEBUGFS_STATS_ADD(failed_count
, local
->dot11FailedCount
);
302 DEBUGFS_STATS_ADD(retry_count
, local
->dot11RetryCount
);
303 DEBUGFS_STATS_ADD(multiple_retry_count
,
304 local
->dot11MultipleRetryCount
);
305 DEBUGFS_STATS_ADD(frame_duplicate_count
,
306 local
->dot11FrameDuplicateCount
);
307 DEBUGFS_STATS_ADD(received_fragment_count
,
308 local
->dot11ReceivedFragmentCount
);
309 DEBUGFS_STATS_ADD(multicast_received_frame_count
,
310 local
->dot11MulticastReceivedFrameCount
);
311 DEBUGFS_STATS_ADD(transmitted_frame_count
,
312 local
->dot11TransmittedFrameCount
);
313 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
314 DEBUGFS_STATS_ADD(tx_handlers_drop
, local
->tx_handlers_drop
);
315 DEBUGFS_STATS_ADD(tx_handlers_queued
, local
->tx_handlers_queued
);
316 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted
,
317 local
->tx_handlers_drop_unencrypted
);
318 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment
,
319 local
->tx_handlers_drop_fragment
);
320 DEBUGFS_STATS_ADD(tx_handlers_drop_wep
,
321 local
->tx_handlers_drop_wep
);
322 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc
,
323 local
->tx_handlers_drop_not_assoc
);
324 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port
,
325 local
->tx_handlers_drop_unauth_port
);
326 DEBUGFS_STATS_ADD(rx_handlers_drop
, local
->rx_handlers_drop
);
327 DEBUGFS_STATS_ADD(rx_handlers_queued
, local
->rx_handlers_queued
);
328 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc
,
329 local
->rx_handlers_drop_nullfunc
);
330 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag
,
331 local
->rx_handlers_drop_defrag
);
332 DEBUGFS_STATS_ADD(rx_handlers_drop_short
,
333 local
->rx_handlers_drop_short
);
334 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan
,
335 local
->rx_handlers_drop_passive_scan
);
336 DEBUGFS_STATS_ADD(tx_expand_skb_head
,
337 local
->tx_expand_skb_head
);
338 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned
,
339 local
->tx_expand_skb_head_cloned
);
340 DEBUGFS_STATS_ADD(rx_expand_skb_head
,
341 local
->rx_expand_skb_head
);
342 DEBUGFS_STATS_ADD(rx_expand_skb_head2
,
343 local
->rx_expand_skb_head2
);
344 DEBUGFS_STATS_ADD(rx_handlers_fragments
,
345 local
->rx_handlers_fragments
);
346 DEBUGFS_STATS_ADD(tx_status_drop
,
347 local
->tx_status_drop
);
349 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount
);
350 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount
);
351 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount
);
352 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount
);