iwl-eeprom.c 32 KB

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