iwl-eeprom.c 33 KB

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