iwl-eeprom.c 34 KB

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