1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2017 Intel Deutschland GmbH
4  * Copyright (C) 2018-2021 Intel Corporation
5  */
6 #ifndef __iwl_fw_acpi__
7 #define __iwl_fw_acpi__
8 
9 #include <linux/acpi.h>
10 #include "fw/api/commands.h"
11 #include "fw/api/power.h"
12 #include "fw/api/phy.h"
13 #include "fw/api/nvm-reg.h"
14 #include "fw/img.h"
15 #include "iwl-trans.h"
16 
17 
18 #define ACPI_WRDS_METHOD	"WRDS"
19 #define ACPI_EWRD_METHOD	"EWRD"
20 #define ACPI_WGDS_METHOD	"WGDS"
21 #define ACPI_WRDD_METHOD	"WRDD"
22 #define ACPI_SPLC_METHOD	"SPLC"
23 #define ACPI_ECKV_METHOD	"ECKV"
24 #define ACPI_PPAG_METHOD	"PPAG"
25 #define ACPI_WTAS_METHOD	"WTAS"
26 
27 #define ACPI_WIFI_DOMAIN	(0x07)
28 
29 #define ACPI_SAR_PROFILE_NUM		4
30 
31 #define ACPI_NUM_GEO_PROFILES		3
32 #define ACPI_NUM_GEO_PROFILES_REV3	8
33 #define ACPI_GEO_PER_CHAIN_SIZE		3
34 
35 #define ACPI_SAR_NUM_CHAINS_REV0	2
36 #define ACPI_SAR_NUM_CHAINS_REV1	2
37 #define ACPI_SAR_NUM_CHAINS_REV2	4
38 #define ACPI_SAR_NUM_SUB_BANDS_REV0	5
39 #define ACPI_SAR_NUM_SUB_BANDS_REV1	11
40 #define ACPI_SAR_NUM_SUB_BANDS_REV2	11
41 
42 #define ACPI_WRDS_WIFI_DATA_SIZE_REV0	(ACPI_SAR_NUM_CHAINS_REV0 * \
43 					 ACPI_SAR_NUM_SUB_BANDS_REV0 + 2)
44 #define ACPI_WRDS_WIFI_DATA_SIZE_REV1	(ACPI_SAR_NUM_CHAINS_REV1 * \
45 					 ACPI_SAR_NUM_SUB_BANDS_REV1 + 2)
46 #define ACPI_WRDS_WIFI_DATA_SIZE_REV2	(ACPI_SAR_NUM_CHAINS_REV2 * \
47 					 ACPI_SAR_NUM_SUB_BANDS_REV2 + 2)
48 #define ACPI_EWRD_WIFI_DATA_SIZE_REV0	((ACPI_SAR_PROFILE_NUM - 1) * \
49 					 ACPI_SAR_NUM_CHAINS_REV0 * \
50 					 ACPI_SAR_NUM_SUB_BANDS_REV0 + 3)
51 #define ACPI_EWRD_WIFI_DATA_SIZE_REV1	((ACPI_SAR_PROFILE_NUM - 1) * \
52 					 ACPI_SAR_NUM_CHAINS_REV1 * \
53 					 ACPI_SAR_NUM_SUB_BANDS_REV1 + 3)
54 #define ACPI_EWRD_WIFI_DATA_SIZE_REV2	((ACPI_SAR_PROFILE_NUM - 1) * \
55 					 ACPI_SAR_NUM_CHAINS_REV2 * \
56 					 ACPI_SAR_NUM_SUB_BANDS_REV2 + 3)
57 
58 /* revision 0 and 1 are identical, except for the semantics in the FW */
59 #define ACPI_GEO_NUM_BANDS_REV0		2
60 #define ACPI_GEO_NUM_BANDS_REV2		3
61 #define ACPI_GEO_NUM_CHAINS		2
62 
63 #define ACPI_WRDD_WIFI_DATA_SIZE	2
64 #define ACPI_SPLC_WIFI_DATA_SIZE	2
65 #define ACPI_ECKV_WIFI_DATA_SIZE	2
66 
67 /*
68  * TAS size: 1 elelment for type,
69  *	     1 element for enabled field,
70  *	     1 element for block list size,
71  *	     16 elements for block list array
72  */
73 #define APCI_WTAS_BLACK_LIST_MAX	16
74 #define ACPI_WTAS_WIFI_DATA_SIZE	(3 + APCI_WTAS_BLACK_LIST_MAX)
75 #define ACPI_WTAS_ENABLED_MSK		0x1
76 #define ACPI_WTAS_OVERRIDE_IEC_MSK	0x2
77 #define ACPI_WTAS_ENABLE_IEC_MSK	0x4
78 #define ACPI_WTAS_OVERRIDE_IEC_POS	0x1
79 #define ACPI_WTAS_ENABLE_IEC_POS	0x2
80 
81 
82 #define ACPI_PPAG_WIFI_DATA_SIZE_V1	((IWL_NUM_CHAIN_LIMITS * \
83 					  IWL_NUM_SUB_BANDS_V1) + 2)
84 #define ACPI_PPAG_WIFI_DATA_SIZE_V2	((IWL_NUM_CHAIN_LIMITS * \
85 					  IWL_NUM_SUB_BANDS_V2) + 2)
86 
87 /* PPAG gain value bounds in 1/8 dBm */
88 #define ACPI_PPAG_MIN_LB -16
89 #define ACPI_PPAG_MAX_LB 24
90 #define ACPI_PPAG_MIN_HB -16
91 #define ACPI_PPAG_MAX_HB 40
92 
93 /*
94  * The profile for revision 2 is a superset of revision 1, which is in
95  * turn a superset of revision 0.  So we can store all revisions
96  * inside revision 2, which is what we represent here.
97  */
98 struct iwl_sar_profile_chain {
99 	u8 subbands[ACPI_SAR_NUM_SUB_BANDS_REV2];
100 };
101 
102 struct iwl_sar_profile {
103 	bool enabled;
104 	struct iwl_sar_profile_chain chains[ACPI_SAR_NUM_CHAINS_REV2];
105 };
106 
107 /* Same thing as with SAR, all revisions fit in revision 2 */
108 struct iwl_geo_profile_band {
109 	u8 max;
110 	u8 chains[ACPI_GEO_NUM_CHAINS];
111 };
112 
113 struct iwl_geo_profile {
114 	struct iwl_geo_profile_band bands[ACPI_GEO_NUM_BANDS_REV2];
115 };
116 
117 /* Same thing as with SAR, all revisions fit in revision 2 */
118 struct iwl_ppag_chain {
119 	s8 subbands[ACPI_SAR_NUM_SUB_BANDS_REV2];
120 };
121 
122 enum iwl_dsm_funcs_rev_0 {
123 	DSM_FUNC_QUERY = 0,
124 	DSM_FUNC_DISABLE_SRD = 1,
125 	DSM_FUNC_ENABLE_INDONESIA_5G2 = 2,
126 	DSM_FUNC_ENABLE_6E = 3,
127 	DSM_FUNC_11AX_ENABLEMENT = 6,
128 	DSM_FUNC_ENABLE_UNII4_CHAN = 7,
129 	DSM_FUNC_ACTIVATE_CHANNEL = 8
130 };
131 
132 enum iwl_dsm_values_srd {
133 	DSM_VALUE_SRD_ACTIVE,
134 	DSM_VALUE_SRD_PASSIVE,
135 	DSM_VALUE_SRD_DISABLE,
136 	DSM_VALUE_SRD_MAX
137 };
138 
139 enum iwl_dsm_values_indonesia {
140 	DSM_VALUE_INDONESIA_DISABLE,
141 	DSM_VALUE_INDONESIA_ENABLE,
142 	DSM_VALUE_INDONESIA_RESERVED,
143 	DSM_VALUE_INDONESIA_MAX
144 };
145 
146 /* DSM RFI uses a different GUID, so need separate definitions */
147 
148 #define DSM_RFI_FUNC_ENABLE 3
149 
150 enum iwl_dsm_values_rfi {
151 	DSM_VALUE_RFI_ENABLE,
152 	DSM_VALUE_RFI_DISABLE,
153 	DSM_VALUE_RFI_MAX
154 };
155 
156 #ifdef CONFIG_ACPI
157 
158 struct iwl_fw_runtime;
159 
160 extern const guid_t iwl_guid;
161 extern const guid_t iwl_rfi_guid;
162 
163 void *iwl_acpi_get_object(struct device *dev, acpi_string method);
164 
165 int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
166 			const guid_t *guid, u8 *value);
167 
168 int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
169 			 const guid_t *guid, u32 *value);
170 
171 union acpi_object *iwl_acpi_get_wifi_pkg_range(struct device *dev,
172 					       union acpi_object *data,
173 					       int min_data_size,
174 					       int max_data_size,
175 					       int *tbl_rev);
176 /**
177  * iwl_acpi_get_mcc - read MCC from ACPI, if available
178  *
179  * @dev: the struct device
180  * @mcc: output buffer (3 bytes) that will get the MCC
181  *
182  * This function tries to read the current MCC from ACPI if available.
183  */
184 int iwl_acpi_get_mcc(struct device *dev, char *mcc);
185 
186 u64 iwl_acpi_get_pwr_limit(struct device *dev);
187 
188 /*
189  * iwl_acpi_get_eckv - read external clock validation from ACPI, if available
190  *
191  * @dev: the struct device
192  * @extl_clk: output var (2 bytes) that will get the clk indication.
193  *
194  * This function tries to read the external clock indication
195  * from ACPI if available.
196  */
197 int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk);
198 
199 int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
200 			   __le16 *per_chain, u32 n_tables, u32 n_subbands,
201 			   int prof_a, int prof_b);
202 
203 int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt);
204 
205 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt);
206 
207 int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt);
208 
209 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt);
210 
211 int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
212 		     struct iwl_per_chain_offset *table,
213 		     u32 n_bands, u32 n_profiles);
214 
215 int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
216 		     struct iwl_tas_config_cmd_v3 *cmd);
217 
218 __le32 iwl_acpi_get_lari_config_bitmap(struct iwl_fw_runtime *fwrt);
219 
220 #else /* CONFIG_ACPI */
221 
222 static inline void *iwl_acpi_get_object(struct device *dev, acpi_string method)
223 {
224 	return ERR_PTR(-ENOENT);
225 }
226 
227 static inline void *iwl_acpi_get_dsm_object(struct device *dev, int rev,
228 					    int func, union acpi_object *args)
229 {
230 	return ERR_PTR(-ENOENT);
231 }
232 
233 static inline int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
234 				      const guid_t *guid, u8 *value)
235 {
236 	return -ENOENT;
237 }
238 
239 static inline int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
240 				       const guid_t *guid, u32 *value)
241 {
242 	return -ENOENT;
243 }
244 
245 static inline union acpi_object *
246 iwl_acpi_get_wifi_pkg_range(struct device *dev,
247 			    union acpi_object *data,
248 			    int min_data_size, int max_data_size,
249 			    int *tbl_rev)
250 {
251 	return ERR_PTR(-ENOENT);
252 }
253 
254 static inline int iwl_acpi_get_mcc(struct device *dev, char *mcc)
255 {
256 	return -ENOENT;
257 }
258 
259 static inline u64 iwl_acpi_get_pwr_limit(struct device *dev)
260 {
261 	return 0;
262 }
263 
264 static inline int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
265 {
266 	return -ENOENT;
267 }
268 
269 static inline int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
270 			   __le16 *per_chain, u32 n_tables, u32 n_subbands,
271 			   int prof_a, int prof_b)
272 {
273 	return -ENOENT;
274 }
275 
276 static inline int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt)
277 {
278 	return -ENOENT;
279 }
280 
281 static inline int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt)
282 {
283 	return -ENOENT;
284 }
285 
286 static inline int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
287 {
288 	return 1;
289 }
290 
291 static inline bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
292 {
293 	return false;
294 }
295 
296 static inline int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
297 				   struct iwl_tas_config_cmd_v3 *cmd)
298 {
299 	return -ENOENT;
300 }
301 
302 static inline __le32 iwl_acpi_get_lari_config_bitmap(struct iwl_fw_runtime *fwrt)
303 {
304 	return 0;
305 }
306 
307 #endif /* CONFIG_ACPI */
308 
309 static inline union acpi_object *
310 iwl_acpi_get_wifi_pkg(struct device *dev,
311 		      union acpi_object *data,
312 		      int data_size, int *tbl_rev)
313 {
314 	return iwl_acpi_get_wifi_pkg_range(dev, data, data_size, data_size,
315 					   tbl_rev);
316 }
317 
318 #endif /* __iwl_fw_acpi__ */
319