iwl-eeprom.c 34 KB

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