xref: /linux/drivers/net/wireless/intel/iwlwifi/fw/init.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
28e99ea8dSJohannes Berg /*
38e99ea8dSJohannes Berg  * Copyright (C) 2017 Intel Deutschland GmbH
4*6ccfc7c4SJohannes Berg  * Copyright (C) 2019-2021, 2024 Intel Corporation
58e99ea8dSJohannes Berg  */
67174beb6SJohannes Berg #include "iwl-drv.h"
77174beb6SJohannes Berg #include "runtime.h"
87174beb6SJohannes Berg #include "dbg.h"
993b167c1SMordechay Goodstein #include "debugfs.h"
107174beb6SJohannes Berg 
11e93d4aafSJohannes Berg #include "fw/api/system.h"
12a8eb340fSEmmanuel Grumbach #include "fw/api/commands.h"
139cd243f2SMordechay Goodstein #include "fw/api/rx.h"
149cd243f2SMordechay Goodstein #include "fw/api/datapath.h"
15a8eb340fSEmmanuel Grumbach 
iwl_fw_runtime_init(struct iwl_fw_runtime * fwrt,struct iwl_trans * trans,const struct iwl_fw * fw,const struct iwl_fw_runtime_ops * ops,void * ops_ctx,const struct iwl_dump_sanitize_ops * sanitize_ops,void * sanitize_ctx,struct dentry * dbgfs_dir)167174beb6SJohannes Berg void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans,
177174beb6SJohannes Berg 			const struct iwl_fw *fw,
1893b167c1SMordechay Goodstein 			const struct iwl_fw_runtime_ops *ops, void *ops_ctx,
19fdb70083SJohannes Berg 			const struct iwl_dump_sanitize_ops *sanitize_ops,
20fdb70083SJohannes Berg 			void *sanitize_ctx,
2193b167c1SMordechay Goodstein 			struct dentry *dbgfs_dir)
227174beb6SJohannes Berg {
23c7ab138eSShahar S Matityahu 	int i;
24c7ab138eSShahar S Matityahu 
257174beb6SJohannes Berg 	memset(fwrt, 0, sizeof(*fwrt));
267174beb6SJohannes Berg 	fwrt->trans = trans;
277174beb6SJohannes Berg 	fwrt->fw = fw;
287174beb6SJohannes Berg 	fwrt->dev = trans->dev;
297174beb6SJohannes Berg 	fwrt->dump.conf = FW_DBG_INVALID;
307174beb6SJohannes Berg 	fwrt->ops = ops;
31fdb70083SJohannes Berg 	fwrt->sanitize_ops = sanitize_ops;
32fdb70083SJohannes Berg 	fwrt->sanitize_ctx = sanitize_ctx;
337174beb6SJohannes Berg 	fwrt->ops_ctx = ops_ctx;
34c7ab138eSShahar S Matityahu 	for (i = 0; i < IWL_FW_RUNTIME_DUMP_WK_NUM; i++) {
35c7ab138eSShahar S Matityahu 		fwrt->dump.wks[i].idx = i;
36c7ab138eSShahar S Matityahu 		INIT_DELAYED_WORK(&fwrt->dump.wks[i].wk, iwl_fw_error_dump_wk);
37c7ab138eSShahar S Matityahu 	}
3893b167c1SMordechay Goodstein 	iwl_fwrt_dbgfs_register(fwrt, dbgfs_dir);
397174beb6SJohannes Berg }
407174beb6SJohannes Berg IWL_EXPORT_SYMBOL(iwl_fw_runtime_init);
417f8ae00fSHaim Dreyfuss 
iwl_fw_runtime_suspend(struct iwl_fw_runtime * fwrt)427f8ae00fSHaim Dreyfuss void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt)
437f8ae00fSHaim Dreyfuss {
447f8ae00fSHaim Dreyfuss 	iwl_fw_suspend_timestamp(fwrt);
451db5c347SMordechay Goodstein 	iwl_dbg_tlv_time_point(fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_START, NULL);
467f8ae00fSHaim Dreyfuss }
477f8ae00fSHaim Dreyfuss IWL_EXPORT_SYMBOL(iwl_fw_runtime_suspend);
487f8ae00fSHaim Dreyfuss 
iwl_fw_runtime_resume(struct iwl_fw_runtime * fwrt)497f8ae00fSHaim Dreyfuss void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt)
507f8ae00fSHaim Dreyfuss {
511db5c347SMordechay Goodstein 	iwl_dbg_tlv_time_point(fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_END, NULL);
527f8ae00fSHaim Dreyfuss 	iwl_fw_resume_timestamp(fwrt);
537f8ae00fSHaim Dreyfuss }
547f8ae00fSHaim Dreyfuss IWL_EXPORT_SYMBOL(iwl_fw_runtime_resume);
55a8eb340fSEmmanuel Grumbach 
56a8eb340fSEmmanuel Grumbach /* set device type and latency */
iwl_set_soc_latency(struct iwl_fw_runtime * fwrt)57a8eb340fSEmmanuel Grumbach int iwl_set_soc_latency(struct iwl_fw_runtime *fwrt)
58a8eb340fSEmmanuel Grumbach {
59a8eb340fSEmmanuel Grumbach 	struct iwl_soc_configuration_cmd cmd = {};
60a8eb340fSEmmanuel Grumbach 	struct iwl_host_cmd hcmd = {
61f0c86427SJohannes Berg 		.id = WIDE_ID(SYSTEM_GROUP, SOC_CONFIGURATION_CMD),
62a8eb340fSEmmanuel Grumbach 		.data[0] = &cmd,
63a8eb340fSEmmanuel Grumbach 		.len[0] = sizeof(cmd),
64a8eb340fSEmmanuel Grumbach 	};
65a8eb340fSEmmanuel Grumbach 	int ret;
66a8eb340fSEmmanuel Grumbach 
67a8eb340fSEmmanuel Grumbach 	/*
68a8eb340fSEmmanuel Grumbach 	 * In VER_1 of this command, the discrete value is considered
69a8eb340fSEmmanuel Grumbach 	 * an integer; In VER_2, it's a bitmask.  Since we have only 2
70a8eb340fSEmmanuel Grumbach 	 * values in VER_1, this is backwards-compatible with VER_2,
71a8eb340fSEmmanuel Grumbach 	 * as long as we don't set any other bits.
72a8eb340fSEmmanuel Grumbach 	 */
73a8eb340fSEmmanuel Grumbach 	if (!fwrt->trans->trans_cfg->integrated)
74a8eb340fSEmmanuel Grumbach 		cmd.flags = cpu_to_le32(SOC_CONFIG_CMD_FLAGS_DISCRETE);
75a8eb340fSEmmanuel Grumbach 
76a8eb340fSEmmanuel Grumbach 	BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_NONE !=
77a8eb340fSEmmanuel Grumbach 		     SOC_FLAGS_LTR_APPLY_DELAY_NONE);
78a8eb340fSEmmanuel Grumbach 	BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_200US !=
79a8eb340fSEmmanuel Grumbach 		     SOC_FLAGS_LTR_APPLY_DELAY_200);
80a8eb340fSEmmanuel Grumbach 	BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_2500US !=
81a8eb340fSEmmanuel Grumbach 		     SOC_FLAGS_LTR_APPLY_DELAY_2500);
82a8eb340fSEmmanuel Grumbach 	BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_1820US !=
83a8eb340fSEmmanuel Grumbach 		     SOC_FLAGS_LTR_APPLY_DELAY_1820);
84a8eb340fSEmmanuel Grumbach 
85a8eb340fSEmmanuel Grumbach 	if (fwrt->trans->trans_cfg->ltr_delay != IWL_CFG_TRANS_LTR_DELAY_NONE &&
86a8eb340fSEmmanuel Grumbach 	    !WARN_ON(!fwrt->trans->trans_cfg->integrated))
87a8eb340fSEmmanuel Grumbach 		cmd.flags |= le32_encode_bits(fwrt->trans->trans_cfg->ltr_delay,
88a8eb340fSEmmanuel Grumbach 					      SOC_FLAGS_LTR_APPLY_DELAY_MASK);
89a8eb340fSEmmanuel Grumbach 
90971cbe50SJohannes Berg 	if (iwl_fw_lookup_cmd_ver(fwrt->fw, SCAN_REQ_UMAC,
91e80bfd11SMordechay Goodstein 				  IWL_FW_CMD_VER_UNKNOWN) >= 2 &&
92a8eb340fSEmmanuel Grumbach 	    fwrt->trans->trans_cfg->low_latency_xtal)
93a8eb340fSEmmanuel Grumbach 		cmd.flags |= cpu_to_le32(SOC_CONFIG_CMD_FLAGS_LOW_LATENCY);
94a8eb340fSEmmanuel Grumbach 
95a8eb340fSEmmanuel Grumbach 	cmd.latency = cpu_to_le32(fwrt->trans->trans_cfg->xtal_latency);
96a8eb340fSEmmanuel Grumbach 
97a8eb340fSEmmanuel Grumbach 	ret = iwl_trans_send_cmd(fwrt->trans, &hcmd);
98a8eb340fSEmmanuel Grumbach 	if (ret)
99a8eb340fSEmmanuel Grumbach 		IWL_ERR(fwrt, "Failed to set soc latency: %d\n", ret);
100a8eb340fSEmmanuel Grumbach 	return ret;
101a8eb340fSEmmanuel Grumbach }
102a8eb340fSEmmanuel Grumbach IWL_EXPORT_SYMBOL(iwl_set_soc_latency);
1039cd243f2SMordechay Goodstein 
iwl_configure_rxq(struct iwl_fw_runtime * fwrt)1049cd243f2SMordechay Goodstein int iwl_configure_rxq(struct iwl_fw_runtime *fwrt)
1059cd243f2SMordechay Goodstein {
1069cd243f2SMordechay Goodstein 	int i, num_queues, size, ret;
1079cd243f2SMordechay Goodstein 	struct iwl_rfh_queue_config *cmd;
1089cd243f2SMordechay Goodstein 	struct iwl_host_cmd hcmd = {
1099cd243f2SMordechay Goodstein 		.id = WIDE_ID(DATA_PATH_GROUP, RFH_QUEUE_CONFIG_CMD),
1109cd243f2SMordechay Goodstein 		.dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1119cd243f2SMordechay Goodstein 	};
1129cd243f2SMordechay Goodstein 
1139cd243f2SMordechay Goodstein 	/*
1149cd243f2SMordechay Goodstein 	 * The default queue is configured via context info, so if we
1159cd243f2SMordechay Goodstein 	 * have a single queue, there's nothing to do here.
1169cd243f2SMordechay Goodstein 	 */
1179cd243f2SMordechay Goodstein 	if (fwrt->trans->num_rx_queues == 1)
1189cd243f2SMordechay Goodstein 		return 0;
1199cd243f2SMordechay Goodstein 
1209cd243f2SMordechay Goodstein 	if (fwrt->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_22000)
1219cd243f2SMordechay Goodstein 		return 0;
1229cd243f2SMordechay Goodstein 
1239cd243f2SMordechay Goodstein 	/* skip the default queue */
1249cd243f2SMordechay Goodstein 	num_queues = fwrt->trans->num_rx_queues - 1;
1259cd243f2SMordechay Goodstein 
1269cd243f2SMordechay Goodstein 	size = struct_size(cmd, data, num_queues);
1279cd243f2SMordechay Goodstein 
1289cd243f2SMordechay Goodstein 	cmd = kzalloc(size, GFP_KERNEL);
1299cd243f2SMordechay Goodstein 	if (!cmd)
1309cd243f2SMordechay Goodstein 		return -ENOMEM;
1319cd243f2SMordechay Goodstein 
1329cd243f2SMordechay Goodstein 	cmd->num_queues = num_queues;
1339cd243f2SMordechay Goodstein 
1349cd243f2SMordechay Goodstein 	for (i = 0; i < num_queues; i++) {
1359cd243f2SMordechay Goodstein 		struct iwl_trans_rxq_dma_data data;
1369cd243f2SMordechay Goodstein 
1379cd243f2SMordechay Goodstein 		cmd->data[i].q_num = i + 1;
138*6ccfc7c4SJohannes Berg 		ret = iwl_trans_get_rxq_dma_data(fwrt->trans, i + 1, &data);
139*6ccfc7c4SJohannes Berg 		if (ret)
140*6ccfc7c4SJohannes Berg 			goto out;
1419cd243f2SMordechay Goodstein 
1429cd243f2SMordechay Goodstein 		cmd->data[i].fr_bd_cb = cpu_to_le64(data.fr_bd_cb);
1439cd243f2SMordechay Goodstein 		cmd->data[i].urbd_stts_wrptr =
1449cd243f2SMordechay Goodstein 			cpu_to_le64(data.urbd_stts_wrptr);
1459cd243f2SMordechay Goodstein 		cmd->data[i].ur_bd_cb = cpu_to_le64(data.ur_bd_cb);
1469cd243f2SMordechay Goodstein 		cmd->data[i].fr_bd_wid = cpu_to_le32(data.fr_bd_wid);
1479cd243f2SMordechay Goodstein 	}
1489cd243f2SMordechay Goodstein 
1499cd243f2SMordechay Goodstein 	hcmd.data[0] = cmd;
1509cd243f2SMordechay Goodstein 	hcmd.len[0] = size;
1519cd243f2SMordechay Goodstein 
1529cd243f2SMordechay Goodstein 	ret = iwl_trans_send_cmd(fwrt->trans, &hcmd);
1539cd243f2SMordechay Goodstein 
154*6ccfc7c4SJohannes Berg out:
1559cd243f2SMordechay Goodstein 	kfree(cmd);
1569cd243f2SMordechay Goodstein 
1579cd243f2SMordechay Goodstein 	if (ret)
1589cd243f2SMordechay Goodstein 		IWL_ERR(fwrt, "Failed to configure RX queues: %d\n", ret);
1599cd243f2SMordechay Goodstein 
1609cd243f2SMordechay Goodstein 	return ret;
1619cd243f2SMordechay Goodstein }
1629cd243f2SMordechay Goodstein IWL_EXPORT_SYMBOL(iwl_configure_rxq);
163