blob: 3bd6fc1b76d4933aa11581d73302a25f55fad460 [file] [log] [blame]
Johannes Bergb1e1adf2013-01-24 14:14:22 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
Emmanuel Grumbach5f0d98f2014-10-30 10:19:38 +02009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Sara Sharonafd5b172016-03-01 12:18:22 +020010 * Copyright(c) 2016 Intel Deutschland GmbH
Johannes Bergb1e1adf2013-01-24 14:14:22 +010011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020027 * in the file called COPYING.
Johannes Bergb1e1adf2013-01-24 14:14:22 +010028 *
29 * Contact Information:
Emmanuel Grumbachd01c5362015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Bergb1e1adf2013-01-24 14:14:22 +010031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020035 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
Emmanuel Grumbach5f0d98f2014-10-30 10:19:38 +020036 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Bergb1e1adf2013-01-24 14:14:22 +010037 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 *
43 * * Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * * Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in
47 * the documentation and/or other materials provided with the
48 * distribution.
49 * * Neither the name Intel Corporation nor the names of its
50 * contributors may be used to endorse or promote products derived
51 * from this software without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
65#include <linux/types.h>
66#include <linux/slab.h>
67#include <linux/export.h>
Eran Harary9f32e012014-04-28 15:22:40 +030068#include <linux/etherdevice.h>
Eran Harary1e0b3932014-06-11 11:37:09 +030069#include <linux/pci.h>
Arik Nemtsov671bed32016-08-07 18:58:29 +030070#include <linux/acpi.h>
Johannes Berg48e29342013-03-01 00:13:33 +010071#include "iwl-drv.h"
Johannes Bergb1e1adf2013-01-24 14:14:22 +010072#include "iwl-modparams.h"
73#include "iwl-nvm-parse.h"
Sara Sharonafd5b172016-03-01 12:18:22 +020074#include "iwl-prph.h"
Sara Sharon17c867b2016-03-07 14:18:29 +020075#include "iwl-io.h"
76#include "iwl-csr.h"
Johannes Bergb1e1adf2013-01-24 14:14:22 +010077
78/* NVM offsets (in words) definitions */
79enum wkp_nvm_offsets {
80 /* NVM HW-Section offset (in words) definitions */
81 HW_ADDR = 0x15,
82
Eran Harary77db0a32014-02-04 14:21:38 +020083 /* NVM SW-Section offset (in words) definitions */
Johannes Bergb1e1adf2013-01-24 14:14:22 +010084 NVM_SW_SECTION = 0x1C0,
85 NVM_VERSION = 0,
86 RADIO_CFG = 1,
87 SKU = 2,
88 N_HW_ADDRS = 3,
89 NVM_CHANNELS = 0x1E0 - NVM_SW_SECTION,
90
Eran Harary77db0a32014-02-04 14:21:38 +020091 /* NVM calibration section offset (in words) definitions */
Johannes Bergb1e1adf2013-01-24 14:14:22 +010092 NVM_CALIB_SECTION = 0x2B8,
93 XTAL_CALIB = 0x316 - NVM_CALIB_SECTION
94};
95
Eran Harary77db0a32014-02-04 14:21:38 +020096enum family_8000_nvm_offsets {
97 /* NVM HW-Section offset (in words) definitions */
Eran Harary1e0b3932014-06-11 11:37:09 +030098 HW_ADDR0_WFPM_FAMILY_8000 = 0x12,
99 HW_ADDR1_WFPM_FAMILY_8000 = 0x16,
100 HW_ADDR0_PCIE_FAMILY_8000 = 0x8A,
101 HW_ADDR1_PCIE_FAMILY_8000 = 0x8E,
Eran Harary77db0a32014-02-04 14:21:38 +0200102 MAC_ADDRESS_OVERRIDE_FAMILY_8000 = 1,
103
104 /* NVM SW-Section offset (in words) definitions */
105 NVM_SW_SECTION_FAMILY_8000 = 0x1C0,
106 NVM_VERSION_FAMILY_8000 = 0,
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200107 RADIO_CFG_FAMILY_8000 = 0,
108 SKU_FAMILY_8000 = 2,
109 N_HW_ADDRS_FAMILY_8000 = 3,
Eran Hararyce500072014-12-01 17:53:53 +0200110
Eran Harary77db0a32014-02-04 14:21:38 +0200111 /* NVM REGULATORY -Section offset (in words) definitions */
112 NVM_CHANNELS_FAMILY_8000 = 0,
Arik Nemtsovf5528632015-02-04 15:38:56 +0200113 NVM_LAR_OFFSET_FAMILY_8000_OLD = 0x4C7,
114 NVM_LAR_OFFSET_FAMILY_8000 = 0x507,
Matti Gottliebd0d15192014-07-31 09:16:25 +0300115 NVM_LAR_ENABLED_FAMILY_8000 = 0x7,
Eran Harary77db0a32014-02-04 14:21:38 +0200116
117 /* NVM calibration section offset (in words) definitions */
118 NVM_CALIB_SECTION_FAMILY_8000 = 0x2B8,
119 XTAL_CALIB_FAMILY_8000 = 0x316 - NVM_CALIB_SECTION_FAMILY_8000
120};
121
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100122/* SKU Capabilities (actual values from NVM definition) */
123enum nvm_sku_bits {
Emmanuel Grumbach5f0d98f2014-10-30 10:19:38 +0200124 NVM_SKU_CAP_BAND_24GHZ = BIT(0),
125 NVM_SKU_CAP_BAND_52GHZ = BIT(1),
126 NVM_SKU_CAP_11N_ENABLE = BIT(2),
127 NVM_SKU_CAP_11AC_ENABLE = BIT(3),
128 NVM_SKU_CAP_MIMO_DISABLE = BIT(5),
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100129};
130
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100131/*
132 * These are the channel numbers in the order that they are stored in the NVM
133 */
134static const u8 iwl_nvm_channels[] = {
135 /* 2.4 GHz */
136 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
137 /* 5 GHz */
138 36, 40, 44 , 48, 52, 56, 60, 64,
139 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
140 149, 153, 157, 161, 165
141};
142
Eran Harary77db0a32014-02-04 14:21:38 +0200143static const u8 iwl_nvm_channels_family_8000[] = {
144 /* 2.4 GHz */
Eran Harary9b1c9a62014-05-07 08:22:41 +0300145 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
Eran Harary77db0a32014-02-04 14:21:38 +0200146 /* 5 GHz */
147 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92,
148 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
149 149, 153, 157, 161, 165, 169, 173, 177, 181
150};
151
Eran Harary749f1fe2014-03-06 09:25:30 +0200152#define IWL_NUM_CHANNELS ARRAY_SIZE(iwl_nvm_channels)
Eran Harary77db0a32014-02-04 14:21:38 +0200153#define IWL_NUM_CHANNELS_FAMILY_8000 ARRAY_SIZE(iwl_nvm_channels_family_8000)
Eran Harary749f1fe2014-03-06 09:25:30 +0200154#define NUM_2GHZ_CHANNELS 14
Eran Harary9b1c9a62014-05-07 08:22:41 +0300155#define NUM_2GHZ_CHANNELS_FAMILY_8000 14
Eran Harary749f1fe2014-03-06 09:25:30 +0200156#define FIRST_2GHZ_HT_MINUS 5
157#define LAST_2GHZ_HT_PLUS 9
Matti Gottliebb281c932014-06-26 11:10:57 +0300158#define LAST_5GHZ_HT 165
159#define LAST_5GHZ_HT_FAMILY_8000 181
Eran Hararyce500072014-12-01 17:53:53 +0200160#define N_HW_ADDR_MASK 0xF
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100161
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100162/* rate data (static) */
163static struct ieee80211_rate iwl_cfg80211_rates[] = {
164 { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
165 { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
166 .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
167 { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
168 .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
169 { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
170 .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
171 { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
172 { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
173 { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
174 { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
175 { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
176 { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
177 { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
178 { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
179};
180#define RATES_24_OFFS 0
181#define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
182#define RATES_52_OFFS 4
183#define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
184
185/**
186 * enum iwl_nvm_channel_flags - channel flags in NVM
187 * @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
188 * @NVM_CHANNEL_IBSS: usable as an IBSS channel
189 * @NVM_CHANNEL_ACTIVE: active scanning allowed
190 * @NVM_CHANNEL_RADAR: radar detection required
David Spinadel9ee6dac2013-05-29 11:37:28 +0300191 * @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed
192 * @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
193 * on same channel on 2.4 or same UNII band on 5.2
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100194 * @NVM_CHANNEL_WIDE: 20 MHz channel okay (?)
195 * @NVM_CHANNEL_40MHZ: 40 MHz channel okay (?)
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200196 * @NVM_CHANNEL_80MHZ: 80 MHz channel okay (?)
197 * @NVM_CHANNEL_160MHZ: 160 MHz channel okay (?)
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100198 */
199enum iwl_nvm_channel_flags {
200 NVM_CHANNEL_VALID = BIT(0),
201 NVM_CHANNEL_IBSS = BIT(1),
202 NVM_CHANNEL_ACTIVE = BIT(3),
203 NVM_CHANNEL_RADAR = BIT(4),
David Spinadel9ee6dac2013-05-29 11:37:28 +0300204 NVM_CHANNEL_INDOOR_ONLY = BIT(5),
205 NVM_CHANNEL_GO_CONCURRENT = BIT(6),
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100206 NVM_CHANNEL_WIDE = BIT(8),
207 NVM_CHANNEL_40MHZ = BIT(9),
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200208 NVM_CHANNEL_80MHZ = BIT(10),
209 NVM_CHANNEL_160MHZ = BIT(11),
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100210};
211
212#define CHECK_AND_PRINT_I(x) \
213 ((ch_flags & NVM_CHANNEL_##x) ? # x " " : "")
214
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200215static u32 iwl_get_channel_flags(u8 ch_num, int ch_idx, bool is_5ghz,
Matti Gottliebb281c932014-06-26 11:10:57 +0300216 u16 nvm_flags, const struct iwl_cfg *cfg)
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200217{
218 u32 flags = IEEE80211_CHAN_NO_HT40;
Matti Gottliebb281c932014-06-26 11:10:57 +0300219 u32 last_5ghz_ht = LAST_5GHZ_HT;
220
221 if (cfg->device_family == IWL_DEVICE_FAMILY_8000)
222 last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200223
224 if (!is_5ghz && (nvm_flags & NVM_CHANNEL_40MHZ)) {
225 if (ch_num <= LAST_2GHZ_HT_PLUS)
226 flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
227 if (ch_num >= FIRST_2GHZ_HT_MINUS)
228 flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
Matti Gottliebb281c932014-06-26 11:10:57 +0300229 } else if (ch_num <= last_5ghz_ht && (nvm_flags & NVM_CHANNEL_40MHZ)) {
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200230 if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
231 flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
232 else
233 flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
234 }
235 if (!(nvm_flags & NVM_CHANNEL_80MHZ))
236 flags |= IEEE80211_CHAN_NO_80MHZ;
237 if (!(nvm_flags & NVM_CHANNEL_160MHZ))
238 flags |= IEEE80211_CHAN_NO_160MHZ;
239
240 if (!(nvm_flags & NVM_CHANNEL_IBSS))
241 flags |= IEEE80211_CHAN_NO_IR;
242
243 if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
244 flags |= IEEE80211_CHAN_NO_IR;
245
246 if (nvm_flags & NVM_CHANNEL_RADAR)
247 flags |= IEEE80211_CHAN_RADAR;
248
249 if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
250 flags |= IEEE80211_CHAN_INDOOR_ONLY;
251
252 /* Set the GO concurrent flag only in case that NO_IR is set.
253 * Otherwise it is meaningless
254 */
255 if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
256 (flags & IEEE80211_CHAN_NO_IR))
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300257 flags |= IEEE80211_CHAN_IR_CONCURRENT;
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200258
259 return flags;
260}
261
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100262static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
263 struct iwl_nvm_data *data,
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200264 const __le16 * const nvm_ch_flags,
265 bool lar_supported)
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100266{
267 int ch_idx;
268 int n_channels = 0;
269 struct ieee80211_channel *channel;
270 u16 ch_flags;
271 bool is_5ghz;
Eran Harary749f1fe2014-03-06 09:25:30 +0200272 int num_of_ch, num_2ghz_channels;
Eran Harary77db0a32014-02-04 14:21:38 +0200273 const u8 *nvm_chan;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100274
Eran Harary77db0a32014-02-04 14:21:38 +0200275 if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
276 num_of_ch = IWL_NUM_CHANNELS;
277 nvm_chan = &iwl_nvm_channels[0];
Eran Harary749f1fe2014-03-06 09:25:30 +0200278 num_2ghz_channels = NUM_2GHZ_CHANNELS;
Eran Harary77db0a32014-02-04 14:21:38 +0200279 } else {
280 num_of_ch = IWL_NUM_CHANNELS_FAMILY_8000;
281 nvm_chan = &iwl_nvm_channels_family_8000[0];
Eran Harary749f1fe2014-03-06 09:25:30 +0200282 num_2ghz_channels = NUM_2GHZ_CHANNELS_FAMILY_8000;
Eran Harary77db0a32014-02-04 14:21:38 +0200283 }
284
285 for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100286 ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
Emmanuel Grumbachc5128652013-12-05 22:42:55 +0200287
Eran Harary749f1fe2014-03-06 09:25:30 +0200288 if (ch_idx >= num_2ghz_channels &&
Emmanuel Grumbachc5128652013-12-05 22:42:55 +0200289 !data->sku_cap_band_52GHz_enable)
Eliad Pellera76f3bf2014-05-26 18:11:37 +0300290 continue;
Emmanuel Grumbachc5128652013-12-05 22:42:55 +0200291
Gregory Greenman4896d762016-04-03 14:06:12 +0300292 if (ch_flags & NVM_CHANNEL_160MHZ)
293 data->vht160_supported = true;
294
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200295 if (!lar_supported && !(ch_flags & NVM_CHANNEL_VALID)) {
Eliad Pellera76f3bf2014-05-26 18:11:37 +0300296 /*
297 * Channels might become valid later if lar is
298 * supported, hence we still want to add them to
299 * the list of supported channels to cfg80211.
300 */
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100301 IWL_DEBUG_EEPROM(dev,
302 "Ch. %d Flags %x [%sGHz] - No traffic\n",
Eran Harary77db0a32014-02-04 14:21:38 +0200303 nvm_chan[ch_idx],
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100304 ch_flags,
Eran Harary749f1fe2014-03-06 09:25:30 +0200305 (ch_idx >= num_2ghz_channels) ?
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100306 "5.2" : "2.4");
307 continue;
308 }
309
310 channel = &data->channels[n_channels];
311 n_channels++;
312
Eran Harary77db0a32014-02-04 14:21:38 +0200313 channel->hw_value = nvm_chan[ch_idx];
Eran Harary749f1fe2014-03-06 09:25:30 +0200314 channel->band = (ch_idx < num_2ghz_channels) ?
Johannes Berg57fbcce2016-04-12 15:56:15 +0200315 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100316 channel->center_freq =
317 ieee80211_channel_to_frequency(
318 channel->hw_value, channel->band);
319
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100320 /* Initialize regulatory-based run-time data */
321
Matti Gottlieb88f2fd72013-07-09 15:25:46 +0300322 /*
323 * Default value - highest tx power value. max_power
324 * is not used in mvm, and is used for backwards compatibility
325 */
Eliad Peller22d059a2014-08-26 11:23:11 +0300326 channel->max_power = IWL_DEFAULT_MAX_TX_POWER;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200327 is_5ghz = channel->band == NL80211_BAND_5GHZ;
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200328
329 /* don't put limitations in case we're using LAR */
330 if (!lar_supported)
331 channel->flags = iwl_get_channel_flags(nvm_chan[ch_idx],
332 ch_idx, is_5ghz,
Matti Gottliebb281c932014-06-26 11:10:57 +0300333 ch_flags, cfg);
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200334 else
335 channel->flags = 0;
336
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100337 IWL_DEBUG_EEPROM(dev,
Gregory Greenman4896d762016-04-03 14:06:12 +0300338 "Ch. %d [%sGHz] flags 0x%x %s%s%s%s%s%s%s%s%s%s(%ddBm): Ad-Hoc %ssupported\n",
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100339 channel->hw_value,
340 is_5ghz ? "5.2" : "2.4",
Gregory Greenman4896d762016-04-03 14:06:12 +0300341 ch_flags,
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100342 CHECK_AND_PRINT_I(VALID),
343 CHECK_AND_PRINT_I(IBSS),
344 CHECK_AND_PRINT_I(ACTIVE),
345 CHECK_AND_PRINT_I(RADAR),
David Spinadel9ee6dac2013-05-29 11:37:28 +0300346 CHECK_AND_PRINT_I(INDOOR_ONLY),
347 CHECK_AND_PRINT_I(GO_CONCURRENT),
Gregory Greenman4896d762016-04-03 14:06:12 +0300348 CHECK_AND_PRINT_I(WIDE),
349 CHECK_AND_PRINT_I(40MHZ),
350 CHECK_AND_PRINT_I(80MHZ),
351 CHECK_AND_PRINT_I(160MHZ),
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100352 channel->max_power,
353 ((ch_flags & NVM_CHANNEL_IBSS) &&
354 !(ch_flags & NVM_CHANNEL_RADAR))
355 ? "" : "not ");
356 }
357
358 return n_channels;
359}
360
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200361static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
362 struct iwl_nvm_data *data,
Johannes Berg6ca89f12014-02-12 21:56:26 +0100363 struct ieee80211_sta_vht_cap *vht_cap,
364 u8 tx_chains, u8 rx_chains)
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200365{
Johannes Berg6ca89f12014-02-12 21:56:26 +0100366 int num_rx_ants = num_of_ant(rx_chains);
367 int num_tx_ants = num_of_ant(tx_chains);
Eran Hararyc064ddf2014-09-30 06:42:06 +0200368 unsigned int max_ampdu_exponent = (cfg->max_vht_ampdu_exponent ?:
369 IEEE80211_VHT_MAX_AMPDU_1024K);
Eyal Shapira48e6de62013-11-03 10:04:08 +0200370
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200371 vht_cap->vht_supported = true;
372
373 vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 |
374 IEEE80211_VHT_CAP_RXSTBC_1 |
375 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
Eyal Shapirae36b7662014-01-06 20:16:48 +0200376 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
Eran Hararyc064ddf2014-09-30 06:42:06 +0200377 max_ampdu_exponent <<
378 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200379
Gregory Greenman4896d762016-04-03 14:06:12 +0300380 if (data->vht160_supported)
Gregory Greenmanfbbd4852016-04-12 15:16:24 +0300381 vht_cap->cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
382 IEEE80211_VHT_CAP_SHORT_GI_160;
Gregory Greenman4896d762016-04-03 14:06:12 +0300383
Sara Sharone48c9472016-01-27 18:59:48 +0200384 if (cfg->vht_mu_mimo_supported)
385 vht_cap->cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
386
Eyal Shapiraa3576ff2014-08-09 10:57:59 +0300387 if (cfg->ht_params->ldpc)
388 vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC;
389
Emmanuel Grumbach5f0d98f2014-10-30 10:19:38 +0200390 if (data->sku_cap_mimo_disabled) {
391 num_rx_ants = 1;
392 num_tx_ants = 1;
393 }
394
Johannes Berg6ca89f12014-02-12 21:56:26 +0100395 if (num_tx_ants > 1)
Eyal Shapira5f7a6f92013-11-12 22:40:40 +0200396 vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
Johannes Berg6ca89f12014-02-12 21:56:26 +0100397 else
398 vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
Eyal Shapira5f7a6f92013-11-12 22:40:40 +0200399
Emmanuel Grumbach6c4fbcb2015-11-10 11:57:41 +0200400 switch (iwlwifi_mod_params.amsdu_size) {
Emmanuel Grumbach4bdd4df2016-04-07 16:44:42 +0300401 case IWL_AMSDU_DEF:
402 if (cfg->mq_rx_supported)
403 vht_cap->cap |=
404 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
405 else
406 vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
407 break;
Emmanuel Grumbach6c4fbcb2015-11-10 11:57:41 +0200408 case IWL_AMSDU_4K:
409 vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
410 break;
411 case IWL_AMSDU_8K:
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200412 vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
Emmanuel Grumbach6c4fbcb2015-11-10 11:57:41 +0200413 break;
414 case IWL_AMSDU_12K:
415 vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
416 break;
417 default:
418 break;
419 }
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200420
421 vht_cap->vht_mcs.rx_mcs_map =
422 cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
423 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
424 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
425 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
426 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
427 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
428 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
429 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
430
Johannes Berg6ca89f12014-02-12 21:56:26 +0100431 if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) {
432 vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
Eytan Lifshitz33158fe2013-02-20 11:01:13 +0200433 /* this works because NOT_SUPPORTED == 3 */
434 vht_cap->vht_mcs.rx_mcs_map |=
435 cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2);
436 }
437
438 vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
439}
440
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100441static void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
Eran Harary77db0a32014-02-04 14:21:38 +0200442 struct iwl_nvm_data *data,
Eliad Peller2926f952014-10-23 16:29:10 +0300443 const __le16 *ch_section,
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200444 u8 tx_chains, u8 rx_chains, bool lar_supported)
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100445{
Eran Harary77db0a32014-02-04 14:21:38 +0200446 int n_channels;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100447 int n_used = 0;
448 struct ieee80211_supported_band *sband;
449
Eran Harary77db0a32014-02-04 14:21:38 +0200450 if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
451 n_channels = iwl_init_channel_map(
452 dev, cfg, data,
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200453 &ch_section[NVM_CHANNELS], lar_supported);
Eran Harary77db0a32014-02-04 14:21:38 +0200454 else
455 n_channels = iwl_init_channel_map(
456 dev, cfg, data,
Arik Nemtsov770ceda2014-03-23 16:18:40 +0200457 &ch_section[NVM_CHANNELS_FAMILY_8000],
458 lar_supported);
Eran Harary77db0a32014-02-04 14:21:38 +0200459
Johannes Berg57fbcce2016-04-12 15:56:15 +0200460 sband = &data->bands[NL80211_BAND_2GHZ];
461 sband->band = NL80211_BAND_2GHZ;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100462 sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
463 sband->n_bitrates = N_RATES_24;
464 n_used += iwl_init_sband_channels(data, sband, n_channels,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200465 NL80211_BAND_2GHZ);
466 iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_2GHZ,
Emmanuel Grumbach9ce4fa72013-05-22 13:16:23 +0300467 tx_chains, rx_chains);
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100468
Johannes Berg57fbcce2016-04-12 15:56:15 +0200469 sband = &data->bands[NL80211_BAND_5GHZ];
470 sband->band = NL80211_BAND_5GHZ;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100471 sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
472 sband->n_bitrates = N_RATES_52;
473 n_used += iwl_init_sband_channels(data, sband, n_channels,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200474 NL80211_BAND_5GHZ);
475 iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_5GHZ,
Emmanuel Grumbach9ce4fa72013-05-22 13:16:23 +0300476 tx_chains, rx_chains);
Andrei Otcheretianski0d0985a2016-02-29 13:25:48 +0200477 if (data->sku_cap_11ac_enable && !iwlwifi_mod_params.disable_11ac)
Johannes Berg6ca89f12014-02-12 21:56:26 +0100478 iwl_init_vht_hw_capab(cfg, data, &sband->vht_cap,
479 tx_chains, rx_chains);
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100480
481 if (n_channels != n_used)
482 IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n",
483 n_used, n_channels);
484}
485
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200486static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
487 const __le16 *phy_sku)
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100488{
Eran Harary77db0a32014-02-04 14:21:38 +0200489 if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
490 return le16_to_cpup(nvm_sw + SKU);
Eran Hararyce500072014-12-01 17:53:53 +0200491
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200492 return le32_to_cpup((__le32 *)(phy_sku + SKU_FAMILY_8000));
Eran Harary77db0a32014-02-04 14:21:38 +0200493}
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100494
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200495static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
Eran Harary77db0a32014-02-04 14:21:38 +0200496{
497 if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
498 return le16_to_cpup(nvm_sw + NVM_VERSION);
499 else
500 return le32_to_cpup((__le32 *)(nvm_sw +
501 NVM_VERSION_FAMILY_8000));
502}
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100503
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200504static int iwl_get_radio_cfg(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
505 const __le16 *phy_sku)
Eran Harary77db0a32014-02-04 14:21:38 +0200506{
507 if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
508 return le16_to_cpup(nvm_sw + RADIO_CFG);
Eran Hararyce500072014-12-01 17:53:53 +0200509
Liad Kaufmanf115fdf2015-05-19 14:20:25 +0300510 return le32_to_cpup((__le32 *)(phy_sku + RADIO_CFG_FAMILY_8000));
Eran Hararyce500072014-12-01 17:53:53 +0200511
Eran Harary77db0a32014-02-04 14:21:38 +0200512}
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100513
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200514static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
Eran Harary77db0a32014-02-04 14:21:38 +0200515{
Eran Hararyce500072014-12-01 17:53:53 +0200516 int n_hw_addr;
517
Eran Harary77db0a32014-02-04 14:21:38 +0200518 if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
519 return le16_to_cpup(nvm_sw + N_HW_ADDRS);
Eran Hararyce500072014-12-01 17:53:53 +0200520
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200521 n_hw_addr = le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000));
Eran Hararyce500072014-12-01 17:53:53 +0200522
523 return n_hw_addr & N_HW_ADDR_MASK;
Eran Harary77db0a32014-02-04 14:21:38 +0200524}
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100525
Eran Harary77db0a32014-02-04 14:21:38 +0200526static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
527 struct iwl_nvm_data *data,
528 u32 radio_cfg)
529{
530 if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
531 data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg);
532 data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg);
533 data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg);
534 data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg);
Eran Harary77db0a32014-02-04 14:21:38 +0200535 return;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100536 }
537
Eran Harary77db0a32014-02-04 14:21:38 +0200538 /* set the radio configuration for family 8000 */
539 data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK_FAMILY_8000(radio_cfg);
540 data->radio_cfg_step = NVM_RF_CFG_STEP_MSK_FAMILY_8000(radio_cfg);
541 data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK_FAMILY_8000(radio_cfg);
542 data->radio_cfg_pnum = NVM_RF_CFG_FLAVOR_MSK_FAMILY_8000(radio_cfg);
Moshe Harela0544272014-12-08 21:13:14 +0200543 data->valid_tx_ant = NVM_RF_CFG_TX_ANT_MSK_FAMILY_8000(radio_cfg);
544 data->valid_rx_ant = NVM_RF_CFG_RX_ANT_MSK_FAMILY_8000(radio_cfg);
Eran Harary77db0a32014-02-04 14:21:38 +0200545}
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100546
Sara Sharon17c867b2016-03-07 14:18:29 +0200547static void iwl_flip_hw_address(__le32 mac_addr0, __le32 mac_addr1, u8 *dest)
548{
549 const u8 *hw_addr;
550
551 hw_addr = (const u8 *)&mac_addr0;
552 dest[0] = hw_addr[3];
553 dest[1] = hw_addr[2];
554 dest[2] = hw_addr[1];
555 dest[3] = hw_addr[0];
556
557 hw_addr = (const u8 *)&mac_addr1;
558 dest[4] = hw_addr[1];
559 dest[5] = hw_addr[0];
560}
561
562static void iwl_set_hw_address_from_csr(struct iwl_trans *trans,
563 struct iwl_nvm_data *data)
564{
565 __le32 mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_STRAP));
566 __le32 mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_STRAP));
567
Haim Dreyfussa6c934b2016-08-02 15:28:23 +0300568 iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
569 /*
570 * If the OEM fused a valid address, use it instead of the one in the
571 * OTP
572 */
573 if (is_valid_ether_addr(data->hw_addr))
574 return;
575
576 mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_OTP));
577 mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_OTP));
Sara Sharon17c867b2016-03-07 14:18:29 +0200578
579 iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
580}
581
Sara Sharonafd5b172016-03-01 12:18:22 +0200582static void iwl_set_hw_address_family_8000(struct iwl_trans *trans,
Eran Harary6a68a392014-05-07 11:09:11 +0300583 const struct iwl_cfg *cfg,
Eran Harary9f32e012014-04-28 15:22:40 +0300584 struct iwl_nvm_data *data,
585 const __le16 *mac_override,
Sara Sharonafd5b172016-03-01 12:18:22 +0200586 const __le16 *nvm_hw)
Eran Harary9f32e012014-04-28 15:22:40 +0300587{
588 const u8 *hw_addr;
589
590 if (mac_override) {
Liad Kaufman18f84672015-05-20 15:50:07 +0300591 static const u8 reserved_mac[] = {
592 0x02, 0xcc, 0xaa, 0xff, 0xee, 0x00
593 };
594
Eran Harary9f32e012014-04-28 15:22:40 +0300595 hw_addr = (const u8 *)(mac_override +
596 MAC_ADDRESS_OVERRIDE_FAMILY_8000);
597
Liad Kaufmanbe88a1a2015-07-01 17:28:34 +0300598 /*
599 * Store the MAC address from MAO section.
600 * No byte swapping is required in MAO section
601 */
602 memcpy(data->hw_addr, hw_addr, ETH_ALEN);
Eran Harary9f32e012014-04-28 15:22:40 +0300603
Liad Kaufman18f84672015-05-20 15:50:07 +0300604 /*
605 * Force the use of the OTP MAC address in case of reserved MAC
606 * address in the NVM, or if address is given but invalid.
607 */
608 if (is_valid_ether_addr(data->hw_addr) &&
609 memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0)
Eran Harary9f32e012014-04-28 15:22:40 +0300610 return;
Eran Harary6a68a392014-05-07 11:09:11 +0300611
Sara Sharonafd5b172016-03-01 12:18:22 +0200612 IWL_ERR(trans,
613 "mac address from nvm override section is not valid\n");
Eran Harary9f32e012014-04-28 15:22:40 +0300614 }
615
Eran Harary6a68a392014-05-07 11:09:11 +0300616 if (nvm_hw) {
Sara Sharonafd5b172016-03-01 12:18:22 +0200617 /* read the mac address from WFMP registers */
618 __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans,
619 WFMP_MAC_ADDR_0));
620 __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans,
621 WFMP_MAC_ADDR_1));
Eran Harary9f32e012014-04-28 15:22:40 +0300622
Sara Sharon17c867b2016-03-07 14:18:29 +0200623 iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
Eran Harary1e0b3932014-06-11 11:37:09 +0300624
Eran Harary6a68a392014-05-07 11:09:11 +0300625 return;
626 }
627
Sara Sharonafd5b172016-03-01 12:18:22 +0200628 IWL_ERR(trans, "mac address is not found\n");
629}
630
Sara Sharon17c867b2016-03-07 14:18:29 +0200631static int iwl_set_hw_address(struct iwl_trans *trans,
632 const struct iwl_cfg *cfg,
633 struct iwl_nvm_data *data, const __le16 *nvm_hw,
634 const __le16 *mac_override)
Sara Sharonafd5b172016-03-01 12:18:22 +0200635{
Sara Sharon17c867b2016-03-07 14:18:29 +0200636 if (cfg->mac_addr_from_csr) {
637 iwl_set_hw_address_from_csr(trans, data);
638 } else if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
Sara Sharonafd5b172016-03-01 12:18:22 +0200639 const u8 *hw_addr = (const u8 *)(nvm_hw + HW_ADDR);
640
641 /* The byte order is little endian 16 bit, meaning 214365 */
642 data->hw_addr[0] = hw_addr[1];
643 data->hw_addr[1] = hw_addr[0];
644 data->hw_addr[2] = hw_addr[3];
645 data->hw_addr[3] = hw_addr[2];
646 data->hw_addr[4] = hw_addr[5];
647 data->hw_addr[5] = hw_addr[4];
648 } else {
649 iwl_set_hw_address_family_8000(trans, cfg, data,
650 mac_override, nvm_hw);
651 }
Sara Sharon17c867b2016-03-07 14:18:29 +0200652
653 if (!is_valid_ether_addr(data->hw_addr)) {
654 IWL_ERR(trans, "no valid mac address was found\n");
655 return -EINVAL;
656 }
657
658 return 0;
Eran Harary9f32e012014-04-28 15:22:40 +0300659}
660
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100661struct iwl_nvm_data *
Sara Sharonafd5b172016-03-01 12:18:22 +0200662iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100663 const __le16 *nvm_hw, const __le16 *nvm_sw,
Eran Harary77db0a32014-02-04 14:21:38 +0200664 const __le16 *nvm_calib, const __le16 *regulatory,
Eran Hararyce500072014-12-01 17:53:53 +0200665 const __le16 *mac_override, const __le16 *phy_sku,
Sara Sharonafd5b172016-03-01 12:18:22 +0200666 u8 tx_chains, u8 rx_chains, bool lar_fw_supported)
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100667{
Sara Sharonafd5b172016-03-01 12:18:22 +0200668 struct device *dev = trans->dev;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100669 struct iwl_nvm_data *data;
Sara Sharonafd5b172016-03-01 12:18:22 +0200670 bool lar_enabled;
671 u32 sku, radio_cfg;
Matti Gottliebd0d15192014-07-31 09:16:25 +0300672 u16 lar_config;
Sara Sharonafd5b172016-03-01 12:18:22 +0200673 const __le16 *ch_section;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100674
Eran Harary77db0a32014-02-04 14:21:38 +0200675 if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
676 data = kzalloc(sizeof(*data) +
677 sizeof(struct ieee80211_channel) *
678 IWL_NUM_CHANNELS,
679 GFP_KERNEL);
680 else
681 data = kzalloc(sizeof(*data) +
682 sizeof(struct ieee80211_channel) *
683 IWL_NUM_CHANNELS_FAMILY_8000,
684 GFP_KERNEL);
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100685 if (!data)
686 return NULL;
687
Eran Harary77db0a32014-02-04 14:21:38 +0200688 data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw);
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100689
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200690 radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw, phy_sku);
Eran Harary77db0a32014-02-04 14:21:38 +0200691 iwl_set_radio_cfg(cfg, data, radio_cfg);
Moshe Harela0544272014-12-08 21:13:14 +0200692 if (data->valid_tx_ant)
693 tx_chains &= data->valid_tx_ant;
694 if (data->valid_rx_ant)
695 rx_chains &= data->valid_rx_ant;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100696
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200697 sku = iwl_get_sku(cfg, nvm_sw, phy_sku);
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100698 data->sku_cap_band_24GHz_enable = sku & NVM_SKU_CAP_BAND_24GHZ;
699 data->sku_cap_band_52GHz_enable = sku & NVM_SKU_CAP_BAND_52GHZ;
700 data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE;
701 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
702 data->sku_cap_11n_enable = false;
Eliad Peller2926f952014-10-23 16:29:10 +0300703 data->sku_cap_11ac_enable = data->sku_cap_11n_enable &&
704 (sku & NVM_SKU_CAP_11AC_ENABLE);
Emmanuel Grumbach5f0d98f2014-10-30 10:19:38 +0200705 data->sku_cap_mimo_disabled = sku & NVM_SKU_CAP_MIMO_DISABLE;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100706
Emmanuel Grumbach5dd9c682015-03-05 13:06:13 +0200707 data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100708
Eran Harary77db0a32014-02-04 14:21:38 +0200709 if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
710 /* Checking for required sections */
711 if (!nvm_calib) {
Sara Sharonafd5b172016-03-01 12:18:22 +0200712 IWL_ERR(trans,
713 "Can't parse empty Calib NVM sections\n");
Eytan Lifshitz1270c412014-02-18 15:02:29 +0200714 kfree(data);
Eran Harary77db0a32014-02-04 14:21:38 +0200715 return NULL;
716 }
717 /* in family 8000 Xtal calibration values moved to OTP */
718 data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
719 data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
Sara Sharonafd5b172016-03-01 12:18:22 +0200720 lar_enabled = true;
721 ch_section = nvm_sw;
Eran Harary77db0a32014-02-04 14:21:38 +0200722 } else {
Arik Nemtsovf5528632015-02-04 15:38:56 +0200723 u16 lar_offset = data->nvm_version < 0xE39 ?
724 NVM_LAR_OFFSET_FAMILY_8000_OLD :
725 NVM_LAR_OFFSET_FAMILY_8000;
726
727 lar_config = le16_to_cpup(regulatory + lar_offset);
Matti Gottliebd0d15192014-07-31 09:16:25 +0300728 data->lar_enabled = !!(lar_config &
729 NVM_LAR_ENABLED_FAMILY_8000);
Sara Sharonafd5b172016-03-01 12:18:22 +0200730 lar_enabled = data->lar_enabled;
731 ch_section = regulatory;
Eran Harary77db0a32014-02-04 14:21:38 +0200732 }
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100733
Sara Sharon17c867b2016-03-07 14:18:29 +0200734 /* If no valid mac address was found - bail out */
735 if (iwl_set_hw_address(trans, cfg, data, nvm_hw, mac_override)) {
736 kfree(data);
737 return NULL;
738 }
739
Sara Sharonafd5b172016-03-01 12:18:22 +0200740 iwl_init_sbands(dev, cfg, data, ch_section, tx_chains, rx_chains,
741 lar_fw_supported && lar_enabled);
Emmanuel Grumbach33b2f682014-01-14 13:48:22 +0200742 data->calib_version = 255;
Johannes Bergb1e1adf2013-01-24 14:14:22 +0100743
744 return data;
745}
Johannes Berg48e29342013-03-01 00:13:33 +0100746IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200747
748static u32 iwl_nvm_get_regdom_bw_flags(const u8 *nvm_chan,
Matti Gottliebb281c932014-06-26 11:10:57 +0300749 int ch_idx, u16 nvm_flags,
750 const struct iwl_cfg *cfg)
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200751{
752 u32 flags = NL80211_RRF_NO_HT40;
Matti Gottliebb281c932014-06-26 11:10:57 +0300753 u32 last_5ghz_ht = LAST_5GHZ_HT;
754
755 if (cfg->device_family == IWL_DEVICE_FAMILY_8000)
756 last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200757
758 if (ch_idx < NUM_2GHZ_CHANNELS &&
759 (nvm_flags & NVM_CHANNEL_40MHZ)) {
760 if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS)
761 flags &= ~NL80211_RRF_NO_HT40PLUS;
762 if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS)
763 flags &= ~NL80211_RRF_NO_HT40MINUS;
Matti Gottliebb281c932014-06-26 11:10:57 +0300764 } else if (nvm_chan[ch_idx] <= last_5ghz_ht &&
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200765 (nvm_flags & NVM_CHANNEL_40MHZ)) {
766 if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
767 flags &= ~NL80211_RRF_NO_HT40PLUS;
768 else
769 flags &= ~NL80211_RRF_NO_HT40MINUS;
770 }
771
772 if (!(nvm_flags & NVM_CHANNEL_80MHZ))
773 flags |= NL80211_RRF_NO_80MHZ;
774 if (!(nvm_flags & NVM_CHANNEL_160MHZ))
775 flags |= NL80211_RRF_NO_160MHZ;
776
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200777 if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
778 flags |= NL80211_RRF_NO_IR;
779
780 if (nvm_flags & NVM_CHANNEL_RADAR)
781 flags |= NL80211_RRF_DFS;
782
783 if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
784 flags |= NL80211_RRF_NO_OUTDOOR;
785
786 /* Set the GO concurrent flag only in case that NO_IR is set.
787 * Otherwise it is meaningless
788 */
789 if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
790 (flags & NL80211_RRF_NO_IR))
791 flags |= NL80211_RRF_GO_CONCURRENT;
792
793 return flags;
794}
795
796struct ieee80211_regdomain *
Arik Nemtsov162ee3c2014-06-10 11:25:35 +0300797iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
798 int num_of_ch, __le32 *channels, u16 fw_mcc)
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200799{
800 int ch_idx;
801 u16 ch_flags, prev_ch_flags = 0;
Arik Nemtsov162ee3c2014-06-10 11:25:35 +0300802 const u8 *nvm_chan = cfg->device_family == IWL_DEVICE_FAMILY_8000 ?
803 iwl_nvm_channels_family_8000 : iwl_nvm_channels;
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200804 struct ieee80211_regdomain *regd;
805 int size_of_regd;
806 struct ieee80211_reg_rule *rule;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200807 enum nl80211_band band;
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200808 int center_freq, prev_center_freq = 0;
809 int valid_rules = 0;
810 bool new_rule;
Arik Nemtsov4557eab2015-03-01 18:24:57 +0200811 int max_num_ch = cfg->device_family == IWL_DEVICE_FAMILY_8000 ?
812 IWL_NUM_CHANNELS_FAMILY_8000 : IWL_NUM_CHANNELS;
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200813
814 if (WARN_ON_ONCE(num_of_ch > NL80211_MAX_SUPP_REG_RULES))
815 return ERR_PTR(-EINVAL);
816
Arik Nemtsov4557eab2015-03-01 18:24:57 +0200817 if (WARN_ON(num_of_ch > max_num_ch))
818 num_of_ch = max_num_ch;
819
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200820 IWL_DEBUG_DEV(dev, IWL_DL_LAR, "building regdom for %d channels\n",
821 num_of_ch);
822
823 /* build a regdomain rule for every valid channel */
824 size_of_regd =
825 sizeof(struct ieee80211_regdomain) +
826 num_of_ch * sizeof(struct ieee80211_reg_rule);
827
828 regd = kzalloc(size_of_regd, GFP_KERNEL);
829 if (!regd)
830 return ERR_PTR(-ENOMEM);
831
832 for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
833 ch_flags = (u16)__le32_to_cpup(channels + ch_idx);
834 band = (ch_idx < NUM_2GHZ_CHANNELS) ?
Johannes Berg57fbcce2016-04-12 15:56:15 +0200835 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200836 center_freq = ieee80211_channel_to_frequency(nvm_chan[ch_idx],
837 band);
838 new_rule = false;
839
840 if (!(ch_flags & NVM_CHANNEL_VALID)) {
841 IWL_DEBUG_DEV(dev, IWL_DL_LAR,
842 "Ch. %d Flags %x [%sGHz] - No traffic\n",
843 nvm_chan[ch_idx],
844 ch_flags,
845 (ch_idx >= NUM_2GHZ_CHANNELS) ?
846 "5.2" : "2.4");
847 continue;
848 }
849
850 /* we can't continue the same rule */
851 if (ch_idx == 0 || prev_ch_flags != ch_flags ||
852 center_freq - prev_center_freq > 20) {
853 valid_rules++;
854 new_rule = true;
855 }
856
857 rule = &regd->reg_rules[valid_rules - 1];
858
859 if (new_rule)
860 rule->freq_range.start_freq_khz =
861 MHZ_TO_KHZ(center_freq - 10);
862
863 rule->freq_range.end_freq_khz = MHZ_TO_KHZ(center_freq + 10);
864
865 /* this doesn't matter - not used by FW */
866 rule->power_rule.max_antenna_gain = DBI_TO_MBI(6);
Eliad Peller02a50492014-09-07 17:45:11 +0300867 rule->power_rule.max_eirp =
868 DBM_TO_MBM(IWL_DEFAULT_MAX_TX_POWER);
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200869
870 rule->flags = iwl_nvm_get_regdom_bw_flags(nvm_chan, ch_idx,
Matti Gottliebb281c932014-06-26 11:10:57 +0300871 ch_flags, cfg);
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200872
873 /* rely on auto-calculation to merge BW of contiguous chans */
874 rule->flags |= NL80211_RRF_AUTO_BW;
875 rule->freq_range.max_bandwidth_khz = 0;
876
877 prev_ch_flags = ch_flags;
878 prev_center_freq = center_freq;
879
880 IWL_DEBUG_DEV(dev, IWL_DL_LAR,
Arik Nemtsovbdf2fae2014-10-30 15:12:39 +0200881 "Ch. %d [%sGHz] %s%s%s%s%s%s%s%s%s(0x%02x): Ad-Hoc %ssupported\n",
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200882 center_freq,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200883 band == NL80211_BAND_5GHZ ? "5.2" : "2.4",
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200884 CHECK_AND_PRINT_I(VALID),
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200885 CHECK_AND_PRINT_I(ACTIVE),
886 CHECK_AND_PRINT_I(RADAR),
887 CHECK_AND_PRINT_I(WIDE),
888 CHECK_AND_PRINT_I(40MHZ),
889 CHECK_AND_PRINT_I(80MHZ),
890 CHECK_AND_PRINT_I(160MHZ),
891 CHECK_AND_PRINT_I(INDOOR_ONLY),
892 CHECK_AND_PRINT_I(GO_CONCURRENT),
893 ch_flags,
Arik Nemtsovbdf2fae2014-10-30 15:12:39 +0200894 ((ch_flags & NVM_CHANNEL_ACTIVE) &&
Arik Nemtsovaf45a902014-03-05 12:19:10 +0200895 !(ch_flags & NVM_CHANNEL_RADAR))
896 ? "" : "not ");
897 }
898
899 regd->n_reg_rules = valid_rules;
900
901 /* set alpha2 from FW. */
902 regd->alpha2[0] = fw_mcc >> 8;
903 regd->alpha2[1] = fw_mcc & 0xff;
904
905 return regd;
906}
907IWL_EXPORT_SYMBOL(iwl_parse_nvm_mcc_info);
Arik Nemtsov671bed32016-08-07 18:58:29 +0300908
909#ifdef CONFIG_ACPI
910#define WRDD_METHOD "WRDD"
911#define WRDD_WIFI (0x07)
912#define WRDD_WIGIG (0x10)
913
914static u32 iwl_wrdd_get_mcc(struct device *dev, union acpi_object *wrdd)
915{
916 union acpi_object *mcc_pkg, *domain_type, *mcc_value;
917 u32 i;
918
919 if (wrdd->type != ACPI_TYPE_PACKAGE ||
920 wrdd->package.count < 2 ||
921 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
922 wrdd->package.elements[0].integer.value != 0) {
923 IWL_DEBUG_EEPROM(dev, "Unsupported wrdd structure\n");
924 return 0;
925 }
926
927 for (i = 1 ; i < wrdd->package.count ; ++i) {
928 mcc_pkg = &wrdd->package.elements[i];
929
930 if (mcc_pkg->type != ACPI_TYPE_PACKAGE ||
931 mcc_pkg->package.count < 2 ||
932 mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
933 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
934 mcc_pkg = NULL;
935 continue;
936 }
937
938 domain_type = &mcc_pkg->package.elements[0];
939 if (domain_type->integer.value == WRDD_WIFI)
940 break;
941
942 mcc_pkg = NULL;
943 }
944
945 if (mcc_pkg) {
946 mcc_value = &mcc_pkg->package.elements[1];
947 return mcc_value->integer.value;
948 }
949
950 return 0;
951}
952
953int iwl_get_bios_mcc(struct device *dev, char *mcc)
954{
955 acpi_handle root_handle;
956 acpi_handle handle;
957 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
958 acpi_status status;
959 u32 mcc_val;
960
961 root_handle = ACPI_HANDLE(dev);
962 if (!root_handle) {
963 IWL_DEBUG_EEPROM(dev,
964 "Could not retrieve root port ACPI handle\n");
965 return -ENOENT;
966 }
967
968 /* Get the method's handle */
969 status = acpi_get_handle(root_handle, (acpi_string)WRDD_METHOD,
970 &handle);
971 if (ACPI_FAILURE(status)) {
972 IWL_DEBUG_EEPROM(dev, "WRD method not found\n");
973 return -ENOENT;
974 }
975
976 /* Call WRDD with no arguments */
977 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
978 if (ACPI_FAILURE(status)) {
979 IWL_DEBUG_EEPROM(dev, "WRDC invocation failed (0x%x)\n",
980 status);
981 return -ENOENT;
982 }
983
984 mcc_val = iwl_wrdd_get_mcc(dev, wrdd.pointer);
985 kfree(wrdd.pointer);
986 if (!mcc_val)
987 return -ENOENT;
988
989 mcc[0] = (mcc_val >> 8) & 0xff;
990 mcc[1] = mcc_val & 0xff;
991 mcc[2] = '\0';
992 return 0;
993}
994IWL_EXPORT_SYMBOL(iwl_get_bios_mcc);
995#endif