add git checkout support
[openwrt.git] / package / mac80211 / src / mac80211 / debugfs.c
1 /*
2 * mac80211 debugfs for wireless PHYs
3 *
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * GPLv2
7 *
8 */
9
10 #include <linux/debugfs.h>
11 #include <linux/rtnetlink.h>
12 #include "ieee80211_i.h"
13 #include "ieee80211_rate.h"
14 #include "debugfs.h"
15
16 int mac80211_open_file_generic(struct inode *inode, struct file *file)
17 {
18 file->private_data = inode->i_private;
19 return 0;
20 }
21
22 static const char *ieee80211_mode_str(int mode)
23 {
24 switch (mode) {
25 case MODE_IEEE80211A:
26 return "IEEE 802.11a";
27 case MODE_IEEE80211B:
28 return "IEEE 802.11b";
29 case MODE_IEEE80211G:
30 return "IEEE 802.11g";
31 default:
32 return "UNKNOWN";
33 }
34 }
35
36 static ssize_t modes_read(struct file *file, char __user *userbuf,
37 size_t count, loff_t *ppos)
38 {
39 struct ieee80211_local *local = file->private_data;
40 struct ieee80211_hw_mode *mode;
41 char buf[150], *p = buf;
42
43 /* FIXME: locking! */
44 list_for_each_entry(mode, &local->modes_list, list) {
45 p += scnprintf(p, sizeof(buf)+buf-p,
46 "%s\n", ieee80211_mode_str(mode->mode));
47 }
48
49 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
50 }
51
52 static const struct file_operations modes_ops = {
53 .read = modes_read,
54 .open = mac80211_open_file_generic,
55 };
56
57 #define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
58 static ssize_t name## _read(struct file *file, char __user *userbuf, \
59 size_t count, loff_t *ppos) \
60 { \
61 struct ieee80211_local *local = file->private_data; \
62 char buf[buflen]; \
63 int res; \
64 \
65 res = scnprintf(buf, buflen, fmt "\n", ##value); \
66 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
67 } \
68 \
69 static const struct file_operations name## _ops = { \
70 .read = name## _read, \
71 .open = mac80211_open_file_generic, \
72 };
73
74 #define DEBUGFS_ADD(name) \
75 local->debugfs.name = debugfs_create_file(#name, 0444, phyd, \
76 local, &name## _ops);
77
78 #define DEBUGFS_DEL(name) \
79 debugfs_remove(local->debugfs.name); \
80 local->debugfs.name = NULL;
81
82
83 DEBUGFS_READONLY_FILE(channel, 20, "%d",
84 local->hw.conf.channel);
85 DEBUGFS_READONLY_FILE(frequency, 20, "%d",
86 local->hw.conf.freq);
87 DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
88 local->hw.conf.antenna_sel_tx);
89 DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
90 local->hw.conf.antenna_sel_rx);
91 DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
92 local->bridge_packets);
93 DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
94 local->rts_threshold);
95 DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
96 local->fragmentation_threshold);
97 DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
98 local->short_retry_limit);
99 DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
100 local->long_retry_limit);
101 DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
102 local->total_ps_buffered);
103 DEBUGFS_READONLY_FILE(mode, 20, "%s",
104 ieee80211_mode_str(local->hw.conf.phymode));
105 DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
106 local->wep_iv & 0xffffff);
107 DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
108 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
109
110 /* statistics stuff */
111
112 static inline int rtnl_lock_local(struct ieee80211_local *local)
113 {
114 rtnl_lock();
115 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
116 rtnl_unlock();
117 return -ENODEV;
118 }
119 return 0;
120 }
121
122 #define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
123 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
124
125 static ssize_t format_devstat_counter(struct ieee80211_local *local,
126 char __user *userbuf,
127 size_t count, loff_t *ppos,
128 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
129 int buflen))
130 {
131 struct ieee80211_low_level_stats stats;
132 char buf[20];
133 int res;
134
135 if (!local->ops->get_stats)
136 return -EOPNOTSUPP;
137
138 res = rtnl_lock_local(local);
139 if (res)
140 return res;
141
142 res = local->ops->get_stats(local_to_hw(local), &stats);
143 rtnl_unlock();
144 if (!res)
145 res = printvalue(&stats, buf, sizeof(buf));
146 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
147 }
148
149 #define DEBUGFS_DEVSTATS_FILE(name) \
150 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
151 char *buf, int buflen) \
152 { \
153 return scnprintf(buf, buflen, "%u\n", stats->name); \
154 } \
155 static ssize_t stats_ ##name## _read(struct file *file, \
156 char __user *userbuf, \
157 size_t count, loff_t *ppos) \
158 { \
159 return format_devstat_counter(file->private_data, \
160 userbuf, \
161 count, \
162 ppos, \
163 print_devstats_##name); \
164 } \
165 \
166 static const struct file_operations stats_ ##name## _ops = { \
167 .read = stats_ ##name## _read, \
168 .open = mac80211_open_file_generic, \
169 };
170
171 #define DEBUGFS_STATS_ADD(name) \
172 local->debugfs.stats.name = debugfs_create_file(#name, 0444, statsd,\
173 local, &stats_ ##name## _ops);
174
175 #define DEBUGFS_STATS_DEL(name) \
176 debugfs_remove(local->debugfs.stats.name); \
177 local->debugfs.stats.name = NULL;
178
179 DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
180 local->dot11TransmittedFragmentCount);
181 DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
182 local->dot11MulticastTransmittedFrameCount);
183 DEBUGFS_STATS_FILE(failed_count, 20, "%u",
184 local->dot11FailedCount);
185 DEBUGFS_STATS_FILE(retry_count, 20, "%u",
186 local->dot11RetryCount);
187 DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
188 local->dot11MultipleRetryCount);
189 DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
190 local->dot11FrameDuplicateCount);
191 DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
192 local->dot11ReceivedFragmentCount);
193 DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
194 local->dot11MulticastReceivedFrameCount);
195 DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
196 local->dot11TransmittedFrameCount);
197 DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
198 local->dot11WEPUndecryptableCount);
199 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
200 DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
201 local->tx_handlers_drop);
202 DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
203 local->tx_handlers_queued);
204 DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
205 local->tx_handlers_drop_unencrypted);
206 DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
207 local->tx_handlers_drop_fragment);
208 DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
209 local->tx_handlers_drop_wep);
210 DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
211 local->tx_handlers_drop_not_assoc);
212 DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
213 local->tx_handlers_drop_unauth_port);
214 DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
215 local->rx_handlers_drop);
216 DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
217 local->rx_handlers_queued);
218 DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
219 local->rx_handlers_drop_nullfunc);
220 DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
221 local->rx_handlers_drop_defrag);
222 DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
223 local->rx_handlers_drop_short);
224 DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
225 local->rx_handlers_drop_passive_scan);
226 DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
227 local->tx_expand_skb_head);
228 DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
229 local->tx_expand_skb_head_cloned);
230 DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
231 local->rx_expand_skb_head);
232 DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
233 local->rx_expand_skb_head2);
234 DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
235 local->rx_handlers_fragments);
236 DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
237 local->tx_status_drop);
238
239 static ssize_t stats_wme_rx_queue_read(struct file *file,
240 char __user *userbuf,
241 size_t count, loff_t *ppos)
242 {
243 struct ieee80211_local *local = file->private_data;
244 char buf[NUM_RX_DATA_QUEUES*15], *p = buf;
245 int i;
246
247 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
248 p += scnprintf(p, sizeof(buf)+buf-p,
249 "%u\n", local->wme_rx_queue[i]);
250
251 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
252 }
253
254 static const struct file_operations stats_wme_rx_queue_ops = {
255 .read = stats_wme_rx_queue_read,
256 .open = mac80211_open_file_generic,
257 };
258
259 static ssize_t stats_wme_tx_queue_read(struct file *file,
260 char __user *userbuf,
261 size_t count, loff_t *ppos)
262 {
263 struct ieee80211_local *local = file->private_data;
264 char buf[NUM_TX_DATA_QUEUES*15], *p = buf;
265 int i;
266
267 for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
268 p += scnprintf(p, sizeof(buf)+buf-p,
269 "%u\n", local->wme_tx_queue[i]);
270
271 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
272 }
273
274 static const struct file_operations stats_wme_tx_queue_ops = {
275 .read = stats_wme_tx_queue_read,
276 .open = mac80211_open_file_generic,
277 };
278 #endif
279
280 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
281 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
282 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
283 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
284
285
286 void debugfs_hw_add(struct ieee80211_local *local)
287 {
288 struct dentry *phyd = local->hw.wiphy->debugfsdir;
289 struct dentry *statsd;
290
291 if (!phyd)
292 return;
293
294 local->debugfs.stations = debugfs_create_dir("stations", phyd);
295 local->debugfs.keys = debugfs_create_dir("keys", phyd);
296
297 DEBUGFS_ADD(channel);
298 DEBUGFS_ADD(frequency);
299 DEBUGFS_ADD(antenna_sel_tx);
300 DEBUGFS_ADD(antenna_sel_rx);
301 DEBUGFS_ADD(bridge_packets);
302 DEBUGFS_ADD(rts_threshold);
303 DEBUGFS_ADD(fragmentation_threshold);
304 DEBUGFS_ADD(short_retry_limit);
305 DEBUGFS_ADD(long_retry_limit);
306 DEBUGFS_ADD(total_ps_buffered);
307 DEBUGFS_ADD(mode);
308 DEBUGFS_ADD(wep_iv);
309 DEBUGFS_ADD(modes);
310
311 statsd = debugfs_create_dir("statistics", phyd);
312 local->debugfs.statistics = statsd;
313
314 /* if the dir failed, don't put all the other things into the root! */
315 if (!statsd)
316 return;
317
318 DEBUGFS_STATS_ADD(transmitted_fragment_count);
319 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
320 DEBUGFS_STATS_ADD(failed_count);
321 DEBUGFS_STATS_ADD(retry_count);
322 DEBUGFS_STATS_ADD(multiple_retry_count);
323 DEBUGFS_STATS_ADD(frame_duplicate_count);
324 DEBUGFS_STATS_ADD(received_fragment_count);
325 DEBUGFS_STATS_ADD(multicast_received_frame_count);
326 DEBUGFS_STATS_ADD(transmitted_frame_count);
327 DEBUGFS_STATS_ADD(wep_undecryptable_count);
328 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
329 DEBUGFS_STATS_ADD(tx_handlers_drop);
330 DEBUGFS_STATS_ADD(tx_handlers_queued);
331 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
332 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
333 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
334 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
335 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
336 DEBUGFS_STATS_ADD(rx_handlers_drop);
337 DEBUGFS_STATS_ADD(rx_handlers_queued);
338 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
339 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
340 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
341 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
342 DEBUGFS_STATS_ADD(tx_expand_skb_head);
343 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
344 DEBUGFS_STATS_ADD(rx_expand_skb_head);
345 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
346 DEBUGFS_STATS_ADD(rx_handlers_fragments);
347 DEBUGFS_STATS_ADD(tx_status_drop);
348 DEBUGFS_STATS_ADD(wme_tx_queue);
349 DEBUGFS_STATS_ADD(wme_rx_queue);
350 #endif
351 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
352 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
353 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
354 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
355 }
356
357 void debugfs_hw_del(struct ieee80211_local *local)
358 {
359 DEBUGFS_DEL(channel);
360 DEBUGFS_DEL(frequency);
361 DEBUGFS_DEL(antenna_sel_tx);
362 DEBUGFS_DEL(antenna_sel_rx);
363 DEBUGFS_DEL(bridge_packets);
364 DEBUGFS_DEL(rts_threshold);
365 DEBUGFS_DEL(fragmentation_threshold);
366 DEBUGFS_DEL(short_retry_limit);
367 DEBUGFS_DEL(long_retry_limit);
368 DEBUGFS_DEL(total_ps_buffered);
369 DEBUGFS_DEL(mode);
370 DEBUGFS_DEL(wep_iv);
371 DEBUGFS_DEL(modes);
372
373 DEBUGFS_STATS_DEL(transmitted_fragment_count);
374 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
375 DEBUGFS_STATS_DEL(failed_count);
376 DEBUGFS_STATS_DEL(retry_count);
377 DEBUGFS_STATS_DEL(multiple_retry_count);
378 DEBUGFS_STATS_DEL(frame_duplicate_count);
379 DEBUGFS_STATS_DEL(received_fragment_count);
380 DEBUGFS_STATS_DEL(multicast_received_frame_count);
381 DEBUGFS_STATS_DEL(transmitted_frame_count);
382 DEBUGFS_STATS_DEL(wep_undecryptable_count);
383 DEBUGFS_STATS_DEL(num_scans);
384 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
385 DEBUGFS_STATS_DEL(tx_handlers_drop);
386 DEBUGFS_STATS_DEL(tx_handlers_queued);
387 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
388 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
389 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
390 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
391 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
392 DEBUGFS_STATS_DEL(rx_handlers_drop);
393 DEBUGFS_STATS_DEL(rx_handlers_queued);
394 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
395 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
396 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
397 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
398 DEBUGFS_STATS_DEL(tx_expand_skb_head);
399 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
400 DEBUGFS_STATS_DEL(rx_expand_skb_head);
401 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
402 DEBUGFS_STATS_DEL(rx_handlers_fragments);
403 DEBUGFS_STATS_DEL(tx_status_drop);
404 DEBUGFS_STATS_DEL(wme_tx_queue);
405 DEBUGFS_STATS_DEL(wme_rx_queue);
406 #endif
407 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
408 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
409 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
410 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
411
412 debugfs_remove(local->debugfs.statistics);
413 local->debugfs.statistics = NULL;
414 debugfs_remove(local->debugfs.stations);
415 local->debugfs.stations = NULL;
416 debugfs_remove(local->debugfs.keys);
417 local->debugfs.keys = NULL;
418 }
This page took 0.063831 seconds and 5 git commands to generate.