18e99ea8dSJohannes Berg /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 28e99ea8dSJohannes Berg /* 38e99ea8dSJohannes Berg * Copyright (C) 2017 Intel Deutschland GmbH 4b0aa02b3SAyala Barazani * Copyright (C) 2018-2022 Intel Corporation 58e99ea8dSJohannes Berg */ 6235acb18SJohannes Berg #ifndef __iwl_fw_runtime_h__ 7235acb18SJohannes Berg #define __iwl_fw_runtime_h__ 8235acb18SJohannes Berg 9235acb18SJohannes Berg #include "iwl-config.h" 10235acb18SJohannes Berg #include "iwl-trans.h" 11235acb18SJohannes Berg #include "img.h" 12d172a5efSJohannes Berg #include "fw/api/debug.h" 13d172a5efSJohannes Berg #include "fw/api/paging.h" 1439c1a972SIhab Zhaika #include "fw/api/power.h" 15c135cb56SShaul Triebitz #include "iwl-eeprom-parse.h" 1639c1a972SIhab Zhaika #include "fw/acpi.h" 17235acb18SJohannes Berg 187174beb6SJohannes Berg struct iwl_fw_runtime_ops { 19f5cdcb86SJohannes Berg void (*dump_start)(void *ctx); 207174beb6SJohannes Berg void (*dump_end)(void *ctx); 218745f12aSShaul Triebitz bool (*fw_running)(void *ctx); 22d3f4b6deSShahar S Matityahu int (*send_hcmd)(void *ctx, struct iwl_host_cmd *host_cmd); 23971377e6SShahar S Matityahu bool (*d3_debug_enable)(void *ctx); 247174beb6SJohannes Berg }; 257174beb6SJohannes Berg 26d0b813fcSJohannes Berg #define MAX_NUM_LMAC 2 27*834f920eSMukesh Sisodiya #define MAX_NUM_TCM 2 28*834f920eSMukesh Sisodiya #define MAX_NUM_RCM 2 29d0b813fcSJohannes Berg struct iwl_fwrt_shared_mem_cfg { 30d0b813fcSJohannes Berg int num_lmacs; 31d0b813fcSJohannes Berg int num_txfifo_entries; 32d0b813fcSJohannes Berg struct { 33d0b813fcSJohannes Berg u32 txfifo_size[TX_FIFO_MAX_NUM]; 34d0b813fcSJohannes Berg u32 rxfifo1_size; 35d0b813fcSJohannes Berg } lmac[MAX_NUM_LMAC]; 36d0b813fcSJohannes Berg u32 rxfifo2_size; 37ebfa7f8aSMordechay Goodstein u32 rxfifo2_control_size; 38d0b813fcSJohannes Berg u32 internal_txfifo_addr; 39d0b813fcSJohannes Berg u32 internal_txfifo_size[TX_FIFO_INTERNAL_MAX_NUM]; 40d0b813fcSJohannes Berg }; 41d0b813fcSJohannes Berg 42c7ab138eSShahar S Matityahu #define IWL_FW_RUNTIME_DUMP_WK_NUM 5 437174beb6SJohannes Berg 44235acb18SJohannes Berg /** 453b589d56SShahar S Matityahu * struct iwl_fwrt_dump_data - dump data 463b589d56SShahar S Matityahu * @trig: trigger the worker was scheduled upon 473b589d56SShahar S Matityahu * @fw_pkt: packet received from FW 483b589d56SShahar S Matityahu */ 493b589d56SShahar S Matityahu struct iwl_fwrt_dump_data { 507a99c877SShahar S Matityahu union { 517a99c877SShahar S Matityahu struct { 523b589d56SShahar S Matityahu struct iwl_fw_ini_trigger_tlv *trig; 533b589d56SShahar S Matityahu struct iwl_rx_packet *fw_pkt; 543b589d56SShahar S Matityahu }; 557a99c877SShahar S Matityahu struct { 567a99c877SShahar S Matityahu const struct iwl_fw_dump_desc *desc; 577a99c877SShahar S Matityahu bool monitor_only; 587a99c877SShahar S Matityahu }; 597a99c877SShahar S Matityahu }; 607a99c877SShahar S Matityahu }; 613b589d56SShahar S Matityahu 623b589d56SShahar S Matityahu /** 633b589d56SShahar S Matityahu * struct iwl_fwrt_wk_data - dump worker data struct 643b589d56SShahar S Matityahu * @idx: index of the worker 653b589d56SShahar S Matityahu * @wk: worker 663b589d56SShahar S Matityahu */ 673b589d56SShahar S Matityahu struct iwl_fwrt_wk_data { 683b589d56SShahar S Matityahu u8 idx; 693b589d56SShahar S Matityahu struct delayed_work wk; 703b589d56SShahar S Matityahu struct iwl_fwrt_dump_data dump_data; 713b589d56SShahar S Matityahu }; 723b589d56SShahar S Matityahu 733b589d56SShahar S Matityahu /** 74d4c444efSShahar S Matityahu * struct iwl_txf_iter_data - Tx fifo iterator data struct 75d4c444efSShahar S Matityahu * @fifo: fifo number 76d4c444efSShahar S Matityahu * @lmac: lmac number 77d4c444efSShahar S Matityahu * @fifo_size: fifo size 78d4c444efSShahar S Matityahu * @internal_txf: non zero if fifo is internal Tx fifo 79d4c444efSShahar S Matityahu */ 80d4c444efSShahar S Matityahu struct iwl_txf_iter_data { 81d4c444efSShahar S Matityahu int fifo; 82d4c444efSShahar S Matityahu int lmac; 83d4c444efSShahar S Matityahu u32 fifo_size; 84d4c444efSShahar S Matityahu u8 internal_txf; 85d4c444efSShahar S Matityahu }; 86d4c444efSShahar S Matityahu 87d4c444efSShahar S Matityahu /** 88235acb18SJohannes Berg * struct iwl_fw_runtime - runtime data for firmware 89235acb18SJohannes Berg * @fw: firmware image 90235acb18SJohannes Berg * @cfg: NIC configuration 91235acb18SJohannes Berg * @dev: device pointer 927174beb6SJohannes Berg * @ops: user ops 937174beb6SJohannes Berg * @ops_ctx: user ops context 94235acb18SJohannes Berg * @fw_paging_db: paging database 95235acb18SJohannes Berg * @num_of_paging_blk: number of paging blocks 96235acb18SJohannes Berg * @num_of_pages_in_last_blk: number of pages in the last block 97d0b813fcSJohannes Berg * @smem_cfg: saved firmware SMEM configuration 98702e975dSJohannes Berg * @cur_fw_img: current firmware image, must be maintained by 99702e975dSJohannes Berg * the driver by calling &iwl_fw_set_current_image() 1007174beb6SJohannes Berg * @dump: debug dump data 101235acb18SJohannes Berg */ 102235acb18SJohannes Berg struct iwl_fw_runtime { 103235acb18SJohannes Berg struct iwl_trans *trans; 104235acb18SJohannes Berg const struct iwl_fw *fw; 105235acb18SJohannes Berg struct device *dev; 106235acb18SJohannes Berg 1077174beb6SJohannes Berg const struct iwl_fw_runtime_ops *ops; 1087174beb6SJohannes Berg void *ops_ctx; 1097174beb6SJohannes Berg 110fdb70083SJohannes Berg const struct iwl_dump_sanitize_ops *sanitize_ops; 111fdb70083SJohannes Berg void *sanitize_ctx; 112fdb70083SJohannes Berg 113235acb18SJohannes Berg /* Paging */ 114235acb18SJohannes Berg struct iwl_fw_paging fw_paging_db[NUM_OF_FW_PAGING_BLOCKS]; 115235acb18SJohannes Berg u16 num_of_paging_blk; 116235acb18SJohannes Berg u16 num_of_pages_in_last_blk; 117d0b813fcSJohannes Berg 118702e975dSJohannes Berg enum iwl_ucode_type cur_fw_img; 119702e975dSJohannes Berg 120d0b813fcSJohannes Berg /* memory configuration */ 121d0b813fcSJohannes Berg struct iwl_fwrt_shared_mem_cfg smem_cfg; 1227174beb6SJohannes Berg 1237174beb6SJohannes Berg /* debug */ 1247174beb6SJohannes Berg struct { 1253b589d56SShahar S Matityahu struct iwl_fwrt_wk_data wks[IWL_FW_RUNTIME_DUMP_WK_NUM]; 126c7ab138eSShahar S Matityahu unsigned long active_wks; 1277174beb6SJohannes Berg 1287174beb6SJohannes Berg u8 conf; 1297174beb6SJohannes Berg 1307174beb6SJohannes Berg /* ts of the beginning of a non-collect fw dbg data period */ 1313b589d56SShahar S Matityahu unsigned long non_collect_ts_start[IWL_FW_INI_TIME_POINT_NUM]; 1322d8c2615SShahar S Matityahu u32 *d3_debug_data; 133d3561e0eSShahar S Matityahu u32 lmac_err_id[MAX_NUM_LMAC]; 134*834f920eSMukesh Sisodiya u32 tcm_err_id[MAX_NUM_TCM]; 135*834f920eSMukesh Sisodiya u32 rcm_err_id[MAX_NUM_RCM]; 136d3561e0eSShahar S Matityahu u32 umac_err_id; 137d4c444efSShahar S Matityahu 138d4c444efSShahar S Matityahu struct iwl_txf_iter_data txf_iter_data; 13957d88b11SShahar S Matityahu 1400a3a3e9eSShahar S Matityahu struct { 1410a3a3e9eSShahar S Matityahu u8 type; 1420a3a3e9eSShahar S Matityahu u8 subtype; 1430a3a3e9eSShahar S Matityahu u32 lmac_major; 1440a3a3e9eSShahar S Matityahu u32 lmac_minor; 1450a3a3e9eSShahar S Matityahu u32 umac_major; 1460a3a3e9eSShahar S Matityahu u32 umac_minor; 1470a3a3e9eSShahar S Matityahu } fw_ver; 1487174beb6SJohannes Berg } dump; 14993b167c1SMordechay Goodstein #ifdef CONFIG_IWLWIFI_DEBUGFS 15093b167c1SMordechay Goodstein struct { 15193b167c1SMordechay Goodstein struct delayed_work wk; 15293b167c1SMordechay Goodstein u32 delay; 15393b167c1SMordechay Goodstein u64 seq; 15493b167c1SMordechay Goodstein } timestamp; 15539c1a972SIhab Zhaika bool tpc_enabled; 15693b167c1SMordechay Goodstein #endif /* CONFIG_IWLWIFI_DEBUGFS */ 15739c1a972SIhab Zhaika #ifdef CONFIG_ACPI 15839c1a972SIhab Zhaika struct iwl_sar_profile sar_profiles[ACPI_SAR_PROFILE_NUM]; 15939c1a972SIhab Zhaika u8 sar_chain_a_profile; 16039c1a972SIhab Zhaika u8 sar_chain_b_profile; 16197f8a3d1SAyala Barazani struct iwl_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES_REV3]; 16239c1a972SIhab Zhaika u32 geo_rev; 163c593d2faSAyala Barazani u32 geo_num_profiles; 164c593d2faSAyala Barazani bool geo_enabled; 1658bdc52b9SMiri Korenblit struct iwl_ppag_chain ppag_chains[IWL_NUM_CHAIN_LIMITS]; 1668bdc52b9SMiri Korenblit u32 ppag_flags; 167f2134f66SGil Adam u32 ppag_ver; 168c593d2faSAyala Barazani struct iwl_sar_offset_mapping_cmd sgom_table; 169c593d2faSAyala Barazani bool sgom_enabled; 170b0aa02b3SAyala Barazani u8 reduced_power_flags; 17139c1a972SIhab Zhaika #endif 172235acb18SJohannes Berg }; 173235acb18SJohannes Berg 1747174beb6SJohannes Berg void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans, 1757174beb6SJohannes Berg const struct iwl_fw *fw, 17693b167c1SMordechay Goodstein const struct iwl_fw_runtime_ops *ops, void *ops_ctx, 177fdb70083SJohannes Berg const struct iwl_dump_sanitize_ops *sanitize_ops, 178fdb70083SJohannes Berg void *sanitize_ctx, 17993b167c1SMordechay Goodstein struct dentry *dbgfs_dir); 18093b167c1SMordechay Goodstein 18154f3f994SShahar S Matityahu static inline void iwl_fw_runtime_free(struct iwl_fw_runtime *fwrt) 18254f3f994SShahar S Matityahu { 183b61a6610SShahar S Matityahu int i; 184b61a6610SShahar S Matityahu 18554f3f994SShahar S Matityahu kfree(fwrt->dump.d3_debug_data); 18654f3f994SShahar S Matityahu fwrt->dump.d3_debug_data = NULL; 187b61a6610SShahar S Matityahu 188787350efSShahar S Matityahu iwl_dbg_tlv_del_timers(fwrt->trans); 189787350efSShahar S Matityahu for (i = 0; i < IWL_FW_RUNTIME_DUMP_WK_NUM; i++) 190787350efSShahar S Matityahu cancel_delayed_work_sync(&fwrt->dump.wks[i].wk); 19154f3f994SShahar S Matityahu } 192235acb18SJohannes Berg 1937f8ae00fSHaim Dreyfuss void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt); 1947f8ae00fSHaim Dreyfuss 1957f8ae00fSHaim Dreyfuss void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt); 1967f8ae00fSHaim Dreyfuss 197702e975dSJohannes Berg static inline void iwl_fw_set_current_image(struct iwl_fw_runtime *fwrt, 198702e975dSJohannes Berg enum iwl_ucode_type cur_fw_img) 199702e975dSJohannes Berg { 200702e975dSJohannes Berg fwrt->cur_fw_img = cur_fw_img; 201702e975dSJohannes Berg } 202702e975dSJohannes Berg 203235acb18SJohannes Berg int iwl_init_paging(struct iwl_fw_runtime *fwrt, enum iwl_ucode_type type); 204235acb18SJohannes Berg void iwl_free_fw_paging(struct iwl_fw_runtime *fwrt); 205235acb18SJohannes Berg 206d0b813fcSJohannes Berg void iwl_get_shared_mem_conf(struct iwl_fw_runtime *fwrt); 207a8eb340fSEmmanuel Grumbach int iwl_set_soc_latency(struct iwl_fw_runtime *fwrt); 2089cd243f2SMordechay Goodstein int iwl_configure_rxq(struct iwl_fw_runtime *fwrt); 209d0b813fcSJohannes Berg 210235acb18SJohannes Berg #endif /* __iwl_fw_runtime_h__ */ 211