iwl-nvm-parse.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  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. *
  8. * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  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
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  37. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  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>
  69. #include <linux/etherdevice.h>
  70. #include <linux/pci.h>
  71. #include "iwl-drv.h"
  72. #include "iwl-modparams.h"
  73. #include "iwl-nvm-parse.h"
  74. #include "iwl-prph.h"
  75. #include "iwl-io.h"
  76. #include "iwl-csr.h"
  77. #include "fw/acpi.h"
  78. /* NVM offsets (in words) definitions */
  79. enum nvm_offsets {
  80. /* NVM HW-Section offset (in words) definitions */
  81. SUBSYSTEM_ID = 0x0A,
  82. HW_ADDR = 0x15,
  83. /* NVM SW-Section offset (in words) definitions */
  84. NVM_SW_SECTION = 0x1C0,
  85. NVM_VERSION = 0,
  86. RADIO_CFG = 1,
  87. SKU = 2,
  88. N_HW_ADDRS = 3,
  89. NVM_CHANNELS = 0x1E0 - NVM_SW_SECTION,
  90. /* NVM calibration section offset (in words) definitions */
  91. NVM_CALIB_SECTION = 0x2B8,
  92. XTAL_CALIB = 0x316 - NVM_CALIB_SECTION,
  93. /* NVM REGULATORY -Section offset (in words) definitions */
  94. NVM_CHANNELS_SDP = 0,
  95. };
  96. enum ext_nvm_offsets {
  97. /* NVM HW-Section offset (in words) definitions */
  98. MAC_ADDRESS_OVERRIDE_EXT_NVM = 1,
  99. /* NVM SW-Section offset (in words) definitions */
  100. NVM_VERSION_EXT_NVM = 0,
  101. RADIO_CFG_FAMILY_EXT_NVM = 0,
  102. SKU_FAMILY_8000 = 2,
  103. N_HW_ADDRS_FAMILY_8000 = 3,
  104. /* NVM REGULATORY -Section offset (in words) definitions */
  105. NVM_CHANNELS_EXTENDED = 0,
  106. NVM_LAR_OFFSET_OLD = 0x4C7,
  107. NVM_LAR_OFFSET = 0x507,
  108. NVM_LAR_ENABLED = 0x7,
  109. };
  110. /* SKU Capabilities (actual values from NVM definition) */
  111. enum nvm_sku_bits {
  112. NVM_SKU_CAP_BAND_24GHZ = BIT(0),
  113. NVM_SKU_CAP_BAND_52GHZ = BIT(1),
  114. NVM_SKU_CAP_11N_ENABLE = BIT(2),
  115. NVM_SKU_CAP_11AC_ENABLE = BIT(3),
  116. NVM_SKU_CAP_MIMO_DISABLE = BIT(5),
  117. };
  118. /*
  119. * These are the channel numbers in the order that they are stored in the NVM
  120. */
  121. static const u8 iwl_nvm_channels[] = {
  122. /* 2.4 GHz */
  123. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  124. /* 5 GHz */
  125. 36, 40, 44 , 48, 52, 56, 60, 64,
  126. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  127. 149, 153, 157, 161, 165
  128. };
  129. static const u8 iwl_ext_nvm_channels[] = {
  130. /* 2.4 GHz */
  131. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  132. /* 5 GHz */
  133. 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92,
  134. 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  135. 149, 153, 157, 161, 165, 169, 173, 177, 181
  136. };
  137. #define IWL_NUM_CHANNELS ARRAY_SIZE(iwl_nvm_channels)
  138. #define IWL_NUM_CHANNELS_EXT ARRAY_SIZE(iwl_ext_nvm_channels)
  139. #define NUM_2GHZ_CHANNELS 14
  140. #define NUM_2GHZ_CHANNELS_EXT 14
  141. #define FIRST_2GHZ_HT_MINUS 5
  142. #define LAST_2GHZ_HT_PLUS 9
  143. #define LAST_5GHZ_HT 165
  144. #define LAST_5GHZ_HT_FAMILY_8000 181
  145. #define N_HW_ADDR_MASK 0xF
  146. /* rate data (static) */
  147. static struct ieee80211_rate iwl_cfg80211_rates[] = {
  148. { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
  149. { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
  150. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  151. { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
  152. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  153. { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
  154. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  155. { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
  156. { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
  157. { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
  158. { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
  159. { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
  160. { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
  161. { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
  162. { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
  163. };
  164. #define RATES_24_OFFS 0
  165. #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
  166. #define RATES_52_OFFS 4
  167. #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
  168. /**
  169. * enum iwl_nvm_channel_flags - channel flags in NVM
  170. * @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
  171. * @NVM_CHANNEL_IBSS: usable as an IBSS channel
  172. * @NVM_CHANNEL_ACTIVE: active scanning allowed
  173. * @NVM_CHANNEL_RADAR: radar detection required
  174. * @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed
  175. * @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
  176. * on same channel on 2.4 or same UNII band on 5.2
  177. * @NVM_CHANNEL_UNIFORM: uniform spreading required
  178. * @NVM_CHANNEL_20MHZ: 20 MHz channel okay
  179. * @NVM_CHANNEL_40MHZ: 40 MHz channel okay
  180. * @NVM_CHANNEL_80MHZ: 80 MHz channel okay
  181. * @NVM_CHANNEL_160MHZ: 160 MHz channel okay
  182. * @NVM_CHANNEL_DC_HIGH: DC HIGH required/allowed (?)
  183. */
  184. enum iwl_nvm_channel_flags {
  185. NVM_CHANNEL_VALID = BIT(0),
  186. NVM_CHANNEL_IBSS = BIT(1),
  187. NVM_CHANNEL_ACTIVE = BIT(3),
  188. NVM_CHANNEL_RADAR = BIT(4),
  189. NVM_CHANNEL_INDOOR_ONLY = BIT(5),
  190. NVM_CHANNEL_GO_CONCURRENT = BIT(6),
  191. NVM_CHANNEL_UNIFORM = BIT(7),
  192. NVM_CHANNEL_20MHZ = BIT(8),
  193. NVM_CHANNEL_40MHZ = BIT(9),
  194. NVM_CHANNEL_80MHZ = BIT(10),
  195. NVM_CHANNEL_160MHZ = BIT(11),
  196. NVM_CHANNEL_DC_HIGH = BIT(12),
  197. };
  198. static inline void iwl_nvm_print_channel_flags(struct device *dev, u32 level,
  199. int chan, u16 flags)
  200. {
  201. #define CHECK_AND_PRINT_I(x) \
  202. ((flags & NVM_CHANNEL_##x) ? " " #x : "")
  203. if (!(flags & NVM_CHANNEL_VALID)) {
  204. IWL_DEBUG_DEV(dev, level, "Ch. %d: 0x%x: No traffic\n",
  205. chan, flags);
  206. return;
  207. }
  208. /* Note: already can print up to 101 characters, 110 is the limit! */
  209. IWL_DEBUG_DEV(dev, level,
  210. "Ch. %d: 0x%x:%s%s%s%s%s%s%s%s%s%s%s%s\n",
  211. chan, flags,
  212. CHECK_AND_PRINT_I(VALID),
  213. CHECK_AND_PRINT_I(IBSS),
  214. CHECK_AND_PRINT_I(ACTIVE),
  215. CHECK_AND_PRINT_I(RADAR),
  216. CHECK_AND_PRINT_I(INDOOR_ONLY),
  217. CHECK_AND_PRINT_I(GO_CONCURRENT),
  218. CHECK_AND_PRINT_I(UNIFORM),
  219. CHECK_AND_PRINT_I(20MHZ),
  220. CHECK_AND_PRINT_I(40MHZ),
  221. CHECK_AND_PRINT_I(80MHZ),
  222. CHECK_AND_PRINT_I(160MHZ),
  223. CHECK_AND_PRINT_I(DC_HIGH));
  224. #undef CHECK_AND_PRINT_I
  225. }
  226. static u32 iwl_get_channel_flags(u8 ch_num, int ch_idx, bool is_5ghz,
  227. u16 nvm_flags, const struct iwl_cfg *cfg)
  228. {
  229. u32 flags = IEEE80211_CHAN_NO_HT40;
  230. u32 last_5ghz_ht = LAST_5GHZ_HT;
  231. if (cfg->nvm_type == IWL_NVM_EXT)
  232. last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
  233. if (!is_5ghz && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  234. if (ch_num <= LAST_2GHZ_HT_PLUS)
  235. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  236. if (ch_num >= FIRST_2GHZ_HT_MINUS)
  237. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  238. } else if (ch_num <= last_5ghz_ht && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  239. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  240. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  241. else
  242. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  243. }
  244. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  245. flags |= IEEE80211_CHAN_NO_80MHZ;
  246. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  247. flags |= IEEE80211_CHAN_NO_160MHZ;
  248. if (!(nvm_flags & NVM_CHANNEL_IBSS))
  249. flags |= IEEE80211_CHAN_NO_IR;
  250. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  251. flags |= IEEE80211_CHAN_NO_IR;
  252. if (nvm_flags & NVM_CHANNEL_RADAR)
  253. flags |= IEEE80211_CHAN_RADAR;
  254. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  255. flags |= IEEE80211_CHAN_INDOOR_ONLY;
  256. /* Set the GO concurrent flag only in case that NO_IR is set.
  257. * Otherwise it is meaningless
  258. */
  259. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  260. (flags & IEEE80211_CHAN_NO_IR))
  261. flags |= IEEE80211_CHAN_IR_CONCURRENT;
  262. return flags;
  263. }
  264. static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
  265. struct iwl_nvm_data *data,
  266. const __le16 * const nvm_ch_flags,
  267. bool lar_supported, bool no_wide_in_5ghz)
  268. {
  269. int ch_idx;
  270. int n_channels = 0;
  271. struct ieee80211_channel *channel;
  272. u16 ch_flags;
  273. int num_of_ch, num_2ghz_channels;
  274. const u8 *nvm_chan;
  275. if (cfg->nvm_type != IWL_NVM_EXT) {
  276. num_of_ch = IWL_NUM_CHANNELS;
  277. nvm_chan = &iwl_nvm_channels[0];
  278. num_2ghz_channels = NUM_2GHZ_CHANNELS;
  279. } else {
  280. num_of_ch = IWL_NUM_CHANNELS_EXT;
  281. nvm_chan = &iwl_ext_nvm_channels[0];
  282. num_2ghz_channels = NUM_2GHZ_CHANNELS_EXT;
  283. }
  284. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  285. bool is_5ghz = (ch_idx >= num_2ghz_channels);
  286. ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
  287. if (is_5ghz && !data->sku_cap_band_52GHz_enable)
  288. continue;
  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. if (ch_flags & NVM_CHANNEL_160MHZ)
  296. data->vht160_supported = true;
  297. if (!lar_supported && !(ch_flags & NVM_CHANNEL_VALID)) {
  298. /*
  299. * Channels might become valid later if lar is
  300. * supported, hence we still want to add them to
  301. * the list of supported channels to cfg80211.
  302. */
  303. iwl_nvm_print_channel_flags(dev, IWL_DL_EEPROM,
  304. nvm_chan[ch_idx], ch_flags);
  305. continue;
  306. }
  307. channel = &data->channels[n_channels];
  308. n_channels++;
  309. channel->hw_value = nvm_chan[ch_idx];
  310. channel->band = is_5ghz ?
  311. NL80211_BAND_5GHZ : NL80211_BAND_2GHZ;
  312. channel->center_freq =
  313. ieee80211_channel_to_frequency(
  314. channel->hw_value, channel->band);
  315. /* Initialize regulatory-based run-time data */
  316. /*
  317. * Default value - highest tx power value. max_power
  318. * is not used in mvm, and is used for backwards compatibility
  319. */
  320. channel->max_power = IWL_DEFAULT_MAX_TX_POWER;
  321. /* don't put limitations in case we're using LAR */
  322. if (!lar_supported)
  323. channel->flags = iwl_get_channel_flags(nvm_chan[ch_idx],
  324. ch_idx, is_5ghz,
  325. ch_flags, cfg);
  326. else
  327. channel->flags = 0;
  328. iwl_nvm_print_channel_flags(dev, IWL_DL_EEPROM,
  329. channel->hw_value, ch_flags);
  330. IWL_DEBUG_EEPROM(dev, "Ch. %d: %ddBm\n",
  331. channel->hw_value, channel->max_power);
  332. }
  333. return n_channels;
  334. }
  335. static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
  336. struct iwl_nvm_data *data,
  337. struct ieee80211_sta_vht_cap *vht_cap,
  338. u8 tx_chains, u8 rx_chains)
  339. {
  340. int num_rx_ants = num_of_ant(rx_chains);
  341. int num_tx_ants = num_of_ant(tx_chains);
  342. unsigned int max_ampdu_exponent = (cfg->max_vht_ampdu_exponent ?:
  343. IEEE80211_VHT_MAX_AMPDU_1024K);
  344. vht_cap->vht_supported = true;
  345. vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 |
  346. IEEE80211_VHT_CAP_RXSTBC_1 |
  347. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  348. 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
  349. max_ampdu_exponent <<
  350. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  351. if (data->vht160_supported)
  352. vht_cap->cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
  353. IEEE80211_VHT_CAP_SHORT_GI_160;
  354. if (cfg->vht_mu_mimo_supported)
  355. vht_cap->cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  356. if (cfg->ht_params->ldpc)
  357. vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC;
  358. if (data->sku_cap_mimo_disabled) {
  359. num_rx_ants = 1;
  360. num_tx_ants = 1;
  361. }
  362. if (num_tx_ants > 1)
  363. vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
  364. else
  365. vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  366. switch (iwlwifi_mod_params.amsdu_size) {
  367. case IWL_AMSDU_DEF:
  368. if (cfg->mq_rx_supported)
  369. vht_cap->cap |=
  370. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  371. else
  372. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  373. break;
  374. case IWL_AMSDU_4K:
  375. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  376. break;
  377. case IWL_AMSDU_8K:
  378. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
  379. break;
  380. case IWL_AMSDU_12K:
  381. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  382. break;
  383. default:
  384. break;
  385. }
  386. vht_cap->vht_mcs.rx_mcs_map =
  387. cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  388. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  389. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  390. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  391. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  392. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  393. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  394. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
  395. if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) {
  396. vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
  397. /* this works because NOT_SUPPORTED == 3 */
  398. vht_cap->vht_mcs.rx_mcs_map |=
  399. cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2);
  400. }
  401. vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
  402. }
  403. void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
  404. struct iwl_nvm_data *data, const __le16 *nvm_ch_flags,
  405. u8 tx_chains, u8 rx_chains, bool lar_supported,
  406. bool no_wide_in_5ghz)
  407. {
  408. int n_channels;
  409. int n_used = 0;
  410. struct ieee80211_supported_band *sband;
  411. n_channels = iwl_init_channel_map(dev, cfg, data, nvm_ch_flags,
  412. lar_supported, no_wide_in_5ghz);
  413. sband = &data->bands[NL80211_BAND_2GHZ];
  414. sband->band = NL80211_BAND_2GHZ;
  415. sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
  416. sband->n_bitrates = N_RATES_24;
  417. n_used += iwl_init_sband_channels(data, sband, n_channels,
  418. NL80211_BAND_2GHZ);
  419. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_2GHZ,
  420. tx_chains, rx_chains);
  421. sband = &data->bands[NL80211_BAND_5GHZ];
  422. sband->band = NL80211_BAND_5GHZ;
  423. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  424. sband->n_bitrates = N_RATES_52;
  425. n_used += iwl_init_sband_channels(data, sband, n_channels,
  426. NL80211_BAND_5GHZ);
  427. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_5GHZ,
  428. tx_chains, rx_chains);
  429. if (data->sku_cap_11ac_enable && !iwlwifi_mod_params.disable_11ac)
  430. iwl_init_vht_hw_capab(cfg, data, &sband->vht_cap,
  431. tx_chains, rx_chains);
  432. if (n_channels != n_used)
  433. IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n",
  434. n_used, n_channels);
  435. }
  436. IWL_EXPORT_SYMBOL(iwl_init_sbands);
  437. static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  438. const __le16 *phy_sku)
  439. {
  440. if (cfg->nvm_type != IWL_NVM_EXT)
  441. return le16_to_cpup(nvm_sw + SKU);
  442. return le32_to_cpup((__le32 *)(phy_sku + SKU_FAMILY_8000));
  443. }
  444. static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  445. {
  446. if (cfg->nvm_type != IWL_NVM_EXT)
  447. return le16_to_cpup(nvm_sw + NVM_VERSION);
  448. else
  449. return le32_to_cpup((__le32 *)(nvm_sw +
  450. NVM_VERSION_EXT_NVM));
  451. }
  452. static int iwl_get_radio_cfg(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  453. const __le16 *phy_sku)
  454. {
  455. if (cfg->nvm_type != IWL_NVM_EXT)
  456. return le16_to_cpup(nvm_sw + RADIO_CFG);
  457. return le32_to_cpup((__le32 *)(phy_sku + RADIO_CFG_FAMILY_EXT_NVM));
  458. }
  459. static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  460. {
  461. int n_hw_addr;
  462. if (cfg->nvm_type != IWL_NVM_EXT)
  463. return le16_to_cpup(nvm_sw + N_HW_ADDRS);
  464. n_hw_addr = le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000));
  465. return n_hw_addr & N_HW_ADDR_MASK;
  466. }
  467. static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
  468. struct iwl_nvm_data *data,
  469. u32 radio_cfg)
  470. {
  471. if (cfg->nvm_type != IWL_NVM_EXT) {
  472. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg);
  473. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg);
  474. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg);
  475. data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg);
  476. return;
  477. }
  478. /* set the radio configuration for family 8000 */
  479. data->radio_cfg_type = EXT_NVM_RF_CFG_TYPE_MSK(radio_cfg);
  480. data->radio_cfg_step = EXT_NVM_RF_CFG_STEP_MSK(radio_cfg);
  481. data->radio_cfg_dash = EXT_NVM_RF_CFG_DASH_MSK(radio_cfg);
  482. data->radio_cfg_pnum = EXT_NVM_RF_CFG_FLAVOR_MSK(radio_cfg);
  483. data->valid_tx_ant = EXT_NVM_RF_CFG_TX_ANT_MSK(radio_cfg);
  484. data->valid_rx_ant = EXT_NVM_RF_CFG_RX_ANT_MSK(radio_cfg);
  485. }
  486. static void iwl_flip_hw_address(__le32 mac_addr0, __le32 mac_addr1, u8 *dest)
  487. {
  488. const u8 *hw_addr;
  489. hw_addr = (const u8 *)&mac_addr0;
  490. dest[0] = hw_addr[3];
  491. dest[1] = hw_addr[2];
  492. dest[2] = hw_addr[1];
  493. dest[3] = hw_addr[0];
  494. hw_addr = (const u8 *)&mac_addr1;
  495. dest[4] = hw_addr[1];
  496. dest[5] = hw_addr[0];
  497. }
  498. void iwl_set_hw_address_from_csr(struct iwl_trans *trans,
  499. struct iwl_nvm_data *data)
  500. {
  501. __le32 mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_STRAP));
  502. __le32 mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_STRAP));
  503. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  504. /*
  505. * If the OEM fused a valid address, use it instead of the one in the
  506. * OTP
  507. */
  508. if (is_valid_ether_addr(data->hw_addr))
  509. return;
  510. mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_OTP));
  511. mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_OTP));
  512. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  513. }
  514. IWL_EXPORT_SYMBOL(iwl_set_hw_address_from_csr);
  515. static void iwl_set_hw_address_family_8000(struct iwl_trans *trans,
  516. const struct iwl_cfg *cfg,
  517. struct iwl_nvm_data *data,
  518. const __le16 *mac_override,
  519. const __be16 *nvm_hw)
  520. {
  521. const u8 *hw_addr;
  522. if (mac_override) {
  523. static const u8 reserved_mac[] = {
  524. 0x02, 0xcc, 0xaa, 0xff, 0xee, 0x00
  525. };
  526. hw_addr = (const u8 *)(mac_override +
  527. MAC_ADDRESS_OVERRIDE_EXT_NVM);
  528. /*
  529. * Store the MAC address from MAO section.
  530. * No byte swapping is required in MAO section
  531. */
  532. memcpy(data->hw_addr, hw_addr, ETH_ALEN);
  533. /*
  534. * Force the use of the OTP MAC address in case of reserved MAC
  535. * address in the NVM, or if address is given but invalid.
  536. */
  537. if (is_valid_ether_addr(data->hw_addr) &&
  538. memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0)
  539. return;
  540. IWL_ERR(trans,
  541. "mac address from nvm override section is not valid\n");
  542. }
  543. if (nvm_hw) {
  544. /* read the mac address from WFMP registers */
  545. __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans,
  546. WFMP_MAC_ADDR_0));
  547. __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans,
  548. WFMP_MAC_ADDR_1));
  549. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  550. return;
  551. }
  552. IWL_ERR(trans, "mac address is not found\n");
  553. }
  554. static int iwl_set_hw_address(struct iwl_trans *trans,
  555. const struct iwl_cfg *cfg,
  556. struct iwl_nvm_data *data, const __be16 *nvm_hw,
  557. const __le16 *mac_override)
  558. {
  559. if (cfg->mac_addr_from_csr) {
  560. iwl_set_hw_address_from_csr(trans, data);
  561. } else if (cfg->nvm_type != IWL_NVM_EXT) {
  562. const u8 *hw_addr = (const u8 *)(nvm_hw + HW_ADDR);
  563. /* The byte order is little endian 16 bit, meaning 214365 */
  564. data->hw_addr[0] = hw_addr[1];
  565. data->hw_addr[1] = hw_addr[0];
  566. data->hw_addr[2] = hw_addr[3];
  567. data->hw_addr[3] = hw_addr[2];
  568. data->hw_addr[4] = hw_addr[5];
  569. data->hw_addr[5] = hw_addr[4];
  570. } else {
  571. iwl_set_hw_address_family_8000(trans, cfg, data,
  572. mac_override, nvm_hw);
  573. }
  574. if (!is_valid_ether_addr(data->hw_addr)) {
  575. IWL_ERR(trans, "no valid mac address was found\n");
  576. return -EINVAL;
  577. }
  578. IWL_INFO(trans, "base HW address: %pM\n", data->hw_addr);
  579. return 0;
  580. }
  581. static bool
  582. iwl_nvm_no_wide_in_5ghz(struct device *dev, const struct iwl_cfg *cfg,
  583. const __be16 *nvm_hw)
  584. {
  585. /*
  586. * Workaround a bug in Indonesia SKUs where the regulatory in
  587. * some 7000-family OTPs erroneously allow wide channels in
  588. * 5GHz. To check for Indonesia, we take the SKU value from
  589. * bits 1-4 in the subsystem ID and check if it is either 5 or
  590. * 9. In those cases, we need to force-disable wide channels
  591. * in 5GHz otherwise the FW will throw a sysassert when we try
  592. * to use them.
  593. */
  594. if (cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  595. /*
  596. * Unlike the other sections in the NVM, the hw
  597. * section uses big-endian.
  598. */
  599. u16 subsystem_id = be16_to_cpup(nvm_hw + SUBSYSTEM_ID);
  600. u8 sku = (subsystem_id & 0x1e) >> 1;
  601. if (sku == 5 || sku == 9) {
  602. IWL_DEBUG_EEPROM(dev,
  603. "disabling wide channels in 5GHz (0x%0x %d)\n",
  604. subsystem_id, sku);
  605. return true;
  606. }
  607. }
  608. return false;
  609. }
  610. struct iwl_nvm_data *
  611. iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  612. const __be16 *nvm_hw, const __le16 *nvm_sw,
  613. const __le16 *nvm_calib, const __le16 *regulatory,
  614. const __le16 *mac_override, const __le16 *phy_sku,
  615. u8 tx_chains, u8 rx_chains, bool lar_fw_supported)
  616. {
  617. struct device *dev = trans->dev;
  618. struct iwl_nvm_data *data;
  619. bool lar_enabled;
  620. bool no_wide_in_5ghz = iwl_nvm_no_wide_in_5ghz(dev, cfg, nvm_hw);
  621. u32 sku, radio_cfg;
  622. u16 lar_config;
  623. const __le16 *ch_section;
  624. if (cfg->nvm_type != IWL_NVM_EXT)
  625. data = kzalloc(sizeof(*data) +
  626. sizeof(struct ieee80211_channel) *
  627. IWL_NUM_CHANNELS,
  628. GFP_KERNEL);
  629. else
  630. data = kzalloc(sizeof(*data) +
  631. sizeof(struct ieee80211_channel) *
  632. IWL_NUM_CHANNELS_EXT,
  633. GFP_KERNEL);
  634. if (!data)
  635. return NULL;
  636. data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw);
  637. radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw, phy_sku);
  638. iwl_set_radio_cfg(cfg, data, radio_cfg);
  639. if (data->valid_tx_ant)
  640. tx_chains &= data->valid_tx_ant;
  641. if (data->valid_rx_ant)
  642. rx_chains &= data->valid_rx_ant;
  643. sku = iwl_get_sku(cfg, nvm_sw, phy_sku);
  644. data->sku_cap_band_24GHz_enable = sku & NVM_SKU_CAP_BAND_24GHZ;
  645. data->sku_cap_band_52GHz_enable = sku & NVM_SKU_CAP_BAND_52GHZ;
  646. data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE;
  647. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  648. data->sku_cap_11n_enable = false;
  649. data->sku_cap_11ac_enable = data->sku_cap_11n_enable &&
  650. (sku & NVM_SKU_CAP_11AC_ENABLE);
  651. data->sku_cap_mimo_disabled = sku & NVM_SKU_CAP_MIMO_DISABLE;
  652. data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
  653. if (cfg->nvm_type != IWL_NVM_EXT) {
  654. /* Checking for required sections */
  655. if (!nvm_calib) {
  656. IWL_ERR(trans,
  657. "Can't parse empty Calib NVM sections\n");
  658. kfree(data);
  659. return NULL;
  660. }
  661. ch_section = cfg->nvm_type == IWL_NVM_SDP ?
  662. &regulatory[NVM_CHANNELS_SDP] :
  663. &nvm_sw[NVM_CHANNELS];
  664. /* in family 8000 Xtal calibration values moved to OTP */
  665. data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
  666. data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
  667. lar_enabled = true;
  668. } else {
  669. u16 lar_offset = data->nvm_version < 0xE39 ?
  670. NVM_LAR_OFFSET_OLD :
  671. NVM_LAR_OFFSET;
  672. lar_config = le16_to_cpup(regulatory + lar_offset);
  673. data->lar_enabled = !!(lar_config &
  674. NVM_LAR_ENABLED);
  675. lar_enabled = data->lar_enabled;
  676. ch_section = &regulatory[NVM_CHANNELS_EXTENDED];
  677. }
  678. /* If no valid mac address was found - bail out */
  679. if (iwl_set_hw_address(trans, cfg, data, nvm_hw, mac_override)) {
  680. kfree(data);
  681. return NULL;
  682. }
  683. iwl_init_sbands(dev, cfg, data, ch_section, tx_chains, rx_chains,
  684. lar_fw_supported && lar_enabled, no_wide_in_5ghz);
  685. data->calib_version = 255;
  686. return data;
  687. }
  688. IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);
  689. static u32 iwl_nvm_get_regdom_bw_flags(const u8 *nvm_chan,
  690. int ch_idx, u16 nvm_flags,
  691. const struct iwl_cfg *cfg)
  692. {
  693. u32 flags = NL80211_RRF_NO_HT40;
  694. u32 last_5ghz_ht = LAST_5GHZ_HT;
  695. if (cfg->nvm_type == IWL_NVM_EXT)
  696. last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
  697. if (ch_idx < NUM_2GHZ_CHANNELS &&
  698. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  699. if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS)
  700. flags &= ~NL80211_RRF_NO_HT40PLUS;
  701. if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS)
  702. flags &= ~NL80211_RRF_NO_HT40MINUS;
  703. } else if (nvm_chan[ch_idx] <= last_5ghz_ht &&
  704. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  705. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  706. flags &= ~NL80211_RRF_NO_HT40PLUS;
  707. else
  708. flags &= ~NL80211_RRF_NO_HT40MINUS;
  709. }
  710. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  711. flags |= NL80211_RRF_NO_80MHZ;
  712. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  713. flags |= NL80211_RRF_NO_160MHZ;
  714. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  715. flags |= NL80211_RRF_NO_IR;
  716. if (nvm_flags & NVM_CHANNEL_RADAR)
  717. flags |= NL80211_RRF_DFS;
  718. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  719. flags |= NL80211_RRF_NO_OUTDOOR;
  720. /* Set the GO concurrent flag only in case that NO_IR is set.
  721. * Otherwise it is meaningless
  722. */
  723. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  724. (flags & NL80211_RRF_NO_IR))
  725. flags |= NL80211_RRF_GO_CONCURRENT;
  726. return flags;
  727. }
  728. struct ieee80211_regdomain *
  729. iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
  730. int num_of_ch, __le32 *channels, u16 fw_mcc)
  731. {
  732. int ch_idx;
  733. u16 ch_flags;
  734. u32 reg_rule_flags, prev_reg_rule_flags = 0;
  735. const u8 *nvm_chan = cfg->nvm_type == IWL_NVM_EXT ?
  736. iwl_ext_nvm_channels : iwl_nvm_channels;
  737. struct ieee80211_regdomain *regd;
  738. int size_of_regd;
  739. struct ieee80211_reg_rule *rule;
  740. enum nl80211_band band;
  741. int center_freq, prev_center_freq = 0;
  742. int valid_rules = 0;
  743. bool new_rule;
  744. int max_num_ch = cfg->nvm_type == IWL_NVM_EXT ?
  745. IWL_NUM_CHANNELS_EXT : IWL_NUM_CHANNELS;
  746. if (WARN_ON_ONCE(num_of_ch > NL80211_MAX_SUPP_REG_RULES))
  747. return ERR_PTR(-EINVAL);
  748. if (WARN_ON(num_of_ch > max_num_ch))
  749. num_of_ch = max_num_ch;
  750. IWL_DEBUG_DEV(dev, IWL_DL_LAR, "building regdom for %d channels\n",
  751. num_of_ch);
  752. /* build a regdomain rule for every valid channel */
  753. size_of_regd =
  754. sizeof(struct ieee80211_regdomain) +
  755. num_of_ch * sizeof(struct ieee80211_reg_rule);
  756. regd = kzalloc(size_of_regd, GFP_KERNEL);
  757. if (!regd)
  758. return ERR_PTR(-ENOMEM);
  759. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  760. ch_flags = (u16)__le32_to_cpup(channels + ch_idx);
  761. band = (ch_idx < NUM_2GHZ_CHANNELS) ?
  762. NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
  763. center_freq = ieee80211_channel_to_frequency(nvm_chan[ch_idx],
  764. band);
  765. new_rule = false;
  766. if (!(ch_flags & NVM_CHANNEL_VALID)) {
  767. iwl_nvm_print_channel_flags(dev, IWL_DL_LAR,
  768. nvm_chan[ch_idx], ch_flags);
  769. continue;
  770. }
  771. reg_rule_flags = iwl_nvm_get_regdom_bw_flags(nvm_chan, ch_idx,
  772. ch_flags, cfg);
  773. /* we can't continue the same rule */
  774. if (ch_idx == 0 || prev_reg_rule_flags != reg_rule_flags ||
  775. center_freq - prev_center_freq > 20) {
  776. valid_rules++;
  777. new_rule = true;
  778. }
  779. rule = &regd->reg_rules[valid_rules - 1];
  780. if (new_rule)
  781. rule->freq_range.start_freq_khz =
  782. MHZ_TO_KHZ(center_freq - 10);
  783. rule->freq_range.end_freq_khz = MHZ_TO_KHZ(center_freq + 10);
  784. /* this doesn't matter - not used by FW */
  785. rule->power_rule.max_antenna_gain = DBI_TO_MBI(6);
  786. rule->power_rule.max_eirp =
  787. DBM_TO_MBM(IWL_DEFAULT_MAX_TX_POWER);
  788. rule->flags = reg_rule_flags;
  789. /* rely on auto-calculation to merge BW of contiguous chans */
  790. rule->flags |= NL80211_RRF_AUTO_BW;
  791. rule->freq_range.max_bandwidth_khz = 0;
  792. prev_center_freq = center_freq;
  793. prev_reg_rule_flags = reg_rule_flags;
  794. iwl_nvm_print_channel_flags(dev, IWL_DL_LAR,
  795. nvm_chan[ch_idx], ch_flags);
  796. }
  797. regd->n_reg_rules = valid_rules;
  798. /* set alpha2 from FW. */
  799. regd->alpha2[0] = fw_mcc >> 8;
  800. regd->alpha2[1] = fw_mcc & 0xff;
  801. return regd;
  802. }
  803. IWL_EXPORT_SYMBOL(iwl_parse_nvm_mcc_info);