iwl-nvm-parse.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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_INDOOR_ONLY: only indoor use is allowed
  164. * @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
  165. * on same channel on 2.4 or same UNII band on 5.2
  166. * @NVM_CHANNEL_WIDE: 20 MHz channel okay (?)
  167. * @NVM_CHANNEL_40MHZ: 40 MHz channel okay (?)
  168. * @NVM_CHANNEL_80MHZ: 80 MHz channel okay (?)
  169. * @NVM_CHANNEL_160MHZ: 160 MHz channel okay (?)
  170. */
  171. enum iwl_nvm_channel_flags {
  172. NVM_CHANNEL_VALID = BIT(0),
  173. NVM_CHANNEL_IBSS = BIT(1),
  174. NVM_CHANNEL_ACTIVE = BIT(3),
  175. NVM_CHANNEL_RADAR = BIT(4),
  176. NVM_CHANNEL_INDOOR_ONLY = BIT(5),
  177. NVM_CHANNEL_GO_CONCURRENT = BIT(6),
  178. NVM_CHANNEL_WIDE = BIT(8),
  179. NVM_CHANNEL_40MHZ = BIT(9),
  180. NVM_CHANNEL_80MHZ = BIT(10),
  181. NVM_CHANNEL_160MHZ = BIT(11),
  182. };
  183. #define CHECK_AND_PRINT_I(x) \
  184. ((ch_flags & NVM_CHANNEL_##x) ? # x " " : "")
  185. static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
  186. struct iwl_nvm_data *data,
  187. const __le16 * const nvm_ch_flags)
  188. {
  189. int ch_idx;
  190. int n_channels = 0;
  191. struct ieee80211_channel *channel;
  192. u16 ch_flags;
  193. bool is_5ghz;
  194. int num_of_ch, num_2ghz_channels;
  195. const u8 *nvm_chan;
  196. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  197. num_of_ch = IWL_NUM_CHANNELS;
  198. nvm_chan = &iwl_nvm_channels[0];
  199. num_2ghz_channels = NUM_2GHZ_CHANNELS;
  200. } else {
  201. num_of_ch = IWL_NUM_CHANNELS_FAMILY_8000;
  202. nvm_chan = &iwl_nvm_channels_family_8000[0];
  203. num_2ghz_channels = NUM_2GHZ_CHANNELS_FAMILY_8000;
  204. }
  205. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  206. ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
  207. if (ch_idx >= num_2ghz_channels &&
  208. !data->sku_cap_band_52GHz_enable)
  209. ch_flags &= ~NVM_CHANNEL_VALID;
  210. if (!(ch_flags & NVM_CHANNEL_VALID)) {
  211. IWL_DEBUG_EEPROM(dev,
  212. "Ch. %d Flags %x [%sGHz] - No traffic\n",
  213. nvm_chan[ch_idx],
  214. ch_flags,
  215. (ch_idx >= num_2ghz_channels) ?
  216. "5.2" : "2.4");
  217. continue;
  218. }
  219. channel = &data->channels[n_channels];
  220. n_channels++;
  221. channel->hw_value = nvm_chan[ch_idx];
  222. channel->band = (ch_idx < num_2ghz_channels) ?
  223. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  224. channel->center_freq =
  225. ieee80211_channel_to_frequency(
  226. channel->hw_value, channel->band);
  227. /* TODO: Need to be dependent to the NVM */
  228. channel->flags = IEEE80211_CHAN_NO_HT40;
  229. if (ch_idx < num_2ghz_channels &&
  230. (ch_flags & NVM_CHANNEL_40MHZ)) {
  231. if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS)
  232. channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  233. if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS)
  234. channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  235. } else if (nvm_chan[ch_idx] <= LAST_5GHZ_HT &&
  236. (ch_flags & NVM_CHANNEL_40MHZ)) {
  237. if ((ch_idx - num_2ghz_channels) % 2 == 0)
  238. channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  239. else
  240. channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  241. }
  242. if (!(ch_flags & NVM_CHANNEL_80MHZ))
  243. channel->flags |= IEEE80211_CHAN_NO_80MHZ;
  244. if (!(ch_flags & NVM_CHANNEL_160MHZ))
  245. channel->flags |= IEEE80211_CHAN_NO_160MHZ;
  246. if (!(ch_flags & NVM_CHANNEL_IBSS))
  247. channel->flags |= IEEE80211_CHAN_NO_IR;
  248. if (!(ch_flags & NVM_CHANNEL_ACTIVE))
  249. channel->flags |= IEEE80211_CHAN_NO_IR;
  250. if (ch_flags & NVM_CHANNEL_RADAR)
  251. channel->flags |= IEEE80211_CHAN_RADAR;
  252. if (ch_flags & NVM_CHANNEL_INDOOR_ONLY)
  253. channel->flags |= IEEE80211_CHAN_INDOOR_ONLY;
  254. /* Set the GO concurrent flag only in case that NO_IR is set.
  255. * Otherwise it is meaningless
  256. */
  257. if ((ch_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  258. (channel->flags & IEEE80211_CHAN_NO_IR))
  259. channel->flags |= IEEE80211_CHAN_GO_CONCURRENT;
  260. /* Initialize regulatory-based run-time data */
  261. /*
  262. * Default value - highest tx power value. max_power
  263. * is not used in mvm, and is used for backwards compatibility
  264. */
  265. channel->max_power = DEFAULT_MAX_TX_POWER;
  266. is_5ghz = channel->band == IEEE80211_BAND_5GHZ;
  267. IWL_DEBUG_EEPROM(dev,
  268. "Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
  269. channel->hw_value,
  270. is_5ghz ? "5.2" : "2.4",
  271. CHECK_AND_PRINT_I(VALID),
  272. CHECK_AND_PRINT_I(IBSS),
  273. CHECK_AND_PRINT_I(ACTIVE),
  274. CHECK_AND_PRINT_I(RADAR),
  275. CHECK_AND_PRINT_I(WIDE),
  276. CHECK_AND_PRINT_I(INDOOR_ONLY),
  277. CHECK_AND_PRINT_I(GO_CONCURRENT),
  278. ch_flags,
  279. channel->max_power,
  280. ((ch_flags & NVM_CHANNEL_IBSS) &&
  281. !(ch_flags & NVM_CHANNEL_RADAR))
  282. ? "" : "not ");
  283. }
  284. return n_channels;
  285. }
  286. static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
  287. struct iwl_nvm_data *data,
  288. struct ieee80211_sta_vht_cap *vht_cap,
  289. u8 tx_chains, u8 rx_chains)
  290. {
  291. int num_rx_ants = num_of_ant(rx_chains);
  292. int num_tx_ants = num_of_ant(tx_chains);
  293. vht_cap->vht_supported = true;
  294. vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 |
  295. IEEE80211_VHT_CAP_RXSTBC_1 |
  296. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  297. 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
  298. 7 << IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  299. if (num_tx_ants > 1)
  300. vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
  301. else
  302. vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  303. if (iwlwifi_mod_params.amsdu_size_8K)
  304. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
  305. vht_cap->vht_mcs.rx_mcs_map =
  306. cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  307. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  308. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  309. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  310. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  311. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  312. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  313. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
  314. if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) {
  315. vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
  316. /* this works because NOT_SUPPORTED == 3 */
  317. vht_cap->vht_mcs.rx_mcs_map |=
  318. cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2);
  319. }
  320. vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
  321. }
  322. static void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
  323. struct iwl_nvm_data *data,
  324. const __le16 *ch_section, bool enable_vht,
  325. u8 tx_chains, u8 rx_chains)
  326. {
  327. int n_channels;
  328. int n_used = 0;
  329. struct ieee80211_supported_band *sband;
  330. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  331. n_channels = iwl_init_channel_map(
  332. dev, cfg, data,
  333. &ch_section[NVM_CHANNELS]);
  334. else
  335. n_channels = iwl_init_channel_map(
  336. dev, cfg, data,
  337. &ch_section[NVM_CHANNELS_FAMILY_8000]);
  338. sband = &data->bands[IEEE80211_BAND_2GHZ];
  339. sband->band = IEEE80211_BAND_2GHZ;
  340. sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
  341. sband->n_bitrates = N_RATES_24;
  342. n_used += iwl_init_sband_channels(data, sband, n_channels,
  343. IEEE80211_BAND_2GHZ);
  344. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_2GHZ,
  345. tx_chains, rx_chains);
  346. sband = &data->bands[IEEE80211_BAND_5GHZ];
  347. sband->band = IEEE80211_BAND_5GHZ;
  348. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  349. sband->n_bitrates = N_RATES_52;
  350. n_used += iwl_init_sband_channels(data, sband, n_channels,
  351. IEEE80211_BAND_5GHZ);
  352. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_5GHZ,
  353. tx_chains, rx_chains);
  354. if (enable_vht)
  355. iwl_init_vht_hw_capab(cfg, data, &sband->vht_cap,
  356. tx_chains, rx_chains);
  357. if (n_channels != n_used)
  358. IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n",
  359. n_used, n_channels);
  360. }
  361. static int iwl_get_sku(const struct iwl_cfg *cfg,
  362. const __le16 *nvm_sw)
  363. {
  364. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  365. return le16_to_cpup(nvm_sw + SKU);
  366. else
  367. return le32_to_cpup((__le32 *)(nvm_sw + SKU_FAMILY_8000));
  368. }
  369. static int iwl_get_nvm_version(const struct iwl_cfg *cfg,
  370. const __le16 *nvm_sw)
  371. {
  372. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  373. return le16_to_cpup(nvm_sw + NVM_VERSION);
  374. else
  375. return le32_to_cpup((__le32 *)(nvm_sw +
  376. NVM_VERSION_FAMILY_8000));
  377. }
  378. static int iwl_get_radio_cfg(const struct iwl_cfg *cfg,
  379. const __le16 *nvm_sw)
  380. {
  381. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  382. return le16_to_cpup(nvm_sw + RADIO_CFG);
  383. else
  384. return le32_to_cpup((__le32 *)(nvm_sw + RADIO_CFG_FAMILY_8000));
  385. }
  386. #define N_HW_ADDRS_MASK_FAMILY_8000 0xF
  387. static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg,
  388. const __le16 *nvm_sw)
  389. {
  390. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  391. return le16_to_cpup(nvm_sw + N_HW_ADDRS);
  392. else
  393. return le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000))
  394. & N_HW_ADDRS_MASK_FAMILY_8000;
  395. }
  396. static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
  397. struct iwl_nvm_data *data,
  398. u32 radio_cfg)
  399. {
  400. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  401. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg);
  402. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg);
  403. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg);
  404. data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg);
  405. return;
  406. }
  407. /* set the radio configuration for family 8000 */
  408. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK_FAMILY_8000(radio_cfg);
  409. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK_FAMILY_8000(radio_cfg);
  410. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK_FAMILY_8000(radio_cfg);
  411. data->radio_cfg_pnum = NVM_RF_CFG_FLAVOR_MSK_FAMILY_8000(radio_cfg);
  412. }
  413. static void iwl_set_hw_address(const struct iwl_cfg *cfg,
  414. struct iwl_nvm_data *data,
  415. const __le16 *nvm_sec)
  416. {
  417. const u8 *hw_addr = (const u8 *)(nvm_sec + HW_ADDR);
  418. /* The byte order is little endian 16 bit, meaning 214365 */
  419. data->hw_addr[0] = hw_addr[1];
  420. data->hw_addr[1] = hw_addr[0];
  421. data->hw_addr[2] = hw_addr[3];
  422. data->hw_addr[3] = hw_addr[2];
  423. data->hw_addr[4] = hw_addr[5];
  424. data->hw_addr[5] = hw_addr[4];
  425. }
  426. static void iwl_set_hw_address_family_8000(struct device *dev,
  427. const struct iwl_cfg *cfg,
  428. struct iwl_nvm_data *data,
  429. const __le16 *mac_override,
  430. const __le16 *nvm_hw)
  431. {
  432. const u8 *hw_addr;
  433. if (mac_override) {
  434. hw_addr = (const u8 *)(mac_override +
  435. MAC_ADDRESS_OVERRIDE_FAMILY_8000);
  436. /* The byte order is little endian 16 bit, meaning 214365 */
  437. data->hw_addr[0] = hw_addr[1];
  438. data->hw_addr[1] = hw_addr[0];
  439. data->hw_addr[2] = hw_addr[3];
  440. data->hw_addr[3] = hw_addr[2];
  441. data->hw_addr[4] = hw_addr[5];
  442. data->hw_addr[5] = hw_addr[4];
  443. if (is_valid_ether_addr(data->hw_addr))
  444. return;
  445. IWL_ERR_DEV(dev,
  446. "mac address from nvm override section is not valid\n");
  447. }
  448. if (nvm_hw) {
  449. /* take the MAC address from the OTP */
  450. hw_addr = (const u8 *)(nvm_hw + HW_ADDR0_FAMILY_8000);
  451. data->hw_addr[0] = hw_addr[3];
  452. data->hw_addr[1] = hw_addr[2];
  453. data->hw_addr[2] = hw_addr[1];
  454. data->hw_addr[3] = hw_addr[0];
  455. hw_addr = (const u8 *)(nvm_hw + HW_ADDR1_FAMILY_8000);
  456. data->hw_addr[4] = hw_addr[1];
  457. data->hw_addr[5] = hw_addr[0];
  458. return;
  459. }
  460. IWL_ERR_DEV(dev, "mac address is not found\n");
  461. }
  462. struct iwl_nvm_data *
  463. iwl_parse_nvm_data(struct device *dev, const struct iwl_cfg *cfg,
  464. const __le16 *nvm_hw, const __le16 *nvm_sw,
  465. const __le16 *nvm_calib, const __le16 *regulatory,
  466. const __le16 *mac_override, u8 tx_chains, u8 rx_chains)
  467. {
  468. struct iwl_nvm_data *data;
  469. u32 sku;
  470. u32 radio_cfg;
  471. if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
  472. data = kzalloc(sizeof(*data) +
  473. sizeof(struct ieee80211_channel) *
  474. IWL_NUM_CHANNELS,
  475. GFP_KERNEL);
  476. else
  477. data = kzalloc(sizeof(*data) +
  478. sizeof(struct ieee80211_channel) *
  479. IWL_NUM_CHANNELS_FAMILY_8000,
  480. GFP_KERNEL);
  481. if (!data)
  482. return NULL;
  483. data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw);
  484. radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw);
  485. iwl_set_radio_cfg(cfg, data, radio_cfg);
  486. sku = iwl_get_sku(cfg, nvm_sw);
  487. data->sku_cap_band_24GHz_enable = sku & NVM_SKU_CAP_BAND_24GHZ;
  488. data->sku_cap_band_52GHz_enable = sku & NVM_SKU_CAP_BAND_52GHZ;
  489. data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE;
  490. data->sku_cap_11ac_enable = sku & NVM_SKU_CAP_11AC_ENABLE;
  491. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  492. data->sku_cap_11n_enable = false;
  493. data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
  494. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  495. /* Checking for required sections */
  496. if (!nvm_calib) {
  497. IWL_ERR_DEV(dev,
  498. "Can't parse empty Calib NVM sections\n");
  499. kfree(data);
  500. return NULL;
  501. }
  502. /* in family 8000 Xtal calibration values moved to OTP */
  503. data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
  504. data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
  505. }
  506. if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
  507. iwl_set_hw_address(cfg, data, nvm_hw);
  508. iwl_init_sbands(dev, cfg, data, nvm_sw,
  509. sku & NVM_SKU_CAP_11AC_ENABLE, tx_chains,
  510. rx_chains);
  511. } else {
  512. /* MAC address in family 8000 */
  513. iwl_set_hw_address_family_8000(dev, cfg, data, mac_override,
  514. nvm_hw);
  515. iwl_init_sbands(dev, cfg, data, regulatory,
  516. sku & NVM_SKU_CAP_11AC_ENABLE, tx_chains,
  517. rx_chains);
  518. }
  519. data->calib_version = 255;
  520. return data;
  521. }
  522. IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);