1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 2 /* 3 * Copyright (C) 2017 Intel Deutschland GmbH 4 * Copyright (C) 2018-2023 Intel Corporation 5 */ 6 #ifndef __iwl_fw_runtime_h__ 7 #define __iwl_fw_runtime_h__ 8 9 #include "iwl-config.h" 10 #include "iwl-trans.h" 11 #include "img.h" 12 #include "fw/api/debug.h" 13 #include "fw/api/paging.h" 14 #include "fw/api/power.h" 15 #include "iwl-eeprom-parse.h" 16 #include "fw/acpi.h" 17 18 struct iwl_fw_runtime_ops { 19 void (*dump_start)(void *ctx); 20 void (*dump_end)(void *ctx); 21 int (*send_hcmd)(void *ctx, struct iwl_host_cmd *host_cmd); 22 bool (*d3_debug_enable)(void *ctx); 23 }; 24 25 #define MAX_NUM_LMAC 2 26 #define MAX_NUM_TCM 2 27 #define MAX_NUM_RCM 2 28 struct iwl_fwrt_shared_mem_cfg { 29 int num_lmacs; 30 int num_txfifo_entries; 31 struct { 32 u32 txfifo_size[TX_FIFO_MAX_NUM]; 33 u32 rxfifo1_size; 34 } lmac[MAX_NUM_LMAC]; 35 u32 rxfifo2_size; 36 u32 rxfifo2_control_size; 37 u32 internal_txfifo_addr; 38 u32 internal_txfifo_size[TX_FIFO_INTERNAL_MAX_NUM]; 39 }; 40 41 #define IWL_FW_RUNTIME_DUMP_WK_NUM 5 42 43 /** 44 * struct iwl_fwrt_dump_data - dump data 45 * @trig: trigger the worker was scheduled upon 46 * @fw_pkt: packet received from FW 47 */ 48 struct iwl_fwrt_dump_data { 49 union { 50 struct { 51 struct iwl_fw_ini_trigger_tlv *trig; 52 struct iwl_rx_packet *fw_pkt; 53 }; 54 struct { 55 const struct iwl_fw_dump_desc *desc; 56 bool monitor_only; 57 }; 58 }; 59 }; 60 61 /** 62 * struct iwl_fwrt_wk_data - dump worker data struct 63 * @idx: index of the worker 64 * @wk: worker 65 */ 66 struct iwl_fwrt_wk_data { 67 u8 idx; 68 struct delayed_work wk; 69 struct iwl_fwrt_dump_data dump_data; 70 }; 71 72 /** 73 * struct iwl_txf_iter_data - Tx fifo iterator data struct 74 * @fifo: fifo number 75 * @lmac: lmac number 76 * @fifo_size: fifo size 77 * @internal_txf: non zero if fifo is internal Tx fifo 78 */ 79 struct iwl_txf_iter_data { 80 int fifo; 81 int lmac; 82 u32 fifo_size; 83 u8 internal_txf; 84 }; 85 86 /** 87 * struct iwl_fw_runtime - runtime data for firmware 88 * @fw: firmware image 89 * @cfg: NIC configuration 90 * @dev: device pointer 91 * @ops: user ops 92 * @ops_ctx: user ops context 93 * @fw_paging_db: paging database 94 * @num_of_paging_blk: number of paging blocks 95 * @num_of_pages_in_last_blk: number of pages in the last block 96 * @smem_cfg: saved firmware SMEM configuration 97 * @cur_fw_img: current firmware image, must be maintained by 98 * the driver by calling &iwl_fw_set_current_image() 99 * @dump: debug dump data 100 */ 101 struct iwl_fw_runtime { 102 struct iwl_trans *trans; 103 const struct iwl_fw *fw; 104 struct device *dev; 105 106 const struct iwl_fw_runtime_ops *ops; 107 void *ops_ctx; 108 109 const struct iwl_dump_sanitize_ops *sanitize_ops; 110 void *sanitize_ctx; 111 112 /* Paging */ 113 struct iwl_fw_paging fw_paging_db[NUM_OF_FW_PAGING_BLOCKS]; 114 u16 num_of_paging_blk; 115 u16 num_of_pages_in_last_blk; 116 117 enum iwl_ucode_type cur_fw_img; 118 119 /* memory configuration */ 120 struct iwl_fwrt_shared_mem_cfg smem_cfg; 121 122 /* debug */ 123 struct { 124 struct iwl_fwrt_wk_data wks[IWL_FW_RUNTIME_DUMP_WK_NUM]; 125 unsigned long active_wks; 126 127 u8 conf; 128 129 /* ts of the beginning of a non-collect fw dbg data period */ 130 unsigned long non_collect_ts_start[IWL_FW_INI_TIME_POINT_NUM]; 131 u32 *d3_debug_data; 132 u32 lmac_err_id[MAX_NUM_LMAC]; 133 u32 tcm_err_id[MAX_NUM_TCM]; 134 u32 rcm_err_id[MAX_NUM_RCM]; 135 u32 umac_err_id; 136 137 struct iwl_txf_iter_data txf_iter_data; 138 139 struct { 140 u8 type; 141 u8 subtype; 142 u32 lmac_major; 143 u32 lmac_minor; 144 u32 umac_major; 145 u32 umac_minor; 146 } fw_ver; 147 } dump; 148 struct { 149 #ifdef CONFIG_IWLWIFI_DEBUGFS 150 struct delayed_work wk; 151 u32 delay; 152 #endif 153 u64 seq; 154 } timestamp; 155 #ifdef CONFIG_IWLWIFI_DEBUGFS 156 bool tpc_enabled; 157 #endif /* CONFIG_IWLWIFI_DEBUGFS */ 158 #ifdef CONFIG_ACPI 159 struct iwl_sar_profile sar_profiles[ACPI_SAR_PROFILE_NUM]; 160 u8 sar_chain_a_profile; 161 u8 sar_chain_b_profile; 162 struct iwl_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES_REV3]; 163 u32 geo_rev; 164 u32 geo_num_profiles; 165 bool geo_enabled; 166 struct iwl_ppag_chain ppag_chains[IWL_NUM_CHAIN_LIMITS]; 167 u32 ppag_flags; 168 u32 ppag_ver; 169 bool ppag_table_valid; 170 struct iwl_sar_offset_mapping_cmd sgom_table; 171 bool sgom_enabled; 172 u8 reduced_power_flags; 173 #endif 174 }; 175 176 void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans, 177 const struct iwl_fw *fw, 178 const struct iwl_fw_runtime_ops *ops, void *ops_ctx, 179 const struct iwl_dump_sanitize_ops *sanitize_ops, 180 void *sanitize_ctx, 181 struct dentry *dbgfs_dir); 182 183 static inline void iwl_fw_runtime_free(struct iwl_fw_runtime *fwrt) 184 { 185 int i; 186 187 kfree(fwrt->dump.d3_debug_data); 188 fwrt->dump.d3_debug_data = NULL; 189 190 iwl_dbg_tlv_del_timers(fwrt->trans); 191 for (i = 0; i < IWL_FW_RUNTIME_DUMP_WK_NUM; i++) 192 cancel_delayed_work_sync(&fwrt->dump.wks[i].wk); 193 } 194 195 void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt); 196 197 void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt); 198 199 static inline void iwl_fw_set_current_image(struct iwl_fw_runtime *fwrt, 200 enum iwl_ucode_type cur_fw_img) 201 { 202 fwrt->cur_fw_img = cur_fw_img; 203 } 204 205 int iwl_init_paging(struct iwl_fw_runtime *fwrt, enum iwl_ucode_type type); 206 void iwl_free_fw_paging(struct iwl_fw_runtime *fwrt); 207 208 void iwl_get_shared_mem_conf(struct iwl_fw_runtime *fwrt); 209 int iwl_set_soc_latency(struct iwl_fw_runtime *fwrt); 210 int iwl_configure_rxq(struct iwl_fw_runtime *fwrt); 211 212 #endif /* __iwl_fw_runtime_h__ */ 213