iwl-eeprom.c 34 KB

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