Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 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 Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 5f0d98f | 2014-10-30 10:19:38 +0200 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Sara Sharon | 2910849 | 2017-01-08 16:45:46 +0200 | [diff] [blame] | 10 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 11 | * |
| 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 Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 27 | * in the file called COPYING. |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 28 | * |
| 29 | * Contact Information: |
Emmanuel Grumbach | d01c536 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 32 | * |
| 33 | * BSD LICENSE |
| 34 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 35 | * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 5f0d98f | 2014-10-30 10:19:38 +0200 | [diff] [blame] | 36 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Sara Sharon | 2910849 | 2017-01-08 16:45:46 +0200 | [diff] [blame] | 37 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 38 | * All rights reserved. |
| 39 | * |
| 40 | * Redistribution and use in source and binary forms, with or without |
| 41 | * modification, are permitted provided that the following conditions |
| 42 | * are met: |
| 43 | * |
| 44 | * * Redistributions of source code must retain the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer. |
| 46 | * * Redistributions in binary form must reproduce the above copyright |
| 47 | * notice, this list of conditions and the following disclaimer in |
| 48 | * the documentation and/or other materials provided with the |
| 49 | * distribution. |
| 50 | * * Neither the name Intel Corporation nor the names of its |
| 51 | * contributors may be used to endorse or promote products derived |
| 52 | * from this software without specific prior written permission. |
| 53 | * |
| 54 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 55 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 56 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 57 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 58 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 59 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 60 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 61 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 62 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 63 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 64 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 65 | *****************************************************************************/ |
| 66 | #include <linux/types.h> |
| 67 | #include <linux/slab.h> |
| 68 | #include <linux/export.h> |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 69 | #include <linux/etherdevice.h> |
Eran Harary | 1e0b393 | 2014-06-11 11:37:09 +0300 | [diff] [blame] | 70 | #include <linux/pci.h> |
Arik Nemtsov | 671bed3 | 2016-08-07 18:58:29 +0300 | [diff] [blame] | 71 | #include <linux/acpi.h> |
Johannes Berg | 48e2934 | 2013-03-01 00:13:33 +0100 | [diff] [blame] | 72 | #include "iwl-drv.h" |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 73 | #include "iwl-modparams.h" |
| 74 | #include "iwl-nvm-parse.h" |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 75 | #include "iwl-prph.h" |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 76 | #include "iwl-io.h" |
| 77 | #include "iwl-csr.h" |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 78 | |
| 79 | /* NVM offsets (in words) definitions */ |
| 80 | enum wkp_nvm_offsets { |
| 81 | /* NVM HW-Section offset (in words) definitions */ |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 82 | SUBSYSTEM_ID = 0x0A, |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 83 | HW_ADDR = 0x15, |
| 84 | |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 85 | /* NVM SW-Section offset (in words) definitions */ |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 86 | NVM_SW_SECTION = 0x1C0, |
| 87 | NVM_VERSION = 0, |
| 88 | RADIO_CFG = 1, |
| 89 | SKU = 2, |
| 90 | N_HW_ADDRS = 3, |
| 91 | NVM_CHANNELS = 0x1E0 - NVM_SW_SECTION, |
| 92 | |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 93 | /* NVM calibration section offset (in words) definitions */ |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 94 | NVM_CALIB_SECTION = 0x2B8, |
| 95 | XTAL_CALIB = 0x316 - NVM_CALIB_SECTION |
| 96 | }; |
| 97 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 98 | enum ext_nvm_offsets { |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 99 | /* NVM HW-Section offset (in words) definitions */ |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 100 | MAC_ADDRESS_OVERRIDE_EXT_NVM = 1, |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 101 | |
| 102 | /* NVM SW-Section offset (in words) definitions */ |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 103 | NVM_VERSION_EXT_NVM = 0, |
| 104 | RADIO_CFG_FAMILY_EXT_NVM = 0, |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 105 | SKU_FAMILY_8000 = 2, |
| 106 | N_HW_ADDRS_FAMILY_8000 = 3, |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 107 | |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 108 | /* NVM REGULATORY -Section offset (in words) definitions */ |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 109 | NVM_CHANNELS_EXTENDED = 0, |
| 110 | NVM_LAR_OFFSET_OLD = 0x4C7, |
| 111 | NVM_LAR_OFFSET = 0x507, |
| 112 | NVM_LAR_ENABLED = 0x7, |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 113 | }; |
| 114 | |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 115 | /* SKU Capabilities (actual values from NVM definition) */ |
| 116 | enum nvm_sku_bits { |
Emmanuel Grumbach | 5f0d98f | 2014-10-30 10:19:38 +0200 | [diff] [blame] | 117 | NVM_SKU_CAP_BAND_24GHZ = BIT(0), |
| 118 | NVM_SKU_CAP_BAND_52GHZ = BIT(1), |
| 119 | NVM_SKU_CAP_11N_ENABLE = BIT(2), |
| 120 | NVM_SKU_CAP_11AC_ENABLE = BIT(3), |
| 121 | NVM_SKU_CAP_MIMO_DISABLE = BIT(5), |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 122 | }; |
| 123 | |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 124 | /* |
| 125 | * These are the channel numbers in the order that they are stored in the NVM |
| 126 | */ |
| 127 | static const u8 iwl_nvm_channels[] = { |
| 128 | /* 2.4 GHz */ |
| 129 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
| 130 | /* 5 GHz */ |
| 131 | 36, 40, 44 , 48, 52, 56, 60, 64, |
| 132 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, |
| 133 | 149, 153, 157, 161, 165 |
| 134 | }; |
| 135 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 136 | static const u8 iwl_ext_nvm_channels[] = { |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 137 | /* 2.4 GHz */ |
Eran Harary | 9b1c9a6 | 2014-05-07 08:22:41 +0300 | [diff] [blame] | 138 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 139 | /* 5 GHz */ |
| 140 | 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, |
| 141 | 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, |
| 142 | 149, 153, 157, 161, 165, 169, 173, 177, 181 |
| 143 | }; |
| 144 | |
Eran Harary | 749f1fe | 2014-03-06 09:25:30 +0200 | [diff] [blame] | 145 | #define IWL_NUM_CHANNELS ARRAY_SIZE(iwl_nvm_channels) |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 146 | #define IWL_NUM_CHANNELS_EXT ARRAY_SIZE(iwl_ext_nvm_channels) |
Eran Harary | 749f1fe | 2014-03-06 09:25:30 +0200 | [diff] [blame] | 147 | #define NUM_2GHZ_CHANNELS 14 |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 148 | #define NUM_2GHZ_CHANNELS_EXT 14 |
Eran Harary | 749f1fe | 2014-03-06 09:25:30 +0200 | [diff] [blame] | 149 | #define FIRST_2GHZ_HT_MINUS 5 |
| 150 | #define LAST_2GHZ_HT_PLUS 9 |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 151 | #define LAST_5GHZ_HT 165 |
| 152 | #define LAST_5GHZ_HT_FAMILY_8000 181 |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 153 | #define N_HW_ADDR_MASK 0xF |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 154 | |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 155 | /* rate data (static) */ |
| 156 | static struct ieee80211_rate iwl_cfg80211_rates[] = { |
| 157 | { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, }, |
| 158 | { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1, |
| 159 | .flags = IEEE80211_RATE_SHORT_PREAMBLE, }, |
| 160 | { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2, |
| 161 | .flags = IEEE80211_RATE_SHORT_PREAMBLE, }, |
| 162 | { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3, |
| 163 | .flags = IEEE80211_RATE_SHORT_PREAMBLE, }, |
| 164 | { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, }, |
| 165 | { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, }, |
| 166 | { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, }, |
| 167 | { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, }, |
| 168 | { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, }, |
| 169 | { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, }, |
| 170 | { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, }, |
| 171 | { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, }, |
| 172 | }; |
| 173 | #define RATES_24_OFFS 0 |
| 174 | #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates) |
| 175 | #define RATES_52_OFFS 4 |
| 176 | #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS) |
| 177 | |
| 178 | /** |
| 179 | * enum iwl_nvm_channel_flags - channel flags in NVM |
| 180 | * @NVM_CHANNEL_VALID: channel is usable for this SKU/geo |
| 181 | * @NVM_CHANNEL_IBSS: usable as an IBSS channel |
| 182 | * @NVM_CHANNEL_ACTIVE: active scanning allowed |
| 183 | * @NVM_CHANNEL_RADAR: radar detection required |
David Spinadel | 9ee6dac | 2013-05-29 11:37:28 +0300 | [diff] [blame] | 184 | * @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed |
| 185 | * @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS |
| 186 | * on same channel on 2.4 or same UNII band on 5.2 |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 187 | * @NVM_CHANNEL_UNIFORM: uniform spreading required |
| 188 | * @NVM_CHANNEL_20MHZ: 20 MHz channel okay |
| 189 | * @NVM_CHANNEL_40MHZ: 40 MHz channel okay |
| 190 | * @NVM_CHANNEL_80MHZ: 80 MHz channel okay |
| 191 | * @NVM_CHANNEL_160MHZ: 160 MHz channel okay |
| 192 | * @NVM_CHANNEL_DC_HIGH: DC HIGH required/allowed (?) |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 193 | */ |
| 194 | enum iwl_nvm_channel_flags { |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 195 | NVM_CHANNEL_VALID = BIT(0), |
| 196 | NVM_CHANNEL_IBSS = BIT(1), |
| 197 | NVM_CHANNEL_ACTIVE = BIT(3), |
| 198 | NVM_CHANNEL_RADAR = BIT(4), |
| 199 | NVM_CHANNEL_INDOOR_ONLY = BIT(5), |
| 200 | NVM_CHANNEL_GO_CONCURRENT = BIT(6), |
| 201 | NVM_CHANNEL_UNIFORM = BIT(7), |
| 202 | NVM_CHANNEL_20MHZ = BIT(8), |
| 203 | NVM_CHANNEL_40MHZ = BIT(9), |
| 204 | NVM_CHANNEL_80MHZ = BIT(10), |
| 205 | NVM_CHANNEL_160MHZ = BIT(11), |
| 206 | NVM_CHANNEL_DC_HIGH = BIT(12), |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 207 | }; |
| 208 | |
| 209 | #define CHECK_AND_PRINT_I(x) \ |
| 210 | ((ch_flags & NVM_CHANNEL_##x) ? # x " " : "") |
| 211 | |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 212 | static u32 iwl_get_channel_flags(u8 ch_num, int ch_idx, bool is_5ghz, |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 213 | u16 nvm_flags, const struct iwl_cfg *cfg) |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 214 | { |
| 215 | u32 flags = IEEE80211_CHAN_NO_HT40; |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 216 | u32 last_5ghz_ht = LAST_5GHZ_HT; |
| 217 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 218 | if (cfg->ext_nvm) |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 219 | last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000; |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 220 | |
| 221 | if (!is_5ghz && (nvm_flags & NVM_CHANNEL_40MHZ)) { |
| 222 | if (ch_num <= LAST_2GHZ_HT_PLUS) |
| 223 | flags &= ~IEEE80211_CHAN_NO_HT40PLUS; |
| 224 | if (ch_num >= FIRST_2GHZ_HT_MINUS) |
| 225 | flags &= ~IEEE80211_CHAN_NO_HT40MINUS; |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 226 | } else if (ch_num <= last_5ghz_ht && (nvm_flags & NVM_CHANNEL_40MHZ)) { |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 227 | if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0) |
| 228 | flags &= ~IEEE80211_CHAN_NO_HT40PLUS; |
| 229 | else |
| 230 | flags &= ~IEEE80211_CHAN_NO_HT40MINUS; |
| 231 | } |
| 232 | if (!(nvm_flags & NVM_CHANNEL_80MHZ)) |
| 233 | flags |= IEEE80211_CHAN_NO_80MHZ; |
| 234 | if (!(nvm_flags & NVM_CHANNEL_160MHZ)) |
| 235 | flags |= IEEE80211_CHAN_NO_160MHZ; |
| 236 | |
| 237 | if (!(nvm_flags & NVM_CHANNEL_IBSS)) |
| 238 | flags |= IEEE80211_CHAN_NO_IR; |
| 239 | |
| 240 | if (!(nvm_flags & NVM_CHANNEL_ACTIVE)) |
| 241 | flags |= IEEE80211_CHAN_NO_IR; |
| 242 | |
| 243 | if (nvm_flags & NVM_CHANNEL_RADAR) |
| 244 | flags |= IEEE80211_CHAN_RADAR; |
| 245 | |
| 246 | if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY) |
| 247 | flags |= IEEE80211_CHAN_INDOOR_ONLY; |
| 248 | |
| 249 | /* Set the GO concurrent flag only in case that NO_IR is set. |
| 250 | * Otherwise it is meaningless |
| 251 | */ |
| 252 | if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) && |
| 253 | (flags & IEEE80211_CHAN_NO_IR)) |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 254 | flags |= IEEE80211_CHAN_IR_CONCURRENT; |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 255 | |
| 256 | return flags; |
| 257 | } |
| 258 | |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 259 | static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg, |
| 260 | struct iwl_nvm_data *data, |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 261 | const __le16 * const nvm_ch_flags, |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 262 | bool lar_supported, bool no_wide_in_5ghz) |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 263 | { |
| 264 | int ch_idx; |
| 265 | int n_channels = 0; |
| 266 | struct ieee80211_channel *channel; |
| 267 | u16 ch_flags; |
Eran Harary | 749f1fe | 2014-03-06 09:25:30 +0200 | [diff] [blame] | 268 | int num_of_ch, num_2ghz_channels; |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 269 | const u8 *nvm_chan; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 270 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 271 | if (!cfg->ext_nvm) { |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 272 | num_of_ch = IWL_NUM_CHANNELS; |
| 273 | nvm_chan = &iwl_nvm_channels[0]; |
Eran Harary | 749f1fe | 2014-03-06 09:25:30 +0200 | [diff] [blame] | 274 | num_2ghz_channels = NUM_2GHZ_CHANNELS; |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 275 | } else { |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 276 | num_of_ch = IWL_NUM_CHANNELS_EXT; |
| 277 | nvm_chan = &iwl_ext_nvm_channels[0]; |
| 278 | num_2ghz_channels = NUM_2GHZ_CHANNELS_EXT; |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) { |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 282 | bool is_5ghz = (ch_idx >= num_2ghz_channels); |
| 283 | |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 284 | ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx); |
Emmanuel Grumbach | c512865 | 2013-12-05 22:42:55 +0200 | [diff] [blame] | 285 | |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 286 | if (is_5ghz && !data->sku_cap_band_52GHz_enable) |
Eliad Peller | a76f3bf | 2014-05-26 18:11:37 +0300 | [diff] [blame] | 287 | continue; |
Emmanuel Grumbach | c512865 | 2013-12-05 22:42:55 +0200 | [diff] [blame] | 288 | |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 289 | /* workaround to disable wide channels in 5GHz */ |
| 290 | if (no_wide_in_5ghz && is_5ghz) { |
| 291 | ch_flags &= ~(NVM_CHANNEL_40MHZ | |
| 292 | NVM_CHANNEL_80MHZ | |
| 293 | NVM_CHANNEL_160MHZ); |
| 294 | } |
| 295 | |
Gregory Greenman | 4896d76 | 2016-04-03 14:06:12 +0300 | [diff] [blame] | 296 | if (ch_flags & NVM_CHANNEL_160MHZ) |
| 297 | data->vht160_supported = true; |
| 298 | |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 299 | if (!lar_supported && !(ch_flags & NVM_CHANNEL_VALID)) { |
Eliad Peller | a76f3bf | 2014-05-26 18:11:37 +0300 | [diff] [blame] | 300 | /* |
| 301 | * Channels might become valid later if lar is |
| 302 | * supported, hence we still want to add them to |
| 303 | * the list of supported channels to cfg80211. |
| 304 | */ |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 305 | IWL_DEBUG_EEPROM(dev, |
| 306 | "Ch. %d Flags %x [%sGHz] - No traffic\n", |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 307 | nvm_chan[ch_idx], |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 308 | ch_flags, |
Eran Harary | 749f1fe | 2014-03-06 09:25:30 +0200 | [diff] [blame] | 309 | (ch_idx >= num_2ghz_channels) ? |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 310 | "5.2" : "2.4"); |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | channel = &data->channels[n_channels]; |
| 315 | n_channels++; |
| 316 | |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 317 | channel->hw_value = nvm_chan[ch_idx]; |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 318 | channel->band = is_5ghz ? |
| 319 | NL80211_BAND_5GHZ : NL80211_BAND_2GHZ; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 320 | channel->center_freq = |
| 321 | ieee80211_channel_to_frequency( |
| 322 | channel->hw_value, channel->band); |
| 323 | |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 324 | /* Initialize regulatory-based run-time data */ |
| 325 | |
Matti Gottlieb | 88f2fd7 | 2013-07-09 15:25:46 +0300 | [diff] [blame] | 326 | /* |
| 327 | * Default value - highest tx power value. max_power |
| 328 | * is not used in mvm, and is used for backwards compatibility |
| 329 | */ |
Eliad Peller | 22d059a | 2014-08-26 11:23:11 +0300 | [diff] [blame] | 330 | channel->max_power = IWL_DEFAULT_MAX_TX_POWER; |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 331 | |
| 332 | /* don't put limitations in case we're using LAR */ |
| 333 | if (!lar_supported) |
| 334 | channel->flags = iwl_get_channel_flags(nvm_chan[ch_idx], |
| 335 | ch_idx, is_5ghz, |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 336 | ch_flags, cfg); |
Arik Nemtsov | 770ceda | 2014-03-23 16:18:40 +0200 | [diff] [blame] | 337 | else |
| 338 | channel->flags = 0; |
| 339 | |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 340 | IWL_DEBUG_EEPROM(dev, |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 341 | "Ch. %d [%sGHz] flags 0x%x %s%s%s%s%s%s%s%s%s%s%s%s(%ddBm): Ad-Hoc %ssupported\n", |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 342 | channel->hw_value, |
| 343 | is_5ghz ? "5.2" : "2.4", |
Gregory Greenman | 4896d76 | 2016-04-03 14:06:12 +0300 | [diff] [blame] | 344 | ch_flags, |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 345 | CHECK_AND_PRINT_I(VALID), |
| 346 | CHECK_AND_PRINT_I(IBSS), |
| 347 | CHECK_AND_PRINT_I(ACTIVE), |
| 348 | CHECK_AND_PRINT_I(RADAR), |
David Spinadel | 9ee6dac | 2013-05-29 11:37:28 +0300 | [diff] [blame] | 349 | CHECK_AND_PRINT_I(INDOOR_ONLY), |
| 350 | CHECK_AND_PRINT_I(GO_CONCURRENT), |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 351 | CHECK_AND_PRINT_I(UNIFORM), |
| 352 | CHECK_AND_PRINT_I(20MHZ), |
Gregory Greenman | 4896d76 | 2016-04-03 14:06:12 +0300 | [diff] [blame] | 353 | CHECK_AND_PRINT_I(40MHZ), |
| 354 | CHECK_AND_PRINT_I(80MHZ), |
| 355 | CHECK_AND_PRINT_I(160MHZ), |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 356 | CHECK_AND_PRINT_I(DC_HIGH), |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 357 | channel->max_power, |
| 358 | ((ch_flags & NVM_CHANNEL_IBSS) && |
| 359 | !(ch_flags & NVM_CHANNEL_RADAR)) |
| 360 | ? "" : "not "); |
| 361 | } |
| 362 | |
| 363 | return n_channels; |
| 364 | } |
| 365 | |
Eytan Lifshitz | 33158fe | 2013-02-20 11:01:13 +0200 | [diff] [blame] | 366 | static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg, |
| 367 | struct iwl_nvm_data *data, |
Johannes Berg | 6ca89f1 | 2014-02-12 21:56:26 +0100 | [diff] [blame] | 368 | struct ieee80211_sta_vht_cap *vht_cap, |
| 369 | u8 tx_chains, u8 rx_chains) |
Eytan Lifshitz | 33158fe | 2013-02-20 11:01:13 +0200 | [diff] [blame] | 370 | { |
Johannes Berg | 6ca89f1 | 2014-02-12 21:56:26 +0100 | [diff] [blame] | 371 | int num_rx_ants = num_of_ant(rx_chains); |
| 372 | int num_tx_ants = num_of_ant(tx_chains); |
Eran Harary | c064ddf | 2014-09-30 06:42:06 +0200 | [diff] [blame] | 373 | unsigned int max_ampdu_exponent = (cfg->max_vht_ampdu_exponent ?: |
| 374 | IEEE80211_VHT_MAX_AMPDU_1024K); |
Eyal Shapira | 48e6de6 | 2013-11-03 10:04:08 +0200 | [diff] [blame] | 375 | |
Eytan Lifshitz | 33158fe | 2013-02-20 11:01:13 +0200 | [diff] [blame] | 376 | vht_cap->vht_supported = true; |
| 377 | |
| 378 | vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 | |
| 379 | IEEE80211_VHT_CAP_RXSTBC_1 | |
| 380 | IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
Eyal Shapira | e36b766 | 2014-01-06 20:16:48 +0200 | [diff] [blame] | 381 | 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT | |
Eran Harary | c064ddf | 2014-09-30 06:42:06 +0200 | [diff] [blame] | 382 | max_ampdu_exponent << |
| 383 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
Eytan Lifshitz | 33158fe | 2013-02-20 11:01:13 +0200 | [diff] [blame] | 384 | |
Gregory Greenman | 4896d76 | 2016-04-03 14:06:12 +0300 | [diff] [blame] | 385 | if (data->vht160_supported) |
Gregory Greenman | fbbd485 | 2016-04-12 15:16:24 +0300 | [diff] [blame] | 386 | vht_cap->cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | |
| 387 | IEEE80211_VHT_CAP_SHORT_GI_160; |
Gregory Greenman | 4896d76 | 2016-04-03 14:06:12 +0300 | [diff] [blame] | 388 | |
Sara Sharon | e48c947 | 2016-01-27 18:59:48 +0200 | [diff] [blame] | 389 | if (cfg->vht_mu_mimo_supported) |
| 390 | vht_cap->cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 391 | |
Eyal Shapira | a3576ff | 2014-08-09 10:57:59 +0300 | [diff] [blame] | 392 | if (cfg->ht_params->ldpc) |
| 393 | vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC; |
| 394 | |
Emmanuel Grumbach | 5f0d98f | 2014-10-30 10:19:38 +0200 | [diff] [blame] | 395 | if (data->sku_cap_mimo_disabled) { |
| 396 | num_rx_ants = 1; |
| 397 | num_tx_ants = 1; |
| 398 | } |
| 399 | |
Johannes Berg | 6ca89f1 | 2014-02-12 21:56:26 +0100 | [diff] [blame] | 400 | if (num_tx_ants > 1) |
Eyal Shapira | 5f7a6f9 | 2013-11-12 22:40:40 +0200 | [diff] [blame] | 401 | vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC; |
Johannes Berg | 6ca89f1 | 2014-02-12 21:56:26 +0100 | [diff] [blame] | 402 | else |
| 403 | vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN; |
Eyal Shapira | 5f7a6f9 | 2013-11-12 22:40:40 +0200 | [diff] [blame] | 404 | |
Emmanuel Grumbach | 6c4fbcb | 2015-11-10 11:57:41 +0200 | [diff] [blame] | 405 | switch (iwlwifi_mod_params.amsdu_size) { |
Emmanuel Grumbach | 4bdd4df | 2016-04-07 16:44:42 +0300 | [diff] [blame] | 406 | case IWL_AMSDU_DEF: |
| 407 | if (cfg->mq_rx_supported) |
| 408 | vht_cap->cap |= |
| 409 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454; |
| 410 | else |
| 411 | vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895; |
| 412 | break; |
Emmanuel Grumbach | 6c4fbcb | 2015-11-10 11:57:41 +0200 | [diff] [blame] | 413 | case IWL_AMSDU_4K: |
| 414 | vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895; |
| 415 | break; |
| 416 | case IWL_AMSDU_8K: |
Eytan Lifshitz | 33158fe | 2013-02-20 11:01:13 +0200 | [diff] [blame] | 417 | vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991; |
Emmanuel Grumbach | 6c4fbcb | 2015-11-10 11:57:41 +0200 | [diff] [blame] | 418 | break; |
| 419 | case IWL_AMSDU_12K: |
| 420 | vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454; |
| 421 | break; |
| 422 | default: |
| 423 | break; |
| 424 | } |
Eytan Lifshitz | 33158fe | 2013-02-20 11:01:13 +0200 | [diff] [blame] | 425 | |
| 426 | vht_cap->vht_mcs.rx_mcs_map = |
| 427 | cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | |
| 428 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 | |
| 429 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | |
| 430 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | |
| 431 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | |
| 432 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | |
| 433 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | |
| 434 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 14); |
| 435 | |
Johannes Berg | 6ca89f1 | 2014-02-12 21:56:26 +0100 | [diff] [blame] | 436 | if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) { |
| 437 | vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN; |
Eytan Lifshitz | 33158fe | 2013-02-20 11:01:13 +0200 | [diff] [blame] | 438 | /* this works because NOT_SUPPORTED == 3 */ |
| 439 | vht_cap->vht_mcs.rx_mcs_map |= |
| 440 | cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2); |
| 441 | } |
| 442 | |
| 443 | vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map; |
| 444 | } |
| 445 | |
Sara Sharon | 2910849 | 2017-01-08 16:45:46 +0200 | [diff] [blame] | 446 | void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg, |
| 447 | struct iwl_nvm_data *data, const __le16 *nvm_ch_flags, |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 448 | u8 tx_chains, u8 rx_chains, bool lar_supported, |
| 449 | bool no_wide_in_5ghz) |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 450 | { |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 451 | int n_channels; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 452 | int n_used = 0; |
| 453 | struct ieee80211_supported_band *sband; |
| 454 | |
Sara Sharon | 2910849 | 2017-01-08 16:45:46 +0200 | [diff] [blame] | 455 | n_channels = iwl_init_channel_map(dev, cfg, data, nvm_ch_flags, |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 456 | lar_supported, no_wide_in_5ghz); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 457 | sband = &data->bands[NL80211_BAND_2GHZ]; |
| 458 | sband->band = NL80211_BAND_2GHZ; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 459 | sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS]; |
| 460 | sband->n_bitrates = N_RATES_24; |
| 461 | n_used += iwl_init_sband_channels(data, sband, n_channels, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 462 | NL80211_BAND_2GHZ); |
| 463 | iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_2GHZ, |
Emmanuel Grumbach | 9ce4fa7 | 2013-05-22 13:16:23 +0300 | [diff] [blame] | 464 | tx_chains, rx_chains); |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 465 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 466 | sband = &data->bands[NL80211_BAND_5GHZ]; |
| 467 | sband->band = NL80211_BAND_5GHZ; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 468 | sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS]; |
| 469 | sband->n_bitrates = N_RATES_52; |
| 470 | n_used += iwl_init_sband_channels(data, sband, n_channels, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 471 | NL80211_BAND_5GHZ); |
| 472 | iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_5GHZ, |
Emmanuel Grumbach | 9ce4fa7 | 2013-05-22 13:16:23 +0300 | [diff] [blame] | 473 | tx_chains, rx_chains); |
Andrei Otcheretianski | 0d0985a | 2016-02-29 13:25:48 +0200 | [diff] [blame] | 474 | if (data->sku_cap_11ac_enable && !iwlwifi_mod_params.disable_11ac) |
Johannes Berg | 6ca89f1 | 2014-02-12 21:56:26 +0100 | [diff] [blame] | 475 | iwl_init_vht_hw_capab(cfg, data, &sband->vht_cap, |
| 476 | tx_chains, rx_chains); |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 477 | |
| 478 | if (n_channels != n_used) |
| 479 | IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n", |
| 480 | n_used, n_channels); |
| 481 | } |
Sara Sharon | 2910849 | 2017-01-08 16:45:46 +0200 | [diff] [blame] | 482 | IWL_EXPORT_SYMBOL(iwl_init_sbands); |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 483 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 484 | static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw, |
| 485 | const __le16 *phy_sku) |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 486 | { |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 487 | if (!cfg->ext_nvm) |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 488 | return le16_to_cpup(nvm_sw + SKU); |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 489 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 490 | return le32_to_cpup((__le32 *)(phy_sku + SKU_FAMILY_8000)); |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 491 | } |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 492 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 493 | static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw) |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 494 | { |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 495 | if (!cfg->ext_nvm) |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 496 | return le16_to_cpup(nvm_sw + NVM_VERSION); |
| 497 | else |
| 498 | return le32_to_cpup((__le32 *)(nvm_sw + |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 499 | NVM_VERSION_EXT_NVM)); |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 500 | } |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 501 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 502 | static int iwl_get_radio_cfg(const struct iwl_cfg *cfg, const __le16 *nvm_sw, |
| 503 | const __le16 *phy_sku) |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 504 | { |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 505 | if (!cfg->ext_nvm) |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 506 | return le16_to_cpup(nvm_sw + RADIO_CFG); |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 507 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 508 | return le32_to_cpup((__le32 *)(phy_sku + RADIO_CFG_FAMILY_EXT_NVM)); |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 509 | |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 510 | } |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 511 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 512 | static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg, const __le16 *nvm_sw) |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 513 | { |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 514 | int n_hw_addr; |
| 515 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 516 | if (!cfg->ext_nvm) |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 517 | return le16_to_cpup(nvm_sw + N_HW_ADDRS); |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 518 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 519 | n_hw_addr = le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000)); |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 520 | |
| 521 | return n_hw_addr & N_HW_ADDR_MASK; |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 522 | } |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 523 | |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 524 | static void iwl_set_radio_cfg(const struct iwl_cfg *cfg, |
| 525 | struct iwl_nvm_data *data, |
| 526 | u32 radio_cfg) |
| 527 | { |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 528 | if (!cfg->ext_nvm) { |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 529 | data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg); |
| 530 | data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg); |
| 531 | data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg); |
| 532 | data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg); |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 533 | return; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 534 | } |
| 535 | |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 536 | /* set the radio configuration for family 8000 */ |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 537 | data->radio_cfg_type = EXT_NVM_RF_CFG_TYPE_MSK(radio_cfg); |
| 538 | data->radio_cfg_step = EXT_NVM_RF_CFG_STEP_MSK(radio_cfg); |
| 539 | data->radio_cfg_dash = EXT_NVM_RF_CFG_DASH_MSK(radio_cfg); |
| 540 | data->radio_cfg_pnum = EXT_NVM_RF_CFG_FLAVOR_MSK(radio_cfg); |
| 541 | data->valid_tx_ant = EXT_NVM_RF_CFG_TX_ANT_MSK(radio_cfg); |
| 542 | data->valid_rx_ant = EXT_NVM_RF_CFG_RX_ANT_MSK(radio_cfg); |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 543 | } |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 544 | |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 545 | static void iwl_flip_hw_address(__le32 mac_addr0, __le32 mac_addr1, u8 *dest) |
| 546 | { |
| 547 | const u8 *hw_addr; |
| 548 | |
| 549 | hw_addr = (const u8 *)&mac_addr0; |
| 550 | dest[0] = hw_addr[3]; |
| 551 | dest[1] = hw_addr[2]; |
| 552 | dest[2] = hw_addr[1]; |
| 553 | dest[3] = hw_addr[0]; |
| 554 | |
| 555 | hw_addr = (const u8 *)&mac_addr1; |
| 556 | dest[4] = hw_addr[1]; |
| 557 | dest[5] = hw_addr[0]; |
| 558 | } |
| 559 | |
Sara Sharon | 2910849 | 2017-01-08 16:45:46 +0200 | [diff] [blame] | 560 | void iwl_set_hw_address_from_csr(struct iwl_trans *trans, |
| 561 | struct iwl_nvm_data *data) |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 562 | { |
| 563 | __le32 mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_STRAP)); |
| 564 | __le32 mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_STRAP)); |
| 565 | |
Haim Dreyfuss | a6c934b | 2016-08-02 15:28:23 +0300 | [diff] [blame] | 566 | iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr); |
| 567 | /* |
| 568 | * If the OEM fused a valid address, use it instead of the one in the |
| 569 | * OTP |
| 570 | */ |
| 571 | if (is_valid_ether_addr(data->hw_addr)) |
| 572 | return; |
| 573 | |
| 574 | mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_OTP)); |
| 575 | mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_OTP)); |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 576 | |
| 577 | iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr); |
| 578 | } |
Sara Sharon | 2910849 | 2017-01-08 16:45:46 +0200 | [diff] [blame] | 579 | IWL_EXPORT_SYMBOL(iwl_set_hw_address_from_csr); |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 580 | |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 581 | static void iwl_set_hw_address_family_8000(struct iwl_trans *trans, |
Eran Harary | 6a68a39 | 2014-05-07 11:09:11 +0300 | [diff] [blame] | 582 | const struct iwl_cfg *cfg, |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 583 | struct iwl_nvm_data *data, |
| 584 | const __le16 *mac_override, |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 585 | const __le16 *nvm_hw) |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 586 | { |
| 587 | const u8 *hw_addr; |
| 588 | |
| 589 | if (mac_override) { |
Liad Kaufman | 18f8467 | 2015-05-20 15:50:07 +0300 | [diff] [blame] | 590 | static const u8 reserved_mac[] = { |
| 591 | 0x02, 0xcc, 0xaa, 0xff, 0xee, 0x00 |
| 592 | }; |
| 593 | |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 594 | hw_addr = (const u8 *)(mac_override + |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 595 | MAC_ADDRESS_OVERRIDE_EXT_NVM); |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 596 | |
Liad Kaufman | be88a1a | 2015-07-01 17:28:34 +0300 | [diff] [blame] | 597 | /* |
| 598 | * Store the MAC address from MAO section. |
| 599 | * No byte swapping is required in MAO section |
| 600 | */ |
| 601 | memcpy(data->hw_addr, hw_addr, ETH_ALEN); |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 602 | |
Liad Kaufman | 18f8467 | 2015-05-20 15:50:07 +0300 | [diff] [blame] | 603 | /* |
| 604 | * Force the use of the OTP MAC address in case of reserved MAC |
| 605 | * address in the NVM, or if address is given but invalid. |
| 606 | */ |
| 607 | if (is_valid_ether_addr(data->hw_addr) && |
| 608 | memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0) |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 609 | return; |
Eran Harary | 6a68a39 | 2014-05-07 11:09:11 +0300 | [diff] [blame] | 610 | |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 611 | IWL_ERR(trans, |
| 612 | "mac address from nvm override section is not valid\n"); |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 613 | } |
| 614 | |
Eran Harary | 6a68a39 | 2014-05-07 11:09:11 +0300 | [diff] [blame] | 615 | if (nvm_hw) { |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 616 | /* read the mac address from WFMP registers */ |
| 617 | __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans, |
| 618 | WFMP_MAC_ADDR_0)); |
| 619 | __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans, |
| 620 | WFMP_MAC_ADDR_1)); |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 621 | |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 622 | iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr); |
Eran Harary | 1e0b393 | 2014-06-11 11:37:09 +0300 | [diff] [blame] | 623 | |
Eran Harary | 6a68a39 | 2014-05-07 11:09:11 +0300 | [diff] [blame] | 624 | return; |
| 625 | } |
| 626 | |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 627 | IWL_ERR(trans, "mac address is not found\n"); |
| 628 | } |
| 629 | |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 630 | static int iwl_set_hw_address(struct iwl_trans *trans, |
| 631 | const struct iwl_cfg *cfg, |
| 632 | struct iwl_nvm_data *data, const __le16 *nvm_hw, |
| 633 | const __le16 *mac_override) |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 634 | { |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 635 | if (cfg->mac_addr_from_csr) { |
| 636 | iwl_set_hw_address_from_csr(trans, data); |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 637 | } else if (!cfg->ext_nvm) { |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 638 | const u8 *hw_addr = (const u8 *)(nvm_hw + HW_ADDR); |
| 639 | |
| 640 | /* The byte order is little endian 16 bit, meaning 214365 */ |
| 641 | data->hw_addr[0] = hw_addr[1]; |
| 642 | data->hw_addr[1] = hw_addr[0]; |
| 643 | data->hw_addr[2] = hw_addr[3]; |
| 644 | data->hw_addr[3] = hw_addr[2]; |
| 645 | data->hw_addr[4] = hw_addr[5]; |
| 646 | data->hw_addr[5] = hw_addr[4]; |
| 647 | } else { |
| 648 | iwl_set_hw_address_family_8000(trans, cfg, data, |
| 649 | mac_override, nvm_hw); |
| 650 | } |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 651 | |
| 652 | if (!is_valid_ether_addr(data->hw_addr)) { |
| 653 | IWL_ERR(trans, "no valid mac address was found\n"); |
| 654 | return -EINVAL; |
| 655 | } |
| 656 | |
Luca Coelho | 4409e72 | 2017-05-09 22:46:19 +0300 | [diff] [blame] | 657 | IWL_INFO(trans, "base HW address: %pM\n", data->hw_addr); |
| 658 | |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 659 | return 0; |
Eran Harary | 9f32e01 | 2014-04-28 15:22:40 +0300 | [diff] [blame] | 660 | } |
| 661 | |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 662 | static bool |
| 663 | iwl_nvm_no_wide_in_5ghz(struct device *dev, const struct iwl_cfg *cfg, |
| 664 | const __le16 *nvm_hw) |
| 665 | { |
| 666 | /* |
| 667 | * Workaround a bug in Indonesia SKUs where the regulatory in |
| 668 | * some 7000-family OTPs erroneously allow wide channels in |
| 669 | * 5GHz. To check for Indonesia, we take the SKU value from |
| 670 | * bits 1-4 in the subsystem ID and check if it is either 5 or |
| 671 | * 9. In those cases, we need to force-disable wide channels |
| 672 | * in 5GHz otherwise the FW will throw a sysassert when we try |
| 673 | * to use them. |
| 674 | */ |
| 675 | if (cfg->device_family == IWL_DEVICE_FAMILY_7000) { |
| 676 | /* |
| 677 | * Unlike the other sections in the NVM, the hw |
| 678 | * section uses big-endian. |
| 679 | */ |
| 680 | u16 subsystem_id = be16_to_cpup((const __be16 *)nvm_hw |
| 681 | + SUBSYSTEM_ID); |
| 682 | u8 sku = (subsystem_id & 0x1e) >> 1; |
| 683 | |
| 684 | if (sku == 5 || sku == 9) { |
| 685 | IWL_DEBUG_EEPROM(dev, |
| 686 | "disabling wide channels in 5GHz (0x%0x %d)\n", |
| 687 | subsystem_id, sku); |
| 688 | return true; |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | return false; |
| 693 | } |
| 694 | |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 695 | struct iwl_nvm_data * |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 696 | iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg, |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 697 | const __le16 *nvm_hw, const __le16 *nvm_sw, |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 698 | const __le16 *nvm_calib, const __le16 *regulatory, |
Eran Harary | ce50007 | 2014-12-01 17:53:53 +0200 | [diff] [blame] | 699 | const __le16 *mac_override, const __le16 *phy_sku, |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 700 | u8 tx_chains, u8 rx_chains, bool lar_fw_supported) |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 701 | { |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 702 | struct device *dev = trans->dev; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 703 | struct iwl_nvm_data *data; |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 704 | bool lar_enabled; |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 705 | bool no_wide_in_5ghz = iwl_nvm_no_wide_in_5ghz(dev, cfg, nvm_hw); |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 706 | u32 sku, radio_cfg; |
Matti Gottlieb | d0d1519 | 2014-07-31 09:16:25 +0300 | [diff] [blame] | 707 | u16 lar_config; |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 708 | const __le16 *ch_section; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 709 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 710 | if (!cfg->ext_nvm) |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 711 | data = kzalloc(sizeof(*data) + |
| 712 | sizeof(struct ieee80211_channel) * |
| 713 | IWL_NUM_CHANNELS, |
| 714 | GFP_KERNEL); |
| 715 | else |
| 716 | data = kzalloc(sizeof(*data) + |
| 717 | sizeof(struct ieee80211_channel) * |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 718 | IWL_NUM_CHANNELS_EXT, |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 719 | GFP_KERNEL); |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 720 | if (!data) |
| 721 | return NULL; |
| 722 | |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 723 | data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw); |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 724 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 725 | radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw, phy_sku); |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 726 | iwl_set_radio_cfg(cfg, data, radio_cfg); |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 727 | if (data->valid_tx_ant) |
| 728 | tx_chains &= data->valid_tx_ant; |
| 729 | if (data->valid_rx_ant) |
| 730 | rx_chains &= data->valid_rx_ant; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 731 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 732 | sku = iwl_get_sku(cfg, nvm_sw, phy_sku); |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 733 | data->sku_cap_band_24GHz_enable = sku & NVM_SKU_CAP_BAND_24GHZ; |
| 734 | data->sku_cap_band_52GHz_enable = sku & NVM_SKU_CAP_BAND_52GHZ; |
| 735 | data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE; |
| 736 | if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL) |
| 737 | data->sku_cap_11n_enable = false; |
Eliad Peller | 2926f95 | 2014-10-23 16:29:10 +0300 | [diff] [blame] | 738 | data->sku_cap_11ac_enable = data->sku_cap_11n_enable && |
| 739 | (sku & NVM_SKU_CAP_11AC_ENABLE); |
Emmanuel Grumbach | 5f0d98f | 2014-10-30 10:19:38 +0200 | [diff] [blame] | 740 | data->sku_cap_mimo_disabled = sku & NVM_SKU_CAP_MIMO_DISABLE; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 741 | |
Emmanuel Grumbach | 5dd9c68 | 2015-03-05 13:06:13 +0200 | [diff] [blame] | 742 | data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw); |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 743 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 744 | if (!cfg->ext_nvm) { |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 745 | /* Checking for required sections */ |
| 746 | if (!nvm_calib) { |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 747 | IWL_ERR(trans, |
| 748 | "Can't parse empty Calib NVM sections\n"); |
Eytan Lifshitz | 1270c41 | 2014-02-18 15:02:29 +0200 | [diff] [blame] | 749 | kfree(data); |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 750 | return NULL; |
| 751 | } |
| 752 | /* in family 8000 Xtal calibration values moved to OTP */ |
| 753 | data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB); |
| 754 | data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1); |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 755 | lar_enabled = true; |
Sara Sharon | 2910849 | 2017-01-08 16:45:46 +0200 | [diff] [blame] | 756 | ch_section = &nvm_sw[NVM_CHANNELS]; |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 757 | } else { |
Arik Nemtsov | f552863 | 2015-02-04 15:38:56 +0200 | [diff] [blame] | 758 | u16 lar_offset = data->nvm_version < 0xE39 ? |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 759 | NVM_LAR_OFFSET_OLD : |
| 760 | NVM_LAR_OFFSET; |
Arik Nemtsov | f552863 | 2015-02-04 15:38:56 +0200 | [diff] [blame] | 761 | |
| 762 | lar_config = le16_to_cpup(regulatory + lar_offset); |
Matti Gottlieb | d0d1519 | 2014-07-31 09:16:25 +0300 | [diff] [blame] | 763 | data->lar_enabled = !!(lar_config & |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 764 | NVM_LAR_ENABLED); |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 765 | lar_enabled = data->lar_enabled; |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 766 | ch_section = ®ulatory[NVM_CHANNELS_EXTENDED]; |
Eran Harary | 77db0a3 | 2014-02-04 14:21:38 +0200 | [diff] [blame] | 767 | } |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 768 | |
Sara Sharon | 17c867b | 2016-03-07 14:18:29 +0200 | [diff] [blame] | 769 | /* If no valid mac address was found - bail out */ |
| 770 | if (iwl_set_hw_address(trans, cfg, data, nvm_hw, mac_override)) { |
| 771 | kfree(data); |
| 772 | return NULL; |
| 773 | } |
| 774 | |
Sara Sharon | afd5b17 | 2016-03-01 12:18:22 +0200 | [diff] [blame] | 775 | iwl_init_sbands(dev, cfg, data, ch_section, tx_chains, rx_chains, |
Luca Coelho | 01a9c94 | 2017-08-15 20:48:41 +0300 | [diff] [blame^] | 776 | lar_fw_supported && lar_enabled, no_wide_in_5ghz); |
Emmanuel Grumbach | 33b2f68 | 2014-01-14 13:48:22 +0200 | [diff] [blame] | 777 | data->calib_version = 255; |
Johannes Berg | b1e1adf | 2013-01-24 14:14:22 +0100 | [diff] [blame] | 778 | |
| 779 | return data; |
| 780 | } |
Johannes Berg | 48e2934 | 2013-03-01 00:13:33 +0100 | [diff] [blame] | 781 | IWL_EXPORT_SYMBOL(iwl_parse_nvm_data); |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 782 | |
| 783 | static u32 iwl_nvm_get_regdom_bw_flags(const u8 *nvm_chan, |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 784 | int ch_idx, u16 nvm_flags, |
| 785 | const struct iwl_cfg *cfg) |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 786 | { |
| 787 | u32 flags = NL80211_RRF_NO_HT40; |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 788 | u32 last_5ghz_ht = LAST_5GHZ_HT; |
| 789 | |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 790 | if (cfg->ext_nvm) |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 791 | last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000; |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 792 | |
| 793 | if (ch_idx < NUM_2GHZ_CHANNELS && |
| 794 | (nvm_flags & NVM_CHANNEL_40MHZ)) { |
| 795 | if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS) |
| 796 | flags &= ~NL80211_RRF_NO_HT40PLUS; |
| 797 | if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS) |
| 798 | flags &= ~NL80211_RRF_NO_HT40MINUS; |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 799 | } else if (nvm_chan[ch_idx] <= last_5ghz_ht && |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 800 | (nvm_flags & NVM_CHANNEL_40MHZ)) { |
| 801 | if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0) |
| 802 | flags &= ~NL80211_RRF_NO_HT40PLUS; |
| 803 | else |
| 804 | flags &= ~NL80211_RRF_NO_HT40MINUS; |
| 805 | } |
| 806 | |
| 807 | if (!(nvm_flags & NVM_CHANNEL_80MHZ)) |
| 808 | flags |= NL80211_RRF_NO_80MHZ; |
| 809 | if (!(nvm_flags & NVM_CHANNEL_160MHZ)) |
| 810 | flags |= NL80211_RRF_NO_160MHZ; |
| 811 | |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 812 | if (!(nvm_flags & NVM_CHANNEL_ACTIVE)) |
| 813 | flags |= NL80211_RRF_NO_IR; |
| 814 | |
| 815 | if (nvm_flags & NVM_CHANNEL_RADAR) |
| 816 | flags |= NL80211_RRF_DFS; |
| 817 | |
| 818 | if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY) |
| 819 | flags |= NL80211_RRF_NO_OUTDOOR; |
| 820 | |
| 821 | /* Set the GO concurrent flag only in case that NO_IR is set. |
| 822 | * Otherwise it is meaningless |
| 823 | */ |
| 824 | if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) && |
| 825 | (flags & NL80211_RRF_NO_IR)) |
| 826 | flags |= NL80211_RRF_GO_CONCURRENT; |
| 827 | |
| 828 | return flags; |
| 829 | } |
| 830 | |
| 831 | struct ieee80211_regdomain * |
Arik Nemtsov | 162ee3c | 2014-06-10 11:25:35 +0300 | [diff] [blame] | 832 | iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg, |
| 833 | int num_of_ch, __le32 *channels, u16 fw_mcc) |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 834 | { |
| 835 | int ch_idx; |
| 836 | u16 ch_flags, prev_ch_flags = 0; |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 837 | const u8 *nvm_chan = cfg->ext_nvm ? |
| 838 | iwl_ext_nvm_channels : iwl_nvm_channels; |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 839 | struct ieee80211_regdomain *regd; |
| 840 | int size_of_regd; |
| 841 | struct ieee80211_reg_rule *rule; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 842 | enum nl80211_band band; |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 843 | int center_freq, prev_center_freq = 0; |
| 844 | int valid_rules = 0; |
| 845 | bool new_rule; |
Sara Sharon | 7042678 | 2017-03-22 12:20:40 +0200 | [diff] [blame] | 846 | int max_num_ch = cfg->ext_nvm ? |
| 847 | IWL_NUM_CHANNELS_EXT : IWL_NUM_CHANNELS; |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 848 | |
| 849 | if (WARN_ON_ONCE(num_of_ch > NL80211_MAX_SUPP_REG_RULES)) |
| 850 | return ERR_PTR(-EINVAL); |
| 851 | |
Arik Nemtsov | 4557eab | 2015-03-01 18:24:57 +0200 | [diff] [blame] | 852 | if (WARN_ON(num_of_ch > max_num_ch)) |
| 853 | num_of_ch = max_num_ch; |
| 854 | |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 855 | IWL_DEBUG_DEV(dev, IWL_DL_LAR, "building regdom for %d channels\n", |
| 856 | num_of_ch); |
| 857 | |
| 858 | /* build a regdomain rule for every valid channel */ |
| 859 | size_of_regd = |
| 860 | sizeof(struct ieee80211_regdomain) + |
| 861 | num_of_ch * sizeof(struct ieee80211_reg_rule); |
| 862 | |
| 863 | regd = kzalloc(size_of_regd, GFP_KERNEL); |
| 864 | if (!regd) |
| 865 | return ERR_PTR(-ENOMEM); |
| 866 | |
| 867 | for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) { |
| 868 | ch_flags = (u16)__le32_to_cpup(channels + ch_idx); |
| 869 | band = (ch_idx < NUM_2GHZ_CHANNELS) ? |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 870 | NL80211_BAND_2GHZ : NL80211_BAND_5GHZ; |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 871 | center_freq = ieee80211_channel_to_frequency(nvm_chan[ch_idx], |
| 872 | band); |
| 873 | new_rule = false; |
| 874 | |
| 875 | if (!(ch_flags & NVM_CHANNEL_VALID)) { |
| 876 | IWL_DEBUG_DEV(dev, IWL_DL_LAR, |
| 877 | "Ch. %d Flags %x [%sGHz] - No traffic\n", |
| 878 | nvm_chan[ch_idx], |
| 879 | ch_flags, |
| 880 | (ch_idx >= NUM_2GHZ_CHANNELS) ? |
| 881 | "5.2" : "2.4"); |
| 882 | continue; |
| 883 | } |
| 884 | |
| 885 | /* we can't continue the same rule */ |
| 886 | if (ch_idx == 0 || prev_ch_flags != ch_flags || |
| 887 | center_freq - prev_center_freq > 20) { |
| 888 | valid_rules++; |
| 889 | new_rule = true; |
| 890 | } |
| 891 | |
| 892 | rule = ®d->reg_rules[valid_rules - 1]; |
| 893 | |
| 894 | if (new_rule) |
| 895 | rule->freq_range.start_freq_khz = |
| 896 | MHZ_TO_KHZ(center_freq - 10); |
| 897 | |
| 898 | rule->freq_range.end_freq_khz = MHZ_TO_KHZ(center_freq + 10); |
| 899 | |
| 900 | /* this doesn't matter - not used by FW */ |
| 901 | rule->power_rule.max_antenna_gain = DBI_TO_MBI(6); |
Eliad Peller | 02a5049 | 2014-09-07 17:45:11 +0300 | [diff] [blame] | 902 | rule->power_rule.max_eirp = |
| 903 | DBM_TO_MBM(IWL_DEFAULT_MAX_TX_POWER); |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 904 | |
| 905 | rule->flags = iwl_nvm_get_regdom_bw_flags(nvm_chan, ch_idx, |
Matti Gottlieb | b281c93 | 2014-06-26 11:10:57 +0300 | [diff] [blame] | 906 | ch_flags, cfg); |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 907 | |
| 908 | /* rely on auto-calculation to merge BW of contiguous chans */ |
| 909 | rule->flags |= NL80211_RRF_AUTO_BW; |
| 910 | rule->freq_range.max_bandwidth_khz = 0; |
| 911 | |
| 912 | prev_ch_flags = ch_flags; |
| 913 | prev_center_freq = center_freq; |
| 914 | |
| 915 | IWL_DEBUG_DEV(dev, IWL_DL_LAR, |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 916 | "Ch. %d [%sGHz] %s%s%s%s%s%s%s%s%s%s%s%s(0x%02x): %s\n", |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 917 | center_freq, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 918 | band == NL80211_BAND_5GHZ ? "5.2" : "2.4", |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 919 | CHECK_AND_PRINT_I(VALID), |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 920 | CHECK_AND_PRINT_I(IBSS), |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 921 | CHECK_AND_PRINT_I(ACTIVE), |
| 922 | CHECK_AND_PRINT_I(RADAR), |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 923 | CHECK_AND_PRINT_I(INDOOR_ONLY), |
| 924 | CHECK_AND_PRINT_I(GO_CONCURRENT), |
| 925 | CHECK_AND_PRINT_I(UNIFORM), |
| 926 | CHECK_AND_PRINT_I(20MHZ), |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 927 | CHECK_AND_PRINT_I(40MHZ), |
| 928 | CHECK_AND_PRINT_I(80MHZ), |
| 929 | CHECK_AND_PRINT_I(160MHZ), |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 930 | CHECK_AND_PRINT_I(DC_HIGH), |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 931 | ch_flags, |
Arik Nemtsov | bdf2fae | 2014-10-30 15:12:39 +0200 | [diff] [blame] | 932 | ((ch_flags & NVM_CHANNEL_ACTIVE) && |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 933 | !(ch_flags & NVM_CHANNEL_RADAR)) |
Luca Coelho | b823cf3 | 2017-08-16 10:46:52 +0300 | [diff] [blame] | 934 | ? "Ad-Hoc" : ""); |
Arik Nemtsov | af45a90 | 2014-03-05 12:19:10 +0200 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | regd->n_reg_rules = valid_rules; |
| 938 | |
| 939 | /* set alpha2 from FW. */ |
| 940 | regd->alpha2[0] = fw_mcc >> 8; |
| 941 | regd->alpha2[1] = fw_mcc & 0xff; |
| 942 | |
| 943 | return regd; |
| 944 | } |
| 945 | IWL_EXPORT_SYMBOL(iwl_parse_nvm_mcc_info); |
Arik Nemtsov | 671bed3 | 2016-08-07 18:58:29 +0300 | [diff] [blame] | 946 | |
| 947 | #ifdef CONFIG_ACPI |
| 948 | #define WRDD_METHOD "WRDD" |
| 949 | #define WRDD_WIFI (0x07) |
| 950 | #define WRDD_WIGIG (0x10) |
| 951 | |
| 952 | static u32 iwl_wrdd_get_mcc(struct device *dev, union acpi_object *wrdd) |
| 953 | { |
| 954 | union acpi_object *mcc_pkg, *domain_type, *mcc_value; |
| 955 | u32 i; |
| 956 | |
| 957 | if (wrdd->type != ACPI_TYPE_PACKAGE || |
| 958 | wrdd->package.count < 2 || |
| 959 | wrdd->package.elements[0].type != ACPI_TYPE_INTEGER || |
| 960 | wrdd->package.elements[0].integer.value != 0) { |
| 961 | IWL_DEBUG_EEPROM(dev, "Unsupported wrdd structure\n"); |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | for (i = 1 ; i < wrdd->package.count ; ++i) { |
| 966 | mcc_pkg = &wrdd->package.elements[i]; |
| 967 | |
| 968 | if (mcc_pkg->type != ACPI_TYPE_PACKAGE || |
| 969 | mcc_pkg->package.count < 2 || |
| 970 | mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER || |
| 971 | mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) { |
| 972 | mcc_pkg = NULL; |
| 973 | continue; |
| 974 | } |
| 975 | |
| 976 | domain_type = &mcc_pkg->package.elements[0]; |
| 977 | if (domain_type->integer.value == WRDD_WIFI) |
| 978 | break; |
| 979 | |
| 980 | mcc_pkg = NULL; |
| 981 | } |
| 982 | |
| 983 | if (mcc_pkg) { |
| 984 | mcc_value = &mcc_pkg->package.elements[1]; |
| 985 | return mcc_value->integer.value; |
| 986 | } |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | int iwl_get_bios_mcc(struct device *dev, char *mcc) |
| 992 | { |
| 993 | acpi_handle root_handle; |
| 994 | acpi_handle handle; |
| 995 | struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 996 | acpi_status status; |
| 997 | u32 mcc_val; |
| 998 | |
| 999 | root_handle = ACPI_HANDLE(dev); |
| 1000 | if (!root_handle) { |
| 1001 | IWL_DEBUG_EEPROM(dev, |
| 1002 | "Could not retrieve root port ACPI handle\n"); |
| 1003 | return -ENOENT; |
| 1004 | } |
| 1005 | |
| 1006 | /* Get the method's handle */ |
| 1007 | status = acpi_get_handle(root_handle, (acpi_string)WRDD_METHOD, |
| 1008 | &handle); |
| 1009 | if (ACPI_FAILURE(status)) { |
| 1010 | IWL_DEBUG_EEPROM(dev, "WRD method not found\n"); |
| 1011 | return -ENOENT; |
| 1012 | } |
| 1013 | |
| 1014 | /* Call WRDD with no arguments */ |
| 1015 | status = acpi_evaluate_object(handle, NULL, NULL, &wrdd); |
| 1016 | if (ACPI_FAILURE(status)) { |
| 1017 | IWL_DEBUG_EEPROM(dev, "WRDC invocation failed (0x%x)\n", |
| 1018 | status); |
| 1019 | return -ENOENT; |
| 1020 | } |
| 1021 | |
| 1022 | mcc_val = iwl_wrdd_get_mcc(dev, wrdd.pointer); |
| 1023 | kfree(wrdd.pointer); |
| 1024 | if (!mcc_val) |
| 1025 | return -ENOENT; |
| 1026 | |
| 1027 | mcc[0] = (mcc_val >> 8) & 0xff; |
| 1028 | mcc[1] = mcc_val & 0xff; |
| 1029 | mcc[2] = '\0'; |
| 1030 | return 0; |
| 1031 | } |
| 1032 | IWL_EXPORT_SYMBOL(iwl_get_bios_mcc); |
| 1033 | #endif |