xref: /linux/drivers/net/wireless/intel/iwlwifi/fw/init.c (revision e93d4aaf4b13963bdd50d11e154ecc251cba4ac7)
18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
28e99ea8dSJohannes Berg /*
38e99ea8dSJohannes Berg  * Copyright (C) 2017 Intel Deutschland GmbH
4fdb70083SJohannes Berg  * Copyright (C) 2019-2021 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 
11*e93d4aafSJohannes 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 
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 
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 
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 */
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 = {
61a8eb340fSEmmanuel Grumbach 		.id = iwl_cmd_id(SOC_CONFIGURATION_CMD, SYSTEM_GROUP, 0),
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 
90a8eb340fSEmmanuel Grumbach 	if (iwl_fw_lookup_cmd_ver(fwrt->fw, IWL_ALWAYS_LONG_GROUP,
91e80bfd11SMordechay Goodstein 				  SCAN_REQ_UMAC,
92e80bfd11SMordechay Goodstein 				  IWL_FW_CMD_VER_UNKNOWN) >= 2 &&
93a8eb340fSEmmanuel Grumbach 	    fwrt->trans->trans_cfg->low_latency_xtal)
94a8eb340fSEmmanuel Grumbach 		cmd.flags |= cpu_to_le32(SOC_CONFIG_CMD_FLAGS_LOW_LATENCY);
95a8eb340fSEmmanuel Grumbach 
96a8eb340fSEmmanuel Grumbach 	cmd.latency = cpu_to_le32(fwrt->trans->trans_cfg->xtal_latency);
97a8eb340fSEmmanuel Grumbach 
98a8eb340fSEmmanuel Grumbach 	ret = iwl_trans_send_cmd(fwrt->trans, &hcmd);
99a8eb340fSEmmanuel Grumbach 	if (ret)
100a8eb340fSEmmanuel Grumbach 		IWL_ERR(fwrt, "Failed to set soc latency: %d\n", ret);
101a8eb340fSEmmanuel Grumbach 	return ret;
102a8eb340fSEmmanuel Grumbach }
103a8eb340fSEmmanuel Grumbach IWL_EXPORT_SYMBOL(iwl_set_soc_latency);
1049cd243f2SMordechay Goodstein 
1059cd243f2SMordechay Goodstein int iwl_configure_rxq(struct iwl_fw_runtime *fwrt)
1069cd243f2SMordechay Goodstein {
1079cd243f2SMordechay Goodstein 	int i, num_queues, size, ret;
1089cd243f2SMordechay Goodstein 	struct iwl_rfh_queue_config *cmd;
1099cd243f2SMordechay Goodstein 	struct iwl_host_cmd hcmd = {
1109cd243f2SMordechay Goodstein 		.id = WIDE_ID(DATA_PATH_GROUP, RFH_QUEUE_CONFIG_CMD),
1119cd243f2SMordechay Goodstein 		.dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1129cd243f2SMordechay Goodstein 	};
1139cd243f2SMordechay Goodstein 
1149cd243f2SMordechay Goodstein 	/*
1159cd243f2SMordechay Goodstein 	 * The default queue is configured via context info, so if we
1169cd243f2SMordechay Goodstein 	 * have a single queue, there's nothing to do here.
1179cd243f2SMordechay Goodstein 	 */
1189cd243f2SMordechay Goodstein 	if (fwrt->trans->num_rx_queues == 1)
1199cd243f2SMordechay Goodstein 		return 0;
1209cd243f2SMordechay Goodstein 
1219cd243f2SMordechay Goodstein 	if (fwrt->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_22000)
1229cd243f2SMordechay Goodstein 		return 0;
1239cd243f2SMordechay Goodstein 
1249cd243f2SMordechay Goodstein 	/* skip the default queue */
1259cd243f2SMordechay Goodstein 	num_queues = fwrt->trans->num_rx_queues - 1;
1269cd243f2SMordechay Goodstein 
1279cd243f2SMordechay Goodstein 	size = struct_size(cmd, data, num_queues);
1289cd243f2SMordechay Goodstein 
1299cd243f2SMordechay Goodstein 	cmd = kzalloc(size, GFP_KERNEL);
1309cd243f2SMordechay Goodstein 	if (!cmd)
1319cd243f2SMordechay Goodstein 		return -ENOMEM;
1329cd243f2SMordechay Goodstein 
1339cd243f2SMordechay Goodstein 	cmd->num_queues = num_queues;
1349cd243f2SMordechay Goodstein 
1359cd243f2SMordechay Goodstein 	for (i = 0; i < num_queues; i++) {
1369cd243f2SMordechay Goodstein 		struct iwl_trans_rxq_dma_data data;
1379cd243f2SMordechay Goodstein 
1389cd243f2SMordechay Goodstein 		cmd->data[i].q_num = i + 1;
1399cd243f2SMordechay Goodstein 		iwl_trans_get_rxq_dma_data(fwrt->trans, i + 1, &data);
1409cd243f2SMordechay Goodstein 
1419cd243f2SMordechay Goodstein 		cmd->data[i].fr_bd_cb = cpu_to_le64(data.fr_bd_cb);
1429cd243f2SMordechay Goodstein 		cmd->data[i].urbd_stts_wrptr =
1439cd243f2SMordechay Goodstein 			cpu_to_le64(data.urbd_stts_wrptr);
1449cd243f2SMordechay Goodstein 		cmd->data[i].ur_bd_cb = cpu_to_le64(data.ur_bd_cb);
1459cd243f2SMordechay Goodstein 		cmd->data[i].fr_bd_wid = cpu_to_le32(data.fr_bd_wid);
1469cd243f2SMordechay Goodstein 	}
1479cd243f2SMordechay Goodstein 
1489cd243f2SMordechay Goodstein 	hcmd.data[0] = cmd;
1499cd243f2SMordechay Goodstein 	hcmd.len[0] = size;
1509cd243f2SMordechay Goodstein 
1519cd243f2SMordechay Goodstein 	ret = iwl_trans_send_cmd(fwrt->trans, &hcmd);
1529cd243f2SMordechay Goodstein 
1539cd243f2SMordechay Goodstein 	kfree(cmd);
1549cd243f2SMordechay Goodstein 
1559cd243f2SMordechay Goodstein 	if (ret)
1569cd243f2SMordechay Goodstein 		IWL_ERR(fwrt, "Failed to configure RX queues: %d\n", ret);
1579cd243f2SMordechay Goodstein 
1589cd243f2SMordechay Goodstein 	return ret;
1599cd243f2SMordechay Goodstein }
1609cd243f2SMordechay Goodstein IWL_EXPORT_SYMBOL(iwl_configure_rxq);
161