18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 28e99ea8dSJohannes Berg /* 38e99ea8dSJohannes Berg * Copyright (C) 2017 Intel Deutschland GmbH 48e99ea8dSJohannes Berg * Copyright (C) 2019-2020 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 11a8eb340fSEmmanuel Grumbach #include "fw/api/soc.h" 12a8eb340fSEmmanuel Grumbach #include "fw/api/commands.h" 13*9cd243f2SMordechay Goodstein #include "fw/api/rx.h" 14*9cd243f2SMordechay 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, 1993b167c1SMordechay Goodstein struct dentry *dbgfs_dir) 207174beb6SJohannes Berg { 21c7ab138eSShahar S Matityahu int i; 22c7ab138eSShahar S Matityahu 237174beb6SJohannes Berg memset(fwrt, 0, sizeof(*fwrt)); 247174beb6SJohannes Berg fwrt->trans = trans; 257174beb6SJohannes Berg fwrt->fw = fw; 267174beb6SJohannes Berg fwrt->dev = trans->dev; 277174beb6SJohannes Berg fwrt->dump.conf = FW_DBG_INVALID; 287174beb6SJohannes Berg fwrt->ops = ops; 297174beb6SJohannes Berg fwrt->ops_ctx = ops_ctx; 30c7ab138eSShahar S Matityahu for (i = 0; i < IWL_FW_RUNTIME_DUMP_WK_NUM; i++) { 31c7ab138eSShahar S Matityahu fwrt->dump.wks[i].idx = i; 32c7ab138eSShahar S Matityahu INIT_DELAYED_WORK(&fwrt->dump.wks[i].wk, iwl_fw_error_dump_wk); 33c7ab138eSShahar S Matityahu } 3493b167c1SMordechay Goodstein iwl_fwrt_dbgfs_register(fwrt, dbgfs_dir); 357174beb6SJohannes Berg } 367174beb6SJohannes Berg IWL_EXPORT_SYMBOL(iwl_fw_runtime_init); 377f8ae00fSHaim Dreyfuss 387f8ae00fSHaim Dreyfuss void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt) 397f8ae00fSHaim Dreyfuss { 407f8ae00fSHaim Dreyfuss iwl_fw_suspend_timestamp(fwrt); 411db5c347SMordechay Goodstein iwl_dbg_tlv_time_point(fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_START, NULL); 427f8ae00fSHaim Dreyfuss } 437f8ae00fSHaim Dreyfuss IWL_EXPORT_SYMBOL(iwl_fw_runtime_suspend); 447f8ae00fSHaim Dreyfuss 457f8ae00fSHaim Dreyfuss void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt) 467f8ae00fSHaim Dreyfuss { 471db5c347SMordechay Goodstein iwl_dbg_tlv_time_point(fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_END, NULL); 487f8ae00fSHaim Dreyfuss iwl_fw_resume_timestamp(fwrt); 497f8ae00fSHaim Dreyfuss } 507f8ae00fSHaim Dreyfuss IWL_EXPORT_SYMBOL(iwl_fw_runtime_resume); 51a8eb340fSEmmanuel Grumbach 52a8eb340fSEmmanuel Grumbach /* set device type and latency */ 53a8eb340fSEmmanuel Grumbach int iwl_set_soc_latency(struct iwl_fw_runtime *fwrt) 54a8eb340fSEmmanuel Grumbach { 55a8eb340fSEmmanuel Grumbach struct iwl_soc_configuration_cmd cmd = {}; 56a8eb340fSEmmanuel Grumbach struct iwl_host_cmd hcmd = { 57a8eb340fSEmmanuel Grumbach .id = iwl_cmd_id(SOC_CONFIGURATION_CMD, SYSTEM_GROUP, 0), 58a8eb340fSEmmanuel Grumbach .data[0] = &cmd, 59a8eb340fSEmmanuel Grumbach .len[0] = sizeof(cmd), 60a8eb340fSEmmanuel Grumbach }; 61a8eb340fSEmmanuel Grumbach int ret; 62a8eb340fSEmmanuel Grumbach 63a8eb340fSEmmanuel Grumbach /* 64a8eb340fSEmmanuel Grumbach * In VER_1 of this command, the discrete value is considered 65a8eb340fSEmmanuel Grumbach * an integer; In VER_2, it's a bitmask. Since we have only 2 66a8eb340fSEmmanuel Grumbach * values in VER_1, this is backwards-compatible with VER_2, 67a8eb340fSEmmanuel Grumbach * as long as we don't set any other bits. 68a8eb340fSEmmanuel Grumbach */ 69a8eb340fSEmmanuel Grumbach if (!fwrt->trans->trans_cfg->integrated) 70a8eb340fSEmmanuel Grumbach cmd.flags = cpu_to_le32(SOC_CONFIG_CMD_FLAGS_DISCRETE); 71a8eb340fSEmmanuel Grumbach 72a8eb340fSEmmanuel Grumbach BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_NONE != 73a8eb340fSEmmanuel Grumbach SOC_FLAGS_LTR_APPLY_DELAY_NONE); 74a8eb340fSEmmanuel Grumbach BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_200US != 75a8eb340fSEmmanuel Grumbach SOC_FLAGS_LTR_APPLY_DELAY_200); 76a8eb340fSEmmanuel Grumbach BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_2500US != 77a8eb340fSEmmanuel Grumbach SOC_FLAGS_LTR_APPLY_DELAY_2500); 78a8eb340fSEmmanuel Grumbach BUILD_BUG_ON(IWL_CFG_TRANS_LTR_DELAY_1820US != 79a8eb340fSEmmanuel Grumbach SOC_FLAGS_LTR_APPLY_DELAY_1820); 80a8eb340fSEmmanuel Grumbach 81a8eb340fSEmmanuel Grumbach if (fwrt->trans->trans_cfg->ltr_delay != IWL_CFG_TRANS_LTR_DELAY_NONE && 82a8eb340fSEmmanuel Grumbach !WARN_ON(!fwrt->trans->trans_cfg->integrated)) 83a8eb340fSEmmanuel Grumbach cmd.flags |= le32_encode_bits(fwrt->trans->trans_cfg->ltr_delay, 84a8eb340fSEmmanuel Grumbach SOC_FLAGS_LTR_APPLY_DELAY_MASK); 85a8eb340fSEmmanuel Grumbach 86a8eb340fSEmmanuel Grumbach if (iwl_fw_lookup_cmd_ver(fwrt->fw, IWL_ALWAYS_LONG_GROUP, 87e80bfd11SMordechay Goodstein SCAN_REQ_UMAC, 88e80bfd11SMordechay Goodstein IWL_FW_CMD_VER_UNKNOWN) >= 2 && 89a8eb340fSEmmanuel Grumbach fwrt->trans->trans_cfg->low_latency_xtal) 90a8eb340fSEmmanuel Grumbach cmd.flags |= cpu_to_le32(SOC_CONFIG_CMD_FLAGS_LOW_LATENCY); 91a8eb340fSEmmanuel Grumbach 92a8eb340fSEmmanuel Grumbach cmd.latency = cpu_to_le32(fwrt->trans->trans_cfg->xtal_latency); 93a8eb340fSEmmanuel Grumbach 94a8eb340fSEmmanuel Grumbach ret = iwl_trans_send_cmd(fwrt->trans, &hcmd); 95a8eb340fSEmmanuel Grumbach if (ret) 96a8eb340fSEmmanuel Grumbach IWL_ERR(fwrt, "Failed to set soc latency: %d\n", ret); 97a8eb340fSEmmanuel Grumbach return ret; 98a8eb340fSEmmanuel Grumbach } 99a8eb340fSEmmanuel Grumbach IWL_EXPORT_SYMBOL(iwl_set_soc_latency); 100*9cd243f2SMordechay Goodstein 101*9cd243f2SMordechay Goodstein int iwl_configure_rxq(struct iwl_fw_runtime *fwrt) 102*9cd243f2SMordechay Goodstein { 103*9cd243f2SMordechay Goodstein int i, num_queues, size, ret; 104*9cd243f2SMordechay Goodstein struct iwl_rfh_queue_config *cmd; 105*9cd243f2SMordechay Goodstein struct iwl_host_cmd hcmd = { 106*9cd243f2SMordechay Goodstein .id = WIDE_ID(DATA_PATH_GROUP, RFH_QUEUE_CONFIG_CMD), 107*9cd243f2SMordechay Goodstein .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 108*9cd243f2SMordechay Goodstein }; 109*9cd243f2SMordechay Goodstein 110*9cd243f2SMordechay Goodstein /* 111*9cd243f2SMordechay Goodstein * The default queue is configured via context info, so if we 112*9cd243f2SMordechay Goodstein * have a single queue, there's nothing to do here. 113*9cd243f2SMordechay Goodstein */ 114*9cd243f2SMordechay Goodstein if (fwrt->trans->num_rx_queues == 1) 115*9cd243f2SMordechay Goodstein return 0; 116*9cd243f2SMordechay Goodstein 117*9cd243f2SMordechay Goodstein if (fwrt->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_22000) 118*9cd243f2SMordechay Goodstein return 0; 119*9cd243f2SMordechay Goodstein 120*9cd243f2SMordechay Goodstein /* skip the default queue */ 121*9cd243f2SMordechay Goodstein num_queues = fwrt->trans->num_rx_queues - 1; 122*9cd243f2SMordechay Goodstein 123*9cd243f2SMordechay Goodstein size = struct_size(cmd, data, num_queues); 124*9cd243f2SMordechay Goodstein 125*9cd243f2SMordechay Goodstein cmd = kzalloc(size, GFP_KERNEL); 126*9cd243f2SMordechay Goodstein if (!cmd) 127*9cd243f2SMordechay Goodstein return -ENOMEM; 128*9cd243f2SMordechay Goodstein 129*9cd243f2SMordechay Goodstein cmd->num_queues = num_queues; 130*9cd243f2SMordechay Goodstein 131*9cd243f2SMordechay Goodstein for (i = 0; i < num_queues; i++) { 132*9cd243f2SMordechay Goodstein struct iwl_trans_rxq_dma_data data; 133*9cd243f2SMordechay Goodstein 134*9cd243f2SMordechay Goodstein cmd->data[i].q_num = i + 1; 135*9cd243f2SMordechay Goodstein iwl_trans_get_rxq_dma_data(fwrt->trans, i + 1, &data); 136*9cd243f2SMordechay Goodstein 137*9cd243f2SMordechay Goodstein cmd->data[i].fr_bd_cb = cpu_to_le64(data.fr_bd_cb); 138*9cd243f2SMordechay Goodstein cmd->data[i].urbd_stts_wrptr = 139*9cd243f2SMordechay Goodstein cpu_to_le64(data.urbd_stts_wrptr); 140*9cd243f2SMordechay Goodstein cmd->data[i].ur_bd_cb = cpu_to_le64(data.ur_bd_cb); 141*9cd243f2SMordechay Goodstein cmd->data[i].fr_bd_wid = cpu_to_le32(data.fr_bd_wid); 142*9cd243f2SMordechay Goodstein } 143*9cd243f2SMordechay Goodstein 144*9cd243f2SMordechay Goodstein hcmd.data[0] = cmd; 145*9cd243f2SMordechay Goodstein hcmd.len[0] = size; 146*9cd243f2SMordechay Goodstein 147*9cd243f2SMordechay Goodstein ret = iwl_trans_send_cmd(fwrt->trans, &hcmd); 148*9cd243f2SMordechay Goodstein 149*9cd243f2SMordechay Goodstein kfree(cmd); 150*9cd243f2SMordechay Goodstein 151*9cd243f2SMordechay Goodstein if (ret) 152*9cd243f2SMordechay Goodstein IWL_ERR(fwrt, "Failed to configure RX queues: %d\n", ret); 153*9cd243f2SMordechay Goodstein 154*9cd243f2SMordechay Goodstein return ret; 155*9cd243f2SMordechay Goodstein } 156*9cd243f2SMordechay Goodstein IWL_EXPORT_SYMBOL(iwl_configure_rxq); 157