iwl-eeprom.c 32 KB

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