iwl-eeprom.c 32 KB

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