iwl-nvm-parse.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  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. static inline void iwl_nvm_print_channel_flags(struct device *dev, u32 level,
  206. int chan, u16 flags)
  207. {
  208. #define CHECK_AND_PRINT_I(x) \
  209. ((flags & NVM_CHANNEL_##x) ? " " #x : "")
  210. if (!(flags & NVM_CHANNEL_VALID)) {
  211. IWL_DEBUG_DEV(dev, level, "Ch. %d: 0x%x: No traffic\n",
  212. chan, flags);
  213. return;
  214. }
  215. /* Note: already can print up to 101 characters, 110 is the limit! */
  216. IWL_DEBUG_DEV(dev, level,
  217. "Ch. %d: 0x%x:%s%s%s%s%s%s%s%s%s%s%s%s\n",
  218. chan, flags,
  219. CHECK_AND_PRINT_I(VALID),
  220. CHECK_AND_PRINT_I(IBSS),
  221. CHECK_AND_PRINT_I(ACTIVE),
  222. CHECK_AND_PRINT_I(RADAR),
  223. CHECK_AND_PRINT_I(INDOOR_ONLY),
  224. CHECK_AND_PRINT_I(GO_CONCURRENT),
  225. CHECK_AND_PRINT_I(UNIFORM),
  226. CHECK_AND_PRINT_I(20MHZ),
  227. CHECK_AND_PRINT_I(40MHZ),
  228. CHECK_AND_PRINT_I(80MHZ),
  229. CHECK_AND_PRINT_I(160MHZ),
  230. CHECK_AND_PRINT_I(DC_HIGH));
  231. #undef CHECK_AND_PRINT_I
  232. }
  233. static u32 iwl_get_channel_flags(u8 ch_num, int ch_idx, bool is_5ghz,
  234. u16 nvm_flags, const struct iwl_cfg *cfg)
  235. {
  236. u32 flags = IEEE80211_CHAN_NO_HT40;
  237. u32 last_5ghz_ht = LAST_5GHZ_HT;
  238. if (cfg->nvm_type == IWL_NVM_EXT)
  239. last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
  240. if (!is_5ghz && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  241. if (ch_num <= LAST_2GHZ_HT_PLUS)
  242. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  243. if (ch_num >= FIRST_2GHZ_HT_MINUS)
  244. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  245. } else if (ch_num <= last_5ghz_ht && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  246. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  247. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  248. else
  249. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  250. }
  251. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  252. flags |= IEEE80211_CHAN_NO_80MHZ;
  253. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  254. flags |= IEEE80211_CHAN_NO_160MHZ;
  255. if (!(nvm_flags & NVM_CHANNEL_IBSS))
  256. flags |= IEEE80211_CHAN_NO_IR;
  257. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  258. flags |= IEEE80211_CHAN_NO_IR;
  259. if (nvm_flags & NVM_CHANNEL_RADAR)
  260. flags |= IEEE80211_CHAN_RADAR;
  261. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  262. flags |= IEEE80211_CHAN_INDOOR_ONLY;
  263. /* Set the GO concurrent flag only in case that NO_IR is set.
  264. * Otherwise it is meaningless
  265. */
  266. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  267. (flags & IEEE80211_CHAN_NO_IR))
  268. flags |= IEEE80211_CHAN_IR_CONCURRENT;
  269. return flags;
  270. }
  271. static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
  272. struct iwl_nvm_data *data,
  273. const __le16 * const nvm_ch_flags,
  274. u32 sbands_flags)
  275. {
  276. int ch_idx;
  277. int n_channels = 0;
  278. struct ieee80211_channel *channel;
  279. u16 ch_flags;
  280. int num_of_ch, num_2ghz_channels;
  281. const u8 *nvm_chan;
  282. if (cfg->nvm_type != IWL_NVM_EXT) {
  283. num_of_ch = IWL_NVM_NUM_CHANNELS;
  284. nvm_chan = &iwl_nvm_channels[0];
  285. num_2ghz_channels = NUM_2GHZ_CHANNELS;
  286. } else {
  287. num_of_ch = IWL_NVM_NUM_CHANNELS_EXT;
  288. nvm_chan = &iwl_ext_nvm_channels[0];
  289. num_2ghz_channels = NUM_2GHZ_CHANNELS_EXT;
  290. }
  291. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  292. bool is_5ghz = (ch_idx >= num_2ghz_channels);
  293. ch_flags = __le16_to_cpup(nvm_ch_flags + ch_idx);
  294. if (is_5ghz && !data->sku_cap_band_52ghz_enable)
  295. continue;
  296. /* workaround to disable wide channels in 5GHz */
  297. if ((sbands_flags & IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ) &&
  298. is_5ghz) {
  299. ch_flags &= ~(NVM_CHANNEL_40MHZ |
  300. NVM_CHANNEL_80MHZ |
  301. NVM_CHANNEL_160MHZ);
  302. }
  303. if (ch_flags & NVM_CHANNEL_160MHZ)
  304. data->vht160_supported = true;
  305. if (!(sbands_flags & IWL_NVM_SBANDS_FLAGS_LAR) &&
  306. !(ch_flags & NVM_CHANNEL_VALID)) {
  307. /*
  308. * Channels might become valid later if lar is
  309. * supported, hence we still want to add them to
  310. * the list of supported channels to cfg80211.
  311. */
  312. iwl_nvm_print_channel_flags(dev, IWL_DL_EEPROM,
  313. nvm_chan[ch_idx], ch_flags);
  314. continue;
  315. }
  316. channel = &data->channels[n_channels];
  317. n_channels++;
  318. channel->hw_value = nvm_chan[ch_idx];
  319. channel->band = is_5ghz ?
  320. NL80211_BAND_5GHZ : NL80211_BAND_2GHZ;
  321. channel->center_freq =
  322. ieee80211_channel_to_frequency(
  323. channel->hw_value, channel->band);
  324. /* Initialize regulatory-based run-time data */
  325. /*
  326. * Default value - highest tx power value. max_power
  327. * is not used in mvm, and is used for backwards compatibility
  328. */
  329. channel->max_power = IWL_DEFAULT_MAX_TX_POWER;
  330. /* don't put limitations in case we're using LAR */
  331. if (!(sbands_flags & IWL_NVM_SBANDS_FLAGS_LAR))
  332. channel->flags = iwl_get_channel_flags(nvm_chan[ch_idx],
  333. ch_idx, is_5ghz,
  334. ch_flags, cfg);
  335. else
  336. channel->flags = 0;
  337. iwl_nvm_print_channel_flags(dev, IWL_DL_EEPROM,
  338. channel->hw_value, ch_flags);
  339. IWL_DEBUG_EEPROM(dev, "Ch. %d: %ddBm\n",
  340. channel->hw_value, channel->max_power);
  341. }
  342. return n_channels;
  343. }
  344. static void iwl_init_vht_hw_capab(const struct iwl_cfg *cfg,
  345. struct iwl_nvm_data *data,
  346. struct ieee80211_sta_vht_cap *vht_cap,
  347. u8 tx_chains, u8 rx_chains)
  348. {
  349. int num_rx_ants = num_of_ant(rx_chains);
  350. int num_tx_ants = num_of_ant(tx_chains);
  351. unsigned int max_ampdu_exponent = (cfg->max_vht_ampdu_exponent ?:
  352. IEEE80211_VHT_MAX_AMPDU_1024K);
  353. vht_cap->vht_supported = true;
  354. vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 |
  355. IEEE80211_VHT_CAP_RXSTBC_1 |
  356. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  357. 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
  358. max_ampdu_exponent <<
  359. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  360. if (data->vht160_supported)
  361. vht_cap->cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
  362. IEEE80211_VHT_CAP_SHORT_GI_160;
  363. if (cfg->vht_mu_mimo_supported)
  364. vht_cap->cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  365. if (cfg->ht_params->ldpc)
  366. vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC;
  367. if (data->sku_cap_mimo_disabled) {
  368. num_rx_ants = 1;
  369. num_tx_ants = 1;
  370. }
  371. if (num_tx_ants > 1)
  372. vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
  373. else
  374. vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  375. switch (iwlwifi_mod_params.amsdu_size) {
  376. case IWL_AMSDU_DEF:
  377. if (cfg->mq_rx_supported)
  378. vht_cap->cap |=
  379. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  380. else
  381. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  382. break;
  383. case IWL_AMSDU_2K:
  384. if (cfg->mq_rx_supported)
  385. vht_cap->cap |=
  386. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  387. else
  388. WARN(1, "RB size of 2K is not supported by this device\n");
  389. break;
  390. case IWL_AMSDU_4K:
  391. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  392. break;
  393. case IWL_AMSDU_8K:
  394. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
  395. break;
  396. case IWL_AMSDU_12K:
  397. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  398. break;
  399. default:
  400. break;
  401. }
  402. vht_cap->vht_mcs.rx_mcs_map =
  403. cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  404. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  405. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  406. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  407. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  408. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  409. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  410. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
  411. if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) {
  412. vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
  413. /* this works because NOT_SUPPORTED == 3 */
  414. vht_cap->vht_mcs.rx_mcs_map |=
  415. cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2);
  416. }
  417. vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
  418. }
  419. static struct ieee80211_sband_iftype_data iwl_he_capa = {
  420. .types_mask = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP),
  421. .he_cap = {
  422. .has_he = true,
  423. .he_cap_elem = {
  424. .mac_cap_info[0] =
  425. IEEE80211_HE_MAC_CAP0_HTC_HE,
  426. .mac_cap_info[1] =
  427. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  428. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_QOS_8,
  429. .mac_cap_info[2] =
  430. IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP |
  431. IEEE80211_HE_MAC_CAP2_ACK_EN,
  432. .mac_cap_info[3] =
  433. IEEE80211_HE_MAC_CAP3_GRP_ADDR_MULTI_STA_BA_DL_MU |
  434. IEEE80211_HE_MAC_CAP3_MAX_A_AMPDU_LEN_EXP_VHT_2,
  435. .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU,
  436. .phy_cap_info[0] =
  437. IEEE80211_HE_PHY_CAP0_DUAL_BAND |
  438. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
  439. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  440. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G,
  441. .phy_cap_info[1] =
  442. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  443. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
  444. IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_MAX_NSTS,
  445. .phy_cap_info[2] =
  446. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  447. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
  448. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ,
  449. .phy_cap_info[3] =
  450. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK |
  451. IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 |
  452. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK |
  453. IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1,
  454. .phy_cap_info[4] =
  455. IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
  456. IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_8 |
  457. IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_8,
  458. .phy_cap_info[5] =
  459. IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_2 |
  460. IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_2,
  461. .phy_cap_info[6] =
  462. IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT,
  463. .phy_cap_info[7] =
  464. IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_AR |
  465. IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI |
  466. IEEE80211_HE_PHY_CAP7_MAX_NC_7,
  467. .phy_cap_info[8] =
  468. IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
  469. IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
  470. IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
  471. IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU,
  472. },
  473. /*
  474. * Set default Tx/Rx HE MCS NSS Support field. Indicate support
  475. * for up to 2 spatial streams and all MCS, without any special
  476. * cases
  477. */
  478. .he_mcs_nss_supp = {
  479. .rx_mcs_80 = cpu_to_le16(0xfffa),
  480. .tx_mcs_80 = cpu_to_le16(0xfffa),
  481. .rx_mcs_160 = cpu_to_le16(0xfffa),
  482. .tx_mcs_160 = cpu_to_le16(0xfffa),
  483. .rx_mcs_80p80 = cpu_to_le16(0xffff),
  484. .tx_mcs_80p80 = cpu_to_le16(0xffff),
  485. },
  486. /*
  487. * Set default PPE thresholds, with PPET16 set to 0, PPET8 set
  488. * to 7
  489. */
  490. .ppe_thres = {0x61, 0x1c, 0xc7, 0x71},
  491. },
  492. };
  493. static void iwl_init_he_hw_capab(struct ieee80211_supported_band *sband,
  494. u8 tx_chains, u8 rx_chains)
  495. {
  496. if (sband->band == NL80211_BAND_2GHZ ||
  497. sband->band == NL80211_BAND_5GHZ)
  498. sband->iftype_data = &iwl_he_capa;
  499. else
  500. return;
  501. sband->n_iftype_data = 1;
  502. /* If not 2x2, we need to indicate 1x1 in the Midamble RX Max NSTS */
  503. if ((tx_chains & rx_chains) != ANT_AB) {
  504. iwl_he_capa.he_cap.he_cap_elem.phy_cap_info[1] &=
  505. ~IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_MAX_NSTS;
  506. iwl_he_capa.he_cap.he_cap_elem.phy_cap_info[2] &=
  507. ~IEEE80211_HE_PHY_CAP2_MIDAMBLE_RX_MAX_NSTS;
  508. }
  509. }
  510. static void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
  511. struct iwl_nvm_data *data,
  512. const __le16 *nvm_ch_flags, u8 tx_chains,
  513. u8 rx_chains, u32 sbands_flags)
  514. {
  515. int n_channels;
  516. int n_used = 0;
  517. struct ieee80211_supported_band *sband;
  518. n_channels = iwl_init_channel_map(dev, cfg, data, nvm_ch_flags,
  519. sbands_flags);
  520. sband = &data->bands[NL80211_BAND_2GHZ];
  521. sband->band = NL80211_BAND_2GHZ;
  522. sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
  523. sband->n_bitrates = N_RATES_24;
  524. n_used += iwl_init_sband_channels(data, sband, n_channels,
  525. NL80211_BAND_2GHZ);
  526. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_2GHZ,
  527. tx_chains, rx_chains);
  528. if (data->sku_cap_11ax_enable && !iwlwifi_mod_params.disable_11ax)
  529. iwl_init_he_hw_capab(sband, tx_chains, rx_chains);
  530. sband = &data->bands[NL80211_BAND_5GHZ];
  531. sband->band = NL80211_BAND_5GHZ;
  532. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  533. sband->n_bitrates = N_RATES_52;
  534. n_used += iwl_init_sband_channels(data, sband, n_channels,
  535. NL80211_BAND_5GHZ);
  536. iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, NL80211_BAND_5GHZ,
  537. tx_chains, rx_chains);
  538. if (data->sku_cap_11ac_enable && !iwlwifi_mod_params.disable_11ac)
  539. iwl_init_vht_hw_capab(cfg, data, &sband->vht_cap,
  540. tx_chains, rx_chains);
  541. if (data->sku_cap_11ax_enable && !iwlwifi_mod_params.disable_11ax)
  542. iwl_init_he_hw_capab(sband, tx_chains, rx_chains);
  543. if (n_channels != n_used)
  544. IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n",
  545. n_used, n_channels);
  546. }
  547. static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  548. const __le16 *phy_sku)
  549. {
  550. if (cfg->nvm_type != IWL_NVM_EXT)
  551. return le16_to_cpup(nvm_sw + SKU);
  552. return le32_to_cpup((__le32 *)(phy_sku + SKU_FAMILY_8000));
  553. }
  554. static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  555. {
  556. if (cfg->nvm_type != IWL_NVM_EXT)
  557. return le16_to_cpup(nvm_sw + NVM_VERSION);
  558. else
  559. return le32_to_cpup((__le32 *)(nvm_sw +
  560. NVM_VERSION_EXT_NVM));
  561. }
  562. static int iwl_get_radio_cfg(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  563. const __le16 *phy_sku)
  564. {
  565. if (cfg->nvm_type != IWL_NVM_EXT)
  566. return le16_to_cpup(nvm_sw + RADIO_CFG);
  567. return le32_to_cpup((__le32 *)(phy_sku + RADIO_CFG_FAMILY_EXT_NVM));
  568. }
  569. static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  570. {
  571. int n_hw_addr;
  572. if (cfg->nvm_type != IWL_NVM_EXT)
  573. return le16_to_cpup(nvm_sw + N_HW_ADDRS);
  574. n_hw_addr = le32_to_cpup((__le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000));
  575. return n_hw_addr & N_HW_ADDR_MASK;
  576. }
  577. static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
  578. struct iwl_nvm_data *data,
  579. u32 radio_cfg)
  580. {
  581. if (cfg->nvm_type != IWL_NVM_EXT) {
  582. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg);
  583. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg);
  584. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg);
  585. data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg);
  586. return;
  587. }
  588. /* set the radio configuration for family 8000 */
  589. data->radio_cfg_type = EXT_NVM_RF_CFG_TYPE_MSK(radio_cfg);
  590. data->radio_cfg_step = EXT_NVM_RF_CFG_STEP_MSK(radio_cfg);
  591. data->radio_cfg_dash = EXT_NVM_RF_CFG_DASH_MSK(radio_cfg);
  592. data->radio_cfg_pnum = EXT_NVM_RF_CFG_FLAVOR_MSK(radio_cfg);
  593. data->valid_tx_ant = EXT_NVM_RF_CFG_TX_ANT_MSK(radio_cfg);
  594. data->valid_rx_ant = EXT_NVM_RF_CFG_RX_ANT_MSK(radio_cfg);
  595. }
  596. static void iwl_flip_hw_address(__le32 mac_addr0, __le32 mac_addr1, u8 *dest)
  597. {
  598. const u8 *hw_addr;
  599. hw_addr = (const u8 *)&mac_addr0;
  600. dest[0] = hw_addr[3];
  601. dest[1] = hw_addr[2];
  602. dest[2] = hw_addr[1];
  603. dest[3] = hw_addr[0];
  604. hw_addr = (const u8 *)&mac_addr1;
  605. dest[4] = hw_addr[1];
  606. dest[5] = hw_addr[0];
  607. }
  608. static void iwl_set_hw_address_from_csr(struct iwl_trans *trans,
  609. struct iwl_nvm_data *data)
  610. {
  611. __le32 mac_addr0 =
  612. cpu_to_le32(iwl_read32(trans,
  613. trans->cfg->csr->mac_addr0_strap));
  614. __le32 mac_addr1 =
  615. cpu_to_le32(iwl_read32(trans,
  616. trans->cfg->csr->mac_addr1_strap));
  617. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  618. /*
  619. * If the OEM fused a valid address, use it instead of the one in the
  620. * OTP
  621. */
  622. if (is_valid_ether_addr(data->hw_addr))
  623. return;
  624. mac_addr0 = cpu_to_le32(iwl_read32(trans,
  625. trans->cfg->csr->mac_addr0_otp));
  626. mac_addr1 = cpu_to_le32(iwl_read32(trans,
  627. trans->cfg->csr->mac_addr1_otp));
  628. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  629. }
  630. static void iwl_set_hw_address_family_8000(struct iwl_trans *trans,
  631. const struct iwl_cfg *cfg,
  632. struct iwl_nvm_data *data,
  633. const __le16 *mac_override,
  634. const __be16 *nvm_hw)
  635. {
  636. const u8 *hw_addr;
  637. if (mac_override) {
  638. static const u8 reserved_mac[] = {
  639. 0x02, 0xcc, 0xaa, 0xff, 0xee, 0x00
  640. };
  641. hw_addr = (const u8 *)(mac_override +
  642. MAC_ADDRESS_OVERRIDE_EXT_NVM);
  643. /*
  644. * Store the MAC address from MAO section.
  645. * No byte swapping is required in MAO section
  646. */
  647. memcpy(data->hw_addr, hw_addr, ETH_ALEN);
  648. /*
  649. * Force the use of the OTP MAC address in case of reserved MAC
  650. * address in the NVM, or if address is given but invalid.
  651. */
  652. if (is_valid_ether_addr(data->hw_addr) &&
  653. memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0)
  654. return;
  655. IWL_ERR(trans,
  656. "mac address from nvm override section is not valid\n");
  657. }
  658. if (nvm_hw) {
  659. /* read the mac address from WFMP registers */
  660. __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans,
  661. WFMP_MAC_ADDR_0));
  662. __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans,
  663. WFMP_MAC_ADDR_1));
  664. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  665. return;
  666. }
  667. IWL_ERR(trans, "mac address is not found\n");
  668. }
  669. static int iwl_set_hw_address(struct iwl_trans *trans,
  670. const struct iwl_cfg *cfg,
  671. struct iwl_nvm_data *data, const __be16 *nvm_hw,
  672. const __le16 *mac_override)
  673. {
  674. if (cfg->mac_addr_from_csr) {
  675. iwl_set_hw_address_from_csr(trans, data);
  676. } else if (cfg->nvm_type != IWL_NVM_EXT) {
  677. const u8 *hw_addr = (const u8 *)(nvm_hw + HW_ADDR);
  678. /* The byte order is little endian 16 bit, meaning 214365 */
  679. data->hw_addr[0] = hw_addr[1];
  680. data->hw_addr[1] = hw_addr[0];
  681. data->hw_addr[2] = hw_addr[3];
  682. data->hw_addr[3] = hw_addr[2];
  683. data->hw_addr[4] = hw_addr[5];
  684. data->hw_addr[5] = hw_addr[4];
  685. } else {
  686. iwl_set_hw_address_family_8000(trans, cfg, data,
  687. mac_override, nvm_hw);
  688. }
  689. if (!is_valid_ether_addr(data->hw_addr)) {
  690. IWL_ERR(trans, "no valid mac address was found\n");
  691. return -EINVAL;
  692. }
  693. IWL_INFO(trans, "base HW address: %pM\n", data->hw_addr);
  694. return 0;
  695. }
  696. static bool
  697. iwl_nvm_no_wide_in_5ghz(struct device *dev, const struct iwl_cfg *cfg,
  698. const __be16 *nvm_hw)
  699. {
  700. /*
  701. * Workaround a bug in Indonesia SKUs where the regulatory in
  702. * some 7000-family OTPs erroneously allow wide channels in
  703. * 5GHz. To check for Indonesia, we take the SKU value from
  704. * bits 1-4 in the subsystem ID and check if it is either 5 or
  705. * 9. In those cases, we need to force-disable wide channels
  706. * in 5GHz otherwise the FW will throw a sysassert when we try
  707. * to use them.
  708. */
  709. if (cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  710. /*
  711. * Unlike the other sections in the NVM, the hw
  712. * section uses big-endian.
  713. */
  714. u16 subsystem_id = be16_to_cpup(nvm_hw + SUBSYSTEM_ID);
  715. u8 sku = (subsystem_id & 0x1e) >> 1;
  716. if (sku == 5 || sku == 9) {
  717. IWL_DEBUG_EEPROM(dev,
  718. "disabling wide channels in 5GHz (0x%0x %d)\n",
  719. subsystem_id, sku);
  720. return true;
  721. }
  722. }
  723. return false;
  724. }
  725. struct iwl_nvm_data *
  726. iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  727. const __be16 *nvm_hw, const __le16 *nvm_sw,
  728. const __le16 *nvm_calib, const __le16 *regulatory,
  729. const __le16 *mac_override, const __le16 *phy_sku,
  730. u8 tx_chains, u8 rx_chains, bool lar_fw_supported)
  731. {
  732. struct device *dev = trans->dev;
  733. struct iwl_nvm_data *data;
  734. bool lar_enabled;
  735. u32 sku, radio_cfg;
  736. u32 sbands_flags = 0;
  737. u16 lar_config;
  738. const __le16 *ch_section;
  739. if (cfg->nvm_type != IWL_NVM_EXT)
  740. data = kzalloc(sizeof(*data) +
  741. sizeof(struct ieee80211_channel) *
  742. IWL_NVM_NUM_CHANNELS,
  743. GFP_KERNEL);
  744. else
  745. data = kzalloc(sizeof(*data) +
  746. sizeof(struct ieee80211_channel) *
  747. IWL_NVM_NUM_CHANNELS_EXT,
  748. GFP_KERNEL);
  749. if (!data)
  750. return NULL;
  751. data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw);
  752. radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw, phy_sku);
  753. iwl_set_radio_cfg(cfg, data, radio_cfg);
  754. if (data->valid_tx_ant)
  755. tx_chains &= data->valid_tx_ant;
  756. if (data->valid_rx_ant)
  757. rx_chains &= data->valid_rx_ant;
  758. sku = iwl_get_sku(cfg, nvm_sw, phy_sku);
  759. data->sku_cap_band_24ghz_enable = sku & NVM_SKU_CAP_BAND_24GHZ;
  760. data->sku_cap_band_52ghz_enable = sku & NVM_SKU_CAP_BAND_52GHZ;
  761. data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE;
  762. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  763. data->sku_cap_11n_enable = false;
  764. data->sku_cap_11ac_enable = data->sku_cap_11n_enable &&
  765. (sku & NVM_SKU_CAP_11AC_ENABLE);
  766. data->sku_cap_mimo_disabled = sku & NVM_SKU_CAP_MIMO_DISABLE;
  767. data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
  768. if (cfg->nvm_type != IWL_NVM_EXT) {
  769. /* Checking for required sections */
  770. if (!nvm_calib) {
  771. IWL_ERR(trans,
  772. "Can't parse empty Calib NVM sections\n");
  773. kfree(data);
  774. return NULL;
  775. }
  776. ch_section = cfg->nvm_type == IWL_NVM_SDP ?
  777. &regulatory[NVM_CHANNELS_SDP] :
  778. &nvm_sw[NVM_CHANNELS];
  779. /* in family 8000 Xtal calibration values moved to OTP */
  780. data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
  781. data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
  782. lar_enabled = true;
  783. } else {
  784. u16 lar_offset = data->nvm_version < 0xE39 ?
  785. NVM_LAR_OFFSET_OLD :
  786. NVM_LAR_OFFSET;
  787. lar_config = le16_to_cpup(regulatory + lar_offset);
  788. data->lar_enabled = !!(lar_config &
  789. NVM_LAR_ENABLED);
  790. lar_enabled = data->lar_enabled;
  791. ch_section = &regulatory[NVM_CHANNELS_EXTENDED];
  792. }
  793. /* If no valid mac address was found - bail out */
  794. if (iwl_set_hw_address(trans, cfg, data, nvm_hw, mac_override)) {
  795. kfree(data);
  796. return NULL;
  797. }
  798. if (lar_fw_supported && lar_enabled)
  799. sbands_flags |= IWL_NVM_SBANDS_FLAGS_LAR;
  800. if (iwl_nvm_no_wide_in_5ghz(dev, cfg, nvm_hw))
  801. sbands_flags |= IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ;
  802. iwl_init_sbands(dev, cfg, data, ch_section, tx_chains, rx_chains,
  803. sbands_flags);
  804. data->calib_version = 255;
  805. return data;
  806. }
  807. IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);
  808. static u32 iwl_nvm_get_regdom_bw_flags(const u8 *nvm_chan,
  809. int ch_idx, u16 nvm_flags,
  810. const struct iwl_cfg *cfg)
  811. {
  812. u32 flags = NL80211_RRF_NO_HT40;
  813. u32 last_5ghz_ht = LAST_5GHZ_HT;
  814. if (cfg->nvm_type == IWL_NVM_EXT)
  815. last_5ghz_ht = LAST_5GHZ_HT_FAMILY_8000;
  816. if (ch_idx < NUM_2GHZ_CHANNELS &&
  817. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  818. if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS)
  819. flags &= ~NL80211_RRF_NO_HT40PLUS;
  820. if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS)
  821. flags &= ~NL80211_RRF_NO_HT40MINUS;
  822. } else if (nvm_chan[ch_idx] <= last_5ghz_ht &&
  823. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  824. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  825. flags &= ~NL80211_RRF_NO_HT40PLUS;
  826. else
  827. flags &= ~NL80211_RRF_NO_HT40MINUS;
  828. }
  829. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  830. flags |= NL80211_RRF_NO_80MHZ;
  831. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  832. flags |= NL80211_RRF_NO_160MHZ;
  833. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  834. flags |= NL80211_RRF_NO_IR;
  835. if (nvm_flags & NVM_CHANNEL_RADAR)
  836. flags |= NL80211_RRF_DFS;
  837. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  838. flags |= NL80211_RRF_NO_OUTDOOR;
  839. /* Set the GO concurrent flag only in case that NO_IR is set.
  840. * Otherwise it is meaningless
  841. */
  842. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  843. (flags & NL80211_RRF_NO_IR))
  844. flags |= NL80211_RRF_GO_CONCURRENT;
  845. return flags;
  846. }
  847. struct regdb_ptrs {
  848. struct ieee80211_wmm_rule *rule;
  849. u32 token;
  850. };
  851. struct ieee80211_regdomain *
  852. iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
  853. int num_of_ch, __le32 *channels, u16 fw_mcc,
  854. u16 geo_info)
  855. {
  856. int ch_idx;
  857. u16 ch_flags;
  858. u32 reg_rule_flags, prev_reg_rule_flags = 0;
  859. const u8 *nvm_chan = cfg->nvm_type == IWL_NVM_EXT ?
  860. iwl_ext_nvm_channels : iwl_nvm_channels;
  861. struct ieee80211_regdomain *regd, *copy_rd;
  862. int size_of_regd, regd_to_copy;
  863. struct ieee80211_reg_rule *rule;
  864. struct regdb_ptrs *regdb_ptrs;
  865. enum nl80211_band band;
  866. int center_freq, prev_center_freq = 0;
  867. int valid_rules = 0;
  868. bool new_rule;
  869. int max_num_ch = cfg->nvm_type == IWL_NVM_EXT ?
  870. IWL_NVM_NUM_CHANNELS_EXT : IWL_NVM_NUM_CHANNELS;
  871. if (WARN_ON_ONCE(num_of_ch > NL80211_MAX_SUPP_REG_RULES))
  872. return ERR_PTR(-EINVAL);
  873. if (WARN_ON(num_of_ch > max_num_ch))
  874. num_of_ch = max_num_ch;
  875. IWL_DEBUG_DEV(dev, IWL_DL_LAR, "building regdom for %d channels\n",
  876. num_of_ch);
  877. /* build a regdomain rule for every valid channel */
  878. size_of_regd =
  879. sizeof(struct ieee80211_regdomain) +
  880. num_of_ch * sizeof(struct ieee80211_reg_rule);
  881. regd = kzalloc(size_of_regd, GFP_KERNEL);
  882. if (!regd)
  883. return ERR_PTR(-ENOMEM);
  884. regdb_ptrs = kcalloc(num_of_ch, sizeof(*regdb_ptrs), GFP_KERNEL);
  885. if (!regdb_ptrs) {
  886. copy_rd = ERR_PTR(-ENOMEM);
  887. goto out;
  888. }
  889. /* set alpha2 from FW. */
  890. regd->alpha2[0] = fw_mcc >> 8;
  891. regd->alpha2[1] = fw_mcc & 0xff;
  892. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  893. ch_flags = (u16)__le32_to_cpup(channels + ch_idx);
  894. band = (ch_idx < NUM_2GHZ_CHANNELS) ?
  895. NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
  896. center_freq = ieee80211_channel_to_frequency(nvm_chan[ch_idx],
  897. band);
  898. new_rule = false;
  899. if (!(ch_flags & NVM_CHANNEL_VALID)) {
  900. iwl_nvm_print_channel_flags(dev, IWL_DL_LAR,
  901. nvm_chan[ch_idx], ch_flags);
  902. continue;
  903. }
  904. reg_rule_flags = iwl_nvm_get_regdom_bw_flags(nvm_chan, ch_idx,
  905. ch_flags, cfg);
  906. /* we can't continue the same rule */
  907. if (ch_idx == 0 || prev_reg_rule_flags != reg_rule_flags ||
  908. center_freq - prev_center_freq > 20) {
  909. valid_rules++;
  910. new_rule = true;
  911. }
  912. rule = &regd->reg_rules[valid_rules - 1];
  913. if (new_rule)
  914. rule->freq_range.start_freq_khz =
  915. MHZ_TO_KHZ(center_freq - 10);
  916. rule->freq_range.end_freq_khz = MHZ_TO_KHZ(center_freq + 10);
  917. /* this doesn't matter - not used by FW */
  918. rule->power_rule.max_antenna_gain = DBI_TO_MBI(6);
  919. rule->power_rule.max_eirp =
  920. DBM_TO_MBM(IWL_DEFAULT_MAX_TX_POWER);
  921. rule->flags = reg_rule_flags;
  922. /* rely on auto-calculation to merge BW of contiguous chans */
  923. rule->flags |= NL80211_RRF_AUTO_BW;
  924. rule->freq_range.max_bandwidth_khz = 0;
  925. prev_center_freq = center_freq;
  926. prev_reg_rule_flags = reg_rule_flags;
  927. iwl_nvm_print_channel_flags(dev, IWL_DL_LAR,
  928. nvm_chan[ch_idx], ch_flags);
  929. if (!(geo_info & GEO_WMM_ETSI_5GHZ_INFO) ||
  930. band == NL80211_BAND_2GHZ)
  931. continue;
  932. reg_query_regdb_wmm(regd->alpha2, center_freq, rule);
  933. }
  934. regd->n_reg_rules = valid_rules;
  935. /*
  936. * Narrow down regdom for unused regulatory rules to prevent hole
  937. * between reg rules to wmm rules.
  938. */
  939. regd_to_copy = sizeof(struct ieee80211_regdomain) +
  940. valid_rules * sizeof(struct ieee80211_reg_rule);
  941. copy_rd = kzalloc(regd_to_copy, GFP_KERNEL);
  942. if (!copy_rd) {
  943. copy_rd = ERR_PTR(-ENOMEM);
  944. goto out;
  945. }
  946. memcpy(copy_rd, regd, regd_to_copy);
  947. out:
  948. kfree(regdb_ptrs);
  949. kfree(regd);
  950. return copy_rd;
  951. }
  952. IWL_EXPORT_SYMBOL(iwl_parse_nvm_mcc_info);
  953. #define IWL_MAX_NVM_SECTION_SIZE 0x1b58
  954. #define IWL_MAX_EXT_NVM_SECTION_SIZE 0x1ffc
  955. #define MAX_NVM_FILE_LEN 16384
  956. void iwl_nvm_fixups(u32 hw_id, unsigned int section, u8 *data,
  957. unsigned int len)
  958. {
  959. #define IWL_4165_DEVICE_ID 0x5501
  960. #define NVM_SKU_CAP_MIMO_DISABLE BIT(5)
  961. if (section == NVM_SECTION_TYPE_PHY_SKU &&
  962. hw_id == IWL_4165_DEVICE_ID && data && len >= 5 &&
  963. (data[4] & NVM_SKU_CAP_MIMO_DISABLE))
  964. /* OTP 0x52 bug work around: it's a 1x1 device */
  965. data[3] = ANT_B | (ANT_B << 4);
  966. }
  967. IWL_EXPORT_SYMBOL(iwl_nvm_fixups);
  968. /*
  969. * Reads external NVM from a file into mvm->nvm_sections
  970. *
  971. * HOW TO CREATE THE NVM FILE FORMAT:
  972. * ------------------------------
  973. * 1. create hex file, format:
  974. * 3800 -> header
  975. * 0000 -> header
  976. * 5a40 -> data
  977. *
  978. * rev - 6 bit (word1)
  979. * len - 10 bit (word1)
  980. * id - 4 bit (word2)
  981. * rsv - 12 bit (word2)
  982. *
  983. * 2. flip 8bits with 8 bits per line to get the right NVM file format
  984. *
  985. * 3. create binary file from the hex file
  986. *
  987. * 4. save as "iNVM_xxx.bin" under /lib/firmware
  988. */
  989. int iwl_read_external_nvm(struct iwl_trans *trans,
  990. const char *nvm_file_name,
  991. struct iwl_nvm_section *nvm_sections)
  992. {
  993. int ret, section_size;
  994. u16 section_id;
  995. const struct firmware *fw_entry;
  996. const struct {
  997. __le16 word1;
  998. __le16 word2;
  999. u8 data[];
  1000. } *file_sec;
  1001. const u8 *eof;
  1002. u8 *temp;
  1003. int max_section_size;
  1004. const __le32 *dword_buff;
  1005. #define NVM_WORD1_LEN(x) (8 * (x & 0x03FF))
  1006. #define NVM_WORD2_ID(x) (x >> 12)
  1007. #define EXT_NVM_WORD2_LEN(x) (2 * (((x) & 0xFF) << 8 | (x) >> 8))
  1008. #define EXT_NVM_WORD1_ID(x) ((x) >> 4)
  1009. #define NVM_HEADER_0 (0x2A504C54)
  1010. #define NVM_HEADER_1 (0x4E564D2A)
  1011. #define NVM_HEADER_SIZE (4 * sizeof(u32))
  1012. IWL_DEBUG_EEPROM(trans->dev, "Read from external NVM\n");
  1013. /* Maximal size depends on NVM version */
  1014. if (trans->cfg->nvm_type != IWL_NVM_EXT)
  1015. max_section_size = IWL_MAX_NVM_SECTION_SIZE;
  1016. else
  1017. max_section_size = IWL_MAX_EXT_NVM_SECTION_SIZE;
  1018. /*
  1019. * Obtain NVM image via request_firmware. Since we already used
  1020. * request_firmware_nowait() for the firmware binary load and only
  1021. * get here after that we assume the NVM request can be satisfied
  1022. * synchronously.
  1023. */
  1024. ret = request_firmware(&fw_entry, nvm_file_name, trans->dev);
  1025. if (ret) {
  1026. IWL_ERR(trans, "ERROR: %s isn't available %d\n",
  1027. nvm_file_name, ret);
  1028. return ret;
  1029. }
  1030. IWL_INFO(trans, "Loaded NVM file %s (%zu bytes)\n",
  1031. nvm_file_name, fw_entry->size);
  1032. if (fw_entry->size > MAX_NVM_FILE_LEN) {
  1033. IWL_ERR(trans, "NVM file too large\n");
  1034. ret = -EINVAL;
  1035. goto out;
  1036. }
  1037. eof = fw_entry->data + fw_entry->size;
  1038. dword_buff = (__le32 *)fw_entry->data;
  1039. /* some NVM file will contain a header.
  1040. * The header is identified by 2 dwords header as follow:
  1041. * dword[0] = 0x2A504C54
  1042. * dword[1] = 0x4E564D2A
  1043. *
  1044. * This header must be skipped when providing the NVM data to the FW.
  1045. */
  1046. if (fw_entry->size > NVM_HEADER_SIZE &&
  1047. dword_buff[0] == cpu_to_le32(NVM_HEADER_0) &&
  1048. dword_buff[1] == cpu_to_le32(NVM_HEADER_1)) {
  1049. file_sec = (void *)(fw_entry->data + NVM_HEADER_SIZE);
  1050. IWL_INFO(trans, "NVM Version %08X\n", le32_to_cpu(dword_buff[2]));
  1051. IWL_INFO(trans, "NVM Manufacturing date %08X\n",
  1052. le32_to_cpu(dword_buff[3]));
  1053. /* nvm file validation, dword_buff[2] holds the file version */
  1054. if (trans->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  1055. CSR_HW_REV_STEP(trans->hw_rev) == SILICON_C_STEP &&
  1056. le32_to_cpu(dword_buff[2]) < 0xE4A) {
  1057. ret = -EFAULT;
  1058. goto out;
  1059. }
  1060. } else {
  1061. file_sec = (void *)fw_entry->data;
  1062. }
  1063. while (true) {
  1064. if (file_sec->data > eof) {
  1065. IWL_ERR(trans,
  1066. "ERROR - NVM file too short for section header\n");
  1067. ret = -EINVAL;
  1068. break;
  1069. }
  1070. /* check for EOF marker */
  1071. if (!file_sec->word1 && !file_sec->word2) {
  1072. ret = 0;
  1073. break;
  1074. }
  1075. if (trans->cfg->nvm_type != IWL_NVM_EXT) {
  1076. section_size =
  1077. 2 * NVM_WORD1_LEN(le16_to_cpu(file_sec->word1));
  1078. section_id = NVM_WORD2_ID(le16_to_cpu(file_sec->word2));
  1079. } else {
  1080. section_size = 2 * EXT_NVM_WORD2_LEN(
  1081. le16_to_cpu(file_sec->word2));
  1082. section_id = EXT_NVM_WORD1_ID(
  1083. le16_to_cpu(file_sec->word1));
  1084. }
  1085. if (section_size > max_section_size) {
  1086. IWL_ERR(trans, "ERROR - section too large (%d)\n",
  1087. section_size);
  1088. ret = -EINVAL;
  1089. break;
  1090. }
  1091. if (!section_size) {
  1092. IWL_ERR(trans, "ERROR - section empty\n");
  1093. ret = -EINVAL;
  1094. break;
  1095. }
  1096. if (file_sec->data + section_size > eof) {
  1097. IWL_ERR(trans,
  1098. "ERROR - NVM file too short for section (%d bytes)\n",
  1099. section_size);
  1100. ret = -EINVAL;
  1101. break;
  1102. }
  1103. if (WARN(section_id >= NVM_MAX_NUM_SECTIONS,
  1104. "Invalid NVM section ID %d\n", section_id)) {
  1105. ret = -EINVAL;
  1106. break;
  1107. }
  1108. temp = kmemdup(file_sec->data, section_size, GFP_KERNEL);
  1109. if (!temp) {
  1110. ret = -ENOMEM;
  1111. break;
  1112. }
  1113. iwl_nvm_fixups(trans->hw_id, section_id, temp, section_size);
  1114. kfree(nvm_sections[section_id].data);
  1115. nvm_sections[section_id].data = temp;
  1116. nvm_sections[section_id].length = section_size;
  1117. /* advance to the next section */
  1118. file_sec = (void *)(file_sec->data + section_size);
  1119. }
  1120. out:
  1121. release_firmware(fw_entry);
  1122. return ret;
  1123. }
  1124. IWL_EXPORT_SYMBOL(iwl_read_external_nvm);
  1125. struct iwl_nvm_data *iwl_get_nvm(struct iwl_trans *trans,
  1126. const struct iwl_fw *fw)
  1127. {
  1128. struct iwl_nvm_get_info cmd = {};
  1129. struct iwl_nvm_get_info_rsp *rsp;
  1130. struct iwl_nvm_data *nvm;
  1131. struct iwl_host_cmd hcmd = {
  1132. .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  1133. .data = { &cmd, },
  1134. .len = { sizeof(cmd) },
  1135. .id = WIDE_ID(REGULATORY_AND_NVM_GROUP, NVM_GET_INFO)
  1136. };
  1137. int ret;
  1138. bool lar_fw_supported = !iwlwifi_mod_params.lar_disable &&
  1139. fw_has_capa(&fw->ucode_capa,
  1140. IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
  1141. u32 mac_flags;
  1142. u32 sbands_flags = 0;
  1143. ret = iwl_trans_send_cmd(trans, &hcmd);
  1144. if (ret)
  1145. return ERR_PTR(ret);
  1146. if (WARN(iwl_rx_packet_payload_len(hcmd.resp_pkt) != sizeof(*rsp),
  1147. "Invalid payload len in NVM response from FW %d",
  1148. iwl_rx_packet_payload_len(hcmd.resp_pkt))) {
  1149. ret = -EINVAL;
  1150. goto out;
  1151. }
  1152. rsp = (void *)hcmd.resp_pkt->data;
  1153. if (le32_to_cpu(rsp->general.flags) & NVM_GENERAL_FLAGS_EMPTY_OTP)
  1154. IWL_INFO(trans, "OTP is empty\n");
  1155. nvm = kzalloc(sizeof(*nvm) +
  1156. sizeof(struct ieee80211_channel) * IWL_NUM_CHANNELS,
  1157. GFP_KERNEL);
  1158. if (!nvm) {
  1159. ret = -ENOMEM;
  1160. goto out;
  1161. }
  1162. iwl_set_hw_address_from_csr(trans, nvm);
  1163. /* TODO: if platform NVM has MAC address - override it here */
  1164. if (!is_valid_ether_addr(nvm->hw_addr)) {
  1165. IWL_ERR(trans, "no valid mac address was found\n");
  1166. ret = -EINVAL;
  1167. goto err_free;
  1168. }
  1169. IWL_INFO(trans, "base HW address: %pM\n", nvm->hw_addr);
  1170. /* Initialize general data */
  1171. nvm->nvm_version = le16_to_cpu(rsp->general.nvm_version);
  1172. /* Initialize MAC sku data */
  1173. mac_flags = le32_to_cpu(rsp->mac_sku.mac_sku_flags);
  1174. nvm->sku_cap_11ac_enable =
  1175. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11AC_ENABLED);
  1176. nvm->sku_cap_11n_enable =
  1177. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11N_ENABLED);
  1178. nvm->sku_cap_11ax_enable =
  1179. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11AX_ENABLED);
  1180. nvm->sku_cap_band_24ghz_enable =
  1181. !!(mac_flags & NVM_MAC_SKU_FLAGS_BAND_2_4_ENABLED);
  1182. nvm->sku_cap_band_52ghz_enable =
  1183. !!(mac_flags & NVM_MAC_SKU_FLAGS_BAND_5_2_ENABLED);
  1184. nvm->sku_cap_mimo_disabled =
  1185. !!(mac_flags & NVM_MAC_SKU_FLAGS_MIMO_DISABLED);
  1186. /* Initialize PHY sku data */
  1187. nvm->valid_tx_ant = (u8)le32_to_cpu(rsp->phy_sku.tx_chains);
  1188. nvm->valid_rx_ant = (u8)le32_to_cpu(rsp->phy_sku.rx_chains);
  1189. if (le32_to_cpu(rsp->regulatory.lar_enabled) && lar_fw_supported) {
  1190. nvm->lar_enabled = true;
  1191. sbands_flags |= IWL_NVM_SBANDS_FLAGS_LAR;
  1192. }
  1193. iwl_init_sbands(trans->dev, trans->cfg, nvm,
  1194. rsp->regulatory.channel_profile,
  1195. nvm->valid_tx_ant & fw->valid_tx_ant,
  1196. nvm->valid_rx_ant & fw->valid_rx_ant,
  1197. sbands_flags);
  1198. iwl_free_resp(&hcmd);
  1199. return nvm;
  1200. err_free:
  1201. kfree(nvm);
  1202. out:
  1203. iwl_free_resp(&hcmd);
  1204. return ERR_PTR(ret);
  1205. }
  1206. IWL_EXPORT_SYMBOL(iwl_get_nvm);