mac80211: remove short slot/short preamble incapable flags
[firefly-linux-kernel-4.4.55.git] / net / mac80211 / debugfs.c
1 /*
2  * mac80211 debugfs for wireless PHYs
3  *
4  * Copyright 2007       Johannes Berg <johannes@sipsolutions.net>
5  * Copyright 2013-2014  Intel Mobile Communications GmbH
6  *
7  * GPLv2
8  *
9  */
10
11 #include <linux/debugfs.h>
12 #include <linux/rtnetlink.h>
13 #include "ieee80211_i.h"
14 #include "driver-ops.h"
15 #include "rate.h"
16 #include "debugfs.h"
17
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
34 #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...)                   \
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;             \
39                                                                         \
40         return mac80211_format_buffer(userbuf, count, ppos,             \
41                                       fmt "\n", ##value);               \
42 }
43
44 #define DEBUGFS_READONLY_FILE_OPS(name)                 \
45 static const struct file_operations name## _ops = {                     \
46         .read = name## _read,                                           \
47         .open = simple_open,                                            \
48         .llseek = generic_file_llseek,                                  \
49 };
50
51 #define DEBUGFS_READONLY_FILE(name, fmt, value...)              \
52         DEBUGFS_READONLY_FILE_FN(name, fmt, value)              \
53         DEBUGFS_READONLY_FILE_OPS(name)
54
55 #define DEBUGFS_ADD(name)                                               \
56         debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
57
58 #define DEBUGFS_ADD_MODE(name, mode)                                    \
59         debugfs_create_file(#name, mode, phyd, local, &name## _ops);
60
61
62 DEBUGFS_READONLY_FILE(user_power, "%d",
63                       local->user_power_level);
64 DEBUGFS_READONLY_FILE(power, "%d",
65                       local->hw.conf.power_level);
66 DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
67                       local->total_ps_buffered);
68 DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
69                       local->wep_iv & 0xffffff);
70 DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
71         local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
72
73 #ifdef CONFIG_PM
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();
80         __ieee80211_suspend(&local->hw, NULL);
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,
89         .open = simple_open,
90         .llseek = noop_llseek,
91 };
92 #endif
93
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
103         if (!buf)
104                 return 0;
105
106         sf += scnprintf(buf, mxln - sf, "0x%x\n", local->hw.flags);
107         if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
108                 sf += scnprintf(buf + sf, mxln - sf, "HAS_RATE_CONTROL\n");
109         if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
110                 sf += scnprintf(buf + sf, mxln - sf, "RX_INCLUDES_FCS\n");
111         if (local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING)
112                 sf += scnprintf(buf + sf, mxln - sf,
113                                 "HOST_BCAST_PS_BUFFERING\n");
114         if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
115                 sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_UNSPEC\n");
116         if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
117                 sf += scnprintf(buf + sf, mxln - sf, "SIGNAL_DBM\n");
118         if (local->hw.flags & IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC)
119                 sf += scnprintf(buf + sf, mxln - sf,
120                                 "NEED_DTIM_BEFORE_ASSOC\n");
121         if (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)
122                 sf += scnprintf(buf + sf, mxln - sf, "SPECTRUM_MGMT\n");
123         if (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)
124                 sf += scnprintf(buf + sf, mxln - sf, "AMPDU_AGGREGATION\n");
125         if (local->hw.flags & IEEE80211_HW_SUPPORTS_PS)
126                 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PS\n");
127         if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
128                 sf += scnprintf(buf + sf, mxln - sf, "PS_NULLFUNC_STACK\n");
129         if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
130                 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_DYNAMIC_PS\n");
131         if (local->hw.flags & IEEE80211_HW_MFP_CAPABLE)
132                 sf += scnprintf(buf + sf, mxln - sf, "MFP_CAPABLE\n");
133         if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
134                 sf += scnprintf(buf + sf, mxln - sf,
135                                 "REPORTS_TX_ACK_STATUS\n");
136         if (local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
137                 sf += scnprintf(buf + sf, mxln - sf, "CONNECTION_MONITOR\n");
138         if (local->hw.flags & IEEE80211_HW_SUPPORTS_PER_STA_GTK)
139                 sf += scnprintf(buf + sf, mxln - sf, "SUPPORTS_PER_STA_GTK\n");
140         if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
141                 sf += scnprintf(buf + sf, mxln - sf, "AP_LINK_PS\n");
142         if (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)
143                 sf += scnprintf(buf + sf, mxln - sf, "TX_AMPDU_SETUP_IN_HW\n");
144
145         rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
146         kfree(buf);
147         return rv;
148 }
149
150 static ssize_t queues_read(struct file *file, char __user *user_buf,
151                            size_t count, loff_t *ppos)
152 {
153         struct ieee80211_local *local = file->private_data;
154         unsigned long flags;
155         char buf[IEEE80211_MAX_QUEUES * 20];
156         int q, res = 0;
157
158         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
159         for (q = 0; q < local->hw.queues; q++)
160                 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
161                                 local->queue_stop_reasons[q],
162                                 skb_queue_len(&local->pending[q]));
163         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
164
165         return simple_read_from_buffer(user_buf, count, ppos, buf, res);
166 }
167
168 DEBUGFS_READONLY_FILE_OPS(hwflags);
169 DEBUGFS_READONLY_FILE_OPS(queues);
170
171 /* statistics stuff */
172
173 static ssize_t format_devstat_counter(struct ieee80211_local *local,
174         char __user *userbuf,
175         size_t count, loff_t *ppos,
176         int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
177                           int buflen))
178 {
179         struct ieee80211_low_level_stats stats;
180         char buf[20];
181         int res;
182
183         rtnl_lock();
184         res = drv_get_stats(local, &stats);
185         rtnl_unlock();
186         if (res)
187                 return res;
188         res = printvalue(&stats, buf, sizeof(buf));
189         return simple_read_from_buffer(userbuf, count, ppos, buf, res);
190 }
191
192 #define DEBUGFS_DEVSTATS_FILE(name)                                     \
193 static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
194                                  char *buf, int buflen)                 \
195 {                                                                       \
196         return scnprintf(buf, buflen, "%u\n", stats->name);             \
197 }                                                                       \
198 static ssize_t stats_ ##name## _read(struct file *file,                 \
199                                      char __user *userbuf,              \
200                                      size_t count, loff_t *ppos)        \
201 {                                                                       \
202         return format_devstat_counter(file->private_data,               \
203                                       userbuf,                          \
204                                       count,                            \
205                                       ppos,                             \
206                                       print_devstats_##name);           \
207 }                                                                       \
208                                                                         \
209 static const struct file_operations stats_ ##name## _ops = {            \
210         .read = stats_ ##name## _read,                                  \
211         .open = simple_open,                                            \
212         .llseek = generic_file_llseek,                                  \
213 };
214
215 #define DEBUGFS_STATS_ADD(name)                                 \
216         debugfs_create_u32(#name, 0400, statsd, &local->name);
217 #define DEBUGFS_DEVSTATS_ADD(name)                                      \
218         debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
219
220 DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
221 DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
222 DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
223 DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
224
225 void debugfs_hw_add(struct ieee80211_local *local)
226 {
227         struct dentry *phyd = local->hw.wiphy->debugfsdir;
228         struct dentry *statsd;
229
230         if (!phyd)
231                 return;
232
233         local->debugfs.keys = debugfs_create_dir("keys", phyd);
234
235         DEBUGFS_ADD(total_ps_buffered);
236         DEBUGFS_ADD(wep_iv);
237         DEBUGFS_ADD(queues);
238 #ifdef CONFIG_PM
239         DEBUGFS_ADD_MODE(reset, 0200);
240 #endif
241         DEBUGFS_ADD(hwflags);
242         DEBUGFS_ADD(user_power);
243         DEBUGFS_ADD(power);
244
245         statsd = debugfs_create_dir("statistics", phyd);
246
247         /* if the dir failed, don't put all the other things into the root! */
248         if (!statsd)
249                 return;
250
251 #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
252         DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
253         DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
254         DEBUGFS_STATS_ADD(dot11FailedCount);
255         DEBUGFS_STATS_ADD(dot11RetryCount);
256         DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
257         DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
258         DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
259         DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
260         DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
261         DEBUGFS_STATS_ADD(tx_handlers_drop);
262         DEBUGFS_STATS_ADD(tx_handlers_queued);
263         DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
264         DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
265         DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
266         DEBUGFS_STATS_ADD(rx_handlers_drop);
267         DEBUGFS_STATS_ADD(rx_handlers_queued);
268         DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
269         DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
270         DEBUGFS_STATS_ADD(rx_handlers_drop_short);
271         DEBUGFS_STATS_ADD(tx_expand_skb_head);
272         DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
273         DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
274         DEBUGFS_STATS_ADD(rx_handlers_fragments);
275         DEBUGFS_STATS_ADD(tx_status_drop);
276 #endif
277         DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
278         DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
279         DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
280         DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
281 }