1/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2/*
3 * Copyright(c) 2021-2023 Intel Corporation
4 */
5#ifndef __iwl_fw_uefi__
6#define __iwl_fw_uefi__
7
8#include "fw/regulatory.h"
9
10#define IWL_UEFI_OEM_PNVM_NAME		L"UefiCnvWlanOemSignedPnvm"
11#define IWL_UEFI_REDUCED_POWER_NAME	L"UefiCnvWlanReducedPower"
12#define IWL_UEFI_SGOM_NAME		L"UefiCnvWlanSarGeoOffsetMapping"
13#define IWL_UEFI_STEP_NAME		L"UefiCnvCommonSTEP"
14#define IWL_UEFI_UATS_NAME		L"CnvUefiWlanUATS"
15#define IWL_UEFI_WRDS_NAME		L"UefiCnvWlanWRDS"
16#define IWL_UEFI_EWRD_NAME		L"UefiCnvWlanEWRD"
17#define IWL_UEFI_WGDS_NAME		L"UefiCnvWlanWGDS"
18#define IWL_UEFI_PPAG_NAME		L"UefiCnvWlanPPAG"
19#define IWL_UEFI_WTAS_NAME		L"UefiCnvWlanWTAS"
20#define IWL_UEFI_SPLC_NAME		L"UefiCnvWlanSPLC"
21#define IWL_UEFI_WRDD_NAME		L"UefiCnvWlanWRDD"
22#define IWL_UEFI_ECKV_NAME		L"UefiCnvWlanECKV"
23#define IWL_UEFI_DSM_NAME		L"UefiCnvWlanGeneralCfg"
24
25
26#define IWL_SGOM_MAP_SIZE		339
27#define IWL_UATS_MAP_SIZE		339
28
29#define IWL_UEFI_WRDS_REVISION		2
30#define IWL_UEFI_EWRD_REVISION		2
31#define IWL_UEFI_WGDS_REVISION		3
32#define IWL_UEFI_MIN_PPAG_REV		1
33#define IWL_UEFI_MAX_PPAG_REV		3
34#define IWL_UEFI_WTAS_REVISION		1
35#define IWL_UEFI_SPLC_REVISION		0
36#define IWL_UEFI_WRDD_REVISION		0
37#define IWL_UEFI_ECKV_REVISION		0
38#define IWL_UEFI_DSM_REVISION		4
39
40struct pnvm_sku_package {
41	u8 rev;
42	u32 total_size;
43	u8 n_skus;
44	u32 reserved[2];
45	u8 data[];
46} __packed;
47
48struct uefi_cnv_wlan_sgom_data {
49	u8 revision;
50	u8 offset_map[IWL_SGOM_MAP_SIZE - 1];
51} __packed;
52
53struct uefi_cnv_wlan_uats_data {
54	u8 revision;
55	u8 offset_map[IWL_UATS_MAP_SIZE - 1];
56} __packed;
57
58struct uefi_cnv_common_step_data {
59	u8 revision;
60	u8 step_mode;
61	u8 cnvi_eq_channel;
62	u8 cnvr_eq_channel;
63	u8 radio1;
64	u8 radio2;
65} __packed;
66
67/*
68 * struct uefi_sar_profile - a SAR profile as defined in UEFI
69 *
70 * @chains: a per-chain table of SAR values
71 */
72struct uefi_sar_profile {
73	struct iwl_sar_profile_chain chains[BIOS_SAR_MAX_CHAINS_PER_PROFILE];
74} __packed;
75
76/*
77 * struct uefi_cnv_var_wrds - WRDS table as defined in UEFI
78 *
79 * @revision: the revision of the table
80 * @mode: is WRDS enbaled/disabled
81 * @sar_profile: sar profile #1
82 */
83struct uefi_cnv_var_wrds {
84	u8 revision;
85	u32 mode;
86	struct uefi_sar_profile sar_profile;
87} __packed;
88
89/*
90 * struct uefi_cnv_var_ewrd - EWRD table as defined in UEFI
91 * @revision: the revision of the table
92 * @mode: is WRDS enbaled/disabled
93 * @num_profiles: how many additional profiles we have in this table (0-3)
94 * @sar_profiles: the additional SAR profiles (#2-#4)
95 */
96struct uefi_cnv_var_ewrd {
97	u8 revision;
98	u32 mode;
99	u32 num_profiles;
100	struct uefi_sar_profile sar_profiles[BIOS_SAR_MAX_PROFILE_NUM - 1];
101} __packed;
102
103/*
104 * struct uefi_cnv_var_wgds - WGDS table as defined in UEFI
105 * @revision: the revision of the table
106 * @num_profiles: the number of geo profiles we have in the table.
107 *	The first 3 are mandatory, and can have up to 8.
108 * @geo_profiles: a per-profile table of the offsets to add to SAR values.
109 */
110struct uefi_cnv_var_wgds {
111	u8 revision;
112	u8 num_profiles;
113	struct iwl_geo_profile geo_profiles[BIOS_GEO_MAX_PROFILE_NUM];
114} __packed;
115
116/*
117 * struct uefi_cnv_var_ppag - PPAG table as defined in UEFI
118 * @revision: the revision of the table
119 * @ppag_modes: values from &enum iwl_ppag_flags
120 * @ppag_chains: the PPAG values per chain and band
121 */
122struct uefi_cnv_var_ppag {
123	u8 revision;
124	u32 ppag_modes;
125	struct iwl_ppag_chain ppag_chains[IWL_NUM_CHAIN_LIMITS];
126} __packed;
127
128/* struct uefi_cnv_var_wtas - WTAS tabled as defined in UEFI
129 * @revision: the revision of the table
130 * @tas_selection: different options of TAS enablement.
131 * @black_list_size: the number of defined entried in the black list
132 * @black_list: a list of countries that are not allowed to use the TAS feature
133 */
134struct uefi_cnv_var_wtas {
135	u8 revision;
136	u32 tas_selection;
137	u8 black_list_size;
138	u16 black_list[IWL_WTAS_BLACK_LIST_MAX];
139} __packed;
140
141/* struct uefi_cnv_var_splc - SPLC tabled as defined in UEFI
142 * @revision: the revision of the table
143 * @default_pwr_limit: The default maximum power per device
144 */
145struct uefi_cnv_var_splc {
146	u8 revision;
147	u32 default_pwr_limit;
148} __packed;
149
150#define UEFI_MCC_CHINA 0x434e
151
152/* struct uefi_cnv_var_wrdd - WRDD table as defined in UEFI
153 * @revision: the revision of the table
154 * @mcc: country identifier as defined in ISO/IEC 3166-1 Alpha 2 code
155 */
156struct uefi_cnv_var_wrdd {
157	u8 revision;
158	u32 mcc;
159} __packed;
160
161/* struct uefi_cnv_var_eckv - ECKV table as defined in UEFI
162 * @revision: the revision of the table
163 * @ext_clock_valid: indicates if external 32KHz clock is valid
164 */
165struct uefi_cnv_var_eckv {
166	u8 revision;
167	u32 ext_clock_valid;
168} __packed;
169
170#define UEFI_MAX_DSM_FUNCS 32
171
172/* struct uefi_cnv_var_general_cfg - DSM-like table as defined in UEFI
173 * @revision: the revision of the table
174 * @functions: payload of the different DSM functions
175 */
176struct uefi_cnv_var_general_cfg {
177	u8 revision;
178	u32 functions[UEFI_MAX_DSM_FUNCS];
179} __packed;
180
181/*
182 * This is known to be broken on v4.19 and to work on v5.4.  Until we
183 * figure out why this is the case and how to make it work, simply
184 * disable the feature in old kernels.
185 */
186#ifdef CONFIG_EFI
187void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len);
188u8 *iwl_uefi_get_reduced_power(struct iwl_trans *trans, size_t *len);
189int iwl_uefi_reduce_power_parse(struct iwl_trans *trans,
190				const u8 *data, size_t len,
191				struct iwl_pnvm_image *pnvm_data);
192void iwl_uefi_get_step_table(struct iwl_trans *trans);
193int iwl_uefi_handle_tlv_mem_desc(struct iwl_trans *trans, const u8 *data,
194				 u32 tlv_len, struct iwl_pnvm_image *pnvm_data);
195int iwl_uefi_get_wrds_table(struct iwl_fw_runtime *fwrt);
196int iwl_uefi_get_ewrd_table(struct iwl_fw_runtime *fwrt);
197int iwl_uefi_get_wgds_table(struct iwl_fw_runtime *fwrt);
198int iwl_uefi_get_ppag_table(struct iwl_fw_runtime *fwrt);
199int iwl_uefi_get_tas_table(struct iwl_fw_runtime *fwrt,
200			   struct iwl_tas_data *data);
201int iwl_uefi_get_pwr_limit(struct iwl_fw_runtime *fwrt,
202			   u64 *dflt_pwr_limit);
203int iwl_uefi_get_mcc(struct iwl_fw_runtime *fwrt, char *mcc);
204int iwl_uefi_get_eckv(struct iwl_fw_runtime *fwrt, u32 *extl_clk);
205int iwl_uefi_get_dsm(struct iwl_fw_runtime *fwrt, enum iwl_dsm_funcs func,
206		     u32 *value);
207void iwl_uefi_get_sgom_table(struct iwl_trans *trans, struct iwl_fw_runtime *fwrt);
208int iwl_uefi_get_uats_table(struct iwl_trans *trans,
209			    struct iwl_fw_runtime *fwrt);
210#else /* CONFIG_EFI */
211static inline void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len)
212{
213	return ERR_PTR(-EOPNOTSUPP);
214}
215
216static inline int
217iwl_uefi_reduce_power_parse(struct iwl_trans *trans,
218			    const u8 *data, size_t len,
219			    struct iwl_pnvm_image *pnvm_data)
220{
221	return -EOPNOTSUPP;
222}
223
224static inline u8 *
225iwl_uefi_get_reduced_power(struct iwl_trans *trans, size_t *len)
226{
227	return ERR_PTR(-EOPNOTSUPP);
228}
229
230static inline void iwl_uefi_get_step_table(struct iwl_trans *trans)
231{
232}
233
234static inline int
235iwl_uefi_handle_tlv_mem_desc(struct iwl_trans *trans, const u8 *data,
236			     u32 tlv_len, struct iwl_pnvm_image *pnvm_data)
237{
238	return 0;
239}
240
241static inline int iwl_uefi_get_wrds_table(struct iwl_fw_runtime *fwrt)
242{
243	return -ENOENT;
244}
245
246static inline int iwl_uefi_get_ewrd_table(struct iwl_fw_runtime *fwrt)
247{
248	return -ENOENT;
249}
250
251static inline int iwl_uefi_get_wgds_table(struct iwl_fw_runtime *fwrt)
252{
253	return -ENOENT;
254}
255
256static inline int iwl_uefi_get_ppag_table(struct iwl_fw_runtime *fwrt)
257{
258	return -ENOENT;
259}
260
261static inline int iwl_uefi_get_tas_table(struct iwl_fw_runtime *fwrt,
262					 struct iwl_tas_data *data)
263{
264	return -ENOENT;
265}
266
267static inline int iwl_uefi_get_pwr_limit(struct iwl_fw_runtime *fwrt,
268					 u64 *dflt_pwr_limit)
269{
270	*dflt_pwr_limit = 0;
271	return 0;
272}
273
274static inline int iwl_uefi_get_mcc(struct iwl_fw_runtime *fwrt, char *mcc)
275{
276	return -ENOENT;
277}
278
279static inline int iwl_uefi_get_eckv(struct iwl_fw_runtime *fwrt, u32 *extl_clk)
280{
281	return -ENOENT;
282}
283
284static inline int iwl_uefi_get_dsm(struct iwl_fw_runtime *fwrt,
285				   enum iwl_dsm_funcs func, u32 *value)
286{
287	return -ENOENT;
288}
289
290static inline
291void iwl_uefi_get_sgom_table(struct iwl_trans *trans, struct iwl_fw_runtime *fwrt)
292{
293}
294
295static inline
296int iwl_uefi_get_uats_table(struct iwl_trans *trans,
297			    struct iwl_fw_runtime *fwrt)
298{
299	return 0;
300}
301#endif /* CONFIG_EFI */
302#endif /* __iwl_fw_uefi__ */
303