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 #define IWL_UEFI_OEM_PNVM_NAME		L"UefiCnvWlanOemSignedPnvm"
9 #define IWL_UEFI_REDUCED_POWER_NAME	L"UefiCnvWlanReducedPower"
10 #define IWL_UEFI_SGOM_NAME		L"UefiCnvWlanSarGeoOffsetMapping"
11 #define IWL_UEFI_STEP_NAME		L"UefiCnvCommonSTEP"
12 
13 /*
14  * TODO: we have these hardcoded values that the caller must pass,
15  * because reading from the UEFI is not working.  To implement this
16  * properly, we have to change iwl_pnvm_get_from_uefi() to call
17  * efivar_entry_size() and return the value to the caller instead.
18  */
19 #define IWL_HARDCODED_PNVM_SIZE		4096
20 #define IWL_HARDCODED_REDUCE_POWER_SIZE	32768
21 #define IWL_HARDCODED_SGOM_SIZE		339
22 #define IWL_HARDCODED_STEP_SIZE		6
23 
24 struct pnvm_sku_package {
25 	u8 rev;
26 	u32 total_size;
27 	u8 n_skus;
28 	u32 reserved[2];
29 	u8 data[];
30 } __packed;
31 
32 struct uefi_cnv_wlan_sgom_data {
33 	u8 revision;
34 	u8 offset_map[IWL_HARDCODED_SGOM_SIZE - 1];
35 } __packed;
36 
37 struct uefi_cnv_common_step_data {
38 	u8 revision;
39 	u8 step_mode;
40 	u8 cnvi_eq_channel;
41 	u8 cnvr_eq_channel;
42 	u8 radio1;
43 	u8 radio2;
44 } __packed;
45 
46 /*
47  * This is known to be broken on v4.19 and to work on v5.4.  Until we
48  * figure out why this is the case and how to make it work, simply
49  * disable the feature in old kernels.
50  */
51 #ifdef CONFIG_EFI
52 void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len);
53 u8 *iwl_uefi_get_reduced_power(struct iwl_trans *trans, size_t *len);
54 int iwl_uefi_reduce_power_parse(struct iwl_trans *trans,
55 				const u8 *data, size_t len,
56 				struct iwl_pnvm_image *pnvm_data);
57 void iwl_uefi_get_step_table(struct iwl_trans *trans);
58 #else /* CONFIG_EFI */
59 static inline void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len)
60 {
61 	return ERR_PTR(-EOPNOTSUPP);
62 }
63 
64 static inline int
65 iwl_uefi_reduce_power_parse(struct iwl_trans *trans,
66 			    const u8 *data, size_t len,
67 			    struct iwl_pnvm_image *pnvm_data)
68 {
69 	return -EOPNOTSUPP;
70 }
71 
72 static inline u8 *
73 iwl_uefi_get_reduced_power(struct iwl_trans *trans, size_t *len)
74 {
75 	return ERR_PTR(-EOPNOTSUPP);
76 }
77 
78 static inline void iwl_uefi_get_step_table(struct iwl_trans *trans)
79 {
80 }
81 #endif /* CONFIG_EFI */
82 
83 #if defined(CONFIG_EFI) && defined(CONFIG_ACPI)
84 void iwl_uefi_get_sgom_table(struct iwl_trans *trans, struct iwl_fw_runtime *fwrt);
85 #else
86 static inline
87 void iwl_uefi_get_sgom_table(struct iwl_trans *trans, struct iwl_fw_runtime *fwrt)
88 {
89 }
90 #endif
91 #endif /* __iwl_fw_uefi__ */
92