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