blob: ee509f1109e2112209977f11887602154ef12171 [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
Jiri Bence9f207f2007-05-05 11:46:38 -070073#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
74 DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
75
76static ssize_t format_devstat_counter(struct ieee80211_local *local,
77 char __user *userbuf,
78 size_t count, loff_t *ppos,
79 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
80 int buflen))
81{
82 struct ieee80211_low_level_stats stats;
83 char buf[20];
84 int res;
85
86 if (!local->ops->get_stats)
87 return -EOPNOTSUPP;
88
Johannes Berg75636522008-07-09 14:40:35 +020089 rtnl_lock();
Jiri Bence9f207f2007-05-05 11:46:38 -070090 res = local->ops->get_stats(local_to_hw(local), &stats);
91 rtnl_unlock();
92 if (!res)
93 res = printvalue(&stats, buf, sizeof(buf));
94 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
95}
96
97#define DEBUGFS_DEVSTATS_FILE(name) \
98static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
99 char *buf, int buflen) \
100{ \
101 return scnprintf(buf, buflen, "%u\n", stats->name); \
102} \
103static ssize_t stats_ ##name## _read(struct file *file, \
104 char __user *userbuf, \
105 size_t count, loff_t *ppos) \
106{ \
107 return format_devstat_counter(file->private_data, \
108 userbuf, \
109 count, \
110 ppos, \
111 print_devstats_##name); \
112} \
113 \
114static const struct file_operations stats_ ##name## _ops = { \
115 .read = stats_ ##name## _read, \
116 .open = mac80211_open_file_generic, \
117};
118
119#define DEBUGFS_STATS_ADD(name) \
Johannes Bergbebb8a52008-04-04 23:33:37 +0200120 local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
Jiri Bence9f207f2007-05-05 11:46:38 -0700121 local, &stats_ ##name## _ops);
122
123#define DEBUGFS_STATS_DEL(name) \
124 debugfs_remove(local->debugfs.stats.name); \
125 local->debugfs.stats.name = NULL;
126
127DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
128 local->dot11TransmittedFragmentCount);
129DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
130 local->dot11MulticastTransmittedFrameCount);
131DEBUGFS_STATS_FILE(failed_count, 20, "%u",
132 local->dot11FailedCount);
133DEBUGFS_STATS_FILE(retry_count, 20, "%u",
134 local->dot11RetryCount);
135DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
136 local->dot11MultipleRetryCount);
137DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
138 local->dot11FrameDuplicateCount);
139DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
140 local->dot11ReceivedFragmentCount);
141DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
142 local->dot11MulticastReceivedFrameCount);
143DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
144 local->dot11TransmittedFrameCount);
145DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
146 local->dot11WEPUndecryptableCount);
147#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
148DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
149 local->tx_handlers_drop);
150DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
151 local->tx_handlers_queued);
152DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
153 local->tx_handlers_drop_unencrypted);
154DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
155 local->tx_handlers_drop_fragment);
156DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
157 local->tx_handlers_drop_wep);
158DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
159 local->tx_handlers_drop_not_assoc);
160DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
161 local->tx_handlers_drop_unauth_port);
162DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
163 local->rx_handlers_drop);
164DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
165 local->rx_handlers_queued);
166DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
167 local->rx_handlers_drop_nullfunc);
168DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
169 local->rx_handlers_drop_defrag);
170DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
171 local->rx_handlers_drop_short);
172DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
173 local->rx_handlers_drop_passive_scan);
174DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
175 local->tx_expand_skb_head);
176DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
177 local->tx_expand_skb_head_cloned);
178DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
179 local->rx_expand_skb_head);
180DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
181 local->rx_expand_skb_head2);
182DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
183 local->rx_handlers_fragments);
184DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
185 local->tx_status_drop);
186
Jiri Bence9f207f2007-05-05 11:46:38 -0700187#endif
188
189DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
190DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
191DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
192DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
193
194
195void debugfs_hw_add(struct ieee80211_local *local)
196{
197 struct dentry *phyd = local->hw.wiphy->debugfsdir;
198 struct dentry *statsd;
199
200 if (!phyd)
201 return;
202
203 local->debugfs.stations = debugfs_create_dir("stations", phyd);
204 local->debugfs.keys = debugfs_create_dir("keys", phyd);
205
Jiri Bence9f207f2007-05-05 11:46:38 -0700206 DEBUGFS_ADD(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700207 DEBUGFS_ADD(antenna_sel_tx);
208 DEBUGFS_ADD(antenna_sel_rx);
209 DEBUGFS_ADD(bridge_packets);
Jiri Bence9f207f2007-05-05 11:46:38 -0700210 DEBUGFS_ADD(rts_threshold);
211 DEBUGFS_ADD(fragmentation_threshold);
212 DEBUGFS_ADD(short_retry_limit);
213 DEBUGFS_ADD(long_retry_limit);
214 DEBUGFS_ADD(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700215 DEBUGFS_ADD(wep_iv);
Jiri Bence9f207f2007-05-05 11:46:38 -0700216
217 statsd = debugfs_create_dir("statistics", phyd);
218 local->debugfs.statistics = statsd;
219
220 /* if the dir failed, don't put all the other things into the root! */
221 if (!statsd)
222 return;
223
224 DEBUGFS_STATS_ADD(transmitted_fragment_count);
225 DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
226 DEBUGFS_STATS_ADD(failed_count);
227 DEBUGFS_STATS_ADD(retry_count);
228 DEBUGFS_STATS_ADD(multiple_retry_count);
229 DEBUGFS_STATS_ADD(frame_duplicate_count);
230 DEBUGFS_STATS_ADD(received_fragment_count);
231 DEBUGFS_STATS_ADD(multicast_received_frame_count);
232 DEBUGFS_STATS_ADD(transmitted_frame_count);
233 DEBUGFS_STATS_ADD(wep_undecryptable_count);
234#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
235 DEBUGFS_STATS_ADD(tx_handlers_drop);
236 DEBUGFS_STATS_ADD(tx_handlers_queued);
237 DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
238 DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
239 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
240 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
241 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
242 DEBUGFS_STATS_ADD(rx_handlers_drop);
243 DEBUGFS_STATS_ADD(rx_handlers_queued);
244 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
245 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
246 DEBUGFS_STATS_ADD(rx_handlers_drop_short);
247 DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
248 DEBUGFS_STATS_ADD(tx_expand_skb_head);
249 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
250 DEBUGFS_STATS_ADD(rx_expand_skb_head);
251 DEBUGFS_STATS_ADD(rx_expand_skb_head2);
252 DEBUGFS_STATS_ADD(rx_handlers_fragments);
253 DEBUGFS_STATS_ADD(tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700254#endif
255 DEBUGFS_STATS_ADD(dot11ACKFailureCount);
256 DEBUGFS_STATS_ADD(dot11RTSFailureCount);
257 DEBUGFS_STATS_ADD(dot11FCSErrorCount);
258 DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
259}
260
261void debugfs_hw_del(struct ieee80211_local *local)
262{
Jiri Bence9f207f2007-05-05 11:46:38 -0700263 DEBUGFS_DEL(frequency);
Jiri Bence9f207f2007-05-05 11:46:38 -0700264 DEBUGFS_DEL(antenna_sel_tx);
265 DEBUGFS_DEL(antenna_sel_rx);
266 DEBUGFS_DEL(bridge_packets);
Jiri Bence9f207f2007-05-05 11:46:38 -0700267 DEBUGFS_DEL(rts_threshold);
268 DEBUGFS_DEL(fragmentation_threshold);
269 DEBUGFS_DEL(short_retry_limit);
270 DEBUGFS_DEL(long_retry_limit);
271 DEBUGFS_DEL(total_ps_buffered);
Jiri Bence9f207f2007-05-05 11:46:38 -0700272 DEBUGFS_DEL(wep_iv);
Jiri Bence9f207f2007-05-05 11:46:38 -0700273
274 DEBUGFS_STATS_DEL(transmitted_fragment_count);
275 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
276 DEBUGFS_STATS_DEL(failed_count);
277 DEBUGFS_STATS_DEL(retry_count);
278 DEBUGFS_STATS_DEL(multiple_retry_count);
279 DEBUGFS_STATS_DEL(frame_duplicate_count);
280 DEBUGFS_STATS_DEL(received_fragment_count);
281 DEBUGFS_STATS_DEL(multicast_received_frame_count);
282 DEBUGFS_STATS_DEL(transmitted_frame_count);
283 DEBUGFS_STATS_DEL(wep_undecryptable_count);
284 DEBUGFS_STATS_DEL(num_scans);
285#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
286 DEBUGFS_STATS_DEL(tx_handlers_drop);
287 DEBUGFS_STATS_DEL(tx_handlers_queued);
288 DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
289 DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
290 DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
291 DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
292 DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
293 DEBUGFS_STATS_DEL(rx_handlers_drop);
294 DEBUGFS_STATS_DEL(rx_handlers_queued);
295 DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
296 DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
297 DEBUGFS_STATS_DEL(rx_handlers_drop_short);
298 DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
299 DEBUGFS_STATS_DEL(tx_expand_skb_head);
300 DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
301 DEBUGFS_STATS_DEL(rx_expand_skb_head);
302 DEBUGFS_STATS_DEL(rx_expand_skb_head2);
303 DEBUGFS_STATS_DEL(rx_handlers_fragments);
304 DEBUGFS_STATS_DEL(tx_status_drop);
Jiri Bence9f207f2007-05-05 11:46:38 -0700305#endif
306 DEBUGFS_STATS_DEL(dot11ACKFailureCount);
307 DEBUGFS_STATS_DEL(dot11RTSFailureCount);
308 DEBUGFS_STATS_DEL(dot11FCSErrorCount);
309 DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
310
311 debugfs_remove(local->debugfs.statistics);
312 local->debugfs.statistics = NULL;
313 debugfs_remove(local->debugfs.stations);
314 local->debugfs.stations = NULL;
315 debugfs_remove(local->debugfs.keys);
316 local->debugfs.keys = NULL;
317}