1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * This file is provided under a dual BSD/GPLv2 license. When using or
4*4882a593Smuzhiyun * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * GPL LICENSE SUMMARY
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9*4882a593Smuzhiyun * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10*4882a593Smuzhiyun * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
13*4882a593Smuzhiyun * it under the terms of version 2 of the GNU General Public License as
14*4882a593Smuzhiyun * published by the Free Software Foundation.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but
17*4882a593Smuzhiyun * WITHOUT ANY WARRANTY; without even the implied warranty of
18*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19*4882a593Smuzhiyun * General Public License for more details.
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * The full GNU General Public License is included in this distribution
22*4882a593Smuzhiyun * in the file called COPYING.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * Contact Information:
25*4882a593Smuzhiyun * Intel Linux Wireless <linuxwifi@intel.com>
26*4882a593Smuzhiyun * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * BSD LICENSE
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
31*4882a593Smuzhiyun * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
32*4882a593Smuzhiyun * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
33*4882a593Smuzhiyun * All rights reserved.
34*4882a593Smuzhiyun *
35*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
36*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
37*4882a593Smuzhiyun * are met:
38*4882a593Smuzhiyun *
39*4882a593Smuzhiyun * * Redistributions of source code must retain the above copyright
40*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
41*4882a593Smuzhiyun * * Redistributions in binary form must reproduce the above copyright
42*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in
43*4882a593Smuzhiyun * the documentation and/or other materials provided with the
44*4882a593Smuzhiyun * distribution.
45*4882a593Smuzhiyun * * Neither the name Intel Corporation nor the names of its
46*4882a593Smuzhiyun * contributors may be used to endorse or promote products derived
47*4882a593Smuzhiyun * from this software without specific prior written permission.
48*4882a593Smuzhiyun *
49*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60*4882a593Smuzhiyun *
61*4882a593Smuzhiyun *****************************************************************************/
62*4882a593Smuzhiyun #include "mvm.h"
63*4882a593Smuzhiyun #include "debugfs.h"
64*4882a593Smuzhiyun
iwl_dbgfs_update_pm(struct iwl_mvm * mvm,struct ieee80211_vif * vif,enum iwl_dbgfs_pm_mask param,int val)65*4882a593Smuzhiyun static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
66*4882a593Smuzhiyun struct ieee80211_vif *vif,
67*4882a593Smuzhiyun enum iwl_dbgfs_pm_mask param, int val)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
70*4882a593Smuzhiyun struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun dbgfs_pm->mask |= param;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun switch (param) {
75*4882a593Smuzhiyun case MVM_DEBUGFS_PM_KEEP_ALIVE: {
76*4882a593Smuzhiyun int dtimper = vif->bss_conf.dtim_period ?: 1;
77*4882a593Smuzhiyun int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
80*4882a593Smuzhiyun if (val * MSEC_PER_SEC < 3 * dtimper_msec)
81*4882a593Smuzhiyun IWL_WARN(mvm,
82*4882a593Smuzhiyun "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
83*4882a593Smuzhiyun val * MSEC_PER_SEC, 3 * dtimper_msec);
84*4882a593Smuzhiyun dbgfs_pm->keep_alive_seconds = val;
85*4882a593Smuzhiyun break;
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
88*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
89*4882a593Smuzhiyun val ? "enabled" : "disabled");
90*4882a593Smuzhiyun dbgfs_pm->skip_over_dtim = val;
91*4882a593Smuzhiyun break;
92*4882a593Smuzhiyun case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
93*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
94*4882a593Smuzhiyun dbgfs_pm->skip_dtim_periods = val;
95*4882a593Smuzhiyun break;
96*4882a593Smuzhiyun case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
97*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
98*4882a593Smuzhiyun dbgfs_pm->rx_data_timeout = val;
99*4882a593Smuzhiyun break;
100*4882a593Smuzhiyun case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
101*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
102*4882a593Smuzhiyun dbgfs_pm->tx_data_timeout = val;
103*4882a593Smuzhiyun break;
104*4882a593Smuzhiyun case MVM_DEBUGFS_PM_LPRX_ENA:
105*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
106*4882a593Smuzhiyun dbgfs_pm->lprx_ena = val;
107*4882a593Smuzhiyun break;
108*4882a593Smuzhiyun case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
109*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
110*4882a593Smuzhiyun dbgfs_pm->lprx_rssi_threshold = val;
111*4882a593Smuzhiyun break;
112*4882a593Smuzhiyun case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
113*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
114*4882a593Smuzhiyun dbgfs_pm->snooze_ena = val;
115*4882a593Smuzhiyun break;
116*4882a593Smuzhiyun case MVM_DEBUGFS_PM_UAPSD_MISBEHAVING:
117*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "uapsd_misbehaving_enable=%d\n", val);
118*4882a593Smuzhiyun dbgfs_pm->uapsd_misbehaving = val;
119*4882a593Smuzhiyun break;
120*4882a593Smuzhiyun case MVM_DEBUGFS_PM_USE_PS_POLL:
121*4882a593Smuzhiyun IWL_DEBUG_POWER(mvm, "use_ps_poll=%d\n", val);
122*4882a593Smuzhiyun dbgfs_pm->use_ps_poll = val;
123*4882a593Smuzhiyun break;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun }
126*4882a593Smuzhiyun
iwl_dbgfs_pm_params_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)127*4882a593Smuzhiyun static ssize_t iwl_dbgfs_pm_params_write(struct ieee80211_vif *vif, char *buf,
128*4882a593Smuzhiyun size_t count, loff_t *ppos)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
131*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
132*4882a593Smuzhiyun enum iwl_dbgfs_pm_mask param;
133*4882a593Smuzhiyun int val, ret;
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun if (!strncmp("keep_alive=", buf, 11)) {
136*4882a593Smuzhiyun if (sscanf(buf + 11, "%d", &val) != 1)
137*4882a593Smuzhiyun return -EINVAL;
138*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_KEEP_ALIVE;
139*4882a593Smuzhiyun } else if (!strncmp("skip_over_dtim=", buf, 15)) {
140*4882a593Smuzhiyun if (sscanf(buf + 15, "%d", &val) != 1)
141*4882a593Smuzhiyun return -EINVAL;
142*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
143*4882a593Smuzhiyun } else if (!strncmp("skip_dtim_periods=", buf, 18)) {
144*4882a593Smuzhiyun if (sscanf(buf + 18, "%d", &val) != 1)
145*4882a593Smuzhiyun return -EINVAL;
146*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
147*4882a593Smuzhiyun } else if (!strncmp("rx_data_timeout=", buf, 16)) {
148*4882a593Smuzhiyun if (sscanf(buf + 16, "%d", &val) != 1)
149*4882a593Smuzhiyun return -EINVAL;
150*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
151*4882a593Smuzhiyun } else if (!strncmp("tx_data_timeout=", buf, 16)) {
152*4882a593Smuzhiyun if (sscanf(buf + 16, "%d", &val) != 1)
153*4882a593Smuzhiyun return -EINVAL;
154*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
155*4882a593Smuzhiyun } else if (!strncmp("lprx=", buf, 5)) {
156*4882a593Smuzhiyun if (sscanf(buf + 5, "%d", &val) != 1)
157*4882a593Smuzhiyun return -EINVAL;
158*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_LPRX_ENA;
159*4882a593Smuzhiyun } else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
160*4882a593Smuzhiyun if (sscanf(buf + 20, "%d", &val) != 1)
161*4882a593Smuzhiyun return -EINVAL;
162*4882a593Smuzhiyun if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
163*4882a593Smuzhiyun POWER_LPRX_RSSI_THRESHOLD_MIN)
164*4882a593Smuzhiyun return -EINVAL;
165*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
166*4882a593Smuzhiyun } else if (!strncmp("snooze_enable=", buf, 14)) {
167*4882a593Smuzhiyun if (sscanf(buf + 14, "%d", &val) != 1)
168*4882a593Smuzhiyun return -EINVAL;
169*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
170*4882a593Smuzhiyun } else if (!strncmp("uapsd_misbehaving=", buf, 18)) {
171*4882a593Smuzhiyun if (sscanf(buf + 18, "%d", &val) != 1)
172*4882a593Smuzhiyun return -EINVAL;
173*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_UAPSD_MISBEHAVING;
174*4882a593Smuzhiyun } else if (!strncmp("use_ps_poll=", buf, 12)) {
175*4882a593Smuzhiyun if (sscanf(buf + 12, "%d", &val) != 1)
176*4882a593Smuzhiyun return -EINVAL;
177*4882a593Smuzhiyun param = MVM_DEBUGFS_PM_USE_PS_POLL;
178*4882a593Smuzhiyun } else {
179*4882a593Smuzhiyun return -EINVAL;
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
183*4882a593Smuzhiyun iwl_dbgfs_update_pm(mvm, vif, param, val);
184*4882a593Smuzhiyun ret = iwl_mvm_power_update_mac(mvm);
185*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun return ret ?: count;
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
iwl_dbgfs_tx_pwr_lmt_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)190*4882a593Smuzhiyun static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,
191*4882a593Smuzhiyun char __user *user_buf,
192*4882a593Smuzhiyun size_t count, loff_t *ppos)
193*4882a593Smuzhiyun {
194*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
195*4882a593Smuzhiyun char buf[64];
196*4882a593Smuzhiyun int bufsz = sizeof(buf);
197*4882a593Smuzhiyun int pos;
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun pos = scnprintf(buf, bufsz, "bss limit = %d\n",
200*4882a593Smuzhiyun vif->bss_conf.txpower);
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
203*4882a593Smuzhiyun }
204*4882a593Smuzhiyun
iwl_dbgfs_pm_params_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)205*4882a593Smuzhiyun static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
206*4882a593Smuzhiyun char __user *user_buf,
207*4882a593Smuzhiyun size_t count, loff_t *ppos)
208*4882a593Smuzhiyun {
209*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
210*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
211*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
212*4882a593Smuzhiyun char buf[512];
213*4882a593Smuzhiyun int bufsz = sizeof(buf);
214*4882a593Smuzhiyun int pos;
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun pos = iwl_mvm_power_mac_dbgfs_read(mvm, vif, buf, bufsz);
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
iwl_dbgfs_mac_params_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)221*4882a593Smuzhiyun static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
222*4882a593Smuzhiyun char __user *user_buf,
223*4882a593Smuzhiyun size_t count, loff_t *ppos)
224*4882a593Smuzhiyun {
225*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
226*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
227*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
228*4882a593Smuzhiyun u8 ap_sta_id;
229*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
230*4882a593Smuzhiyun char buf[512];
231*4882a593Smuzhiyun int bufsz = sizeof(buf);
232*4882a593Smuzhiyun int pos = 0;
233*4882a593Smuzhiyun int i;
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun ap_sta_id = mvmvif->ap_sta_id;
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun switch (ieee80211_vif_type_p2p(vif)) {
240*4882a593Smuzhiyun case NL80211_IFTYPE_ADHOC:
241*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "type: ibss\n");
242*4882a593Smuzhiyun break;
243*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
244*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "type: bss\n");
245*4882a593Smuzhiyun break;
246*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
247*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "type: ap\n");
248*4882a593Smuzhiyun break;
249*4882a593Smuzhiyun case NL80211_IFTYPE_P2P_CLIENT:
250*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "type: p2p client\n");
251*4882a593Smuzhiyun break;
252*4882a593Smuzhiyun case NL80211_IFTYPE_P2P_GO:
253*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "type: p2p go\n");
254*4882a593Smuzhiyun break;
255*4882a593Smuzhiyun case NL80211_IFTYPE_P2P_DEVICE:
256*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "type: p2p dev\n");
257*4882a593Smuzhiyun break;
258*4882a593Smuzhiyun default:
259*4882a593Smuzhiyun break;
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
263*4882a593Smuzhiyun mvmvif->id, mvmvif->color);
264*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
265*4882a593Smuzhiyun vif->bss_conf.bssid);
266*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "Load: %d\n",
267*4882a593Smuzhiyun mvm->tcm.result.load[mvmvif->id]);
268*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
269*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(mvmvif->queue_params); i++)
270*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos,
271*4882a593Smuzhiyun "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
272*4882a593Smuzhiyun i, mvmvif->queue_params[i].txop,
273*4882a593Smuzhiyun mvmvif->queue_params[i].cw_min,
274*4882a593Smuzhiyun mvmvif->queue_params[i].cw_max,
275*4882a593Smuzhiyun mvmvif->queue_params[i].aifs,
276*4882a593Smuzhiyun mvmvif->queue_params[i].uapsd);
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun if (vif->type == NL80211_IFTYPE_STATION &&
279*4882a593Smuzhiyun ap_sta_id != IWL_MVM_INVALID_STA) {
280*4882a593Smuzhiyun struct iwl_mvm_sta *mvm_sta;
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun mvm_sta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id);
283*4882a593Smuzhiyun if (mvm_sta) {
284*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos,
285*4882a593Smuzhiyun "ap_sta_id %d - reduced Tx power %d\n",
286*4882a593Smuzhiyun ap_sta_id,
287*4882a593Smuzhiyun mvm_sta->bt_reduced_txpower);
288*4882a593Smuzhiyun }
289*4882a593Smuzhiyun }
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun rcu_read_lock();
292*4882a593Smuzhiyun chanctx_conf = rcu_dereference(vif->chanctx_conf);
293*4882a593Smuzhiyun if (chanctx_conf)
294*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos,
295*4882a593Smuzhiyun "idle rx chains %d, active rx chains: %d\n",
296*4882a593Smuzhiyun chanctx_conf->rx_chains_static,
297*4882a593Smuzhiyun chanctx_conf->rx_chains_dynamic);
298*4882a593Smuzhiyun rcu_read_unlock();
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
303*4882a593Smuzhiyun }
304*4882a593Smuzhiyun
iwl_dbgfs_update_bf(struct ieee80211_vif * vif,enum iwl_dbgfs_bf_mask param,int value)305*4882a593Smuzhiyun static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
306*4882a593Smuzhiyun enum iwl_dbgfs_bf_mask param, int value)
307*4882a593Smuzhiyun {
308*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
309*4882a593Smuzhiyun struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun dbgfs_bf->mask |= param;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun switch (param) {
314*4882a593Smuzhiyun case MVM_DEBUGFS_BF_ENERGY_DELTA:
315*4882a593Smuzhiyun dbgfs_bf->bf_energy_delta = value;
316*4882a593Smuzhiyun break;
317*4882a593Smuzhiyun case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
318*4882a593Smuzhiyun dbgfs_bf->bf_roaming_energy_delta = value;
319*4882a593Smuzhiyun break;
320*4882a593Smuzhiyun case MVM_DEBUGFS_BF_ROAMING_STATE:
321*4882a593Smuzhiyun dbgfs_bf->bf_roaming_state = value;
322*4882a593Smuzhiyun break;
323*4882a593Smuzhiyun case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
324*4882a593Smuzhiyun dbgfs_bf->bf_temp_threshold = value;
325*4882a593Smuzhiyun break;
326*4882a593Smuzhiyun case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
327*4882a593Smuzhiyun dbgfs_bf->bf_temp_fast_filter = value;
328*4882a593Smuzhiyun break;
329*4882a593Smuzhiyun case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
330*4882a593Smuzhiyun dbgfs_bf->bf_temp_slow_filter = value;
331*4882a593Smuzhiyun break;
332*4882a593Smuzhiyun case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
333*4882a593Smuzhiyun dbgfs_bf->bf_enable_beacon_filter = value;
334*4882a593Smuzhiyun break;
335*4882a593Smuzhiyun case MVM_DEBUGFS_BF_DEBUG_FLAG:
336*4882a593Smuzhiyun dbgfs_bf->bf_debug_flag = value;
337*4882a593Smuzhiyun break;
338*4882a593Smuzhiyun case MVM_DEBUGFS_BF_ESCAPE_TIMER:
339*4882a593Smuzhiyun dbgfs_bf->bf_escape_timer = value;
340*4882a593Smuzhiyun break;
341*4882a593Smuzhiyun case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
342*4882a593Smuzhiyun dbgfs_bf->ba_enable_beacon_abort = value;
343*4882a593Smuzhiyun break;
344*4882a593Smuzhiyun case MVM_DEBUGFS_BA_ESCAPE_TIMER:
345*4882a593Smuzhiyun dbgfs_bf->ba_escape_timer = value;
346*4882a593Smuzhiyun break;
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun }
349*4882a593Smuzhiyun
iwl_dbgfs_bf_params_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)350*4882a593Smuzhiyun static ssize_t iwl_dbgfs_bf_params_write(struct ieee80211_vif *vif, char *buf,
351*4882a593Smuzhiyun size_t count, loff_t *ppos)
352*4882a593Smuzhiyun {
353*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
354*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
355*4882a593Smuzhiyun enum iwl_dbgfs_bf_mask param;
356*4882a593Smuzhiyun int value, ret = 0;
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun if (!strncmp("bf_energy_delta=", buf, 16)) {
359*4882a593Smuzhiyun if (sscanf(buf+16, "%d", &value) != 1)
360*4882a593Smuzhiyun return -EINVAL;
361*4882a593Smuzhiyun if (value < IWL_BF_ENERGY_DELTA_MIN ||
362*4882a593Smuzhiyun value > IWL_BF_ENERGY_DELTA_MAX)
363*4882a593Smuzhiyun return -EINVAL;
364*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_ENERGY_DELTA;
365*4882a593Smuzhiyun } else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
366*4882a593Smuzhiyun if (sscanf(buf+24, "%d", &value) != 1)
367*4882a593Smuzhiyun return -EINVAL;
368*4882a593Smuzhiyun if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
369*4882a593Smuzhiyun value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
370*4882a593Smuzhiyun return -EINVAL;
371*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
372*4882a593Smuzhiyun } else if (!strncmp("bf_roaming_state=", buf, 17)) {
373*4882a593Smuzhiyun if (sscanf(buf+17, "%d", &value) != 1)
374*4882a593Smuzhiyun return -EINVAL;
375*4882a593Smuzhiyun if (value < IWL_BF_ROAMING_STATE_MIN ||
376*4882a593Smuzhiyun value > IWL_BF_ROAMING_STATE_MAX)
377*4882a593Smuzhiyun return -EINVAL;
378*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_ROAMING_STATE;
379*4882a593Smuzhiyun } else if (!strncmp("bf_temp_threshold=", buf, 18)) {
380*4882a593Smuzhiyun if (sscanf(buf+18, "%d", &value) != 1)
381*4882a593Smuzhiyun return -EINVAL;
382*4882a593Smuzhiyun if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
383*4882a593Smuzhiyun value > IWL_BF_TEMP_THRESHOLD_MAX)
384*4882a593Smuzhiyun return -EINVAL;
385*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
386*4882a593Smuzhiyun } else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
387*4882a593Smuzhiyun if (sscanf(buf+20, "%d", &value) != 1)
388*4882a593Smuzhiyun return -EINVAL;
389*4882a593Smuzhiyun if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
390*4882a593Smuzhiyun value > IWL_BF_TEMP_FAST_FILTER_MAX)
391*4882a593Smuzhiyun return -EINVAL;
392*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
393*4882a593Smuzhiyun } else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
394*4882a593Smuzhiyun if (sscanf(buf+20, "%d", &value) != 1)
395*4882a593Smuzhiyun return -EINVAL;
396*4882a593Smuzhiyun if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
397*4882a593Smuzhiyun value > IWL_BF_TEMP_SLOW_FILTER_MAX)
398*4882a593Smuzhiyun return -EINVAL;
399*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
400*4882a593Smuzhiyun } else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
401*4882a593Smuzhiyun if (sscanf(buf+24, "%d", &value) != 1)
402*4882a593Smuzhiyun return -EINVAL;
403*4882a593Smuzhiyun if (value < 0 || value > 1)
404*4882a593Smuzhiyun return -EINVAL;
405*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
406*4882a593Smuzhiyun } else if (!strncmp("bf_debug_flag=", buf, 14)) {
407*4882a593Smuzhiyun if (sscanf(buf+14, "%d", &value) != 1)
408*4882a593Smuzhiyun return -EINVAL;
409*4882a593Smuzhiyun if (value < 0 || value > 1)
410*4882a593Smuzhiyun return -EINVAL;
411*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_DEBUG_FLAG;
412*4882a593Smuzhiyun } else if (!strncmp("bf_escape_timer=", buf, 16)) {
413*4882a593Smuzhiyun if (sscanf(buf+16, "%d", &value) != 1)
414*4882a593Smuzhiyun return -EINVAL;
415*4882a593Smuzhiyun if (value < IWL_BF_ESCAPE_TIMER_MIN ||
416*4882a593Smuzhiyun value > IWL_BF_ESCAPE_TIMER_MAX)
417*4882a593Smuzhiyun return -EINVAL;
418*4882a593Smuzhiyun param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
419*4882a593Smuzhiyun } else if (!strncmp("ba_escape_timer=", buf, 16)) {
420*4882a593Smuzhiyun if (sscanf(buf+16, "%d", &value) != 1)
421*4882a593Smuzhiyun return -EINVAL;
422*4882a593Smuzhiyun if (value < IWL_BA_ESCAPE_TIMER_MIN ||
423*4882a593Smuzhiyun value > IWL_BA_ESCAPE_TIMER_MAX)
424*4882a593Smuzhiyun return -EINVAL;
425*4882a593Smuzhiyun param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
426*4882a593Smuzhiyun } else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
427*4882a593Smuzhiyun if (sscanf(buf+23, "%d", &value) != 1)
428*4882a593Smuzhiyun return -EINVAL;
429*4882a593Smuzhiyun if (value < 0 || value > 1)
430*4882a593Smuzhiyun return -EINVAL;
431*4882a593Smuzhiyun param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
432*4882a593Smuzhiyun } else {
433*4882a593Smuzhiyun return -EINVAL;
434*4882a593Smuzhiyun }
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
437*4882a593Smuzhiyun iwl_dbgfs_update_bf(vif, param, value);
438*4882a593Smuzhiyun if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)
439*4882a593Smuzhiyun ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
440*4882a593Smuzhiyun else
441*4882a593Smuzhiyun ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
442*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun return ret ?: count;
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun
iwl_dbgfs_bf_params_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)447*4882a593Smuzhiyun static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
448*4882a593Smuzhiyun char __user *user_buf,
449*4882a593Smuzhiyun size_t count, loff_t *ppos)
450*4882a593Smuzhiyun {
451*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
452*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
453*4882a593Smuzhiyun char buf[256];
454*4882a593Smuzhiyun int pos = 0;
455*4882a593Smuzhiyun const size_t bufsz = sizeof(buf);
456*4882a593Smuzhiyun struct iwl_beacon_filter_cmd cmd = {
457*4882a593Smuzhiyun IWL_BF_CMD_CONFIG_DEFAULTS,
458*4882a593Smuzhiyun .bf_enable_beacon_filter =
459*4882a593Smuzhiyun cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
460*4882a593Smuzhiyun .ba_enable_beacon_abort =
461*4882a593Smuzhiyun cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
462*4882a593Smuzhiyun };
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
465*4882a593Smuzhiyun if (mvmvif->bf_data.bf_enabled)
466*4882a593Smuzhiyun cmd.bf_enable_beacon_filter = cpu_to_le32(1);
467*4882a593Smuzhiyun else
468*4882a593Smuzhiyun cmd.bf_enable_beacon_filter = 0;
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
471*4882a593Smuzhiyun le32_to_cpu(cmd.bf_energy_delta));
472*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
473*4882a593Smuzhiyun le32_to_cpu(cmd.bf_roaming_energy_delta));
474*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
475*4882a593Smuzhiyun le32_to_cpu(cmd.bf_roaming_state));
476*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
477*4882a593Smuzhiyun le32_to_cpu(cmd.bf_temp_threshold));
478*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
479*4882a593Smuzhiyun le32_to_cpu(cmd.bf_temp_fast_filter));
480*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
481*4882a593Smuzhiyun le32_to_cpu(cmd.bf_temp_slow_filter));
482*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
483*4882a593Smuzhiyun le32_to_cpu(cmd.bf_enable_beacon_filter));
484*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
485*4882a593Smuzhiyun le32_to_cpu(cmd.bf_debug_flag));
486*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
487*4882a593Smuzhiyun le32_to_cpu(cmd.bf_escape_timer));
488*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
489*4882a593Smuzhiyun le32_to_cpu(cmd.ba_escape_timer));
490*4882a593Smuzhiyun pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
491*4882a593Smuzhiyun le32_to_cpu(cmd.ba_enable_beacon_abort));
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun
iwl_dbgfs_is_match(char * name,char * buf)496*4882a593Smuzhiyun static inline char *iwl_dbgfs_is_match(char *name, char *buf)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun int len = strlen(name);
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun return !strncmp(name, buf, len) ? buf + len : NULL;
501*4882a593Smuzhiyun }
502*4882a593Smuzhiyun
iwl_dbgfs_os_device_timediff_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)503*4882a593Smuzhiyun static ssize_t iwl_dbgfs_os_device_timediff_read(struct file *file,
504*4882a593Smuzhiyun char __user *user_buf,
505*4882a593Smuzhiyun size_t count, loff_t *ppos)
506*4882a593Smuzhiyun {
507*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
508*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
509*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
510*4882a593Smuzhiyun u32 curr_gp2;
511*4882a593Smuzhiyun u64 curr_os;
512*4882a593Smuzhiyun s64 diff;
513*4882a593Smuzhiyun char buf[64];
514*4882a593Smuzhiyun const size_t bufsz = sizeof(buf);
515*4882a593Smuzhiyun int pos = 0;
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
518*4882a593Smuzhiyun iwl_mvm_get_sync_time(mvm, &curr_gp2, &curr_os);
519*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
520*4882a593Smuzhiyun
521*4882a593Smuzhiyun do_div(curr_os, NSEC_PER_USEC);
522*4882a593Smuzhiyun diff = curr_os - curr_gp2;
523*4882a593Smuzhiyun pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
526*4882a593Smuzhiyun }
527*4882a593Smuzhiyun
iwl_dbgfs_low_latency_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)528*4882a593Smuzhiyun static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
529*4882a593Smuzhiyun size_t count, loff_t *ppos)
530*4882a593Smuzhiyun {
531*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
532*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
533*4882a593Smuzhiyun u8 value;
534*4882a593Smuzhiyun int ret;
535*4882a593Smuzhiyun
536*4882a593Smuzhiyun ret = kstrtou8(buf, 0, &value);
537*4882a593Smuzhiyun if (ret)
538*4882a593Smuzhiyun return ret;
539*4882a593Smuzhiyun if (value > 1)
540*4882a593Smuzhiyun return -EINVAL;
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
543*4882a593Smuzhiyun iwl_mvm_update_low_latency(mvm, vif, value, LOW_LATENCY_DEBUGFS);
544*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun return count;
547*4882a593Smuzhiyun }
548*4882a593Smuzhiyun
549*4882a593Smuzhiyun static ssize_t
iwl_dbgfs_low_latency_force_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)550*4882a593Smuzhiyun iwl_dbgfs_low_latency_force_write(struct ieee80211_vif *vif, char *buf,
551*4882a593Smuzhiyun size_t count, loff_t *ppos)
552*4882a593Smuzhiyun {
553*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
554*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
555*4882a593Smuzhiyun u8 value;
556*4882a593Smuzhiyun int ret;
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun ret = kstrtou8(buf, 0, &value);
559*4882a593Smuzhiyun if (ret)
560*4882a593Smuzhiyun return ret;
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun if (value > NUM_LOW_LATENCY_FORCE)
563*4882a593Smuzhiyun return -EINVAL;
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
566*4882a593Smuzhiyun if (value == LOW_LATENCY_FORCE_UNSET) {
567*4882a593Smuzhiyun iwl_mvm_update_low_latency(mvm, vif, false,
568*4882a593Smuzhiyun LOW_LATENCY_DEBUGFS_FORCE);
569*4882a593Smuzhiyun iwl_mvm_update_low_latency(mvm, vif, false,
570*4882a593Smuzhiyun LOW_LATENCY_DEBUGFS_FORCE_ENABLE);
571*4882a593Smuzhiyun } else {
572*4882a593Smuzhiyun iwl_mvm_update_low_latency(mvm, vif,
573*4882a593Smuzhiyun value == LOW_LATENCY_FORCE_ON,
574*4882a593Smuzhiyun LOW_LATENCY_DEBUGFS_FORCE);
575*4882a593Smuzhiyun iwl_mvm_update_low_latency(mvm, vif, true,
576*4882a593Smuzhiyun LOW_LATENCY_DEBUGFS_FORCE_ENABLE);
577*4882a593Smuzhiyun }
578*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
579*4882a593Smuzhiyun return count;
580*4882a593Smuzhiyun }
581*4882a593Smuzhiyun
iwl_dbgfs_low_latency_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)582*4882a593Smuzhiyun static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
583*4882a593Smuzhiyun char __user *user_buf,
584*4882a593Smuzhiyun size_t count, loff_t *ppos)
585*4882a593Smuzhiyun {
586*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
587*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
588*4882a593Smuzhiyun char format[] = "traffic=%d\ndbgfs=%d\nvcmd=%d\nvif_type=%d\n"
589*4882a593Smuzhiyun "dbgfs_force_enable=%d\ndbgfs_force=%d\nactual=%d\n";
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun /*
592*4882a593Smuzhiyun * all values in format are boolean so the size of format is enough
593*4882a593Smuzhiyun * for holding the result string
594*4882a593Smuzhiyun */
595*4882a593Smuzhiyun char buf[sizeof(format) + 1] = {};
596*4882a593Smuzhiyun int len;
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun len = scnprintf(buf, sizeof(buf) - 1, format,
599*4882a593Smuzhiyun !!(mvmvif->low_latency & LOW_LATENCY_TRAFFIC),
600*4882a593Smuzhiyun !!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS),
601*4882a593Smuzhiyun !!(mvmvif->low_latency & LOW_LATENCY_VCMD),
602*4882a593Smuzhiyun !!(mvmvif->low_latency & LOW_LATENCY_VIF_TYPE),
603*4882a593Smuzhiyun !!(mvmvif->low_latency &
604*4882a593Smuzhiyun LOW_LATENCY_DEBUGFS_FORCE_ENABLE),
605*4882a593Smuzhiyun !!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS_FORCE),
606*4882a593Smuzhiyun !!(mvmvif->low_latency_actual));
607*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, len);
608*4882a593Smuzhiyun }
609*4882a593Smuzhiyun
iwl_dbgfs_uapsd_misbehaving_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)610*4882a593Smuzhiyun static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
611*4882a593Smuzhiyun char __user *user_buf,
612*4882a593Smuzhiyun size_t count, loff_t *ppos)
613*4882a593Smuzhiyun {
614*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
615*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
616*4882a593Smuzhiyun char buf[20];
617*4882a593Smuzhiyun int len;
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_bssid);
620*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, len);
621*4882a593Smuzhiyun }
622*4882a593Smuzhiyun
iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)623*4882a593Smuzhiyun static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
624*4882a593Smuzhiyun char *buf, size_t count,
625*4882a593Smuzhiyun loff_t *ppos)
626*4882a593Smuzhiyun {
627*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
628*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
629*4882a593Smuzhiyun bool ret;
630*4882a593Smuzhiyun
631*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
632*4882a593Smuzhiyun ret = mac_pton(buf, mvmvif->uapsd_misbehaving_bssid);
633*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun return ret ? count : -EINVAL;
636*4882a593Smuzhiyun }
637*4882a593Smuzhiyun
iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)638*4882a593Smuzhiyun static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
639*4882a593Smuzhiyun size_t count, loff_t *ppos)
640*4882a593Smuzhiyun {
641*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
642*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
643*4882a593Smuzhiyun struct ieee80211_chanctx_conf *chanctx_conf;
644*4882a593Smuzhiyun struct iwl_mvm_phy_ctxt *phy_ctxt;
645*4882a593Smuzhiyun u16 value;
646*4882a593Smuzhiyun int ret;
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun ret = kstrtou16(buf, 0, &value);
649*4882a593Smuzhiyun if (ret)
650*4882a593Smuzhiyun return ret;
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
653*4882a593Smuzhiyun rcu_read_lock();
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun chanctx_conf = rcu_dereference(vif->chanctx_conf);
656*4882a593Smuzhiyun /* make sure the channel context is assigned */
657*4882a593Smuzhiyun if (!chanctx_conf) {
658*4882a593Smuzhiyun rcu_read_unlock();
659*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
660*4882a593Smuzhiyun return -EINVAL;
661*4882a593Smuzhiyun }
662*4882a593Smuzhiyun
663*4882a593Smuzhiyun phy_ctxt = &mvm->phy_ctxts[*(u16 *)chanctx_conf->drv_priv];
664*4882a593Smuzhiyun rcu_read_unlock();
665*4882a593Smuzhiyun
666*4882a593Smuzhiyun mvm->dbgfs_rx_phyinfo = value;
667*4882a593Smuzhiyun
668*4882a593Smuzhiyun ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chanctx_conf->min_def,
669*4882a593Smuzhiyun chanctx_conf->rx_chains_static,
670*4882a593Smuzhiyun chanctx_conf->rx_chains_dynamic);
671*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun return ret ?: count;
674*4882a593Smuzhiyun }
675*4882a593Smuzhiyun
iwl_dbgfs_rx_phyinfo_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)676*4882a593Smuzhiyun static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
677*4882a593Smuzhiyun char __user *user_buf,
678*4882a593Smuzhiyun size_t count, loff_t *ppos)
679*4882a593Smuzhiyun {
680*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
681*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
682*4882a593Smuzhiyun char buf[8];
683*4882a593Smuzhiyun int len;
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun len = scnprintf(buf, sizeof(buf), "0x%04x\n",
686*4882a593Smuzhiyun mvmvif->mvm->dbgfs_rx_phyinfo);
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, len);
689*4882a593Smuzhiyun }
690*4882a593Smuzhiyun
iwl_dbgfs_quota_check(void * data,u8 * mac,struct ieee80211_vif * vif)691*4882a593Smuzhiyun static void iwl_dbgfs_quota_check(void *data, u8 *mac,
692*4882a593Smuzhiyun struct ieee80211_vif *vif)
693*4882a593Smuzhiyun {
694*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
695*4882a593Smuzhiyun int *ret = data;
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun if (mvmvif->dbgfs_quota_min)
698*4882a593Smuzhiyun *ret = -EINVAL;
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun
iwl_dbgfs_quota_min_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)701*4882a593Smuzhiyun static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,
702*4882a593Smuzhiyun size_t count, loff_t *ppos)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
705*4882a593Smuzhiyun struct iwl_mvm *mvm = mvmvif->mvm;
706*4882a593Smuzhiyun u16 value;
707*4882a593Smuzhiyun int ret;
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun ret = kstrtou16(buf, 0, &value);
710*4882a593Smuzhiyun if (ret)
711*4882a593Smuzhiyun return ret;
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun if (value > 95)
714*4882a593Smuzhiyun return -EINVAL;
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun mutex_lock(&mvm->mutex);
717*4882a593Smuzhiyun
718*4882a593Smuzhiyun mvmvif->dbgfs_quota_min = 0;
719*4882a593Smuzhiyun ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
720*4882a593Smuzhiyun iwl_dbgfs_quota_check, &ret);
721*4882a593Smuzhiyun if (ret == 0) {
722*4882a593Smuzhiyun mvmvif->dbgfs_quota_min = value;
723*4882a593Smuzhiyun iwl_mvm_update_quotas(mvm, false, NULL);
724*4882a593Smuzhiyun }
725*4882a593Smuzhiyun mutex_unlock(&mvm->mutex);
726*4882a593Smuzhiyun
727*4882a593Smuzhiyun return ret ?: count;
728*4882a593Smuzhiyun }
729*4882a593Smuzhiyun
iwl_dbgfs_quota_min_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)730*4882a593Smuzhiyun static ssize_t iwl_dbgfs_quota_min_read(struct file *file,
731*4882a593Smuzhiyun char __user *user_buf,
732*4882a593Smuzhiyun size_t count, loff_t *ppos)
733*4882a593Smuzhiyun {
734*4882a593Smuzhiyun struct ieee80211_vif *vif = file->private_data;
735*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
736*4882a593Smuzhiyun char buf[10];
737*4882a593Smuzhiyun int len;
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun len = scnprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun return simple_read_from_buffer(user_buf, count, ppos, buf, len);
742*4882a593Smuzhiyun }
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
745*4882a593Smuzhiyun _MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
746*4882a593Smuzhiyun #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
747*4882a593Smuzhiyun _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
748*4882a593Smuzhiyun #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do { \
749*4882a593Smuzhiyun debugfs_create_file(#name, mode, parent, vif, \
750*4882a593Smuzhiyun &iwl_dbgfs_##name##_ops); \
751*4882a593Smuzhiyun } while (0)
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun MVM_DEBUGFS_READ_FILE_OPS(mac_params);
754*4882a593Smuzhiyun MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
755*4882a593Smuzhiyun MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
756*4882a593Smuzhiyun MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
757*4882a593Smuzhiyun MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
758*4882a593Smuzhiyun MVM_DEBUGFS_WRITE_FILE_OPS(low_latency_force, 10);
759*4882a593Smuzhiyun MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
760*4882a593Smuzhiyun MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
761*4882a593Smuzhiyun MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);
762*4882a593Smuzhiyun MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun
iwl_mvm_vif_dbgfs_register(struct iwl_mvm * mvm,struct ieee80211_vif * vif)765*4882a593Smuzhiyun void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
766*4882a593Smuzhiyun {
767*4882a593Smuzhiyun struct dentry *dbgfs_dir = vif->debugfs_dir;
768*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
769*4882a593Smuzhiyun char buf[100];
770*4882a593Smuzhiyun
771*4882a593Smuzhiyun /*
772*4882a593Smuzhiyun * Check if debugfs directory already exist before creating it.
773*4882a593Smuzhiyun * This may happen when, for example, resetting hw or suspend-resume
774*4882a593Smuzhiyun */
775*4882a593Smuzhiyun if (!dbgfs_dir || mvmvif->dbgfs_dir)
776*4882a593Smuzhiyun return;
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
779*4882a593Smuzhiyun if (IS_ERR_OR_NULL(mvmvif->dbgfs_dir)) {
780*4882a593Smuzhiyun IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
781*4882a593Smuzhiyun dbgfs_dir);
782*4882a593Smuzhiyun return;
783*4882a593Smuzhiyun }
784*4882a593Smuzhiyun
785*4882a593Smuzhiyun if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
786*4882a593Smuzhiyun ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
787*4882a593Smuzhiyun (vif->type == NL80211_IFTYPE_STATION && vif->p2p)))
788*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, 0600);
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, 0400);
791*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, 0400);
792*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir, 0600);
793*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(low_latency_force, mvmvif->dbgfs_dir, 0600);
794*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir, 0600);
795*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir, 0600);
796*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir, 0600);
797*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff, mvmvif->dbgfs_dir, 0400);
798*4882a593Smuzhiyun
799*4882a593Smuzhiyun if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
800*4882a593Smuzhiyun mvmvif == mvm->bf_allowed_vif)
801*4882a593Smuzhiyun MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir, 0600);
802*4882a593Smuzhiyun
803*4882a593Smuzhiyun /*
804*4882a593Smuzhiyun * Create symlink for convenience pointing to interface specific
805*4882a593Smuzhiyun * debugfs entries for the driver. For example, under
806*4882a593Smuzhiyun * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
807*4882a593Smuzhiyun * find
808*4882a593Smuzhiyun * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
809*4882a593Smuzhiyun */
810*4882a593Smuzhiyun snprintf(buf, 100, "../../../%pd3/%pd",
811*4882a593Smuzhiyun dbgfs_dir,
812*4882a593Smuzhiyun mvmvif->dbgfs_dir);
813*4882a593Smuzhiyun
814*4882a593Smuzhiyun mvmvif->dbgfs_slink = debugfs_create_symlink(dbgfs_dir->d_name.name,
815*4882a593Smuzhiyun mvm->debugfs_dir, buf);
816*4882a593Smuzhiyun }
817*4882a593Smuzhiyun
iwl_mvm_vif_dbgfs_clean(struct iwl_mvm * mvm,struct ieee80211_vif * vif)818*4882a593Smuzhiyun void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
819*4882a593Smuzhiyun {
820*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
821*4882a593Smuzhiyun
822*4882a593Smuzhiyun debugfs_remove(mvmvif->dbgfs_slink);
823*4882a593Smuzhiyun mvmvif->dbgfs_slink = NULL;
824*4882a593Smuzhiyun
825*4882a593Smuzhiyun debugfs_remove_recursive(mvmvif->dbgfs_dir);
826*4882a593Smuzhiyun mvmvif->dbgfs_dir = NULL;
827*4882a593Smuzhiyun }
828