iwl-eeprom.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  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 - 2010 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2010 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *****************************************************************************/
  62. #include <linux/kernel.h>
  63. #include <linux/module.h>
  64. #include <linux/slab.h>
  65. #include <linux/init.h>
  66. #include <net/mac80211.h>
  67. #include "iwl-commands.h"
  68. #include "iwl-dev.h"
  69. #include "iwl-core.h"
  70. #include "iwl-debug.h"
  71. #include "iwl-eeprom.h"
  72. #include "iwl-io.h"
  73. /************************** EEPROM BANDS ****************************
  74. *
  75. * The iwl_eeprom_band definitions below provide the mapping from the
  76. * EEPROM contents to the specific channel number supported for each
  77. * band.
  78. *
  79. * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
  80. * definition below maps to physical channel 42 in the 5.2GHz spectrum.
  81. * The specific geography and calibration information for that channel
  82. * is contained in the eeprom map itself.
  83. *
  84. * During init, we copy the eeprom information and channel map
  85. * information into priv->channel_info_24/52 and priv->channel_map_24/52
  86. *
  87. * channel_map_24/52 provides the index in the channel_info array for a
  88. * given channel. We have to have two separate maps as there is channel
  89. * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
  90. * band_2
  91. *
  92. * A value of 0xff stored in the channel_map indicates that the channel
  93. * is not supported by the hardware at all.
  94. *
  95. * A value of 0xfe in the channel_map indicates that the channel is not
  96. * valid for Tx with the current hardware. This means that
  97. * while the system can tune and receive on a given channel, it may not
  98. * be able to associate or transmit any frames on that
  99. * channel. There is no corresponding channel information for that
  100. * entry.
  101. *
  102. *********************************************************************/
  103. /* 2.4 GHz */
  104. const u8 iwl_eeprom_band_1[14] = {
  105. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
  106. };
  107. /* 5.2 GHz bands */
  108. static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
  109. 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
  110. };
  111. static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
  112. 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
  113. };
  114. static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
  115. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
  116. };
  117. static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
  118. 145, 149, 153, 157, 161, 165
  119. };
  120. static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */
  121. 1, 2, 3, 4, 5, 6, 7
  122. };
  123. static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */
  124. 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
  125. };
  126. /**
  127. * struct iwl_txpwr_section: eeprom section information
  128. * @offset: indirect address into eeprom image
  129. * @count: number of "struct iwl_eeprom_enhanced_txpwr" in this section
  130. * @band: band type for the section
  131. * @is_common - true: common section, false: channel section
  132. * @is_cck - true: cck section, false: not cck section
  133. * @is_ht_40 - true: all channel in the section are HT40 channel,
  134. * false: legacy or HT 20 MHz
  135. * ignore if it is common section
  136. * @iwl_eeprom_section_channel: channel array in the section,
  137. * ignore if common section
  138. */
  139. struct iwl_txpwr_section {
  140. u32 offset;
  141. u8 count;
  142. enum ieee80211_band band;
  143. bool is_common;
  144. bool is_cck;
  145. bool is_ht40;
  146. u8 iwl_eeprom_section_channel[EEPROM_MAX_TXPOWER_SECTION_ELEMENTS];
  147. };
  148. /**
  149. * section 1 - 3 are regulatory tx power apply to all channels based on
  150. * modulation: CCK, OFDM
  151. * Band: 2.4GHz, 5.2GHz
  152. * section 4 - 10 are regulatory tx power apply to specified channels
  153. * For example:
  154. * 1L - Channel 1 Legacy
  155. * 1HT - Channel 1 HT
  156. * (1,+1) - Channel 1 HT40 "_above_"
  157. *
  158. * Section 1: all CCK channels
  159. * Section 2: all 2.4 GHz OFDM (Legacy, HT and HT40) channels
  160. * Section 3: all 5.2 GHz OFDM (Legacy, HT and HT40) channels
  161. * Section 4: 2.4 GHz 20MHz channels: 1L, 1HT, 2L, 2HT, 10L, 10HT, 11L, 11HT
  162. * Section 5: 2.4 GHz 40MHz channels: (1,+1) (2,+1) (6,+1) (7,+1) (9,+1)
  163. * Section 6: 5.2 GHz 20MHz channels: 36L, 64L, 100L, 36HT, 64HT, 100HT
  164. * Section 7: 5.2 GHz 40MHz channels: (36,+1) (60,+1) (100,+1)
  165. * Section 8: 2.4 GHz channel: 13L, 13HT
  166. * Section 9: 2.4 GHz channel: 140L, 140HT
  167. * Section 10: 2.4 GHz 40MHz channels: (132,+1) (44,+1)
  168. *
  169. */
  170. static const struct iwl_txpwr_section enhinfo[] = {
  171. { EEPROM_LB_CCK_20_COMMON, 1, IEEE80211_BAND_2GHZ, true, true, false },
  172. { EEPROM_LB_OFDM_COMMON, 3, IEEE80211_BAND_2GHZ, true, false, false },
  173. { EEPROM_HB_OFDM_COMMON, 3, IEEE80211_BAND_5GHZ, true, false, false },
  174. { EEPROM_LB_OFDM_20_BAND, 8, IEEE80211_BAND_2GHZ,
  175. false, false, false,
  176. {1, 1, 2, 2, 10, 10, 11, 11 } },
  177. { EEPROM_LB_OFDM_HT40_BAND, 5, IEEE80211_BAND_2GHZ,
  178. false, false, true,
  179. { 1, 2, 6, 7, 9 } },
  180. { EEPROM_HB_OFDM_20_BAND, 6, IEEE80211_BAND_5GHZ,
  181. false, false, false,
  182. { 36, 64, 100, 36, 64, 100 } },
  183. { EEPROM_HB_OFDM_HT40_BAND, 3, IEEE80211_BAND_5GHZ,
  184. false, false, true,
  185. { 36, 60, 100 } },
  186. { EEPROM_LB_OFDM_20_CHANNEL_13, 2, IEEE80211_BAND_2GHZ,
  187. false, false, false,
  188. { 13, 13 } },
  189. { EEPROM_HB_OFDM_20_CHANNEL_140, 2, IEEE80211_BAND_5GHZ,
  190. false, false, false,
  191. { 140, 140 } },
  192. { EEPROM_HB_OFDM_HT40_BAND_1, 2, IEEE80211_BAND_5GHZ,
  193. false, false, true,
  194. { 132, 44 } },
  195. };
  196. /******************************************************************************
  197. *
  198. * EEPROM related functions
  199. *
  200. ******************************************************************************/
  201. int iwlcore_eeprom_verify_signature(struct iwl_priv *priv)
  202. {
  203. u32 gp = iwl_read32(priv, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK;
  204. int ret = 0;
  205. IWL_DEBUG_INFO(priv, "EEPROM signature=0x%08x\n", gp);
  206. switch (gp) {
  207. case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP:
  208. if (priv->nvm_device_type != NVM_DEVICE_TYPE_OTP) {
  209. IWL_ERR(priv, "EEPROM with bad signature: 0x%08x\n",
  210. gp);
  211. ret = -ENOENT;
  212. }
  213. break;
  214. case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
  215. case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
  216. if (priv->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) {
  217. IWL_ERR(priv, "OTP with bad signature: 0x%08x\n", gp);
  218. ret = -ENOENT;
  219. }
  220. break;
  221. case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP:
  222. default:
  223. IWL_ERR(priv, "bad EEPROM/OTP signature, type=%s, "
  224. "EEPROM_GP=0x%08x\n",
  225. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  226. ? "OTP" : "EEPROM", gp);
  227. ret = -ENOENT;
  228. break;
  229. }
  230. return ret;
  231. }
  232. EXPORT_SYMBOL(iwlcore_eeprom_verify_signature);
  233. static void iwl_set_otp_access(struct iwl_priv *priv, enum iwl_access_mode mode)
  234. {
  235. u32 otpgp;
  236. otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
  237. if (mode == IWL_OTP_ACCESS_ABSOLUTE)
  238. iwl_clear_bit(priv, CSR_OTP_GP_REG,
  239. CSR_OTP_GP_REG_OTP_ACCESS_MODE);
  240. else
  241. iwl_set_bit(priv, CSR_OTP_GP_REG,
  242. CSR_OTP_GP_REG_OTP_ACCESS_MODE);
  243. }
  244. static int iwlcore_get_nvm_type(struct iwl_priv *priv)
  245. {
  246. u32 otpgp;
  247. int nvm_type;
  248. /* OTP only valid for CP/PP and after */
  249. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  250. case CSR_HW_REV_TYPE_NONE:
  251. IWL_ERR(priv, "Unknown hardware type\n");
  252. return -ENOENT;
  253. case CSR_HW_REV_TYPE_3945:
  254. case CSR_HW_REV_TYPE_4965:
  255. case CSR_HW_REV_TYPE_5300:
  256. case CSR_HW_REV_TYPE_5350:
  257. case CSR_HW_REV_TYPE_5100:
  258. case CSR_HW_REV_TYPE_5150:
  259. nvm_type = NVM_DEVICE_TYPE_EEPROM;
  260. break;
  261. default:
  262. otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
  263. if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT)
  264. nvm_type = NVM_DEVICE_TYPE_OTP;
  265. else
  266. nvm_type = NVM_DEVICE_TYPE_EEPROM;
  267. break;
  268. }
  269. return nvm_type;
  270. }
  271. /*
  272. * The device's EEPROM semaphore prevents conflicts between driver and uCode
  273. * when accessing the EEPROM; each access is a series of pulses to/from the
  274. * EEPROM chip, not a single event, so even reads could conflict if they
  275. * weren't arbitrated by the semaphore.
  276. */
  277. int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv)
  278. {
  279. u16 count;
  280. int ret;
  281. for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
  282. /* Request semaphore */
  283. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  284. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  285. /* See if we got it */
  286. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  287. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  288. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  289. EEPROM_SEM_TIMEOUT);
  290. if (ret >= 0) {
  291. IWL_DEBUG_IO(priv, "Acquired semaphore after %d tries.\n",
  292. count+1);
  293. return ret;
  294. }
  295. }
  296. return ret;
  297. }
  298. EXPORT_SYMBOL(iwlcore_eeprom_acquire_semaphore);
  299. void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv)
  300. {
  301. iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
  302. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  303. }
  304. EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore);
  305. const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
  306. {
  307. BUG_ON(offset >= priv->cfg->eeprom_size);
  308. return &priv->eeprom[offset];
  309. }
  310. EXPORT_SYMBOL(iwlcore_eeprom_query_addr);
  311. static int iwl_init_otp_access(struct iwl_priv *priv)
  312. {
  313. int ret;
  314. /* Enable 40MHz radio clock */
  315. _iwl_write32(priv, CSR_GP_CNTRL,
  316. _iwl_read32(priv, CSR_GP_CNTRL) |
  317. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  318. /* wait for clock to be ready */
  319. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  320. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  321. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  322. 25000);
  323. if (ret < 0)
  324. IWL_ERR(priv, "Time out access OTP\n");
  325. else {
  326. iwl_set_bits_prph(priv, APMG_PS_CTRL_REG,
  327. APMG_PS_CTRL_VAL_RESET_REQ);
  328. udelay(5);
  329. iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG,
  330. APMG_PS_CTRL_VAL_RESET_REQ);
  331. /*
  332. * CSR auto clock gate disable bit -
  333. * this is only applicable for HW with OTP shadow RAM
  334. */
  335. if (priv->cfg->shadow_ram_support)
  336. iwl_set_bit(priv, CSR_DBG_LINK_PWR_MGMT_REG,
  337. CSR_RESET_LINK_PWR_MGMT_DISABLED);
  338. }
  339. return ret;
  340. }
  341. static int iwl_read_otp_word(struct iwl_priv *priv, u16 addr, __le16 *eeprom_data)
  342. {
  343. int ret = 0;
  344. u32 r;
  345. u32 otpgp;
  346. _iwl_write32(priv, CSR_EEPROM_REG,
  347. CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
  348. ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
  349. CSR_EEPROM_REG_READ_VALID_MSK,
  350. CSR_EEPROM_REG_READ_VALID_MSK,
  351. IWL_EEPROM_ACCESS_TIMEOUT);
  352. if (ret < 0) {
  353. IWL_ERR(priv, "Time out reading OTP[%d]\n", addr);
  354. return ret;
  355. }
  356. r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
  357. /* check for ECC errors: */
  358. otpgp = iwl_read32(priv, CSR_OTP_GP_REG);
  359. if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
  360. /* stop in this case */
  361. /* set the uncorrectable OTP ECC bit for acknowledgement */
  362. iwl_set_bit(priv, CSR_OTP_GP_REG,
  363. CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
  364. IWL_ERR(priv, "Uncorrectable OTP ECC error, abort OTP read\n");
  365. return -EINVAL;
  366. }
  367. if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
  368. /* continue in this case */
  369. /* set the correctable OTP ECC bit for acknowledgement */
  370. iwl_set_bit(priv, CSR_OTP_GP_REG,
  371. CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
  372. IWL_ERR(priv, "Correctable OTP ECC error, continue read\n");
  373. }
  374. *eeprom_data = cpu_to_le16(r >> 16);
  375. return 0;
  376. }
  377. /*
  378. * iwl_is_otp_empty: check for empty OTP
  379. */
  380. static bool iwl_is_otp_empty(struct iwl_priv *priv)
  381. {
  382. u16 next_link_addr = 0;
  383. __le16 link_value;
  384. bool is_empty = false;
  385. /* locate the beginning of OTP link list */
  386. if (!iwl_read_otp_word(priv, next_link_addr, &link_value)) {
  387. if (!link_value) {
  388. IWL_ERR(priv, "OTP is empty\n");
  389. is_empty = true;
  390. }
  391. } else {
  392. IWL_ERR(priv, "Unable to read first block of OTP list.\n");
  393. is_empty = true;
  394. }
  395. return is_empty;
  396. }
  397. /*
  398. * iwl_find_otp_image: find EEPROM image in OTP
  399. * finding the OTP block that contains the EEPROM image.
  400. * the last valid block on the link list (the block _before_ the last block)
  401. * is the block we should read and used to configure the device.
  402. * If all the available OTP blocks are full, the last block will be the block
  403. * we should read and used to configure the device.
  404. * only perform this operation if shadow RAM is disabled
  405. */
  406. static int iwl_find_otp_image(struct iwl_priv *priv,
  407. u16 *validblockaddr)
  408. {
  409. u16 next_link_addr = 0, valid_addr;
  410. __le16 link_value = 0;
  411. int usedblocks = 0;
  412. /* set addressing mode to absolute to traverse the link list */
  413. iwl_set_otp_access(priv, IWL_OTP_ACCESS_ABSOLUTE);
  414. /* checking for empty OTP or error */
  415. if (iwl_is_otp_empty(priv))
  416. return -EINVAL;
  417. /*
  418. * start traverse link list
  419. * until reach the max number of OTP blocks
  420. * different devices have different number of OTP blocks
  421. */
  422. do {
  423. /* save current valid block address
  424. * check for more block on the link list
  425. */
  426. valid_addr = next_link_addr;
  427. next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
  428. IWL_DEBUG_INFO(priv, "OTP blocks %d addr 0x%x\n",
  429. usedblocks, next_link_addr);
  430. if (iwl_read_otp_word(priv, next_link_addr, &link_value))
  431. return -EINVAL;
  432. if (!link_value) {
  433. /*
  434. * reach the end of link list, return success and
  435. * set address point to the starting address
  436. * of the image
  437. */
  438. *validblockaddr = valid_addr;
  439. /* skip first 2 bytes (link list pointer) */
  440. *validblockaddr += 2;
  441. return 0;
  442. }
  443. /* more in the link list, continue */
  444. usedblocks++;
  445. } while (usedblocks <= priv->cfg->max_ll_items);
  446. /* OTP has no valid blocks */
  447. IWL_DEBUG_INFO(priv, "OTP has no valid blocks\n");
  448. return -EINVAL;
  449. }
  450. /**
  451. * iwl_eeprom_init - read EEPROM contents
  452. *
  453. * Load the EEPROM contents from adapter into priv->eeprom
  454. *
  455. * NOTE: This routine uses the non-debug IO access functions.
  456. */
  457. int iwl_eeprom_init(struct iwl_priv *priv)
  458. {
  459. __le16 *e;
  460. u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
  461. int sz;
  462. int ret;
  463. u16 addr;
  464. u16 validblockaddr = 0;
  465. u16 cache_addr = 0;
  466. priv->nvm_device_type = iwlcore_get_nvm_type(priv);
  467. if (priv->nvm_device_type == -ENOENT)
  468. return -ENOENT;
  469. /* allocate eeprom */
  470. IWL_DEBUG_INFO(priv, "NVM size = %d\n", priv->cfg->eeprom_size);
  471. sz = priv->cfg->eeprom_size;
  472. priv->eeprom = kzalloc(sz, GFP_KERNEL);
  473. if (!priv->eeprom) {
  474. ret = -ENOMEM;
  475. goto alloc_err;
  476. }
  477. e = (__le16 *)priv->eeprom;
  478. priv->cfg->ops->lib->apm_ops.init(priv);
  479. ret = priv->cfg->ops->lib->eeprom_ops.verify_signature(priv);
  480. if (ret < 0) {
  481. IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
  482. ret = -ENOENT;
  483. goto err;
  484. }
  485. /* Make sure driver (instead of uCode) is allowed to read EEPROM */
  486. ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
  487. if (ret < 0) {
  488. IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
  489. ret = -ENOENT;
  490. goto err;
  491. }
  492. if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
  493. ret = iwl_init_otp_access(priv);
  494. if (ret) {
  495. IWL_ERR(priv, "Failed to initialize OTP access.\n");
  496. ret = -ENOENT;
  497. goto done;
  498. }
  499. _iwl_write32(priv, CSR_EEPROM_GP,
  500. iwl_read32(priv, CSR_EEPROM_GP) &
  501. ~CSR_EEPROM_GP_IF_OWNER_MSK);
  502. iwl_set_bit(priv, CSR_OTP_GP_REG,
  503. CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
  504. CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
  505. /* traversing the linked list if no shadow ram supported */
  506. if (!priv->cfg->shadow_ram_support) {
  507. if (iwl_find_otp_image(priv, &validblockaddr)) {
  508. ret = -ENOENT;
  509. goto done;
  510. }
  511. }
  512. for (addr = validblockaddr; addr < validblockaddr + sz;
  513. addr += sizeof(u16)) {
  514. __le16 eeprom_data;
  515. ret = iwl_read_otp_word(priv, addr, &eeprom_data);
  516. if (ret)
  517. goto done;
  518. e[cache_addr / 2] = eeprom_data;
  519. cache_addr += sizeof(u16);
  520. }
  521. } else {
  522. /* eeprom is an array of 16bit values */
  523. for (addr = 0; addr < sz; addr += sizeof(u16)) {
  524. u32 r;
  525. _iwl_write32(priv, CSR_EEPROM_REG,
  526. CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
  527. ret = iwl_poll_bit(priv, CSR_EEPROM_REG,
  528. CSR_EEPROM_REG_READ_VALID_MSK,
  529. CSR_EEPROM_REG_READ_VALID_MSK,
  530. IWL_EEPROM_ACCESS_TIMEOUT);
  531. if (ret < 0) {
  532. IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr);
  533. goto done;
  534. }
  535. r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
  536. e[addr / 2] = cpu_to_le16(r >> 16);
  537. }
  538. }
  539. ret = 0;
  540. done:
  541. priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
  542. err:
  543. if (ret)
  544. iwl_eeprom_free(priv);
  545. /* Reset chip to save power until we load uCode during "up". */
  546. priv->cfg->ops->lib->apm_ops.stop(priv);
  547. alloc_err:
  548. return ret;
  549. }
  550. EXPORT_SYMBOL(iwl_eeprom_init);
  551. void iwl_eeprom_free(struct iwl_priv *priv)
  552. {
  553. kfree(priv->eeprom);
  554. priv->eeprom = NULL;
  555. }
  556. EXPORT_SYMBOL(iwl_eeprom_free);
  557. int iwl_eeprom_check_version(struct iwl_priv *priv)
  558. {
  559. u16 eeprom_ver;
  560. u16 calib_ver;
  561. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  562. calib_ver = priv->cfg->ops->lib->eeprom_ops.calib_version(priv);
  563. if (eeprom_ver < priv->cfg->eeprom_ver ||
  564. calib_ver < priv->cfg->eeprom_calib_ver)
  565. goto err;
  566. return 0;
  567. err:
  568. IWL_ERR(priv, "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
  569. eeprom_ver, priv->cfg->eeprom_ver,
  570. calib_ver, priv->cfg->eeprom_calib_ver);
  571. return -EINVAL;
  572. }
  573. EXPORT_SYMBOL(iwl_eeprom_check_version);
  574. const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
  575. {
  576. return priv->cfg->ops->lib->eeprom_ops.query_addr(priv, offset);
  577. }
  578. EXPORT_SYMBOL(iwl_eeprom_query_addr);
  579. u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset)
  580. {
  581. if (!priv->eeprom)
  582. return 0;
  583. return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
  584. }
  585. EXPORT_SYMBOL(iwl_eeprom_query16);
  586. void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
  587. {
  588. const u8 *addr = priv->cfg->ops->lib->eeprom_ops.query_addr(priv,
  589. EEPROM_MAC_ADDRESS);
  590. memcpy(mac, addr, ETH_ALEN);
  591. }
  592. EXPORT_SYMBOL(iwl_eeprom_get_mac);
  593. static void iwl_init_band_reference(const struct iwl_priv *priv,
  594. int eep_band, int *eeprom_ch_count,
  595. const struct iwl_eeprom_channel **eeprom_ch_info,
  596. const u8 **eeprom_ch_index)
  597. {
  598. u32 offset = priv->cfg->ops->lib->
  599. eeprom_ops.regulatory_bands[eep_band - 1];
  600. switch (eep_band) {
  601. case 1: /* 2.4GHz band */
  602. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
  603. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  604. iwl_eeprom_query_addr(priv, offset);
  605. *eeprom_ch_index = iwl_eeprom_band_1;
  606. break;
  607. case 2: /* 4.9GHz band */
  608. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
  609. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  610. iwl_eeprom_query_addr(priv, offset);
  611. *eeprom_ch_index = iwl_eeprom_band_2;
  612. break;
  613. case 3: /* 5.2GHz band */
  614. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
  615. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  616. iwl_eeprom_query_addr(priv, offset);
  617. *eeprom_ch_index = iwl_eeprom_band_3;
  618. break;
  619. case 4: /* 5.5GHz band */
  620. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
  621. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  622. iwl_eeprom_query_addr(priv, offset);
  623. *eeprom_ch_index = iwl_eeprom_band_4;
  624. break;
  625. case 5: /* 5.7GHz band */
  626. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
  627. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  628. iwl_eeprom_query_addr(priv, offset);
  629. *eeprom_ch_index = iwl_eeprom_band_5;
  630. break;
  631. case 6: /* 2.4GHz ht40 channels */
  632. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
  633. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  634. iwl_eeprom_query_addr(priv, offset);
  635. *eeprom_ch_index = iwl_eeprom_band_6;
  636. break;
  637. case 7: /* 5 GHz ht40 channels */
  638. *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
  639. *eeprom_ch_info = (struct iwl_eeprom_channel *)
  640. iwl_eeprom_query_addr(priv, offset);
  641. *eeprom_ch_index = iwl_eeprom_band_7;
  642. break;
  643. default:
  644. BUG();
  645. return;
  646. }
  647. }
  648. #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
  649. ? # x " " : "")
  650. /**
  651. * iwl_mod_ht40_chan_info - Copy ht40 channel info into driver's priv.
  652. *
  653. * Does not set up a command, or touch hardware.
  654. */
  655. static int iwl_mod_ht40_chan_info(struct iwl_priv *priv,
  656. enum ieee80211_band band, u16 channel,
  657. const struct iwl_eeprom_channel *eeprom_ch,
  658. u8 clear_ht40_extension_channel)
  659. {
  660. struct iwl_channel_info *ch_info;
  661. ch_info = (struct iwl_channel_info *)
  662. iwl_get_channel_info(priv, band, channel);
  663. if (!is_channel_valid(ch_info))
  664. return -1;
  665. IWL_DEBUG_INFO(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
  666. " Ad-Hoc %ssupported\n",
  667. ch_info->channel,
  668. is_channel_a_band(ch_info) ?
  669. "5.2" : "2.4",
  670. CHECK_AND_PRINT(IBSS),
  671. CHECK_AND_PRINT(ACTIVE),
  672. CHECK_AND_PRINT(RADAR),
  673. CHECK_AND_PRINT(WIDE),
  674. CHECK_AND_PRINT(DFS),
  675. eeprom_ch->flags,
  676. eeprom_ch->max_power_avg,
  677. ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
  678. && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
  679. "" : "not ");
  680. ch_info->ht40_eeprom = *eeprom_ch;
  681. ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg;
  682. ch_info->ht40_flags = eeprom_ch->flags;
  683. if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
  684. ch_info->ht40_extension_channel &= ~clear_ht40_extension_channel;
  685. return 0;
  686. }
  687. /**
  688. * iwl_get_max_txpower_avg - get the highest tx power from all chains.
  689. * find the highest tx power from all chains for the channel
  690. */
  691. static s8 iwl_get_max_txpower_avg(struct iwl_priv *priv,
  692. struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
  693. int element, s8 *max_txpower_in_half_dbm)
  694. {
  695. s8 max_txpower_avg = 0; /* (dBm) */
  696. IWL_DEBUG_INFO(priv, "%d - "
  697. "chain_a: %d dB chain_b: %d dB "
  698. "chain_c: %d dB mimo2: %d dB mimo3: %d dB\n",
  699. element,
  700. enhanced_txpower[element].chain_a_max >> 1,
  701. enhanced_txpower[element].chain_b_max >> 1,
  702. enhanced_txpower[element].chain_c_max >> 1,
  703. enhanced_txpower[element].mimo2_max >> 1,
  704. enhanced_txpower[element].mimo3_max >> 1);
  705. /* Take the highest tx power from any valid chains */
  706. if ((priv->cfg->valid_tx_ant & ANT_A) &&
  707. (enhanced_txpower[element].chain_a_max > max_txpower_avg))
  708. max_txpower_avg = enhanced_txpower[element].chain_a_max;
  709. if ((priv->cfg->valid_tx_ant & ANT_B) &&
  710. (enhanced_txpower[element].chain_b_max > max_txpower_avg))
  711. max_txpower_avg = enhanced_txpower[element].chain_b_max;
  712. if ((priv->cfg->valid_tx_ant & ANT_C) &&
  713. (enhanced_txpower[element].chain_c_max > max_txpower_avg))
  714. max_txpower_avg = enhanced_txpower[element].chain_c_max;
  715. if (((priv->cfg->valid_tx_ant == ANT_AB) |
  716. (priv->cfg->valid_tx_ant == ANT_BC) |
  717. (priv->cfg->valid_tx_ant == ANT_AC)) &&
  718. (enhanced_txpower[element].mimo2_max > max_txpower_avg))
  719. max_txpower_avg = enhanced_txpower[element].mimo2_max;
  720. if ((priv->cfg->valid_tx_ant == ANT_ABC) &&
  721. (enhanced_txpower[element].mimo3_max > max_txpower_avg))
  722. max_txpower_avg = enhanced_txpower[element].mimo3_max;
  723. /*
  724. * max. tx power in EEPROM is in 1/2 dBm format
  725. * convert from 1/2 dBm to dBm (round-up convert)
  726. * but we also do not want to loss 1/2 dBm resolution which
  727. * will impact performance
  728. */
  729. *max_txpower_in_half_dbm = max_txpower_avg;
  730. return (max_txpower_avg & 0x01) + (max_txpower_avg >> 1);
  731. }
  732. /**
  733. * iwl_update_common_txpower: update channel tx power
  734. * update tx power per band based on EEPROM enhanced tx power info.
  735. */
  736. static s8 iwl_update_common_txpower(struct iwl_priv *priv,
  737. struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
  738. int section, int element, s8 *max_txpower_in_half_dbm)
  739. {
  740. struct iwl_channel_info *ch_info;
  741. int ch;
  742. bool is_ht40 = false;
  743. s8 max_txpower_avg; /* (dBm) */
  744. /* it is common section, contain all type (Legacy, HT and HT40)
  745. * based on the element in the section to determine
  746. * is it HT 40 or not
  747. */
  748. if (element == EEPROM_TXPOWER_COMMON_HT40_INDEX)
  749. is_ht40 = true;
  750. max_txpower_avg =
  751. iwl_get_max_txpower_avg(priv, enhanced_txpower,
  752. element, max_txpower_in_half_dbm);
  753. ch_info = priv->channel_info;
  754. for (ch = 0; ch < priv->channel_count; ch++) {
  755. /* find matching band and update tx power if needed */
  756. if ((ch_info->band == enhinfo[section].band) &&
  757. (ch_info->max_power_avg < max_txpower_avg) &&
  758. (!is_ht40)) {
  759. /* Update regulatory-based run-time data */
  760. ch_info->max_power_avg = ch_info->curr_txpow =
  761. max_txpower_avg;
  762. ch_info->scan_power = max_txpower_avg;
  763. }
  764. if ((ch_info->band == enhinfo[section].band) && is_ht40 &&
  765. (ch_info->ht40_max_power_avg < max_txpower_avg)) {
  766. /* Update regulatory-based run-time data */
  767. ch_info->ht40_max_power_avg = max_txpower_avg;
  768. }
  769. ch_info++;
  770. }
  771. return max_txpower_avg;
  772. }
  773. /**
  774. * iwl_update_channel_txpower: update channel tx power
  775. * update channel tx power based on EEPROM enhanced tx power info.
  776. */
  777. static s8 iwl_update_channel_txpower(struct iwl_priv *priv,
  778. struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
  779. int section, int element, s8 *max_txpower_in_half_dbm)
  780. {
  781. struct iwl_channel_info *ch_info;
  782. int ch;
  783. u8 channel;
  784. s8 max_txpower_avg; /* (dBm) */
  785. channel = enhinfo[section].iwl_eeprom_section_channel[element];
  786. max_txpower_avg =
  787. iwl_get_max_txpower_avg(priv, enhanced_txpower,
  788. element, max_txpower_in_half_dbm);
  789. ch_info = priv->channel_info;
  790. for (ch = 0; ch < priv->channel_count; ch++) {
  791. /* find matching channel and update tx power if needed */
  792. if (ch_info->channel == channel) {
  793. if ((ch_info->max_power_avg < max_txpower_avg) &&
  794. (!enhinfo[section].is_ht40)) {
  795. /* Update regulatory-based run-time data */
  796. ch_info->max_power_avg = max_txpower_avg;
  797. ch_info->curr_txpow = max_txpower_avg;
  798. ch_info->scan_power = max_txpower_avg;
  799. }
  800. if ((enhinfo[section].is_ht40) &&
  801. (ch_info->ht40_max_power_avg < max_txpower_avg)) {
  802. /* Update regulatory-based run-time data */
  803. ch_info->ht40_max_power_avg = max_txpower_avg;
  804. }
  805. break;
  806. }
  807. ch_info++;
  808. }
  809. return max_txpower_avg;
  810. }
  811. /**
  812. * iwlcore_eeprom_enhanced_txpower: process enhanced tx power info
  813. */
  814. void iwlcore_eeprom_enhanced_txpower(struct iwl_priv *priv)
  815. {
  816. int eeprom_section_count = 0;
  817. int section, element;
  818. struct iwl_eeprom_enhanced_txpwr *enhanced_txpower;
  819. u32 offset;
  820. s8 max_txpower_avg; /* (dBm) */
  821. s8 max_txpower_in_half_dbm; /* (half-dBm) */
  822. /* Loop through all the sections
  823. * adjust bands and channel's max tx power
  824. * Set the tx_power_user_lmt to the highest power
  825. * supported by any channels and chains
  826. */
  827. for (section = 0; section < ARRAY_SIZE(enhinfo); section++) {
  828. eeprom_section_count = enhinfo[section].count;
  829. offset = enhinfo[section].offset;
  830. enhanced_txpower = (struct iwl_eeprom_enhanced_txpwr *)
  831. iwl_eeprom_query_addr(priv, offset);
  832. /*
  833. * check for valid entry -
  834. * different version of EEPROM might contain different set
  835. * of enhanced tx power table
  836. * always check for valid entry before process
  837. * the information
  838. */
  839. if (!enhanced_txpower->common || enhanced_txpower->reserved)
  840. continue;
  841. for (element = 0; element < eeprom_section_count; element++) {
  842. if (enhinfo[section].is_common)
  843. max_txpower_avg =
  844. iwl_update_common_txpower(priv,
  845. enhanced_txpower, section,
  846. element,
  847. &max_txpower_in_half_dbm);
  848. else
  849. max_txpower_avg =
  850. iwl_update_channel_txpower(priv,
  851. enhanced_txpower, section,
  852. element,
  853. &max_txpower_in_half_dbm);
  854. /* Update the tx_power_user_lmt to the highest power
  855. * supported by any channel */
  856. if (max_txpower_avg > priv->tx_power_user_lmt)
  857. priv->tx_power_user_lmt = max_txpower_avg;
  858. /*
  859. * Update the tx_power_lmt_in_half_dbm to
  860. * the highest power supported by any channel
  861. */
  862. if (max_txpower_in_half_dbm >
  863. priv->tx_power_lmt_in_half_dbm)
  864. priv->tx_power_lmt_in_half_dbm =
  865. max_txpower_in_half_dbm;
  866. }
  867. }
  868. }
  869. EXPORT_SYMBOL(iwlcore_eeprom_enhanced_txpower);
  870. #define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
  871. ? # x " " : "")
  872. /**
  873. * iwl_init_channel_map - Set up driver's info for all possible channels
  874. */
  875. int iwl_init_channel_map(struct iwl_priv *priv)
  876. {
  877. int eeprom_ch_count = 0;
  878. const u8 *eeprom_ch_index = NULL;
  879. const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
  880. int band, ch;
  881. struct iwl_channel_info *ch_info;
  882. if (priv->channel_count) {
  883. IWL_DEBUG_INFO(priv, "Channel map already initialized.\n");
  884. return 0;
  885. }
  886. IWL_DEBUG_INFO(priv, "Initializing regulatory info from EEPROM\n");
  887. priv->channel_count =
  888. ARRAY_SIZE(iwl_eeprom_band_1) +
  889. ARRAY_SIZE(iwl_eeprom_band_2) +
  890. ARRAY_SIZE(iwl_eeprom_band_3) +
  891. ARRAY_SIZE(iwl_eeprom_band_4) +
  892. ARRAY_SIZE(iwl_eeprom_band_5);
  893. IWL_DEBUG_INFO(priv, "Parsing data for %d channels.\n", priv->channel_count);
  894. priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
  895. priv->channel_count, GFP_KERNEL);
  896. if (!priv->channel_info) {
  897. IWL_ERR(priv, "Could not allocate channel_info\n");
  898. priv->channel_count = 0;
  899. return -ENOMEM;
  900. }
  901. ch_info = priv->channel_info;
  902. /* Loop through the 5 EEPROM bands adding them in order to the
  903. * channel map we maintain (that contains additional information than
  904. * what just in the EEPROM) */
  905. for (band = 1; band <= 5; band++) {
  906. iwl_init_band_reference(priv, band, &eeprom_ch_count,
  907. &eeprom_ch_info, &eeprom_ch_index);
  908. /* Loop through each band adding each of the channels */
  909. for (ch = 0; ch < eeprom_ch_count; ch++) {
  910. ch_info->channel = eeprom_ch_index[ch];
  911. ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
  912. IEEE80211_BAND_5GHZ;
  913. /* permanently store EEPROM's channel regulatory flags
  914. * and max power in channel info database. */
  915. ch_info->eeprom = eeprom_ch_info[ch];
  916. /* Copy the run-time flags so they are there even on
  917. * invalid channels */
  918. ch_info->flags = eeprom_ch_info[ch].flags;
  919. /* First write that ht40 is not enabled, and then enable
  920. * one by one */
  921. ch_info->ht40_extension_channel =
  922. IEEE80211_CHAN_NO_HT40;
  923. if (!(is_channel_valid(ch_info))) {
  924. IWL_DEBUG_INFO(priv, "Ch. %d Flags %x [%sGHz] - "
  925. "No traffic\n",
  926. ch_info->channel,
  927. ch_info->flags,
  928. is_channel_a_band(ch_info) ?
  929. "5.2" : "2.4");
  930. ch_info++;
  931. continue;
  932. }
  933. /* Initialize regulatory-based run-time data */
  934. ch_info->max_power_avg = ch_info->curr_txpow =
  935. eeprom_ch_info[ch].max_power_avg;
  936. ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
  937. ch_info->min_power = 0;
  938. IWL_DEBUG_INFO(priv, "Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x %ddBm):"
  939. " Ad-Hoc %ssupported\n",
  940. ch_info->channel,
  941. is_channel_a_band(ch_info) ?
  942. "5.2" : "2.4",
  943. CHECK_AND_PRINT_I(VALID),
  944. CHECK_AND_PRINT_I(IBSS),
  945. CHECK_AND_PRINT_I(ACTIVE),
  946. CHECK_AND_PRINT_I(RADAR),
  947. CHECK_AND_PRINT_I(WIDE),
  948. CHECK_AND_PRINT_I(DFS),
  949. eeprom_ch_info[ch].flags,
  950. eeprom_ch_info[ch].max_power_avg,
  951. ((eeprom_ch_info[ch].
  952. flags & EEPROM_CHANNEL_IBSS)
  953. && !(eeprom_ch_info[ch].
  954. flags & EEPROM_CHANNEL_RADAR))
  955. ? "" : "not ");
  956. /* Set the tx_power_user_lmt to the highest power
  957. * supported by any channel */
  958. if (eeprom_ch_info[ch].max_power_avg >
  959. priv->tx_power_user_lmt)
  960. priv->tx_power_user_lmt =
  961. eeprom_ch_info[ch].max_power_avg;
  962. ch_info++;
  963. }
  964. }
  965. /* Check if we do have HT40 channels */
  966. if (priv->cfg->ops->lib->eeprom_ops.regulatory_bands[5] ==
  967. EEPROM_REGULATORY_BAND_NO_HT40 &&
  968. priv->cfg->ops->lib->eeprom_ops.regulatory_bands[6] ==
  969. EEPROM_REGULATORY_BAND_NO_HT40)
  970. return 0;
  971. /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
  972. for (band = 6; band <= 7; band++) {
  973. enum ieee80211_band ieeeband;
  974. iwl_init_band_reference(priv, band, &eeprom_ch_count,
  975. &eeprom_ch_info, &eeprom_ch_index);
  976. /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
  977. ieeeband =
  978. (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  979. /* Loop through each band adding each of the channels */
  980. for (ch = 0; ch < eeprom_ch_count; ch++) {
  981. /* Set up driver's info for lower half */
  982. iwl_mod_ht40_chan_info(priv, ieeeband,
  983. eeprom_ch_index[ch],
  984. &eeprom_ch_info[ch],
  985. IEEE80211_CHAN_NO_HT40PLUS);
  986. /* Set up driver's info for upper half */
  987. iwl_mod_ht40_chan_info(priv, ieeeband,
  988. eeprom_ch_index[ch] + 4,
  989. &eeprom_ch_info[ch],
  990. IEEE80211_CHAN_NO_HT40MINUS);
  991. }
  992. }
  993. /* for newer device (6000 series and up)
  994. * EEPROM contain enhanced tx power information
  995. * driver need to process addition information
  996. * to determine the max channel tx power limits
  997. */
  998. if (priv->cfg->ops->lib->eeprom_ops.update_enhanced_txpower)
  999. priv->cfg->ops->lib->eeprom_ops.update_enhanced_txpower(priv);
  1000. return 0;
  1001. }
  1002. EXPORT_SYMBOL(iwl_init_channel_map);
  1003. /*
  1004. * iwl_free_channel_map - undo allocations in iwl_init_channel_map
  1005. */
  1006. void iwl_free_channel_map(struct iwl_priv *priv)
  1007. {
  1008. kfree(priv->channel_info);
  1009. priv->channel_count = 0;
  1010. }
  1011. EXPORT_SYMBOL(iwl_free_channel_map);
  1012. /**
  1013. * iwl_get_channel_info - Find driver's private channel info
  1014. *
  1015. * Based on band and channel number.
  1016. */
  1017. const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv,
  1018. enum ieee80211_band band, u16 channel)
  1019. {
  1020. int i;
  1021. switch (band) {
  1022. case IEEE80211_BAND_5GHZ:
  1023. for (i = 14; i < priv->channel_count; i++) {
  1024. if (priv->channel_info[i].channel == channel)
  1025. return &priv->channel_info[i];
  1026. }
  1027. break;
  1028. case IEEE80211_BAND_2GHZ:
  1029. if (channel >= 1 && channel <= 14)
  1030. return &priv->channel_info[channel - 1];
  1031. break;
  1032. default:
  1033. BUG();
  1034. }
  1035. return NULL;
  1036. }
  1037. EXPORT_SYMBOL(iwl_get_channel_info);