xref: /linux/drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2012-2014, 2018-2024 Intel Corporation
4  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5  * Copyright (C) 2016-2017 Intel Deutschland GmbH
6  */
7 #include "mvm.h"
8 #include "debugfs.h"
9 
iwl_dbgfs_update_pm(struct iwl_mvm * mvm,struct ieee80211_vif * vif,enum iwl_dbgfs_pm_mask param,int val)10 static void iwl_dbgfs_update_pm(struct iwl_mvm *mvm,
11 				 struct ieee80211_vif *vif,
12 				 enum iwl_dbgfs_pm_mask param, int val)
13 {
14 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
15 	struct iwl_dbgfs_pm *dbgfs_pm = &mvmvif->dbgfs_pm;
16 
17 	dbgfs_pm->mask |= param;
18 
19 	switch (param) {
20 	case MVM_DEBUGFS_PM_KEEP_ALIVE: {
21 		int dtimper = vif->bss_conf.dtim_period ?: 1;
22 		int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
23 
24 		IWL_DEBUG_POWER(mvm, "debugfs: set keep_alive= %d sec\n", val);
25 		if (val * MSEC_PER_SEC < 3 * dtimper_msec)
26 			IWL_WARN(mvm,
27 				 "debugfs: keep alive period (%ld msec) is less than minimum required (%d msec)\n",
28 				 val * MSEC_PER_SEC, 3 * dtimper_msec);
29 		dbgfs_pm->keep_alive_seconds = val;
30 		break;
31 	}
32 	case MVM_DEBUGFS_PM_SKIP_OVER_DTIM:
33 		IWL_DEBUG_POWER(mvm, "skip_over_dtim %s\n",
34 				val ? "enabled" : "disabled");
35 		dbgfs_pm->skip_over_dtim = val;
36 		break;
37 	case MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS:
38 		IWL_DEBUG_POWER(mvm, "skip_dtim_periods=%d\n", val);
39 		dbgfs_pm->skip_dtim_periods = val;
40 		break;
41 	case MVM_DEBUGFS_PM_RX_DATA_TIMEOUT:
42 		IWL_DEBUG_POWER(mvm, "rx_data_timeout=%d\n", val);
43 		dbgfs_pm->rx_data_timeout = val;
44 		break;
45 	case MVM_DEBUGFS_PM_TX_DATA_TIMEOUT:
46 		IWL_DEBUG_POWER(mvm, "tx_data_timeout=%d\n", val);
47 		dbgfs_pm->tx_data_timeout = val;
48 		break;
49 	case MVM_DEBUGFS_PM_LPRX_ENA:
50 		IWL_DEBUG_POWER(mvm, "lprx %s\n", val ? "enabled" : "disabled");
51 		dbgfs_pm->lprx_ena = val;
52 		break;
53 	case MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD:
54 		IWL_DEBUG_POWER(mvm, "lprx_rssi_threshold=%d\n", val);
55 		dbgfs_pm->lprx_rssi_threshold = val;
56 		break;
57 	case MVM_DEBUGFS_PM_SNOOZE_ENABLE:
58 		IWL_DEBUG_POWER(mvm, "snooze_enable=%d\n", val);
59 		dbgfs_pm->snooze_ena = val;
60 		break;
61 	case MVM_DEBUGFS_PM_UAPSD_MISBEHAVING:
62 		IWL_DEBUG_POWER(mvm, "uapsd_misbehaving_enable=%d\n", val);
63 		dbgfs_pm->uapsd_misbehaving = val;
64 		break;
65 	case MVM_DEBUGFS_PM_USE_PS_POLL:
66 		IWL_DEBUG_POWER(mvm, "use_ps_poll=%d\n", val);
67 		dbgfs_pm->use_ps_poll = val;
68 		break;
69 	}
70 }
71 
iwl_dbgfs_pm_params_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)72 static ssize_t iwl_dbgfs_pm_params_write(struct ieee80211_vif *vif, char *buf,
73 					 size_t count, loff_t *ppos)
74 {
75 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
76 	struct iwl_mvm *mvm = mvmvif->mvm;
77 	enum iwl_dbgfs_pm_mask param;
78 	int val, ret;
79 
80 	if (!strncmp("keep_alive=", buf, 11)) {
81 		if (sscanf(buf + 11, "%d", &val) != 1)
82 			return -EINVAL;
83 		param = MVM_DEBUGFS_PM_KEEP_ALIVE;
84 	} else if (!strncmp("skip_over_dtim=", buf, 15)) {
85 		if (sscanf(buf + 15, "%d", &val) != 1)
86 			return -EINVAL;
87 		param = MVM_DEBUGFS_PM_SKIP_OVER_DTIM;
88 	} else if (!strncmp("skip_dtim_periods=", buf, 18)) {
89 		if (sscanf(buf + 18, "%d", &val) != 1)
90 			return -EINVAL;
91 		param = MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS;
92 	} else if (!strncmp("rx_data_timeout=", buf, 16)) {
93 		if (sscanf(buf + 16, "%d", &val) != 1)
94 			return -EINVAL;
95 		param = MVM_DEBUGFS_PM_RX_DATA_TIMEOUT;
96 	} else if (!strncmp("tx_data_timeout=", buf, 16)) {
97 		if (sscanf(buf + 16, "%d", &val) != 1)
98 			return -EINVAL;
99 		param = MVM_DEBUGFS_PM_TX_DATA_TIMEOUT;
100 	} else if (!strncmp("lprx=", buf, 5)) {
101 		if (sscanf(buf + 5, "%d", &val) != 1)
102 			return -EINVAL;
103 		param = MVM_DEBUGFS_PM_LPRX_ENA;
104 	} else if (!strncmp("lprx_rssi_threshold=", buf, 20)) {
105 		if (sscanf(buf + 20, "%d", &val) != 1)
106 			return -EINVAL;
107 		if (val > POWER_LPRX_RSSI_THRESHOLD_MAX || val <
108 		    POWER_LPRX_RSSI_THRESHOLD_MIN)
109 			return -EINVAL;
110 		param = MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD;
111 	} else if (!strncmp("snooze_enable=", buf, 14)) {
112 		if (sscanf(buf + 14, "%d", &val) != 1)
113 			return -EINVAL;
114 		param = MVM_DEBUGFS_PM_SNOOZE_ENABLE;
115 	} else if (!strncmp("uapsd_misbehaving=", buf, 18)) {
116 		if (sscanf(buf + 18, "%d", &val) != 1)
117 			return -EINVAL;
118 		param = MVM_DEBUGFS_PM_UAPSD_MISBEHAVING;
119 	} else if (!strncmp("use_ps_poll=", buf, 12)) {
120 		if (sscanf(buf + 12, "%d", &val) != 1)
121 			return -EINVAL;
122 		param = MVM_DEBUGFS_PM_USE_PS_POLL;
123 	} else {
124 		return -EINVAL;
125 	}
126 
127 	mutex_lock(&mvm->mutex);
128 	iwl_dbgfs_update_pm(mvm, vif, param, val);
129 	ret = iwl_mvm_power_update_mac(mvm);
130 	mutex_unlock(&mvm->mutex);
131 
132 	return ret ?: count;
133 }
134 
iwl_dbgfs_tx_pwr_lmt_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)135 static ssize_t iwl_dbgfs_tx_pwr_lmt_read(struct file *file,
136 					 char __user *user_buf,
137 					 size_t count, loff_t *ppos)
138 {
139 	struct ieee80211_vif *vif = file->private_data;
140 	char buf[64];
141 	int bufsz = sizeof(buf);
142 	int pos;
143 
144 	pos = scnprintf(buf, bufsz, "bss limit = %d\n",
145 			vif->bss_conf.txpower);
146 
147 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
148 }
149 
iwl_dbgfs_pm_params_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)150 static ssize_t iwl_dbgfs_pm_params_read(struct file *file,
151 					char __user *user_buf,
152 					size_t count, loff_t *ppos)
153 {
154 	struct ieee80211_vif *vif = file->private_data;
155 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
156 	struct iwl_mvm *mvm = mvmvif->mvm;
157 	char buf[512];
158 	int bufsz = sizeof(buf);
159 	int pos;
160 
161 	pos = iwl_mvm_power_mac_dbgfs_read(mvm, vif, buf, bufsz);
162 
163 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
164 }
165 
iwl_dbgfs_mac_params_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)166 static ssize_t iwl_dbgfs_mac_params_read(struct file *file,
167 					 char __user *user_buf,
168 					 size_t count, loff_t *ppos)
169 {
170 	struct ieee80211_vif *vif = file->private_data;
171 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
172 	struct iwl_mvm *mvm = mvmvif->mvm;
173 	u8 ap_sta_id;
174 	struct ieee80211_chanctx_conf *chanctx_conf;
175 	char buf[512];
176 	int bufsz = sizeof(buf);
177 	int pos = 0;
178 	int i;
179 
180 	mutex_lock(&mvm->mutex);
181 
182 	ap_sta_id = mvmvif->deflink.ap_sta_id;
183 
184 	switch (ieee80211_vif_type_p2p(vif)) {
185 	case NL80211_IFTYPE_ADHOC:
186 		pos += scnprintf(buf+pos, bufsz-pos, "type: ibss\n");
187 		break;
188 	case NL80211_IFTYPE_STATION:
189 		pos += scnprintf(buf+pos, bufsz-pos, "type: bss\n");
190 		break;
191 	case NL80211_IFTYPE_AP:
192 		pos += scnprintf(buf+pos, bufsz-pos, "type: ap\n");
193 		break;
194 	case NL80211_IFTYPE_P2P_CLIENT:
195 		pos += scnprintf(buf+pos, bufsz-pos, "type: p2p client\n");
196 		break;
197 	case NL80211_IFTYPE_P2P_GO:
198 		pos += scnprintf(buf+pos, bufsz-pos, "type: p2p go\n");
199 		break;
200 	case NL80211_IFTYPE_P2P_DEVICE:
201 		pos += scnprintf(buf+pos, bufsz-pos, "type: p2p dev\n");
202 		break;
203 	default:
204 		break;
205 	}
206 
207 	pos += scnprintf(buf+pos, bufsz-pos, "mac id/color: %d / %d\n",
208 			 mvmvif->id, mvmvif->color);
209 	pos += scnprintf(buf+pos, bufsz-pos, "bssid: %pM\n",
210 			 vif->bss_conf.bssid);
211 	pos += scnprintf(buf+pos, bufsz-pos, "Load: %d\n",
212 			 mvm->tcm.result.load[mvmvif->id]);
213 	pos += scnprintf(buf+pos, bufsz-pos, "QoS:\n");
214 	for (i = 0; i < ARRAY_SIZE(mvmvif->deflink.queue_params); i++)
215 		pos += scnprintf(buf+pos, bufsz-pos,
216 				 "\t%d: txop:%d - cw_min:%d - cw_max = %d - aifs = %d upasd = %d\n",
217 				 i, mvmvif->deflink.queue_params[i].txop,
218 				 mvmvif->deflink.queue_params[i].cw_min,
219 				 mvmvif->deflink.queue_params[i].cw_max,
220 				 mvmvif->deflink.queue_params[i].aifs,
221 				 mvmvif->deflink.queue_params[i].uapsd);
222 
223 	if (vif->type == NL80211_IFTYPE_STATION &&
224 	    ap_sta_id != IWL_MVM_INVALID_STA) {
225 		struct iwl_mvm_sta *mvm_sta;
226 
227 		mvm_sta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id);
228 		if (mvm_sta) {
229 			pos += scnprintf(buf+pos, bufsz-pos,
230 					 "ap_sta_id %d - reduced Tx power %d\n",
231 					 ap_sta_id,
232 					 mvm_sta->bt_reduced_txpower);
233 		}
234 	}
235 
236 	rcu_read_lock();
237 	chanctx_conf = rcu_dereference(vif->bss_conf.chanctx_conf);
238 	if (chanctx_conf)
239 		pos += scnprintf(buf+pos, bufsz-pos,
240 				 "idle rx chains %d, active rx chains: %d\n",
241 				 chanctx_conf->rx_chains_static,
242 				 chanctx_conf->rx_chains_dynamic);
243 	rcu_read_unlock();
244 
245 	mutex_unlock(&mvm->mutex);
246 
247 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
248 }
249 
iwl_dbgfs_update_bf(struct ieee80211_vif * vif,enum iwl_dbgfs_bf_mask param,int value)250 static void iwl_dbgfs_update_bf(struct ieee80211_vif *vif,
251 				enum iwl_dbgfs_bf_mask param, int value)
252 {
253 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
254 	struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
255 
256 	dbgfs_bf->mask |= param;
257 
258 	switch (param) {
259 	case MVM_DEBUGFS_BF_ENERGY_DELTA:
260 		dbgfs_bf->bf_energy_delta = value;
261 		break;
262 	case MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA:
263 		dbgfs_bf->bf_roaming_energy_delta = value;
264 		break;
265 	case MVM_DEBUGFS_BF_ROAMING_STATE:
266 		dbgfs_bf->bf_roaming_state = value;
267 		break;
268 	case MVM_DEBUGFS_BF_TEMP_THRESHOLD:
269 		dbgfs_bf->bf_temp_threshold = value;
270 		break;
271 	case MVM_DEBUGFS_BF_TEMP_FAST_FILTER:
272 		dbgfs_bf->bf_temp_fast_filter = value;
273 		break;
274 	case MVM_DEBUGFS_BF_TEMP_SLOW_FILTER:
275 		dbgfs_bf->bf_temp_slow_filter = value;
276 		break;
277 	case MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER:
278 		dbgfs_bf->bf_enable_beacon_filter = value;
279 		break;
280 	case MVM_DEBUGFS_BF_DEBUG_FLAG:
281 		dbgfs_bf->bf_debug_flag = value;
282 		break;
283 	case MVM_DEBUGFS_BF_ESCAPE_TIMER:
284 		dbgfs_bf->bf_escape_timer = value;
285 		break;
286 	case MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT:
287 		dbgfs_bf->ba_enable_beacon_abort = value;
288 		break;
289 	case MVM_DEBUGFS_BA_ESCAPE_TIMER:
290 		dbgfs_bf->ba_escape_timer = value;
291 		break;
292 	}
293 }
294 
iwl_dbgfs_bf_params_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)295 static ssize_t iwl_dbgfs_bf_params_write(struct ieee80211_vif *vif, char *buf,
296 					 size_t count, loff_t *ppos)
297 {
298 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
299 	struct iwl_mvm *mvm = mvmvif->mvm;
300 	enum iwl_dbgfs_bf_mask param;
301 	int value, ret = 0;
302 
303 	if (!strncmp("bf_energy_delta=", buf, 16)) {
304 		if (sscanf(buf+16, "%d", &value) != 1)
305 			return -EINVAL;
306 		if (value < IWL_BF_ENERGY_DELTA_MIN ||
307 		    value > IWL_BF_ENERGY_DELTA_MAX)
308 			return -EINVAL;
309 		param = MVM_DEBUGFS_BF_ENERGY_DELTA;
310 	} else if (!strncmp("bf_roaming_energy_delta=", buf, 24)) {
311 		if (sscanf(buf+24, "%d", &value) != 1)
312 			return -EINVAL;
313 		if (value < IWL_BF_ROAMING_ENERGY_DELTA_MIN ||
314 		    value > IWL_BF_ROAMING_ENERGY_DELTA_MAX)
315 			return -EINVAL;
316 		param = MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA;
317 	} else if (!strncmp("bf_roaming_state=", buf, 17)) {
318 		if (sscanf(buf+17, "%d", &value) != 1)
319 			return -EINVAL;
320 		if (value < IWL_BF_ROAMING_STATE_MIN ||
321 		    value > IWL_BF_ROAMING_STATE_MAX)
322 			return -EINVAL;
323 		param = MVM_DEBUGFS_BF_ROAMING_STATE;
324 	} else if (!strncmp("bf_temp_threshold=", buf, 18)) {
325 		if (sscanf(buf+18, "%d", &value) != 1)
326 			return -EINVAL;
327 		if (value < IWL_BF_TEMP_THRESHOLD_MIN ||
328 		    value > IWL_BF_TEMP_THRESHOLD_MAX)
329 			return -EINVAL;
330 		param = MVM_DEBUGFS_BF_TEMP_THRESHOLD;
331 	} else if (!strncmp("bf_temp_fast_filter=", buf, 20)) {
332 		if (sscanf(buf+20, "%d", &value) != 1)
333 			return -EINVAL;
334 		if (value < IWL_BF_TEMP_FAST_FILTER_MIN ||
335 		    value > IWL_BF_TEMP_FAST_FILTER_MAX)
336 			return -EINVAL;
337 		param = MVM_DEBUGFS_BF_TEMP_FAST_FILTER;
338 	} else if (!strncmp("bf_temp_slow_filter=", buf, 20)) {
339 		if (sscanf(buf+20, "%d", &value) != 1)
340 			return -EINVAL;
341 		if (value < IWL_BF_TEMP_SLOW_FILTER_MIN ||
342 		    value > IWL_BF_TEMP_SLOW_FILTER_MAX)
343 			return -EINVAL;
344 		param = MVM_DEBUGFS_BF_TEMP_SLOW_FILTER;
345 	} else if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
346 		if (sscanf(buf+24, "%d", &value) != 1)
347 			return -EINVAL;
348 		if (value < 0 || value > 1)
349 			return -EINVAL;
350 		param = MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER;
351 	} else if (!strncmp("bf_debug_flag=", buf, 14)) {
352 		if (sscanf(buf+14, "%d", &value) != 1)
353 			return -EINVAL;
354 		if (value < 0 || value > 1)
355 			return -EINVAL;
356 		param = MVM_DEBUGFS_BF_DEBUG_FLAG;
357 	} else if (!strncmp("bf_escape_timer=", buf, 16)) {
358 		if (sscanf(buf+16, "%d", &value) != 1)
359 			return -EINVAL;
360 		if (value < IWL_BF_ESCAPE_TIMER_MIN ||
361 		    value > IWL_BF_ESCAPE_TIMER_MAX)
362 			return -EINVAL;
363 		param = MVM_DEBUGFS_BF_ESCAPE_TIMER;
364 	} else if (!strncmp("ba_escape_timer=", buf, 16)) {
365 		if (sscanf(buf+16, "%d", &value) != 1)
366 			return -EINVAL;
367 		if (value < IWL_BA_ESCAPE_TIMER_MIN ||
368 		    value > IWL_BA_ESCAPE_TIMER_MAX)
369 			return -EINVAL;
370 		param = MVM_DEBUGFS_BA_ESCAPE_TIMER;
371 	} else if (!strncmp("ba_enable_beacon_abort=", buf, 23)) {
372 		if (sscanf(buf+23, "%d", &value) != 1)
373 			return -EINVAL;
374 		if (value < 0 || value > 1)
375 			return -EINVAL;
376 		param = MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT;
377 	} else {
378 		return -EINVAL;
379 	}
380 
381 	mutex_lock(&mvm->mutex);
382 	iwl_dbgfs_update_bf(vif, param, value);
383 	if (param == MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER && !value)
384 		ret = iwl_mvm_disable_beacon_filter(mvm, vif);
385 	else
386 		ret = iwl_mvm_enable_beacon_filter(mvm, vif);
387 	mutex_unlock(&mvm->mutex);
388 
389 	return ret ?: count;
390 }
391 
iwl_dbgfs_bf_params_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)392 static ssize_t iwl_dbgfs_bf_params_read(struct file *file,
393 					char __user *user_buf,
394 					size_t count, loff_t *ppos)
395 {
396 	struct ieee80211_vif *vif = file->private_data;
397 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
398 	char buf[256];
399 	int pos = 0;
400 	const size_t bufsz = sizeof(buf);
401 	struct iwl_beacon_filter_cmd cmd = {
402 		IWL_BF_CMD_CONFIG_DEFAULTS,
403 		.bf_enable_beacon_filter =
404 			cpu_to_le32(IWL_BF_ENABLE_BEACON_FILTER_DEFAULT),
405 		.ba_enable_beacon_abort =
406 			cpu_to_le32(IWL_BA_ENABLE_BEACON_ABORT_DEFAULT),
407 	};
408 
409 	iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
410 	if (mvmvif->bf_enabled)
411 		cmd.bf_enable_beacon_filter = cpu_to_le32(1);
412 	else
413 		cmd.bf_enable_beacon_filter = 0;
414 
415 	pos += scnprintf(buf+pos, bufsz-pos, "bf_energy_delta = %d\n",
416 			 le32_to_cpu(cmd.bf_energy_delta));
417 	pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_energy_delta = %d\n",
418 			 le32_to_cpu(cmd.bf_roaming_energy_delta));
419 	pos += scnprintf(buf+pos, bufsz-pos, "bf_roaming_state = %d\n",
420 			 le32_to_cpu(cmd.bf_roaming_state));
421 	pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_threshold = %d\n",
422 			 le32_to_cpu(cmd.bf_temp_threshold));
423 	pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_fast_filter = %d\n",
424 			 le32_to_cpu(cmd.bf_temp_fast_filter));
425 	pos += scnprintf(buf+pos, bufsz-pos, "bf_temp_slow_filter = %d\n",
426 			 le32_to_cpu(cmd.bf_temp_slow_filter));
427 	pos += scnprintf(buf+pos, bufsz-pos, "bf_enable_beacon_filter = %d\n",
428 			 le32_to_cpu(cmd.bf_enable_beacon_filter));
429 	pos += scnprintf(buf+pos, bufsz-pos, "bf_debug_flag = %d\n",
430 			 le32_to_cpu(cmd.bf_debug_flag));
431 	pos += scnprintf(buf+pos, bufsz-pos, "bf_escape_timer = %d\n",
432 			 le32_to_cpu(cmd.bf_escape_timer));
433 	pos += scnprintf(buf+pos, bufsz-pos, "ba_escape_timer = %d\n",
434 			 le32_to_cpu(cmd.ba_escape_timer));
435 	pos += scnprintf(buf+pos, bufsz-pos, "ba_enable_beacon_abort = %d\n",
436 			 le32_to_cpu(cmd.ba_enable_beacon_abort));
437 
438 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
439 }
440 
iwl_dbgfs_os_device_timediff_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)441 static ssize_t iwl_dbgfs_os_device_timediff_read(struct file *file,
442 						 char __user *user_buf,
443 						 size_t count, loff_t *ppos)
444 {
445 	struct ieee80211_vif *vif = file->private_data;
446 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
447 	struct iwl_mvm *mvm = mvmvif->mvm;
448 	u32 curr_gp2;
449 	u64 curr_os;
450 	s64 diff;
451 	char buf[64];
452 	const size_t bufsz = sizeof(buf);
453 	int pos = 0;
454 
455 	mutex_lock(&mvm->mutex);
456 	iwl_mvm_get_sync_time(mvm, CLOCK_BOOTTIME, &curr_gp2, &curr_os, NULL);
457 	mutex_unlock(&mvm->mutex);
458 
459 	do_div(curr_os, NSEC_PER_USEC);
460 	diff = curr_os - curr_gp2;
461 	pos += scnprintf(buf + pos, bufsz - pos, "diff=%lld\n", diff);
462 
463 	return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
464 }
465 
iwl_dbgfs_low_latency_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)466 static ssize_t iwl_dbgfs_low_latency_write(struct ieee80211_vif *vif, char *buf,
467 					   size_t count, loff_t *ppos)
468 {
469 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
470 	struct iwl_mvm *mvm = mvmvif->mvm;
471 	u8 value;
472 	int ret;
473 
474 	ret = kstrtou8(buf, 0, &value);
475 	if (ret)
476 		return ret;
477 	if (value > 1)
478 		return -EINVAL;
479 
480 	mutex_lock(&mvm->mutex);
481 	iwl_mvm_update_low_latency(mvm, vif, value, LOW_LATENCY_DEBUGFS);
482 	mutex_unlock(&mvm->mutex);
483 
484 	return count;
485 }
486 
487 static ssize_t
iwl_dbgfs_low_latency_force_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)488 iwl_dbgfs_low_latency_force_write(struct ieee80211_vif *vif, char *buf,
489 				  size_t count, loff_t *ppos)
490 {
491 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
492 	struct iwl_mvm *mvm = mvmvif->mvm;
493 	u8 value;
494 	int ret;
495 
496 	ret = kstrtou8(buf, 0, &value);
497 	if (ret)
498 		return ret;
499 
500 	if (value > NUM_LOW_LATENCY_FORCE)
501 		return -EINVAL;
502 
503 	mutex_lock(&mvm->mutex);
504 	if (value == LOW_LATENCY_FORCE_UNSET) {
505 		iwl_mvm_update_low_latency(mvm, vif, false,
506 					   LOW_LATENCY_DEBUGFS_FORCE);
507 		iwl_mvm_update_low_latency(mvm, vif, false,
508 					   LOW_LATENCY_DEBUGFS_FORCE_ENABLE);
509 	} else {
510 		iwl_mvm_update_low_latency(mvm, vif,
511 					   value == LOW_LATENCY_FORCE_ON,
512 					   LOW_LATENCY_DEBUGFS_FORCE);
513 		iwl_mvm_update_low_latency(mvm, vif, true,
514 					   LOW_LATENCY_DEBUGFS_FORCE_ENABLE);
515 	}
516 	mutex_unlock(&mvm->mutex);
517 	return count;
518 }
519 
iwl_dbgfs_low_latency_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)520 static ssize_t iwl_dbgfs_low_latency_read(struct file *file,
521 					  char __user *user_buf,
522 					  size_t count, loff_t *ppos)
523 {
524 	struct ieee80211_vif *vif = file->private_data;
525 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
526 	char format[] = "traffic=%d\ndbgfs=%d\nvcmd=%d\nvif_type=%d\n"
527 			"dbgfs_force_enable=%d\ndbgfs_force=%d\nactual=%d\n";
528 
529 	/*
530 	 * all values in format are boolean so the size of format is enough
531 	 * for holding the result string
532 	 */
533 	char buf[sizeof(format) + 1] = {};
534 	int len;
535 
536 	len = scnprintf(buf, sizeof(buf) - 1, format,
537 			!!(mvmvif->low_latency & LOW_LATENCY_TRAFFIC),
538 			!!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS),
539 			!!(mvmvif->low_latency & LOW_LATENCY_VCMD),
540 			!!(mvmvif->low_latency & LOW_LATENCY_VIF_TYPE),
541 			!!(mvmvif->low_latency &
542 			   LOW_LATENCY_DEBUGFS_FORCE_ENABLE),
543 			!!(mvmvif->low_latency & LOW_LATENCY_DEBUGFS_FORCE),
544 			!!(mvmvif->low_latency_actual));
545 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
546 }
547 
iwl_dbgfs_uapsd_misbehaving_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)548 static ssize_t iwl_dbgfs_uapsd_misbehaving_read(struct file *file,
549 						char __user *user_buf,
550 						size_t count, loff_t *ppos)
551 {
552 	struct ieee80211_vif *vif = file->private_data;
553 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
554 	char buf[20];
555 	int len;
556 
557 	len = sprintf(buf, "%pM\n", mvmvif->uapsd_misbehaving_ap_addr);
558 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
559 }
560 
iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)561 static ssize_t iwl_dbgfs_uapsd_misbehaving_write(struct ieee80211_vif *vif,
562 						 char *buf, size_t count,
563 						 loff_t *ppos)
564 {
565 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
566 	struct iwl_mvm *mvm = mvmvif->mvm;
567 	bool ret;
568 
569 	mutex_lock(&mvm->mutex);
570 	ret = mac_pton(buf, mvmvif->uapsd_misbehaving_ap_addr);
571 	mutex_unlock(&mvm->mutex);
572 
573 	return ret ? count : -EINVAL;
574 }
575 
iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)576 static ssize_t iwl_dbgfs_rx_phyinfo_write(struct ieee80211_vif *vif, char *buf,
577 					  size_t count, loff_t *ppos)
578 {
579 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
580 	struct iwl_mvm *mvm = mvmvif->mvm;
581 	struct ieee80211_bss_conf *link_conf;
582 	u16 value;
583 	int link_id, ret = -EINVAL;
584 
585 	ret = kstrtou16(buf, 0, &value);
586 	if (ret)
587 		return ret;
588 
589 	mutex_lock(&mvm->mutex);
590 
591 	mvm->dbgfs_rx_phyinfo = value;
592 
593 	for_each_vif_active_link(vif, link_conf, link_id) {
594 		struct ieee80211_chanctx_conf *chanctx_conf;
595 		struct cfg80211_chan_def min_def, ap_def;
596 		struct iwl_mvm_phy_ctxt *phy_ctxt;
597 		u8 chains_static, chains_dynamic;
598 
599 		rcu_read_lock();
600 		chanctx_conf = rcu_dereference(link_conf->chanctx_conf);
601 		if (!chanctx_conf) {
602 			rcu_read_unlock();
603 			continue;
604 		}
605 		/* A command can't be sent with RCU lock held, so copy
606 		 * everything here and use it after unlocking
607 		 */
608 		min_def = chanctx_conf->min_def;
609 		ap_def = chanctx_conf->ap;
610 		chains_static = chanctx_conf->rx_chains_static;
611 		chains_dynamic = chanctx_conf->rx_chains_dynamic;
612 		rcu_read_unlock();
613 
614 		phy_ctxt = mvmvif->link[link_id]->phy_ctxt;
615 		if (!phy_ctxt)
616 			continue;
617 
618 		ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &min_def, &ap_def,
619 					       chains_static, chains_dynamic);
620 	}
621 
622 	mutex_unlock(&mvm->mutex);
623 
624 	return ret ?: count;
625 }
626 
iwl_dbgfs_rx_phyinfo_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)627 static ssize_t iwl_dbgfs_rx_phyinfo_read(struct file *file,
628 					 char __user *user_buf,
629 					 size_t count, loff_t *ppos)
630 {
631 	struct ieee80211_vif *vif = file->private_data;
632 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
633 	char buf[8];
634 	int len;
635 
636 	len = scnprintf(buf, sizeof(buf), "0x%04x\n",
637 			mvmvif->mvm->dbgfs_rx_phyinfo);
638 
639 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
640 }
641 
iwl_dbgfs_quota_check(void * data,u8 * mac,struct ieee80211_vif * vif)642 static void iwl_dbgfs_quota_check(void *data, u8 *mac,
643 				  struct ieee80211_vif *vif)
644 {
645 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
646 	int *ret = data;
647 
648 	if (mvmvif->dbgfs_quota_min)
649 		*ret = -EINVAL;
650 }
651 
iwl_dbgfs_quota_min_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)652 static ssize_t iwl_dbgfs_quota_min_write(struct ieee80211_vif *vif, char *buf,
653 					 size_t count, loff_t *ppos)
654 {
655 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
656 	struct iwl_mvm *mvm = mvmvif->mvm;
657 	u16 value;
658 	int ret;
659 
660 	ret = kstrtou16(buf, 0, &value);
661 	if (ret)
662 		return ret;
663 
664 	if (value > 95)
665 		return -EINVAL;
666 
667 	mutex_lock(&mvm->mutex);
668 
669 	mvmvif->dbgfs_quota_min = 0;
670 	ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
671 				     iwl_dbgfs_quota_check, &ret);
672 	if (ret == 0) {
673 		mvmvif->dbgfs_quota_min = value;
674 		iwl_mvm_update_quotas(mvm, false, NULL);
675 	}
676 	mutex_unlock(&mvm->mutex);
677 
678 	return ret ?: count;
679 }
680 
iwl_dbgfs_quota_min_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)681 static ssize_t iwl_dbgfs_quota_min_read(struct file *file,
682 					char __user *user_buf,
683 					size_t count, loff_t *ppos)
684 {
685 	struct ieee80211_vif *vif = file->private_data;
686 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
687 	char buf[10];
688 	int len;
689 
690 	len = scnprintf(buf, sizeof(buf), "%d\n", mvmvif->dbgfs_quota_min);
691 
692 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
693 }
694 
iwl_dbgfs_max_tx_op_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)695 static ssize_t iwl_dbgfs_max_tx_op_write(struct ieee80211_vif *vif, char *buf,
696 					 size_t count, loff_t *ppos)
697 {
698 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
699 	struct iwl_mvm *mvm = mvmvif->mvm;
700 	u16 value;
701 	int ret;
702 
703 	ret = kstrtou16(buf, 0, &value);
704 	if (ret)
705 		return ret;
706 
707 	mutex_lock(&mvm->mutex);
708 	mvmvif->max_tx_op = value;
709 	mutex_unlock(&mvm->mutex);
710 
711 	return count;
712 }
713 
iwl_dbgfs_max_tx_op_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)714 static ssize_t iwl_dbgfs_max_tx_op_read(struct file *file,
715 					char __user *user_buf,
716 					size_t count, loff_t *ppos)
717 {
718 	struct ieee80211_vif *vif = file->private_data;
719 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
720 	struct iwl_mvm *mvm = mvmvif->mvm;
721 	char buf[10];
722 	int len;
723 
724 	mutex_lock(&mvm->mutex);
725 	len = scnprintf(buf, sizeof(buf), "%hu\n", mvmvif->max_tx_op);
726 	mutex_unlock(&mvm->mutex);
727 
728 	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
729 }
730 
iwl_dbgfs_int_mlo_scan_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)731 static ssize_t iwl_dbgfs_int_mlo_scan_write(struct ieee80211_vif *vif,
732 					    char *buf, size_t count,
733 					    loff_t *ppos)
734 {
735 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
736 	struct iwl_mvm *mvm = mvmvif->mvm;
737 	u32 action;
738 	int ret;
739 
740 	if (!vif->cfg.assoc || !ieee80211_vif_is_mld(vif))
741 		return -EINVAL;
742 
743 	if (kstrtou32(buf, 0, &action))
744 		return -EINVAL;
745 
746 	mutex_lock(&mvm->mutex);
747 
748 	if (!action) {
749 		ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_INT_MLO, false);
750 	} else if (action == 1) {
751 		ret = iwl_mvm_int_mlo_scan(mvm, vif);
752 	} else {
753 		ret = -EINVAL;
754 	}
755 
756 	mutex_unlock(&mvm->mutex);
757 
758 	return ret ?: count;
759 }
760 
iwl_dbgfs_esr_disable_reason_read(struct file * file,char __user * user_buf,size_t count,loff_t * ppos)761 static ssize_t iwl_dbgfs_esr_disable_reason_read(struct file *file,
762 						 char __user *user_buf,
763 						 size_t count, loff_t *ppos)
764 {
765 	struct ieee80211_vif *vif = file->private_data;
766 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
767 	struct iwl_mvm *mvm = mvmvif->mvm;
768 	unsigned long esr_mask;
769 	char *buf;
770 	int bufsz, pos, i;
771 	ssize_t rv;
772 
773 	mutex_lock(&mvm->mutex);
774 	esr_mask = mvmvif->esr_disable_reason;
775 	mutex_unlock(&mvm->mutex);
776 
777 	bufsz = hweight32(esr_mask) * 32 + 40;
778 	buf = kmalloc(bufsz, GFP_KERNEL);
779 	if (!buf)
780 		return -ENOMEM;
781 
782 	pos = scnprintf(buf, bufsz, "EMLSR state: '0x%lx'\nreasons:\n",
783 			esr_mask);
784 	for_each_set_bit(i, &esr_mask, BITS_PER_LONG)
785 		pos += scnprintf(buf + pos, bufsz - pos, " - %s\n",
786 				 iwl_get_esr_state_string(BIT(i)));
787 
788 	rv = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
789 	kfree(buf);
790 	return rv;
791 }
792 
iwl_dbgfs_esr_disable_reason_write(struct ieee80211_vif * vif,char * buf,size_t count,loff_t * ppos)793 static ssize_t iwl_dbgfs_esr_disable_reason_write(struct ieee80211_vif *vif,
794 						  char *buf, size_t count,
795 						  loff_t *ppos)
796 {
797 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
798 	struct iwl_mvm *mvm = mvmvif->mvm;
799 	u32 reason;
800 	u8 block;
801 	int ret;
802 
803 	ret = sscanf(buf, "%u %hhu", &reason, &block);
804 	if (ret < 0)
805 		return ret;
806 
807 	if (hweight16(reason) != 1 || !(reason & IWL_MVM_BLOCK_ESR_REASONS))
808 		return -EINVAL;
809 
810 	mutex_lock(&mvm->mutex);
811 	if (block)
812 		iwl_mvm_block_esr(mvm, vif, reason,
813 				  iwl_mvm_get_primary_link(vif));
814 	else
815 		iwl_mvm_unblock_esr(mvm, vif, reason);
816 	mutex_unlock(&mvm->mutex);
817 
818 	return count;
819 }
820 
821 #define MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz) \
822 	_MVM_DEBUGFS_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
823 #define MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz) \
824 	_MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)
825 #define MVM_DEBUGFS_ADD_FILE_VIF(name, parent, mode) do {		\
826 		debugfs_create_file(#name, mode, parent, vif,		\
827 				    &iwl_dbgfs_##name##_ops);		\
828 	} while (0)
829 
830 MVM_DEBUGFS_READ_FILE_OPS(mac_params);
831 MVM_DEBUGFS_READ_FILE_OPS(tx_pwr_lmt);
832 MVM_DEBUGFS_READ_WRITE_FILE_OPS(pm_params, 32);
833 MVM_DEBUGFS_READ_WRITE_FILE_OPS(bf_params, 256);
834 MVM_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 10);
835 MVM_DEBUGFS_WRITE_FILE_OPS(low_latency_force, 10);
836 MVM_DEBUGFS_READ_WRITE_FILE_OPS(uapsd_misbehaving, 20);
837 MVM_DEBUGFS_READ_WRITE_FILE_OPS(rx_phyinfo, 10);
838 MVM_DEBUGFS_READ_WRITE_FILE_OPS(quota_min, 32);
839 MVM_DEBUGFS_READ_FILE_OPS(os_device_timediff);
840 MVM_DEBUGFS_READ_WRITE_FILE_OPS(max_tx_op, 10);
841 MVM_DEBUGFS_WRITE_FILE_OPS(int_mlo_scan, 32);
842 MVM_DEBUGFS_READ_WRITE_FILE_OPS(esr_disable_reason, 32);
843 
iwl_mvm_vif_add_debugfs(struct ieee80211_hw * hw,struct ieee80211_vif * vif)844 void iwl_mvm_vif_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
845 {
846 	struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
847 	struct dentry *dbgfs_dir = vif->debugfs_dir;
848 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
849 
850 	mvmvif->dbgfs_dir = debugfs_create_dir("iwlmvm", dbgfs_dir);
851 	if (IS_ERR_OR_NULL(mvmvif->dbgfs_dir)) {
852 		IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
853 			dbgfs_dir);
854 		return;
855 	}
856 
857 	if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
858 	    ((vif->type == NL80211_IFTYPE_STATION && !vif->p2p) ||
859 	     (vif->type == NL80211_IFTYPE_STATION && vif->p2p)))
860 		MVM_DEBUGFS_ADD_FILE_VIF(pm_params, mvmvif->dbgfs_dir, 0600);
861 
862 	MVM_DEBUGFS_ADD_FILE_VIF(tx_pwr_lmt, mvmvif->dbgfs_dir, 0400);
863 	MVM_DEBUGFS_ADD_FILE_VIF(mac_params, mvmvif->dbgfs_dir, 0400);
864 	MVM_DEBUGFS_ADD_FILE_VIF(low_latency, mvmvif->dbgfs_dir, 0600);
865 	MVM_DEBUGFS_ADD_FILE_VIF(low_latency_force, mvmvif->dbgfs_dir, 0600);
866 	MVM_DEBUGFS_ADD_FILE_VIF(uapsd_misbehaving, mvmvif->dbgfs_dir, 0600);
867 	MVM_DEBUGFS_ADD_FILE_VIF(rx_phyinfo, mvmvif->dbgfs_dir, 0600);
868 	MVM_DEBUGFS_ADD_FILE_VIF(quota_min, mvmvif->dbgfs_dir, 0600);
869 	MVM_DEBUGFS_ADD_FILE_VIF(os_device_timediff, mvmvif->dbgfs_dir, 0400);
870 	MVM_DEBUGFS_ADD_FILE_VIF(max_tx_op, mvmvif->dbgfs_dir, 0600);
871 	debugfs_create_bool("ftm_unprotected", 0200, mvmvif->dbgfs_dir,
872 			    &mvmvif->ftm_unprotected);
873 	MVM_DEBUGFS_ADD_FILE_VIF(int_mlo_scan, mvmvif->dbgfs_dir, 0200);
874 	MVM_DEBUGFS_ADD_FILE_VIF(esr_disable_reason, mvmvif->dbgfs_dir, 0600);
875 
876 	if (vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
877 	    mvmvif == mvm->bf_allowed_vif)
878 		MVM_DEBUGFS_ADD_FILE_VIF(bf_params, mvmvif->dbgfs_dir, 0600);
879 }
880 
iwl_mvm_vif_dbgfs_add_link(struct iwl_mvm * mvm,struct ieee80211_vif * vif)881 void iwl_mvm_vif_dbgfs_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
882 {
883 	struct dentry *dbgfs_dir = vif->debugfs_dir;
884 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
885 	char buf[3 * 3 + 11 + (NL80211_WIPHY_NAME_MAXLEN + 1) +
886 		 (7 + IFNAMSIZ + 1) + 6 + 1];
887 	char name[7 + IFNAMSIZ + 1];
888 
889 	/* this will happen in monitor mode */
890 	if (!dbgfs_dir)
891 		return;
892 
893 	/*
894 	 * Create symlink for convenience pointing to interface specific
895 	 * debugfs entries for the driver. For example, under
896 	 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmvm/
897 	 * find
898 	 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmvm/
899 	 */
900 	snprintf(name, sizeof(name), "%pd", dbgfs_dir);
901 	snprintf(buf, sizeof(buf), "../../../%pd3/iwlmvm", dbgfs_dir);
902 
903 	mvmvif->dbgfs_slink =
904 		debugfs_create_symlink(name, mvm->debugfs_dir, buf);
905 }
906 
iwl_mvm_vif_dbgfs_rm_link(struct iwl_mvm * mvm,struct ieee80211_vif * vif)907 void iwl_mvm_vif_dbgfs_rm_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
908 {
909 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
910 
911 	debugfs_remove(mvmvif->dbgfs_slink);
912 	mvmvif->dbgfs_slink = NULL;
913 }
914 
915 #define MVM_DEBUGFS_WRITE_LINK_FILE_OPS(name, bufsz)			\
916 	_MVM_DEBUGFS_WRITE_FILE_OPS(link_##name, bufsz,			\
917 				    struct ieee80211_bss_conf)
918 #define MVM_DEBUGFS_READ_WRITE_LINK_FILE_OPS(name, bufsz)		\
919 	_MVM_DEBUGFS_READ_WRITE_FILE_OPS(link_##name, bufsz,		\
920 					 struct ieee80211_bss_conf)
921 #define MVM_DEBUGFS_ADD_LINK_FILE(name, parent, mode)			\
922 	debugfs_create_file(#name, mode, parent, link_conf,		\
923 			    &iwl_dbgfs_link_##name##_ops)
924 
iwl_mvm_debugfs_add_link_files(struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct dentry * mvm_dir)925 static void iwl_mvm_debugfs_add_link_files(struct ieee80211_vif *vif,
926 					   struct ieee80211_bss_conf *link_conf,
927 					   struct dentry *mvm_dir)
928 {
929 	/* Add per-link files here*/
930 }
931 
iwl_mvm_link_add_debugfs(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct dentry * dir)932 void iwl_mvm_link_add_debugfs(struct ieee80211_hw *hw,
933 			      struct ieee80211_vif *vif,
934 			      struct ieee80211_bss_conf *link_conf,
935 			      struct dentry *dir)
936 {
937 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
938 	struct iwl_mvm *mvm = mvmvif->mvm;
939 	unsigned int link_id = link_conf->link_id;
940 	struct iwl_mvm_vif_link_info *link_info = mvmvif->link[link_id];
941 	struct dentry *mvm_dir;
942 
943 	if (WARN_ON(!link_info) || !dir)
944 		return;
945 
946 	if (dir == vif->debugfs_dir) {
947 		WARN_ON(!mvmvif->dbgfs_dir);
948 		mvm_dir = mvmvif->dbgfs_dir;
949 	} else {
950 		mvm_dir = debugfs_create_dir("iwlmvm", dir);
951 		if (IS_ERR_OR_NULL(mvm_dir)) {
952 			IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
953 				dir);
954 			return;
955 		}
956 	}
957 
958 	iwl_mvm_debugfs_add_link_files(vif, link_conf, mvm_dir);
959 }
960