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"
16 int mac80211_open_file_generic(struct inode *inode, struct file *file)
18 file->private_data = inode->i_private;
22 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
23 static ssize_t name## _read(struct file *file, char __user *userbuf, \
24 size_t count, loff_t *ppos) \
26 struct ieee80211_local *local = file->private_data; \
30 res = scnprintf(buf, buflen, fmt "\n", ##value); \
31 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
34 static const struct file_operations name## _ops = { \
35 .read = name## _read, \
36 .open = mac80211_open_file_generic, \
39 #define DEBUGFS_ADD(name) \
40 local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \
43 #define DEBUGFS_DEL(name) \
44 debugfs_remove(local->debugfs.name); \
45 local->debugfs.name = NULL;
48 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
49 local->hw.conf.channel->center_freq);
50 DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
51 local->rts_threshold);
52 DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
53 local->fragmentation_threshold);
54 DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
55 local->hw.conf.short_frame_max_tx_count);
56 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
57 local->hw.conf.long_frame_max_tx_count);
58 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
59 local->total_ps_buffered);
60 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
61 local->wep_iv & 0xffffff);
62 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
63 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
65 static ssize_t tsf_read(struct file *file, char __user *user_buf,
66 size_t count, loff_t *ppos)
68 struct ieee80211_local *local = file->private_data;
72 if (local->ops->get_tsf)
73 tsf = local->ops->get_tsf(local_to_hw(local));
75 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
77 return simple_read_from_buffer(user_buf, count, ppos, buf, 19);
80 static ssize_t tsf_write(struct file *file,
81 const char __user *user_buf,
82 size_t count, loff_t *ppos)
84 struct ieee80211_local *local = file->private_data;
85 unsigned long long tsf;
89 len = min(count, sizeof(buf) - 1);
90 if (copy_from_user(buf, user_buf, len))
94 if (strncmp(buf, "reset", 5) == 0) {
95 if (local->ops->reset_tsf) {
96 local->ops->reset_tsf(local_to_hw(local));
97 printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy));
100 tsf = simple_strtoul(buf, NULL, 0);
101 if (local->ops->set_tsf) {
102 local->ops->set_tsf(local_to_hw(local), tsf);
103 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
110 static const struct file_operations tsf_ops = {
113 .open = mac80211_open_file_generic
116 /* statistics stuff */
118 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
119 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
121 static ssize_t format_devstat_counter(struct ieee80211_local *local,
122 char __user *userbuf,
123 size_t count, loff_t *ppos,
124 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
127 struct ieee80211_low_level_stats stats;
131 if (!local->ops->get_stats)
135 res = local->ops->get_stats(local_to_hw(local), &stats);
138 res = printvalue(&stats, buf, sizeof(buf));
139 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
142 #define DEBUGFS_DEVSTATS_FILE(name) \
143 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
144 char *buf, int buflen) \
146 return scnprintf(buf, buflen, "%u\n", stats->name); \
148 static ssize_t stats_ ##name## _read(struct file *file, \
149 char __user *userbuf, \
150 size_t count, loff_t *ppos) \
152 return format_devstat_counter(file->private_data, \
156 print_devstats_##name); \
159 static const struct file_operations stats_ ##name## _ops = { \
160 .read = stats_ ##name## _read, \
161 .open = mac80211_open_file_generic, \
164 #define DEBUGFS_STATS_ADD(name) \
165 local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
166 local, &stats_ ##name## _ops);
168 #define DEBUGFS_STATS_DEL(name) \
169 debugfs_remove(local->debugfs.stats.name); \
170 local->debugfs.stats.name = NULL;
172 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
173 local->dot11TransmittedFragmentCount);
174 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
175 local->dot11MulticastTransmittedFrameCount);
176 DEBUGFS_STATS_FILE(failed_count, 20, "%u",
177 local->dot11FailedCount);
178 DEBUGFS_STATS_FILE(retry_count, 20, "%u",
179 local->dot11RetryCount);
180 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
181 local->dot11MultipleRetryCount);
182 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
183 local->dot11FrameDuplicateCount);
184 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
185 local->dot11ReceivedFragmentCount);
186 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
187 local->dot11MulticastReceivedFrameCount);
188 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
189 local->dot11TransmittedFrameCount);
190 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
191 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
192 local->tx_handlers_drop);
193 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
194 local->tx_handlers_queued);
195 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
196 local->tx_handlers_drop_unencrypted);
197 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
198 local->tx_handlers_drop_fragment);
199 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
200 local->tx_handlers_drop_wep);
201 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
202 local->tx_handlers_drop_not_assoc);
203 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
204 local->tx_handlers_drop_unauth_port);
205 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
206 local->rx_handlers_drop);
207 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
208 local->rx_handlers_queued);
209 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
210 local->rx_handlers_drop_nullfunc);
211 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
212 local->rx_handlers_drop_defrag);
213 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
214 local->rx_handlers_drop_short);
215 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
216 local->rx_handlers_drop_passive_scan);
217 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
218 local->tx_expand_skb_head);
219 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
220 local->tx_expand_skb_head_cloned);
221 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
222 local->rx_expand_skb_head);
223 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
224 local->rx_expand_skb_head2);
225 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
226 local->rx_handlers_fragments);
227 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
228 local->tx_status_drop);
232 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
233 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
234 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
235 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
238 void debugfs_hw_add(struct ieee80211_local *local)
240 struct dentry *phyd = local->hw.wiphy->debugfsdir;
241 struct dentry *statsd;
246 local->debugfs.stations = debugfs_create_dir("stations", phyd);
247 local->debugfs.keys = debugfs_create_dir("keys", phyd);
249 DEBUGFS_ADD(frequency);
250 DEBUGFS_ADD(rts_threshold);
251 DEBUGFS_ADD(fragmentation_threshold);
252 DEBUGFS_ADD(short_retry_limit);
253 DEBUGFS_ADD(long_retry_limit);
254 DEBUGFS_ADD(total_ps_buffered);
258 statsd = debugfs_create_dir("statistics", phyd);
259 local->debugfs.statistics = statsd;
261 /* if the dir failed, don't put all the other things into the root! */
265 DEBUGFS_STATS_ADD(transmitted_fragment_count);
266 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
267 DEBUGFS_STATS_ADD(failed_count);
268 DEBUGFS_STATS_ADD(retry_count);
269 DEBUGFS_STATS_ADD(multiple_retry_count);
270 DEBUGFS_STATS_ADD(frame_duplicate_count);
271 DEBUGFS_STATS_ADD(received_fragment_count);
272 DEBUGFS_STATS_ADD(multicast_received_frame_count);
273 DEBUGFS_STATS_ADD(transmitted_frame_count);
274 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
275 DEBUGFS_STATS_ADD(tx_handlers_drop);
276 DEBUGFS_STATS_ADD(tx_handlers_queued);
277 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
278 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
279 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
280 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
281 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
282 DEBUGFS_STATS_ADD(rx_handlers_drop);
283 DEBUGFS_STATS_ADD(rx_handlers_queued);
284 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
285 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
286 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
287 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
288 DEBUGFS_STATS_ADD(tx_expand_skb_head);
289 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
290 DEBUGFS_STATS_ADD(rx_expand_skb_head);
291 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
292 DEBUGFS_STATS_ADD(rx_handlers_fragments);
293 DEBUGFS_STATS_ADD(tx_status_drop);
295 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
296 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
297 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
298 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
301 void debugfs_hw_del(struct ieee80211_local *local)
303 DEBUGFS_DEL(frequency);
304 DEBUGFS_DEL(rts_threshold);
305 DEBUGFS_DEL(fragmentation_threshold);
306 DEBUGFS_DEL(short_retry_limit);
307 DEBUGFS_DEL(long_retry_limit);
308 DEBUGFS_DEL(total_ps_buffered);
312 DEBUGFS_STATS_DEL(transmitted_fragment_count);
313 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
314 DEBUGFS_STATS_DEL(failed_count);
315 DEBUGFS_STATS_DEL(retry_count);
316 DEBUGFS_STATS_DEL(multiple_retry_count);
317 DEBUGFS_STATS_DEL(frame_duplicate_count);
318 DEBUGFS_STATS_DEL(received_fragment_count);
319 DEBUGFS_STATS_DEL(multicast_received_frame_count);
320 DEBUGFS_STATS_DEL(transmitted_frame_count);
321 DEBUGFS_STATS_DEL(num_scans);
322 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
323 DEBUGFS_STATS_DEL(tx_handlers_drop);
324 DEBUGFS_STATS_DEL(tx_handlers_queued);
325 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
326 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
327 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
328 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
329 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
330 DEBUGFS_STATS_DEL(rx_handlers_drop);
331 DEBUGFS_STATS_DEL(rx_handlers_queued);
332 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
333 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
334 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
335 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
336 DEBUGFS_STATS_DEL(tx_expand_skb_head);
337 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
338 DEBUGFS_STATS_DEL(rx_expand_skb_head);
339 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
340 DEBUGFS_STATS_DEL(rx_handlers_fragments);
341 DEBUGFS_STATS_DEL(tx_status_drop);
343 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
344 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
345 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
346 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
348 debugfs_remove(local->debugfs.statistics);
349 local->debugfs.statistics = NULL;
350 debugfs_remove(local->debugfs.stations);
351 local->debugfs.stations = NULL;
352 debugfs_remove(local->debugfs.keys);
353 local->debugfs.keys = NULL;