kernel: printk: specify alignment for struct printk_log
[deliverable/linux.git] / net / mac80211 / debugfs.c
CommitLineData
e9f207f0
JB
1/*
2 * mac80211 debugfs for wireless PHYs
3 *
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
d98ad83e 5 * Copyright 2013-2014 Intel Mobile Communications GmbH
e9f207f0
JB
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
20int 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
35static 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
45static 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
62DEBUGFS_READONLY_FILE(user_power, "%d",
63 local->user_power_level);
64DEBUGFS_READONLY_FILE(power, "%d",
65 local->hw.conf.power_level);
07caf9d6 66DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
e9f207f0 67 local->total_ps_buffered);
07caf9d6 68DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
e9f207f0 69 local->wep_iv & 0xffffff);
07caf9d6 70DEBUGFS_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
74static 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
87static 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
30686bf7
JB
94static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = {
95#define FLAG(F) [IEEE80211_HW_##F] = #F
96 FLAG(HAS_RATE_CONTROL),
97 FLAG(RX_INCLUDES_FCS),
98 FLAG(HOST_BROADCAST_PS_BUFFERING),
99 FLAG(SIGNAL_UNSPEC),
100 FLAG(SIGNAL_DBM),
101 FLAG(NEED_DTIM_BEFORE_ASSOC),
102 FLAG(SPECTRUM_MGMT),
103 FLAG(AMPDU_AGGREGATION),
104 FLAG(SUPPORTS_PS),
105 FLAG(PS_NULLFUNC_STACK),
106 FLAG(SUPPORTS_DYNAMIC_PS),
107 FLAG(MFP_CAPABLE),
108 FLAG(WANT_MONITOR_VIF),
109 FLAG(NO_AUTO_VIF),
110 FLAG(SW_CRYPTO_CONTROL),
111 FLAG(SUPPORT_FAST_XMIT),
112 FLAG(REPORTS_TX_ACK_STATUS),
113 FLAG(CONNECTION_MONITOR),
114 FLAG(QUEUE_CONTROL),
115 FLAG(SUPPORTS_PER_STA_GTK),
116 FLAG(AP_LINK_PS),
117 FLAG(TX_AMPDU_SETUP_IN_HW),
118 FLAG(SUPPORTS_RC_TABLE),
119 FLAG(P2P_DEV_ADDR_FOR_INTF),
120 FLAG(TIMING_BEACON_ONLY),
121 FLAG(SUPPORTS_HT_CCK_RATES),
122 FLAG(CHANCTX_STA_CSA),
123 FLAG(SUPPORTS_CLONED_SKBS),
124 FLAG(SINGLE_SCAN_ON_ALL_BANDS),
b98fb44f 125 FLAG(TDLS_WIDER_BW),
99e7ca44 126 FLAG(SUPPORTS_AMSDU_IN_AMPDU),
35afa588 127 FLAG(BEACON_TX_STATUS),
31104891 128 FLAG(NEEDS_UNIQUE_STA_ADDR),
30686bf7
JB
129
130 /* keep last for the build bug below */
131 (void *)0x1
132#undef FLAG
133};
134
279daf64
BG
135static ssize_t hwflags_read(struct file *file, char __user *user_buf,
136 size_t count, loff_t *ppos)
137{
138 struct ieee80211_local *local = file->private_data;
30686bf7
JB
139 size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS;
140 char *buf = kzalloc(bufsz, GFP_KERNEL);
141 char *pos = buf, *end = buf + bufsz - 1;
279daf64 142 ssize_t rv;
30686bf7 143 int i;
279daf64 144
d15b8459 145 if (!buf)
30686bf7
JB
146 return -ENOMEM;
147
148 /* fail compilation if somebody adds or removes
149 * a flag without updating the name array above
150 */
151 BUILD_BUG_ON(hw_flag_names[NUM_IEEE80211_HW_FLAGS] != (void *)0x1);
152
153 for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
154 if (test_bit(i, local->hw.flags))
4633dfc3 155 pos += scnprintf(pos, end - pos, "%s\n",
30686bf7
JB
156 hw_flag_names[i]);
157 }
279daf64
BG
158
159 rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
160 kfree(buf);
161 return rv;
162}
199d69f2 163
db2e6bd4
JB
164static ssize_t queues_read(struct file *file, char __user *user_buf,
165 size_t count, loff_t *ppos)
166{
167 struct ieee80211_local *local = file->private_data;
168 unsigned long flags;
169 char buf[IEEE80211_MAX_QUEUES * 20];
170 int q, res = 0;
171
172 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
173 for (q = 0; q < local->hw.queues; q++)
174 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
175 local->queue_stop_reasons[q],
3b8d81e0 176 skb_queue_len(&local->pending[q]));
db2e6bd4
JB
177 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
178
179 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
180}
181
279daf64 182DEBUGFS_READONLY_FILE_OPS(hwflags);
279daf64 183DEBUGFS_READONLY_FILE_OPS(queues);
db2e6bd4 184
e9f207f0
JB
185/* statistics stuff */
186
e9f207f0
JB
187static ssize_t format_devstat_counter(struct ieee80211_local *local,
188 char __user *userbuf,
189 size_t count, loff_t *ppos,
190 int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
191 int buflen))
192{
193 struct ieee80211_low_level_stats stats;
194 char buf[20];
195 int res;
196
75636525 197 rtnl_lock();
24487981 198 res = drv_get_stats(local, &stats);
e9f207f0 199 rtnl_unlock();
24487981
JB
200 if (res)
201 return res;
202 res = printvalue(&stats, buf, sizeof(buf));
e9f207f0
JB
203 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
204}
205
206#define DEBUGFS_DEVSTATS_FILE(name) \
207static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
208 char *buf, int buflen) \
209{ \
210 return scnprintf(buf, buflen, "%u\n", stats->name); \
211} \
212static ssize_t stats_ ##name## _read(struct file *file, \
213 char __user *userbuf, \
214 size_t count, loff_t *ppos) \
215{ \
216 return format_devstat_counter(file->private_data, \
217 userbuf, \
218 count, \
219 ppos, \
220 print_devstats_##name); \
221} \
222 \
223static const struct file_operations stats_ ##name## _ops = { \
224 .read = stats_ ##name## _read, \
234e3405 225 .open = simple_open, \
2b18ab36 226 .llseek = generic_file_llseek, \
e9f207f0
JB
227};
228
f1160434
JB
229#define DEBUGFS_STATS_ADD(name) \
230 debugfs_create_u32(#name, 0400, statsd, &local->name);
2826bcd8 231#define DEBUGFS_DEVSTATS_ADD(name) \
7bcfaf2f 232 debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
e9f207f0 233
e9f207f0
JB
234DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
235DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
236DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
237DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
238
e9f207f0
JB
239void debugfs_hw_add(struct ieee80211_local *local)
240{
241 struct dentry *phyd = local->hw.wiphy->debugfsdir;
242 struct dentry *statsd;
243
244 if (!phyd)
245 return;
246
e9f207f0
JB
247 local->debugfs.keys = debugfs_create_dir("keys", phyd);
248
e9f207f0 249 DEBUGFS_ADD(total_ps_buffered);
e9f207f0 250 DEBUGFS_ADD(wep_iv);
db2e6bd4 251 DEBUGFS_ADD(queues);
2ad4814f 252#ifdef CONFIG_PM
827b1fb4 253 DEBUGFS_ADD_MODE(reset, 0200);
2ad4814f 254#endif
279daf64 255 DEBUGFS_ADD(hwflags);
83bdf2a1
BG
256 DEBUGFS_ADD(user_power);
257 DEBUGFS_ADD(power);
e9f207f0
JB
258
259 statsd = debugfs_create_dir("statistics", phyd);
e9f207f0
JB
260
261 /* if the dir failed, don't put all the other things into the root! */
262 if (!statsd)
263 return;
264
c206ca67 265#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
f1160434
JB
266 DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
267 DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
268 DEBUGFS_STATS_ADD(dot11FailedCount);
269 DEBUGFS_STATS_ADD(dot11RetryCount);
270 DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
271 DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
272 DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
273 DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
274 DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
f1160434
JB
275 DEBUGFS_STATS_ADD(tx_handlers_drop);
276 DEBUGFS_STATS_ADD(tx_handlers_queued);
277 DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
278 DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
279 DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
280 DEBUGFS_STATS_ADD(rx_handlers_drop);
281 DEBUGFS_STATS_ADD(rx_handlers_queued);
282 DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
283 DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
f1160434
JB
284 DEBUGFS_STATS_ADD(tx_expand_skb_head);
285 DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
286 DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
287 DEBUGFS_STATS_ADD(rx_handlers_fragments);
288 DEBUGFS_STATS_ADD(tx_status_drop);
e9f207f0 289#endif
2826bcd8
FF
290 DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
291 DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
292 DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
293 DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
e9f207f0 294}
This page took 0.576047 seconds and 5 git commands to generate.