iwl-nvm-parse.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called COPYING.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *****************************************************************************/
  62. #include <linux/types.h>
  63. #include <linux/slab.h>
  64. #include <linux/export.h>
  65. #include <linux/etherdevice.h>
  66. #include "iwl-drv.h"
  67. #include "iwl-modparams.h"
  68. #include "iwl-nvm-parse.h"
  69. /* NVM offsets (in words) definitions */
  70. enum wkp_nvm_offsets {
  71. /* NVM HW-Section offset (in words) definitions */
  72. HW_ADDR = 0x15,
  73. /* NVM SW-Section offset (in words) definitions */
  74. NVM_SW_SECTION = 0x1C0,
  75. NVM_VERSION = 0,
  76. RADIO_CFG = 1,
  77. SKU = 2,
  78. N_HW_ADDRS = 3,
  79. NVM_CHANNELS = 0x1E0 - NVM_SW_SECTION,
  80. /* NVM calibration section offset (in words) definitions */
  81. NVM_CALIB_SECTION = 0x2B8,
  82. XTAL_CALIB = 0x316 - NVM_CALIB_SECTION
  83. };
  84. enum family_8000_nvm_offsets {
  85. /* NVM HW-Section offset (in words) definitions */
  86. HW_ADDR0_FAMILY_8000 = 0x12,
  87. HW_ADDR1_FAMILY_8000 = 0x16,
  88. MAC_ADDRESS_OVERRIDE_FAMILY_8000 = 1,
  89. /* NVM SW-Section offset (in words) definitions */
  90. NVM_SW_SECTION_FAMILY_8000 = 0x1C0,
  91. NVM_VERSION_FAMILY_8000 = 0,
  92. RADIO_CFG_FAMILY_8000 = 2,
  93. SKU_FAMILY_8000 = 4,
  94. N_HW_ADDRS_FAMILY_8000 = 5,
  95. /* NVM REGULATORY -Section offset (in words) definitions */
  96. NVM_CHANNELS_FAMILY_8000 = 0,
  97. /* NVM calibration section offset (in words) definitions */
  98. NVM_CALIB_SECTION_FAMILY_8000 = 0x2B8,
  99. XTAL_CALIB_FAMILY_8000 = 0x316 - NVM_CALIB_SECTION_FAMILY_8000
  100. };
  101. /* SKU Capabilities (actual values from NVM definition) */
  102. enum nvm_sku_bits {
  103. NVM_SKU_CAP_BAND_24GHZ = BIT(0),
  104. NVM_SKU_CAP_BAND_52GHZ = BIT(1),
  105. NVM_SKU_CAP_11N_ENABLE = BIT(2),
  106. NVM_SKU_CAP_11AC_ENABLE = BIT(3),
  107. };
  108. /*
  109. * These are the channel numbers in the order that they are stored in the NVM
  110. */
  111. static const u8 iwl_nvm_channels[] = {
  112. /* 2.4 GHz */
  113. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  114. /* 5 GHz */
  115. 36, 40, 44 , 48, 52, 56, 60, 64,
  116. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  117. 149, 153, 157, 161, 165
  118. };
  119. static const u8 iwl_nvm_channels_family_8000[] = {
  120. /* 2.4 GHz */
  121. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  122. /* 5 GHz */
  123. 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92,
  124. 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  125. 149, 153, 157, 161, 165, 169, 173, 177, 181
  126. };
  127. #define IWL_NUM_CHANNELS ARRAY_SIZE(iwl_nvm_channels)
  128. #define IWL_NUM_CHANNELS_FAMILY_8000 ARRAY_SIZE(iwl_nvm_channels_family_8000)
  129. #define NUM_2GHZ_CHANNELS 14
  130. #define NUM_2GHZ_CHANNELS_FAMILY_8000 14
  131. #define FIRST_2GHZ_HT_MINUS 5
  132. #define LAST_2GHZ_HT_PLUS 9
  133. #define LAST_5GHZ_HT 161
  134. #define DEFAULT_MAX_TX_POWER 16
  135. /* rate data (static) */
  136. static struct ieee80211_rate iwl_cfg80211_rates[] = {
  137. { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
  138. { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
  139. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  140. { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
  141. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  142. { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
  143. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  144. { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
  145. { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
  146. { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
  147. { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
  148. { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
  149. { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
  150. { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
  151. { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
  152. };
  153. #define RATES_24_OFFS 0
  154. #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
  155. #define RATES_52_OFFS 4
  156. #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
  157. /**
  158. * enum iwl_nvm_channel_flags - channel flags in NVM
  159. * @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
  160. * @NVM_CHANNEL_IBSS: usable as an IBSS channel
  161. * @NVM_CHANNEL_ACTIVE: active scanning allowed
  162. * @NVM_CHANNEL_RADAR: radar detection required
  163. * @NVM_CHANNEL_DFS: dynamic freq selection candidate
  164. * @NVM_CHANNEL_WIDE: 20 MHz channel okay (?)
  165. * @NVM_CHANNEL_40MHZ: 40 MHz channel okay (?)
  166. * @NVM_CHANNEL_80MHZ: 80 MHz channel okay (?)
  167. * @NVM_CHANNEL_160MHZ: 160 MHz channel okay (?)
  168. */
  169. enum iwl_nvm_channel_flags {
  170. NVM_CHANNEL_VALID = BIT(0),
  171. NVM_CHANNEL_IBSS = BIT(1),
  172. NVM_CHANNEL_ACTIVE = BIT(3),
  173. NVM_CHANNEL_RADAR = BIT(4),
  174. NVM_CHANNEL_DFS = BIT(7),
  175. NVM_CHANNEL_WIDE = BIT(8),
  176. NVM_CHANNEL_40MHZ = BIT(9),
  177. NVM_CHANNEL_80MHZ = BIT(10),
  178. NVM_CHANNEL_160MHZ = BIT(11),
  179. };
  180. #define CHECK_AND_PRINT_I(x) \
  181. ((ch_flags & NVM_CHANNEL_##x) ? # x " " : "")
  182. static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
  183. struct iwl_nvm_data *data,
  184. const __le16 * const nvm_ch_flags)
  185. {
  186. int ch_idx;
  187. int n_channels = 0;
  188. struct ieee80211_channel *channel;
  189. u16 ch_flags;
  190. bool is_5ghz;
  191. int num_of_ch, num_2ghz_channels;
  192. const u8 *nvm_chan;
  193. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  194. num_of_ch = IWL_NUM_CHANNELS;
  195. nvm_chan = &iwl_nvm_channels[0];
  196. num_2ghz_channels = NUM_2GHZ_CHANNELS;
  197. } else {
  198. num_of_ch = IWL_NUM_CHANNELS_FAMILY_8000;
  199. nvm_chan = &iwl_nvm_channels_family_8000[0];
  200. num_2ghz_channels = NUM_2GHZ_CHANNELS_FAMILY_8000;
  201. }
  202. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  203. ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
  204. if (ch_idx >= num_2ghz_channels &&
  205. !data->sku_cap_band_52GHz_enable)
  206. ch_flags &= ~NVM_CHANNEL_VALID;
  207. if (!(ch_flags & NVM_CHANNEL_VALID)) {
  208. IWL_DEBUG_EEPROM(dev,
  209. "Ch. %d Flags %x [%sGHz] - No traffic\n",
  210. nvm_chan[ch_idx],
  211. ch_flags,
  212. (ch_idx >= num_2ghz_channels) ?
  213. "5.2" : "2.4");
  214. continue;
  215. }
  216. channel = &data->channels[n_channels];
  217. n_channels++;
  218. channel->hw_value = nvm_chan[ch_idx];
  219. channel->band = (ch_idx < num_2ghz_channels) ?
  220. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  221. channel->center_freq =
  222. ieee80211_channel_to_frequency(
  223. channel->hw_value, channel->band);
  224. /* TODO: Need to be dependent to the NVM */
  225. channel->flags = IEEE80211_CHAN_NO_HT40;
  226. if (ch_idx < num_2ghz_channels &&
  227. (ch_flags & NVM_CHANNEL_40MHZ)) {
  228. if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS)
  229. channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  230. if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS)
  231. channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  232. } else if (nvm_chan[ch_idx] <= LAST_5GHZ_HT &&
  233. (ch_flags & NVM_CHANNEL_40MHZ)) {
  234. if ((ch_idx - num_2ghz_channels) % 2 == 0)
  235. channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  236. else
  237. channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  238. }
  239. if (!(ch_flags & NVM_CHANNEL_80MHZ))
  240. channel->flags |= IEEE80211_CHAN_NO_80MHZ;
  241. if (!(ch_flags & NVM_CHANNEL_160MHZ))
  242. channel->flags |= IEEE80211_CHAN_NO_160MHZ;
  243. if (!(ch_flags & NVM_CHANNEL_IBSS))
  244. channel->flags |= IEEE80211_CHAN_NO_IR;
  245. if (!(ch_flags & NVM_CHANNEL_ACTIVE))
  246. channel->flags |= IEEE80211_CHAN_NO_IR;
  247. if (ch_flags & NVM_CHANNEL_RADAR)
  248. channel->flags |= IEEE80211_CHAN_RADAR;
  249. /* Initialize regulatory-based run-time data */
  250. /*
  251. * Default value - highest tx power value. max_power
  252. * is not used in mvm, and is used for backwards compatibility
  253. */
  254. channel->max_power = DEFAULT_MAX_TX_POWER;
  255. is_5ghz = channel->band == IEEE80211_BAND_5GHZ;
  256. IWL_DEBUG_EEPROM(dev,
  257. "Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
  258. channel->hw_value,
  259. is_5ghz ? "5.2" : "2.4",
  260. CHECK_AND_PRINT_I(VALID),
  261. CHECK_AND_PRINT_I(IBSS),
  262. CHECK_AND_PRINT_I(ACTIVE),
  263. CHECK_AND_PRINT_I(RADAR),
  264. CHECK_AND_PRINT_I(WIDE),
  265. CHECK_AND_PRINT_I(DFS),
  266. ch_flags,
  267. channel->max_power,
  268. ((ch_flags & NVM_CHANNEL_IBSS) &&
  269. !(ch_flags & NVM_CHANNEL_RADAR))
  270. ? "" : "not ");
  271. }
  272. return n_channels;
  273. }
  274. static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
  275. struct iwl_nvm_data *data,
  276. struct ieee80211_sta_vht_cap *vht_cap,
  277. u8 tx_chains, u8 rx_chains)
  278. {
  279. int num_rx_ants = num_of_ant(rx_chains);
  280. int num_tx_ants = num_of_ant(tx_chains);
  281. vht_cap->vht_supported = true;
  282. vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 |
  283. IEEE80211_VHT_CAP_RXSTBC_1 |
  284. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  285. 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
  286. 7 << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  287. if (num_tx_ants > 1)
  288. vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
  289. else
  290. vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  291. if (iwlwifi_mod_params.amsdu_size_8K)
  292. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
  293. vht_cap->vht_mcs.rx_mcs_map =
  294. cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  295. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  296. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  297. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  298. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  299. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  300. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  301. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
  302. if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) {
  303. vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
  304. /* this works because NOT_SUPPORTED == 3 */
  305. vht_cap->vht_mcs.rx_mcs_map |=
  306. cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2);
  307. }
  308. vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
  309. }
  310. static void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
  311. struct iwl_nvm_data *data,
  312. const __le16 *ch_section, bool enable_vht,
  313. u8 tx_chains, u8 rx_chains)
  314. {
  315. int n_channels;
  316. int n_used = 0;
  317. struct ieee80211_supported_band *sband;
  318. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  319. n_channels = iwl_init_channel_map(
  320. dev, cfg, data,
  321. &ch_section[NVM_CHANNELS]);
  322. else
  323. n_channels = iwl_init_channel_map(
  324. dev, cfg, data,
  325. &ch_section[NVM_CHANNELS_FAMILY_8000]);
  326. sband = &data->bands[IEEE80211_BAND_2GHZ];
  327. sband->band = IEEE80211_BAND_2GHZ;
  328. sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
  329. sband->n_bitrates = N_RATES_24;
  330. n_used += iwl_init_sband_channels(data, sband, n_channels,
  331. IEEE80211_BAND_2GHZ);
  332. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_2GHZ,
  333. tx_chains, rx_chains);
  334. sband = &data->bands[IEEE80211_BAND_5GHZ];
  335. sband->band = IEEE80211_BAND_5GHZ;
  336. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  337. sband->n_bitrates = N_RATES_52;
  338. n_used += iwl_init_sband_channels(data, sband, n_channels,
  339. IEEE80211_BAND_5GHZ);
  340. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_5GHZ,
  341. tx_chains, rx_chains);
  342. if (enable_vht)
  343. iwl_init_vht_hw_capab(cfg, data, &sband->vht_cap,
  344. tx_chains, rx_chains);
  345. if (n_channels != n_used)
  346. IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n",
  347. n_used, n_channels);
  348. }
  349. static int iwl_get_sku(const struct iwl_cfg *cfg,
  350. const __le16 *nvm_sw)
  351. {
  352. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  353. return le16_to_cpup(nvm_sw + SKU);
  354. else
  355. return le32_to_cpup((__le32 *)(nvm_sw + SKU_FAMILY_8000));
  356. }
  357. static int iwl_get_nvm_version(const struct iwl_cfg *cfg,
  358. const __le16 *nvm_sw)
  359. {
  360. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  361. return le16_to_cpup(nvm_sw + NVM_VERSION);
  362. else
  363. return le32_to_cpup((__le32 *)(nvm_sw +
  364. NVM_VERSION_FAMILY_8000));
  365. }
  366. static int iwl_get_radio_cfg(const struct iwl_cfg *cfg,
  367. const __le16 *nvm_sw)
  368. {
  369. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  370. return le16_to_cpup(nvm_sw + RADIO_CFG);
  371. else
  372. return le32_to_cpup((__le32 *)(nvm_sw + RADIO_CFG_FAMILY_8000));
  373. }
  374. #define N_HW_ADDRS_MASK_FAMILY_8000 0xF
  375. static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg,
  376. const __le16 *nvm_sw)
  377. {
  378. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  379. return le16_to_cpup(nvm_sw + N_HW_ADDRS);
  380. else
  381. return le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000))
  382. & N_HW_ADDRS_MASK_FAMILY_8000;
  383. }
  384. static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
  385. struct iwl_nvm_data *data,
  386. u32 radio_cfg)
  387. {
  388. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  389. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg);
  390. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg);
  391. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg);
  392. data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg);
  393. return;
  394. }
  395. /* set the radio configuration for family 8000 */
  396. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK_FAMILY_8000(radio_cfg);
  397. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK_FAMILY_8000(radio_cfg);
  398. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK_FAMILY_8000(radio_cfg);
  399. data->radio_cfg_pnum = NVM_RF_CFG_FLAVOR_MSK_FAMILY_8000(radio_cfg);
  400. }
  401. static void iwl_set_hw_address(const struct iwl_cfg *cfg,
  402. struct iwl_nvm_data *data,
  403. const __le16 *nvm_sec)
  404. {
  405. const u8 *hw_addr = (const u8 *)(nvm_sec + HW_ADDR);
  406. /* The byte order is little endian 16 bit, meaning 214365 */
  407. data->hw_addr[0] = hw_addr[1];
  408. data->hw_addr[1] = hw_addr[0];
  409. data->hw_addr[2] = hw_addr[3];
  410. data->hw_addr[3] = hw_addr[2];
  411. data->hw_addr[4] = hw_addr[5];
  412. data->hw_addr[5] = hw_addr[4];
  413. }
  414. static void iwl_set_hw_address_family_8000(const struct iwl_cfg *cfg,
  415. struct iwl_nvm_data *data,
  416. const __le16 *mac_override,
  417. const __le16 *nvm_hw)
  418. {
  419. const u8 *hw_addr;
  420. if (mac_override) {
  421. hw_addr = (const u8 *)(mac_override +
  422. MAC_ADDRESS_OVERRIDE_FAMILY_8000);
  423. /* The byte order is little endian 16 bit, meaning 214365 */
  424. data->hw_addr[0] = hw_addr[1];
  425. data->hw_addr[1] = hw_addr[0];
  426. data->hw_addr[2] = hw_addr[3];
  427. data->hw_addr[3] = hw_addr[2];
  428. data->hw_addr[4] = hw_addr[5];
  429. data->hw_addr[5] = hw_addr[4];
  430. if (is_valid_ether_addr(hw_addr))
  431. return;
  432. }
  433. /* take the MAC address from the OTP */
  434. hw_addr = (const u8 *)(nvm_hw + HW_ADDR0_FAMILY_8000);
  435. data->hw_addr[0] = hw_addr[3];
  436. data->hw_addr[1] = hw_addr[2];
  437. data->hw_addr[2] = hw_addr[1];
  438. data->hw_addr[3] = hw_addr[0];
  439. hw_addr = (const u8 *)(nvm_hw + HW_ADDR1_FAMILY_8000);
  440. data->hw_addr[4] = hw_addr[1];
  441. data->hw_addr[5] = hw_addr[0];
  442. }
  443. struct iwl_nvm_data *
  444. iwl_parse_nvm_data(struct device *dev, const struct iwl_cfg *cfg,
  445. const __le16 *nvm_hw, const __le16 *nvm_sw,
  446. const __le16 *nvm_calib, const __le16 *regulatory,
  447. const __le16 *mac_override, u8 tx_chains, u8 rx_chains)
  448. {
  449. struct iwl_nvm_data *data;
  450. u32 sku;
  451. u32 radio_cfg;
  452. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  453. data = kzalloc(sizeof(*data) +
  454. sizeof(struct ieee80211_channel) *
  455. IWL_NUM_CHANNELS,
  456. GFP_KERNEL);
  457. else
  458. data = kzalloc(sizeof(*data) +
  459. sizeof(struct ieee80211_channel) *
  460. IWL_NUM_CHANNELS_FAMILY_8000,
  461. GFP_KERNEL);
  462. if (!data)
  463. return NULL;
  464. data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw);
  465. radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw);
  466. iwl_set_radio_cfg(cfg, data, radio_cfg);
  467. sku = iwl_get_sku(cfg, nvm_sw);
  468. data->sku_cap_band_24GHz_enable = sku & NVM_SKU_CAP_BAND_24GHZ;
  469. data->sku_cap_band_52GHz_enable = sku & NVM_SKU_CAP_BAND_52GHZ;
  470. data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE;
  471. data->sku_cap_11ac_enable = sku & NVM_SKU_CAP_11AC_ENABLE;
  472. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  473. data->sku_cap_11n_enable = false;
  474. data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
  475. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  476. /* Checking for required sections */
  477. if (!nvm_calib) {
  478. IWL_ERR_DEV(dev,
  479. "Can't parse empty Calib NVM sections\n");
  480. kfree(data);
  481. return NULL;
  482. }
  483. /* in family 8000 Xtal calibration values moved to OTP */
  484. data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
  485. data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
  486. }
  487. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  488. iwl_set_hw_address(cfg, data, nvm_hw);
  489. iwl_init_sbands(dev, cfg, data, nvm_sw,
  490. sku & NVM_SKU_CAP_11AC_ENABLE, tx_chains,
  491. rx_chains);
  492. } else {
  493. /* MAC address in family 8000 */
  494. iwl_set_hw_address_family_8000(cfg, data, mac_override, nvm_hw);
  495. iwl_init_sbands(dev, cfg, data, regulatory,
  496. sku & NVM_SKU_CAP_11AC_ENABLE, tx_chains,
  497. rx_chains);
  498. }
  499. data->calib_version = 255;
  500. return data;
  501. }
  502. IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);