iwl-eeprom.c 34 KB

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