xref: /linux/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2005-2015, 2018-2026 Intel Corporation
4  * Copyright (C) 2016-2017 Intel Deutschland GmbH
5  */
6 #ifndef __iwl_nvm_parse_h__
7 #define __iwl_nvm_parse_h__
8 
9 #include <net/cfg80211.h>
10 #include "iwl-nvm-utils.h"
11 #include "mei/iwl-mei.h"
12 
13 /**
14  * enum iwl_nvm_sbands_flags - modification flags for the channel profiles
15  *
16  * @IWL_NVM_SBANDS_FLAGS_LAR: LAR is enabled
17  * @IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ: disallow 40, 80 and 160MHz on 5GHz
18  */
19 enum iwl_nvm_sbands_flags {
20 	IWL_NVM_SBANDS_FLAGS_LAR		= BIT(0),
21 	IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ	= BIT(1),
22 };
23 
24 /**
25  * enum iwl_puncturing_status - EHT puncturing status from MCC capabilities
26  * @IWL_PUNCTURING_STATUS_UNKNOWN: puncturing status is not provided by FW
27  *	or is not initialized yet
28  * @IWL_PUNCTURING_STATUS_ENABLED: puncturing is enabled for the current MCC
29  * @IWL_PUNCTURING_STATUS_DISABLED: puncturing is disabled for the current MCC
30  */
31 enum iwl_puncturing_status {
32 	IWL_PUNCTURING_STATUS_UNKNOWN,
33 	IWL_PUNCTURING_STATUS_ENABLED,
34 	IWL_PUNCTURING_STATUS_DISABLED,
35 };
36 
37 /**
38  * struct iwl_reg_capa - struct for global regulatory capabilities, Used for
39  * handling the different APIs of reg_capa_flags.
40  *
41  * @allow_40mhz: 11n channel with a width of 40Mhz is allowed
42  *	for this regulatory domain.
43  * @allow_80mhz: 11ac channel with a width of 80Mhz is allowed
44  *	for this regulatory domain (valid only in 5 and 6 Ghz).
45  * @allow_160mhz: 11ac channel with a width of 160Mhz is allowed
46  *	for this regulatory domain (valid only in 5 and 6 Ghz).
47  * @allow_320mhz: 11be channel with a width of 320Mhz is allowed
48  *	for this regulatory domain (valid only in 6 Ghz).
49  * @disable_11ax: 11ax is forbidden for this regulatory domain.
50  * @disable_11be: 11be is forbidden for this regulatory domain.
51  * @disable_11bn: UHR/11bn is not allowed for this regulatory domain
52  * @puncturing_status: EHT puncturing status for the current MCC.
53  *	See &enum iwl_puncturing_status.
54  */
55 struct iwl_reg_capa {
56 	bool allow_40mhz;
57 	bool allow_80mhz;
58 	bool allow_160mhz;
59 	bool allow_320mhz;
60 	bool disable_11ax;
61 	bool disable_11be;
62 	bool disable_11bn;
63 	enum iwl_puncturing_status puncturing_status;
64 };
65 
66 /**
67  * enum iwl_nvm_channel_flags - channel flags in NVM
68  * @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
69  * @NVM_CHANNEL_IBSS: usable as an IBSS channel and deprecated
70  *	when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
71  * @NVM_CHANNEL_ALLOW_20MHZ_ACTIVITY: active scanning allowed and
72  *	AP allowed only in 20 MHz. Valid only
73  *	when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
74  * @NVM_CHANNEL_ACTIVE: active scanning allowed and allows IBSS
75  *	when %IWL_NVM_SBANDS_FLAGS_LAR enabled.
76  * @NVM_CHANNEL_RADAR: radar detection required
77  * @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed
78  * @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
79  *	on same channel on 2.4 or same UNII band on 5.2
80  * @NVM_CHANNEL_UNIFORM: uniform spreading required
81  * @NVM_CHANNEL_20MHZ: 20 MHz channel okay
82  * @NVM_CHANNEL_40MHZ: 40 MHz channel okay
83  * @NVM_CHANNEL_80MHZ: 80 MHz channel okay
84  * @NVM_CHANNEL_160MHZ: 160 MHz channel okay
85  * @NVM_CHANNEL_DC_HIGH: DC HIGH required/allowed (?)
86  * @NVM_CHANNEL_VLP: client support connection to UHB VLP AP
87  * @NVM_CHANNEL_AFC: client support connection to UHB AFC AP
88  * @NVM_CHANNEL_VLP_AP_NOT_ALLOWED: UHB VLP AP not allowed,
89  *	Valid only when %NVM_CHANNEL_VLP is enabled.
90  */
91 enum iwl_nvm_channel_flags {
92 	NVM_CHANNEL_VALID			= BIT(0),
93 	NVM_CHANNEL_IBSS			= BIT(1),
94 	NVM_CHANNEL_ALLOW_20MHZ_ACTIVITY	= BIT(2),
95 	NVM_CHANNEL_ACTIVE			= BIT(3),
96 	NVM_CHANNEL_RADAR			= BIT(4),
97 	NVM_CHANNEL_INDOOR_ONLY			= BIT(5),
98 	NVM_CHANNEL_GO_CONCURRENT		= BIT(6),
99 	NVM_CHANNEL_UNIFORM			= BIT(7),
100 	NVM_CHANNEL_20MHZ			= BIT(8),
101 	NVM_CHANNEL_40MHZ			= BIT(9),
102 	NVM_CHANNEL_80MHZ			= BIT(10),
103 	NVM_CHANNEL_160MHZ			= BIT(11),
104 	NVM_CHANNEL_DC_HIGH			= BIT(12),
105 	NVM_CHANNEL_VLP				= BIT(13),
106 	NVM_CHANNEL_AFC				= BIT(14),
107 	NVM_CHANNEL_VLP_AP_NOT_ALLOWED		= BIT(15),
108 };
109 
110 #if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
111 u32 iwl_nvm_get_regdom_bw_flags(const u16 *nvm_chan,
112 				int ch_idx, u16 nvm_flags,
113 				struct iwl_reg_capa reg_capa);
114 #endif
115 
116 /*
117  * iwl_parse_nvm_data - parse NVM data and return values
118  *
119  * This function parses all NVM values we need and then
120  * returns a (newly allocated) struct containing all the
121  * relevant values for driver use. The struct must be freed
122  * later with iwl_free_nvm_data().
123  */
124 struct iwl_nvm_data *
125 iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_rf_cfg *cfg,
126 		   const struct iwl_fw *fw,
127 		   const __be16 *nvm_hw, const __le16 *nvm_sw,
128 		   const __le16 *nvm_calib, const __le16 *regulatory,
129 		   const __le16 *mac_override, const __le16 *phy_sku,
130 		   u8 tx_chains, u8 rx_chains);
131 
132 /**
133  * iwl_parse_nvm_mcc_info - parse MCC (mobile country code) info coming from FW
134  *
135  * This function parses the regulatory channel data received as a
136  * MCC_UPDATE_CMD command.
137  *
138  * Return: a newly allocation regulatory domain, to be given to the regulatory
139  *	core. In case the geo_info is set handle accordingly. An ERR_PTR is
140  *	returned on error. If not given to the regulatory core, the user is
141  *	responsible for freeing the regdomain returned here with kfree().
142  *
143  * @trans: the transport
144  * @num_of_ch: the number of channels
145  * @channels: channel map
146  * @fw_mcc: firmware country code
147  * @geo_info: geo info value
148  * @cap: capability
149  * @resp_ver: FW response version
150  * @puncturing_status: FW puncturing status for current MCC, when available
151  */
152 struct ieee80211_regdomain *
153 iwl_parse_nvm_mcc_info(struct iwl_trans *trans,
154 		       int num_of_ch, __le32 *channels, u16 fw_mcc,
155 		       u16 geo_info, u32 cap, u8 resp_ver,
156 		       enum iwl_puncturing_status *puncturing_status);
157 
158 /**
159  * struct iwl_nvm_section - describes an NVM section in memory.
160  *
161  * This struct holds an NVM section read from the NIC using NVM_ACCESS_CMD,
162  * and saved for later use by the driver. Not all NVM sections are saved
163  * this way, only the needed ones.
164  * @length: length of the section
165  * @data: section data
166  */
167 struct iwl_nvm_section {
168 	u16 length;
169 	const u8 *data;
170 };
171 
172 /**
173  * iwl_read_external_nvm - Reads external NVM from a file into nvm_sections
174  * @trans: the transport
175  * @nvm_file_name: the filename to request
176  * @nvm_sections: sections data to fill
177  * Return: 0 on success or an error code
178  */
179 int iwl_read_external_nvm(struct iwl_trans *trans,
180 			  const char *nvm_file_name,
181 			  struct iwl_nvm_section *nvm_sections);
182 void iwl_nvm_fixups(u32 hw_id, unsigned int section, u8 *data,
183 		    unsigned int len);
184 
185 /*
186  * iwl_get_nvm - retrieve NVM data from firmware
187  *
188  * Allocates a new iwl_nvm_data structure, fills it with
189  * NVM data, and returns it to caller.
190  */
191 struct iwl_nvm_data *iwl_get_nvm(struct iwl_trans *trans,
192 				 const struct iwl_fw *fw,
193 				 u8 set_tx_ant, u8 set_rx_ant);
194 
195 /*
196  * iwl_parse_mei_nvm_data - parse the mei_nvm_data and get an iwl_nvm_data
197  */
198 struct iwl_nvm_data *
199 iwl_parse_mei_nvm_data(struct iwl_trans *trans, const struct iwl_rf_cfg *cfg,
200 		       const struct iwl_mei_nvm *mei_nvm,
201 		       const struct iwl_fw *fw, u8 set_tx_ant, u8 set_rx_ant);
202 
203 /*
204  * iwl_reinit_cab - to be called when the tx_chains or rx_chains are modified
205  */
206 void iwl_reinit_cab(struct iwl_trans *trans, struct iwl_nvm_data *data,
207 		    u8 tx_chains, u8 rx_chains, const struct iwl_fw *fw);
208 
209 #endif /* __iwl_nvm_parse_h__ */
210