blob: 1cccbfd781f67e651dd72ff0423a2eaaae616eda [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"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040013#include "rate.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070014#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
Jiri Bence9f207f2007-05-05 11:46:38 -070022#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
23static ssize_t name## _read(struct file *file, char __user *userbuf, \
24 size_t count, loff_t *ppos) \
25{ \
26 struct ieee80211_local *local = file->private_data; \
27 char buf[buflen]; \
28 int res; \
29 \
30 res = scnprintf(buf, buflen, fmt "\n", ##value); \
31 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
32} \
33 \
34static const struct file_operations name## _ops = { \
35 .read = name## _read, \
36 .open = mac80211_open_file_generic, \
37};
38
39#define DEBUGFS_ADD(name) \
Johannes Bergbebb8a52008-04-04 23:33:37 +020040 local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \
Jiri Bence9f207f2007-05-05 11:46:38 -070041 local, &name## _ops);
42
43#define DEBUGFS_DEL(name) \
44 debugfs_remove(local->debugfs.name); \
45 local->debugfs.name = NULL;
46
47
Jiri Bence9f207f2007-05-05 11:46:38 -070048DEBUGFS_READONLY_FILE(frequency, 20, "%d",
Johannes Berg8318d782008-01-24 19:38:38 +010049 local->hw.conf.channel->center_freq);
Jiri Bence9f207f2007-05-05 11:46:38 -070050DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
51 local->hw.conf.antenna_sel_tx);
52DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
53 local->hw.conf.antenna_sel_rx);
54DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
55 local->bridge_packets);
Jiri Bence9f207f2007-05-05 11:46:38 -070056DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
57 local->rts_threshold);
58DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
59 local->fragmentation_threshold);
60DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
61 local->short_retry_limit);
62DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
63 local->long_retry_limit);
64DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
65 local->total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -070066DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
67 local->wep_iv & 0xffffff);
Jiri Bence9f207f2007-05-05 11:46:38 -070068DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
69 local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
70
71/* statistics stuff */
72
73static inline int rtnl_lock_local(struct ieee80211_local *local)
74{
75 rtnl_lock();
76 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
77 rtnl_unlock();
78 return -ENODEV;
79 }
80 return 0;
81}
82
83#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
84 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
85
86static ssize_t format_devstat_counter(struct ieee80211_local *local,
87 char __user *userbuf,
88 size_t count, loff_t *ppos,
89 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
90 int buflen))
91{
92 struct ieee80211_low_level_stats stats;
93 char buf[20];
94 int res;
95
96 if (!local->ops->get_stats)
97 return -EOPNOTSUPP;
98
99 res = rtnl_lock_local(local);
100 if (res)
101 return res;
102
103 res = local->ops->get_stats(local_to_hw(local), &stats);
104 rtnl_unlock();
105 if (!res)
106 res = printvalue(&stats, buf, sizeof(buf));
107 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
108}
109
110#define DEBUGFS_DEVSTATS_FILE(name) \
111static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
112 char *buf, int buflen) \
113{ \
114 return scnprintf(buf, buflen, "%u\n", stats->name); \
115} \
116static ssize_t stats_ ##name## _read(struct file *file, \
117 char __user *userbuf, \
118 size_t count, loff_t *ppos) \
119{ \
120 return format_devstat_counter(file->private_data, \
121 userbuf, \
122 count, \
123 ppos, \
124 print_devstats_##name); \
125} \
126 \
127static const struct file_operations stats_ ##name## _ops = { \
128 .read = stats_ ##name## _read, \
129 .open = mac80211_open_file_generic, \
130};
131
132#define DEBUGFS_STATS_ADD(name) \
Johannes Bergbebb8a52008-04-04 23:33:37 +0200133 local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
Jiri Bence9f207f2007-05-05 11:46:38 -0700134 local, &stats_ ##name## _ops);
135
136#define DEBUGFS_STATS_DEL(name) \
137 debugfs_remove(local->debugfs.stats.name); \
138 local->debugfs.stats.name = NULL;
139
140DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
141 local->dot11TransmittedFragmentCount);
142DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
143 local->dot11MulticastTransmittedFrameCount);
144DEBUGFS_STATS_FILE(failed_count, 20, "%u",
145 local->dot11FailedCount);
146DEBUGFS_STATS_FILE(retry_count, 20, "%u",
147 local->dot11RetryCount);
148DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
149 local->dot11MultipleRetryCount);
150DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
151 local->dot11FrameDuplicateCount);
152DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
153 local->dot11ReceivedFragmentCount);
154DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
155 local->dot11MulticastReceivedFrameCount);
156DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
157 local->dot11TransmittedFrameCount);
158DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
159 local->dot11WEPUndecryptableCount);
160#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
161DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
162 local->tx_handlers_drop);
163DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
164 local->tx_handlers_queued);
165DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
166 local->tx_handlers_drop_unencrypted);
167DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
168 local->tx_handlers_drop_fragment);
169DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
170 local->tx_handlers_drop_wep);
171DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
172 local->tx_handlers_drop_not_assoc);
173DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
174 local->tx_handlers_drop_unauth_port);
175DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
176 local->rx_handlers_drop);
177DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
178 local->rx_handlers_queued);
179DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
180 local->rx_handlers_drop_nullfunc);
181DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
182 local->rx_handlers_drop_defrag);
183DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
184 local->rx_handlers_drop_short);
185DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
186 local->rx_handlers_drop_passive_scan);
187DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
188 local->tx_expand_skb_head);
189DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
190 local->tx_expand_skb_head_cloned);
191DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
192 local->rx_expand_skb_head);
193DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
194 local->rx_expand_skb_head2);
195DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
196 local->rx_handlers_fragments);
197DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
198 local->tx_status_drop);
199
200static ssize_t stats_wme_rx_queue_read(struct file *file,
201 char __user *userbuf,
202 size_t count, loff_t *ppos)
203{
204 struct ieee80211_local *local = file->private_data;
205 char buf[NUM_RX_DATA_QUEUES*15], *p = buf;
206 int i;
207
208 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
209 p += scnprintf(p, sizeof(buf)+buf-p,
210 "%u\n", local->wme_rx_queue[i]);
211
212 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
213}
214
215static const struct file_operations stats_wme_rx_queue_ops = {
216 .read = stats_wme_rx_queue_read,
217 .open = mac80211_open_file_generic,
218};
219
220static ssize_t stats_wme_tx_queue_read(struct file *file,
221 char __user *userbuf,
222 size_t count, loff_t *ppos)
223{
224 struct ieee80211_local *local = file->private_data;
225 char buf[NUM_TX_DATA_QUEUES*15], *p = buf;
226 int i;
227
228 for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
229 p += scnprintf(p, sizeof(buf)+buf-p,
230 "%u\n", local->wme_tx_queue[i]);
231
232 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
233}
234
235static const struct file_operations stats_wme_tx_queue_ops = {
236 .read = stats_wme_tx_queue_read,
237 .open = mac80211_open_file_generic,
238};
239#endif
240
241DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
242DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
243DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
244DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
245
246
247void debugfs_hw_add(struct ieee80211_local *local)
248{
249 struct dentry *phyd = local->hw.wiphy->debugfsdir;
250 struct dentry *statsd;
251
252 if (!phyd)
253 return;
254
255 local->debugfs.stations = debugfs_create_dir("stations", phyd);
256 local->debugfs.keys = debugfs_create_dir("keys", phyd);
257
Jiri Bence9f207f2007-05-05 11:46:38 -0700258 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700259 DEBUGFS_ADD(antenna_sel_tx);
260 DEBUGFS_ADD(antenna_sel_rx);
261 DEBUGFS_ADD(bridge_packets);
Jiri Bence9f207f2007-05-05 11:46:38 -0700262 DEBUGFS_ADD(rts_threshold);
263 DEBUGFS_ADD(fragmentation_threshold);
264 DEBUGFS_ADD(short_retry_limit);
265 DEBUGFS_ADD(long_retry_limit);
266 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700267 DEBUGFS_ADD(wep_iv);
Jiri Bence9f207f2007-05-05 11:46:38 -0700268
269 statsd = debugfs_create_dir("statistics", phyd);
270 local->debugfs.statistics = statsd;
271
272 /* if the dir failed, don't put all the other things into the root! */
273 if (!statsd)
274 return;
275
276 DEBUGFS_STATS_ADD(transmitted_fragment_count);
277 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
278 DEBUGFS_STATS_ADD(failed_count);
279 DEBUGFS_STATS_ADD(retry_count);
280 DEBUGFS_STATS_ADD(multiple_retry_count);
281 DEBUGFS_STATS_ADD(frame_duplicate_count);
282 DEBUGFS_STATS_ADD(received_fragment_count);
283 DEBUGFS_STATS_ADD(multicast_received_frame_count);
284 DEBUGFS_STATS_ADD(transmitted_frame_count);
285 DEBUGFS_STATS_ADD(wep_undecryptable_count);
286#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
287 DEBUGFS_STATS_ADD(tx_handlers_drop);
288 DEBUGFS_STATS_ADD(tx_handlers_queued);
289 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
290 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
291 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
292 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
293 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
294 DEBUGFS_STATS_ADD(rx_handlers_drop);
295 DEBUGFS_STATS_ADD(rx_handlers_queued);
296 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
297 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
298 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
299 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
300 DEBUGFS_STATS_ADD(tx_expand_skb_head);
301 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
302 DEBUGFS_STATS_ADD(rx_expand_skb_head);
303 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
304 DEBUGFS_STATS_ADD(rx_handlers_fragments);
305 DEBUGFS_STATS_ADD(tx_status_drop);
306 DEBUGFS_STATS_ADD(wme_tx_queue);
307 DEBUGFS_STATS_ADD(wme_rx_queue);
308#endif
309 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
310 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
311 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
312 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
313}
314
315void debugfs_hw_del(struct ieee80211_local *local)
316{
Jiri Bence9f207f2007-05-05 11:46:38 -0700317 DEBUGFS_DEL(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700318 DEBUGFS_DEL(antenna_sel_tx);
319 DEBUGFS_DEL(antenna_sel_rx);
320 DEBUGFS_DEL(bridge_packets);
Jiri Bence9f207f2007-05-05 11:46:38 -0700321 DEBUGFS_DEL(rts_threshold);
322 DEBUGFS_DEL(fragmentation_threshold);
323 DEBUGFS_DEL(short_retry_limit);
324 DEBUGFS_DEL(long_retry_limit);
325 DEBUGFS_DEL(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700326 DEBUGFS_DEL(wep_iv);
Jiri Bence9f207f2007-05-05 11:46:38 -0700327
328 DEBUGFS_STATS_DEL(transmitted_fragment_count);
329 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
330 DEBUGFS_STATS_DEL(failed_count);
331 DEBUGFS_STATS_DEL(retry_count);
332 DEBUGFS_STATS_DEL(multiple_retry_count);
333 DEBUGFS_STATS_DEL(frame_duplicate_count);
334 DEBUGFS_STATS_DEL(received_fragment_count);
335 DEBUGFS_STATS_DEL(multicast_received_frame_count);
336 DEBUGFS_STATS_DEL(transmitted_frame_count);
337 DEBUGFS_STATS_DEL(wep_undecryptable_count);
338 DEBUGFS_STATS_DEL(num_scans);
339#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
340 DEBUGFS_STATS_DEL(tx_handlers_drop);
341 DEBUGFS_STATS_DEL(tx_handlers_queued);
342 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
343 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
344 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
345 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
346 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
347 DEBUGFS_STATS_DEL(rx_handlers_drop);
348 DEBUGFS_STATS_DEL(rx_handlers_queued);
349 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
350 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
351 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
352 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
353 DEBUGFS_STATS_DEL(tx_expand_skb_head);
354 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
355 DEBUGFS_STATS_DEL(rx_expand_skb_head);
356 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
357 DEBUGFS_STATS_DEL(rx_handlers_fragments);
358 DEBUGFS_STATS_DEL(tx_status_drop);
359 DEBUGFS_STATS_DEL(wme_tx_queue);
360 DEBUGFS_STATS_DEL(wme_rx_queue);
361#endif
362 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
363 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
364 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
365 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
366
367 debugfs_remove(local->debugfs.statistics);
368 local->debugfs.statistics = NULL;
369 debugfs_remove(local->debugfs.stations);
370 local->debugfs.stations = NULL;
371 debugfs_remove(local->debugfs.keys);
372 local->debugfs.keys = NULL;
373}