iwl-eeprom.c 35 KB

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