xref: /linux/drivers/net/wireless/intel/iwlwifi/mld/debugfs.c (revision 1a9239bb4253f9076b5b4b2a1a4e8d7defd77a95)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2024-2025 Intel Corporation
4  */
5 
6 #include "mld.h"
7 #include "debugfs.h"
8 #include "iwl-io.h"
9 #include "hcmd.h"
10 #include "iface.h"
11 #include "sta.h"
12 #include "tlc.h"
13 #include "power.h"
14 #include "notif.h"
15 #include "ap.h"
16 #include "iwl-utils.h"
17 #include "scan.h"
18 #ifdef CONFIG_THERMAL
19 #include "thermal.h"
20 #endif
21 
22 #include "fw/api/rs.h"
23 #include "fw/api/dhc.h"
24 #include "fw/api/rfi.h"
25 #include "fw/dhc-utils.h"
26 #include <linux/dmi.h>
27 
28 #define MLD_DEBUGFS_READ_FILE_OPS(name, bufsz)				\
29 	_MLD_DEBUGFS_READ_FILE_OPS(name, bufsz, struct iwl_mld)
30 
31 #define MLD_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode)		\
32 	debugfs_create_file(alias, mode, parent, mld,			\
33 			    &iwl_dbgfs_##name##_ops)
34 #define MLD_DEBUGFS_ADD_FILE(name, parent, mode)			\
35 	MLD_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
36 
iwl_mld_dbgfs_fw_cmd_disabled(struct iwl_mld * mld)37 static bool iwl_mld_dbgfs_fw_cmd_disabled(struct iwl_mld *mld)
38 {
39 #ifdef CONFIG_PM_SLEEP
40 	return !mld->fw_status.running || mld->fw_status.in_d3;
41 #else
42 	return !mld->fw_status.running;
43 #endif /* CONFIG_PM_SLEEP */
44 }
45 
iwl_dbgfs_fw_dbg_clear_write(struct iwl_mld * mld,char * buf,size_t count)46 static ssize_t iwl_dbgfs_fw_dbg_clear_write(struct iwl_mld *mld,
47 					    char *buf, size_t count)
48 {
49 	/* If the firmware is not running, silently succeed since there is
50 	 * no data to clear.
51 	 */
52 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
53 		return 0;
54 
55 	iwl_fw_dbg_clear_monitor_buf(&mld->fwrt);
56 
57 	return count;
58 }
59 
iwl_dbgfs_fw_nmi_write(struct iwl_mld * mld,char * buf,size_t count)60 static ssize_t iwl_dbgfs_fw_nmi_write(struct iwl_mld *mld, char *buf,
61 				      size_t count)
62 {
63 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
64 		return -EIO;
65 
66 	IWL_ERR(mld, "Triggering an NMI from debugfs\n");
67 
68 	if (count == 6 && !strcmp(buf, "nolog\n"))
69 		mld->fw_status.do_not_dump_once = true;
70 
71 	iwl_force_nmi(mld->trans);
72 
73 	return count;
74 }
75 
iwl_dbgfs_fw_restart_write(struct iwl_mld * mld,char * buf,size_t count)76 static ssize_t iwl_dbgfs_fw_restart_write(struct iwl_mld *mld, char *buf,
77 					  size_t count)
78 {
79 	int __maybe_unused ret;
80 
81 	if (!iwlwifi_mod_params.fw_restart)
82 		return -EPERM;
83 
84 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
85 		return -EIO;
86 
87 	if (count == 6 && !strcmp(buf, "nolog\n")) {
88 		mld->fw_status.do_not_dump_once = true;
89 		set_bit(STATUS_SUPPRESS_CMD_ERROR_ONCE, &mld->trans->status);
90 	}
91 
92 	/* take the return value to make compiler happy - it will
93 	 * fail anyway
94 	 */
95 	ret = iwl_mld_send_cmd_empty(mld, WIDE_ID(LONG_GROUP, REPLY_ERROR));
96 
97 	return count;
98 }
99 
iwl_dbgfs_send_echo_cmd_write(struct iwl_mld * mld,char * buf,size_t count)100 static ssize_t iwl_dbgfs_send_echo_cmd_write(struct iwl_mld *mld, char *buf,
101 					     size_t count)
102 {
103 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
104 		return -EIO;
105 
106 	return iwl_mld_send_cmd_empty(mld, ECHO_CMD) ?: count;
107 }
108 
109 struct iwl_mld_sniffer_apply {
110 	struct iwl_mld *mld;
111 	const u8 *bssid;
112 	u16 aid;
113 };
114 
iwl_mld_sniffer_apply(struct iwl_notif_wait_data * notif_data,struct iwl_rx_packet * pkt,void * data)115 static bool iwl_mld_sniffer_apply(struct iwl_notif_wait_data *notif_data,
116 				  struct iwl_rx_packet *pkt, void *data)
117 {
118 	struct iwl_mld_sniffer_apply *apply = data;
119 
120 	apply->mld->monitor.cur_aid = cpu_to_le16(apply->aid);
121 	memcpy(apply->mld->monitor.cur_bssid, apply->bssid,
122 	       sizeof(apply->mld->monitor.cur_bssid));
123 
124 	return true;
125 }
126 
127 static ssize_t
iwl_dbgfs_he_sniffer_params_write(struct iwl_mld * mld,char * buf,size_t count)128 iwl_dbgfs_he_sniffer_params_write(struct iwl_mld *mld, char *buf,
129 				  size_t count)
130 {
131 	struct iwl_notification_wait wait;
132 	struct iwl_he_monitor_cmd he_mon_cmd = {};
133 	struct iwl_mld_sniffer_apply apply = {
134 		.mld = mld,
135 	};
136 	u16 wait_cmds[] = {
137 		WIDE_ID(DATA_PATH_GROUP, HE_AIR_SNIFFER_CONFIG_CMD),
138 	};
139 	u32 aid;
140 	int ret;
141 
142 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
143 		return -EIO;
144 
145 	if (!mld->monitor.on)
146 		return -ENODEV;
147 
148 	ret = sscanf(buf, "%x %2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", &aid,
149 		     &he_mon_cmd.bssid[0], &he_mon_cmd.bssid[1],
150 		     &he_mon_cmd.bssid[2], &he_mon_cmd.bssid[3],
151 		     &he_mon_cmd.bssid[4], &he_mon_cmd.bssid[5]);
152 	if (ret != 7)
153 		return -EINVAL;
154 
155 	he_mon_cmd.aid = cpu_to_le16(aid);
156 
157 	apply.aid = aid;
158 	apply.bssid = (void *)he_mon_cmd.bssid;
159 
160 	/* Use the notification waiter to get our function triggered
161 	 * in sequence with other RX. This ensures that frames we get
162 	 * on the RX queue _before_ the new configuration is applied
163 	 * still have mld->cur_aid pointing to the old AID, and that
164 	 * frames on the RX queue _after_ the firmware processed the
165 	 * new configuration (and sent the response, synchronously)
166 	 * get mld->cur_aid correctly set to the new AID.
167 	 */
168 	iwl_init_notification_wait(&mld->notif_wait, &wait,
169 				   wait_cmds, ARRAY_SIZE(wait_cmds),
170 				   iwl_mld_sniffer_apply, &apply);
171 
172 	ret = iwl_mld_send_cmd_pdu(mld,
173 				   WIDE_ID(DATA_PATH_GROUP,
174 					   HE_AIR_SNIFFER_CONFIG_CMD),
175 				   &he_mon_cmd);
176 
177 	/* no need to really wait, we already did anyway */
178 	iwl_remove_notification(&mld->notif_wait, &wait);
179 
180 	return ret ?: count;
181 }
182 
183 static ssize_t
iwl_dbgfs_he_sniffer_params_read(struct iwl_mld * mld,char * buf,size_t count)184 iwl_dbgfs_he_sniffer_params_read(struct iwl_mld *mld, char *buf, size_t count)
185 {
186 	return scnprintf(buf, count,
187 			 "%d %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
188 			 le16_to_cpu(mld->monitor.cur_aid),
189 			 mld->monitor.cur_bssid[0], mld->monitor.cur_bssid[1],
190 			 mld->monitor.cur_bssid[2], mld->monitor.cur_bssid[3],
191 			 mld->monitor.cur_bssid[4], mld->monitor.cur_bssid[5]);
192 }
193 
194 /* The size computation is as follows:
195  * each number needs at most 3 characters, number of rows is the size of
196  * the table; So, need 5 chars for the "freq: " part and each tuple afterwards
197  * needs 6 characters for numbers and 5 for the punctuation around. 32 bytes
198  * for feature support message.
199  */
200 #define IWL_RFI_DDR_BUF_SIZE (IWL_RFI_DDR_LUT_INSTALLED_SIZE *\
201 				(5 + IWL_RFI_DDR_LUT_ENTRY_CHANNELS_NUM *\
202 					(6 + 5)) + 32)
203 #define IWL_RFI_DLVR_BUF_SIZE (IWL_RFI_DLVR_LUT_INSTALLED_SIZE *\
204 				(5 + IWL_RFI_DLVR_LUT_ENTRY_CHANNELS_NUM *\
205 					(6 + 5)) + 32)
206 #define IWL_RFI_DESENSE_BUF_SIZE IWL_RFI_DDR_BUF_SIZE
207 
208 /* Extra 32 for "DDR and DLVR table" message */
209 #define IWL_RFI_BUF_SIZE (IWL_RFI_DDR_BUF_SIZE + IWL_RFI_DLVR_BUF_SIZE +\
210 				IWL_RFI_DESENSE_BUF_SIZE + 32)
211 
iwl_mld_dump_tas_resp(struct iwl_dhc_tas_status_resp * resp,size_t count,u8 * buf)212 static size_t iwl_mld_dump_tas_resp(struct iwl_dhc_tas_status_resp *resp,
213 				    size_t count, u8 *buf)
214 {
215 	const char * const tas_dis_reason[TAS_DISABLED_REASON_MAX] = {
216 		[TAS_DISABLED_DUE_TO_BIOS] =
217 			"Due To BIOS",
218 		[TAS_DISABLED_DUE_TO_SAR_6DBM] =
219 			"Due To SAR Limit Less Than 6 dBm",
220 		[TAS_DISABLED_REASON_INVALID] =
221 			"N/A",
222 		[TAS_DISABLED_DUE_TO_TABLE_SOURCE_INVALID] =
223 			"Due to table source invalid"
224 	};
225 	const char * const tas_current_status[TAS_DYNA_STATUS_MAX] = {
226 		[TAS_DYNA_INACTIVE] = "INACTIVE",
227 		[TAS_DYNA_INACTIVE_MVM_MODE] =
228 			"inactive due to mvm mode",
229 		[TAS_DYNA_INACTIVE_TRIGGER_MODE] =
230 			"inactive due to trigger mode",
231 		[TAS_DYNA_INACTIVE_BLOCK_LISTED] =
232 			"inactive due to block listed",
233 		[TAS_DYNA_INACTIVE_UHB_NON_US] =
234 			"inactive due to uhb non US",
235 		[TAS_DYNA_ACTIVE] = "ACTIVE",
236 	};
237 	ssize_t pos = 0;
238 
239 	if (resp->header.version != 1) {
240 		pos += scnprintf(buf + pos, count - pos,
241 				 "Unsupported TAS response version:%d",
242 				 resp->header.version);
243 		return pos;
244 	}
245 
246 	pos += scnprintf(buf + pos, count - pos, "TAS Report\n");
247 	switch (resp->tas_config_info.table_source) {
248 	case BIOS_SOURCE_NONE:
249 		pos += scnprintf(buf + pos, count - pos,
250 				 "BIOS SOURCE NONE ");
251 		break;
252 	case BIOS_SOURCE_ACPI:
253 		pos += scnprintf(buf + pos, count - pos,
254 				 "BIOS SOURCE ACPI ");
255 		break;
256 	case BIOS_SOURCE_UEFI:
257 		pos += scnprintf(buf + pos, count - pos,
258 				 "BIOS SOURCE UEFI ");
259 		break;
260 	default:
261 		pos += scnprintf(buf + pos, count - pos,
262 				 "BIOS SOURCE UNKNOWN (%d) ",
263 				 resp->tas_config_info.table_source);
264 		break;
265 	}
266 
267 	pos += scnprintf(buf + pos, count - pos,
268 			 "revision is: %d data is: 0x%08x\n",
269 			 resp->tas_config_info.table_revision,
270 			 resp->tas_config_info.value);
271 	pos += scnprintf(buf + pos, count - pos, "Current MCC: 0x%x\n",
272 			 le16_to_cpu(resp->curr_mcc));
273 
274 	pos += scnprintf(buf + pos, count - pos, "Block list entries:");
275 	for (int i = 0; i < ARRAY_SIZE(resp->mcc_block_list); i++)
276 		pos += scnprintf(buf + pos, count - pos, " 0x%x",
277 				 le16_to_cpu(resp->mcc_block_list[i]));
278 
279 	pos += scnprintf(buf + pos, count - pos,
280 			 "\nDo TAS Support Dual Radio?: %s\n",
281 			 hweight8(resp->valid_radio_mask) > 1 ?
282 			 "TRUE" : "FALSE");
283 
284 	for (int i = 0; i < ARRAY_SIZE(resp->tas_status_radio); i++) {
285 		int tmp;
286 		unsigned long dynamic_status;
287 
288 		if (!(resp->valid_radio_mask & BIT(i)))
289 			continue;
290 
291 		pos += scnprintf(buf + pos, count - pos,
292 				 "TAS report for radio:%d\n", i + 1);
293 		pos += scnprintf(buf + pos, count - pos,
294 				 "Static status: %sabled\n",
295 				 resp->tas_status_radio[i].static_status ?
296 				 "En" : "Dis");
297 		if (!resp->tas_status_radio[i].static_status) {
298 			u8 static_disable_reason =
299 				resp->tas_status_radio[i].static_disable_reason;
300 
301 			pos += scnprintf(buf + pos, count - pos,
302 					 "\tStatic Disabled Reason: ");
303 			if (static_disable_reason >= TAS_DISABLED_REASON_MAX) {
304 				pos += scnprintf(buf + pos, count - pos,
305 						 "unsupported value (%d)\n",
306 						 static_disable_reason);
307 				continue;
308 			}
309 
310 			pos += scnprintf(buf + pos, count - pos,
311 					 "%s (%d)\n",
312 					 tas_dis_reason[static_disable_reason],
313 					 static_disable_reason);
314 			continue;
315 		}
316 
317 		pos += scnprintf(buf + pos, count - pos, "\tANT A %s and ",
318 				 (resp->tas_status_radio[i].dynamic_status_ant_a
319 				  & BIT(TAS_DYNA_ACTIVE)) ? "ON" : "OFF");
320 
321 		pos += scnprintf(buf + pos, count - pos, "ANT B %s for ",
322 				 (resp->tas_status_radio[i].dynamic_status_ant_b
323 				  & BIT(TAS_DYNA_ACTIVE)) ? "ON" : "OFF");
324 
325 		switch (resp->tas_status_radio[i].band) {
326 		case PHY_BAND_5:
327 			pos += scnprintf(buf + pos, count - pos, "HB\n");
328 			break;
329 		case PHY_BAND_24:
330 			pos += scnprintf(buf + pos, count - pos, "LB\n");
331 			break;
332 		case PHY_BAND_6:
333 			pos += scnprintf(buf + pos, count - pos, "UHB\n");
334 			break;
335 		default:
336 			pos += scnprintf(buf + pos, count - pos,
337 					 "Unsupported band (%d)\n",
338 					 resp->tas_status_radio[i].band);
339 			break;
340 		}
341 
342 		pos += scnprintf(buf + pos, count - pos,
343 				 "Is near disconnection?: %s\n",
344 				 resp->tas_status_radio[i].near_disconnection ?
345 				 "True" : "False");
346 
347 		pos += scnprintf(buf + pos, count - pos,
348 				 "Dynamic status antenna A:\n");
349 		dynamic_status = resp->tas_status_radio[i].dynamic_status_ant_a;
350 		for_each_set_bit(tmp, &dynamic_status, TAS_DYNA_STATUS_MAX) {
351 			pos += scnprintf(buf + pos, count - pos, "\t%s (%d)\n",
352 					 tas_current_status[tmp], tmp);
353 		}
354 		pos += scnprintf(buf + pos, count - pos,
355 				 "\nDynamic status antenna B:\n");
356 		dynamic_status = resp->tas_status_radio[i].dynamic_status_ant_b;
357 		for_each_set_bit(tmp, &dynamic_status, TAS_DYNA_STATUS_MAX) {
358 			pos += scnprintf(buf + pos, count - pos, "\t%s (%d)\n",
359 					 tas_current_status[tmp], tmp);
360 		}
361 
362 		tmp = le16_to_cpu(resp->tas_status_radio[i].max_reg_pwr_limit_ant_a);
363 		pos += scnprintf(buf + pos, count - pos,
364 				 "Max antenna A regulatory pwr limit (dBm): %d.%03d\n",
365 				 tmp / 8, 125 * (tmp % 8));
366 		tmp = le16_to_cpu(resp->tas_status_radio[i].max_reg_pwr_limit_ant_b);
367 		pos += scnprintf(buf + pos, count - pos,
368 				 "Max antenna B regulatory pwr limit (dBm): %d.%03d\n",
369 				 tmp / 8, 125 * (tmp % 8));
370 
371 		tmp = le16_to_cpu(resp->tas_status_radio[i].sar_limit_ant_a);
372 		pos += scnprintf(buf + pos, count - pos,
373 				 "Antenna A SAR limit (dBm): %d.%03d\n",
374 				 tmp / 8, 125 * (tmp % 8));
375 		tmp = le16_to_cpu(resp->tas_status_radio[i].sar_limit_ant_b);
376 		pos += scnprintf(buf + pos, count - pos,
377 				 "Antenna B SAR limit (dBm): %d.%03d\n",
378 				 tmp / 8, 125 * (tmp % 8));
379 	}
380 
381 	return pos;
382 }
383 
iwl_dbgfs_tas_get_status_read(struct iwl_mld * mld,char * buf,size_t count)384 static ssize_t iwl_dbgfs_tas_get_status_read(struct iwl_mld *mld, char *buf,
385 					     size_t count)
386 {
387 	struct iwl_dhc_cmd cmd = {
388 		.index_and_mask = cpu_to_le32(DHC_TABLE_TOOLS |
389 					      DHC_TARGET_UMAC |
390 					      DHC_TOOLS_UMAC_GET_TAS_STATUS),
391 	};
392 	struct iwl_host_cmd hcmd = {
393 		.id = WIDE_ID(LEGACY_GROUP, DEBUG_HOST_COMMAND),
394 		.flags = CMD_WANT_SKB,
395 		.len[0] = sizeof(cmd),
396 		.data[0] = &cmd,
397 	};
398 	struct iwl_dhc_tas_status_resp *resp = NULL;
399 	ssize_t pos = 0;
400 	u32 resp_len;
401 	u32 status;
402 	int ret;
403 
404 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
405 		return -EIO;
406 
407 	ret = iwl_mld_send_cmd(mld, &hcmd);
408 	if (ret)
409 		return ret;
410 
411 	pos += scnprintf(buf + pos, count - pos, "\nOEM name: %s\n",
412 			 dmi_get_system_info(DMI_SYS_VENDOR) ?: "<unknown>");
413 	pos += scnprintf(buf + pos, count - pos,
414 			 "\tVendor In Approved List: %s\n",
415 			 iwl_is_tas_approved() ? "YES" : "NO");
416 
417 	status = iwl_dhc_resp_status(mld->fwrt.fw, hcmd.resp_pkt);
418 	if (status != 1) {
419 		pos += scnprintf(buf + pos, count - pos,
420 				 "response status is not success: %d\n",
421 				 status);
422 		goto out;
423 	}
424 
425 	resp = iwl_dhc_resp_data(mld->fwrt.fw, hcmd.resp_pkt, &resp_len);
426 	if (IS_ERR(resp) || resp_len != sizeof(*resp)) {
427 		pos += scnprintf(buf + pos, count - pos,
428 			"Invalid size for TAS response (%u instead of %zd)\n",
429 			resp_len, sizeof(*resp));
430 		goto out;
431 	}
432 
433 	pos += iwl_mld_dump_tas_resp(resp, count - pos, buf + pos);
434 
435 out:
436 	iwl_free_resp(&hcmd);
437 	return pos;
438 }
439 
440 WIPHY_DEBUGFS_WRITE_FILE_OPS_MLD(fw_nmi, 10);
441 WIPHY_DEBUGFS_WRITE_FILE_OPS_MLD(fw_restart, 10);
442 WIPHY_DEBUGFS_READ_WRITE_FILE_OPS_MLD(he_sniffer_params, 32);
443 WIPHY_DEBUGFS_WRITE_FILE_OPS_MLD(fw_dbg_clear, 10);
444 WIPHY_DEBUGFS_WRITE_FILE_OPS_MLD(send_echo_cmd, 8);
445 WIPHY_DEBUGFS_READ_FILE_OPS_MLD(tas_get_status, 2048);
446 
iwl_dbgfs_wifi_6e_enable_read(struct iwl_mld * mld,size_t count,u8 * buf)447 static ssize_t iwl_dbgfs_wifi_6e_enable_read(struct iwl_mld *mld,
448 					     size_t count, u8 *buf)
449 {
450 	int err;
451 	u32 value;
452 
453 	err = iwl_bios_get_dsm(&mld->fwrt, DSM_FUNC_ENABLE_6E, &value);
454 	if (err)
455 		return err;
456 
457 	return scnprintf(buf, count, "0x%08x\n", value);
458 }
459 
460 MLD_DEBUGFS_READ_FILE_OPS(wifi_6e_enable, 64);
461 
iwl_dbgfs_inject_packet_write(struct iwl_mld * mld,char * buf,size_t count)462 static ssize_t iwl_dbgfs_inject_packet_write(struct iwl_mld *mld,
463 					     char *buf, size_t count)
464 {
465 	struct iwl_op_mode *opmode = container_of((void *)mld,
466 						  struct iwl_op_mode,
467 						  op_mode_specific);
468 	struct iwl_rx_cmd_buffer rxb = {};
469 	struct iwl_rx_packet *pkt;
470 	int n_bytes = count / 2;
471 	int ret = -EINVAL;
472 
473 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
474 		return -EIO;
475 
476 	rxb._page = alloc_pages(GFP_KERNEL, 0);
477 	if (!rxb._page)
478 		return -ENOMEM;
479 	pkt = rxb_addr(&rxb);
480 
481 	ret = hex2bin(page_address(rxb._page), buf, n_bytes);
482 	if (ret)
483 		goto out;
484 
485 	/* avoid invalid memory access and malformed packet */
486 	if (n_bytes < sizeof(*pkt) ||
487 	    n_bytes != sizeof(*pkt) + iwl_rx_packet_payload_len(pkt))
488 		goto out;
489 
490 	local_bh_disable();
491 	iwl_mld_rx(opmode, NULL, &rxb);
492 	local_bh_enable();
493 	ret = 0;
494 
495 out:
496 	iwl_free_rxb(&rxb);
497 
498 	return ret ?: count;
499 }
500 
501 WIPHY_DEBUGFS_WRITE_FILE_OPS_MLD(inject_packet, 512);
502 
503 #ifdef CONFIG_THERMAL
504 
iwl_dbgfs_stop_ctdp_write(struct iwl_mld * mld,char * buf,size_t count)505 static ssize_t iwl_dbgfs_stop_ctdp_write(struct iwl_mld *mld,
506 					 char *buf, size_t count)
507 {
508 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
509 		return -EIO;
510 
511 	return iwl_mld_config_ctdp(mld, mld->cooling_dev.cur_state,
512 				   CTDP_CMD_OPERATION_STOP) ? : count;
513 }
514 
515 WIPHY_DEBUGFS_WRITE_FILE_OPS_MLD(stop_ctdp, 8);
516 
iwl_dbgfs_start_ctdp_write(struct iwl_mld * mld,char * buf,size_t count)517 static ssize_t iwl_dbgfs_start_ctdp_write(struct iwl_mld *mld,
518 					  char *buf, size_t count)
519 {
520 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
521 		return -EIO;
522 
523 	return iwl_mld_config_ctdp(mld, mld->cooling_dev.cur_state,
524 				   CTDP_CMD_OPERATION_START) ? : count;
525 }
526 
527 WIPHY_DEBUGFS_WRITE_FILE_OPS_MLD(start_ctdp, 8);
528 
529 #endif /* CONFIG_THERMAL */
530 
531 void
iwl_mld_add_debugfs_files(struct iwl_mld * mld,struct dentry * debugfs_dir)532 iwl_mld_add_debugfs_files(struct iwl_mld *mld, struct dentry *debugfs_dir)
533 {
534 	/* Add debugfs files here */
535 
536 	MLD_DEBUGFS_ADD_FILE(fw_nmi, debugfs_dir, 0200);
537 	MLD_DEBUGFS_ADD_FILE(fw_restart, debugfs_dir, 0200);
538 	MLD_DEBUGFS_ADD_FILE(wifi_6e_enable, debugfs_dir, 0400);
539 	MLD_DEBUGFS_ADD_FILE(he_sniffer_params, debugfs_dir, 0600);
540 	MLD_DEBUGFS_ADD_FILE(fw_dbg_clear, debugfs_dir, 0200);
541 	MLD_DEBUGFS_ADD_FILE(send_echo_cmd, debugfs_dir, 0200);
542 	MLD_DEBUGFS_ADD_FILE(tas_get_status, debugfs_dir, 0400);
543 #ifdef CONFIG_THERMAL
544 	MLD_DEBUGFS_ADD_FILE(start_ctdp, debugfs_dir, 0200);
545 	MLD_DEBUGFS_ADD_FILE(stop_ctdp, debugfs_dir, 0200);
546 #endif
547 	MLD_DEBUGFS_ADD_FILE(inject_packet, debugfs_dir, 0200);
548 
549 	/* Create a symlink with mac80211. It will be removed when mac80211
550 	 * exits (before the opmode exits which removes the target.)
551 	 */
552 	if (!IS_ERR(debugfs_dir)) {
553 		char buf[100];
554 
555 		snprintf(buf, 100, "../../%pd2", debugfs_dir->d_parent);
556 		debugfs_create_symlink("iwlwifi", mld->wiphy->debugfsdir,
557 				       buf);
558 	}
559 }
560 
561 #define VIF_DEBUGFS_WRITE_FILE_OPS(name, bufsz)			\
562 	WIPHY_DEBUGFS_WRITE_FILE_OPS(vif_##name, bufsz, vif)
563 
564 #define VIF_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz)			    \
565 	IEEE80211_WIPHY_DEBUGFS_READ_WRITE_FILE_OPS(vif_##name, bufsz, vif) \
566 
567 #define VIF_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode)	\
568 	debugfs_create_file(alias, mode, parent, vif,		\
569 			    &iwl_dbgfs_vif_##name##_ops)
570 #define VIF_DEBUGFS_ADD_FILE(name, parent, mode)		\
571 	VIF_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
572 
iwl_dbgfs_vif_bf_params_write(struct iwl_mld * mld,char * buf,size_t count,void * data)573 static ssize_t iwl_dbgfs_vif_bf_params_write(struct iwl_mld *mld, char *buf,
574 					     size_t count, void *data)
575 {
576 	struct ieee80211_vif *vif = data;
577 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
578 	int link_id = vif->active_links ? __ffs(vif->active_links) : 0;
579 	struct ieee80211_bss_conf *link_conf;
580 	int val;
581 
582 	if (!strncmp("bf_enable_beacon_filter=", buf, 24)) {
583 		if (sscanf(buf + 24, "%d", &val) != 1)
584 			return -EINVAL;
585 	} else {
586 		return -EINVAL;
587 	}
588 
589 	if (val != 0 && val != 1)
590 		return -EINVAL;
591 
592 	link_conf = link_conf_dereference_protected(vif, link_id);
593 	if (WARN_ON(!link_conf))
594 		return -ENODEV;
595 
596 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
597 		return -EIO;
598 
599 	mld_vif->disable_bf = !val;
600 
601 	if (val)
602 		return iwl_mld_enable_beacon_filter(mld, link_conf,
603 						    false) ?: count;
604 	else
605 		return iwl_mld_disable_beacon_filter(mld, vif) ?: count;
606 }
607 
iwl_dbgfs_vif_pm_params_write(struct iwl_mld * mld,char * buf,size_t count,void * data)608 static ssize_t iwl_dbgfs_vif_pm_params_write(struct iwl_mld *mld,
609 					     char *buf,
610 					     size_t count, void *data)
611 {
612 	struct ieee80211_vif *vif = data;
613 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
614 	int val;
615 
616 	if (!strncmp("use_ps_poll=", buf, 12)) {
617 		if (sscanf(buf + 12, "%d", &val) != 1)
618 			return -EINVAL;
619 	} else {
620 		return -EINVAL;
621 	}
622 
623 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
624 		return -EIO;
625 
626 	mld_vif->use_ps_poll = val;
627 
628 	return iwl_mld_update_mac_power(mld, vif, false) ?: count;
629 }
630 
iwl_dbgfs_vif_low_latency_write(struct iwl_mld * mld,char * buf,size_t count,void * data)631 static ssize_t iwl_dbgfs_vif_low_latency_write(struct iwl_mld *mld,
632 					       char *buf, size_t count,
633 					       void *data)
634 {
635 	struct ieee80211_vif *vif = data;
636 	u8 value;
637 	int ret;
638 
639 	ret = kstrtou8(buf, 0, &value);
640 	if (ret)
641 		return ret;
642 
643 	if (value > 1)
644 		return -EINVAL;
645 
646 	iwl_mld_vif_update_low_latency(mld, vif, value, LOW_LATENCY_DEBUGFS);
647 
648 	return count;
649 }
650 
iwl_dbgfs_vif_low_latency_read(struct ieee80211_vif * vif,size_t count,char * buf)651 static ssize_t iwl_dbgfs_vif_low_latency_read(struct ieee80211_vif *vif,
652 					      size_t count, char *buf)
653 {
654 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
655 	char format[] = "traffic=%d\ndbgfs=%d\nvif_type=%d\nactual=%d\n";
656 	u8 ll_causes;
657 
658 	if (WARN_ON(count < sizeof(format)))
659 		return -EINVAL;
660 
661 	ll_causes = READ_ONCE(mld_vif->low_latency_causes);
662 
663 	/* all values in format are boolean so the size of format is enough
664 	 * for holding the result string
665 	 */
666 	return scnprintf(buf, count, format,
667 			 !!(ll_causes & LOW_LATENCY_TRAFFIC),
668 			 !!(ll_causes & LOW_LATENCY_DEBUGFS),
669 			 !!(ll_causes & LOW_LATENCY_VIF_TYPE),
670 			 !!(ll_causes));
671 }
672 
673 VIF_DEBUGFS_WRITE_FILE_OPS(pm_params, 32);
674 VIF_DEBUGFS_WRITE_FILE_OPS(bf_params, 32);
675 VIF_DEBUGFS_READ_WRITE_FILE_OPS(low_latency, 45);
676 
677 static int
_iwl_dbgfs_inject_beacon_ie(struct iwl_mld * mld,struct ieee80211_vif * vif,char * bin,ssize_t len,bool restore)678 _iwl_dbgfs_inject_beacon_ie(struct iwl_mld *mld, struct ieee80211_vif *vif,
679 			    char *bin, ssize_t len,
680 			    bool restore)
681 {
682 	struct iwl_mld_vif *mld_vif;
683 	struct iwl_mld_link *mld_link;
684 	struct iwl_mac_beacon_cmd beacon_cmd = {};
685 	int n_bytes = len / 2;
686 
687 	/* Element len should be represented by u8 */
688 	if (n_bytes >= U8_MAX)
689 		return -EINVAL;
690 
691 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
692 		return -EIO;
693 
694 	if (!vif)
695 		return -EINVAL;
696 
697 	mld_vif = iwl_mld_vif_from_mac80211(vif);
698 	mld_vif->beacon_inject_active = true;
699 	mld->hw->extra_beacon_tailroom = n_bytes;
700 
701 	for_each_mld_vif_valid_link(mld_vif, mld_link) {
702 		u32 offset;
703 		struct ieee80211_tx_info *info;
704 		struct ieee80211_bss_conf *link_conf =
705 			link_conf_dereference_protected(vif, link_id);
706 		struct ieee80211_chanctx_conf *ctx =
707 			wiphy_dereference(mld->wiphy, link_conf->chanctx_conf);
708 		struct sk_buff *beacon =
709 			ieee80211_beacon_get_template(mld->hw, vif,
710 						      NULL, link_id);
711 
712 		if (!beacon)
713 			return -EINVAL;
714 
715 		if (!restore && (WARN_ON(!n_bytes || !bin) ||
716 				 hex2bin(skb_put_zero(beacon, n_bytes),
717 					 bin, n_bytes))) {
718 			dev_kfree_skb(beacon);
719 			return -EINVAL;
720 		}
721 
722 		info = IEEE80211_SKB_CB(beacon);
723 
724 		beacon_cmd.flags =
725 			cpu_to_le16(iwl_mld_get_rate_flags(mld, info, vif,
726 							   link_conf,
727 							   ctx->def.chan->band));
728 		beacon_cmd.byte_cnt = cpu_to_le16((u16)beacon->len);
729 		beacon_cmd.link_id =
730 			cpu_to_le32(mld_link->fw_id);
731 
732 		iwl_mld_set_tim_idx(mld, &beacon_cmd.tim_idx,
733 				    beacon->data, beacon->len);
734 
735 		offset = iwl_find_ie_offset(beacon->data,
736 					    WLAN_EID_S1G_TWT,
737 					    beacon->len);
738 
739 		beacon_cmd.btwt_offset = cpu_to_le32(offset);
740 
741 		iwl_mld_send_beacon_template_cmd(mld, beacon, &beacon_cmd);
742 		dev_kfree_skb(beacon);
743 	}
744 
745 	if (restore)
746 		mld_vif->beacon_inject_active = false;
747 
748 	return 0;
749 }
750 
751 static ssize_t
iwl_dbgfs_vif_inject_beacon_ie_write(struct iwl_mld * mld,char * buf,size_t count,void * data)752 iwl_dbgfs_vif_inject_beacon_ie_write(struct iwl_mld *mld,
753 				     char *buf, size_t count,
754 				     void *data)
755 {
756 	struct ieee80211_vif *vif = data;
757 	int ret = _iwl_dbgfs_inject_beacon_ie(mld, vif, buf,
758 					      count, false);
759 
760 	mld->hw->extra_beacon_tailroom = 0;
761 	return ret ?: count;
762 }
763 
764 VIF_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie, 512);
765 
766 static ssize_t
iwl_dbgfs_vif_inject_beacon_ie_restore_write(struct iwl_mld * mld,char * buf,size_t count,void * data)767 iwl_dbgfs_vif_inject_beacon_ie_restore_write(struct iwl_mld *mld,
768 					     char *buf,
769 					     size_t count,
770 					     void *data)
771 {
772 	struct ieee80211_vif *vif = data;
773 	int ret = _iwl_dbgfs_inject_beacon_ie(mld, vif, NULL,
774 					      0, true);
775 
776 	mld->hw->extra_beacon_tailroom = 0;
777 	return ret ?: count;
778 }
779 
780 VIF_DEBUGFS_WRITE_FILE_OPS(inject_beacon_ie_restore, 512);
781 
782 static ssize_t
iwl_dbgfs_vif_twt_setup_write(struct iwl_mld * mld,char * buf,size_t count,void * data)783 iwl_dbgfs_vif_twt_setup_write(struct iwl_mld *mld, char *buf, size_t count,
784 			      void *data)
785 {
786 	struct iwl_host_cmd hcmd = {
787 		.id = WIDE_ID(IWL_ALWAYS_LONG_GROUP, DEBUG_HOST_COMMAND),
788 	};
789 	struct ieee80211_vif *vif = data;
790 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
791 	struct iwl_dhc_cmd *cmd __free(kfree) = NULL;
792 	struct iwl_dhc_twt_operation *dhc_twt_cmd;
793 	u64 target_wake_time;
794 	u32 twt_operation, interval_exp, interval_mantissa, min_wake_duration;
795 	u8 trigger, flow_type, flow_id, protection, tenth_param;
796 	u8 twt_request = 1, broadcast = 0;
797 	int ret;
798 
799 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
800 		return -EIO;
801 
802 	ret = sscanf(buf, "%u %llu %u %u %u %hhu %hhu %hhu %hhu %hhu",
803 		     &twt_operation, &target_wake_time, &interval_exp,
804 		     &interval_mantissa, &min_wake_duration, &trigger,
805 		     &flow_type, &flow_id, &protection, &tenth_param);
806 
807 	/* the new twt_request parameter is optional for station */
808 	if ((ret != 9 && ret != 10) ||
809 	    (ret == 10 && vif->type != NL80211_IFTYPE_STATION &&
810 	     tenth_param == 1))
811 		return -EINVAL;
812 
813 	/* The 10th parameter:
814 	 * In STA mode - the TWT type (broadcast or individual)
815 	 * In AP mode - the role (0 responder, 2 unsolicited)
816 	 */
817 	if (ret == 10) {
818 		if (vif->type == NL80211_IFTYPE_STATION)
819 			broadcast = tenth_param;
820 		else
821 			twt_request = tenth_param;
822 	}
823 
824 	cmd = kzalloc(sizeof(*cmd) + sizeof(*dhc_twt_cmd), GFP_KERNEL);
825 	if (!cmd)
826 		return -ENOMEM;
827 
828 	dhc_twt_cmd = (void *)cmd->data;
829 	dhc_twt_cmd->mac_id = cpu_to_le32(mld_vif->fw_id);
830 	dhc_twt_cmd->twt_operation = cpu_to_le32(twt_operation);
831 	dhc_twt_cmd->target_wake_time = cpu_to_le64(target_wake_time);
832 	dhc_twt_cmd->interval_exp = cpu_to_le32(interval_exp);
833 	dhc_twt_cmd->interval_mantissa = cpu_to_le32(interval_mantissa);
834 	dhc_twt_cmd->min_wake_duration = cpu_to_le32(min_wake_duration);
835 	dhc_twt_cmd->trigger = trigger;
836 	dhc_twt_cmd->flow_type = flow_type;
837 	dhc_twt_cmd->flow_id = flow_id;
838 	dhc_twt_cmd->protection = protection;
839 	dhc_twt_cmd->twt_request = twt_request;
840 	dhc_twt_cmd->negotiation_type = broadcast ? 3 : 0;
841 
842 	cmd->length = cpu_to_le32(sizeof(*dhc_twt_cmd) >> 2);
843 	cmd->index_and_mask =
844 		cpu_to_le32(DHC_TABLE_INTEGRATION | DHC_TARGET_UMAC |
845 			    DHC_INT_UMAC_TWT_OPERATION);
846 
847 	hcmd.len[0] = sizeof(*cmd) + sizeof(*dhc_twt_cmd);
848 	hcmd.data[0] = cmd;
849 
850 	ret = iwl_mld_send_cmd(mld, &hcmd);
851 
852 	return ret ?: count;
853 }
854 
855 VIF_DEBUGFS_WRITE_FILE_OPS(twt_setup, 256);
856 
857 static ssize_t
iwl_dbgfs_vif_twt_operation_write(struct iwl_mld * mld,char * buf,size_t count,void * data)858 iwl_dbgfs_vif_twt_operation_write(struct iwl_mld *mld, char *buf, size_t count,
859 				  void *data)
860 {
861 	struct ieee80211_vif *vif = data;
862 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
863 	struct iwl_twt_operation_cmd twt_cmd = {};
864 	int link_id = vif->active_links ? __ffs(vif->active_links) : 0;
865 	struct iwl_mld_link *mld_link = iwl_mld_link_dereference_check(mld_vif,
866 								       link_id);
867 	int ret;
868 
869 	if (WARN_ON(!mld_link))
870 		return -ENODEV;
871 
872 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
873 		return -EIO;
874 
875 	if (hweight16(vif->active_links) > 1)
876 		return -EOPNOTSUPP;
877 
878 	ret = sscanf(buf,
879 		     "%u %llu %u %u %u %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu %hhu",
880 		     &twt_cmd.twt_operation, &twt_cmd.target_wake_time,
881 		     &twt_cmd.interval_exponent, &twt_cmd.interval_mantissa,
882 		     &twt_cmd.minimum_wake_duration, &twt_cmd.trigger,
883 		     &twt_cmd.flow_type, &twt_cmd.flow_id,
884 		     &twt_cmd.twt_protection, &twt_cmd.ndp_paging_indicator,
885 		     &twt_cmd.responder_pm_mode, &twt_cmd.negotiation_type,
886 		     &twt_cmd.twt_request, &twt_cmd.implicit,
887 		     &twt_cmd.twt_group_assignment, &twt_cmd.twt_channel,
888 		     &twt_cmd.restricted_info_present, &twt_cmd.dl_bitmap_valid,
889 		     &twt_cmd.ul_bitmap_valid, &twt_cmd.dl_tid_bitmap,
890 		     &twt_cmd.ul_tid_bitmap);
891 
892 	if (ret != 21)
893 		return -EINVAL;
894 
895 	twt_cmd.link_id = cpu_to_le32(mld_link->fw_id);
896 
897 	ret = iwl_mld_send_cmd_pdu(mld,
898 				   WIDE_ID(MAC_CONF_GROUP, TWT_OPERATION_CMD),
899 				   &twt_cmd);
900 	return ret ?: count;
901 }
902 
903 VIF_DEBUGFS_WRITE_FILE_OPS(twt_operation, 256);
904 
iwl_dbgfs_vif_int_mlo_scan_write(struct iwl_mld * mld,char * buf,size_t count,void * data)905 static ssize_t iwl_dbgfs_vif_int_mlo_scan_write(struct iwl_mld *mld, char *buf,
906 						size_t count, void *data)
907 {
908 	struct ieee80211_vif *vif = data;
909 	u32 action;
910 	int ret;
911 
912 	if (!vif->cfg.assoc || !ieee80211_vif_is_mld(vif))
913 		return -EINVAL;
914 
915 	if (kstrtou32(buf, 0, &action))
916 		return -EINVAL;
917 
918 	if (action == 0) {
919 		ret = iwl_mld_scan_stop(mld, IWL_MLD_SCAN_INT_MLO, false);
920 	} else if (action == 1) {
921 		iwl_mld_int_mlo_scan(mld, vif);
922 		ret = 0;
923 	} else {
924 		ret = -EINVAL;
925 	}
926 
927 	return ret ?: count;
928 }
929 
930 VIF_DEBUGFS_WRITE_FILE_OPS(int_mlo_scan, 32);
931 
iwl_mld_add_vif_debugfs(struct ieee80211_hw * hw,struct ieee80211_vif * vif)932 void iwl_mld_add_vif_debugfs(struct ieee80211_hw *hw,
933 			     struct ieee80211_vif *vif)
934 {
935 	struct dentry *mld_vif_dbgfs =
936 		debugfs_create_dir("iwlmld", vif->debugfs_dir);
937 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
938 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
939 	char target[3 * 3 + 11 + (NL80211_WIPHY_NAME_MAXLEN + 1) +
940 		    (7 + IFNAMSIZ + 1) + 6 + 1];
941 	char name[7 + IFNAMSIZ + 1];
942 
943 	/* Create symlink for convenience pointing to interface specific
944 	 * debugfs entries for the driver. For example, under
945 	 * /sys/kernel/debug/iwlwifi/0000\:02\:00.0/iwlmld/
946 	 * find
947 	 * netdev:wlan0 -> ../../../ieee80211/phy0/netdev:wlan0/iwlmld/
948 	 */
949 	snprintf(name, sizeof(name), "%pd", vif->debugfs_dir);
950 	snprintf(target, sizeof(target), "../../../%pd3/iwlmld",
951 		 vif->debugfs_dir);
952 	mld_vif->dbgfs_slink =
953 		debugfs_create_symlink(name, mld->debugfs_dir, target);
954 
955 	if (iwlmld_mod_params.power_scheme != IWL_POWER_SCHEME_CAM &&
956 	    vif->type == NL80211_IFTYPE_STATION) {
957 		VIF_DEBUGFS_ADD_FILE(pm_params, mld_vif_dbgfs, 0200);
958 		VIF_DEBUGFS_ADD_FILE(bf_params, mld_vif_dbgfs, 0200);
959 	}
960 
961 	if (vif->type == NL80211_IFTYPE_AP) {
962 		VIF_DEBUGFS_ADD_FILE(inject_beacon_ie, mld_vif_dbgfs, 0200);
963 		VIF_DEBUGFS_ADD_FILE(inject_beacon_ie_restore,
964 				     mld_vif_dbgfs, 0200);
965 	}
966 
967 	VIF_DEBUGFS_ADD_FILE(low_latency, mld_vif_dbgfs, 0600);
968 	VIF_DEBUGFS_ADD_FILE(twt_setup, mld_vif_dbgfs, 0200);
969 	VIF_DEBUGFS_ADD_FILE(twt_operation, mld_vif_dbgfs, 0200);
970 	VIF_DEBUGFS_ADD_FILE(int_mlo_scan, mld_vif_dbgfs, 0200);
971 }
972 #define LINK_DEBUGFS_WRITE_FILE_OPS(name, bufsz)			\
973 	WIPHY_DEBUGFS_WRITE_FILE_OPS(link_##name, bufsz, bss_conf)
974 
975 #define LINK_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode)		\
976 	debugfs_create_file(alias, mode, parent, link_conf,		\
977 			    &iwl_dbgfs_link_##name##_ops)
978 #define LINK_DEBUGFS_ADD_FILE(name, parent, mode)			\
979 	LINK_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
980 
iwl_mld_add_link_debugfs(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct dentry * dir)981 void iwl_mld_add_link_debugfs(struct ieee80211_hw *hw,
982 			      struct ieee80211_vif *vif,
983 			      struct ieee80211_bss_conf *link_conf,
984 			      struct dentry *dir)
985 {
986 	struct dentry *mld_link_dir;
987 
988 	mld_link_dir = debugfs_lookup("iwlmld", dir);
989 
990 	/* For non-MLO vifs, the dir of deflink is the same as the vif's one.
991 	 * so if iwlmld dir already exists, this means that this is deflink.
992 	 * If not, this is a per-link dir of a MLO vif, add in it the iwlmld
993 	 * dir.
994 	 */
995 	if (!mld_link_dir)
996 		mld_link_dir = debugfs_create_dir("iwlmld", dir);
997 }
998 
iwl_dbgfs_fixed_rate_write(struct iwl_mld * mld,char * buf,size_t count,void * data)999 static ssize_t iwl_dbgfs_fixed_rate_write(struct iwl_mld *mld, char *buf,
1000 					  size_t count, void *data)
1001 {
1002 	struct ieee80211_link_sta *link_sta = data;
1003 	struct iwl_mld_link_sta *mld_link_sta;
1004 	u32 rate;
1005 	u32 partial = false;
1006 	char pretty_rate[100];
1007 	int ret;
1008 	u8 fw_sta_id;
1009 
1010 	mld_link_sta = iwl_mld_link_sta_from_mac80211(link_sta);
1011 	if (WARN_ON(!mld_link_sta))
1012 		return -EINVAL;
1013 
1014 	fw_sta_id = mld_link_sta->fw_id;
1015 
1016 	if (sscanf(buf, "%i %i", &rate, &partial) == 0)
1017 		return -EINVAL;
1018 
1019 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
1020 		return -EIO;
1021 
1022 	ret = iwl_mld_send_tlc_dhc(mld, fw_sta_id,
1023 				   partial ? IWL_TLC_DEBUG_PARTIAL_FIXED_RATE :
1024 					     IWL_TLC_DEBUG_FIXED_RATE,
1025 				   rate);
1026 
1027 	rs_pretty_print_rate(pretty_rate, sizeof(pretty_rate), rate);
1028 
1029 	IWL_DEBUG_RATE(mld, "sta_id %d rate %s partial: %d, ret:%d\n",
1030 		       fw_sta_id, pretty_rate, partial, ret);
1031 
1032 	return ret ? : count;
1033 }
1034 
iwl_dbgfs_tlc_dhc_write(struct iwl_mld * mld,char * buf,size_t count,void * data)1035 static ssize_t iwl_dbgfs_tlc_dhc_write(struct iwl_mld *mld, char *buf,
1036 				       size_t count, void *data)
1037 {
1038 	struct ieee80211_link_sta *link_sta = data;
1039 	struct iwl_mld_link_sta *mld_link_sta;
1040 	u32 type, value;
1041 	int ret;
1042 	u8 fw_sta_id;
1043 
1044 	mld_link_sta = iwl_mld_link_sta_from_mac80211(link_sta);
1045 	if (WARN_ON(!mld_link_sta))
1046 		return -EINVAL;
1047 
1048 	fw_sta_id = mld_link_sta->fw_id;
1049 
1050 	if (sscanf(buf, "%i %i", &type, &value) != 2) {
1051 		IWL_DEBUG_RATE(mld, "usage <type> <value>\n");
1052 		return -EINVAL;
1053 	}
1054 
1055 	if (iwl_mld_dbgfs_fw_cmd_disabled(mld))
1056 		return -EIO;
1057 
1058 	ret = iwl_mld_send_tlc_dhc(mld, fw_sta_id, type, value);
1059 
1060 	return ret ? : count;
1061 }
1062 
1063 #define LINK_STA_DEBUGFS_ADD_FILE_ALIAS(alias, name, parent, mode)	\
1064 	debugfs_create_file(alias, mode, parent, link_sta,		\
1065 			    &iwl_dbgfs_##name##_ops)
1066 #define LINK_STA_DEBUGFS_ADD_FILE(name, parent, mode)			\
1067 	LINK_STA_DEBUGFS_ADD_FILE_ALIAS(#name, name, parent, mode)
1068 
1069 #define LINK_STA_WIPHY_DEBUGFS_WRITE_OPS(name, bufsz)			\
1070 	WIPHY_DEBUGFS_WRITE_FILE_OPS(name, bufsz, link_sta)
1071 
1072 LINK_STA_WIPHY_DEBUGFS_WRITE_OPS(tlc_dhc, 64);
1073 LINK_STA_WIPHY_DEBUGFS_WRITE_OPS(fixed_rate, 64);
1074 
iwl_mld_add_link_sta_debugfs(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_link_sta * link_sta,struct dentry * dir)1075 void iwl_mld_add_link_sta_debugfs(struct ieee80211_hw *hw,
1076 				  struct ieee80211_vif *vif,
1077 				  struct ieee80211_link_sta *link_sta,
1078 				  struct dentry *dir)
1079 {
1080 	LINK_STA_DEBUGFS_ADD_FILE(fixed_rate, dir, 0200);
1081 	LINK_STA_DEBUGFS_ADD_FILE(tlc_dhc, dir, 0200);
1082 }
1083