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