iwl-nvm-parse.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  1. // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  2. /*
  3. * Copyright (C) 2005-2014, 2018-2021 Intel Corporation
  4. * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
  5. * Copyright (C) 2016-2017 Intel Deutschland GmbH
  6. */
  7. #include <linux/types.h>
  8. #include <linux/slab.h>
  9. #include <linux/export.h>
  10. #include <linux/etherdevice.h>
  11. #include <linux/pci.h>
  12. #include <linux/firmware.h>
  13. #include "iwl-drv.h"
  14. #include "iwl-modparams.h"
  15. #include "iwl-nvm-parse.h"
  16. #include "iwl-prph.h"
  17. #include "iwl-io.h"
  18. #include "iwl-csr.h"
  19. #include "fw/acpi.h"
  20. #include "fw/api/nvm-reg.h"
  21. #include "fw/api/commands.h"
  22. #include "fw/api/cmdhdr.h"
  23. #include "fw/img.h"
  24. #include "mei/iwl-mei.h"
  25. /* NVM offsets (in words) definitions */
  26. enum nvm_offsets {
  27. /* NVM HW-Section offset (in words) definitions */
  28. SUBSYSTEM_ID = 0x0A,
  29. HW_ADDR = 0x15,
  30. /* NVM SW-Section offset (in words) definitions */
  31. NVM_SW_SECTION = 0x1C0,
  32. NVM_VERSION = 0,
  33. RADIO_CFG = 1,
  34. SKU = 2,
  35. N_HW_ADDRS = 3,
  36. NVM_CHANNELS = 0x1E0 - NVM_SW_SECTION,
  37. /* NVM calibration section offset (in words) definitions */
  38. NVM_CALIB_SECTION = 0x2B8,
  39. XTAL_CALIB = 0x316 - NVM_CALIB_SECTION,
  40. /* NVM REGULATORY -Section offset (in words) definitions */
  41. NVM_CHANNELS_SDP = 0,
  42. };
  43. enum ext_nvm_offsets {
  44. /* NVM HW-Section offset (in words) definitions */
  45. MAC_ADDRESS_OVERRIDE_EXT_NVM = 1,
  46. /* NVM SW-Section offset (in words) definitions */
  47. NVM_VERSION_EXT_NVM = 0,
  48. N_HW_ADDRS_FAMILY_8000 = 3,
  49. /* NVM PHY_SKU-Section offset (in words) definitions */
  50. RADIO_CFG_FAMILY_EXT_NVM = 0,
  51. SKU_FAMILY_8000 = 2,
  52. /* NVM REGULATORY -Section offset (in words) definitions */
  53. NVM_CHANNELS_EXTENDED = 0,
  54. NVM_LAR_OFFSET_OLD = 0x4C7,
  55. NVM_LAR_OFFSET = 0x507,
  56. NVM_LAR_ENABLED = 0x7,
  57. };
  58. /* SKU Capabilities (actual values from NVM definition) */
  59. enum nvm_sku_bits {
  60. NVM_SKU_CAP_BAND_24GHZ = BIT(0),
  61. NVM_SKU_CAP_BAND_52GHZ = BIT(1),
  62. NVM_SKU_CAP_11N_ENABLE = BIT(2),
  63. NVM_SKU_CAP_11AC_ENABLE = BIT(3),
  64. NVM_SKU_CAP_MIMO_DISABLE = BIT(5),
  65. };
  66. /*
  67. * These are the channel numbers in the order that they are stored in the NVM
  68. */
  69. static const u16 iwl_nvm_channels[] = {
  70. /* 2.4 GHz */
  71. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  72. /* 5 GHz */
  73. 36, 40, 44 , 48, 52, 56, 60, 64,
  74. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  75. 149, 153, 157, 161, 165
  76. };
  77. static const u16 iwl_ext_nvm_channels[] = {
  78. /* 2.4 GHz */
  79. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  80. /* 5 GHz */
  81. 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92,
  82. 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  83. 149, 153, 157, 161, 165, 169, 173, 177, 181
  84. };
  85. static const u16 iwl_uhb_nvm_channels[] = {
  86. /* 2.4 GHz */
  87. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  88. /* 5 GHz */
  89. 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92,
  90. 96, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,
  91. 149, 153, 157, 161, 165, 169, 173, 177, 181,
  92. /* 6-7 GHz */
  93. 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69,
  94. 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 129,
  95. 133, 137, 141, 145, 149, 153, 157, 161, 165, 169, 173, 177, 181, 185,
  96. 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 233
  97. };
  98. #define IWL_NVM_NUM_CHANNELS ARRAY_SIZE(iwl_nvm_channels)
  99. #define IWL_NVM_NUM_CHANNELS_EXT ARRAY_SIZE(iwl_ext_nvm_channels)
  100. #define IWL_NVM_NUM_CHANNELS_UHB ARRAY_SIZE(iwl_uhb_nvm_channels)
  101. #define NUM_2GHZ_CHANNELS 14
  102. #define NUM_5GHZ_CHANNELS 37
  103. #define FIRST_2GHZ_HT_MINUS 5
  104. #define LAST_2GHZ_HT_PLUS 9
  105. #define N_HW_ADDR_MASK 0xF
  106. /* rate data (static) */
  107. static struct ieee80211_rate iwl_cfg80211_rates[] = {
  108. { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
  109. { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
  110. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  111. { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
  112. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  113. { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
  114. .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
  115. { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
  116. { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
  117. { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
  118. { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
  119. { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
  120. { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
  121. { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
  122. { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
  123. };
  124. #define RATES_24_OFFS 0
  125. #define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
  126. #define RATES_52_OFFS 4
  127. #define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
  128. /**
  129. * enum iwl_nvm_channel_flags - channel flags in NVM
  130. * @NVM_CHANNEL_VALID: channel is usable for this SKU/geo
  131. * @NVM_CHANNEL_IBSS: usable as an IBSS channel
  132. * @NVM_CHANNEL_ACTIVE: active scanning allowed
  133. * @NVM_CHANNEL_RADAR: radar detection required
  134. * @NVM_CHANNEL_INDOOR_ONLY: only indoor use is allowed
  135. * @NVM_CHANNEL_GO_CONCURRENT: GO operation is allowed when connected to BSS
  136. * on same channel on 2.4 or same UNII band on 5.2
  137. * @NVM_CHANNEL_UNIFORM: uniform spreading required
  138. * @NVM_CHANNEL_20MHZ: 20 MHz channel okay
  139. * @NVM_CHANNEL_40MHZ: 40 MHz channel okay
  140. * @NVM_CHANNEL_80MHZ: 80 MHz channel okay
  141. * @NVM_CHANNEL_160MHZ: 160 MHz channel okay
  142. * @NVM_CHANNEL_DC_HIGH: DC HIGH required/allowed (?)
  143. */
  144. enum iwl_nvm_channel_flags {
  145. NVM_CHANNEL_VALID = BIT(0),
  146. NVM_CHANNEL_IBSS = BIT(1),
  147. NVM_CHANNEL_ACTIVE = BIT(3),
  148. NVM_CHANNEL_RADAR = BIT(4),
  149. NVM_CHANNEL_INDOOR_ONLY = BIT(5),
  150. NVM_CHANNEL_GO_CONCURRENT = BIT(6),
  151. NVM_CHANNEL_UNIFORM = BIT(7),
  152. NVM_CHANNEL_20MHZ = BIT(8),
  153. NVM_CHANNEL_40MHZ = BIT(9),
  154. NVM_CHANNEL_80MHZ = BIT(10),
  155. NVM_CHANNEL_160MHZ = BIT(11),
  156. NVM_CHANNEL_DC_HIGH = BIT(12),
  157. };
  158. /**
  159. * enum iwl_reg_capa_flags - global flags applied for the whole regulatory
  160. * domain.
  161. * @REG_CAPA_BF_CCD_LOW_BAND: Beam-forming or Cyclic Delay Diversity in the
  162. * 2.4Ghz band is allowed.
  163. * @REG_CAPA_BF_CCD_HIGH_BAND: Beam-forming or Cyclic Delay Diversity in the
  164. * 5Ghz band is allowed.
  165. * @REG_CAPA_160MHZ_ALLOWED: 11ac channel with a width of 160Mhz is allowed
  166. * for this regulatory domain (valid only in 5Ghz).
  167. * @REG_CAPA_80MHZ_ALLOWED: 11ac channel with a width of 80Mhz is allowed
  168. * for this regulatory domain (valid only in 5Ghz).
  169. * @REG_CAPA_MCS_8_ALLOWED: 11ac with MCS 8 is allowed.
  170. * @REG_CAPA_MCS_9_ALLOWED: 11ac with MCS 9 is allowed.
  171. * @REG_CAPA_40MHZ_FORBIDDEN: 11n channel with a width of 40Mhz is forbidden
  172. * for this regulatory domain (valid only in 5Ghz).
  173. * @REG_CAPA_DC_HIGH_ENABLED: DC HIGH allowed.
  174. * @REG_CAPA_11AX_DISABLED: 11ax is forbidden for this regulatory domain.
  175. */
  176. enum iwl_reg_capa_flags {
  177. REG_CAPA_BF_CCD_LOW_BAND = BIT(0),
  178. REG_CAPA_BF_CCD_HIGH_BAND = BIT(1),
  179. REG_CAPA_160MHZ_ALLOWED = BIT(2),
  180. REG_CAPA_80MHZ_ALLOWED = BIT(3),
  181. REG_CAPA_MCS_8_ALLOWED = BIT(4),
  182. REG_CAPA_MCS_9_ALLOWED = BIT(5),
  183. REG_CAPA_40MHZ_FORBIDDEN = BIT(7),
  184. REG_CAPA_DC_HIGH_ENABLED = BIT(9),
  185. REG_CAPA_11AX_DISABLED = BIT(10),
  186. };
  187. /**
  188. * enum iwl_reg_capa_flags_v2 - global flags applied for the whole regulatory
  189. * domain (version 2).
  190. * @REG_CAPA_V2_STRADDLE_DISABLED: Straddle channels (144, 142, 138) are
  191. * disabled.
  192. * @REG_CAPA_V2_BF_CCD_LOW_BAND: Beam-forming or Cyclic Delay Diversity in the
  193. * 2.4Ghz band is allowed.
  194. * @REG_CAPA_V2_BF_CCD_HIGH_BAND: Beam-forming or Cyclic Delay Diversity in the
  195. * 5Ghz band is allowed.
  196. * @REG_CAPA_V2_160MHZ_ALLOWED: 11ac channel with a width of 160Mhz is allowed
  197. * for this regulatory domain (valid only in 5Ghz).
  198. * @REG_CAPA_V2_80MHZ_ALLOWED: 11ac channel with a width of 80Mhz is allowed
  199. * for this regulatory domain (valid only in 5Ghz).
  200. * @REG_CAPA_V2_MCS_8_ALLOWED: 11ac with MCS 8 is allowed.
  201. * @REG_CAPA_V2_MCS_9_ALLOWED: 11ac with MCS 9 is allowed.
  202. * @REG_CAPA_V2_WEATHER_DISABLED: Weather radar channels (120, 124, 128, 118,
  203. * 126, 122) are disabled.
  204. * @REG_CAPA_V2_40MHZ_ALLOWED: 11n channel with a width of 40Mhz is allowed
  205. * for this regulatory domain (uvalid only in 5Ghz).
  206. * @REG_CAPA_V2_11AX_DISABLED: 11ax is forbidden for this regulatory domain.
  207. */
  208. enum iwl_reg_capa_flags_v2 {
  209. REG_CAPA_V2_STRADDLE_DISABLED = BIT(0),
  210. REG_CAPA_V2_BF_CCD_LOW_BAND = BIT(1),
  211. REG_CAPA_V2_BF_CCD_HIGH_BAND = BIT(2),
  212. REG_CAPA_V2_160MHZ_ALLOWED = BIT(3),
  213. REG_CAPA_V2_80MHZ_ALLOWED = BIT(4),
  214. REG_CAPA_V2_MCS_8_ALLOWED = BIT(5),
  215. REG_CAPA_V2_MCS_9_ALLOWED = BIT(6),
  216. REG_CAPA_V2_WEATHER_DISABLED = BIT(7),
  217. REG_CAPA_V2_40MHZ_ALLOWED = BIT(8),
  218. REG_CAPA_V2_11AX_DISABLED = BIT(10),
  219. };
  220. /*
  221. * API v2 for reg_capa_flags is relevant from version 6 and onwards of the
  222. * MCC update command response.
  223. */
  224. #define REG_CAPA_V2_RESP_VER 6
  225. /**
  226. * struct iwl_reg_capa - struct for global regulatory capabilities, Used for
  227. * handling the different APIs of reg_capa_flags.
  228. *
  229. * @allow_40mhz: 11n channel with a width of 40Mhz is allowed
  230. * for this regulatory domain (valid only in 5Ghz).
  231. * @allow_80mhz: 11ac channel with a width of 80Mhz is allowed
  232. * for this regulatory domain (valid only in 5Ghz).
  233. * @allow_160mhz: 11ac channel with a width of 160Mhz is allowed
  234. * for this regulatory domain (valid only in 5Ghz).
  235. * @disable_11ax: 11ax is forbidden for this regulatory domain.
  236. */
  237. struct iwl_reg_capa {
  238. u16 allow_40mhz;
  239. u16 allow_80mhz;
  240. u16 allow_160mhz;
  241. u16 disable_11ax;
  242. };
  243. static inline void iwl_nvm_print_channel_flags(struct device *dev, u32 level,
  244. int chan, u32 flags)
  245. {
  246. #define CHECK_AND_PRINT_I(x) \
  247. ((flags & NVM_CHANNEL_##x) ? " " #x : "")
  248. if (!(flags & NVM_CHANNEL_VALID)) {
  249. IWL_DEBUG_DEV(dev, level, "Ch. %d: 0x%x: No traffic\n",
  250. chan, flags);
  251. return;
  252. }
  253. /* Note: already can print up to 101 characters, 110 is the limit! */
  254. IWL_DEBUG_DEV(dev, level,
  255. "Ch. %d: 0x%x:%s%s%s%s%s%s%s%s%s%s%s%s\n",
  256. chan, flags,
  257. CHECK_AND_PRINT_I(VALID),
  258. CHECK_AND_PRINT_I(IBSS),
  259. CHECK_AND_PRINT_I(ACTIVE),
  260. CHECK_AND_PRINT_I(RADAR),
  261. CHECK_AND_PRINT_I(INDOOR_ONLY),
  262. CHECK_AND_PRINT_I(GO_CONCURRENT),
  263. CHECK_AND_PRINT_I(UNIFORM),
  264. CHECK_AND_PRINT_I(20MHZ),
  265. CHECK_AND_PRINT_I(40MHZ),
  266. CHECK_AND_PRINT_I(80MHZ),
  267. CHECK_AND_PRINT_I(160MHZ),
  268. CHECK_AND_PRINT_I(DC_HIGH));
  269. #undef CHECK_AND_PRINT_I
  270. }
  271. static u32 iwl_get_channel_flags(u8 ch_num, int ch_idx, enum nl80211_band band,
  272. u32 nvm_flags, const struct iwl_cfg *cfg)
  273. {
  274. u32 flags = IEEE80211_CHAN_NO_HT40;
  275. if (band == NL80211_BAND_2GHZ && (nvm_flags & NVM_CHANNEL_40MHZ)) {
  276. if (ch_num <= LAST_2GHZ_HT_PLUS)
  277. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  278. if (ch_num >= FIRST_2GHZ_HT_MINUS)
  279. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  280. } else if (nvm_flags & NVM_CHANNEL_40MHZ) {
  281. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  282. flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
  283. else
  284. flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
  285. }
  286. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  287. flags |= IEEE80211_CHAN_NO_80MHZ;
  288. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  289. flags |= IEEE80211_CHAN_NO_160MHZ;
  290. if (!(nvm_flags & NVM_CHANNEL_IBSS))
  291. flags |= IEEE80211_CHAN_NO_IR;
  292. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  293. flags |= IEEE80211_CHAN_NO_IR;
  294. if (nvm_flags & NVM_CHANNEL_RADAR)
  295. flags |= IEEE80211_CHAN_RADAR;
  296. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  297. flags |= IEEE80211_CHAN_INDOOR_ONLY;
  298. /* Set the GO concurrent flag only in case that NO_IR is set.
  299. * Otherwise it is meaningless
  300. */
  301. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  302. (flags & IEEE80211_CHAN_NO_IR))
  303. flags |= IEEE80211_CHAN_IR_CONCURRENT;
  304. return flags;
  305. }
  306. static enum nl80211_band iwl_nl80211_band_from_channel_idx(int ch_idx)
  307. {
  308. if (ch_idx >= NUM_2GHZ_CHANNELS + NUM_5GHZ_CHANNELS) {
  309. return NL80211_BAND_6GHZ;
  310. }
  311. if (ch_idx >= NUM_2GHZ_CHANNELS)
  312. return NL80211_BAND_5GHZ;
  313. return NL80211_BAND_2GHZ;
  314. }
  315. static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
  316. struct iwl_nvm_data *data,
  317. const void * const nvm_ch_flags,
  318. u32 sbands_flags, bool v4)
  319. {
  320. int ch_idx;
  321. int n_channels = 0;
  322. struct ieee80211_channel *channel;
  323. u32 ch_flags;
  324. int num_of_ch;
  325. const u16 *nvm_chan;
  326. if (cfg->uhb_supported) {
  327. num_of_ch = IWL_NVM_NUM_CHANNELS_UHB;
  328. nvm_chan = iwl_uhb_nvm_channels;
  329. } else if (cfg->nvm_type == IWL_NVM_EXT) {
  330. num_of_ch = IWL_NVM_NUM_CHANNELS_EXT;
  331. nvm_chan = iwl_ext_nvm_channels;
  332. } else {
  333. num_of_ch = IWL_NVM_NUM_CHANNELS;
  334. nvm_chan = iwl_nvm_channels;
  335. }
  336. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  337. enum nl80211_band band =
  338. iwl_nl80211_band_from_channel_idx(ch_idx);
  339. if (v4)
  340. ch_flags =
  341. __le32_to_cpup((const __le32 *)nvm_ch_flags + ch_idx);
  342. else
  343. ch_flags =
  344. __le16_to_cpup((const __le16 *)nvm_ch_flags + ch_idx);
  345. if (band == NL80211_BAND_5GHZ &&
  346. !data->sku_cap_band_52ghz_enable)
  347. continue;
  348. /* workaround to disable wide channels in 5GHz */
  349. if ((sbands_flags & IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ) &&
  350. band == NL80211_BAND_5GHZ) {
  351. ch_flags &= ~(NVM_CHANNEL_40MHZ |
  352. NVM_CHANNEL_80MHZ |
  353. NVM_CHANNEL_160MHZ);
  354. }
  355. if (ch_flags & NVM_CHANNEL_160MHZ)
  356. data->vht160_supported = true;
  357. if (!(sbands_flags & IWL_NVM_SBANDS_FLAGS_LAR) &&
  358. !(ch_flags & NVM_CHANNEL_VALID)) {
  359. /*
  360. * Channels might become valid later if lar is
  361. * supported, hence we still want to add them to
  362. * the list of supported channels to cfg80211.
  363. */
  364. iwl_nvm_print_channel_flags(dev, IWL_DL_EEPROM,
  365. nvm_chan[ch_idx], ch_flags);
  366. continue;
  367. }
  368. channel = &data->channels[n_channels];
  369. n_channels++;
  370. channel->hw_value = nvm_chan[ch_idx];
  371. channel->band = band;
  372. channel->center_freq =
  373. ieee80211_channel_to_frequency(
  374. channel->hw_value, channel->band);
  375. /* Initialize regulatory-based run-time data */
  376. /*
  377. * Default value - highest tx power value. max_power
  378. * is not used in mvm, and is used for backwards compatibility
  379. */
  380. channel->max_power = IWL_DEFAULT_MAX_TX_POWER;
  381. /* don't put limitations in case we're using LAR */
  382. if (!(sbands_flags & IWL_NVM_SBANDS_FLAGS_LAR))
  383. channel->flags = iwl_get_channel_flags(nvm_chan[ch_idx],
  384. ch_idx, band,
  385. ch_flags, cfg);
  386. else
  387. channel->flags = 0;
  388. /* TODO: Don't put limitations on UHB devices as we still don't
  389. * have NVM for them
  390. */
  391. if (cfg->uhb_supported)
  392. channel->flags = 0;
  393. iwl_nvm_print_channel_flags(dev, IWL_DL_EEPROM,
  394. channel->hw_value, ch_flags);
  395. IWL_DEBUG_EEPROM(dev, "Ch. %d: %ddBm\n",
  396. channel->hw_value, channel->max_power);
  397. }
  398. return n_channels;
  399. }
  400. static void iwl_init_vht_hw_capab(struct iwl_trans *trans,
  401. struct iwl_nvm_data *data,
  402. struct ieee80211_sta_vht_cap *vht_cap,
  403. u8 tx_chains, u8 rx_chains)
  404. {
  405. const struct iwl_cfg *cfg = trans->cfg;
  406. int num_rx_ants = num_of_ant(rx_chains);
  407. int num_tx_ants = num_of_ant(tx_chains);
  408. vht_cap->vht_supported = true;
  409. vht_cap->cap = IEEE80211_VHT_CAP_SHORT_GI_80 |
  410. IEEE80211_VHT_CAP_RXSTBC_1 |
  411. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  412. 3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT |
  413. IEEE80211_VHT_MAX_AMPDU_1024K <<
  414. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
  415. if (data->vht160_supported)
  416. vht_cap->cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
  417. IEEE80211_VHT_CAP_SHORT_GI_160;
  418. if (cfg->vht_mu_mimo_supported)
  419. vht_cap->cap |= IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  420. if (cfg->ht_params->ldpc)
  421. vht_cap->cap |= IEEE80211_VHT_CAP_RXLDPC;
  422. if (data->sku_cap_mimo_disabled) {
  423. num_rx_ants = 1;
  424. num_tx_ants = 1;
  425. }
  426. if (num_tx_ants > 1)
  427. vht_cap->cap |= IEEE80211_VHT_CAP_TXSTBC;
  428. else
  429. vht_cap->cap |= IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN;
  430. switch (iwlwifi_mod_params.amsdu_size) {
  431. case IWL_AMSDU_DEF:
  432. if (trans->trans_cfg->mq_rx_supported)
  433. vht_cap->cap |=
  434. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  435. else
  436. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  437. break;
  438. case IWL_AMSDU_2K:
  439. if (trans->trans_cfg->mq_rx_supported)
  440. vht_cap->cap |=
  441. IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  442. else
  443. WARN(1, "RB size of 2K is not supported by this device\n");
  444. break;
  445. case IWL_AMSDU_4K:
  446. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895;
  447. break;
  448. case IWL_AMSDU_8K:
  449. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991;
  450. break;
  451. case IWL_AMSDU_12K:
  452. vht_cap->cap |= IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454;
  453. break;
  454. default:
  455. break;
  456. }
  457. vht_cap->vht_mcs.rx_mcs_map =
  458. cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
  459. IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
  460. IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
  461. IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
  462. IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
  463. IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
  464. IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
  465. IEEE80211_VHT_MCS_NOT_SUPPORTED << 14);
  466. if (num_rx_ants == 1 || cfg->rx_with_siso_diversity) {
  467. vht_cap->cap |= IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN;
  468. /* this works because NOT_SUPPORTED == 3 */
  469. vht_cap->vht_mcs.rx_mcs_map |=
  470. cpu_to_le16(IEEE80211_VHT_MCS_NOT_SUPPORTED << 2);
  471. }
  472. vht_cap->vht_mcs.tx_mcs_map = vht_cap->vht_mcs.rx_mcs_map;
  473. vht_cap->vht_mcs.tx_highest |=
  474. cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
  475. }
  476. static const u8 iwl_vendor_caps[] = {
  477. 0xdd, /* vendor element */
  478. 0x06, /* length */
  479. 0x00, 0x17, 0x35, /* Intel OUI */
  480. 0x08, /* type (Intel Capabilities) */
  481. /* followed by 16 bits of capabilities */
  482. #define IWL_VENDOR_CAP_IMPROVED_BF_FDBK_HE BIT(0)
  483. IWL_VENDOR_CAP_IMPROVED_BF_FDBK_HE,
  484. 0x00
  485. };
  486. static const struct ieee80211_sband_iftype_data iwl_he_capa[] = {
  487. {
  488. .types_mask = BIT(NL80211_IFTYPE_STATION),
  489. .he_cap = {
  490. .has_he = true,
  491. .he_cap_elem = {
  492. .mac_cap_info[0] =
  493. IEEE80211_HE_MAC_CAP0_HTC_HE,
  494. .mac_cap_info[1] =
  495. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  496. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  497. .mac_cap_info[2] =
  498. IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP,
  499. .mac_cap_info[3] =
  500. IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
  501. IEEE80211_HE_MAC_CAP3_RX_CTRL_FRAME_TO_MULTIBSS,
  502. .mac_cap_info[4] =
  503. IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU |
  504. IEEE80211_HE_MAC_CAP4_MULTI_TID_AGG_TX_QOS_B39,
  505. .mac_cap_info[5] =
  506. IEEE80211_HE_MAC_CAP5_MULTI_TID_AGG_TX_QOS_B40 |
  507. IEEE80211_HE_MAC_CAP5_MULTI_TID_AGG_TX_QOS_B41 |
  508. IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU |
  509. IEEE80211_HE_MAC_CAP5_HE_DYNAMIC_SM_PS |
  510. IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX,
  511. .phy_cap_info[0] =
  512. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
  513. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
  514. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G,
  515. .phy_cap_info[1] =
  516. IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
  517. IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
  518. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD,
  519. .phy_cap_info[2] =
  520. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
  521. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ,
  522. .phy_cap_info[3] =
  523. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK |
  524. IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 |
  525. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK |
  526. IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1,
  527. .phy_cap_info[4] =
  528. IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
  529. IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_8 |
  530. IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_8,
  531. .phy_cap_info[6] =
  532. IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMING_FB |
  533. IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB |
  534. IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT,
  535. .phy_cap_info[7] =
  536. IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
  537. IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI,
  538. .phy_cap_info[8] =
  539. IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
  540. IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
  541. IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
  542. IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU |
  543. IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_242,
  544. .phy_cap_info[9] =
  545. IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
  546. IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB |
  547. (IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED <<
  548. IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_POS),
  549. .phy_cap_info[10] =
  550. IEEE80211_HE_PHY_CAP10_HE_MU_M1RU_MAX_LTF,
  551. },
  552. /*
  553. * Set default Tx/Rx HE MCS NSS Support field.
  554. * Indicate support for up to 2 spatial streams and all
  555. * MCS, without any special cases
  556. */
  557. .he_mcs_nss_supp = {
  558. .rx_mcs_80 = cpu_to_le16(0xfffa),
  559. .tx_mcs_80 = cpu_to_le16(0xfffa),
  560. .rx_mcs_160 = cpu_to_le16(0xfffa),
  561. .tx_mcs_160 = cpu_to_le16(0xfffa),
  562. .rx_mcs_80p80 = cpu_to_le16(0xffff),
  563. .tx_mcs_80p80 = cpu_to_le16(0xffff),
  564. },
  565. /*
  566. * Set default PPE thresholds, with PPET16 set to 0,
  567. * PPET8 set to 7
  568. */
  569. .ppe_thres = {0x61, 0x1c, 0xc7, 0x71},
  570. },
  571. },
  572. {
  573. .types_mask = BIT(NL80211_IFTYPE_AP),
  574. .he_cap = {
  575. .has_he = true,
  576. .he_cap_elem = {
  577. .mac_cap_info[0] =
  578. IEEE80211_HE_MAC_CAP0_HTC_HE,
  579. .mac_cap_info[1] =
  580. IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
  581. IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
  582. .mac_cap_info[3] =
  583. IEEE80211_HE_MAC_CAP3_OMI_CONTROL,
  584. .phy_cap_info[0] =
  585. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G |
  586. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G,
  587. .phy_cap_info[1] =
  588. IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD,
  589. .phy_cap_info[2] =
  590. IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
  591. IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US,
  592. .phy_cap_info[3] =
  593. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_BPSK |
  594. IEEE80211_HE_PHY_CAP3_DCM_MAX_TX_NSS_1 |
  595. IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_BPSK |
  596. IEEE80211_HE_PHY_CAP3_DCM_MAX_RX_NSS_1,
  597. .phy_cap_info[6] =
  598. IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT,
  599. .phy_cap_info[7] =
  600. IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI,
  601. .phy_cap_info[8] =
  602. IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
  603. IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_242,
  604. .phy_cap_info[9] =
  605. IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED
  606. << IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_POS,
  607. },
  608. /*
  609. * Set default Tx/Rx HE MCS NSS Support field.
  610. * Indicate support for up to 2 spatial streams and all
  611. * MCS, without any special cases
  612. */
  613. .he_mcs_nss_supp = {
  614. .rx_mcs_80 = cpu_to_le16(0xfffa),
  615. .tx_mcs_80 = cpu_to_le16(0xfffa),
  616. .rx_mcs_160 = cpu_to_le16(0xfffa),
  617. .tx_mcs_160 = cpu_to_le16(0xfffa),
  618. .rx_mcs_80p80 = cpu_to_le16(0xffff),
  619. .tx_mcs_80p80 = cpu_to_le16(0xffff),
  620. },
  621. /*
  622. * Set default PPE thresholds, with PPET16 set to 0,
  623. * PPET8 set to 7
  624. */
  625. .ppe_thres = {0x61, 0x1c, 0xc7, 0x71},
  626. },
  627. },
  628. };
  629. static void iwl_init_he_6ghz_capa(struct iwl_trans *trans,
  630. struct iwl_nvm_data *data,
  631. struct ieee80211_supported_band *sband,
  632. u8 tx_chains, u8 rx_chains)
  633. {
  634. struct ieee80211_sta_ht_cap ht_cap;
  635. struct ieee80211_sta_vht_cap vht_cap = {};
  636. struct ieee80211_sband_iftype_data *iftype_data;
  637. u16 he_6ghz_capa = 0;
  638. u32 exp;
  639. int i;
  640. if (sband->band != NL80211_BAND_6GHZ)
  641. return;
  642. /* grab HT/VHT capabilities and calculate HE 6 GHz capabilities */
  643. iwl_init_ht_hw_capab(trans, data, &ht_cap, NL80211_BAND_5GHZ,
  644. tx_chains, rx_chains);
  645. WARN_ON(!ht_cap.ht_supported);
  646. iwl_init_vht_hw_capab(trans, data, &vht_cap, tx_chains, rx_chains);
  647. WARN_ON(!vht_cap.vht_supported);
  648. he_6ghz_capa |=
  649. u16_encode_bits(ht_cap.ampdu_density,
  650. IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START);
  651. exp = u32_get_bits(vht_cap.cap,
  652. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK);
  653. he_6ghz_capa |=
  654. u16_encode_bits(exp, IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP);
  655. exp = u32_get_bits(vht_cap.cap, IEEE80211_VHT_CAP_MAX_MPDU_MASK);
  656. he_6ghz_capa |=
  657. u16_encode_bits(exp, IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN);
  658. /* we don't support extended_ht_cap_info anywhere, so no RD_RESPONDER */
  659. if (vht_cap.cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN)
  660. he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS;
  661. if (vht_cap.cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN)
  662. he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
  663. IWL_DEBUG_EEPROM(trans->dev, "he_6ghz_capa=0x%x\n", he_6ghz_capa);
  664. /* we know it's writable - we set it before ourselves */
  665. iftype_data = (void *)(uintptr_t)sband->iftype_data;
  666. for (i = 0; i < sband->n_iftype_data; i++)
  667. iftype_data[i].he_6ghz_capa.capa = cpu_to_le16(he_6ghz_capa);
  668. }
  669. static void
  670. iwl_nvm_fixup_sband_iftd(struct iwl_trans *trans,
  671. struct ieee80211_supported_band *sband,
  672. struct ieee80211_sband_iftype_data *iftype_data,
  673. u8 tx_chains, u8 rx_chains,
  674. const struct iwl_fw *fw)
  675. {
  676. bool is_ap = iftype_data->types_mask & BIT(NL80211_IFTYPE_AP);
  677. /* Advertise an A-MPDU exponent extension based on
  678. * operating band
  679. */
  680. if (sband->band != NL80211_BAND_2GHZ)
  681. iftype_data->he_cap.he_cap_elem.mac_cap_info[3] |=
  682. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_1;
  683. else
  684. iftype_data->he_cap.he_cap_elem.mac_cap_info[3] |=
  685. IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3;
  686. if (is_ap && iwlwifi_mod_params.nvm_file)
  687. iftype_data->he_cap.he_cap_elem.phy_cap_info[0] |=
  688. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
  689. if ((tx_chains & rx_chains) == ANT_AB) {
  690. iftype_data->he_cap.he_cap_elem.phy_cap_info[2] |=
  691. IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ;
  692. iftype_data->he_cap.he_cap_elem.phy_cap_info[5] |=
  693. IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_2 |
  694. IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_2;
  695. if (!is_ap)
  696. iftype_data->he_cap.he_cap_elem.phy_cap_info[7] |=
  697. IEEE80211_HE_PHY_CAP7_MAX_NC_2;
  698. } else if (!is_ap) {
  699. /* If not 2x2, we need to indicate 1x1 in the
  700. * Midamble RX Max NSTS - but not for AP mode
  701. */
  702. iftype_data->he_cap.he_cap_elem.phy_cap_info[1] &=
  703. ~IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS;
  704. iftype_data->he_cap.he_cap_elem.phy_cap_info[2] &=
  705. ~IEEE80211_HE_PHY_CAP2_MIDAMBLE_RX_TX_MAX_NSTS;
  706. iftype_data->he_cap.he_cap_elem.phy_cap_info[7] |=
  707. IEEE80211_HE_PHY_CAP7_MAX_NC_1;
  708. }
  709. switch (CSR_HW_RFID_TYPE(trans->hw_rf_id)) {
  710. case IWL_CFG_RF_TYPE_GF:
  711. case IWL_CFG_RF_TYPE_MR:
  712. case IWL_CFG_RF_TYPE_MS:
  713. iftype_data->he_cap.he_cap_elem.phy_cap_info[9] |=
  714. IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU;
  715. if (!is_ap)
  716. iftype_data->he_cap.he_cap_elem.phy_cap_info[9] |=
  717. IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
  718. break;
  719. }
  720. if (fw_has_capa(&fw->ucode_capa, IWL_UCODE_TLV_CAPA_BROADCAST_TWT))
  721. iftype_data->he_cap.he_cap_elem.mac_cap_info[2] |=
  722. IEEE80211_HE_MAC_CAP2_BCAST_TWT;
  723. if (trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_22000 &&
  724. !is_ap) {
  725. iftype_data->vendor_elems.data = iwl_vendor_caps;
  726. iftype_data->vendor_elems.len = ARRAY_SIZE(iwl_vendor_caps);
  727. }
  728. }
  729. static void iwl_init_he_hw_capab(struct iwl_trans *trans,
  730. struct iwl_nvm_data *data,
  731. struct ieee80211_supported_band *sband,
  732. u8 tx_chains, u8 rx_chains,
  733. const struct iwl_fw *fw)
  734. {
  735. struct ieee80211_sband_iftype_data *iftype_data;
  736. int i;
  737. /* should only initialize once */
  738. if (WARN_ON(sband->iftype_data))
  739. return;
  740. BUILD_BUG_ON(sizeof(data->iftd.low) != sizeof(iwl_he_capa));
  741. BUILD_BUG_ON(sizeof(data->iftd.high) != sizeof(iwl_he_capa));
  742. switch (sband->band) {
  743. case NL80211_BAND_2GHZ:
  744. iftype_data = data->iftd.low;
  745. break;
  746. case NL80211_BAND_5GHZ:
  747. case NL80211_BAND_6GHZ:
  748. iftype_data = data->iftd.high;
  749. break;
  750. default:
  751. WARN_ON(1);
  752. return;
  753. }
  754. memcpy(iftype_data, iwl_he_capa, sizeof(iwl_he_capa));
  755. sband->iftype_data = iftype_data;
  756. sband->n_iftype_data = ARRAY_SIZE(iwl_he_capa);
  757. for (i = 0; i < sband->n_iftype_data; i++)
  758. iwl_nvm_fixup_sband_iftd(trans, sband, &iftype_data[i],
  759. tx_chains, rx_chains, fw);
  760. iwl_init_he_6ghz_capa(trans, data, sband, tx_chains, rx_chains);
  761. }
  762. static void iwl_init_sbands(struct iwl_trans *trans,
  763. struct iwl_nvm_data *data,
  764. const void *nvm_ch_flags, u8 tx_chains,
  765. u8 rx_chains, u32 sbands_flags, bool v4,
  766. const struct iwl_fw *fw)
  767. {
  768. struct device *dev = trans->dev;
  769. const struct iwl_cfg *cfg = trans->cfg;
  770. int n_channels;
  771. int n_used = 0;
  772. struct ieee80211_supported_band *sband;
  773. n_channels = iwl_init_channel_map(dev, cfg, data, nvm_ch_flags,
  774. sbands_flags, v4);
  775. sband = &data->bands[NL80211_BAND_2GHZ];
  776. sband->band = NL80211_BAND_2GHZ;
  777. sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
  778. sband->n_bitrates = N_RATES_24;
  779. n_used += iwl_init_sband_channels(data, sband, n_channels,
  780. NL80211_BAND_2GHZ);
  781. iwl_init_ht_hw_capab(trans, data, &sband->ht_cap, NL80211_BAND_2GHZ,
  782. tx_chains, rx_chains);
  783. if (data->sku_cap_11ax_enable && !iwlwifi_mod_params.disable_11ax)
  784. iwl_init_he_hw_capab(trans, data, sband, tx_chains, rx_chains,
  785. fw);
  786. sband = &data->bands[NL80211_BAND_5GHZ];
  787. sband->band = NL80211_BAND_5GHZ;
  788. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  789. sband->n_bitrates = N_RATES_52;
  790. n_used += iwl_init_sband_channels(data, sband, n_channels,
  791. NL80211_BAND_5GHZ);
  792. iwl_init_ht_hw_capab(trans, data, &sband->ht_cap, NL80211_BAND_5GHZ,
  793. tx_chains, rx_chains);
  794. if (data->sku_cap_11ac_enable && !iwlwifi_mod_params.disable_11ac)
  795. iwl_init_vht_hw_capab(trans, data, &sband->vht_cap,
  796. tx_chains, rx_chains);
  797. if (data->sku_cap_11ax_enable && !iwlwifi_mod_params.disable_11ax)
  798. iwl_init_he_hw_capab(trans, data, sband, tx_chains, rx_chains,
  799. fw);
  800. /* 6GHz band. */
  801. sband = &data->bands[NL80211_BAND_6GHZ];
  802. sband->band = NL80211_BAND_6GHZ;
  803. /* use the same rates as 5GHz band */
  804. sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
  805. sband->n_bitrates = N_RATES_52;
  806. n_used += iwl_init_sband_channels(data, sband, n_channels,
  807. NL80211_BAND_6GHZ);
  808. if (data->sku_cap_11ax_enable && !iwlwifi_mod_params.disable_11ax)
  809. iwl_init_he_hw_capab(trans, data, sband, tx_chains, rx_chains,
  810. fw);
  811. else
  812. sband->n_channels = 0;
  813. if (n_channels != n_used)
  814. IWL_ERR_DEV(dev, "NVM: used only %d of %d channels\n",
  815. n_used, n_channels);
  816. }
  817. static int iwl_get_sku(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  818. const __le16 *phy_sku)
  819. {
  820. if (cfg->nvm_type != IWL_NVM_EXT)
  821. return le16_to_cpup(nvm_sw + SKU);
  822. return le32_to_cpup((const __le32 *)(phy_sku + SKU_FAMILY_8000));
  823. }
  824. static int iwl_get_nvm_version(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  825. {
  826. if (cfg->nvm_type != IWL_NVM_EXT)
  827. return le16_to_cpup(nvm_sw + NVM_VERSION);
  828. else
  829. return le32_to_cpup((const __le32 *)(nvm_sw +
  830. NVM_VERSION_EXT_NVM));
  831. }
  832. static int iwl_get_radio_cfg(const struct iwl_cfg *cfg, const __le16 *nvm_sw,
  833. const __le16 *phy_sku)
  834. {
  835. if (cfg->nvm_type != IWL_NVM_EXT)
  836. return le16_to_cpup(nvm_sw + RADIO_CFG);
  837. return le32_to_cpup((const __le32 *)(phy_sku + RADIO_CFG_FAMILY_EXT_NVM));
  838. }
  839. static int iwl_get_n_hw_addrs(const struct iwl_cfg *cfg, const __le16 *nvm_sw)
  840. {
  841. int n_hw_addr;
  842. if (cfg->nvm_type != IWL_NVM_EXT)
  843. return le16_to_cpup(nvm_sw + N_HW_ADDRS);
  844. n_hw_addr = le32_to_cpup((const __le32 *)(nvm_sw + N_HW_ADDRS_FAMILY_8000));
  845. return n_hw_addr & N_HW_ADDR_MASK;
  846. }
  847. static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
  848. struct iwl_nvm_data *data,
  849. u32 radio_cfg)
  850. {
  851. if (cfg->nvm_type != IWL_NVM_EXT) {
  852. data->radio_cfg_type = NVM_RF_CFG_TYPE_MSK(radio_cfg);
  853. data->radio_cfg_step = NVM_RF_CFG_STEP_MSK(radio_cfg);
  854. data->radio_cfg_dash = NVM_RF_CFG_DASH_MSK(radio_cfg);
  855. data->radio_cfg_pnum = NVM_RF_CFG_PNUM_MSK(radio_cfg);
  856. return;
  857. }
  858. /* set the radio configuration for family 8000 */
  859. data->radio_cfg_type = EXT_NVM_RF_CFG_TYPE_MSK(radio_cfg);
  860. data->radio_cfg_step = EXT_NVM_RF_CFG_STEP_MSK(radio_cfg);
  861. data->radio_cfg_dash = EXT_NVM_RF_CFG_DASH_MSK(radio_cfg);
  862. data->radio_cfg_pnum = EXT_NVM_RF_CFG_FLAVOR_MSK(radio_cfg);
  863. data->valid_tx_ant = EXT_NVM_RF_CFG_TX_ANT_MSK(radio_cfg);
  864. data->valid_rx_ant = EXT_NVM_RF_CFG_RX_ANT_MSK(radio_cfg);
  865. }
  866. static void iwl_flip_hw_address(__le32 mac_addr0, __le32 mac_addr1, u8 *dest)
  867. {
  868. const u8 *hw_addr;
  869. hw_addr = (const u8 *)&mac_addr0;
  870. dest[0] = hw_addr[3];
  871. dest[1] = hw_addr[2];
  872. dest[2] = hw_addr[1];
  873. dest[3] = hw_addr[0];
  874. hw_addr = (const u8 *)&mac_addr1;
  875. dest[4] = hw_addr[1];
  876. dest[5] = hw_addr[0];
  877. }
  878. static void iwl_set_hw_address_from_csr(struct iwl_trans *trans,
  879. struct iwl_nvm_data *data)
  880. {
  881. __le32 mac_addr0 = cpu_to_le32(iwl_read32(trans,
  882. CSR_MAC_ADDR0_STRAP(trans)));
  883. __le32 mac_addr1 = cpu_to_le32(iwl_read32(trans,
  884. CSR_MAC_ADDR1_STRAP(trans)));
  885. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  886. /*
  887. * If the OEM fused a valid address, use it instead of the one in the
  888. * OTP
  889. */
  890. if (is_valid_ether_addr(data->hw_addr))
  891. return;
  892. mac_addr0 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR0_OTP(trans)));
  893. mac_addr1 = cpu_to_le32(iwl_read32(trans, CSR_MAC_ADDR1_OTP(trans)));
  894. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  895. }
  896. static void iwl_set_hw_address_family_8000(struct iwl_trans *trans,
  897. const struct iwl_cfg *cfg,
  898. struct iwl_nvm_data *data,
  899. const __le16 *mac_override,
  900. const __be16 *nvm_hw)
  901. {
  902. const u8 *hw_addr;
  903. if (mac_override) {
  904. static const u8 reserved_mac[] = {
  905. 0x02, 0xcc, 0xaa, 0xff, 0xee, 0x00
  906. };
  907. hw_addr = (const u8 *)(mac_override +
  908. MAC_ADDRESS_OVERRIDE_EXT_NVM);
  909. /*
  910. * Store the MAC address from MAO section.
  911. * No byte swapping is required in MAO section
  912. */
  913. memcpy(data->hw_addr, hw_addr, ETH_ALEN);
  914. /*
  915. * Force the use of the OTP MAC address in case of reserved MAC
  916. * address in the NVM, or if address is given but invalid.
  917. */
  918. if (is_valid_ether_addr(data->hw_addr) &&
  919. memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0)
  920. return;
  921. IWL_ERR(trans,
  922. "mac address from nvm override section is not valid\n");
  923. }
  924. if (nvm_hw) {
  925. /* read the mac address from WFMP registers */
  926. __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans,
  927. WFMP_MAC_ADDR_0));
  928. __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans,
  929. WFMP_MAC_ADDR_1));
  930. iwl_flip_hw_address(mac_addr0, mac_addr1, data->hw_addr);
  931. return;
  932. }
  933. IWL_ERR(trans, "mac address is not found\n");
  934. }
  935. static int iwl_set_hw_address(struct iwl_trans *trans,
  936. const struct iwl_cfg *cfg,
  937. struct iwl_nvm_data *data, const __be16 *nvm_hw,
  938. const __le16 *mac_override)
  939. {
  940. if (cfg->mac_addr_from_csr) {
  941. iwl_set_hw_address_from_csr(trans, data);
  942. } else if (cfg->nvm_type != IWL_NVM_EXT) {
  943. const u8 *hw_addr = (const u8 *)(nvm_hw + HW_ADDR);
  944. /* The byte order is little endian 16 bit, meaning 214365 */
  945. data->hw_addr[0] = hw_addr[1];
  946. data->hw_addr[1] = hw_addr[0];
  947. data->hw_addr[2] = hw_addr[3];
  948. data->hw_addr[3] = hw_addr[2];
  949. data->hw_addr[4] = hw_addr[5];
  950. data->hw_addr[5] = hw_addr[4];
  951. } else {
  952. iwl_set_hw_address_family_8000(trans, cfg, data,
  953. mac_override, nvm_hw);
  954. }
  955. if (!is_valid_ether_addr(data->hw_addr)) {
  956. IWL_ERR(trans, "no valid mac address was found\n");
  957. return -EINVAL;
  958. }
  959. if (!trans->csme_own)
  960. IWL_INFO(trans, "base HW address: %pM, OTP minor version: 0x%x\n",
  961. data->hw_addr, iwl_read_prph(trans, REG_OTP_MINOR));
  962. return 0;
  963. }
  964. static bool
  965. iwl_nvm_no_wide_in_5ghz(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  966. const __be16 *nvm_hw)
  967. {
  968. /*
  969. * Workaround a bug in Indonesia SKUs where the regulatory in
  970. * some 7000-family OTPs erroneously allow wide channels in
  971. * 5GHz. To check for Indonesia, we take the SKU value from
  972. * bits 1-4 in the subsystem ID and check if it is either 5 or
  973. * 9. In those cases, we need to force-disable wide channels
  974. * in 5GHz otherwise the FW will throw a sysassert when we try
  975. * to use them.
  976. */
  977. if (trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_7000) {
  978. /*
  979. * Unlike the other sections in the NVM, the hw
  980. * section uses big-endian.
  981. */
  982. u16 subsystem_id = be16_to_cpup(nvm_hw + SUBSYSTEM_ID);
  983. u8 sku = (subsystem_id & 0x1e) >> 1;
  984. if (sku == 5 || sku == 9) {
  985. IWL_DEBUG_EEPROM(trans->dev,
  986. "disabling wide channels in 5GHz (0x%0x %d)\n",
  987. subsystem_id, sku);
  988. return true;
  989. }
  990. }
  991. return false;
  992. }
  993. struct iwl_nvm_data *
  994. iwl_parse_mei_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  995. const struct iwl_mei_nvm *mei_nvm,
  996. const struct iwl_fw *fw)
  997. {
  998. struct iwl_nvm_data *data;
  999. u32 sbands_flags = 0;
  1000. u8 rx_chains = fw->valid_rx_ant;
  1001. u8 tx_chains = fw->valid_rx_ant;
  1002. if (cfg->uhb_supported)
  1003. data = kzalloc(struct_size(data, channels,
  1004. IWL_NVM_NUM_CHANNELS_UHB),
  1005. GFP_KERNEL);
  1006. else
  1007. data = kzalloc(struct_size(data, channels,
  1008. IWL_NVM_NUM_CHANNELS_EXT),
  1009. GFP_KERNEL);
  1010. if (!data)
  1011. return NULL;
  1012. BUILD_BUG_ON(ARRAY_SIZE(mei_nvm->channels) !=
  1013. IWL_NVM_NUM_CHANNELS_UHB);
  1014. data->nvm_version = mei_nvm->nvm_version;
  1015. iwl_set_radio_cfg(cfg, data, mei_nvm->radio_cfg);
  1016. if (data->valid_tx_ant)
  1017. tx_chains &= data->valid_tx_ant;
  1018. if (data->valid_rx_ant)
  1019. rx_chains &= data->valid_rx_ant;
  1020. data->sku_cap_mimo_disabled = false;
  1021. data->sku_cap_band_24ghz_enable = true;
  1022. data->sku_cap_band_52ghz_enable = true;
  1023. data->sku_cap_11n_enable =
  1024. !(iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL);
  1025. data->sku_cap_11ac_enable = true;
  1026. data->sku_cap_11ax_enable =
  1027. mei_nvm->caps & MEI_NVM_CAPS_11AX_SUPPORT;
  1028. data->lar_enabled = mei_nvm->caps & MEI_NVM_CAPS_LARI_SUPPORT;
  1029. data->n_hw_addrs = mei_nvm->n_hw_addrs;
  1030. /* If no valid mac address was found - bail out */
  1031. if (iwl_set_hw_address(trans, cfg, data, NULL, NULL)) {
  1032. kfree(data);
  1033. return NULL;
  1034. }
  1035. if (data->lar_enabled &&
  1036. fw_has_capa(&fw->ucode_capa, IWL_UCODE_TLV_CAPA_LAR_SUPPORT))
  1037. sbands_flags |= IWL_NVM_SBANDS_FLAGS_LAR;
  1038. iwl_init_sbands(trans, data, mei_nvm->channels, tx_chains, rx_chains,
  1039. sbands_flags, true, fw);
  1040. return data;
  1041. }
  1042. IWL_EXPORT_SYMBOL(iwl_parse_mei_nvm_data);
  1043. struct iwl_nvm_data *
  1044. iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
  1045. const struct iwl_fw *fw,
  1046. const __be16 *nvm_hw, const __le16 *nvm_sw,
  1047. const __le16 *nvm_calib, const __le16 *regulatory,
  1048. const __le16 *mac_override, const __le16 *phy_sku,
  1049. u8 tx_chains, u8 rx_chains)
  1050. {
  1051. struct iwl_nvm_data *data;
  1052. bool lar_enabled;
  1053. u32 sku, radio_cfg;
  1054. u32 sbands_flags = 0;
  1055. u16 lar_config;
  1056. const __le16 *ch_section;
  1057. if (cfg->uhb_supported)
  1058. data = kzalloc(struct_size(data, channels,
  1059. IWL_NVM_NUM_CHANNELS_UHB),
  1060. GFP_KERNEL);
  1061. else if (cfg->nvm_type != IWL_NVM_EXT)
  1062. data = kzalloc(struct_size(data, channels,
  1063. IWL_NVM_NUM_CHANNELS),
  1064. GFP_KERNEL);
  1065. else
  1066. data = kzalloc(struct_size(data, channels,
  1067. IWL_NVM_NUM_CHANNELS_EXT),
  1068. GFP_KERNEL);
  1069. if (!data)
  1070. return NULL;
  1071. data->nvm_version = iwl_get_nvm_version(cfg, nvm_sw);
  1072. radio_cfg = iwl_get_radio_cfg(cfg, nvm_sw, phy_sku);
  1073. iwl_set_radio_cfg(cfg, data, radio_cfg);
  1074. if (data->valid_tx_ant)
  1075. tx_chains &= data->valid_tx_ant;
  1076. if (data->valid_rx_ant)
  1077. rx_chains &= data->valid_rx_ant;
  1078. sku = iwl_get_sku(cfg, nvm_sw, phy_sku);
  1079. data->sku_cap_band_24ghz_enable = sku & NVM_SKU_CAP_BAND_24GHZ;
  1080. data->sku_cap_band_52ghz_enable = sku & NVM_SKU_CAP_BAND_52GHZ;
  1081. data->sku_cap_11n_enable = sku & NVM_SKU_CAP_11N_ENABLE;
  1082. if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  1083. data->sku_cap_11n_enable = false;
  1084. data->sku_cap_11ac_enable = data->sku_cap_11n_enable &&
  1085. (sku & NVM_SKU_CAP_11AC_ENABLE);
  1086. data->sku_cap_mimo_disabled = sku & NVM_SKU_CAP_MIMO_DISABLE;
  1087. data->n_hw_addrs = iwl_get_n_hw_addrs(cfg, nvm_sw);
  1088. if (cfg->nvm_type != IWL_NVM_EXT) {
  1089. /* Checking for required sections */
  1090. if (!nvm_calib) {
  1091. IWL_ERR(trans,
  1092. "Can't parse empty Calib NVM sections\n");
  1093. kfree(data);
  1094. return NULL;
  1095. }
  1096. ch_section = cfg->nvm_type == IWL_NVM_SDP ?
  1097. &regulatory[NVM_CHANNELS_SDP] :
  1098. &nvm_sw[NVM_CHANNELS];
  1099. /* in family 8000 Xtal calibration values moved to OTP */
  1100. data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
  1101. data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
  1102. lar_enabled = true;
  1103. } else {
  1104. u16 lar_offset = data->nvm_version < 0xE39 ?
  1105. NVM_LAR_OFFSET_OLD :
  1106. NVM_LAR_OFFSET;
  1107. lar_config = le16_to_cpup(regulatory + lar_offset);
  1108. data->lar_enabled = !!(lar_config &
  1109. NVM_LAR_ENABLED);
  1110. lar_enabled = data->lar_enabled;
  1111. ch_section = &regulatory[NVM_CHANNELS_EXTENDED];
  1112. }
  1113. /* If no valid mac address was found - bail out */
  1114. if (iwl_set_hw_address(trans, cfg, data, nvm_hw, mac_override)) {
  1115. kfree(data);
  1116. return NULL;
  1117. }
  1118. if (lar_enabled &&
  1119. fw_has_capa(&fw->ucode_capa, IWL_UCODE_TLV_CAPA_LAR_SUPPORT))
  1120. sbands_flags |= IWL_NVM_SBANDS_FLAGS_LAR;
  1121. if (iwl_nvm_no_wide_in_5ghz(trans, cfg, nvm_hw))
  1122. sbands_flags |= IWL_NVM_SBANDS_FLAGS_NO_WIDE_IN_5GHZ;
  1123. iwl_init_sbands(trans, data, ch_section, tx_chains, rx_chains,
  1124. sbands_flags, false, fw);
  1125. data->calib_version = 255;
  1126. return data;
  1127. }
  1128. IWL_EXPORT_SYMBOL(iwl_parse_nvm_data);
  1129. static u32 iwl_nvm_get_regdom_bw_flags(const u16 *nvm_chan,
  1130. int ch_idx, u16 nvm_flags,
  1131. struct iwl_reg_capa reg_capa,
  1132. const struct iwl_cfg *cfg)
  1133. {
  1134. u32 flags = NL80211_RRF_NO_HT40;
  1135. if (ch_idx < NUM_2GHZ_CHANNELS &&
  1136. (nvm_flags & NVM_CHANNEL_40MHZ)) {
  1137. if (nvm_chan[ch_idx] <= LAST_2GHZ_HT_PLUS)
  1138. flags &= ~NL80211_RRF_NO_HT40PLUS;
  1139. if (nvm_chan[ch_idx] >= FIRST_2GHZ_HT_MINUS)
  1140. flags &= ~NL80211_RRF_NO_HT40MINUS;
  1141. } else if (nvm_flags & NVM_CHANNEL_40MHZ) {
  1142. if ((ch_idx - NUM_2GHZ_CHANNELS) % 2 == 0)
  1143. flags &= ~NL80211_RRF_NO_HT40PLUS;
  1144. else
  1145. flags &= ~NL80211_RRF_NO_HT40MINUS;
  1146. }
  1147. if (!(nvm_flags & NVM_CHANNEL_80MHZ))
  1148. flags |= NL80211_RRF_NO_80MHZ;
  1149. if (!(nvm_flags & NVM_CHANNEL_160MHZ))
  1150. flags |= NL80211_RRF_NO_160MHZ;
  1151. if (!(nvm_flags & NVM_CHANNEL_ACTIVE))
  1152. flags |= NL80211_RRF_NO_IR;
  1153. if (nvm_flags & NVM_CHANNEL_RADAR)
  1154. flags |= NL80211_RRF_DFS;
  1155. if (nvm_flags & NVM_CHANNEL_INDOOR_ONLY)
  1156. flags |= NL80211_RRF_NO_OUTDOOR;
  1157. /* Set the GO concurrent flag only in case that NO_IR is set.
  1158. * Otherwise it is meaningless
  1159. */
  1160. if ((nvm_flags & NVM_CHANNEL_GO_CONCURRENT) &&
  1161. (flags & NL80211_RRF_NO_IR))
  1162. flags |= NL80211_RRF_GO_CONCURRENT;
  1163. /*
  1164. * reg_capa is per regulatory domain so apply it for every channel
  1165. */
  1166. if (ch_idx >= NUM_2GHZ_CHANNELS) {
  1167. if (!reg_capa.allow_40mhz)
  1168. flags |= NL80211_RRF_NO_HT40;
  1169. if (!reg_capa.allow_80mhz)
  1170. flags |= NL80211_RRF_NO_80MHZ;
  1171. if (!reg_capa.allow_160mhz)
  1172. flags |= NL80211_RRF_NO_160MHZ;
  1173. }
  1174. if (reg_capa.disable_11ax)
  1175. flags |= NL80211_RRF_NO_HE;
  1176. return flags;
  1177. }
  1178. static struct iwl_reg_capa iwl_get_reg_capa(u16 flags, u8 resp_ver)
  1179. {
  1180. struct iwl_reg_capa reg_capa;
  1181. if (resp_ver >= REG_CAPA_V2_RESP_VER) {
  1182. reg_capa.allow_40mhz = flags & REG_CAPA_V2_40MHZ_ALLOWED;
  1183. reg_capa.allow_80mhz = flags & REG_CAPA_V2_80MHZ_ALLOWED;
  1184. reg_capa.allow_160mhz = flags & REG_CAPA_V2_160MHZ_ALLOWED;
  1185. reg_capa.disable_11ax = flags & REG_CAPA_V2_11AX_DISABLED;
  1186. } else {
  1187. reg_capa.allow_40mhz = !(flags & REG_CAPA_40MHZ_FORBIDDEN);
  1188. reg_capa.allow_80mhz = flags & REG_CAPA_80MHZ_ALLOWED;
  1189. reg_capa.allow_160mhz = flags & REG_CAPA_160MHZ_ALLOWED;
  1190. reg_capa.disable_11ax = flags & REG_CAPA_11AX_DISABLED;
  1191. }
  1192. return reg_capa;
  1193. }
  1194. struct ieee80211_regdomain *
  1195. iwl_parse_nvm_mcc_info(struct device *dev, const struct iwl_cfg *cfg,
  1196. int num_of_ch, __le32 *channels, u16 fw_mcc,
  1197. u16 geo_info, u16 cap, u8 resp_ver)
  1198. {
  1199. int ch_idx;
  1200. u16 ch_flags;
  1201. u32 reg_rule_flags, prev_reg_rule_flags = 0;
  1202. const u16 *nvm_chan;
  1203. struct ieee80211_regdomain *regd, *copy_rd;
  1204. struct ieee80211_reg_rule *rule;
  1205. enum nl80211_band band;
  1206. int center_freq, prev_center_freq = 0;
  1207. int valid_rules = 0;
  1208. bool new_rule;
  1209. int max_num_ch;
  1210. struct iwl_reg_capa reg_capa;
  1211. if (cfg->uhb_supported) {
  1212. max_num_ch = IWL_NVM_NUM_CHANNELS_UHB;
  1213. nvm_chan = iwl_uhb_nvm_channels;
  1214. } else if (cfg->nvm_type == IWL_NVM_EXT) {
  1215. max_num_ch = IWL_NVM_NUM_CHANNELS_EXT;
  1216. nvm_chan = iwl_ext_nvm_channels;
  1217. } else {
  1218. max_num_ch = IWL_NVM_NUM_CHANNELS;
  1219. nvm_chan = iwl_nvm_channels;
  1220. }
  1221. if (num_of_ch > max_num_ch) {
  1222. IWL_DEBUG_DEV(dev, IWL_DL_LAR,
  1223. "Num of channels (%d) is greater than expected. Truncating to %d\n",
  1224. num_of_ch, max_num_ch);
  1225. num_of_ch = max_num_ch;
  1226. }
  1227. if (WARN_ON_ONCE(num_of_ch > NL80211_MAX_SUPP_REG_RULES))
  1228. return ERR_PTR(-EINVAL);
  1229. IWL_DEBUG_DEV(dev, IWL_DL_LAR, "building regdom for %d channels\n",
  1230. num_of_ch);
  1231. /* build a regdomain rule for every valid channel */
  1232. regd = kzalloc(struct_size(regd, reg_rules, num_of_ch), GFP_KERNEL);
  1233. if (!regd)
  1234. return ERR_PTR(-ENOMEM);
  1235. /* set alpha2 from FW. */
  1236. regd->alpha2[0] = fw_mcc >> 8;
  1237. regd->alpha2[1] = fw_mcc & 0xff;
  1238. /* parse regulatory capability flags */
  1239. reg_capa = iwl_get_reg_capa(cap, resp_ver);
  1240. for (ch_idx = 0; ch_idx < num_of_ch; ch_idx++) {
  1241. ch_flags = (u16)__le32_to_cpup(channels + ch_idx);
  1242. band = iwl_nl80211_band_from_channel_idx(ch_idx);
  1243. center_freq = ieee80211_channel_to_frequency(nvm_chan[ch_idx],
  1244. band);
  1245. new_rule = false;
  1246. if (!(ch_flags & NVM_CHANNEL_VALID)) {
  1247. iwl_nvm_print_channel_flags(dev, IWL_DL_LAR,
  1248. nvm_chan[ch_idx], ch_flags);
  1249. continue;
  1250. }
  1251. reg_rule_flags = iwl_nvm_get_regdom_bw_flags(nvm_chan, ch_idx,
  1252. ch_flags, reg_capa,
  1253. cfg);
  1254. /* we can't continue the same rule */
  1255. if (ch_idx == 0 || prev_reg_rule_flags != reg_rule_flags ||
  1256. center_freq - prev_center_freq > 20) {
  1257. valid_rules++;
  1258. new_rule = true;
  1259. }
  1260. rule = &regd->reg_rules[valid_rules - 1];
  1261. if (new_rule)
  1262. rule->freq_range.start_freq_khz =
  1263. MHZ_TO_KHZ(center_freq - 10);
  1264. rule->freq_range.end_freq_khz = MHZ_TO_KHZ(center_freq + 10);
  1265. /* this doesn't matter - not used by FW */
  1266. rule->power_rule.max_antenna_gain = DBI_TO_MBI(6);
  1267. rule->power_rule.max_eirp =
  1268. DBM_TO_MBM(IWL_DEFAULT_MAX_TX_POWER);
  1269. rule->flags = reg_rule_flags;
  1270. /* rely on auto-calculation to merge BW of contiguous chans */
  1271. rule->flags |= NL80211_RRF_AUTO_BW;
  1272. rule->freq_range.max_bandwidth_khz = 0;
  1273. prev_center_freq = center_freq;
  1274. prev_reg_rule_flags = reg_rule_flags;
  1275. iwl_nvm_print_channel_flags(dev, IWL_DL_LAR,
  1276. nvm_chan[ch_idx], ch_flags);
  1277. if (!(geo_info & GEO_WMM_ETSI_5GHZ_INFO) ||
  1278. band == NL80211_BAND_2GHZ)
  1279. continue;
  1280. reg_query_regdb_wmm(regd->alpha2, center_freq, rule);
  1281. }
  1282. /*
  1283. * Certain firmware versions might report no valid channels
  1284. * if booted in RF-kill, i.e. not all calibrations etc. are
  1285. * running. We'll get out of this situation later when the
  1286. * rfkill is removed and we update the regdomain again, but
  1287. * since cfg80211 doesn't accept an empty regdomain, add a
  1288. * dummy (unusable) rule here in this case so we can init.
  1289. */
  1290. if (!valid_rules) {
  1291. valid_rules = 1;
  1292. rule = &regd->reg_rules[valid_rules - 1];
  1293. rule->freq_range.start_freq_khz = MHZ_TO_KHZ(2412);
  1294. rule->freq_range.end_freq_khz = MHZ_TO_KHZ(2413);
  1295. rule->freq_range.max_bandwidth_khz = MHZ_TO_KHZ(1);
  1296. rule->power_rule.max_antenna_gain = DBI_TO_MBI(6);
  1297. rule->power_rule.max_eirp =
  1298. DBM_TO_MBM(IWL_DEFAULT_MAX_TX_POWER);
  1299. }
  1300. regd->n_reg_rules = valid_rules;
  1301. /*
  1302. * Narrow down regdom for unused regulatory rules to prevent hole
  1303. * between reg rules to wmm rules.
  1304. */
  1305. copy_rd = kmemdup(regd, struct_size(regd, reg_rules, valid_rules),
  1306. GFP_KERNEL);
  1307. if (!copy_rd)
  1308. copy_rd = ERR_PTR(-ENOMEM);
  1309. kfree(regd);
  1310. return copy_rd;
  1311. }
  1312. IWL_EXPORT_SYMBOL(iwl_parse_nvm_mcc_info);
  1313. #define IWL_MAX_NVM_SECTION_SIZE 0x1b58
  1314. #define IWL_MAX_EXT_NVM_SECTION_SIZE 0x1ffc
  1315. #define MAX_NVM_FILE_LEN 16384
  1316. void iwl_nvm_fixups(u32 hw_id, unsigned int section, u8 *data,
  1317. unsigned int len)
  1318. {
  1319. #define IWL_4165_DEVICE_ID 0x5501
  1320. #define NVM_SKU_CAP_MIMO_DISABLE BIT(5)
  1321. if (section == NVM_SECTION_TYPE_PHY_SKU &&
  1322. hw_id == IWL_4165_DEVICE_ID && data && len >= 5 &&
  1323. (data[4] & NVM_SKU_CAP_MIMO_DISABLE))
  1324. /* OTP 0x52 bug work around: it's a 1x1 device */
  1325. data[3] = ANT_B | (ANT_B << 4);
  1326. }
  1327. IWL_EXPORT_SYMBOL(iwl_nvm_fixups);
  1328. /*
  1329. * Reads external NVM from a file into mvm->nvm_sections
  1330. *
  1331. * HOW TO CREATE THE NVM FILE FORMAT:
  1332. * ------------------------------
  1333. * 1. create hex file, format:
  1334. * 3800 -> header
  1335. * 0000 -> header
  1336. * 5a40 -> data
  1337. *
  1338. * rev - 6 bit (word1)
  1339. * len - 10 bit (word1)
  1340. * id - 4 bit (word2)
  1341. * rsv - 12 bit (word2)
  1342. *
  1343. * 2. flip 8bits with 8 bits per line to get the right NVM file format
  1344. *
  1345. * 3. create binary file from the hex file
  1346. *
  1347. * 4. save as "iNVM_xxx.bin" under /lib/firmware
  1348. */
  1349. int iwl_read_external_nvm(struct iwl_trans *trans,
  1350. const char *nvm_file_name,
  1351. struct iwl_nvm_section *nvm_sections)
  1352. {
  1353. int ret, section_size;
  1354. u16 section_id;
  1355. const struct firmware *fw_entry;
  1356. const struct {
  1357. __le16 word1;
  1358. __le16 word2;
  1359. u8 data[];
  1360. } *file_sec;
  1361. const u8 *eof;
  1362. u8 *temp;
  1363. int max_section_size;
  1364. const __le32 *dword_buff;
  1365. #define NVM_WORD1_LEN(x) (8 * (x & 0x03FF))
  1366. #define NVM_WORD2_ID(x) (x >> 12)
  1367. #define EXT_NVM_WORD2_LEN(x) (2 * (((x) & 0xFF) << 8 | (x) >> 8))
  1368. #define EXT_NVM_WORD1_ID(x) ((x) >> 4)
  1369. #define NVM_HEADER_0 (0x2A504C54)
  1370. #define NVM_HEADER_1 (0x4E564D2A)
  1371. #define NVM_HEADER_SIZE (4 * sizeof(u32))
  1372. IWL_DEBUG_EEPROM(trans->dev, "Read from external NVM\n");
  1373. /* Maximal size depends on NVM version */
  1374. if (trans->cfg->nvm_type != IWL_NVM_EXT)
  1375. max_section_size = IWL_MAX_NVM_SECTION_SIZE;
  1376. else
  1377. max_section_size = IWL_MAX_EXT_NVM_SECTION_SIZE;
  1378. /*
  1379. * Obtain NVM image via request_firmware. Since we already used
  1380. * request_firmware_nowait() for the firmware binary load and only
  1381. * get here after that we assume the NVM request can be satisfied
  1382. * synchronously.
  1383. */
  1384. ret = request_firmware(&fw_entry, nvm_file_name, trans->dev);
  1385. if (ret) {
  1386. IWL_ERR(trans, "ERROR: %s isn't available %d\n",
  1387. nvm_file_name, ret);
  1388. return ret;
  1389. }
  1390. IWL_INFO(trans, "Loaded NVM file %s (%zu bytes)\n",
  1391. nvm_file_name, fw_entry->size);
  1392. if (fw_entry->size > MAX_NVM_FILE_LEN) {
  1393. IWL_ERR(trans, "NVM file too large\n");
  1394. ret = -EINVAL;
  1395. goto out;
  1396. }
  1397. eof = fw_entry->data + fw_entry->size;
  1398. dword_buff = (const __le32 *)fw_entry->data;
  1399. /* some NVM file will contain a header.
  1400. * The header is identified by 2 dwords header as follow:
  1401. * dword[0] = 0x2A504C54
  1402. * dword[1] = 0x4E564D2A
  1403. *
  1404. * This header must be skipped when providing the NVM data to the FW.
  1405. */
  1406. if (fw_entry->size > NVM_HEADER_SIZE &&
  1407. dword_buff[0] == cpu_to_le32(NVM_HEADER_0) &&
  1408. dword_buff[1] == cpu_to_le32(NVM_HEADER_1)) {
  1409. file_sec = (const void *)(fw_entry->data + NVM_HEADER_SIZE);
  1410. IWL_INFO(trans, "NVM Version %08X\n", le32_to_cpu(dword_buff[2]));
  1411. IWL_INFO(trans, "NVM Manufacturing date %08X\n",
  1412. le32_to_cpu(dword_buff[3]));
  1413. /* nvm file validation, dword_buff[2] holds the file version */
  1414. if (trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
  1415. trans->hw_rev_step == SILICON_C_STEP &&
  1416. le32_to_cpu(dword_buff[2]) < 0xE4A) {
  1417. ret = -EFAULT;
  1418. goto out;
  1419. }
  1420. } else {
  1421. file_sec = (const void *)fw_entry->data;
  1422. }
  1423. while (true) {
  1424. if (file_sec->data > eof) {
  1425. IWL_ERR(trans,
  1426. "ERROR - NVM file too short for section header\n");
  1427. ret = -EINVAL;
  1428. break;
  1429. }
  1430. /* check for EOF marker */
  1431. if (!file_sec->word1 && !file_sec->word2) {
  1432. ret = 0;
  1433. break;
  1434. }
  1435. if (trans->cfg->nvm_type != IWL_NVM_EXT) {
  1436. section_size =
  1437. 2 * NVM_WORD1_LEN(le16_to_cpu(file_sec->word1));
  1438. section_id = NVM_WORD2_ID(le16_to_cpu(file_sec->word2));
  1439. } else {
  1440. section_size = 2 * EXT_NVM_WORD2_LEN(
  1441. le16_to_cpu(file_sec->word2));
  1442. section_id = EXT_NVM_WORD1_ID(
  1443. le16_to_cpu(file_sec->word1));
  1444. }
  1445. if (section_size > max_section_size) {
  1446. IWL_ERR(trans, "ERROR - section too large (%d)\n",
  1447. section_size);
  1448. ret = -EINVAL;
  1449. break;
  1450. }
  1451. if (!section_size) {
  1452. IWL_ERR(trans, "ERROR - section empty\n");
  1453. ret = -EINVAL;
  1454. break;
  1455. }
  1456. if (file_sec->data + section_size > eof) {
  1457. IWL_ERR(trans,
  1458. "ERROR - NVM file too short for section (%d bytes)\n",
  1459. section_size);
  1460. ret = -EINVAL;
  1461. break;
  1462. }
  1463. if (WARN(section_id >= NVM_MAX_NUM_SECTIONS,
  1464. "Invalid NVM section ID %d\n", section_id)) {
  1465. ret = -EINVAL;
  1466. break;
  1467. }
  1468. temp = kmemdup(file_sec->data, section_size, GFP_KERNEL);
  1469. if (!temp) {
  1470. ret = -ENOMEM;
  1471. break;
  1472. }
  1473. iwl_nvm_fixups(trans->hw_id, section_id, temp, section_size);
  1474. kfree(nvm_sections[section_id].data);
  1475. nvm_sections[section_id].data = temp;
  1476. nvm_sections[section_id].length = section_size;
  1477. /* advance to the next section */
  1478. file_sec = (const void *)(file_sec->data + section_size);
  1479. }
  1480. out:
  1481. release_firmware(fw_entry);
  1482. return ret;
  1483. }
  1484. IWL_EXPORT_SYMBOL(iwl_read_external_nvm);
  1485. struct iwl_nvm_data *iwl_get_nvm(struct iwl_trans *trans,
  1486. const struct iwl_fw *fw)
  1487. {
  1488. struct iwl_nvm_get_info cmd = {};
  1489. struct iwl_nvm_data *nvm;
  1490. struct iwl_host_cmd hcmd = {
  1491. .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  1492. .data = { &cmd, },
  1493. .len = { sizeof(cmd) },
  1494. .id = WIDE_ID(REGULATORY_AND_NVM_GROUP, NVM_GET_INFO)
  1495. };
  1496. int ret;
  1497. bool empty_otp;
  1498. u32 mac_flags;
  1499. u32 sbands_flags = 0;
  1500. /*
  1501. * All the values in iwl_nvm_get_info_rsp v4 are the same as
  1502. * in v3, except for the channel profile part of the
  1503. * regulatory. So we can just access the new struct, with the
  1504. * exception of the latter.
  1505. */
  1506. struct iwl_nvm_get_info_rsp *rsp;
  1507. struct iwl_nvm_get_info_rsp_v3 *rsp_v3;
  1508. bool v4 = fw_has_api(&fw->ucode_capa,
  1509. IWL_UCODE_TLV_API_REGULATORY_NVM_INFO);
  1510. size_t rsp_size = v4 ? sizeof(*rsp) : sizeof(*rsp_v3);
  1511. void *channel_profile;
  1512. ret = iwl_trans_send_cmd(trans, &hcmd);
  1513. if (ret)
  1514. return ERR_PTR(ret);
  1515. if (WARN(iwl_rx_packet_payload_len(hcmd.resp_pkt) != rsp_size,
  1516. "Invalid payload len in NVM response from FW %d",
  1517. iwl_rx_packet_payload_len(hcmd.resp_pkt))) {
  1518. ret = -EINVAL;
  1519. goto out;
  1520. }
  1521. rsp = (void *)hcmd.resp_pkt->data;
  1522. empty_otp = !!(le32_to_cpu(rsp->general.flags) &
  1523. NVM_GENERAL_FLAGS_EMPTY_OTP);
  1524. if (empty_otp)
  1525. IWL_INFO(trans, "OTP is empty\n");
  1526. nvm = kzalloc(struct_size(nvm, channels, IWL_NUM_CHANNELS), GFP_KERNEL);
  1527. if (!nvm) {
  1528. ret = -ENOMEM;
  1529. goto out;
  1530. }
  1531. iwl_set_hw_address_from_csr(trans, nvm);
  1532. /* TODO: if platform NVM has MAC address - override it here */
  1533. if (!is_valid_ether_addr(nvm->hw_addr)) {
  1534. IWL_ERR(trans, "no valid mac address was found\n");
  1535. ret = -EINVAL;
  1536. goto err_free;
  1537. }
  1538. IWL_INFO(trans, "base HW address: %pM\n", nvm->hw_addr);
  1539. /* Initialize general data */
  1540. nvm->nvm_version = le16_to_cpu(rsp->general.nvm_version);
  1541. nvm->n_hw_addrs = rsp->general.n_hw_addrs;
  1542. if (nvm->n_hw_addrs == 0)
  1543. IWL_WARN(trans,
  1544. "Firmware declares no reserved mac addresses. OTP is empty: %d\n",
  1545. empty_otp);
  1546. /* Initialize MAC sku data */
  1547. mac_flags = le32_to_cpu(rsp->mac_sku.mac_sku_flags);
  1548. nvm->sku_cap_11ac_enable =
  1549. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11AC_ENABLED);
  1550. nvm->sku_cap_11n_enable =
  1551. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11N_ENABLED);
  1552. nvm->sku_cap_11ax_enable =
  1553. !!(mac_flags & NVM_MAC_SKU_FLAGS_802_11AX_ENABLED);
  1554. nvm->sku_cap_band_24ghz_enable =
  1555. !!(mac_flags & NVM_MAC_SKU_FLAGS_BAND_2_4_ENABLED);
  1556. nvm->sku_cap_band_52ghz_enable =
  1557. !!(mac_flags & NVM_MAC_SKU_FLAGS_BAND_5_2_ENABLED);
  1558. nvm->sku_cap_mimo_disabled =
  1559. !!(mac_flags & NVM_MAC_SKU_FLAGS_MIMO_DISABLED);
  1560. /* Initialize PHY sku data */
  1561. nvm->valid_tx_ant = (u8)le32_to_cpu(rsp->phy_sku.tx_chains);
  1562. nvm->valid_rx_ant = (u8)le32_to_cpu(rsp->phy_sku.rx_chains);
  1563. if (le32_to_cpu(rsp->regulatory.lar_enabled) &&
  1564. fw_has_capa(&fw->ucode_capa,
  1565. IWL_UCODE_TLV_CAPA_LAR_SUPPORT)) {
  1566. nvm->lar_enabled = true;
  1567. sbands_flags |= IWL_NVM_SBANDS_FLAGS_LAR;
  1568. }
  1569. rsp_v3 = (void *)rsp;
  1570. channel_profile = v4 ? (void *)rsp->regulatory.channel_profile :
  1571. (void *)rsp_v3->regulatory.channel_profile;
  1572. iwl_init_sbands(trans, nvm,
  1573. channel_profile,
  1574. nvm->valid_tx_ant & fw->valid_tx_ant,
  1575. nvm->valid_rx_ant & fw->valid_rx_ant,
  1576. sbands_flags, v4, fw);
  1577. iwl_free_resp(&hcmd);
  1578. return nvm;
  1579. err_free:
  1580. kfree(nvm);
  1581. out:
  1582. iwl_free_resp(&hcmd);
  1583. return ERR_PTR(ret);
  1584. }
  1585. IWL_EXPORT_SYMBOL(iwl_get_nvm);