iwl-nvm-parse.c 30 KB

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