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