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 * 1 type, 1 enabled, 1 block list size, 16 block list array
69 */
70 #define APCI_WTAS_BLACK_LIST_MAX 16
71 #define ACPI_WTAS_WIFI_DATA_SIZE (3 + APCI_WTAS_BLACK_LIST_MAX)
72
73 #define ACPI_PPAG_WIFI_DATA_SIZE_V1 ((IWL_NUM_CHAIN_LIMITS * \
74 IWL_NUM_SUB_BANDS_V1) + 2)
75 #define ACPI_PPAG_WIFI_DATA_SIZE_V2 ((IWL_NUM_CHAIN_LIMITS * \
76 IWL_NUM_SUB_BANDS_V2) + 2)
77
78 /* PPAG gain value bounds in 1/8 dBm */
79 #define ACPI_PPAG_MIN_LB -16
80 #define ACPI_PPAG_MAX_LB 24
81 #define ACPI_PPAG_MIN_HB -16
82 #define ACPI_PPAG_MAX_HB 40
83
84 /*
85 * The profile for revision 2 is a superset of revision 1, which is in
86 * turn a superset of revision 0. So we can store all revisions
87 * inside revision 2, which is what we represent here.
88 */
89 struct iwl_sar_profile_chain {
90 u8 subbands[ACPI_SAR_NUM_SUB_BANDS_REV2];
91 };
92
93 struct iwl_sar_profile {
94 bool enabled;
95 struct iwl_sar_profile_chain chains[ACPI_SAR_NUM_CHAINS_REV2];
96 };
97
98 /* Same thing as with SAR, all revisions fit in revision 2 */
99 struct iwl_geo_profile_band {
100 u8 max;
101 u8 chains[ACPI_GEO_NUM_CHAINS];
102 };
103
104 struct iwl_geo_profile {
105 struct iwl_geo_profile_band bands[ACPI_GEO_NUM_BANDS_REV2];
106 };
107
108 enum iwl_dsm_funcs_rev_0 {
109 DSM_FUNC_QUERY = 0,
110 DSM_FUNC_DISABLE_SRD = 1,
111 DSM_FUNC_ENABLE_INDONESIA_5G2 = 2,
112 DSM_FUNC_ENABLE_6E = 3,
113 DSM_FUNC_11AX_ENABLEMENT = 6,
114 DSM_FUNC_ENABLE_UNII4_CHAN = 7,
115 DSM_FUNC_ACTIVATE_CHANNEL = 8
116 };
117
118 enum iwl_dsm_values_srd {
119 DSM_VALUE_SRD_ACTIVE,
120 DSM_VALUE_SRD_PASSIVE,
121 DSM_VALUE_SRD_DISABLE,
122 DSM_VALUE_SRD_MAX
123 };
124
125 enum iwl_dsm_values_indonesia {
126 DSM_VALUE_INDONESIA_DISABLE,
127 DSM_VALUE_INDONESIA_ENABLE,
128 DSM_VALUE_INDONESIA_RESERVED,
129 DSM_VALUE_INDONESIA_MAX
130 };
131
132 /* DSM RFI uses a different GUID, so need separate definitions */
133
134 #define DSM_RFI_FUNC_ENABLE 3
135
136 enum iwl_dsm_values_rfi {
137 DSM_VALUE_RFI_ENABLE,
138 DSM_VALUE_RFI_DISABLE,
139 DSM_VALUE_RFI_MAX
140 };
141
142 #ifdef CONFIG_ACPI
143
144 struct iwl_fw_runtime;
145
146 extern const guid_t iwl_guid;
147 extern const guid_t iwl_rfi_guid;
148
149 void *iwl_acpi_get_object(struct device *dev, acpi_string method);
150
151 int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
152 const guid_t *guid, u8 *value);
153
154 int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
155 const guid_t *guid, u32 *value);
156
157 union acpi_object *iwl_acpi_get_wifi_pkg_range(struct device *dev,
158 union acpi_object *data,
159 int min_data_size,
160 int max_data_size,
161 int *tbl_rev);
162 /**
163 * iwl_acpi_get_mcc - read MCC from ACPI, if available
164 *
165 * @dev: the struct device
166 * @mcc: output buffer (3 bytes) that will get the MCC
167 *
168 * This function tries to read the current MCC from ACPI if available.
169 */
170 int iwl_acpi_get_mcc(struct device *dev, char *mcc);
171
172 u64 iwl_acpi_get_pwr_limit(struct device *dev);
173
174 /*
175 * iwl_acpi_get_eckv - read external clock validation from ACPI, if available
176 *
177 * @dev: the struct device
178 * @extl_clk: output var (2 bytes) that will get the clk indication.
179 *
180 * This function tries to read the external clock indication
181 * from ACPI if available.
182 */
183 int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk);
184
185 int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
186 __le16 *per_chain, u32 n_tables, u32 n_subbands,
187 int prof_a, int prof_b);
188
189 int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt);
190
191 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt);
192
193 int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt);
194
195 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt);
196
197 int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
198 struct iwl_per_chain_offset *table,
199 u32 n_bands, u32 n_profiles);
200
201 int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt, __le32 *block_list_array,
202 int *block_list_size);
203
204 __le32 iwl_acpi_get_lari_config_bitmap(struct iwl_fw_runtime *fwrt);
205
206 #else /* CONFIG_ACPI */
207
iwl_acpi_get_object(struct device * dev,acpi_string method)208 static inline void *iwl_acpi_get_object(struct device *dev, acpi_string method)
209 {
210 return ERR_PTR(-ENOENT);
211 }
212
iwl_acpi_get_dsm_object(struct device * dev,int rev,int func,union acpi_object * args)213 static inline void *iwl_acpi_get_dsm_object(struct device *dev, int rev,
214 int func, union acpi_object *args)
215 {
216 return ERR_PTR(-ENOENT);
217 }
218
iwl_acpi_get_dsm_u8(struct device * dev,int rev,int func,const guid_t * guid,u8 * value)219 static inline int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
220 const guid_t *guid, u8 *value)
221 {
222 return -ENOENT;
223 }
224
iwl_acpi_get_dsm_u32(struct device * dev,int rev,int func,const guid_t * guid,u32 * value)225 static inline int iwl_acpi_get_dsm_u32(struct device *dev, int rev, int func,
226 const guid_t *guid, u32 *value)
227 {
228 return -ENOENT;
229 }
230
231 static inline union acpi_object *
iwl_acpi_get_wifi_pkg_range(struct device * dev,union acpi_object * data,int min_data_size,int max_data_size,int * tbl_rev)232 iwl_acpi_get_wifi_pkg_range(struct device *dev,
233 union acpi_object *data,
234 int min_data_size, int max_data_size,
235 int *tbl_rev)
236 {
237 return ERR_PTR(-ENOENT);
238 }
239
iwl_acpi_get_mcc(struct device * dev,char * mcc)240 static inline int iwl_acpi_get_mcc(struct device *dev, char *mcc)
241 {
242 return -ENOENT;
243 }
244
iwl_acpi_get_pwr_limit(struct device * dev)245 static inline u64 iwl_acpi_get_pwr_limit(struct device *dev)
246 {
247 return 0;
248 }
249
iwl_acpi_get_eckv(struct device * dev,u32 * extl_clk)250 static inline int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
251 {
252 return -ENOENT;
253 }
254
iwl_sar_select_profile(struct iwl_fw_runtime * fwrt,__le16 * per_chain,u32 n_tables,u32 n_subbands,int prof_a,int prof_b)255 static inline int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
256 __le16 *per_chain, u32 n_tables, u32 n_subbands,
257 int prof_a, int prof_b)
258 {
259 return -ENOENT;
260 }
261
iwl_sar_get_wrds_table(struct iwl_fw_runtime * fwrt)262 static inline int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt)
263 {
264 return -ENOENT;
265 }
266
iwl_sar_get_ewrd_table(struct iwl_fw_runtime * fwrt)267 static inline int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt)
268 {
269 return -ENOENT;
270 }
271
iwl_sar_get_wgds_table(struct iwl_fw_runtime * fwrt)272 static inline int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
273 {
274 return 1;
275 }
276
iwl_sar_geo_support(struct iwl_fw_runtime * fwrt)277 static inline bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
278 {
279 return false;
280 }
281
iwl_acpi_get_tas(struct iwl_fw_runtime * fwrt,__le32 * block_list_array,int * block_list_size)282 static inline int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
283 __le32 *block_list_array,
284 int *block_list_size)
285 {
286 return -ENOENT;
287 }
288
iwl_acpi_get_lari_config_bitmap(struct iwl_fw_runtime * fwrt)289 static inline __le32 iwl_acpi_get_lari_config_bitmap(struct iwl_fw_runtime *fwrt)
290 {
291 return 0;
292 }
293
294 #endif /* CONFIG_ACPI */
295
296 static inline union acpi_object *
iwl_acpi_get_wifi_pkg(struct device * dev,union acpi_object * data,int data_size,int * tbl_rev)297 iwl_acpi_get_wifi_pkg(struct device *dev,
298 union acpi_object *data,
299 int data_size, int *tbl_rev)
300 {
301 return iwl_acpi_get_wifi_pkg_range(dev, data, data_size, data_size,
302 tbl_rev);
303 }
304
305 #endif /* __iwl_fw_acpi__ */
306