eeprom.c 34 KB

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