1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * mac80211 debugfs for wireless PHYs
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
6*4882a593Smuzhiyun * Copyright 2013-2014 Intel Mobile Communications GmbH
7*4882a593Smuzhiyun * Copyright (C) 2018 - 2019 Intel Corporation
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include <linux/debugfs.h>
11*4882a593Smuzhiyun #include <linux/rtnetlink.h>
12*4882a593Smuzhiyun #include <linux/vmalloc.h>
13*4882a593Smuzhiyun #include "ieee80211_i.h"
14*4882a593Smuzhiyun #include "driver-ops.h"
15*4882a593Smuzhiyun #include "rate.h"
16*4882a593Smuzhiyun #include "debugfs.h"
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #define DEBUGFS_FORMAT_BUFFER_SIZE 100
19*4882a593Smuzhiyun
mac80211_format_buffer(char __user * userbuf,size_t count,loff_t * ppos,char * fmt,...)20*4882a593Smuzhiyun int mac80211_format_buffer(char __user *userbuf, size_t count,
21*4882a593Smuzhiyun loff_t *ppos, char *fmt, ...)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun va_list args;
24*4882a593Smuzhiyun char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
25*4882a593Smuzhiyun int res;
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun va_start(args, fmt);
28*4882a593Smuzhiyun res = vscnprintf(buf, sizeof(buf), fmt, args);
29*4882a593Smuzhiyun va_end(args);
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun return simple_read_from_buffer(userbuf, count, ppos, buf, res);
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #define DEBUGFS_READONLY_FILE_FN(name, fmt, value...) \
35*4882a593Smuzhiyun static ssize_t name## _read(struct file *file, char __user *userbuf, \
36*4882a593Smuzhiyun size_t count, loff_t *ppos) \
37*4882a593Smuzhiyun { \
38*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data; \
39*4882a593Smuzhiyun \
40*4882a593Smuzhiyun return mac80211_format_buffer(userbuf, count, ppos, \
41*4882a593Smuzhiyun fmt "\n", ##value); \
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun #define DEBUGFS_READONLY_FILE_OPS(name) \
45*4882a593Smuzhiyun static const struct file_operations name## _ops = { \
46*4882a593Smuzhiyun .read = name## _read, \
47*4882a593Smuzhiyun .open = simple_open, \
48*4882a593Smuzhiyun .llseek = generic_file_llseek, \
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun #define DEBUGFS_READONLY_FILE(name, fmt, value...) \
52*4882a593Smuzhiyun DEBUGFS_READONLY_FILE_FN(name, fmt, value) \
53*4882a593Smuzhiyun DEBUGFS_READONLY_FILE_OPS(name)
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun #define DEBUGFS_ADD(name) \
56*4882a593Smuzhiyun debugfs_create_file(#name, 0400, phyd, local, &name## _ops);
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun #define DEBUGFS_ADD_MODE(name, mode) \
59*4882a593Smuzhiyun debugfs_create_file(#name, mode, phyd, local, &name## _ops);
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(hw_conf, "%x",
63*4882a593Smuzhiyun local->hw.conf.flags);
64*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(user_power, "%d",
65*4882a593Smuzhiyun local->user_power_level);
66*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(power, "%d",
67*4882a593Smuzhiyun local->hw.conf.power_level);
68*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(total_ps_buffered, "%d",
69*4882a593Smuzhiyun local->total_ps_buffered);
70*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(wep_iv, "%#08x",
71*4882a593Smuzhiyun local->wep_iv & 0xffffff);
72*4882a593Smuzhiyun DEBUGFS_READONLY_FILE(rate_ctrl_alg, "%s",
73*4882a593Smuzhiyun local->rate_ctrl ? local->rate_ctrl->ops->name : "hw/driver");
74*4882a593Smuzhiyun
aqm_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)75*4882a593Smuzhiyun static ssize_t aqm_read(struct file *file,
76*4882a593Smuzhiyun char __user *user_buf,
77*4882a593Smuzhiyun size_t count,
78*4882a593Smuzhiyun loff_t *ppos)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
81*4882a593Smuzhiyun struct fq *fq = &local->fq;
82*4882a593Smuzhiyun char buf[200];
83*4882a593Smuzhiyun int len = 0;
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun spin_lock_bh(&local->fq.lock);
86*4882a593Smuzhiyun rcu_read_lock();
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun len = scnprintf(buf, sizeof(buf),
89*4882a593Smuzhiyun "access name value\n"
90*4882a593Smuzhiyun "R fq_flows_cnt %u\n"
91*4882a593Smuzhiyun "R fq_backlog %u\n"
92*4882a593Smuzhiyun "R fq_overlimit %u\n"
93*4882a593Smuzhiyun "R fq_overmemory %u\n"
94*4882a593Smuzhiyun "R fq_collisions %u\n"
95*4882a593Smuzhiyun "R fq_memory_usage %u\n"
96*4882a593Smuzhiyun "RW fq_memory_limit %u\n"
97*4882a593Smuzhiyun "RW fq_limit %u\n"
98*4882a593Smuzhiyun "RW fq_quantum %u\n",
99*4882a593Smuzhiyun fq->flows_cnt,
100*4882a593Smuzhiyun fq->backlog,
101*4882a593Smuzhiyun fq->overmemory,
102*4882a593Smuzhiyun fq->overlimit,
103*4882a593Smuzhiyun fq->collisions,
104*4882a593Smuzhiyun fq->memory_usage,
105*4882a593Smuzhiyun fq->memory_limit,
106*4882a593Smuzhiyun fq->limit,
107*4882a593Smuzhiyun fq->quantum);
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun rcu_read_unlock();
110*4882a593Smuzhiyun spin_unlock_bh(&local->fq.lock);
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos,
113*4882a593Smuzhiyun buf, len);
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun
aqm_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)116*4882a593Smuzhiyun static ssize_t aqm_write(struct file *file,
117*4882a593Smuzhiyun const char __user *user_buf,
118*4882a593Smuzhiyun size_t count,
119*4882a593Smuzhiyun loff_t *ppos)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
122*4882a593Smuzhiyun char buf[100];
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun if (count >= sizeof(buf))
125*4882a593Smuzhiyun return -EINVAL;
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun if (copy_from_user(buf, user_buf, count))
128*4882a593Smuzhiyun return -EFAULT;
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun if (count && buf[count - 1] == '\n')
131*4882a593Smuzhiyun buf[count - 1] = '\0';
132*4882a593Smuzhiyun else
133*4882a593Smuzhiyun buf[count] = '\0';
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun if (sscanf(buf, "fq_limit %u", &local->fq.limit) == 1)
136*4882a593Smuzhiyun return count;
137*4882a593Smuzhiyun else if (sscanf(buf, "fq_memory_limit %u", &local->fq.memory_limit) == 1)
138*4882a593Smuzhiyun return count;
139*4882a593Smuzhiyun else if (sscanf(buf, "fq_quantum %u", &local->fq.quantum) == 1)
140*4882a593Smuzhiyun return count;
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun return -EINVAL;
143*4882a593Smuzhiyun }
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun static const struct file_operations aqm_ops = {
146*4882a593Smuzhiyun .write = aqm_write,
147*4882a593Smuzhiyun .read = aqm_read,
148*4882a593Smuzhiyun .open = simple_open,
149*4882a593Smuzhiyun .llseek = default_llseek,
150*4882a593Smuzhiyun };
151*4882a593Smuzhiyun
airtime_flags_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)152*4882a593Smuzhiyun static ssize_t airtime_flags_read(struct file *file,
153*4882a593Smuzhiyun char __user *user_buf,
154*4882a593Smuzhiyun size_t count, loff_t *ppos)
155*4882a593Smuzhiyun {
156*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
157*4882a593Smuzhiyun char buf[128] = {}, *pos, *end;
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun pos = buf;
160*4882a593Smuzhiyun end = pos + sizeof(buf) - 1;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun if (local->airtime_flags & AIRTIME_USE_TX)
163*4882a593Smuzhiyun pos += scnprintf(pos, end - pos, "AIRTIME_TX\t(%lx)\n",
164*4882a593Smuzhiyun AIRTIME_USE_TX);
165*4882a593Smuzhiyun if (local->airtime_flags & AIRTIME_USE_RX)
166*4882a593Smuzhiyun pos += scnprintf(pos, end - pos, "AIRTIME_RX\t(%lx)\n",
167*4882a593Smuzhiyun AIRTIME_USE_RX);
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf,
170*4882a593Smuzhiyun strlen(buf));
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun
airtime_flags_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)173*4882a593Smuzhiyun static ssize_t airtime_flags_write(struct file *file,
174*4882a593Smuzhiyun const char __user *user_buf,
175*4882a593Smuzhiyun size_t count, loff_t *ppos)
176*4882a593Smuzhiyun {
177*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
178*4882a593Smuzhiyun char buf[16];
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun if (count >= sizeof(buf))
181*4882a593Smuzhiyun return -EINVAL;
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun if (copy_from_user(buf, user_buf, count))
184*4882a593Smuzhiyun return -EFAULT;
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun if (count && buf[count - 1] == '\n')
187*4882a593Smuzhiyun buf[count - 1] = '\0';
188*4882a593Smuzhiyun else
189*4882a593Smuzhiyun buf[count] = '\0';
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun if (kstrtou16(buf, 0, &local->airtime_flags))
192*4882a593Smuzhiyun return -EINVAL;
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun return count;
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun static const struct file_operations airtime_flags_ops = {
198*4882a593Smuzhiyun .write = airtime_flags_write,
199*4882a593Smuzhiyun .read = airtime_flags_read,
200*4882a593Smuzhiyun .open = simple_open,
201*4882a593Smuzhiyun .llseek = default_llseek,
202*4882a593Smuzhiyun };
203*4882a593Smuzhiyun
aql_txq_limit_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)204*4882a593Smuzhiyun static ssize_t aql_txq_limit_read(struct file *file,
205*4882a593Smuzhiyun char __user *user_buf,
206*4882a593Smuzhiyun size_t count,
207*4882a593Smuzhiyun loff_t *ppos)
208*4882a593Smuzhiyun {
209*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
210*4882a593Smuzhiyun char buf[400];
211*4882a593Smuzhiyun int len = 0;
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun len = scnprintf(buf, sizeof(buf),
214*4882a593Smuzhiyun "AC AQL limit low AQL limit high\n"
215*4882a593Smuzhiyun "VO %u %u\n"
216*4882a593Smuzhiyun "VI %u %u\n"
217*4882a593Smuzhiyun "BE %u %u\n"
218*4882a593Smuzhiyun "BK %u %u\n",
219*4882a593Smuzhiyun local->aql_txq_limit_low[IEEE80211_AC_VO],
220*4882a593Smuzhiyun local->aql_txq_limit_high[IEEE80211_AC_VO],
221*4882a593Smuzhiyun local->aql_txq_limit_low[IEEE80211_AC_VI],
222*4882a593Smuzhiyun local->aql_txq_limit_high[IEEE80211_AC_VI],
223*4882a593Smuzhiyun local->aql_txq_limit_low[IEEE80211_AC_BE],
224*4882a593Smuzhiyun local->aql_txq_limit_high[IEEE80211_AC_BE],
225*4882a593Smuzhiyun local->aql_txq_limit_low[IEEE80211_AC_BK],
226*4882a593Smuzhiyun local->aql_txq_limit_high[IEEE80211_AC_BK]);
227*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos,
228*4882a593Smuzhiyun buf, len);
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun
aql_txq_limit_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)231*4882a593Smuzhiyun static ssize_t aql_txq_limit_write(struct file *file,
232*4882a593Smuzhiyun const char __user *user_buf,
233*4882a593Smuzhiyun size_t count,
234*4882a593Smuzhiyun loff_t *ppos)
235*4882a593Smuzhiyun {
236*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
237*4882a593Smuzhiyun char buf[100];
238*4882a593Smuzhiyun u32 ac, q_limit_low, q_limit_high, q_limit_low_old, q_limit_high_old;
239*4882a593Smuzhiyun struct sta_info *sta;
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun if (count >= sizeof(buf))
242*4882a593Smuzhiyun return -EINVAL;
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun if (copy_from_user(buf, user_buf, count))
245*4882a593Smuzhiyun return -EFAULT;
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun if (count && buf[count - 1] == '\n')
248*4882a593Smuzhiyun buf[count - 1] = '\0';
249*4882a593Smuzhiyun else
250*4882a593Smuzhiyun buf[count] = '\0';
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun if (sscanf(buf, "%u %u %u", &ac, &q_limit_low, &q_limit_high) != 3)
253*4882a593Smuzhiyun return -EINVAL;
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun if (ac >= IEEE80211_NUM_ACS)
256*4882a593Smuzhiyun return -EINVAL;
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun q_limit_low_old = local->aql_txq_limit_low[ac];
259*4882a593Smuzhiyun q_limit_high_old = local->aql_txq_limit_high[ac];
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun local->aql_txq_limit_low[ac] = q_limit_low;
262*4882a593Smuzhiyun local->aql_txq_limit_high[ac] = q_limit_high;
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun mutex_lock(&local->sta_mtx);
265*4882a593Smuzhiyun list_for_each_entry(sta, &local->sta_list, list) {
266*4882a593Smuzhiyun /* If a sta has customized queue limits, keep it */
267*4882a593Smuzhiyun if (sta->airtime[ac].aql_limit_low == q_limit_low_old &&
268*4882a593Smuzhiyun sta->airtime[ac].aql_limit_high == q_limit_high_old) {
269*4882a593Smuzhiyun sta->airtime[ac].aql_limit_low = q_limit_low;
270*4882a593Smuzhiyun sta->airtime[ac].aql_limit_high = q_limit_high;
271*4882a593Smuzhiyun }
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun mutex_unlock(&local->sta_mtx);
274*4882a593Smuzhiyun return count;
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun static const struct file_operations aql_txq_limit_ops = {
278*4882a593Smuzhiyun .write = aql_txq_limit_write,
279*4882a593Smuzhiyun .read = aql_txq_limit_read,
280*4882a593Smuzhiyun .open = simple_open,
281*4882a593Smuzhiyun .llseek = default_llseek,
282*4882a593Smuzhiyun };
283*4882a593Smuzhiyun
force_tx_status_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)284*4882a593Smuzhiyun static ssize_t force_tx_status_read(struct file *file,
285*4882a593Smuzhiyun char __user *user_buf,
286*4882a593Smuzhiyun size_t count,
287*4882a593Smuzhiyun loff_t *ppos)
288*4882a593Smuzhiyun {
289*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
290*4882a593Smuzhiyun char buf[3];
291*4882a593Smuzhiyun int len = 0;
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun len = scnprintf(buf, sizeof(buf), "%d\n", (int)local->force_tx_status);
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos,
296*4882a593Smuzhiyun buf, len);
297*4882a593Smuzhiyun }
298*4882a593Smuzhiyun
force_tx_status_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)299*4882a593Smuzhiyun static ssize_t force_tx_status_write(struct file *file,
300*4882a593Smuzhiyun const char __user *user_buf,
301*4882a593Smuzhiyun size_t count,
302*4882a593Smuzhiyun loff_t *ppos)
303*4882a593Smuzhiyun {
304*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
305*4882a593Smuzhiyun char buf[3];
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun if (count >= sizeof(buf))
308*4882a593Smuzhiyun return -EINVAL;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun if (copy_from_user(buf, user_buf, count))
311*4882a593Smuzhiyun return -EFAULT;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun if (count && buf[count - 1] == '\n')
314*4882a593Smuzhiyun buf[count - 1] = '\0';
315*4882a593Smuzhiyun else
316*4882a593Smuzhiyun buf[count] = '\0';
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun if (buf[0] == '0' && buf[1] == '\0')
319*4882a593Smuzhiyun local->force_tx_status = 0;
320*4882a593Smuzhiyun else if (buf[0] == '1' && buf[1] == '\0')
321*4882a593Smuzhiyun local->force_tx_status = 1;
322*4882a593Smuzhiyun else
323*4882a593Smuzhiyun return -EINVAL;
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun return count;
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun static const struct file_operations force_tx_status_ops = {
329*4882a593Smuzhiyun .write = force_tx_status_write,
330*4882a593Smuzhiyun .read = force_tx_status_read,
331*4882a593Smuzhiyun .open = simple_open,
332*4882a593Smuzhiyun .llseek = default_llseek,
333*4882a593Smuzhiyun };
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun #ifdef CONFIG_PM
reset_write(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)336*4882a593Smuzhiyun static ssize_t reset_write(struct file *file, const char __user *user_buf,
337*4882a593Smuzhiyun size_t count, loff_t *ppos)
338*4882a593Smuzhiyun {
339*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun rtnl_lock();
342*4882a593Smuzhiyun __ieee80211_suspend(&local->hw, NULL);
343*4882a593Smuzhiyun __ieee80211_resume(&local->hw);
344*4882a593Smuzhiyun rtnl_unlock();
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun return count;
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun static const struct file_operations reset_ops = {
350*4882a593Smuzhiyun .write = reset_write,
351*4882a593Smuzhiyun .open = simple_open,
352*4882a593Smuzhiyun .llseek = noop_llseek,
353*4882a593Smuzhiyun };
354*4882a593Smuzhiyun #endif
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun static const char *hw_flag_names[] = {
357*4882a593Smuzhiyun #define FLAG(F) [IEEE80211_HW_##F] = #F
358*4882a593Smuzhiyun FLAG(HAS_RATE_CONTROL),
359*4882a593Smuzhiyun FLAG(RX_INCLUDES_FCS),
360*4882a593Smuzhiyun FLAG(HOST_BROADCAST_PS_BUFFERING),
361*4882a593Smuzhiyun FLAG(SIGNAL_UNSPEC),
362*4882a593Smuzhiyun FLAG(SIGNAL_DBM),
363*4882a593Smuzhiyun FLAG(NEED_DTIM_BEFORE_ASSOC),
364*4882a593Smuzhiyun FLAG(SPECTRUM_MGMT),
365*4882a593Smuzhiyun FLAG(AMPDU_AGGREGATION),
366*4882a593Smuzhiyun FLAG(SUPPORTS_PS),
367*4882a593Smuzhiyun FLAG(PS_NULLFUNC_STACK),
368*4882a593Smuzhiyun FLAG(SUPPORTS_DYNAMIC_PS),
369*4882a593Smuzhiyun FLAG(MFP_CAPABLE),
370*4882a593Smuzhiyun FLAG(WANT_MONITOR_VIF),
371*4882a593Smuzhiyun FLAG(NO_AUTO_VIF),
372*4882a593Smuzhiyun FLAG(SW_CRYPTO_CONTROL),
373*4882a593Smuzhiyun FLAG(SUPPORT_FAST_XMIT),
374*4882a593Smuzhiyun FLAG(REPORTS_TX_ACK_STATUS),
375*4882a593Smuzhiyun FLAG(CONNECTION_MONITOR),
376*4882a593Smuzhiyun FLAG(QUEUE_CONTROL),
377*4882a593Smuzhiyun FLAG(SUPPORTS_PER_STA_GTK),
378*4882a593Smuzhiyun FLAG(AP_LINK_PS),
379*4882a593Smuzhiyun FLAG(TX_AMPDU_SETUP_IN_HW),
380*4882a593Smuzhiyun FLAG(SUPPORTS_RC_TABLE),
381*4882a593Smuzhiyun FLAG(P2P_DEV_ADDR_FOR_INTF),
382*4882a593Smuzhiyun FLAG(TIMING_BEACON_ONLY),
383*4882a593Smuzhiyun FLAG(SUPPORTS_HT_CCK_RATES),
384*4882a593Smuzhiyun FLAG(CHANCTX_STA_CSA),
385*4882a593Smuzhiyun FLAG(SUPPORTS_CLONED_SKBS),
386*4882a593Smuzhiyun FLAG(SINGLE_SCAN_ON_ALL_BANDS),
387*4882a593Smuzhiyun FLAG(TDLS_WIDER_BW),
388*4882a593Smuzhiyun FLAG(SUPPORTS_AMSDU_IN_AMPDU),
389*4882a593Smuzhiyun FLAG(BEACON_TX_STATUS),
390*4882a593Smuzhiyun FLAG(NEEDS_UNIQUE_STA_ADDR),
391*4882a593Smuzhiyun FLAG(SUPPORTS_REORDERING_BUFFER),
392*4882a593Smuzhiyun FLAG(USES_RSS),
393*4882a593Smuzhiyun FLAG(TX_AMSDU),
394*4882a593Smuzhiyun FLAG(TX_FRAG_LIST),
395*4882a593Smuzhiyun FLAG(REPORTS_LOW_ACK),
396*4882a593Smuzhiyun FLAG(SUPPORTS_TX_FRAG),
397*4882a593Smuzhiyun FLAG(SUPPORTS_TDLS_BUFFER_STA),
398*4882a593Smuzhiyun FLAG(DEAUTH_NEED_MGD_TX_PREP),
399*4882a593Smuzhiyun FLAG(DOESNT_SUPPORT_QOS_NDP),
400*4882a593Smuzhiyun FLAG(BUFF_MMPDU_TXQ),
401*4882a593Smuzhiyun FLAG(SUPPORTS_VHT_EXT_NSS_BW),
402*4882a593Smuzhiyun FLAG(STA_MMPDU_TXQ),
403*4882a593Smuzhiyun FLAG(TX_STATUS_NO_AMPDU_LEN),
404*4882a593Smuzhiyun FLAG(SUPPORTS_MULTI_BSSID),
405*4882a593Smuzhiyun FLAG(SUPPORTS_ONLY_HE_MULTI_BSSID),
406*4882a593Smuzhiyun FLAG(AMPDU_KEYBORDER_SUPPORT),
407*4882a593Smuzhiyun FLAG(SUPPORTS_TX_ENCAP_OFFLOAD),
408*4882a593Smuzhiyun #undef FLAG
409*4882a593Smuzhiyun };
410*4882a593Smuzhiyun
hwflags_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)411*4882a593Smuzhiyun static ssize_t hwflags_read(struct file *file, char __user *user_buf,
412*4882a593Smuzhiyun size_t count, loff_t *ppos)
413*4882a593Smuzhiyun {
414*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
415*4882a593Smuzhiyun size_t bufsz = 30 * NUM_IEEE80211_HW_FLAGS;
416*4882a593Smuzhiyun char *buf = kzalloc(bufsz, GFP_KERNEL);
417*4882a593Smuzhiyun char *pos = buf, *end = buf + bufsz - 1;
418*4882a593Smuzhiyun ssize_t rv;
419*4882a593Smuzhiyun int i;
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun if (!buf)
422*4882a593Smuzhiyun return -ENOMEM;
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun /* fail compilation if somebody adds or removes
425*4882a593Smuzhiyun * a flag without updating the name array above
426*4882a593Smuzhiyun */
427*4882a593Smuzhiyun BUILD_BUG_ON(ARRAY_SIZE(hw_flag_names) != NUM_IEEE80211_HW_FLAGS);
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
430*4882a593Smuzhiyun if (test_bit(i, local->hw.flags))
431*4882a593Smuzhiyun pos += scnprintf(pos, end - pos, "%s\n",
432*4882a593Smuzhiyun hw_flag_names[i]);
433*4882a593Smuzhiyun }
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
436*4882a593Smuzhiyun kfree(buf);
437*4882a593Smuzhiyun return rv;
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun
misc_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)440*4882a593Smuzhiyun static ssize_t misc_read(struct file *file, char __user *user_buf,
441*4882a593Smuzhiyun size_t count, loff_t *ppos)
442*4882a593Smuzhiyun {
443*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
444*4882a593Smuzhiyun /* Max len of each line is 16 characters, plus 9 for 'pending:\n' */
445*4882a593Smuzhiyun size_t bufsz = IEEE80211_MAX_QUEUES * 16 + 9;
446*4882a593Smuzhiyun char *buf;
447*4882a593Smuzhiyun char *pos, *end;
448*4882a593Smuzhiyun ssize_t rv;
449*4882a593Smuzhiyun int i;
450*4882a593Smuzhiyun int ln;
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun buf = kzalloc(bufsz, GFP_KERNEL);
453*4882a593Smuzhiyun if (!buf)
454*4882a593Smuzhiyun return -ENOMEM;
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun pos = buf;
457*4882a593Smuzhiyun end = buf + bufsz - 1;
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun pos += scnprintf(pos, end - pos, "pending:\n");
460*4882a593Smuzhiyun
461*4882a593Smuzhiyun for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
462*4882a593Smuzhiyun ln = skb_queue_len(&local->pending[i]);
463*4882a593Smuzhiyun pos += scnprintf(pos, end - pos, "[%i] %d\n",
464*4882a593Smuzhiyun i, ln);
465*4882a593Smuzhiyun }
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun rv = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf));
468*4882a593Smuzhiyun kfree(buf);
469*4882a593Smuzhiyun return rv;
470*4882a593Smuzhiyun }
471*4882a593Smuzhiyun
queues_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)472*4882a593Smuzhiyun static ssize_t queues_read(struct file *file, char __user *user_buf,
473*4882a593Smuzhiyun size_t count, loff_t *ppos)
474*4882a593Smuzhiyun {
475*4882a593Smuzhiyun struct ieee80211_local *local = file->private_data;
476*4882a593Smuzhiyun unsigned long flags;
477*4882a593Smuzhiyun char buf[IEEE80211_MAX_QUEUES * 20];
478*4882a593Smuzhiyun int q, res = 0;
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
481*4882a593Smuzhiyun for (q = 0; q < local->hw.queues; q++)
482*4882a593Smuzhiyun res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
483*4882a593Smuzhiyun local->queue_stop_reasons[q],
484*4882a593Smuzhiyun skb_queue_len(&local->pending[q]));
485*4882a593Smuzhiyun spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, res);
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun DEBUGFS_READONLY_FILE_OPS(hwflags);
491*4882a593Smuzhiyun DEBUGFS_READONLY_FILE_OPS(queues);
492*4882a593Smuzhiyun DEBUGFS_READONLY_FILE_OPS(misc);
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun /* statistics stuff */
495*4882a593Smuzhiyun
format_devstat_counter(struct ieee80211_local * local,char __user * userbuf,size_t count,loff_t * ppos,int (* printvalue)(struct ieee80211_low_level_stats * stats,char * buf,int buflen))496*4882a593Smuzhiyun static ssize_t format_devstat_counter(struct ieee80211_local *local,
497*4882a593Smuzhiyun char __user *userbuf,
498*4882a593Smuzhiyun size_t count, loff_t *ppos,
499*4882a593Smuzhiyun int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
500*4882a593Smuzhiyun int buflen))
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun struct ieee80211_low_level_stats stats;
503*4882a593Smuzhiyun char buf[20];
504*4882a593Smuzhiyun int res;
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun rtnl_lock();
507*4882a593Smuzhiyun res = drv_get_stats(local, &stats);
508*4882a593Smuzhiyun rtnl_unlock();
509*4882a593Smuzhiyun if (res)
510*4882a593Smuzhiyun return res;
511*4882a593Smuzhiyun res = printvalue(&stats, buf, sizeof(buf));
512*4882a593Smuzhiyun return simple_read_from_buffer(userbuf, count, ppos, buf, res);
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun #define DEBUGFS_DEVSTATS_FILE(name) \
516*4882a593Smuzhiyun static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
517*4882a593Smuzhiyun char *buf, int buflen) \
518*4882a593Smuzhiyun { \
519*4882a593Smuzhiyun return scnprintf(buf, buflen, "%u\n", stats->name); \
520*4882a593Smuzhiyun } \
521*4882a593Smuzhiyun static ssize_t stats_ ##name## _read(struct file *file, \
522*4882a593Smuzhiyun char __user *userbuf, \
523*4882a593Smuzhiyun size_t count, loff_t *ppos) \
524*4882a593Smuzhiyun { \
525*4882a593Smuzhiyun return format_devstat_counter(file->private_data, \
526*4882a593Smuzhiyun userbuf, \
527*4882a593Smuzhiyun count, \
528*4882a593Smuzhiyun ppos, \
529*4882a593Smuzhiyun print_devstats_##name); \
530*4882a593Smuzhiyun } \
531*4882a593Smuzhiyun \
532*4882a593Smuzhiyun static const struct file_operations stats_ ##name## _ops = { \
533*4882a593Smuzhiyun .read = stats_ ##name## _read, \
534*4882a593Smuzhiyun .open = simple_open, \
535*4882a593Smuzhiyun .llseek = generic_file_llseek, \
536*4882a593Smuzhiyun };
537*4882a593Smuzhiyun
538*4882a593Smuzhiyun #define DEBUGFS_STATS_ADD(name) \
539*4882a593Smuzhiyun debugfs_create_u32(#name, 0400, statsd, &local->name);
540*4882a593Smuzhiyun #define DEBUGFS_DEVSTATS_ADD(name) \
541*4882a593Smuzhiyun debugfs_create_file(#name, 0400, statsd, local, &stats_ ##name## _ops);
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
544*4882a593Smuzhiyun DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
545*4882a593Smuzhiyun DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
546*4882a593Smuzhiyun DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
547*4882a593Smuzhiyun
debugfs_hw_add(struct ieee80211_local * local)548*4882a593Smuzhiyun void debugfs_hw_add(struct ieee80211_local *local)
549*4882a593Smuzhiyun {
550*4882a593Smuzhiyun struct dentry *phyd = local->hw.wiphy->debugfsdir;
551*4882a593Smuzhiyun struct dentry *statsd;
552*4882a593Smuzhiyun
553*4882a593Smuzhiyun if (!phyd)
554*4882a593Smuzhiyun return;
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun local->debugfs.keys = debugfs_create_dir("keys", phyd);
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun DEBUGFS_ADD(total_ps_buffered);
559*4882a593Smuzhiyun DEBUGFS_ADD(wep_iv);
560*4882a593Smuzhiyun DEBUGFS_ADD(rate_ctrl_alg);
561*4882a593Smuzhiyun DEBUGFS_ADD(queues);
562*4882a593Smuzhiyun DEBUGFS_ADD(misc);
563*4882a593Smuzhiyun #ifdef CONFIG_PM
564*4882a593Smuzhiyun DEBUGFS_ADD_MODE(reset, 0200);
565*4882a593Smuzhiyun #endif
566*4882a593Smuzhiyun DEBUGFS_ADD(hwflags);
567*4882a593Smuzhiyun DEBUGFS_ADD(user_power);
568*4882a593Smuzhiyun DEBUGFS_ADD(power);
569*4882a593Smuzhiyun DEBUGFS_ADD(hw_conf);
570*4882a593Smuzhiyun DEBUGFS_ADD_MODE(force_tx_status, 0600);
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun if (local->ops->wake_tx_queue)
573*4882a593Smuzhiyun DEBUGFS_ADD_MODE(aqm, 0600);
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun DEBUGFS_ADD_MODE(airtime_flags, 0600);
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun DEBUGFS_ADD(aql_txq_limit);
578*4882a593Smuzhiyun debugfs_create_u32("aql_threshold", 0600,
579*4882a593Smuzhiyun phyd, &local->aql_threshold);
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun statsd = debugfs_create_dir("statistics", phyd);
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun /* if the dir failed, don't put all the other things into the root! */
584*4882a593Smuzhiyun if (!statsd)
585*4882a593Smuzhiyun return;
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_DEBUG_COUNTERS
588*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11TransmittedFragmentCount);
589*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11MulticastTransmittedFrameCount);
590*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11FailedCount);
591*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11RetryCount);
592*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11MultipleRetryCount);
593*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11FrameDuplicateCount);
594*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11ReceivedFragmentCount);
595*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11MulticastReceivedFrameCount);
596*4882a593Smuzhiyun DEBUGFS_STATS_ADD(dot11TransmittedFrameCount);
597*4882a593Smuzhiyun DEBUGFS_STATS_ADD(tx_handlers_drop);
598*4882a593Smuzhiyun DEBUGFS_STATS_ADD(tx_handlers_queued);
599*4882a593Smuzhiyun DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
600*4882a593Smuzhiyun DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
601*4882a593Smuzhiyun DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
602*4882a593Smuzhiyun DEBUGFS_STATS_ADD(rx_handlers_drop);
603*4882a593Smuzhiyun DEBUGFS_STATS_ADD(rx_handlers_queued);
604*4882a593Smuzhiyun DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
605*4882a593Smuzhiyun DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
606*4882a593Smuzhiyun DEBUGFS_STATS_ADD(tx_expand_skb_head);
607*4882a593Smuzhiyun DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
608*4882a593Smuzhiyun DEBUGFS_STATS_ADD(rx_expand_skb_head_defrag);
609*4882a593Smuzhiyun DEBUGFS_STATS_ADD(rx_handlers_fragments);
610*4882a593Smuzhiyun DEBUGFS_STATS_ADD(tx_status_drop);
611*4882a593Smuzhiyun #endif
612*4882a593Smuzhiyun DEBUGFS_DEVSTATS_ADD(dot11ACKFailureCount);
613*4882a593Smuzhiyun DEBUGFS_DEVSTATS_ADD(dot11RTSFailureCount);
614*4882a593Smuzhiyun DEBUGFS_DEVSTATS_ADD(dot11FCSErrorCount);
615*4882a593Smuzhiyun DEBUGFS_DEVSTATS_ADD(dot11RTSSuccessCount);
616*4882a593Smuzhiyun }
617