blob: 12db9adc0361fccb21448f3330d68cfae2e828de [file] [log] [blame]
Jiri Bence9f207f2007-05-05 11:46:38 -07001/*
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
16int mac80211_open_file_generic(struct inode *inode, struct file *file)
17{
18 file->private_data = inode->i_private;
19 return 0;
20}
21
22static 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";
Jiri Bence9f207f2007-05-05 11:46:38 -070031 default:
32 return "UNKNOWN";
33 }
34}
35
36static 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
52static 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...) \
58static 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 \
69static 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
83DEBUGFS_READONLY_FILE(channel, 20, "%d",
84 local->hw.conf.channel);
85DEBUGFS_READONLY_FILE(frequency, 20, "%d",
86 local->hw.conf.freq);
Jiri Bence9f207f2007-05-05 11:46:38 -070087DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
88 local->hw.conf.antenna_sel_tx);
89DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
90 local->hw.conf.antenna_sel_rx);
91DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
92 local->bridge_packets);
93DEBUGFS_READONLY_FILE(key_tx_rx_threshold, 20, "%d",
94 local->key_tx_rx_threshold);
95DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
96 local->rts_threshold);
97DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
98 local->fragmentation_threshold);
99DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
100 local->short_retry_limit);
101DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
102 local->long_retry_limit);
103DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
104 local->total_ps_buffered);
105DEBUGFS_READONLY_FILE(mode, 20, "%s",
106 ieee80211_mode_str(local->hw.conf.phymode));
107DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
108 local->wep_iv & 0xffffff);
Jiri Bence9f207f2007-05-05 11:46:38 -0700109DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
110 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
111
112/* statistics stuff */
113
114static inline int rtnl_lock_local(struct ieee80211_local *local)
115{
116 rtnl_lock();
117 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
118 rtnl_unlock();
119 return -ENODEV;
120 }
121 return 0;
122}
123
124#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
125 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
126
127static ssize_t format_devstat_counter(struct ieee80211_local *local,
128 char __user *userbuf,
129 size_t count, loff_t *ppos,
130 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
131 int buflen))
132{
133 struct ieee80211_low_level_stats stats;
134 char buf[20];
135 int res;
136
137 if (!local->ops->get_stats)
138 return -EOPNOTSUPP;
139
140 res = rtnl_lock_local(local);
141 if (res)
142 return res;
143
144 res = local->ops->get_stats(local_to_hw(local), &stats);
145 rtnl_unlock();
146 if (!res)
147 res = printvalue(&stats, buf, sizeof(buf));
148 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
149}
150
151#define DEBUGFS_DEVSTATS_FILE(name) \
152static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
153 char *buf, int buflen) \
154{ \
155 return scnprintf(buf, buflen, "%u\n", stats->name); \
156} \
157static ssize_t stats_ ##name## _read(struct file *file, \
158 char __user *userbuf, \
159 size_t count, loff_t *ppos) \
160{ \
161 return format_devstat_counter(file->private_data, \
162 userbuf, \
163 count, \
164 ppos, \
165 print_devstats_##name); \
166} \
167 \
168static const struct file_operations stats_ ##name## _ops = { \
169 .read = stats_ ##name## _read, \
170 .open = mac80211_open_file_generic, \
171};
172
173#define DEBUGFS_STATS_ADD(name) \
174 local->debugfs.stats.name = debugfs_create_file(#name, 0444, statsd,\
175 local, &stats_ ##name## _ops);
176
177#define DEBUGFS_STATS_DEL(name) \
178 debugfs_remove(local->debugfs.stats.name); \
179 local->debugfs.stats.name = NULL;
180
181DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
182 local->dot11TransmittedFragmentCount);
183DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
184 local->dot11MulticastTransmittedFrameCount);
185DEBUGFS_STATS_FILE(failed_count, 20, "%u",
186 local->dot11FailedCount);
187DEBUGFS_STATS_FILE(retry_count, 20, "%u",
188 local->dot11RetryCount);
189DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
190 local->dot11MultipleRetryCount);
191DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
192 local->dot11FrameDuplicateCount);
193DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
194 local->dot11ReceivedFragmentCount);
195DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
196 local->dot11MulticastReceivedFrameCount);
197DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
198 local->dot11TransmittedFrameCount);
199DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
200 local->dot11WEPUndecryptableCount);
201#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
202DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
203 local->tx_handlers_drop);
204DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
205 local->tx_handlers_queued);
206DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
207 local->tx_handlers_drop_unencrypted);
208DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
209 local->tx_handlers_drop_fragment);
210DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
211 local->tx_handlers_drop_wep);
212DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
213 local->tx_handlers_drop_not_assoc);
214DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
215 local->tx_handlers_drop_unauth_port);
216DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
217 local->rx_handlers_drop);
218DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
219 local->rx_handlers_queued);
220DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
221 local->rx_handlers_drop_nullfunc);
222DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
223 local->rx_handlers_drop_defrag);
224DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
225 local->rx_handlers_drop_short);
226DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
227 local->rx_handlers_drop_passive_scan);
228DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
229 local->tx_expand_skb_head);
230DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
231 local->tx_expand_skb_head_cloned);
232DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
233 local->rx_expand_skb_head);
234DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
235 local->rx_expand_skb_head2);
236DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
237 local->rx_handlers_fragments);
238DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
239 local->tx_status_drop);
240
241static ssize_t stats_wme_rx_queue_read(struct file *file,
242 char __user *userbuf,
243 size_t count, loff_t *ppos)
244{
245 struct ieee80211_local *local = file->private_data;
246 char buf[NUM_RX_DATA_QUEUES*15], *p = buf;
247 int i;
248
249 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
250 p += scnprintf(p, sizeof(buf)+buf-p,
251 "%u\n", local->wme_rx_queue[i]);
252
253 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
254}
255
256static const struct file_operations stats_wme_rx_queue_ops = {
257 .read = stats_wme_rx_queue_read,
258 .open = mac80211_open_file_generic,
259};
260
261static ssize_t stats_wme_tx_queue_read(struct file *file,
262 char __user *userbuf,
263 size_t count, loff_t *ppos)
264{
265 struct ieee80211_local *local = file->private_data;
266 char buf[NUM_TX_DATA_QUEUES*15], *p = buf;
267 int i;
268
269 for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
270 p += scnprintf(p, sizeof(buf)+buf-p,
271 "%u\n", local->wme_tx_queue[i]);
272
273 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
274}
275
276static const struct file_operations stats_wme_tx_queue_ops = {
277 .read = stats_wme_tx_queue_read,
278 .open = mac80211_open_file_generic,
279};
280#endif
281
282DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
283DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
284DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
285DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
286
287
288void debugfs_hw_add(struct ieee80211_local *local)
289{
290 struct dentry *phyd = local->hw.wiphy->debugfsdir;
291 struct dentry *statsd;
292
293 if (!phyd)
294 return;
295
296 local->debugfs.stations = debugfs_create_dir("stations", phyd);
297 local->debugfs.keys = debugfs_create_dir("keys", phyd);
298
299 DEBUGFS_ADD(channel);
300 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700301 DEBUGFS_ADD(antenna_sel_tx);
302 DEBUGFS_ADD(antenna_sel_rx);
303 DEBUGFS_ADD(bridge_packets);
304 DEBUGFS_ADD(key_tx_rx_threshold);
305 DEBUGFS_ADD(rts_threshold);
306 DEBUGFS_ADD(fragmentation_threshold);
307 DEBUGFS_ADD(short_retry_limit);
308 DEBUGFS_ADD(long_retry_limit);
309 DEBUGFS_ADD(total_ps_buffered);
310 DEBUGFS_ADD(mode);
311 DEBUGFS_ADD(wep_iv);
Jiri Bence9f207f2007-05-05 11:46:38 -0700312 DEBUGFS_ADD(modes);
313
314 statsd = debugfs_create_dir("statistics", phyd);
315 local->debugfs.statistics = statsd;
316
317 /* if the dir failed, don't put all the other things into the root! */
318 if (!statsd)
319 return;
320
321 DEBUGFS_STATS_ADD(transmitted_fragment_count);
322 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
323 DEBUGFS_STATS_ADD(failed_count);
324 DEBUGFS_STATS_ADD(retry_count);
325 DEBUGFS_STATS_ADD(multiple_retry_count);
326 DEBUGFS_STATS_ADD(frame_duplicate_count);
327 DEBUGFS_STATS_ADD(received_fragment_count);
328 DEBUGFS_STATS_ADD(multicast_received_frame_count);
329 DEBUGFS_STATS_ADD(transmitted_frame_count);
330 DEBUGFS_STATS_ADD(wep_undecryptable_count);
331#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
332 DEBUGFS_STATS_ADD(tx_handlers_drop);
333 DEBUGFS_STATS_ADD(tx_handlers_queued);
334 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
335 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
336 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
337 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
338 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
339 DEBUGFS_STATS_ADD(rx_handlers_drop);
340 DEBUGFS_STATS_ADD(rx_handlers_queued);
341 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
342 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
343 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
344 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
345 DEBUGFS_STATS_ADD(tx_expand_skb_head);
346 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
347 DEBUGFS_STATS_ADD(rx_expand_skb_head);
348 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
349 DEBUGFS_STATS_ADD(rx_handlers_fragments);
350 DEBUGFS_STATS_ADD(tx_status_drop);
351 DEBUGFS_STATS_ADD(wme_tx_queue);
352 DEBUGFS_STATS_ADD(wme_rx_queue);
353#endif
354 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
355 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
356 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
357 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
358}
359
360void debugfs_hw_del(struct ieee80211_local *local)
361{
362 DEBUGFS_DEL(channel);
363 DEBUGFS_DEL(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700364 DEBUGFS_DEL(antenna_sel_tx);
365 DEBUGFS_DEL(antenna_sel_rx);
366 DEBUGFS_DEL(bridge_packets);
367 DEBUGFS_DEL(key_tx_rx_threshold);
368 DEBUGFS_DEL(rts_threshold);
369 DEBUGFS_DEL(fragmentation_threshold);
370 DEBUGFS_DEL(short_retry_limit);
371 DEBUGFS_DEL(long_retry_limit);
372 DEBUGFS_DEL(total_ps_buffered);
373 DEBUGFS_DEL(mode);
374 DEBUGFS_DEL(wep_iv);
Jiri Bence9f207f2007-05-05 11:46:38 -0700375 DEBUGFS_DEL(modes);
376
377 DEBUGFS_STATS_DEL(transmitted_fragment_count);
378 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
379 DEBUGFS_STATS_DEL(failed_count);
380 DEBUGFS_STATS_DEL(retry_count);
381 DEBUGFS_STATS_DEL(multiple_retry_count);
382 DEBUGFS_STATS_DEL(frame_duplicate_count);
383 DEBUGFS_STATS_DEL(received_fragment_count);
384 DEBUGFS_STATS_DEL(multicast_received_frame_count);
385 DEBUGFS_STATS_DEL(transmitted_frame_count);
386 DEBUGFS_STATS_DEL(wep_undecryptable_count);
387 DEBUGFS_STATS_DEL(num_scans);
388#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
389 DEBUGFS_STATS_DEL(tx_handlers_drop);
390 DEBUGFS_STATS_DEL(tx_handlers_queued);
391 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
392 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
393 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
394 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
395 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
396 DEBUGFS_STATS_DEL(rx_handlers_drop);
397 DEBUGFS_STATS_DEL(rx_handlers_queued);
398 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
399 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
400 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
401 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
402 DEBUGFS_STATS_DEL(tx_expand_skb_head);
403 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
404 DEBUGFS_STATS_DEL(rx_expand_skb_head);
405 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
406 DEBUGFS_STATS_DEL(rx_handlers_fragments);
407 DEBUGFS_STATS_DEL(tx_status_drop);
408 DEBUGFS_STATS_DEL(wme_tx_queue);
409 DEBUGFS_STATS_DEL(wme_rx_queue);
410#endif
411 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
412 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
413 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
414 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
415
416 debugfs_remove(local->debugfs.statistics);
417 local->debugfs.statistics = NULL;
418 debugfs_remove(local->debugfs.stations);
419 local->debugfs.stations = NULL;
420 debugfs_remove(local->debugfs.keys);
421 local->debugfs.keys = NULL;
422}