iwl-agn-eeprom.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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 - 2010 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 - 2010 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-io.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. /**
  104. * struct iwl_txpwr_section: eeprom section information
  105. * @offset: indirect address into eeprom image
  106. * @count: number of "struct iwl_eeprom_enhanced_txpwr" in this section
  107. * @band: band type for the section
  108. * @is_common - true: common section, false: channel section
  109. * @is_cck - true: cck section, false: not cck section
  110. * @is_ht_40 - true: all channel in the section are HT40 channel,
  111. * false: legacy or HT 20 MHz
  112. * ignore if it is common section
  113. * @iwl_eeprom_section_channel: channel array in the section,
  114. * ignore if common section
  115. */
  116. struct iwl_txpwr_section {
  117. u32 offset;
  118. u8 count;
  119. enum ieee80211_band band;
  120. bool is_common;
  121. bool is_cck;
  122. bool is_ht40;
  123. u8 iwl_eeprom_section_channel[EEPROM_MAX_TXPOWER_SECTION_ELEMENTS];
  124. };
  125. /**
  126. * section 1 - 3 are regulatory tx power apply to all channels based on
  127. * modulation: CCK, OFDM
  128. * Band: 2.4GHz, 5.2GHz
  129. * section 4 - 10 are regulatory tx power apply to specified channels
  130. * For example:
  131. * 1L - Channel 1 Legacy
  132. * 1HT - Channel 1 HT
  133. * (1,+1) - Channel 1 HT40 "_above_"
  134. *
  135. * Section 1: all CCK channels
  136. * Section 2: all 2.4 GHz OFDM (Legacy, HT and HT40) channels
  137. * Section 3: all 5.2 GHz OFDM (Legacy, HT and HT40) channels
  138. * Section 4: 2.4 GHz 20MHz channels: 1L, 1HT, 2L, 2HT, 10L, 10HT, 11L, 11HT
  139. * Section 5: 2.4 GHz 40MHz channels: (1,+1) (2,+1) (6,+1) (7,+1) (9,+1)
  140. * Section 6: 5.2 GHz 20MHz channels: 36L, 64L, 100L, 36HT, 64HT, 100HT
  141. * Section 7: 5.2 GHz 40MHz channels: (36,+1) (60,+1) (100,+1)
  142. * Section 8: 2.4 GHz channel: 13L, 13HT
  143. * Section 9: 2.4 GHz channel: 140L, 140HT
  144. * Section 10: 2.4 GHz 40MHz channels: (132,+1) (44,+1)
  145. *
  146. */
  147. static const struct iwl_txpwr_section enhinfo[] = {
  148. { EEPROM_LB_CCK_20_COMMON, 1, IEEE80211_BAND_2GHZ, true, true, false },
  149. { EEPROM_LB_OFDM_COMMON, 3, IEEE80211_BAND_2GHZ, true, false, false },
  150. { EEPROM_HB_OFDM_COMMON, 3, IEEE80211_BAND_5GHZ, true, false, false },
  151. { EEPROM_LB_OFDM_20_BAND, 8, IEEE80211_BAND_2GHZ,
  152. false, false, false,
  153. {1, 1, 2, 2, 10, 10, 11, 11 } },
  154. { EEPROM_LB_OFDM_HT40_BAND, 5, IEEE80211_BAND_2GHZ,
  155. false, false, true,
  156. { 1, 2, 6, 7, 9 } },
  157. { EEPROM_HB_OFDM_20_BAND, 6, IEEE80211_BAND_5GHZ,
  158. false, false, false,
  159. { 36, 64, 100, 36, 64, 100 } },
  160. { EEPROM_HB_OFDM_HT40_BAND, 3, IEEE80211_BAND_5GHZ,
  161. false, false, true,
  162. { 36, 60, 100 } },
  163. { EEPROM_LB_OFDM_20_CHANNEL_13, 2, IEEE80211_BAND_2GHZ,
  164. false, false, false,
  165. { 13, 13 } },
  166. { EEPROM_HB_OFDM_20_CHANNEL_140, 2, IEEE80211_BAND_5GHZ,
  167. false, false, false,
  168. { 140, 140 } },
  169. { EEPROM_HB_OFDM_HT40_BAND_1, 2, IEEE80211_BAND_5GHZ,
  170. false, false, true,
  171. { 132, 44 } },
  172. };
  173. /******************************************************************************
  174. *
  175. * EEPROM related functions
  176. *
  177. ******************************************************************************/
  178. /*
  179. * The device's EEPROM semaphore prevents conflicts between driver and uCode
  180. * when accessing the EEPROM; each access is a series of pulses to/from the
  181. * EEPROM chip, not a single event, so even reads could conflict if they
  182. * weren't arbitrated by the semaphore.
  183. */
  184. int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv)
  185. {
  186. u16 count;
  187. int ret;
  188. for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
  189. /* Request semaphore */
  190. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  191. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  192. /* See if we got it */
  193. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  194. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  195. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  196. EEPROM_SEM_TIMEOUT);
  197. if (ret >= 0) {
  198. IWL_DEBUG_IO(priv,
  199. "Acquired semaphore after %d tries.\n",
  200. count+1);
  201. return ret;
  202. }
  203. }
  204. return ret;
  205. }
  206. void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv)
  207. {
  208. iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
  209. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  210. }
  211. int iwl_eeprom_check_version(struct iwl_priv *priv)
  212. {
  213. u16 eeprom_ver;
  214. u16 calib_ver;
  215. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  216. calib_ver = priv->cfg->ops->lib->eeprom_ops.calib_version(priv);
  217. if (eeprom_ver < priv->cfg->eeprom_ver ||
  218. calib_ver < priv->cfg->eeprom_calib_ver)
  219. goto err;
  220. IWL_INFO(priv, "device EEPROM VER=0x%x, CALIB=0x%x\n",
  221. eeprom_ver, calib_ver);
  222. return 0;
  223. err:
  224. IWL_ERR(priv, "Unsupported (too old) EEPROM VER=0x%x < 0x%x "
  225. "CALIB=0x%x < 0x%x\n",
  226. eeprom_ver, priv->cfg->eeprom_ver,
  227. calib_ver, priv->cfg->eeprom_calib_ver);
  228. return -EINVAL;
  229. }
  230. int iwl_eeprom_check_sku(struct iwl_priv *priv)
  231. {
  232. u16 eeprom_sku;
  233. u16 radio_cfg;
  234. eeprom_sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP);
  235. priv->cfg->sku = ((eeprom_sku & EEPROM_SKU_CAP_BAND_SELECTION) >>
  236. EEPROM_SKU_CAP_BAND_POS);
  237. if (eeprom_sku & EEPROM_SKU_CAP_11N_ENABLE)
  238. priv->cfg->sku |= IWL_SKU_N;
  239. if (!priv->cfg->sku) {
  240. IWL_ERR(priv, "Invalid device sku\n");
  241. return -EINVAL;
  242. }
  243. IWL_INFO(priv, "Device SKU: 0X%x\n", priv->cfg->sku);
  244. if (!priv->cfg->valid_tx_ant && !priv->cfg->valid_rx_ant) {
  245. /* not using .cfg overwrite */
  246. radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
  247. priv->cfg->valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
  248. priv->cfg->valid_rx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
  249. if (!priv->cfg->valid_tx_ant || !priv->cfg->valid_rx_ant) {
  250. IWL_ERR(priv, "Invalid chain (0X%x, 0X%x)\n",
  251. priv->cfg->valid_tx_ant,
  252. priv->cfg->valid_rx_ant);
  253. return -EINVAL;
  254. }
  255. IWL_INFO(priv, "Valid Tx ant: 0X%x, Valid Rx ant: 0X%x\n",
  256. priv->cfg->valid_tx_ant, priv->cfg->valid_rx_ant);
  257. }
  258. /*
  259. * for some special cases,
  260. * EEPROM did not reflect the correct antenna setting
  261. * so overwrite the valid tx/rx antenna from .cfg
  262. */
  263. return 0;
  264. }
  265. void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
  266. {
  267. const u8 *addr = priv->cfg->ops->lib->eeprom_ops.query_addr(priv,
  268. EEPROM_MAC_ADDRESS);
  269. memcpy(mac, addr, ETH_ALEN);
  270. }
  271. /**
  272. * iwl_get_max_txpower_avg - get the highest tx power from all chains.
  273. * find the highest tx power from all chains for the channel
  274. */
  275. static s8 iwl_get_max_txpower_avg(struct iwl_priv *priv,
  276. struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
  277. int element, s8 *max_txpower_in_half_dbm)
  278. {
  279. s8 max_txpower_avg = 0; /* (dBm) */
  280. IWL_DEBUG_INFO(priv, "%d - "
  281. "chain_a: %d dB chain_b: %d dB "
  282. "chain_c: %d dB mimo2: %d dB mimo3: %d dB\n",
  283. element,
  284. enhanced_txpower[element].chain_a_max >> 1,
  285. enhanced_txpower[element].chain_b_max >> 1,
  286. enhanced_txpower[element].chain_c_max >> 1,
  287. enhanced_txpower[element].mimo2_max >> 1,
  288. enhanced_txpower[element].mimo3_max >> 1);
  289. /* Take the highest tx power from any valid chains */
  290. if ((priv->cfg->valid_tx_ant & ANT_A) &&
  291. (enhanced_txpower[element].chain_a_max > max_txpower_avg))
  292. max_txpower_avg = enhanced_txpower[element].chain_a_max;
  293. if ((priv->cfg->valid_tx_ant & ANT_B) &&
  294. (enhanced_txpower[element].chain_b_max > max_txpower_avg))
  295. max_txpower_avg = enhanced_txpower[element].chain_b_max;
  296. if ((priv->cfg->valid_tx_ant & ANT_C) &&
  297. (enhanced_txpower[element].chain_c_max > max_txpower_avg))
  298. max_txpower_avg = enhanced_txpower[element].chain_c_max;
  299. if (((priv->cfg->valid_tx_ant == ANT_AB) |
  300. (priv->cfg->valid_tx_ant == ANT_BC) |
  301. (priv->cfg->valid_tx_ant == ANT_AC)) &&
  302. (enhanced_txpower[element].mimo2_max > max_txpower_avg))
  303. max_txpower_avg = enhanced_txpower[element].mimo2_max;
  304. if ((priv->cfg->valid_tx_ant == ANT_ABC) &&
  305. (enhanced_txpower[element].mimo3_max > max_txpower_avg))
  306. max_txpower_avg = enhanced_txpower[element].mimo3_max;
  307. /*
  308. * max. tx power in EEPROM is in 1/2 dBm format
  309. * convert from 1/2 dBm to dBm (round-up convert)
  310. * but we also do not want to loss 1/2 dBm resolution which
  311. * will impact performance
  312. */
  313. *max_txpower_in_half_dbm = max_txpower_avg;
  314. return (max_txpower_avg & 0x01) + (max_txpower_avg >> 1);
  315. }
  316. /**
  317. * iwl_update_common_txpower: update channel tx power
  318. * update tx power per band based on EEPROM enhanced tx power info.
  319. */
  320. static s8 iwl_update_common_txpower(struct iwl_priv *priv,
  321. struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
  322. int section, int element, s8 *max_txpower_in_half_dbm)
  323. {
  324. struct iwl_channel_info *ch_info;
  325. int ch;
  326. bool is_ht40 = false;
  327. s8 max_txpower_avg; /* (dBm) */
  328. /* it is common section, contain all type (Legacy, HT and HT40)
  329. * based on the element in the section to determine
  330. * is it HT 40 or not
  331. */
  332. if (element == EEPROM_TXPOWER_COMMON_HT40_INDEX)
  333. is_ht40 = true;
  334. max_txpower_avg =
  335. iwl_get_max_txpower_avg(priv, enhanced_txpower,
  336. element, max_txpower_in_half_dbm);
  337. ch_info = priv->channel_info;
  338. for (ch = 0; ch < priv->channel_count; ch++) {
  339. /* find matching band and update tx power if needed */
  340. if ((ch_info->band == enhinfo[section].band) &&
  341. (ch_info->max_power_avg < max_txpower_avg) &&
  342. (!is_ht40)) {
  343. /* Update regulatory-based run-time data */
  344. ch_info->max_power_avg = ch_info->curr_txpow =
  345. max_txpower_avg;
  346. ch_info->scan_power = max_txpower_avg;
  347. }
  348. if ((ch_info->band == enhinfo[section].band) && is_ht40 &&
  349. (ch_info->ht40_max_power_avg < max_txpower_avg)) {
  350. /* Update regulatory-based run-time data */
  351. ch_info->ht40_max_power_avg = max_txpower_avg;
  352. }
  353. ch_info++;
  354. }
  355. return max_txpower_avg;
  356. }
  357. /**
  358. * iwl_update_channel_txpower: update channel tx power
  359. * update channel tx power based on EEPROM enhanced tx power info.
  360. */
  361. static s8 iwl_update_channel_txpower(struct iwl_priv *priv,
  362. struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
  363. int section, int element, s8 *max_txpower_in_half_dbm)
  364. {
  365. struct iwl_channel_info *ch_info;
  366. int ch;
  367. u8 channel;
  368. s8 max_txpower_avg; /* (dBm) */
  369. channel = enhinfo[section].iwl_eeprom_section_channel[element];
  370. max_txpower_avg =
  371. iwl_get_max_txpower_avg(priv, enhanced_txpower,
  372. element, max_txpower_in_half_dbm);
  373. ch_info = priv->channel_info;
  374. for (ch = 0; ch < priv->channel_count; ch++) {
  375. /* find matching channel and update tx power if needed */
  376. if (ch_info->channel == channel) {
  377. if ((ch_info->max_power_avg < max_txpower_avg) &&
  378. (!enhinfo[section].is_ht40)) {
  379. /* Update regulatory-based run-time data */
  380. ch_info->max_power_avg = max_txpower_avg;
  381. ch_info->curr_txpow = max_txpower_avg;
  382. ch_info->scan_power = max_txpower_avg;
  383. }
  384. if ((enhinfo[section].is_ht40) &&
  385. (ch_info->ht40_max_power_avg < max_txpower_avg)) {
  386. /* Update regulatory-based run-time data */
  387. ch_info->ht40_max_power_avg = max_txpower_avg;
  388. }
  389. break;
  390. }
  391. ch_info++;
  392. }
  393. return max_txpower_avg;
  394. }
  395. /**
  396. * iwlcore_eeprom_enhanced_txpower: process enhanced tx power info
  397. */
  398. void iwlcore_eeprom_enhanced_txpower(struct iwl_priv *priv)
  399. {
  400. int eeprom_section_count = 0;
  401. int section, element;
  402. struct iwl_eeprom_enhanced_txpwr *enhanced_txpower;
  403. u32 offset;
  404. s8 max_txpower_avg; /* (dBm) */
  405. s8 max_txpower_in_half_dbm; /* (half-dBm) */
  406. /* Loop through all the sections
  407. * adjust bands and channel's max tx power
  408. * Set the tx_power_user_lmt to the highest power
  409. * supported by any channels and chains
  410. */
  411. for (section = 0; section < ARRAY_SIZE(enhinfo); section++) {
  412. eeprom_section_count = enhinfo[section].count;
  413. offset = enhinfo[section].offset;
  414. enhanced_txpower = (struct iwl_eeprom_enhanced_txpwr *)
  415. iwl_eeprom_query_addr(priv, offset);
  416. /*
  417. * check for valid entry -
  418. * different version of EEPROM might contain different set
  419. * of enhanced tx power table
  420. * always check for valid entry before process
  421. * the information
  422. */
  423. if (!enhanced_txpower->common || enhanced_txpower->reserved)
  424. continue;
  425. for (element = 0; element < eeprom_section_count; element++) {
  426. if (enhinfo[section].is_common)
  427. max_txpower_avg =
  428. iwl_update_common_txpower(priv,
  429. enhanced_txpower, section,
  430. element,
  431. &max_txpower_in_half_dbm);
  432. else
  433. max_txpower_avg =
  434. iwl_update_channel_txpower(priv,
  435. enhanced_txpower, section,
  436. element,
  437. &max_txpower_in_half_dbm);
  438. /* Update the tx_power_user_lmt to the highest power
  439. * supported by any channel */
  440. if (max_txpower_avg > priv->tx_power_user_lmt)
  441. priv->tx_power_user_lmt = max_txpower_avg;
  442. /*
  443. * Update the tx_power_lmt_in_half_dbm to
  444. * the highest power supported by any channel
  445. */
  446. if (max_txpower_in_half_dbm >
  447. priv->tx_power_lmt_in_half_dbm)
  448. priv->tx_power_lmt_in_half_dbm =
  449. max_txpower_in_half_dbm;
  450. }
  451. }
  452. }