iwl-nvm-parse.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  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. * Copyright(c) 2018 Intel Corporation
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of version 2 of the GNU General Public License as
  15. * published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  25. * USA
  26. *
  27. * The full GNU General Public License is included in this distribution
  28. * in the file called COPYING.
  29. *
  30. * Contact Information:
  31. * Intel Linux Wireless <linuxwifi@intel.com>
  32. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  33. *
  34. * BSD LICENSE
  35. *
  36. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  37. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  38. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  39. * Copyright(c) 2018 Intel Corporation
  40. * All rights reserved.
  41. *
  42. * Redistribution and use in source and binary forms, with or without
  43. * modification, are permitted provided that the following conditions
  44. * are met:
  45. *
  46. * * Redistributions of source code must retain the above copyright
  47. * notice, this list of conditions and the following disclaimer.
  48. * * Redistributions in binary form must reproduce the above copyright
  49. * notice, this list of conditions and the following disclaimer in
  50. * the documentation and/or other materials provided with the
  51. * distribution.
  52. * * Neither the name Intel Corporation nor the names of its
  53. * contributors may be used to endorse or promote products derived
  54. * from this software without specific prior written permission.
  55. *
  56. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  57. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  58. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  59. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  60. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  61. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  62. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  63. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  64. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  65. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  66. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  67. *****************************************************************************/
  68. #include <linux/types.h>
  69. #include <linux/slab.h>
  70. #include <linux/export.h>
  71. #include <linux/etherdevice.h>
  72. #include <linux/pci.h>
  73. #include <linux/firmware.h>
  74. #include "iwl-drv.h"
  75. #include "iwl-modparams.h"
  76. #include "iwl-nvm-parse.h"
  77. #include "iwl-prph.h"
  78. #include "iwl-io.h"
  79. #include "iwl-csr.h"
  80. #include "fw/acpi.h"
  81. #include "fw/api/nvm-reg.h"
  82. #include "fw/api/commands.h"
  83. #include "fw/api/cmdhdr.h"
  84. #include "fw/img.h"
  85. /* NVM offsets (in words) definitions */
  86. enum nvm_offsets {
  87. /* NVM HW-Section offset (in words) definitions */
  88. SUBSYSTEM_ID = 0x0A,
  89. HW_ADDR = 0x15,
  90. /* NVM SW-Section offset (in words) definitions */
  91. NVM_SW_SECTION = 0x1C0,
  92. NVM_VERSION = 0,
  93. RADIO_CFG = 1,
  94. SKU = 2,
  95. N_HW_ADDRS = 3,
  96. NVM_CHANNELS = 0x1E0 - NVM_SW_SECTION,
  97. /* NVM calibration section offset (in words) definitions */
  98. NVM_CALIB_SECTION = 0x2B8,
  99. XTAL_CALIB = 0x316 - NVM_CALIB_SECTION,
  100. /* NVM REGULATORY -Section offset (in words) definitions */
  101. NVM_CHANNELS_SDP = 0,
  102. };
  103. enum ext_nvm_offsets {
  104. /* NVM HW-Section offset (in words) definitions */
  105. MAC_ADDRESS_OVERRIDE_EXT_NVM = 1,
  106. /* NVM SW-Section offset (in words) definitions */
  107. NVM_VERSION_EXT_NVM = 0,
  108. RADIO_CFG_FAMILY_EXT_NVM = 0,
  109. SKU_FAMILY_8000 = 2,
  110. N_HW_ADDRS_FAMILY_8000 = 3,
  111. /* NVM REGULATORY -Section offset (in words) definitions */
  112. NVM_CHANNELS_EXTENDED = 0,
  113. NVM_LAR_OFFSET_OLD = 0x4C7,
  114. NVM_LAR_OFFSET = 0x507,
  115. NVM_LAR_ENABLED = 0x7,
  116. };
  117. /* SKU Capabilities (actual values from NVM definition) */
  118. enum nvm_sku_bits {
  119. NVM_SKU_CAP_BAND_24GHZ = BIT(0),
  120. NVM_SKU_CAP_BAND_52GHZ = BIT(1),
  121. NVM_SKU_CAP_11N_ENABLE = BIT(2),
  122. NVM_SKU_CAP_11AC_ENABLE = BIT(3),
  123. NVM_SKU_CAP_MIMO_DISABLE = BIT(5),
  124. };
  125. /*
  126. * These are the channel numbers in the order that they are stored in the NVM
  127. */
  128. static const u8 iwl_nvm_channels[] = {
  129. /* 2.4 GHz */
  130. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  131. /* 5 GHz */
  132. 36, 40, 44 , 48, 52, 56, 60, 64,
  133. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  134. 149, 153, 157, 161, 165
  135. };
  136. static const u8 iwl_ext_nvm_channels[] = {
  137. /* 2.4 GHz */
  138. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  139. /* 5 GHz */
  140. 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92,
  141. 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  142. 149, 153, 157, 161, 165, 169, 173, 177, 181
  143. };
  144. #define IWL_NVM_NUM_CHANNELS ARRAY_SIZE(iwl_nvm_channels)
  145. #define IWL_NVM_NUM_CHANNELS_EXT ARRAY_SIZE(iwl_ext_nvm_channels)
  146. #define NUM_2GHZ_CHANNELS 14
  147. #define NUM_2GHZ_CHANNELS_EXT 14
  148. #define FIRST_2GHZ_HT_MINUS 5
  149. #define LAST_2GHZ_HT_PLUS 9
  150. #define LAST_5GHZ_HT 165
  151. #define LAST_5GHZ_HT_FAMILY_8000 181
  152. #define N_HW_ADDR_MASK 0xF
  153. /* rate data (static) */
  154. static struct ieee80211_rate iwl_cfg80211_rates[] = {
  155. { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
  156. { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
  157. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  158. { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
  159. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  160. { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
  161. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  162. { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
  163. { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
  164. { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
  165. { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
  166. { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
  167. { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
  168. { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
  169. { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
  170. };
  171. #define RATES_24_OFFS 0
  172. #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
  173. #define RATES_52_OFFS 4
  174. #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
  175. /**
  176. * enum iwl_nvm_channel_flags - channel flags in NVM
  177. * @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
  178. * @NVM_CHANNEL_IBSS: usable as an IBSS channel
  179. * @NVM_CHANNEL_ACTIVE: active scanning allowed
  180. * @NVM_CHANNEL_RADAR: radar detection required
  181. * @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed
  182. * @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
  183. * on same channel on 2.4 or same UNII band on 5.2
  184. * @NVM_CHANNEL_UNIFORM: uniform spreading required
  185. * @NVM_CHANNEL_20MHZ: 20 MHz channel okay
  186. * @NVM_CHANNEL_40MHZ: 40 MHz channel okay
  187. * @NVM_CHANNEL_80MHZ: 80 MHz channel okay
  188. * @NVM_CHANNEL_160MHZ: 160 MHz channel okay
  189. * @NVM_CHANNEL_DC_HIGH: DC HIGH required/allowed (?)
  190. */
  191. enum iwl_nvm_channel_flags {
  192. NVM_CHANNEL_VALID = BIT(0),
  193. NVM_CHANNEL_IBSS = BIT(1),
  194. NVM_CHANNEL_ACTIVE = BIT(3),
  195. NVM_CHANNEL_RADAR = BIT(4),
  196. NVM_CHANNEL_INDOOR_ONLY = BIT(5),
  197. NVM_CHANNEL_GO_CONCURRENT = BIT(6),
  198. NVM_CHANNEL_UNIFORM = BIT(7),
  199. NVM_CHANNEL_20MHZ = BIT(8),
  200. NVM_CHANNEL_40MHZ = BIT(9),
  201. NVM_CHANNEL_80MHZ = BIT(10),
  202. NVM_CHANNEL_160MHZ = BIT(11),
  203. NVM_CHANNEL_DC_HIGH = BIT(12),
  204. };
  205. /**
  206. * enum iwl_reg_capa_flags - global flags applied for the whole regulatory
  207. * domain.
  208. * @REG_CAPA_BF_CCD_LOW_BAND: Beam-forming or Cyclic Delay Diversity in the
  209. * 2.4Ghz band is allowed.
  210. * @REG_CAPA_BF_CCD_HIGH_BAND: Beam-forming or Cyclic Delay Diversity in the
  211. * 5Ghz band is allowed.
  212. * @REG_CAPA_160MHZ_ALLOWED: 11ac channel with a width of 160Mhz is allowed
  213. * for this regulatory domain (valid only in 5Ghz).
  214. * @REG_CAPA_80MHZ_ALLOWED: 11ac channel with a width of 80Mhz is allowed
  215. * for this regulatory domain (valid only in 5Ghz).
  216. * @REG_CAPA_MCS_8_ALLOWED: 11ac with MCS 8 is allowed.
  217. * @REG_CAPA_MCS_9_ALLOWED: 11ac with MCS 9 is allowed.
  218. * @REG_CAPA_40MHZ_FORBIDDEN: 11n channel with a width of 40Mhz is forbidden
  219. * for this regulatory domain (valid only in 5Ghz).
  220. * @REG_CAPA_DC_HIGH_ENABLED: DC HIGH allowed.
  221. */
  222. enum iwl_reg_capa_flags {
  223. REG_CAPA_BF_CCD_LOW_BAND = BIT(0),
  224. REG_CAPA_BF_CCD_HIGH_BAND = BIT(1),
  225. REG_CAPA_160MHZ_ALLOWED = BIT(2),
  226. REG_CAPA_80MHZ_ALLOWED = BIT(3),
  227. REG_CAPA_MCS_8_ALLOWED = BIT(4),
  228. REG_CAPA_MCS_9_ALLOWED = BIT(5),
  229. REG_CAPA_40MHZ_FORBIDDEN = BIT(7),
  230. REG_CAPA_DC_HIGH_ENABLED = BIT(9),
  231. };
  232. static inline void iwl_nvm_print_channel_flags(struct device *dev, u32 level,
  233. int chan, u16 flags)
  234. {
  235. #define CHECK_AND_PRINT_I(x) \
  236. ((flags & NVM_CHANNEL_##x) ? " " #x : "")
  237. if (!(flags & NVM_CHANNEL_VALID)) {
  238. IWL_DEBUG_DEV(dev, level, "Ch. %d: 0x%x: No traffic\n",
  239. chan, flags);
  240. return;
  241. }
  242. /* Note: already can print up to 101 characters, 110 is the limit! */
  243. IWL_DEBUG_DEV(dev, level,
  244. "Ch. %d: 0x%x:%s%s%s%s%s%s%s%s%s%s%s%s\n",
  245. chan, flags,
  246. CHECK_AND_PRINT_I(VALID),
  247. CHECK_AND_PRINT_I(IBSS),
  248. CHECK_AND_PRINT_I(ACTIVE),
  249. CHECK_AND_PRINT_I(RADAR),
  250. CHECK_AND_PRINT_I(INDOOR_ONLY),
  251. CHECK_AND_PRINT_I(GO_CONCURRENT),
  252. CHECK_AND_PRINT_I(UNIFORM),
  253. CHECK_AND_PRINT_I(20MHZ),
  254. CHECK_AND_PRINT_I(40MHZ),
  255. CHECK_AND_PRINT_I(80MHZ),
  256. CHECK_AND_PRINT_I(160MHZ),
  257. CHECK_AND_PRINT_I(DC_HIGH));
  258. #undef CHECK_AND_PRINT_I
  259. }
  260. static u32 iwl_get_channel_flags(u8 ch_num, int ch_idx, bool is_5ghz,
  261. u16 nvm_flags, const struct iwl_cfg *cfg)
  262. {
  263. u32 flags = IEEE80211_CHAN_NO_HT40;
  264. u32 last_5ghz_ht = LAST_5GHZ_HT;
  265. if (cfg->nvm_type == IWL_NVM_EXT)
  266. last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
  267. if (!is_5ghz && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  268. if (ch_num <= LAST_2GHZ_HT_PLUS)
  269. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  270. if (ch_num >= FIRST_2GHZ_HT_MINUS)
  271. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  272. } else if (ch_num <= last_5ghz_ht && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  273. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  274. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  275. else
  276. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  277. }
  278. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  279. flags |= IEEE80211_CHAN_NO_80MHZ;
  280. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  281. flags |= IEEE80211_CHAN_NO_160MHZ;
  282. if (!(nvm_flags & NVM_CHANNEL_IBSS))
  283. flags |= IEEE80211_CHAN_NO_IR;
  284. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  285. flags |= IEEE80211_CHAN_NO_IR;
  286. if (nvm_flags & NVM_CHANNEL_RADAR)
  287. flags |= IEEE80211_CHAN_RADAR;
  288. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  289. flags |= IEEE80211_CHAN_INDOOR_ONLY;
  290. /* Set the GO concurrent flag only in case that NO_IR is set.
  291. * Otherwise it is meaningless
  292. */
  293. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  294. (flags & IEEE80211_CHAN_NO_IR))
  295. flags |= IEEE80211_CHAN_IR_CONCURRENT;
  296. return flags;
  297. }
  298. static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
  299. struct iwl_nvm_data *data,
  300. const __le16 * const nvm_ch_flags,
  301. u32 sbands_flags)
  302. {
  303. int ch_idx;
  304. int n_channels = 0;
  305. struct ieee80211_channel *channel;
  306. u16 ch_flags;
  307. int num_of_ch, num_2ghz_channels;
  308. const u8 *nvm_chan;
  309. if (cfg->nvm_type != IWL_NVM_EXT) {
  310. num_of_ch = IWL_NVM_NUM_CHANNELS;
  311. nvm_chan = &iwl_nvm_channels[0];
  312. num_2ghz_channels = NUM_2GHZ_CHANNELS;
  313. } else {
  314. num_of_ch = IWL_NVM_NUM_CHANNELS_EXT;
  315. nvm_chan = &iwl_ext_nvm_channels[0];
  316. num_2ghz_channels = NUM_2GHZ_CHANNELS_EXT;
  317. }
  318. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  319. bool is_5ghz = (ch_idx >= num_2ghz_channels);
  320. ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
  321. if (is_5ghz && !data->sku_cap_band_52ghz_enable)
  322. continue;
  323. /* workaround to disable wide channels in 5GHz */
  324. if ((sbands_flags & IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ) &&
  325. is_5ghz) {
  326. ch_flags &= ~(NVM_CHANNEL_40MHZ |
  327. NVM_CHANNEL_80MHZ |
  328. NVM_CHANNEL_160MHZ);
  329. }
  330. if (ch_flags & NVM_CHANNEL_160MHZ)
  331. data->vht160_supported = true;
  332. if (!(sbands_flags & IWL_NVM_SBANDS_FLAGS_LAR) &&
  333. !(ch_flags & NVM_CHANNEL_VALID)) {
  334. /*
  335. * Channels might become valid later if lar is
  336. * supported, hence we still want to add them to
  337. * the list of supported channels to cfg80211.
  338. */
  339. iwl_nvm_print_channel_flags(dev, IWL_DL_EEPROM,
  340. nvm_chan[ch_idx], ch_flags);
  341. continue;
  342. }
  343. channel = &data->channels[n_channels];
  344. n_channels++;
  345. channel->hw_value = nvm_chan[ch_idx];
  346. channel->band = is_5ghz ?
  347. NL80211_BAND_5GHZ : NL80211_BAND_2GHZ;
  348. channel->center_freq =
  349. ieee80211_channel_to_frequency(
  350. channel->hw_value, channel->band);
  351. /* Initialize regulatory-based run-time data */
  352. /*
  353. * Default value - highest tx power value. max_power
  354. * is not used in mvm, and is used for backwards compatibility
  355. */
  356. channel->max_power = IWL_DEFAULT_MAX_TX_POWER;
  357. /* don't put limitations in case we're using LAR */
  358. if (!(sbands_flags & IWL_NVM_SBANDS_FLAGS_LAR))
  359. channel->flags = iwl_get_channel_flags(nvm_chan[ch_idx],
  360. ch_idx, is_5ghz,
  361. ch_flags, cfg);
  362. else
  363. channel->flags = 0;
  364. iwl_nvm_print_channel_flags(dev, IWL_DL_EEPROM,
  365. channel->hw_value, ch_flags);
  366. IWL_DEBUG_EEPROM(dev, "Ch. %d: %ddBm\n",
  367. channel->hw_value, channel->max_power);
  368. }
  369. return n_channels;
  370. }
  371. static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
  372. struct iwl_nvm_data *data,
  373. struct ieee80211_sta_vht_cap *vht_cap,
  374. u8 tx_chains, u8 rx_chains)
  375. {
  376. int num_rx_ants = num_of_ant(rx_chains);
  377. int num_tx_ants = num_of_ant(tx_chains);
  378. unsigned int max_ampdu_exponent = (cfg->max_vht_ampdu_exponent ?:
  379. IEEE80211_VHT_MAX_AMPDU_1024K);
  380. vht_cap->vht_supported = true;
  381. vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 |
  382. IEEE80211_VHT_CAP_RXSTBC_1 |
  383. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  384. 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
  385. max_ampdu_exponent <<
  386. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  387. if (data->vht160_supported)
  388. vht_cap->cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
  389. IEEE80211_VHT_CAP_SHORT_GI_160;
  390. if (cfg->vht_mu_mimo_supported)
  391. vht_cap->cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  392. if (cfg->ht_params->ldpc)
  393. vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC;
  394. if (data->sku_cap_mimo_disabled) {
  395. num_rx_ants = 1;
  396. num_tx_ants = 1;
  397. }
  398. if (num_tx_ants > 1)
  399. vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
  400. else
  401. vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  402. switch (iwlwifi_mod_params.amsdu_size) {
  403. case IWL_AMSDU_DEF:
  404. if (cfg->mq_rx_supported)
  405. vht_cap->cap |=
  406. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  407. else
  408. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  409. break;
  410. case IWL_AMSDU_2K:
  411. if (cfg->mq_rx_supported)
  412. vht_cap->cap |=
  413. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  414. else
  415. WARN(1, "RB size of 2K is not supported by this device\n");
  416. break;
  417. case IWL_AMSDU_4K:
  418. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  419. break;
  420. case IWL_AMSDU_8K:
  421. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
  422. break;
  423. case IWL_AMSDU_12K:
  424. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  425. break;
  426. default:
  427. break;
  428. }
  429. vht_cap->vht_mcs.rx_mcs_map =
  430. cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  431. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  432. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  433. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  434. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  435. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  436. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  437. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
  438. if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) {
  439. vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
  440. /* this works because NOT_SUPPORTED == 3 */
  441. vht_cap->vht_mcs.rx_mcs_map |=
  442. cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2);
  443. }
  444. vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
  445. }
  446. static struct ieee80211_sband_iftype_data iwl_he_capa = {
  447. .types_mask = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP),
  448. .he_cap = {
  449. .has_he = true,
  450. .he_cap_elem = {
  451. .mac_cap_info[0] =
  452. IEEE80211_HE_MAC_CAP0_HTC_HE,
  453. .mac_cap_info[1] =
  454. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  455. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_QOS_8,
  456. .mac_cap_info[2] =
  457. IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP |
  458. IEEE80211_HE_MAC_CAP2_ACK_EN,
  459. .mac_cap_info[3] =
  460. IEEE80211_HE_MAC_CAP3_GRP_ADDR_MULTI_STA_BA_DL_MU |
  461. IEEE80211_HE_MAC_CAP3_MAX_A_AMPDU_LEN_EXP_VHT_2,
  462. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU,
  463. .phy_cap_info[0] =
  464. IEEE80211_HE_PHY_CAP0_DUAL_BAND |
  465. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
  466. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  467. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G,
  468. .phy_cap_info[1] =
  469. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  470. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  471. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_MAX_NSTS,
  472. .phy_cap_info[2] =
  473. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  474. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  475. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ,
  476. .phy_cap_info[3] =
  477. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK |
  478. IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 |
  479. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK |
  480. IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1,
  481. .phy_cap_info[4] =
  482. IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
  483. IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_8 |
  484. IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_8,
  485. .phy_cap_info[5] =
  486. IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_2 |
  487. IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_2,
  488. .phy_cap_info[6] =
  489. IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT,
  490. .phy_cap_info[7] =
  491. IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_AR |
  492. IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI |
  493. IEEE80211_HE_PHY_CAP7_MAX_NC_7,
  494. .phy_cap_info[8] =
  495. IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
  496. IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
  497. IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
  498. IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU,
  499. },
  500. /*
  501. * Set default Tx/Rx HE MCS NSS Support field. Indicate support
  502. * for up to 2 spatial streams and all MCS, without any special
  503. * cases
  504. */
  505. .he_mcs_nss_supp = {
  506. .rx_mcs_80 = cpu_to_le16(0xfffa),
  507. .tx_mcs_80 = cpu_to_le16(0xfffa),
  508. .rx_mcs_160 = cpu_to_le16(0xfffa),
  509. .tx_mcs_160 = cpu_to_le16(0xfffa),
  510. .rx_mcs_80p80 = cpu_to_le16(0xffff),
  511. .tx_mcs_80p80 = cpu_to_le16(0xffff),
  512. },
  513. /*
  514. * Set default PPE thresholds, with PPET16 set to 0, PPET8 set
  515. * to 7
  516. */
  517. .ppe_thres = {0x61, 0x1c, 0xc7, 0x71},
  518. },
  519. };
  520. static void iwl_init_he_hw_capab(struct ieee80211_supported_band *sband,
  521. u8 tx_chains, u8 rx_chains)
  522. {
  523. if (sband->band == NL80211_BAND_2GHZ ||
  524. sband->band == NL80211_BAND_5GHZ)
  525. sband->iftype_data = &iwl_he_capa;
  526. else
  527. return;
  528. sband->n_iftype_data = 1;
  529. /* If not 2x2, we need to indicate 1x1 in the Midamble RX Max NSTS */
  530. if ((tx_chains & rx_chains) != ANT_AB) {
  531. iwl_he_capa.he_cap.he_cap_elem.phy_cap_info[1] &=
  532. ~IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_MAX_NSTS;
  533. iwl_he_capa.he_cap.he_cap_elem.phy_cap_info[2] &=
  534. ~IEEE80211_HE_PHY_CAP2_MIDAMBLE_RX_MAX_NSTS;
  535. }
  536. }
  537. static void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
  538. struct iwl_nvm_data *data,
  539. const __le16 *nvm_ch_flags, u8 tx_chains,
  540. u8 rx_chains, u32 sbands_flags)
  541. {
  542. int n_channels;
  543. int n_used = 0;
  544. struct ieee80211_supported_band *sband;
  545. n_channels = iwl_init_channel_map(dev, cfg, data, nvm_ch_flags,
  546. sbands_flags);
  547. sband = &data->bands[NL80211_BAND_2GHZ];
  548. sband->band = NL80211_BAND_2GHZ;
  549. sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
  550. sband->n_bitrates = N_RATES_24;
  551. n_used += iwl_init_sband_channels(data, sband, n_channels,
  552. NL80211_BAND_2GHZ);
  553. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_2GHZ,
  554. tx_chains, rx_chains);
  555. if (data->sku_cap_11ax_enable && !iwlwifi_mod_params.disable_11ax)
  556. iwl_init_he_hw_capab(sband, tx_chains, rx_chains);
  557. sband = &data->bands[NL80211_BAND_5GHZ];
  558. sband->band = NL80211_BAND_5GHZ;
  559. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  560. sband->n_bitrates = N_RATES_52;
  561. n_used += iwl_init_sband_channels(data, sband, n_channels,
  562. NL80211_BAND_5GHZ);
  563. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_5GHZ,
  564. tx_chains, rx_chains);
  565. if (data->sku_cap_11ac_enable && !iwlwifi_mod_params.disable_11ac)
  566. iwl_init_vht_hw_capab(cfg, data, &sband->vht_cap,
  567. tx_chains, rx_chains);
  568. if (data->sku_cap_11ax_enable && !iwlwifi_mod_params.disable_11ax)
  569. iwl_init_he_hw_capab(sband, tx_chains, rx_chains);
  570. if (n_channels != n_used)
  571. IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n",
  572. n_used, n_channels);
  573. }
  574. static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  575. const __le16 *phy_sku)
  576. {
  577. if (cfg->nvm_type != IWL_NVM_EXT)
  578. return le16_to_cpup(nvm_sw + SKU);
  579. return le32_to_cpup((__le32 *)(phy_sku + SKU_FAMILY_8000));
  580. }
  581. static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  582. {
  583. if (cfg->nvm_type != IWL_NVM_EXT)
  584. return le16_to_cpup(nvm_sw + NVM_VERSION);
  585. else
  586. return le32_to_cpup((__le32 *)(nvm_sw +
  587. NVM_VERSION_EXT_NVM));
  588. }
  589. static int iwl_get_radio_cfg(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  590. const __le16 *phy_sku)
  591. {
  592. if (cfg->nvm_type != IWL_NVM_EXT)
  593. return le16_to_cpup(nvm_sw + RADIO_CFG);
  594. return le32_to_cpup((__le32 *)(phy_sku + RADIO_CFG_FAMILY_EXT_NVM));
  595. }
  596. static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  597. {
  598. int n_hw_addr;
  599. if (cfg->nvm_type != IWL_NVM_EXT)
  600. return le16_to_cpup(nvm_sw + N_HW_ADDRS);
  601. n_hw_addr = le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000));
  602. return n_hw_addr & N_HW_ADDR_MASK;
  603. }
  604. static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
  605. struct iwl_nvm_data *data,
  606. u32 radio_cfg)
  607. {
  608. if (cfg->nvm_type != IWL_NVM_EXT) {
  609. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg);
  610. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg);
  611. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg);
  612. data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg);
  613. return;
  614. }
  615. /* set the radio configuration for family 8000 */
  616. data->radio_cfg_type = EXT_NVM_RF_CFG_TYPE_MSK(radio_cfg);
  617. data->radio_cfg_step = EXT_NVM_RF_CFG_STEP_MSK(radio_cfg);
  618. data->radio_cfg_dash = EXT_NVM_RF_CFG_DASH_MSK(radio_cfg);
  619. data->radio_cfg_pnum = EXT_NVM_RF_CFG_FLAVOR_MSK(radio_cfg);
  620. data->valid_tx_ant = EXT_NVM_RF_CFG_TX_ANT_MSK(radio_cfg);
  621. data->valid_rx_ant = EXT_NVM_RF_CFG_RX_ANT_MSK(radio_cfg);
  622. }
  623. static void iwl_flip_hw_address(__le32 mac_addr0, __le32 mac_addr1, u8 *dest)
  624. {
  625. const u8 *hw_addr;
  626. hw_addr = (const u8 *)&mac_addr0;
  627. dest[0] = hw_addr[3];
  628. dest[1] = hw_addr[2];
  629. dest[2] = hw_addr[1];
  630. dest[3] = hw_addr[0];
  631. hw_addr = (const u8 *)&mac_addr1;
  632. dest[4] = hw_addr[1];
  633. dest[5] = hw_addr[0];
  634. }
  635. static void iwl_set_hw_address_from_csr(struct iwl_trans *trans,
  636. struct iwl_nvm_data *data)
  637. {
  638. __le32 mac_addr0 =
  639. cpu_to_le32(iwl_read32(trans,
  640. trans->cfg->csr->mac_addr0_strap));
  641. __le32 mac_addr1 =
  642. cpu_to_le32(iwl_read32(trans,
  643. trans->cfg->csr->mac_addr1_strap));
  644. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  645. /*
  646. * If the OEM fused a valid address, use it instead of the one in the
  647. * OTP
  648. */
  649. if (is_valid_ether_addr(data->hw_addr))
  650. return;
  651. mac_addr0 = cpu_to_le32(iwl_read32(trans,
  652. trans->cfg->csr->mac_addr0_otp));
  653. mac_addr1 = cpu_to_le32(iwl_read32(trans,
  654. trans->cfg->csr->mac_addr1_otp));
  655. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  656. }
  657. static void iwl_set_hw_address_family_8000(struct iwl_trans *trans,
  658. const struct iwl_cfg *cfg,
  659. struct iwl_nvm_data *data,
  660. const __le16 *mac_override,
  661. const __be16 *nvm_hw)
  662. {
  663. const u8 *hw_addr;
  664. if (mac_override) {
  665. static const u8 reserved_mac[] = {
  666. 0x02, 0xcc, 0xaa, 0xff, 0xee, 0x00
  667. };
  668. hw_addr = (const u8 *)(mac_override +
  669. MAC_ADDRESS_OVERRIDE_EXT_NVM);
  670. /*
  671. * Store the MAC address from MAO section.
  672. * No byte swapping is required in MAO section
  673. */
  674. memcpy(data->hw_addr, hw_addr, ETH_ALEN);
  675. /*
  676. * Force the use of the OTP MAC address in case of reserved MAC
  677. * address in the NVM, or if address is given but invalid.
  678. */
  679. if (is_valid_ether_addr(data->hw_addr) &&
  680. memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0)
  681. return;
  682. IWL_ERR(trans,
  683. "mac address from nvm override section is not valid\n");
  684. }
  685. if (nvm_hw) {
  686. /* read the mac address from WFMP registers */
  687. __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans,
  688. WFMP_MAC_ADDR_0));
  689. __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans,
  690. WFMP_MAC_ADDR_1));
  691. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  692. return;
  693. }
  694. IWL_ERR(trans, "mac address is not found\n");
  695. }
  696. static int iwl_set_hw_address(struct iwl_trans *trans,
  697. const struct iwl_cfg *cfg,
  698. struct iwl_nvm_data *data, const __be16 *nvm_hw,
  699. const __le16 *mac_override)
  700. {
  701. if (cfg->mac_addr_from_csr) {
  702. iwl_set_hw_address_from_csr(trans, data);
  703. } else if (cfg->nvm_type != IWL_NVM_EXT) {
  704. const u8 *hw_addr = (const u8 *)(nvm_hw + HW_ADDR);
  705. /* The byte order is little endian 16 bit, meaning 214365 */
  706. data->hw_addr[0] = hw_addr[1];
  707. data->hw_addr[1] = hw_addr[0];
  708. data->hw_addr[2] = hw_addr[3];
  709. data->hw_addr[3] = hw_addr[2];
  710. data->hw_addr[4] = hw_addr[5];
  711. data->hw_addr[5] = hw_addr[4];
  712. } else {
  713. iwl_set_hw_address_family_8000(trans, cfg, data,
  714. mac_override, nvm_hw);
  715. }
  716. if (!is_valid_ether_addr(data->hw_addr)) {
  717. IWL_ERR(trans, "no valid mac address was found\n");
  718. return -EINVAL;
  719. }
  720. IWL_INFO(trans, "base HW address: %pM\n", data->hw_addr);
  721. return 0;
  722. }
  723. static bool
  724. iwl_nvm_no_wide_in_5ghz(struct device *dev, const struct iwl_cfg *cfg,
  725. const __be16 *nvm_hw)
  726. {
  727. /*
  728. * Workaround a bug in Indonesia SKUs where the regulatory in
  729. * some 7000-family OTPs erroneously allow wide channels in
  730. * 5GHz. To check for Indonesia, we take the SKU value from
  731. * bits 1-4 in the subsystem ID and check if it is either 5 or
  732. * 9. In those cases, we need to force-disable wide channels
  733. * in 5GHz otherwise the FW will throw a sysassert when we try
  734. * to use them.
  735. */
  736. if (cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  737. /*
  738. * Unlike the other sections in the NVM, the hw
  739. * section uses big-endian.
  740. */
  741. u16 subsystem_id = be16_to_cpup(nvm_hw + SUBSYSTEM_ID);
  742. u8 sku = (subsystem_id & 0x1e) >> 1;
  743. if (sku == 5 || sku == 9) {
  744. IWL_DEBUG_EEPROM(dev,
  745. "disabling wide channels in 5GHz (0x%0x %d)\n",
  746. subsystem_id, sku);
  747. return true;
  748. }
  749. }
  750. return false;
  751. }
  752. struct iwl_nvm_data *
  753. iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  754. const __be16 *nvm_hw, const __le16 *nvm_sw,
  755. const __le16 *nvm_calib, const __le16 *regulatory,
  756. const __le16 *mac_override, const __le16 *phy_sku,
  757. u8 tx_chains, u8 rx_chains, bool lar_fw_supported)
  758. {
  759. struct device *dev = trans->dev;
  760. struct iwl_nvm_data *data;
  761. bool lar_enabled;
  762. u32 sku, radio_cfg;
  763. u32 sbands_flags = 0;
  764. u16 lar_config;
  765. const __le16 *ch_section;
  766. if (cfg->nvm_type != IWL_NVM_EXT)
  767. data = kzalloc(sizeof(*data) +
  768. sizeof(struct ieee80211_channel) *
  769. IWL_NVM_NUM_CHANNELS,
  770. GFP_KERNEL);
  771. else
  772. data = kzalloc(sizeof(*data) +
  773. sizeof(struct ieee80211_channel) *
  774. IWL_NVM_NUM_CHANNELS_EXT,
  775. GFP_KERNEL);
  776. if (!data)
  777. return NULL;
  778. data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw);
  779. radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw, phy_sku);
  780. iwl_set_radio_cfg(cfg, data, radio_cfg);
  781. if (data->valid_tx_ant)
  782. tx_chains &= data->valid_tx_ant;
  783. if (data->valid_rx_ant)
  784. rx_chains &= data->valid_rx_ant;
  785. sku = iwl_get_sku(cfg, nvm_sw, phy_sku);
  786. data->sku_cap_band_24ghz_enable = sku & NVM_SKU_CAP_BAND_24GHZ;
  787. data->sku_cap_band_52ghz_enable = sku & NVM_SKU_CAP_BAND_52GHZ;
  788. data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE;
  789. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  790. data->sku_cap_11n_enable = false;
  791. data->sku_cap_11ac_enable = data->sku_cap_11n_enable &&
  792. (sku & NVM_SKU_CAP_11AC_ENABLE);
  793. data->sku_cap_mimo_disabled = sku & NVM_SKU_CAP_MIMO_DISABLE;
  794. data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
  795. if (cfg->nvm_type != IWL_NVM_EXT) {
  796. /* Checking for required sections */
  797. if (!nvm_calib) {
  798. IWL_ERR(trans,
  799. "Can't parse empty Calib NVM sections\n");
  800. kfree(data);
  801. return NULL;
  802. }
  803. ch_section = cfg->nvm_type == IWL_NVM_SDP ?
  804. &regulatory[NVM_CHANNELS_SDP] :
  805. &nvm_sw[NVM_CHANNELS];
  806. /* in family 8000 Xtal calibration values moved to OTP */
  807. data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
  808. data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
  809. lar_enabled = true;
  810. } else {
  811. u16 lar_offset = data->nvm_version < 0xE39 ?
  812. NVM_LAR_OFFSET_OLD :
  813. NVM_LAR_OFFSET;
  814. lar_config = le16_to_cpup(regulatory + lar_offset);
  815. data->lar_enabled = !!(lar_config &
  816. NVM_LAR_ENABLED);
  817. lar_enabled = data->lar_enabled;
  818. ch_section = &regulatory[NVM_CHANNELS_EXTENDED];
  819. }
  820. /* If no valid mac address was found - bail out */
  821. if (iwl_set_hw_address(trans, cfg, data, nvm_hw, mac_override)) {
  822. kfree(data);
  823. return NULL;
  824. }
  825. if (lar_fw_supported && lar_enabled)
  826. sbands_flags |= IWL_NVM_SBANDS_FLAGS_LAR;
  827. if (iwl_nvm_no_wide_in_5ghz(dev, cfg, nvm_hw))
  828. sbands_flags |= IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ;
  829. iwl_init_sbands(dev, cfg, data, ch_section, tx_chains, rx_chains,
  830. sbands_flags);
  831. data->calib_version = 255;
  832. return data;
  833. }
  834. IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);
  835. static u32 iwl_nvm_get_regdom_bw_flags(const u8 *nvm_chan,
  836. int ch_idx, u16 nvm_flags,
  837. u16 cap_flags,
  838. const struct iwl_cfg *cfg)
  839. {
  840. u32 flags = NL80211_RRF_NO_HT40;
  841. u32 last_5ghz_ht = LAST_5GHZ_HT;
  842. if (cfg->nvm_type == IWL_NVM_EXT)
  843. last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
  844. if (ch_idx < NUM_2GHZ_CHANNELS &&
  845. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  846. if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS)
  847. flags &= ~NL80211_RRF_NO_HT40PLUS;
  848. if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS)
  849. flags &= ~NL80211_RRF_NO_HT40MINUS;
  850. } else if (nvm_chan[ch_idx] <= last_5ghz_ht &&
  851. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  852. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  853. flags &= ~NL80211_RRF_NO_HT40PLUS;
  854. else
  855. flags &= ~NL80211_RRF_NO_HT40MINUS;
  856. }
  857. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  858. flags |= NL80211_RRF_NO_80MHZ;
  859. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  860. flags |= NL80211_RRF_NO_160MHZ;
  861. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  862. flags |= NL80211_RRF_NO_IR;
  863. if (nvm_flags & NVM_CHANNEL_RADAR)
  864. flags |= NL80211_RRF_DFS;
  865. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  866. flags |= NL80211_RRF_NO_OUTDOOR;
  867. /* Set the GO concurrent flag only in case that NO_IR is set.
  868. * Otherwise it is meaningless
  869. */
  870. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  871. (flags & NL80211_RRF_NO_IR))
  872. flags |= NL80211_RRF_GO_CONCURRENT;
  873. /*
  874. * cap_flags is per regulatory domain so apply it for every channel
  875. */
  876. if (ch_idx >= NUM_2GHZ_CHANNELS) {
  877. if (cap_flags & REG_CAPA_40MHZ_FORBIDDEN)
  878. flags |= NL80211_RRF_NO_HT40;
  879. if (!(cap_flags & REG_CAPA_80MHZ_ALLOWED))
  880. flags |= NL80211_RRF_NO_80MHZ;
  881. if (!(cap_flags & REG_CAPA_160MHZ_ALLOWED))
  882. flags |= NL80211_RRF_NO_160MHZ;
  883. }
  884. return flags;
  885. }
  886. struct regdb_ptrs {
  887. struct ieee80211_wmm_rule *rule;
  888. u32 token;
  889. };
  890. struct ieee80211_regdomain *
  891. iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
  892. int num_of_ch, __le32 *channels, u16 fw_mcc,
  893. u16 geo_info, u16 cap)
  894. {
  895. int ch_idx;
  896. u16 ch_flags;
  897. u32 reg_rule_flags, prev_reg_rule_flags = 0;
  898. const u8 *nvm_chan = cfg->nvm_type == IWL_NVM_EXT ?
  899. iwl_ext_nvm_channels : iwl_nvm_channels;
  900. struct ieee80211_regdomain *regd, *copy_rd;
  901. int size_of_regd, regd_to_copy;
  902. struct ieee80211_reg_rule *rule;
  903. struct regdb_ptrs *regdb_ptrs;
  904. enum nl80211_band band;
  905. int center_freq, prev_center_freq = 0;
  906. int valid_rules = 0;
  907. bool new_rule;
  908. int max_num_ch = cfg->nvm_type == IWL_NVM_EXT ?
  909. IWL_NVM_NUM_CHANNELS_EXT : IWL_NVM_NUM_CHANNELS;
  910. if (WARN_ON_ONCE(num_of_ch > NL80211_MAX_SUPP_REG_RULES))
  911. return ERR_PTR(-EINVAL);
  912. if (WARN_ON(num_of_ch > max_num_ch))
  913. num_of_ch = max_num_ch;
  914. IWL_DEBUG_DEV(dev, IWL_DL_LAR, "building regdom for %d channels\n",
  915. num_of_ch);
  916. /* build a regdomain rule for every valid channel */
  917. size_of_regd =
  918. sizeof(struct ieee80211_regdomain) +
  919. num_of_ch * sizeof(struct ieee80211_reg_rule);
  920. regd = kzalloc(size_of_regd, GFP_KERNEL);
  921. if (!regd)
  922. return ERR_PTR(-ENOMEM);
  923. regdb_ptrs = kcalloc(num_of_ch, sizeof(*regdb_ptrs), GFP_KERNEL);
  924. if (!regdb_ptrs) {
  925. copy_rd = ERR_PTR(-ENOMEM);
  926. goto out;
  927. }
  928. /* set alpha2 from FW. */
  929. regd->alpha2[0] = fw_mcc >> 8;
  930. regd->alpha2[1] = fw_mcc & 0xff;
  931. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  932. ch_flags = (u16)__le32_to_cpup(channels + ch_idx);
  933. band = (ch_idx < NUM_2GHZ_CHANNELS) ?
  934. NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
  935. center_freq = ieee80211_channel_to_frequency(nvm_chan[ch_idx],
  936. band);
  937. new_rule = false;
  938. if (!(ch_flags & NVM_CHANNEL_VALID)) {
  939. iwl_nvm_print_channel_flags(dev, IWL_DL_LAR,
  940. nvm_chan[ch_idx], ch_flags);
  941. continue;
  942. }
  943. reg_rule_flags = iwl_nvm_get_regdom_bw_flags(nvm_chan, ch_idx,
  944. ch_flags, cap,
  945. cfg);
  946. /* we can't continue the same rule */
  947. if (ch_idx == 0 || prev_reg_rule_flags != reg_rule_flags ||
  948. center_freq - prev_center_freq > 20) {
  949. valid_rules++;
  950. new_rule = true;
  951. }
  952. rule = &regd->reg_rules[valid_rules - 1];
  953. if (new_rule)
  954. rule->freq_range.start_freq_khz =
  955. MHZ_TO_KHZ(center_freq - 10);
  956. rule->freq_range.end_freq_khz = MHZ_TO_KHZ(center_freq + 10);
  957. /* this doesn't matter - not used by FW */
  958. rule->power_rule.max_antenna_gain = DBI_TO_MBI(6);
  959. rule->power_rule.max_eirp =
  960. DBM_TO_MBM(IWL_DEFAULT_MAX_TX_POWER);
  961. rule->flags = reg_rule_flags;
  962. /* rely on auto-calculation to merge BW of contiguous chans */
  963. rule->flags |= NL80211_RRF_AUTO_BW;
  964. rule->freq_range.max_bandwidth_khz = 0;
  965. prev_center_freq = center_freq;
  966. prev_reg_rule_flags = reg_rule_flags;
  967. iwl_nvm_print_channel_flags(dev, IWL_DL_LAR,
  968. nvm_chan[ch_idx], ch_flags);
  969. if (!(geo_info & GEO_WMM_ETSI_5GHZ_INFO) ||
  970. band == NL80211_BAND_2GHZ)
  971. continue;
  972. reg_query_regdb_wmm(regd->alpha2, center_freq, rule);
  973. }
  974. regd->n_reg_rules = valid_rules;
  975. /*
  976. * Narrow down regdom for unused regulatory rules to prevent hole
  977. * between reg rules to wmm rules.
  978. */
  979. regd_to_copy = sizeof(struct ieee80211_regdomain) +
  980. valid_rules * sizeof(struct ieee80211_reg_rule);
  981. copy_rd = kzalloc(regd_to_copy, GFP_KERNEL);
  982. if (!copy_rd) {
  983. copy_rd = ERR_PTR(-ENOMEM);
  984. goto out;
  985. }
  986. memcpy(copy_rd, regd, regd_to_copy);
  987. out:
  988. kfree(regdb_ptrs);
  989. kfree(regd);
  990. return copy_rd;
  991. }
  992. IWL_EXPORT_SYMBOL(iwl_parse_nvm_mcc_info);
  993. #define IWL_MAX_NVM_SECTION_SIZE 0x1b58
  994. #define IWL_MAX_EXT_NVM_SECTION_SIZE 0x1ffc
  995. #define MAX_NVM_FILE_LEN 16384
  996. void iwl_nvm_fixups(u32 hw_id, unsigned int section, u8 *data,
  997. unsigned int len)
  998. {
  999. #define IWL_4165_DEVICE_ID 0x5501
  1000. #define NVM_SKU_CAP_MIMO_DISABLE BIT(5)
  1001. if (section == NVM_SECTION_TYPE_PHY_SKU &&
  1002. hw_id == IWL_4165_DEVICE_ID && data && len >= 5 &&
  1003. (data[4] & NVM_SKU_CAP_MIMO_DISABLE))
  1004. /* OTP 0x52 bug work around: it's a 1x1 device */
  1005. data[3] = ANT_B | (ANT_B << 4);
  1006. }
  1007. IWL_EXPORT_SYMBOL(iwl_nvm_fixups);
  1008. /*
  1009. * Reads external NVM from a file into mvm->nvm_sections
  1010. *
  1011. * HOW TO CREATE THE NVM FILE FORMAT:
  1012. * ------------------------------
  1013. * 1. create hex file, format:
  1014. * 3800 -> header
  1015. * 0000 -> header
  1016. * 5a40 -> data
  1017. *
  1018. * rev - 6 bit (word1)
  1019. * len - 10 bit (word1)
  1020. * id - 4 bit (word2)
  1021. * rsv - 12 bit (word2)
  1022. *
  1023. * 2. flip 8bits with 8 bits per line to get the right NVM file format
  1024. *
  1025. * 3. create binary file from the hex file
  1026. *
  1027. * 4. save as "iNVM_xxx.bin" under /lib/firmware
  1028. */
  1029. int iwl_read_external_nvm(struct iwl_trans *trans,
  1030. const char *nvm_file_name,
  1031. struct iwl_nvm_section *nvm_sections)
  1032. {
  1033. int ret, section_size;
  1034. u16 section_id;
  1035. const struct firmware *fw_entry;
  1036. const struct {
  1037. __le16 word1;
  1038. __le16 word2;
  1039. u8 data[];
  1040. } *file_sec;
  1041. const u8 *eof;
  1042. u8 *temp;
  1043. int max_section_size;
  1044. const __le32 *dword_buff;
  1045. #define NVM_WORD1_LEN(x) (8 * (x & 0x03FF))
  1046. #define NVM_WORD2_ID(x) (x >> 12)
  1047. #define EXT_NVM_WORD2_LEN(x) (2 * (((x) & 0xFF) << 8 | (x) >> 8))
  1048. #define EXT_NVM_WORD1_ID(x) ((x) >> 4)
  1049. #define NVM_HEADER_0 (0x2A504C54)
  1050. #define NVM_HEADER_1 (0x4E564D2A)
  1051. #define NVM_HEADER_SIZE (4 * sizeof(u32))
  1052. IWL_DEBUG_EEPROM(trans->dev, "Read from external NVM\n");
  1053. /* Maximal size depends on NVM version */
  1054. if (trans->cfg->nvm_type != IWL_NVM_EXT)
  1055. max_section_size = IWL_MAX_NVM_SECTION_SIZE;
  1056. else
  1057. max_section_size = IWL_MAX_EXT_NVM_SECTION_SIZE;
  1058. /*
  1059. * Obtain NVM image via request_firmware. Since we already used
  1060. * request_firmware_nowait() for the firmware binary load and only
  1061. * get here after that we assume the NVM request can be satisfied
  1062. * synchronously.
  1063. */
  1064. ret = request_firmware(&fw_entry, nvm_file_name, trans->dev);
  1065. if (ret) {
  1066. IWL_ERR(trans, "ERROR: %s isn't available %d\n",
  1067. nvm_file_name, ret);
  1068. return ret;
  1069. }
  1070. IWL_INFO(trans, "Loaded NVM file %s (%zu bytes)\n",
  1071. nvm_file_name, fw_entry->size);
  1072. if (fw_entry->size > MAX_NVM_FILE_LEN) {
  1073. IWL_ERR(trans, "NVM file too large\n");
  1074. ret = -EINVAL;
  1075. goto out;
  1076. }
  1077. eof = fw_entry->data + fw_entry->size;
  1078. dword_buff = (__le32 *)fw_entry->data;
  1079. /* some NVM file will contain a header.
  1080. * The header is identified by 2 dwords header as follow:
  1081. * dword[0] = 0x2A504C54
  1082. * dword[1] = 0x4E564D2A
  1083. *
  1084. * This header must be skipped when providing the NVM data to the FW.
  1085. */
  1086. if (fw_entry->size > NVM_HEADER_SIZE &&
  1087. dword_buff[0] == cpu_to_le32(NVM_HEADER_0) &&
  1088. dword_buff[1] == cpu_to_le32(NVM_HEADER_1)) {
  1089. file_sec = (void *)(fw_entry->data + NVM_HEADER_SIZE);
  1090. IWL_INFO(trans, "NVM Version %08X\n", le32_to_cpu(dword_buff[2]));
  1091. IWL_INFO(trans, "NVM Manufacturing date %08X\n",
  1092. le32_to_cpu(dword_buff[3]));
  1093. /* nvm file validation, dword_buff[2] holds the file version */
  1094. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  1095. CSR_HW_REV_STEP(trans->hw_rev) == SILICON_C_STEP &&
  1096. le32_to_cpu(dword_buff[2]) < 0xE4A) {
  1097. ret = -EFAULT;
  1098. goto out;
  1099. }
  1100. } else {
  1101. file_sec = (void *)fw_entry->data;
  1102. }
  1103. while (true) {
  1104. if (file_sec->data > eof) {
  1105. IWL_ERR(trans,
  1106. "ERROR - NVM file too short for section header\n");
  1107. ret = -EINVAL;
  1108. break;
  1109. }
  1110. /* check for EOF marker */
  1111. if (!file_sec->word1 && !file_sec->word2) {
  1112. ret = 0;
  1113. break;
  1114. }
  1115. if (trans->cfg->nvm_type != IWL_NVM_EXT) {
  1116. section_size =
  1117. 2 * NVM_WORD1_LEN(le16_to_cpu(file_sec->word1));
  1118. section_id = NVM_WORD2_ID(le16_to_cpu(file_sec->word2));
  1119. } else {
  1120. section_size = 2 * EXT_NVM_WORD2_LEN(
  1121. le16_to_cpu(file_sec->word2));
  1122. section_id = EXT_NVM_WORD1_ID(
  1123. le16_to_cpu(file_sec->word1));
  1124. }
  1125. if (section_size > max_section_size) {
  1126. IWL_ERR(trans, "ERROR - section too large (%d)\n",
  1127. section_size);
  1128. ret = -EINVAL;
  1129. break;
  1130. }
  1131. if (!section_size) {
  1132. IWL_ERR(trans, "ERROR - section empty\n");
  1133. ret = -EINVAL;
  1134. break;
  1135. }
  1136. if (file_sec->data + section_size > eof) {
  1137. IWL_ERR(trans,
  1138. "ERROR - NVM file too short for section (%d bytes)\n",
  1139. section_size);
  1140. ret = -EINVAL;
  1141. break;
  1142. }
  1143. if (WARN(section_id >= NVM_MAX_NUM_SECTIONS,
  1144. "Invalid NVM section ID %d\n", section_id)) {
  1145. ret = -EINVAL;
  1146. break;
  1147. }
  1148. temp = kmemdup(file_sec->data, section_size, GFP_KERNEL);
  1149. if (!temp) {
  1150. ret = -ENOMEM;
  1151. break;
  1152. }
  1153. iwl_nvm_fixups(trans->hw_id, section_id, temp, section_size);
  1154. kfree(nvm_sections[section_id].data);
  1155. nvm_sections[section_id].data = temp;
  1156. nvm_sections[section_id].length = section_size;
  1157. /* advance to the next section */
  1158. file_sec = (void *)(file_sec->data + section_size);
  1159. }
  1160. out:
  1161. release_firmware(fw_entry);
  1162. return ret;
  1163. }
  1164. IWL_EXPORT_SYMBOL(iwl_read_external_nvm);
  1165. struct iwl_nvm_data *iwl_get_nvm(struct iwl_trans *trans,
  1166. const struct iwl_fw *fw)
  1167. {
  1168. struct iwl_nvm_get_info cmd = {};
  1169. struct iwl_nvm_get_info_rsp *rsp;
  1170. struct iwl_nvm_data *nvm;
  1171. struct iwl_host_cmd hcmd = {
  1172. .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  1173. .data = { &cmd, },
  1174. .len = { sizeof(cmd) },
  1175. .id = WIDE_ID(REGULATORY_AND_NVM_GROUP, NVM_GET_INFO)
  1176. };
  1177. int ret;
  1178. bool lar_fw_supported = !iwlwifi_mod_params.lar_disable &&
  1179. fw_has_capa(&fw->ucode_capa,
  1180. IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
  1181. bool empty_otp;
  1182. u32 mac_flags;
  1183. u32 sbands_flags = 0;
  1184. ret = iwl_trans_send_cmd(trans, &hcmd);
  1185. if (ret)
  1186. return ERR_PTR(ret);
  1187. if (WARN(iwl_rx_packet_payload_len(hcmd.resp_pkt) != sizeof(*rsp),
  1188. "Invalid payload len in NVM response from FW %d",
  1189. iwl_rx_packet_payload_len(hcmd.resp_pkt))) {
  1190. ret = -EINVAL;
  1191. goto out;
  1192. }
  1193. rsp = (void *)hcmd.resp_pkt->data;
  1194. empty_otp = !!(le32_to_cpu(rsp->general.flags) &
  1195. NVM_GENERAL_FLAGS_EMPTY_OTP);
  1196. if (empty_otp)
  1197. IWL_INFO(trans, "OTP is empty\n");
  1198. nvm = kzalloc(sizeof(*nvm) +
  1199. sizeof(struct ieee80211_channel) * IWL_NUM_CHANNELS,
  1200. GFP_KERNEL);
  1201. if (!nvm) {
  1202. ret = -ENOMEM;
  1203. goto out;
  1204. }
  1205. iwl_set_hw_address_from_csr(trans, nvm);
  1206. /* TODO: if platform NVM has MAC address - override it here */
  1207. if (!is_valid_ether_addr(nvm->hw_addr)) {
  1208. IWL_ERR(trans, "no valid mac address was found\n");
  1209. ret = -EINVAL;
  1210. goto err_free;
  1211. }
  1212. IWL_INFO(trans, "base HW address: %pM\n", nvm->hw_addr);
  1213. /* Initialize general data */
  1214. nvm->nvm_version = le16_to_cpu(rsp->general.nvm_version);
  1215. nvm->n_hw_addrs = rsp->general.n_hw_addrs;
  1216. if (nvm->n_hw_addrs == 0)
  1217. IWL_WARN(trans,
  1218. "Firmware declares no reserved mac addresses. OTP is empty: %d\n",
  1219. empty_otp);
  1220. /* Initialize MAC sku data */
  1221. mac_flags = le32_to_cpu(rsp->mac_sku.mac_sku_flags);
  1222. nvm->sku_cap_11ac_enable =
  1223. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11AC_ENABLED);
  1224. nvm->sku_cap_11n_enable =
  1225. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11N_ENABLED);
  1226. nvm->sku_cap_11ax_enable =
  1227. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11AX_ENABLED);
  1228. nvm->sku_cap_band_24ghz_enable =
  1229. !!(mac_flags & NVM_MAC_SKU_FLAGS_BAND_2_4_ENABLED);
  1230. nvm->sku_cap_band_52ghz_enable =
  1231. !!(mac_flags & NVM_MAC_SKU_FLAGS_BAND_5_2_ENABLED);
  1232. nvm->sku_cap_mimo_disabled =
  1233. !!(mac_flags & NVM_MAC_SKU_FLAGS_MIMO_DISABLED);
  1234. /* Initialize PHY sku data */
  1235. nvm->valid_tx_ant = (u8)le32_to_cpu(rsp->phy_sku.tx_chains);
  1236. nvm->valid_rx_ant = (u8)le32_to_cpu(rsp->phy_sku.rx_chains);
  1237. if (le32_to_cpu(rsp->regulatory.lar_enabled) && lar_fw_supported) {
  1238. nvm->lar_enabled = true;
  1239. sbands_flags |= IWL_NVM_SBANDS_FLAGS_LAR;
  1240. }
  1241. iwl_init_sbands(trans->dev, trans->cfg, nvm,
  1242. rsp->regulatory.channel_profile,
  1243. nvm->valid_tx_ant & fw->valid_tx_ant,
  1244. nvm->valid_rx_ant & fw->valid_rx_ant,
  1245. sbands_flags);
  1246. iwl_free_resp(&hcmd);
  1247. return nvm;
  1248. err_free:
  1249. kfree(nvm);
  1250. out:
  1251. iwl_free_resp(&hcmd);
  1252. return ERR_PTR(ret);
  1253. }
  1254. IWL_EXPORT_SYMBOL(iwl_get_nvm);