iwl-eeprom.c 32 KB

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