iwl-nvm-parse.c 30 KB

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