xref: /freebsd/sys/contrib/dev/iwlwifi/fw/regulatory.h (revision a4128aad8503277614f2d214011ef60a19447b83)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2023-2024 Intel Corporation
4  */
5 
6 #ifndef __fw_regulatory_h__
7 #define __fw_regulatory_h__
8 
9 #include "fw/img.h"
10 #include "fw/api/commands.h"
11 #include "fw/api/power.h"
12 #include "fw/api/phy.h"
13 #include "fw/api/config.h"
14 #include "fw/api/nvm-reg.h"
15 #include "fw/img.h"
16 #include "iwl-trans.h"
17 
18 #define BIOS_SAR_MAX_PROFILE_NUM	4
19 /*
20  * Each SAR profile has (up to, depends on the table revision) 4 chains:
21  * chain A, chain B, chain A when in CDB, chain B when in CDB
22  */
23 #define BIOS_SAR_MAX_CHAINS_PER_PROFILE 4
24 #define BIOS_SAR_NUM_CHAINS             2
25 #define BIOS_SAR_MAX_SUB_BANDS_NUM      11
26 
27 #define BIOS_GEO_NUM_CHAINS		2
28 #define BIOS_GEO_MAX_NUM_BANDS		3
29 #define BIOS_GEO_MAX_PROFILE_NUM	8
30 #define BIOS_GEO_MIN_PROFILE_NUM	3
31 
32 #define IWL_SAR_ENABLE_MSK		BIT(0)
33 
34 /* PPAG gain value bounds in 1/8 dBm */
35 #define IWL_PPAG_MIN_LB	-16
36 #define IWL_PPAG_MAX_LB 24
37 #define IWL_PPAG_MIN_HB -16
38 #define IWL_PPAG_MAX_HB 40
39 
40 #define IWL_PPAG_ETSI_CHINA_MASK	3
41 #define IWL_PPAG_REV3_MASK		0x7FF
42 
43 #define IWL_WTAS_ENABLED_MSK		0x1
44 #define IWL_WTAS_OVERRIDE_IEC_MSK	0x2
45 #define IWL_WTAS_ENABLE_IEC_MSK	0x4
46 #define IWL_WTAS_USA_UHB_MSK		BIT(16)
47 
48 /*
49  * The profile for revision 2 is a superset of revision 1, which is in
50  * turn a superset of revision 0.  So we can store all revisions
51  * inside revision 2, which is what we represent here.
52  */
53 
54 /*
55  * struct iwl_sar_profile_chain - per-chain values of a SAR profile
56  * @subbands: the SAR value for each subband
57  */
58 struct iwl_sar_profile_chain {
59 	u8 subbands[BIOS_SAR_MAX_SUB_BANDS_NUM];
60 };
61 
62 /*
63  * struct iwl_sar_profile - SAR profile from SAR tables
64  * @enabled: whether the profile is enabled or not
65  * @chains: per-chain SAR values
66  */
67 struct iwl_sar_profile {
68 	bool enabled;
69 	struct iwl_sar_profile_chain chains[BIOS_SAR_MAX_CHAINS_PER_PROFILE];
70 };
71 
72 /* Same thing as with SAR, all revisions fit in revision 2 */
73 
74 /*
75  * struct iwl_geo_profile_band - per-band geo SAR offsets
76  * @max: the max tx power allowed for the band
77  * @chains: SAR offsets values for each chain
78  */
79 struct iwl_geo_profile_band {
80 	u8 max;
81 	u8 chains[BIOS_GEO_NUM_CHAINS];
82 };
83 
84 /*
85  * struct iwl_geo_profile - geo profile
86  * @bands: per-band table of the SAR offsets
87  */
88 struct iwl_geo_profile {
89 	struct iwl_geo_profile_band bands[BIOS_GEO_MAX_NUM_BANDS];
90 };
91 
92 /* Same thing as with SAR, all revisions fit in revision 2 */
93 struct iwl_ppag_chain {
94 	s8 subbands[BIOS_SAR_MAX_SUB_BANDS_NUM];
95 };
96 
97 struct iwl_tas_data {
98 	__le32 block_list_size;
99 	__le32 block_list_array[IWL_WTAS_BLACK_LIST_MAX];
100 	u8 override_tas_iec;
101 	u8 enable_tas_iec;
102 	u8 usa_tas_uhb_allowed;
103 };
104 
105 /* For DSM revision 0 and 4 */
106 enum iwl_dsm_funcs {
107 	DSM_FUNC_QUERY = 0,
108 	DSM_FUNC_DISABLE_SRD = 1,
109 	DSM_FUNC_ENABLE_INDONESIA_5G2 = 2,
110 	DSM_FUNC_ENABLE_6E = 3,
111 	DSM_FUNC_REGULATORY_CONFIG = 4,
112 	DSM_FUNC_11AX_ENABLEMENT = 6,
113 	DSM_FUNC_ENABLE_UNII4_CHAN = 7,
114 	DSM_FUNC_ACTIVATE_CHANNEL = 8,
115 	DSM_FUNC_FORCE_DISABLE_CHANNELS = 9,
116 	DSM_FUNC_ENERGY_DETECTION_THRESHOLD = 10,
117 	DSM_FUNC_RFI_CONFIG = 11,
118 	DSM_FUNC_ENABLE_11BE = 12,
119 	DSM_FUNC_NUM_FUNCS = 13,
120 };
121 
122 enum iwl_dsm_values_srd {
123 	DSM_VALUE_SRD_ACTIVE,
124 	DSM_VALUE_SRD_PASSIVE,
125 	DSM_VALUE_SRD_DISABLE,
126 	DSM_VALUE_SRD_MAX
127 };
128 
129 enum iwl_dsm_values_indonesia {
130 	DSM_VALUE_INDONESIA_DISABLE,
131 	DSM_VALUE_INDONESIA_ENABLE,
132 	DSM_VALUE_INDONESIA_RESERVED,
133 	DSM_VALUE_INDONESIA_MAX
134 };
135 
136 enum iwl_dsm_unii4_bitmap {
137 	DSM_VALUE_UNII4_US_OVERRIDE_MSK		= BIT(0),
138 	DSM_VALUE_UNII4_US_EN_MSK		= BIT(1),
139 	DSM_VALUE_UNII4_ETSI_OVERRIDE_MSK	= BIT(2),
140 	DSM_VALUE_UNII4_ETSI_EN_MSK		= BIT(3),
141 	DSM_VALUE_UNII4_CANADA_OVERRIDE_MSK	= BIT(4),
142 	DSM_VALUE_UNII4_CANADA_EN_MSK		= BIT(5),
143 };
144 
145 #define DSM_UNII4_ALLOW_BITMAP_CMD_V8 (DSM_VALUE_UNII4_US_OVERRIDE_MSK | \
146 				       DSM_VALUE_UNII4_US_EN_MSK | \
147 				       DSM_VALUE_UNII4_ETSI_OVERRIDE_MSK | \
148 				       DSM_VALUE_UNII4_ETSI_EN_MSK)
149 #define DSM_UNII4_ALLOW_BITMAP (DSM_UNII4_ALLOW_BITMAP_CMD_V8 | \
150 				DSM_VALUE_UNII4_CANADA_OVERRIDE_MSK | \
151 				DSM_VALUE_UNII4_CANADA_EN_MSK)
152 
153 enum iwl_dsm_values_rfi {
154 	DSM_VALUE_RFI_DLVR_DISABLE	= BIT(0),
155 	DSM_VALUE_RFI_DDR_DISABLE	= BIT(1),
156 };
157 
158 #define DSM_VALUE_RFI_DISABLE	(DSM_VALUE_RFI_DLVR_DISABLE |\
159 				 DSM_VALUE_RFI_DDR_DISABLE)
160 
161 enum iwl_dsm_masks_reg {
162 	DSM_MASK_CHINA_22_REG = BIT(2)
163 };
164 
165 struct iwl_fw_runtime;
166 
167 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt);
168 
169 int iwl_sar_geo_fill_table(struct iwl_fw_runtime *fwrt,
170 			   struct iwl_per_chain_offset *table,
171 			   u32 n_bands, u32 n_profiles);
172 
173 int iwl_sar_fill_profile(struct iwl_fw_runtime *fwrt,
174 			 __le16 *per_chain, u32 n_tables, u32 n_subbands,
175 			 int prof_a, int prof_b);
176 
177 int iwl_fill_ppag_table(struct iwl_fw_runtime *fwrt,
178 			union iwl_ppag_table_cmd *cmd,
179 			int *cmd_size);
180 
181 bool iwl_is_ppag_approved(struct iwl_fw_runtime *fwrt);
182 
183 bool iwl_is_tas_approved(void);
184 
185 int iwl_parse_tas_selection(struct iwl_fw_runtime *fwrt,
186 			    struct iwl_tas_data *tas_data,
187 			    const u32 tas_selection);
188 
189 int iwl_bios_get_wrds_table(struct iwl_fw_runtime *fwrt);
190 
191 int iwl_bios_get_ewrd_table(struct iwl_fw_runtime *fwrt);
192 
193 int iwl_bios_get_wgds_table(struct iwl_fw_runtime *fwrt);
194 
195 int iwl_bios_get_ppag_table(struct iwl_fw_runtime *fwrt);
196 
197 int iwl_bios_get_tas_table(struct iwl_fw_runtime *fwrt,
198 			   struct iwl_tas_data *data);
199 
200 int iwl_bios_get_pwr_limit(struct iwl_fw_runtime *fwrt,
201 			   u64 *dflt_pwr_limit);
202 
203 int iwl_bios_get_mcc(struct iwl_fw_runtime *fwrt, char *mcc);
204 int iwl_bios_get_eckv(struct iwl_fw_runtime *fwrt, u32 *ext_clk);
205 int iwl_bios_get_wbem(struct iwl_fw_runtime *fwrt, u32 *value);
206 
207 int iwl_fill_lari_config(struct iwl_fw_runtime *fwrt,
208 			 struct iwl_lari_config_change_cmd *cmd,
209 			 size_t *cmd_size);
210 
211 int iwl_bios_get_dsm(struct iwl_fw_runtime *fwrt, enum iwl_dsm_funcs func,
212 		     u32 *value);
213 
214 static inline u32 iwl_bios_get_ppag_flags(const u32 ppag_modes,
215 					  const u8 ppag_ver)
216 {
217 	return ppag_modes & (ppag_ver < 3 ? IWL_PPAG_ETSI_CHINA_MASK :
218 					    IWL_PPAG_REV3_MASK);
219 }
220 #endif /* __fw_regulatory_h__ */
221