Commit | Line | Data |
---|---|---|
7bcfaf2f | 1 | |
e9f207f0 JB |
2 | /* |
3 | * mac80211 debugfs for wireless PHYs | |
4 | * | |
5 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> | |
6 | * | |
7 | * GPLv2 | |
8 | * | |
9 | */ | |
10 | ||
11 | #include <linux/debugfs.h> | |
12 | #include <linux/rtnetlink.h> | |
13 | #include "ieee80211_i.h" | |
24487981 | 14 | #include "driver-ops.h" |
2c8dccc7 | 15 | #include "rate.h" |
e9f207f0 JB |
16 | #include "debugfs.h" |
17 | ||
07caf9d6 EP |
18 | #define DEBUGFS_FORMAT_BUFFER_SIZE 100 |
19 | ||
20 | int mac80211_format_buffer(char __user *userbuf, size_t count, | |
21 | loff_t *ppos, char *fmt, ...) | |
22 | { | |
23 | va_list args; | |
24 | char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; | |
25 | int res; | |
26 | ||
27 | va_start(args, fmt); | |
28 | res = vscnprintf(buf, sizeof(buf), fmt, args); | |
29 | va_end(args); | |
30 | ||
31 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); | |
32 | } | |
33 | ||
279daf64 | 34 | #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \ |
e9f207f0 JB |
35 | static ssize_t name## _read(struct file *file, char __user *userbuf, \ |
36 | size_t count, loff_t *ppos) \ | |
37 | { \ | |
38 | struct ieee80211_local *local = file->private_data; \ | |
e9f207f0 | 39 | \ |
07caf9d6 EP |
40 | return mac80211_format_buffer(userbuf, count, ppos, \ |
41 | fmt "\n", ##value); \ | |
279daf64 BG |
42 | } |
43 | ||
44 | #define DEBUGFS_READONLY_FILE_OPS(name) \ | |
e9f207f0 JB |
45 | static const struct file_operations name## _ops = { \ |
46 | .read = name## _read, \ | |
234e3405 | 47 | .open = simple_open, \ |
2b18ab36 | 48 | .llseek = generic_file_llseek, \ |
e9f207f0 JB |
49 | }; |
50 | ||
279daf64 BG |
51 | #define DEBUGFS_READONLY_FILE(name, fmt, value...) \ |
52 | DEBUGFS_READONLY_FILE_FN(name, fmt, value) \ | |
53 | DEBUGFS_READONLY_FILE_OPS(name) | |
54 | ||
e9f207f0 | 55 | #define DEBUGFS_ADD(name) \ |
7bcfaf2f | 56 | debugfs_create_file(#name, 0400, phyd, local, &name## _ops); |
e9f207f0 | 57 | |
827b1fb4 | 58 | #define DEBUGFS_ADD_MODE(name, mode) \ |
7bcfaf2f | 59 | debugfs_create_file(#name, mode, phyd, local, &name## _ops); |
e9f207f0 JB |
60 | |
61 | ||
83bdf2a1 BG |
62 | DEBUGFS_READONLY_FILE(user_power, "%d", |
63 | local->user_power_level); | |
64 | DEBUGFS_READONLY_FILE(power, "%d", | |
65 | local->hw.conf.power_level); | |
07caf9d6 | 66 | DEBUGFS_READONLY_FILE(total_ps_buffered, "%d", |
e9f207f0 | 67 | local->total_ps_buffered); |
07caf9d6 | 68 | DEBUGFS_READONLY_FILE(wep_iv, "%#08x", |
e9f207f0 | 69 | local->wep_iv & 0xffffff); |
07caf9d6 | 70 | DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s", |
af65cd96 | 71 | local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver"); |
3b5d665b | 72 | |
2ad4814f | 73 | #ifdef CONFIG_PM |
827b1fb4 JB |
74 | static ssize_t reset_write(struct file *file, const char __user *user_buf, |
75 | size_t count, loff_t *ppos) | |
76 | { | |
77 | struct ieee80211_local *local = file->private_data; | |
78 | ||
79 | rtnl_lock(); | |
eecc4800 | 80 | __ieee80211_suspend(&local->hw, NULL); |
827b1fb4 JB |
81 | __ieee80211_resume(&local->hw); |
82 | rtnl_unlock(); | |
83 | ||
84 | return count; | |
85 | } | |
86 | ||
87 | static const struct file_operations reset_ops = { | |
88 | .write = reset_write, | |
234e3405 | 89 | .open = simple_open, |
6038f373 | 90 | .llseek = noop_llseek, |
827b1fb4 | 91 | }; |
2ad4814f | 92 | #endif |
827b1fb4 | 93 | |
279daf64 BG |
94 | static ssize_t hwflags_read(struct file *file, char __user *user_buf, |
95 | size_t count, loff_t *ppos) | |
96 | { | |
97 | struct ieee80211_local *local = file->private_data; | |
98 | int mxln = 500; | |
99 | ssize_t rv; | |
100 | char *buf = kzalloc(mxln, GFP_KERNEL); | |
101 | int sf = 0; /* how many written so far */ | |
102 | ||
d15b8459 JP |
103 | if (!buf) |
104 | return 0; | |
105 | ||
279daf64 BG |
106 | sf += snprintf(buf, mxln - sf, "0x%x\n", local->hw.flags); |
107 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) | |
108 | sf += snprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n"); | |
109 | if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) | |
110 | sf += snprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n"); | |
111 | if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) | |
112 | sf += snprintf(buf + sf, mxln - sf, | |
113 | "HOST_BCAST_PS_BUFFERING\n"); | |
114 | if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE) | |
115 | sf += snprintf(buf + sf, mxln - sf, | |
116 | "2GHZ_SHORT_SLOT_INCAPABLE\n"); | |
117 | if (local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE) | |
118 | sf += snprintf(buf + sf, mxln - sf, | |
119 | "2GHZ_SHORT_PREAMBLE_INCAPABLE\n"); | |
120 | if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) | |
121 | sf += snprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n"); | |
122 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) | |
123 | sf += snprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n"); | |
124 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) | |
125 | sf += snprintf(buf + sf, mxln - sf, "NEED_DTIM_PERIOD\n"); | |
126 | if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT) | |
127 | sf += snprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n"); | |
128 | if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) | |
129 | sf += snprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n"); | |
130 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS) | |
131 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n"); | |
132 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) | |
133 | sf += snprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n"); | |
134 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) | |
135 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n"); | |
136 | if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE) | |
137 | sf += snprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n"); | |
279daf64 BG |
138 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS) |
139 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_STATIC_SMPS\n"); | |
140 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) | |
141 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_SMPS\n"); | |
142 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD) | |
143 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_UAPSD\n"); | |
144 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) | |
145 | sf += snprintf(buf + sf, mxln - sf, "REPORTS_TX_ACK_STATUS\n"); | |
146 | if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) | |
147 | sf += snprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n"); | |
279daf64 BG |
148 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK) |
149 | sf += snprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n"); | |
150 | if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) | |
151 | sf += snprintf(buf + sf, mxln - sf, "AP_LINK_PS\n"); | |
edf6b784 AN |
152 | if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW) |
153 | sf += snprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n"); | |
885bd8ec EP |
154 | if (local->hw.flags & IEEE80211_HW_SCAN_WHILE_IDLE) |
155 | sf += snprintf(buf + sf, mxln - sf, "SCAN_WHILE_IDLE\n"); | |
279daf64 BG |
156 | |
157 | rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); | |
158 | kfree(buf); | |
159 | return rv; | |
160 | } | |
199d69f2 | 161 | |
db2e6bd4 JB |
162 | static ssize_t queues_read(struct file *file, char __user *user_buf, |
163 | size_t count, loff_t *ppos) | |
164 | { | |
165 | struct ieee80211_local *local = file->private_data; | |
166 | unsigned long flags; | |
167 | char buf[IEEE80211_MAX_QUEUES * 20]; | |
168 | int q, res = 0; | |
169 | ||
170 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); | |
171 | for (q = 0; q < local->hw.queues; q++) | |
172 | res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q, | |
173 | local->queue_stop_reasons[q], | |
3b8d81e0 | 174 | skb_queue_len(&local->pending[q])); |
db2e6bd4 JB |
175 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
176 | ||
177 | return simple_read_from_buffer(user_buf, count, ppos, buf, res); | |
178 | } | |
179 | ||
279daf64 | 180 | DEBUGFS_READONLY_FILE_OPS(hwflags); |
279daf64 | 181 | DEBUGFS_READONLY_FILE_OPS(queues); |
db2e6bd4 | 182 | |
e9f207f0 JB |
183 | /* statistics stuff */ |
184 | ||
e9f207f0 JB |
185 | static ssize_t format_devstat_counter(struct ieee80211_local *local, |
186 | char __user *userbuf, | |
187 | size_t count, loff_t *ppos, | |
188 | int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf, | |
189 | int buflen)) | |
190 | { | |
191 | struct ieee80211_low_level_stats stats; | |
192 | char buf[20]; | |
193 | int res; | |
194 | ||
75636525 | 195 | rtnl_lock(); |
24487981 | 196 | res = drv_get_stats(local, &stats); |
e9f207f0 | 197 | rtnl_unlock(); |
24487981 JB |
198 | if (res) |
199 | return res; | |
200 | res = printvalue(&stats, buf, sizeof(buf)); | |
e9f207f0 JB |
201 | return simple_read_from_buffer(userbuf, count, ppos, buf, res); |
202 | } | |
203 | ||
204 | #define DEBUGFS_DEVSTATS_FILE(name) \ | |
205 | static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\ | |
206 | char *buf, int buflen) \ | |
207 | { \ | |
208 | return scnprintf(buf, buflen, "%u\n", stats->name); \ | |
209 | } \ | |
210 | static ssize_t stats_ ##name## _read(struct file *file, \ | |
211 | char __user *userbuf, \ | |
212 | size_t count, loff_t *ppos) \ | |
213 | { \ | |
214 | return format_devstat_counter(file->private_data, \ | |
215 | userbuf, \ | |
216 | count, \ | |
217 | ppos, \ | |
218 | print_devstats_##name); \ | |
219 | } \ | |
220 | \ | |
221 | static const struct file_operations stats_ ##name## _ops = { \ | |
222 | .read = stats_ ##name## _read, \ | |
234e3405 | 223 | .open = simple_open, \ |
2b18ab36 | 224 | .llseek = generic_file_llseek, \ |
e9f207f0 JB |
225 | }; |
226 | ||
2826bcd8 FF |
227 | #define DEBUGFS_STATS_ADD(name, field) \ |
228 | debugfs_create_u32(#name, 0400, statsd, (u32 *) &field); | |
229 | #define DEBUGFS_DEVSTATS_ADD(name) \ | |
7bcfaf2f | 230 | debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops); |
e9f207f0 | 231 | |
e9f207f0 JB |
232 | DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount); |
233 | DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount); | |
234 | DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount); | |
235 | DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount); | |
236 | ||
e9f207f0 JB |
237 | void debugfs_hw_add(struct ieee80211_local *local) |
238 | { | |
239 | struct dentry *phyd = local->hw.wiphy->debugfsdir; | |
240 | struct dentry *statsd; | |
241 | ||
242 | if (!phyd) | |
243 | return; | |
244 | ||
e9f207f0 JB |
245 | local->debugfs.keys = debugfs_create_dir("keys", phyd); |
246 | ||
e9f207f0 | 247 | DEBUGFS_ADD(total_ps_buffered); |
e9f207f0 | 248 | DEBUGFS_ADD(wep_iv); |
db2e6bd4 | 249 | DEBUGFS_ADD(queues); |
2ad4814f | 250 | #ifdef CONFIG_PM |
827b1fb4 | 251 | DEBUGFS_ADD_MODE(reset, 0200); |
2ad4814f | 252 | #endif |
279daf64 | 253 | DEBUGFS_ADD(hwflags); |
83bdf2a1 BG |
254 | DEBUGFS_ADD(user_power); |
255 | DEBUGFS_ADD(power); | |
e9f207f0 JB |
256 | |
257 | statsd = debugfs_create_dir("statistics", phyd); | |
e9f207f0 JB |
258 | |
259 | /* if the dir failed, don't put all the other things into the root! */ | |
260 | if (!statsd) | |
261 | return; | |
262 | ||
2826bcd8 FF |
263 | DEBUGFS_STATS_ADD(transmitted_fragment_count, |
264 | local->dot11TransmittedFragmentCount); | |
265 | DEBUGFS_STATS_ADD(multicast_transmitted_frame_count, | |
266 | local->dot11MulticastTransmittedFrameCount); | |
267 | DEBUGFS_STATS_ADD(failed_count, local->dot11FailedCount); | |
268 | DEBUGFS_STATS_ADD(retry_count, local->dot11RetryCount); | |
269 | DEBUGFS_STATS_ADD(multiple_retry_count, | |
270 | local->dot11MultipleRetryCount); | |
271 | DEBUGFS_STATS_ADD(frame_duplicate_count, | |
272 | local->dot11FrameDuplicateCount); | |
273 | DEBUGFS_STATS_ADD(received_fragment_count, | |
274 | local->dot11ReceivedFragmentCount); | |
275 | DEBUGFS_STATS_ADD(multicast_received_frame_count, | |
276 | local->dot11MulticastReceivedFrameCount); | |
277 | DEBUGFS_STATS_ADD(transmitted_frame_count, | |
278 | local->dot11TransmittedFrameCount); | |
e9f207f0 | 279 | #ifdef CONFIG_MAC80211_DEBUG_COUNTERS |
2826bcd8 FF |
280 | DEBUGFS_STATS_ADD(tx_handlers_drop, local->tx_handlers_drop); |
281 | DEBUGFS_STATS_ADD(tx_handlers_queued, local->tx_handlers_queued); | |
282 | DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted, | |
283 | local->tx_handlers_drop_unencrypted); | |
284 | DEBUGFS_STATS_ADD(tx_handlers_drop_fragment, | |
285 | local->tx_handlers_drop_fragment); | |
286 | DEBUGFS_STATS_ADD(tx_handlers_drop_wep, | |
287 | local->tx_handlers_drop_wep); | |
288 | DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc, | |
289 | local->tx_handlers_drop_not_assoc); | |
290 | DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port, | |
291 | local->tx_handlers_drop_unauth_port); | |
292 | DEBUGFS_STATS_ADD(rx_handlers_drop, local->rx_handlers_drop); | |
293 | DEBUGFS_STATS_ADD(rx_handlers_queued, local->rx_handlers_queued); | |
294 | DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc, | |
295 | local->rx_handlers_drop_nullfunc); | |
296 | DEBUGFS_STATS_ADD(rx_handlers_drop_defrag, | |
297 | local->rx_handlers_drop_defrag); | |
298 | DEBUGFS_STATS_ADD(rx_handlers_drop_short, | |
299 | local->rx_handlers_drop_short); | |
2826bcd8 FF |
300 | DEBUGFS_STATS_ADD(tx_expand_skb_head, |
301 | local->tx_expand_skb_head); | |
302 | DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned, | |
303 | local->tx_expand_skb_head_cloned); | |
304 | DEBUGFS_STATS_ADD(rx_expand_skb_head, | |
305 | local->rx_expand_skb_head); | |
306 | DEBUGFS_STATS_ADD(rx_expand_skb_head2, | |
307 | local->rx_expand_skb_head2); | |
308 | DEBUGFS_STATS_ADD(rx_handlers_fragments, | |
309 | local->rx_handlers_fragments); | |
310 | DEBUGFS_STATS_ADD(tx_status_drop, | |
311 | local->tx_status_drop); | |
e9f207f0 | 312 | #endif |
2826bcd8 FF |
313 | DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount); |
314 | DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount); | |
315 | DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount); | |
316 | DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount); | |
e9f207f0 | 317 | } |