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