iwl-nvm-parse.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  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 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. * All rights reserved.
  38. *
  39. * Redistribution and use in source and binary forms, with or without
  40. * modification, are permitted provided that the following conditions
  41. * are met:
  42. *
  43. * * Redistributions of source code must retain the above copyright
  44. * notice, this list of conditions and the following disclaimer.
  45. * * Redistributions in binary form must reproduce the above copyright
  46. * notice, this list of conditions and the following disclaimer in
  47. * the documentation and/or other materials provided with the
  48. * distribution.
  49. * * Neither the name Intel Corporation nor the names of its
  50. * contributors may be used to endorse or promote products derived
  51. * from this software without specific prior written permission.
  52. *
  53. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  54. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  55. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  56. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  57. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  58. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  59. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  60. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  61. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  62. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  63. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  64. *****************************************************************************/
  65. #include <linux/types.h>
  66. #include <linux/slab.h>
  67. #include <linux/export.h>
  68. #include <linux/etherdevice.h>
  69. #include <linux/pci.h>
  70. #include "iwl-drv.h"
  71. #include "iwl-modparams.h"
  72. #include "iwl-nvm-parse.h"
  73. #include "iwl-prph.h"
  74. #include "iwl-io.h"
  75. #include "iwl-csr.h"
  76. /* NVM offsets (in words) definitions */
  77. enum wkp_nvm_offsets {
  78. /* NVM HW-Section offset (in words) definitions */
  79. HW_ADDR = 0x15,
  80. /* NVM SW-Section offset (in words) definitions */
  81. NVM_SW_SECTION = 0x1C0,
  82. NVM_VERSION = 0,
  83. RADIO_CFG = 1,
  84. SKU = 2,
  85. N_HW_ADDRS = 3,
  86. NVM_CHANNELS = 0x1E0 - NVM_SW_SECTION,
  87. /* NVM calibration section offset (in words) definitions */
  88. NVM_CALIB_SECTION = 0x2B8,
  89. XTAL_CALIB = 0x316 - NVM_CALIB_SECTION
  90. };
  91. enum family_8000_nvm_offsets {
  92. /* NVM HW-Section offset (in words) definitions */
  93. HW_ADDR0_WFPM_FAMILY_8000 = 0x12,
  94. HW_ADDR1_WFPM_FAMILY_8000 = 0x16,
  95. HW_ADDR0_PCIE_FAMILY_8000 = 0x8A,
  96. HW_ADDR1_PCIE_FAMILY_8000 = 0x8E,
  97. MAC_ADDRESS_OVERRIDE_FAMILY_8000 = 1,
  98. /* NVM SW-Section offset (in words) definitions */
  99. NVM_SW_SECTION_FAMILY_8000 = 0x1C0,
  100. NVM_VERSION_FAMILY_8000 = 0,
  101. RADIO_CFG_FAMILY_8000 = 0,
  102. SKU_FAMILY_8000 = 2,
  103. N_HW_ADDRS_FAMILY_8000 = 3,
  104. /* NVM REGULATORY -Section offset (in words) definitions */
  105. NVM_CHANNELS_FAMILY_8000 = 0,
  106. NVM_LAR_OFFSET_FAMILY_8000_OLD = 0x4C7,
  107. NVM_LAR_OFFSET_FAMILY_8000 = 0x507,
  108. NVM_LAR_ENABLED_FAMILY_8000 = 0x7,
  109. /* NVM calibration section offset (in words) definitions */
  110. NVM_CALIB_SECTION_FAMILY_8000 = 0x2B8,
  111. XTAL_CALIB_FAMILY_8000 = 0x316 - NVM_CALIB_SECTION_FAMILY_8000
  112. };
  113. /* SKU Capabilities (actual values from NVM definition) */
  114. enum nvm_sku_bits {
  115. NVM_SKU_CAP_BAND_24GHZ = BIT(0),
  116. NVM_SKU_CAP_BAND_52GHZ = BIT(1),
  117. NVM_SKU_CAP_11N_ENABLE = BIT(2),
  118. NVM_SKU_CAP_11AC_ENABLE = BIT(3),
  119. NVM_SKU_CAP_MIMO_DISABLE = BIT(5),
  120. };
  121. /*
  122. * These are the channel numbers in the order that they are stored in the NVM
  123. */
  124. static const u8 iwl_nvm_channels[] = {
  125. /* 2.4 GHz */
  126. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  127. /* 5 GHz */
  128. 36, 40, 44 , 48, 52, 56, 60, 64,
  129. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  130. 149, 153, 157, 161, 165
  131. };
  132. static const u8 iwl_nvm_channels_family_8000[] = {
  133. /* 2.4 GHz */
  134. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  135. /* 5 GHz */
  136. 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92,
  137. 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  138. 149, 153, 157, 161, 165, 169, 173, 177, 181
  139. };
  140. #define IWL_NUM_CHANNELS ARRAY_SIZE(iwl_nvm_channels)
  141. #define IWL_NUM_CHANNELS_FAMILY_8000 ARRAY_SIZE(iwl_nvm_channels_family_8000)
  142. #define NUM_2GHZ_CHANNELS 14
  143. #define NUM_2GHZ_CHANNELS_FAMILY_8000 14
  144. #define FIRST_2GHZ_HT_MINUS 5
  145. #define LAST_2GHZ_HT_PLUS 9
  146. #define LAST_5GHZ_HT 165
  147. #define LAST_5GHZ_HT_FAMILY_8000 181
  148. #define N_HW_ADDR_MASK 0xF
  149. /* rate data (static) */
  150. static struct ieee80211_rate iwl_cfg80211_rates[] = {
  151. { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
  152. { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
  153. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  154. { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
  155. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  156. { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
  157. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  158. { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
  159. { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
  160. { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
  161. { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
  162. { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
  163. { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
  164. { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
  165. { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
  166. };
  167. #define RATES_24_OFFS 0
  168. #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
  169. #define RATES_52_OFFS 4
  170. #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
  171. /**
  172. * enum iwl_nvm_channel_flags - channel flags in NVM
  173. * @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
  174. * @NVM_CHANNEL_IBSS: usable as an IBSS channel
  175. * @NVM_CHANNEL_ACTIVE: active scanning allowed
  176. * @NVM_CHANNEL_RADAR: radar detection required
  177. * @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed
  178. * @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
  179. * on same channel on 2.4 or same UNII band on 5.2
  180. * @NVM_CHANNEL_WIDE: 20 MHz channel okay (?)
  181. * @NVM_CHANNEL_40MHZ: 40 MHz channel okay (?)
  182. * @NVM_CHANNEL_80MHZ: 80 MHz channel okay (?)
  183. * @NVM_CHANNEL_160MHZ: 160 MHz channel okay (?)
  184. */
  185. enum iwl_nvm_channel_flags {
  186. NVM_CHANNEL_VALID = BIT(0),
  187. NVM_CHANNEL_IBSS = BIT(1),
  188. NVM_CHANNEL_ACTIVE = BIT(3),
  189. NVM_CHANNEL_RADAR = BIT(4),
  190. NVM_CHANNEL_INDOOR_ONLY = BIT(5),
  191. NVM_CHANNEL_GO_CONCURRENT = BIT(6),
  192. NVM_CHANNEL_WIDE = BIT(8),
  193. NVM_CHANNEL_40MHZ = BIT(9),
  194. NVM_CHANNEL_80MHZ = BIT(10),
  195. NVM_CHANNEL_160MHZ = BIT(11),
  196. };
  197. #define CHECK_AND_PRINT_I(x) \
  198. ((ch_flags & NVM_CHANNEL_##x) ? # x " " : "")
  199. static u32 iwl_get_channel_flags(u8 ch_num, int ch_idx, bool is_5ghz,
  200. u16 nvm_flags, const struct iwl_cfg *cfg)
  201. {
  202. u32 flags = IEEE80211_CHAN_NO_HT40;
  203. u32 last_5ghz_ht = LAST_5GHZ_HT;
  204. if (cfg->device_family == IWL_DEVICE_FAMILY_8000)
  205. last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
  206. if (!is_5ghz && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  207. if (ch_num <= LAST_2GHZ_HT_PLUS)
  208. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  209. if (ch_num >= FIRST_2GHZ_HT_MINUS)
  210. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  211. } else if (ch_num <= last_5ghz_ht && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  212. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  213. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  214. else
  215. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  216. }
  217. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  218. flags |= IEEE80211_CHAN_NO_80MHZ;
  219. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  220. flags |= IEEE80211_CHAN_NO_160MHZ;
  221. if (!(nvm_flags & NVM_CHANNEL_IBSS))
  222. flags |= IEEE80211_CHAN_NO_IR;
  223. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  224. flags |= IEEE80211_CHAN_NO_IR;
  225. if (nvm_flags & NVM_CHANNEL_RADAR)
  226. flags |= IEEE80211_CHAN_RADAR;
  227. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  228. flags |= IEEE80211_CHAN_INDOOR_ONLY;
  229. /* Set the GO concurrent flag only in case that NO_IR is set.
  230. * Otherwise it is meaningless
  231. */
  232. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  233. (flags & IEEE80211_CHAN_NO_IR))
  234. flags |= IEEE80211_CHAN_IR_CONCURRENT;
  235. return flags;
  236. }
  237. static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
  238. struct iwl_nvm_data *data,
  239. const __le16 * const nvm_ch_flags,
  240. bool lar_supported)
  241. {
  242. int ch_idx;
  243. int n_channels = 0;
  244. struct ieee80211_channel *channel;
  245. u16 ch_flags;
  246. bool is_5ghz;
  247. int num_of_ch, num_2ghz_channels;
  248. const u8 *nvm_chan;
  249. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  250. num_of_ch = IWL_NUM_CHANNELS;
  251. nvm_chan = &iwl_nvm_channels[0];
  252. num_2ghz_channels = NUM_2GHZ_CHANNELS;
  253. } else {
  254. num_of_ch = IWL_NUM_CHANNELS_FAMILY_8000;
  255. nvm_chan = &iwl_nvm_channels_family_8000[0];
  256. num_2ghz_channels = NUM_2GHZ_CHANNELS_FAMILY_8000;
  257. }
  258. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  259. ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
  260. if (ch_idx >= num_2ghz_channels &&
  261. !data->sku_cap_band_52GHz_enable)
  262. continue;
  263. if (!lar_supported && !(ch_flags & NVM_CHANNEL_VALID)) {
  264. /*
  265. * Channels might become valid later if lar is
  266. * supported, hence we still want to add them to
  267. * the list of supported channels to cfg80211.
  268. */
  269. IWL_DEBUG_EEPROM(dev,
  270. "Ch. %d Flags %x [%sGHz] - No traffic\n",
  271. nvm_chan[ch_idx],
  272. ch_flags,
  273. (ch_idx >= num_2ghz_channels) ?
  274. "5.2" : "2.4");
  275. continue;
  276. }
  277. channel = &data->channels[n_channels];
  278. n_channels++;
  279. channel->hw_value = nvm_chan[ch_idx];
  280. channel->band = (ch_idx < num_2ghz_channels) ?
  281. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  282. channel->center_freq =
  283. ieee80211_channel_to_frequency(
  284. channel->hw_value, channel->band);
  285. /* Initialize regulatory-based run-time data */
  286. /*
  287. * Default value - highest tx power value. max_power
  288. * is not used in mvm, and is used for backwards compatibility
  289. */
  290. channel->max_power = IWL_DEFAULT_MAX_TX_POWER;
  291. is_5ghz = channel->band == IEEE80211_BAND_5GHZ;
  292. /* don't put limitations in case we're using LAR */
  293. if (!lar_supported)
  294. channel->flags = iwl_get_channel_flags(nvm_chan[ch_idx],
  295. ch_idx, is_5ghz,
  296. ch_flags, cfg);
  297. else
  298. channel->flags = 0;
  299. IWL_DEBUG_EEPROM(dev,
  300. "Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
  301. channel->hw_value,
  302. is_5ghz ? "5.2" : "2.4",
  303. CHECK_AND_PRINT_I(VALID),
  304. CHECK_AND_PRINT_I(IBSS),
  305. CHECK_AND_PRINT_I(ACTIVE),
  306. CHECK_AND_PRINT_I(RADAR),
  307. CHECK_AND_PRINT_I(WIDE),
  308. CHECK_AND_PRINT_I(INDOOR_ONLY),
  309. CHECK_AND_PRINT_I(GO_CONCURRENT),
  310. ch_flags,
  311. channel->max_power,
  312. ((ch_flags & NVM_CHANNEL_IBSS) &&
  313. !(ch_flags & NVM_CHANNEL_RADAR))
  314. ? "" : "not ");
  315. }
  316. return n_channels;
  317. }
  318. static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
  319. struct iwl_nvm_data *data,
  320. struct ieee80211_sta_vht_cap *vht_cap,
  321. u8 tx_chains, u8 rx_chains)
  322. {
  323. int num_rx_ants = num_of_ant(rx_chains);
  324. int num_tx_ants = num_of_ant(tx_chains);
  325. unsigned int max_ampdu_exponent = (cfg->max_vht_ampdu_exponent ?:
  326. IEEE80211_VHT_MAX_AMPDU_1024K);
  327. vht_cap->vht_supported = true;
  328. vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 |
  329. IEEE80211_VHT_CAP_RXSTBC_1 |
  330. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  331. 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
  332. max_ampdu_exponent <<
  333. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  334. if (cfg->vht_mu_mimo_supported)
  335. vht_cap->cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  336. if (cfg->ht_params->ldpc)
  337. vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC;
  338. if (data->sku_cap_mimo_disabled) {
  339. num_rx_ants = 1;
  340. num_tx_ants = 1;
  341. }
  342. if (num_tx_ants > 1)
  343. vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
  344. else
  345. vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  346. switch (iwlwifi_mod_params.amsdu_size) {
  347. case IWL_AMSDU_4K:
  348. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  349. break;
  350. case IWL_AMSDU_8K:
  351. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
  352. break;
  353. case IWL_AMSDU_12K:
  354. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  355. break;
  356. default:
  357. break;
  358. }
  359. vht_cap->vht_mcs.rx_mcs_map =
  360. cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  361. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  362. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  363. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  364. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  365. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  366. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  367. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
  368. if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) {
  369. vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
  370. /* this works because NOT_SUPPORTED == 3 */
  371. vht_cap->vht_mcs.rx_mcs_map |=
  372. cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2);
  373. }
  374. vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
  375. }
  376. static void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
  377. struct iwl_nvm_data *data,
  378. const __le16 *ch_section,
  379. u8 tx_chains, u8 rx_chains, bool lar_supported)
  380. {
  381. int n_channels;
  382. int n_used = 0;
  383. struct ieee80211_supported_band *sband;
  384. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  385. n_channels = iwl_init_channel_map(
  386. dev, cfg, data,
  387. &ch_section[NVM_CHANNELS], lar_supported);
  388. else
  389. n_channels = iwl_init_channel_map(
  390. dev, cfg, data,
  391. &ch_section[NVM_CHANNELS_FAMILY_8000],
  392. lar_supported);
  393. sband = &data->bands[IEEE80211_BAND_2GHZ];
  394. sband->band = IEEE80211_BAND_2GHZ;
  395. sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
  396. sband->n_bitrates = N_RATES_24;
  397. n_used += iwl_init_sband_channels(data, sband, n_channels,
  398. IEEE80211_BAND_2GHZ);
  399. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_2GHZ,
  400. tx_chains, rx_chains);
  401. sband = &data->bands[IEEE80211_BAND_5GHZ];
  402. sband->band = IEEE80211_BAND_5GHZ;
  403. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  404. sband->n_bitrates = N_RATES_52;
  405. n_used += iwl_init_sband_channels(data, sband, n_channels,
  406. IEEE80211_BAND_5GHZ);
  407. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_5GHZ,
  408. tx_chains, rx_chains);
  409. if (data->sku_cap_11ac_enable && !iwlwifi_mod_params.disable_11ac)
  410. iwl_init_vht_hw_capab(cfg, data, &sband->vht_cap,
  411. tx_chains, rx_chains);
  412. if (n_channels != n_used)
  413. IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n",
  414. n_used, n_channels);
  415. }
  416. static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  417. const __le16 *phy_sku)
  418. {
  419. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  420. return le16_to_cpup(nvm_sw + SKU);
  421. return le32_to_cpup((__le32 *)(phy_sku + SKU_FAMILY_8000));
  422. }
  423. static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  424. {
  425. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  426. return le16_to_cpup(nvm_sw + NVM_VERSION);
  427. else
  428. return le32_to_cpup((__le32 *)(nvm_sw +
  429. NVM_VERSION_FAMILY_8000));
  430. }
  431. static int iwl_get_radio_cfg(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  432. const __le16 *phy_sku)
  433. {
  434. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  435. return le16_to_cpup(nvm_sw + RADIO_CFG);
  436. return le32_to_cpup((__le32 *)(phy_sku + RADIO_CFG_FAMILY_8000));
  437. }
  438. static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  439. {
  440. int n_hw_addr;
  441. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  442. return le16_to_cpup(nvm_sw + N_HW_ADDRS);
  443. n_hw_addr = le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000));
  444. return n_hw_addr & N_HW_ADDR_MASK;
  445. }
  446. static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
  447. struct iwl_nvm_data *data,
  448. u32 radio_cfg)
  449. {
  450. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  451. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg);
  452. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg);
  453. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg);
  454. data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg);
  455. return;
  456. }
  457. /* set the radio configuration for family 8000 */
  458. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK_FAMILY_8000(radio_cfg);
  459. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK_FAMILY_8000(radio_cfg);
  460. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK_FAMILY_8000(radio_cfg);
  461. data->radio_cfg_pnum = NVM_RF_CFG_FLAVOR_MSK_FAMILY_8000(radio_cfg);
  462. data->valid_tx_ant = NVM_RF_CFG_TX_ANT_MSK_FAMILY_8000(radio_cfg);
  463. data->valid_rx_ant = NVM_RF_CFG_RX_ANT_MSK_FAMILY_8000(radio_cfg);
  464. }
  465. static void iwl_flip_hw_address(__le32 mac_addr0, __le32 mac_addr1, u8 *dest)
  466. {
  467. const u8 *hw_addr;
  468. hw_addr = (const u8 *)&mac_addr0;
  469. dest[0] = hw_addr[3];
  470. dest[1] = hw_addr[2];
  471. dest[2] = hw_addr[1];
  472. dest[3] = hw_addr[0];
  473. hw_addr = (const u8 *)&mac_addr1;
  474. dest[4] = hw_addr[1];
  475. dest[5] = hw_addr[0];
  476. }
  477. static void iwl_set_hw_address_from_csr(struct iwl_trans *trans,
  478. struct iwl_nvm_data *data)
  479. {
  480. __le32 mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_STRAP));
  481. __le32 mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_STRAP));
  482. /* If OEM did not fuse address - get it from OTP */
  483. if (!mac_addr0 && !mac_addr1) {
  484. mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_OTP));
  485. mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_OTP));
  486. }
  487. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  488. }
  489. static void iwl_set_hw_address_family_8000(struct iwl_trans *trans,
  490. const struct iwl_cfg *cfg,
  491. struct iwl_nvm_data *data,
  492. const __le16 *mac_override,
  493. const __le16 *nvm_hw)
  494. {
  495. const u8 *hw_addr;
  496. if (mac_override) {
  497. static const u8 reserved_mac[] = {
  498. 0x02, 0xcc, 0xaa, 0xff, 0xee, 0x00
  499. };
  500. hw_addr = (const u8 *)(mac_override +
  501. MAC_ADDRESS_OVERRIDE_FAMILY_8000);
  502. /*
  503. * Store the MAC address from MAO section.
  504. * No byte swapping is required in MAO section
  505. */
  506. memcpy(data->hw_addr, hw_addr, ETH_ALEN);
  507. /*
  508. * Force the use of the OTP MAC address in case of reserved MAC
  509. * address in the NVM, or if address is given but invalid.
  510. */
  511. if (is_valid_ether_addr(data->hw_addr) &&
  512. memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0)
  513. return;
  514. IWL_ERR(trans,
  515. "mac address from nvm override section is not valid\n");
  516. }
  517. if (nvm_hw) {
  518. /* read the mac address from WFMP registers */
  519. __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans,
  520. WFMP_MAC_ADDR_0));
  521. __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans,
  522. WFMP_MAC_ADDR_1));
  523. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  524. return;
  525. }
  526. IWL_ERR(trans, "mac address is not found\n");
  527. }
  528. static int iwl_set_hw_address(struct iwl_trans *trans,
  529. const struct iwl_cfg *cfg,
  530. struct iwl_nvm_data *data, const __le16 *nvm_hw,
  531. const __le16 *mac_override)
  532. {
  533. if (cfg->mac_addr_from_csr) {
  534. iwl_set_hw_address_from_csr(trans, data);
  535. } else if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  536. const u8 *hw_addr = (const u8 *)(nvm_hw + HW_ADDR);
  537. /* The byte order is little endian 16 bit, meaning 214365 */
  538. data->hw_addr[0] = hw_addr[1];
  539. data->hw_addr[1] = hw_addr[0];
  540. data->hw_addr[2] = hw_addr[3];
  541. data->hw_addr[3] = hw_addr[2];
  542. data->hw_addr[4] = hw_addr[5];
  543. data->hw_addr[5] = hw_addr[4];
  544. } else {
  545. iwl_set_hw_address_family_8000(trans, cfg, data,
  546. mac_override, nvm_hw);
  547. }
  548. if (!is_valid_ether_addr(data->hw_addr)) {
  549. IWL_ERR(trans, "no valid mac address was found\n");
  550. return -EINVAL;
  551. }
  552. return 0;
  553. }
  554. struct iwl_nvm_data *
  555. iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  556. const __le16 *nvm_hw, const __le16 *nvm_sw,
  557. const __le16 *nvm_calib, const __le16 *regulatory,
  558. const __le16 *mac_override, const __le16 *phy_sku,
  559. u8 tx_chains, u8 rx_chains, bool lar_fw_supported)
  560. {
  561. struct device *dev = trans->dev;
  562. struct iwl_nvm_data *data;
  563. bool lar_enabled;
  564. u32 sku, radio_cfg;
  565. u16 lar_config;
  566. const __le16 *ch_section;
  567. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  568. data = kzalloc(sizeof(*data) +
  569. sizeof(struct ieee80211_channel) *
  570. IWL_NUM_CHANNELS,
  571. GFP_KERNEL);
  572. else
  573. data = kzalloc(sizeof(*data) +
  574. sizeof(struct ieee80211_channel) *
  575. IWL_NUM_CHANNELS_FAMILY_8000,
  576. GFP_KERNEL);
  577. if (!data)
  578. return NULL;
  579. data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw);
  580. radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw, phy_sku);
  581. iwl_set_radio_cfg(cfg, data, radio_cfg);
  582. if (data->valid_tx_ant)
  583. tx_chains &= data->valid_tx_ant;
  584. if (data->valid_rx_ant)
  585. rx_chains &= data->valid_rx_ant;
  586. sku = iwl_get_sku(cfg, nvm_sw, phy_sku);
  587. data->sku_cap_band_24GHz_enable = sku & NVM_SKU_CAP_BAND_24GHZ;
  588. data->sku_cap_band_52GHz_enable = sku & NVM_SKU_CAP_BAND_52GHZ;
  589. data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE;
  590. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  591. data->sku_cap_11n_enable = false;
  592. data->sku_cap_11ac_enable = data->sku_cap_11n_enable &&
  593. (sku & NVM_SKU_CAP_11AC_ENABLE);
  594. data->sku_cap_mimo_disabled = sku & NVM_SKU_CAP_MIMO_DISABLE;
  595. data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
  596. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  597. /* Checking for required sections */
  598. if (!nvm_calib) {
  599. IWL_ERR(trans,
  600. "Can't parse empty Calib NVM sections\n");
  601. kfree(data);
  602. return NULL;
  603. }
  604. /* in family 8000 Xtal calibration values moved to OTP */
  605. data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
  606. data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
  607. lar_enabled = true;
  608. ch_section = nvm_sw;
  609. } else {
  610. u16 lar_offset = data->nvm_version < 0xE39 ?
  611. NVM_LAR_OFFSET_FAMILY_8000_OLD :
  612. NVM_LAR_OFFSET_FAMILY_8000;
  613. lar_config = le16_to_cpup(regulatory + lar_offset);
  614. data->lar_enabled = !!(lar_config &
  615. NVM_LAR_ENABLED_FAMILY_8000);
  616. lar_enabled = data->lar_enabled;
  617. ch_section = regulatory;
  618. }
  619. /* If no valid mac address was found - bail out */
  620. if (iwl_set_hw_address(trans, cfg, data, nvm_hw, mac_override)) {
  621. kfree(data);
  622. return NULL;
  623. }
  624. iwl_init_sbands(dev, cfg, data, ch_section, tx_chains, rx_chains,
  625. lar_fw_supported && lar_enabled);
  626. data->calib_version = 255;
  627. return data;
  628. }
  629. IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);
  630. static u32 iwl_nvm_get_regdom_bw_flags(const u8 *nvm_chan,
  631. int ch_idx, u16 nvm_flags,
  632. const struct iwl_cfg *cfg)
  633. {
  634. u32 flags = NL80211_RRF_NO_HT40;
  635. u32 last_5ghz_ht = LAST_5GHZ_HT;
  636. if (cfg->device_family == IWL_DEVICE_FAMILY_8000)
  637. last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
  638. if (ch_idx < NUM_2GHZ_CHANNELS &&
  639. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  640. if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS)
  641. flags &= ~NL80211_RRF_NO_HT40PLUS;
  642. if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS)
  643. flags &= ~NL80211_RRF_NO_HT40MINUS;
  644. } else if (nvm_chan[ch_idx] <= last_5ghz_ht &&
  645. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  646. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  647. flags &= ~NL80211_RRF_NO_HT40PLUS;
  648. else
  649. flags &= ~NL80211_RRF_NO_HT40MINUS;
  650. }
  651. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  652. flags |= NL80211_RRF_NO_80MHZ;
  653. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  654. flags |= NL80211_RRF_NO_160MHZ;
  655. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  656. flags |= NL80211_RRF_NO_IR;
  657. if (nvm_flags & NVM_CHANNEL_RADAR)
  658. flags |= NL80211_RRF_DFS;
  659. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  660. flags |= NL80211_RRF_NO_OUTDOOR;
  661. /* Set the GO concurrent flag only in case that NO_IR is set.
  662. * Otherwise it is meaningless
  663. */
  664. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  665. (flags & NL80211_RRF_NO_IR))
  666. flags |= NL80211_RRF_GO_CONCURRENT;
  667. return flags;
  668. }
  669. struct ieee80211_regdomain *
  670. iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
  671. int num_of_ch, __le32 *channels, u16 fw_mcc)
  672. {
  673. int ch_idx;
  674. u16 ch_flags, prev_ch_flags = 0;
  675. const u8 *nvm_chan = cfg->device_family == IWL_DEVICE_FAMILY_8000 ?
  676. iwl_nvm_channels_family_8000 : iwl_nvm_channels;
  677. struct ieee80211_regdomain *regd;
  678. int size_of_regd;
  679. struct ieee80211_reg_rule *rule;
  680. enum ieee80211_band band;
  681. int center_freq, prev_center_freq = 0;
  682. int valid_rules = 0;
  683. bool new_rule;
  684. int max_num_ch = cfg->device_family == IWL_DEVICE_FAMILY_8000 ?
  685. IWL_NUM_CHANNELS_FAMILY_8000 : IWL_NUM_CHANNELS;
  686. if (WARN_ON_ONCE(num_of_ch > NL80211_MAX_SUPP_REG_RULES))
  687. return ERR_PTR(-EINVAL);
  688. if (WARN_ON(num_of_ch > max_num_ch))
  689. num_of_ch = max_num_ch;
  690. IWL_DEBUG_DEV(dev, IWL_DL_LAR, "building regdom for %d channels\n",
  691. num_of_ch);
  692. /* build a regdomain rule for every valid channel */
  693. size_of_regd =
  694. sizeof(struct ieee80211_regdomain) +
  695. num_of_ch * sizeof(struct ieee80211_reg_rule);
  696. regd = kzalloc(size_of_regd, GFP_KERNEL);
  697. if (!regd)
  698. return ERR_PTR(-ENOMEM);
  699. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  700. ch_flags = (u16)__le32_to_cpup(channels + ch_idx);
  701. band = (ch_idx < NUM_2GHZ_CHANNELS) ?
  702. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  703. center_freq = ieee80211_channel_to_frequency(nvm_chan[ch_idx],
  704. band);
  705. new_rule = false;
  706. if (!(ch_flags & NVM_CHANNEL_VALID)) {
  707. IWL_DEBUG_DEV(dev, IWL_DL_LAR,
  708. "Ch. %d Flags %x [%sGHz] - No traffic\n",
  709. nvm_chan[ch_idx],
  710. ch_flags,
  711. (ch_idx >= NUM_2GHZ_CHANNELS) ?
  712. "5.2" : "2.4");
  713. continue;
  714. }
  715. /* we can't continue the same rule */
  716. if (ch_idx == 0 || prev_ch_flags != ch_flags ||
  717. center_freq - prev_center_freq > 20) {
  718. valid_rules++;
  719. new_rule = true;
  720. }
  721. rule = &regd->reg_rules[valid_rules - 1];
  722. if (new_rule)
  723. rule->freq_range.start_freq_khz =
  724. MHZ_TO_KHZ(center_freq - 10);
  725. rule->freq_range.end_freq_khz = MHZ_TO_KHZ(center_freq + 10);
  726. /* this doesn't matter - not used by FW */
  727. rule->power_rule.max_antenna_gain = DBI_TO_MBI(6);
  728. rule->power_rule.max_eirp =
  729. DBM_TO_MBM(IWL_DEFAULT_MAX_TX_POWER);
  730. rule->flags = iwl_nvm_get_regdom_bw_flags(nvm_chan, ch_idx,
  731. ch_flags, cfg);
  732. /* rely on auto-calculation to merge BW of contiguous chans */
  733. rule->flags |= NL80211_RRF_AUTO_BW;
  734. rule->freq_range.max_bandwidth_khz = 0;
  735. prev_ch_flags = ch_flags;
  736. prev_center_freq = center_freq;
  737. IWL_DEBUG_DEV(dev, IWL_DL_LAR,
  738. "Ch. %d [%sGHz] %s%s%s%s%s%s%s%s%s(0x%02x): Ad-Hoc %ssupported\n",
  739. center_freq,
  740. band == IEEE80211_BAND_5GHZ ? "5.2" : "2.4",
  741. CHECK_AND_PRINT_I(VALID),
  742. CHECK_AND_PRINT_I(ACTIVE),
  743. CHECK_AND_PRINT_I(RADAR),
  744. CHECK_AND_PRINT_I(WIDE),
  745. CHECK_AND_PRINT_I(40MHZ),
  746. CHECK_AND_PRINT_I(80MHZ),
  747. CHECK_AND_PRINT_I(160MHZ),
  748. CHECK_AND_PRINT_I(INDOOR_ONLY),
  749. CHECK_AND_PRINT_I(GO_CONCURRENT),
  750. ch_flags,
  751. ((ch_flags & NVM_CHANNEL_ACTIVE) &&
  752. !(ch_flags & NVM_CHANNEL_RADAR))
  753. ? "" : "not ");
  754. }
  755. regd->n_reg_rules = valid_rules;
  756. /* set alpha2 from FW. */
  757. regd->alpha2[0] = fw_mcc >> 8;
  758. regd->alpha2[1] = fw_mcc & 0xff;
  759. return regd;
  760. }
  761. IWL_EXPORT_SYMBOL(iwl_parse_nvm_mcc_info);