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 	/* Paging */
109 	struct iwl_fw_paging fw_paging_db[NUM_OF_FW_PAGING_BLOCKS];
110 	u16 num_of_paging_blk;
111 	u16 num_of_pages_in_last_blk;
112 
113 	enum iwl_ucode_type cur_fw_img;
114 
115 	/* memory configuration */
116 	struct iwl_fwrt_shared_mem_cfg smem_cfg;
117 
118 	/* debug */
119 	struct {
120 		struct iwl_fwrt_wk_data wks[IWL_FW_RUNTIME_DUMP_WK_NUM];
121 		unsigned long active_wks;
122 
123 		u8 conf;
124 
125 		/* ts of the beginning of a non-collect fw dbg data period */
126 		unsigned long non_collect_ts_start[IWL_FW_INI_TIME_POINT_NUM];
127 		u32 *d3_debug_data;
128 		u32 lmac_err_id[MAX_NUM_LMAC];
129 		u32 umac_err_id;
130 
131 		struct iwl_txf_iter_data txf_iter_data;
132 
133 		struct {
134 			u8 type;
135 			u8 subtype;
136 			u32 lmac_major;
137 			u32 lmac_minor;
138 			u32 umac_major;
139 			u32 umac_minor;
140 		} fw_ver;
141 	} dump;
142 #ifdef CONFIG_IWLWIFI_DEBUGFS
143 	struct {
144 		struct delayed_work wk;
145 		u32 delay;
146 		u64 seq;
147 	} timestamp;
148 	bool tpc_enabled;
149 #endif /* CONFIG_IWLWIFI_DEBUGFS */
150 #ifdef CONFIG_ACPI
151 	struct iwl_sar_profile sar_profiles[ACPI_SAR_PROFILE_NUM];
152 	u8 sar_chain_a_profile;
153 	u8 sar_chain_b_profile;
154 	struct iwl_geo_profile geo_profiles[ACPI_NUM_GEO_PROFILES];
155 	u32 geo_rev;
156 	union iwl_ppag_table_cmd ppag_table;
157 	u32 ppag_ver;
158 #endif
159 };
160 
161 void iwl_fw_runtime_init(struct iwl_fw_runtime *fwrt, struct iwl_trans *trans,
162 			const struct iwl_fw *fw,
163 			const struct iwl_fw_runtime_ops *ops, void *ops_ctx,
164 			struct dentry *dbgfs_dir);
165 
166 static inline void iwl_fw_runtime_free(struct iwl_fw_runtime *fwrt)
167 {
168 	int i;
169 
170 	kfree(fwrt->dump.d3_debug_data);
171 	fwrt->dump.d3_debug_data = NULL;
172 
173 	iwl_dbg_tlv_del_timers(fwrt->trans);
174 	for (i = 0; i < IWL_FW_RUNTIME_DUMP_WK_NUM; i++)
175 		cancel_delayed_work_sync(&fwrt->dump.wks[i].wk);
176 }
177 
178 void iwl_fw_runtime_suspend(struct iwl_fw_runtime *fwrt);
179 
180 void iwl_fw_runtime_resume(struct iwl_fw_runtime *fwrt);
181 
182 static inline void iwl_fw_set_current_image(struct iwl_fw_runtime *fwrt,
183 					    enum iwl_ucode_type cur_fw_img)
184 {
185 	fwrt->cur_fw_img = cur_fw_img;
186 }
187 
188 int iwl_init_paging(struct iwl_fw_runtime *fwrt, enum iwl_ucode_type type);
189 void iwl_free_fw_paging(struct iwl_fw_runtime *fwrt);
190 
191 void iwl_get_shared_mem_conf(struct iwl_fw_runtime *fwrt);
192 int iwl_set_soc_latency(struct iwl_fw_runtime *fwrt);
193 int iwl_configure_rxq(struct iwl_fw_runtime *fwrt);
194 
195 #endif /* __iwl_fw_runtime_h__ */
196