1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * Copyright (C) 2017 Intel Deutschland GmbH 4 * Copyright (C) 2019-2020 Intel Corporation 5 */ 6 #include "iwl-drv.h" 7 #include "runtime.h" 8 #include "dbg.h" 9 #include "debugfs.h" 10 11 #include "fw/api/soc.h" 12 #include "fw/api/commands.h" 13 14 void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans, 15 const struct iwl_fw *fw, 16 const struct iwl_fw_runtime_ops *ops, void *ops_ctx, 17 struct dentry *dbgfs_dir) 18 { 19 int i; 20 21 memset(fwrt, 0, sizeof(*fwrt)); 22 fwrt->trans = trans; 23 fwrt->fw = fw; 24 fwrt->dev = trans->dev; 25 fwrt->dump.conf = FW_DBG_INVALID; 26 fwrt->ops = ops; 27 fwrt->ops_ctx = ops_ctx; 28 for (i = 0; i < IWL_FW_RUNTIME_DUMP_WK_NUM; i++) { 29 fwrt->dump.wks[i].idx = i; 30 INIT_DELAYED_WORK(&fwrt->dump.wks[i].wk, iwl_fw_error_dump_wk); 31 } 32 iwl_fwrt_dbgfs_register(fwrt, dbgfs_dir); 33 } 34 IWL_EXPORT_SYMBOL(iwl_fw_runtime_init); 35 36 void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt) 37 { 38 iwl_fw_suspend_timestamp(fwrt); 39 iwl_dbg_tlv_time_point(fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_START, NULL); 40 } 41 IWL_EXPORT_SYMBOL(iwl_fw_runtime_suspend); 42 43 void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt) 44 { 45 iwl_dbg_tlv_time_point(fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_END, NULL); 46 iwl_fw_resume_timestamp(fwrt); 47 } 48 IWL_EXPORT_SYMBOL(iwl_fw_runtime_resume); 49 50 /* set device type and latency */ 51 int iwl_set_soc_latency(struct iwl_fw_runtime *fwrt) 52 { 53 struct iwl_soc_configuration_cmd cmd = {}; 54 struct iwl_host_cmd hcmd = { 55 .id = iwl_cmd_id(SOC_CONFIGURATION_CMD, SYSTEM_GROUP, 0), 56 .data[0] = &cmd, 57 .len[0] = sizeof(cmd), 58 }; 59 int ret; 60 61 /* 62 * In VER_1 of this command, the discrete value is considered 63 * an integer; In VER_2, it's a bitmask. Since we have only 2 64 * values in VER_1, this is backwards-compatible with VER_2, 65 * as long as we don't set any other bits. 66 */ 67 if (!fwrt->trans->trans_cfg->integrated) 68 cmd.flags = cpu_to_le32(SOC_CONFIG_CMD_FLAGS_DISCRETE); 69 70 BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_NONE != 71 SOC_FLAGS_LTR_APPLY_DELAY_NONE); 72 BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_200US != 73 SOC_FLAGS_LTR_APPLY_DELAY_200); 74 BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_2500US != 75 SOC_FLAGS_LTR_APPLY_DELAY_2500); 76 BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_1820US != 77 SOC_FLAGS_LTR_APPLY_DELAY_1820); 78 79 if (fwrt->trans->trans_cfg->ltr_delay != IWL_CFG_TRANS_LTR_DELAY_NONE && 80 !WARN_ON(!fwrt->trans->trans_cfg->integrated)) 81 cmd.flags |= le32_encode_bits(fwrt->trans->trans_cfg->ltr_delay, 82 SOC_FLAGS_LTR_APPLY_DELAY_MASK); 83 84 if (iwl_fw_lookup_cmd_ver(fwrt->fw, IWL_ALWAYS_LONG_GROUP, 85 SCAN_REQ_UMAC, 86 IWL_FW_CMD_VER_UNKNOWN) >= 2 && 87 fwrt->trans->trans_cfg->low_latency_xtal) 88 cmd.flags |= cpu_to_le32(SOC_CONFIG_CMD_FLAGS_LOW_LATENCY); 89 90 cmd.latency = cpu_to_le32(fwrt->trans->trans_cfg->xtal_latency); 91 92 ret = iwl_trans_send_cmd(fwrt->trans, &hcmd); 93 if (ret) 94 IWL_ERR(fwrt, "Failed to set soc latency: %d\n", ret); 95 return ret; 96 } 97 IWL_EXPORT_SYMBOL(iwl_set_soc_latency); 98