18e99ea8dSJohannes Berg /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
28e99ea8dSJohannes Berg /*
38e99ea8dSJohannes Berg * Copyright (C) 2017 Intel Deutschland GmbH
4*eeef0168SMiri Korenblit * Copyright (C) 2018-2023 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);
21d3f4b6deSShahar S Matityahu int (*send_hcmd)(void *ctx, struct iwl_host_cmd *host_cmd);
22971377e6SShahar S Matityahu bool (*d3_debug_enable)(void *ctx);
237174beb6SJohannes Berg };
247174beb6SJohannes Berg
25d0b813fcSJohannes Berg #define MAX_NUM_LMAC 2
26834f920eSMukesh Sisodiya #define MAX_NUM_TCM 2
27834f920eSMukesh Sisodiya #define MAX_NUM_RCM 2
28d0b813fcSJohannes Berg struct iwl_fwrt_shared_mem_cfg {
29d0b813fcSJohannes Berg int num_lmacs;
30d0b813fcSJohannes Berg int num_txfifo_entries;
31d0b813fcSJohannes Berg struct {
32d0b813fcSJohannes Berg u32 txfifo_size[TX_FIFO_MAX_NUM];
33d0b813fcSJohannes Berg u32 rxfifo1_size;
34d0b813fcSJohannes Berg } lmac[MAX_NUM_LMAC];
35d0b813fcSJohannes Berg u32 rxfifo2_size;
36ebfa7f8aSMordechay Goodstein u32 rxfifo2_control_size;
37d0b813fcSJohannes Berg u32 internal_txfifo_addr;
38d0b813fcSJohannes Berg u32 internal_txfifo_size[TX_FIFO_INTERNAL_MAX_NUM];
39d0b813fcSJohannes Berg };
40d0b813fcSJohannes Berg
41c7ab138eSShahar S Matityahu #define IWL_FW_RUNTIME_DUMP_WK_NUM 5
427174beb6SJohannes Berg
43235acb18SJohannes Berg /**
443b589d56SShahar S Matityahu * struct iwl_fwrt_dump_data - dump data
453b589d56SShahar S Matityahu * @trig: trigger the worker was scheduled upon
463b589d56SShahar S Matityahu * @fw_pkt: packet received from FW
473b589d56SShahar S Matityahu */
483b589d56SShahar S Matityahu struct iwl_fwrt_dump_data {
497a99c877SShahar S Matityahu union {
507a99c877SShahar S Matityahu struct {
513b589d56SShahar S Matityahu struct iwl_fw_ini_trigger_tlv *trig;
523b589d56SShahar S Matityahu struct iwl_rx_packet *fw_pkt;
533b589d56SShahar S Matityahu };
547a99c877SShahar S Matityahu struct {
557a99c877SShahar S Matityahu const struct iwl_fw_dump_desc *desc;
567a99c877SShahar S Matityahu bool monitor_only;
577a99c877SShahar S Matityahu };
587a99c877SShahar S Matityahu };
597a99c877SShahar S Matityahu };
603b589d56SShahar S Matityahu
613b589d56SShahar S Matityahu /**
623b589d56SShahar S Matityahu * struct iwl_fwrt_wk_data - dump worker data struct
633b589d56SShahar S Matityahu * @idx: index of the worker
643b589d56SShahar S Matityahu * @wk: worker
653b589d56SShahar S Matityahu */
663b589d56SShahar S Matityahu struct iwl_fwrt_wk_data {
673b589d56SShahar S Matityahu u8 idx;
683b589d56SShahar S Matityahu struct delayed_work wk;
693b589d56SShahar S Matityahu struct iwl_fwrt_dump_data dump_data;
703b589d56SShahar S Matityahu };
713b589d56SShahar S Matityahu
723b589d56SShahar S Matityahu /**
73d4c444efSShahar S Matityahu * struct iwl_txf_iter_data - Tx fifo iterator data struct
74d4c444efSShahar S Matityahu * @fifo: fifo number
75d4c444efSShahar S Matityahu * @lmac: lmac number
76d4c444efSShahar S Matityahu * @fifo_size: fifo size
77d4c444efSShahar S Matityahu * @internal_txf: non zero if fifo is internal Tx fifo
78d4c444efSShahar S Matityahu */
79d4c444efSShahar S Matityahu struct iwl_txf_iter_data {
80d4c444efSShahar S Matityahu int fifo;
81d4c444efSShahar S Matityahu int lmac;
82d4c444efSShahar S Matityahu u32 fifo_size;
83d4c444efSShahar S Matityahu u8 internal_txf;
84d4c444efSShahar S Matityahu };
85d4c444efSShahar S Matityahu
86d4c444efSShahar S Matityahu /**
87235acb18SJohannes Berg * struct iwl_fw_runtime - runtime data for firmware
88235acb18SJohannes Berg * @fw: firmware image
89235acb18SJohannes Berg * @cfg: NIC configuration
90235acb18SJohannes Berg * @dev: device pointer
917174beb6SJohannes Berg * @ops: user ops
927174beb6SJohannes Berg * @ops_ctx: user ops context
93235acb18SJohannes Berg * @fw_paging_db: paging database
94235acb18SJohannes Berg * @num_of_paging_blk: number of paging blocks
95235acb18SJohannes Berg * @num_of_pages_in_last_blk: number of pages in the last block
96d0b813fcSJohannes Berg * @smem_cfg: saved firmware SMEM configuration
97702e975dSJohannes Berg * @cur_fw_img: current firmware image, must be maintained by
98702e975dSJohannes Berg * the driver by calling &iwl_fw_set_current_image()
997174beb6SJohannes Berg * @dump: debug dump data
100235acb18SJohannes Berg */
101235acb18SJohannes Berg struct iwl_fw_runtime {
102235acb18SJohannes Berg struct iwl_trans *trans;
103235acb18SJohannes Berg const struct iwl_fw *fw;
104235acb18SJohannes Berg struct device *dev;
105235acb18SJohannes Berg
1067174beb6SJohannes Berg const struct iwl_fw_runtime_ops *ops;
1077174beb6SJohannes Berg void *ops_ctx;
1087174beb6SJohannes Berg
109fdb70083SJohannes Berg const struct iwl_dump_sanitize_ops *sanitize_ops;
110fdb70083SJohannes Berg void *sanitize_ctx;
111fdb70083SJohannes Berg
112235acb18SJohannes Berg /* Paging */
113235acb18SJohannes Berg struct iwl_fw_paging fw_paging_db[NUM_OF_FW_PAGING_BLOCKS];
114235acb18SJohannes Berg u16 num_of_paging_blk;
115235acb18SJohannes Berg u16 num_of_pages_in_last_blk;
116d0b813fcSJohannes Berg
117702e975dSJohannes Berg enum iwl_ucode_type cur_fw_img;
118702e975dSJohannes Berg
119d0b813fcSJohannes Berg /* memory configuration */
120d0b813fcSJohannes Berg struct iwl_fwrt_shared_mem_cfg smem_cfg;
1217174beb6SJohannes Berg
1227174beb6SJohannes Berg /* debug */
1237174beb6SJohannes Berg struct {
1243b589d56SShahar S Matityahu struct iwl_fwrt_wk_data wks[IWL_FW_RUNTIME_DUMP_WK_NUM];
125c7ab138eSShahar S Matityahu unsigned long active_wks;
1267174beb6SJohannes Berg
1277174beb6SJohannes Berg u8 conf;
1287174beb6SJohannes Berg
1297174beb6SJohannes Berg /* ts of the beginning of a non-collect fw dbg data period */
1303b589d56SShahar S Matityahu unsigned long non_collect_ts_start[IWL_FW_INI_TIME_POINT_NUM];
1312d8c2615SShahar S Matityahu u32 *d3_debug_data;
132d3561e0eSShahar S Matityahu u32 lmac_err_id[MAX_NUM_LMAC];
133834f920eSMukesh Sisodiya u32 tcm_err_id[MAX_NUM_TCM];
134834f920eSMukesh Sisodiya u32 rcm_err_id[MAX_NUM_RCM];
135d3561e0eSShahar S Matityahu u32 umac_err_id;
136d4c444efSShahar S Matityahu
137d4c444efSShahar S Matityahu struct iwl_txf_iter_data txf_iter_data;
13857d88b11SShahar S Matityahu
1390a3a3e9eSShahar S Matityahu struct {
1400a3a3e9eSShahar S Matityahu u8 type;
1410a3a3e9eSShahar S Matityahu u8 subtype;
1420a3a3e9eSShahar S Matityahu u32 lmac_major;
1430a3a3e9eSShahar S Matityahu u32 lmac_minor;
1440a3a3e9eSShahar S Matityahu u32 umac_major;
1450a3a3e9eSShahar S Matityahu u32 umac_minor;
1460a3a3e9eSShahar S Matityahu } fw_ver;
1477174beb6SJohannes Berg } dump;
14893b167c1SMordechay Goodstein struct {
149*eeef0168SMiri Korenblit #ifdef CONFIG_IWLWIFI_DEBUGFS
15093b167c1SMordechay Goodstein struct delayed_work wk;
15193b167c1SMordechay Goodstein u32 delay;
152*eeef0168SMiri Korenblit #endif
15393b167c1SMordechay Goodstein u64 seq;
15493b167c1SMordechay Goodstein } timestamp;
155*eeef0168SMiri Korenblit #ifdef CONFIG_IWLWIFI_DEBUGFS
15639c1a972SIhab Zhaika bool tpc_enabled;
15793b167c1SMordechay Goodstein #endif /* CONFIG_IWLWIFI_DEBUGFS */
15839c1a972SIhab Zhaika #ifdef CONFIG_ACPI
15939c1a972SIhab Zhaika struct iwl_sar_profile sar_profiles[ACPI_SAR_PROFILE_NUM];
16039c1a972SIhab Zhaika u8 sar_chain_a_profile;
16139c1a972SIhab Zhaika u8 sar_chain_b_profile;
16297f8a3d1SAyala Barazani struct iwl_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES_REV3];
16339c1a972SIhab Zhaika u32 geo_rev;
164c593d2faSAyala Barazani u32 geo_num_profiles;
165c593d2faSAyala Barazani bool geo_enabled;
1668bdc52b9SMiri Korenblit struct iwl_ppag_chain ppag_chains[IWL_NUM_CHAIN_LIMITS];
1678bdc52b9SMiri Korenblit u32 ppag_flags;
168f2134f66SGil Adam u32 ppag_ver;
1691843676aSAlon Giladi bool ppag_table_valid;
170c593d2faSAyala Barazani struct iwl_sar_offset_mapping_cmd sgom_table;
171c593d2faSAyala Barazani bool sgom_enabled;
172b0aa02b3SAyala Barazani u8 reduced_power_flags;
17339c1a972SIhab Zhaika #endif
174235acb18SJohannes Berg };
175235acb18SJohannes Berg
1767174beb6SJohannes Berg void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans,
1777174beb6SJohannes Berg const struct iwl_fw *fw,
17893b167c1SMordechay Goodstein const struct iwl_fw_runtime_ops *ops, void *ops_ctx,
179fdb70083SJohannes Berg const struct iwl_dump_sanitize_ops *sanitize_ops,
180fdb70083SJohannes Berg void *sanitize_ctx,
18193b167c1SMordechay Goodstein struct dentry *dbgfs_dir);
18293b167c1SMordechay Goodstein
iwl_fw_runtime_free(struct iwl_fw_runtime * fwrt)18354f3f994SShahar S Matityahu static inline void iwl_fw_runtime_free(struct iwl_fw_runtime *fwrt)
18454f3f994SShahar S Matityahu {
185b61a6610SShahar S Matityahu int i;
186b61a6610SShahar S Matityahu
18754f3f994SShahar S Matityahu kfree(fwrt->dump.d3_debug_data);
18854f3f994SShahar S Matityahu fwrt->dump.d3_debug_data = NULL;
189b61a6610SShahar S Matityahu
190787350efSShahar S Matityahu iwl_dbg_tlv_del_timers(fwrt->trans);
191787350efSShahar S Matityahu for (i = 0; i < IWL_FW_RUNTIME_DUMP_WK_NUM; i++)
192787350efSShahar S Matityahu cancel_delayed_work_sync(&fwrt->dump.wks[i].wk);
19354f3f994SShahar S Matityahu }
194235acb18SJohannes Berg
1957f8ae00fSHaim Dreyfuss void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt);
1967f8ae00fSHaim Dreyfuss
1977f8ae00fSHaim Dreyfuss void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt);
1987f8ae00fSHaim Dreyfuss
iwl_fw_set_current_image(struct iwl_fw_runtime * fwrt,enum iwl_ucode_type cur_fw_img)199702e975dSJohannes Berg static inline void iwl_fw_set_current_image(struct iwl_fw_runtime *fwrt,
200702e975dSJohannes Berg enum iwl_ucode_type cur_fw_img)
201702e975dSJohannes Berg {
202702e975dSJohannes Berg fwrt->cur_fw_img = cur_fw_img;
203702e975dSJohannes Berg }
204702e975dSJohannes Berg
205235acb18SJohannes Berg int iwl_init_paging(struct iwl_fw_runtime *fwrt, enum iwl_ucode_type type);
206235acb18SJohannes Berg void iwl_free_fw_paging(struct iwl_fw_runtime *fwrt);
207235acb18SJohannes Berg
208d0b813fcSJohannes Berg void iwl_get_shared_mem_conf(struct iwl_fw_runtime *fwrt);
209a8eb340fSEmmanuel Grumbach int iwl_set_soc_latency(struct iwl_fw_runtime *fwrt);
2109cd243f2SMordechay Goodstein int iwl_configure_rxq(struct iwl_fw_runtime *fwrt);
211d0b813fcSJohannes Berg
212235acb18SJohannes Berg #endif /* __iwl_fw_runtime_h__ */
213