iwl-5000.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  23. *
  24. *****************************************************************************/
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/version.h>
  28. #include <linux/init.h>
  29. #include <linux/pci.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/delay.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/wireless.h>
  35. #include <net/mac80211.h>
  36. #include <linux/etherdevice.h>
  37. #include <asm/unaligned.h>
  38. #include "iwl-eeprom.h"
  39. #include "iwl-4965.h"
  40. #include "iwl-core.h"
  41. #include "iwl-io.h"
  42. #include "iwl-helpers.h"
  43. #include "iwl-5000-hw.h"
  44. #define IWL5000_UCODE_API "-1"
  45. static int iwl5000_apm_init(struct iwl_priv *priv)
  46. {
  47. int ret = 0;
  48. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  49. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  50. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  51. /* set "initialization complete" bit to move adapter
  52. * D0U* --> D0A* state */
  53. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  54. /* wait for clock stabilization */
  55. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  56. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  57. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  58. if (ret < 0) {
  59. IWL_DEBUG_INFO("Failed to init the card\n");
  60. return ret;
  61. }
  62. ret = iwl_grab_nic_access(priv);
  63. if (ret)
  64. return ret;
  65. /* enable DMA */
  66. iwl_write_prph(priv, APMG_CLK_EN_REG,
  67. APMG_CLK_VAL_DMA_CLK_RQT);
  68. udelay(20);
  69. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  70. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  71. iwl_release_nic_access(priv);
  72. return ret;
  73. }
  74. /*
  75. * EEPROM
  76. */
  77. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  78. {
  79. u16 offset = 0;
  80. if ((address & INDIRECT_ADDRESS) == 0)
  81. return address;
  82. switch (address & INDIRECT_TYPE_MSK) {
  83. case INDIRECT_HOST:
  84. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
  85. break;
  86. case INDIRECT_GENERAL:
  87. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
  88. break;
  89. case INDIRECT_REGULATORY:
  90. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
  91. break;
  92. case INDIRECT_CALIBRATION:
  93. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
  94. break;
  95. case INDIRECT_PROCESS_ADJST:
  96. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
  97. break;
  98. case INDIRECT_OTHERS:
  99. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
  100. break;
  101. default:
  102. IWL_ERROR("illegal indirect type: 0x%X\n",
  103. address & INDIRECT_TYPE_MSK);
  104. break;
  105. }
  106. /* translate the offset from words to byte */
  107. return (address & ADDRESS_MSK) + (offset << 1);
  108. }
  109. static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
  110. {
  111. u16 eeprom_ver;
  112. struct iwl_eeprom_calib_hdr {
  113. u8 version;
  114. u8 pa_type;
  115. u16 voltage;
  116. } *hdr;
  117. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  118. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  119. EEPROM_5000_CALIB_ALL);
  120. if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
  121. hdr->version < EEPROM_5000_TX_POWER_VERSION)
  122. goto err;
  123. return 0;
  124. err:
  125. IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
  126. eeprom_ver, EEPROM_5000_EEPROM_VERSION,
  127. hdr->version, EEPROM_5000_TX_POWER_VERSION);
  128. return -EINVAL;
  129. }
  130. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  131. static void iwl5000_gain_computation(struct iwl_priv *priv,
  132. u32 average_noise[NUM_RX_CHAINS],
  133. u16 min_average_noise_antenna_i,
  134. u32 min_average_noise)
  135. {
  136. int i;
  137. s32 delta_g;
  138. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  139. /* Find Gain Code for the antennas B and C */
  140. for (i = 1; i < NUM_RX_CHAINS; i++) {
  141. if ((data->disconn_array[i])) {
  142. data->delta_gain_code[i] = 0;
  143. continue;
  144. }
  145. delta_g = (1000 * ((s32)average_noise[0] -
  146. (s32)average_noise[i])) / 1500;
  147. /* bound gain by 2 bits value max, 3rd bit is sign */
  148. data->delta_gain_code[i] =
  149. min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  150. if (delta_g < 0)
  151. /* set negative sign */
  152. data->delta_gain_code[i] |= (1 << 2);
  153. }
  154. IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
  155. data->delta_gain_code[1], data->delta_gain_code[2]);
  156. if (!data->radio_write) {
  157. struct iwl5000_calibration_chain_noise_gain_cmd cmd;
  158. memset(&cmd, 0, sizeof(cmd));
  159. cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
  160. cmd.delta_gain_1 = data->delta_gain_code[1];
  161. cmd.delta_gain_2 = data->delta_gain_code[2];
  162. iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
  163. sizeof(cmd), &cmd, NULL);
  164. data->radio_write = 1;
  165. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  166. }
  167. data->chain_noise_a = 0;
  168. data->chain_noise_b = 0;
  169. data->chain_noise_c = 0;
  170. data->chain_signal_a = 0;
  171. data->chain_signal_b = 0;
  172. data->chain_signal_c = 0;
  173. data->beacon_count = 0;
  174. }
  175. static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
  176. {
  177. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  178. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  179. struct iwl5000_calibration_chain_noise_reset_cmd cmd;
  180. memset(&cmd, 0, sizeof(cmd));
  181. cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
  182. if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  183. sizeof(cmd), &cmd))
  184. IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
  185. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  186. IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
  187. }
  188. }
  189. static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  190. .min_nrg_cck = 95,
  191. .max_nrg_cck = 0,
  192. .auto_corr_min_ofdm = 90,
  193. .auto_corr_min_ofdm_mrc = 170,
  194. .auto_corr_min_ofdm_x1 = 120,
  195. .auto_corr_min_ofdm_mrc_x1 = 240,
  196. .auto_corr_max_ofdm = 120,
  197. .auto_corr_max_ofdm_mrc = 210,
  198. .auto_corr_max_ofdm_x1 = 155,
  199. .auto_corr_max_ofdm_mrc_x1 = 290,
  200. .auto_corr_min_cck = 125,
  201. .auto_corr_max_cck = 200,
  202. .auto_corr_min_cck_mrc = 170,
  203. .auto_corr_max_cck_mrc = 400,
  204. .nrg_th_cck = 95,
  205. .nrg_th_ofdm = 95,
  206. };
  207. #endif /* CONFIG_IWL5000_RUN_TIME_CALIB */
  208. static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
  209. size_t offset)
  210. {
  211. u32 address = eeprom_indirect_address(priv, offset);
  212. BUG_ON(address >= priv->cfg->eeprom_size);
  213. return &priv->eeprom[address];
  214. }
  215. static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  216. {
  217. if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
  218. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  219. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  220. IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
  221. return -EINVAL;
  222. }
  223. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  224. priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
  225. priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
  226. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  227. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  228. if (priv->cfg->mod_params->amsdu_size_8K)
  229. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
  230. else
  231. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
  232. priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
  233. priv->hw_params.max_stations = IWL5000_STATION_COUNT;
  234. priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
  235. priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
  236. priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
  237. priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
  238. priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
  239. BIT(IEEE80211_BAND_5GHZ);
  240. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  241. priv->hw_params.sens = &iwl5000_sensitivity;
  242. #endif
  243. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  244. case CSR_HW_REV_TYPE_5100:
  245. case CSR_HW_REV_TYPE_5150:
  246. priv->hw_params.tx_chains_num = 1;
  247. priv->hw_params.rx_chains_num = 2;
  248. /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
  249. priv->hw_params.valid_tx_ant = ANT_A;
  250. priv->hw_params.valid_rx_ant = ANT_AB;
  251. break;
  252. case CSR_HW_REV_TYPE_5300:
  253. case CSR_HW_REV_TYPE_5350:
  254. priv->hw_params.tx_chains_num = 3;
  255. priv->hw_params.rx_chains_num = 3;
  256. priv->hw_params.valid_tx_ant = ANT_ABC;
  257. priv->hw_params.valid_rx_ant = ANT_ABC;
  258. break;
  259. }
  260. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  261. case CSR_HW_REV_TYPE_5100:
  262. case CSR_HW_REV_TYPE_5300:
  263. /* 5X00 wants in Celsius */
  264. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
  265. break;
  266. case CSR_HW_REV_TYPE_5150:
  267. case CSR_HW_REV_TYPE_5350:
  268. /* 5X50 wants in Kelvin */
  269. priv->hw_params.ct_kill_threshold =
  270. CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
  271. break;
  272. }
  273. return 0;
  274. }
  275. static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
  276. {
  277. priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
  278. sizeof(struct iwl5000_shared),
  279. &priv->shared_phys);
  280. if (!priv->shared_virt)
  281. return -ENOMEM;
  282. memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
  283. return 0;
  284. }
  285. static void iwl5000_free_shared_mem(struct iwl_priv *priv)
  286. {
  287. if (priv->shared_virt)
  288. pci_free_consistent(priv->pci_dev,
  289. sizeof(struct iwl5000_shared),
  290. priv->shared_virt,
  291. priv->shared_phys);
  292. }
  293. /**
  294. * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  295. */
  296. static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  297. struct iwl4965_tx_queue *txq,
  298. u16 byte_cnt)
  299. {
  300. struct iwl5000_shared *shared_data = priv->shared_virt;
  301. int txq_id = txq->q.id;
  302. u8 sec_ctl = 0;
  303. u8 sta = 0;
  304. int len;
  305. len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  306. if (txq_id != IWL_CMD_QUEUE_NUM) {
  307. sta = txq->cmd[txq->q.write_ptr].cmd.tx.sta_id;
  308. sec_ctl = txq->cmd[txq->q.write_ptr].cmd.tx.sec_ctl;
  309. switch (sec_ctl & TX_CMD_SEC_MSK) {
  310. case TX_CMD_SEC_CCM:
  311. len += CCMP_MIC_LEN;
  312. break;
  313. case TX_CMD_SEC_TKIP:
  314. len += TKIP_ICV_LEN;
  315. break;
  316. case TX_CMD_SEC_WEP:
  317. len += WEP_IV_LEN + WEP_ICV_LEN;
  318. break;
  319. }
  320. }
  321. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  322. tfd_offset[txq->q.write_ptr], byte_cnt, len);
  323. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  324. tfd_offset[txq->q.write_ptr], sta_id, sta);
  325. if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
  326. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  327. tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
  328. byte_cnt, len);
  329. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  330. tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
  331. sta_id, sta);
  332. }
  333. }
  334. static struct iwl_hcmd_ops iwl5000_hcmd = {
  335. };
  336. static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  337. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  338. .gain_computation = iwl5000_gain_computation,
  339. .chain_noise_reset = iwl5000_chain_noise_reset,
  340. #endif
  341. };
  342. static struct iwl_lib_ops iwl5000_lib = {
  343. .set_hw_params = iwl5000_hw_set_hw_params,
  344. .alloc_shared_mem = iwl5000_alloc_shared_mem,
  345. .free_shared_mem = iwl5000_free_shared_mem,
  346. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  347. .apm_ops = {
  348. .init = iwl5000_apm_init,
  349. .set_pwr_src = iwl4965_set_pwr_src,
  350. },
  351. .eeprom_ops = {
  352. .regulatory_bands = {
  353. EEPROM_5000_REG_BAND_1_CHANNELS,
  354. EEPROM_5000_REG_BAND_2_CHANNELS,
  355. EEPROM_5000_REG_BAND_3_CHANNELS,
  356. EEPROM_5000_REG_BAND_4_CHANNELS,
  357. EEPROM_5000_REG_BAND_5_CHANNELS,
  358. EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
  359. EEPROM_5000_REG_BAND_52_FAT_CHANNELS
  360. },
  361. .verify_signature = iwlcore_eeprom_verify_signature,
  362. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  363. .release_semaphore = iwlcore_eeprom_release_semaphore,
  364. .check_version = iwl5000_eeprom_check_version,
  365. .query_addr = iwl5000_eeprom_query_addr,
  366. },
  367. };
  368. static struct iwl_ops iwl5000_ops = {
  369. .lib = &iwl5000_lib,
  370. .hcmd = &iwl5000_hcmd,
  371. .utils = &iwl5000_hcmd_utils,
  372. };
  373. static struct iwl_mod_params iwl50_mod_params = {
  374. .num_of_queues = IWL50_NUM_QUEUES,
  375. .enable_qos = 1,
  376. .amsdu_size_8K = 1,
  377. /* the rest are 0 by default */
  378. };
  379. struct iwl_cfg iwl5300_agn_cfg = {
  380. .name = "5300AGN",
  381. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  382. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  383. .ops = &iwl5000_ops,
  384. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  385. .mod_params = &iwl50_mod_params,
  386. };
  387. struct iwl_cfg iwl5100_agn_cfg = {
  388. .name = "5100AGN",
  389. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  390. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  391. .ops = &iwl5000_ops,
  392. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  393. .mod_params = &iwl50_mod_params,
  394. };
  395. struct iwl_cfg iwl5350_agn_cfg = {
  396. .name = "5350AGN",
  397. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  398. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  399. .ops = &iwl5000_ops,
  400. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  401. .mod_params = &iwl50_mod_params,
  402. };
  403. module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
  404. MODULE_PARM_DESC(disable50,
  405. "manually disable the 50XX radio (default 0 [radio on])");
  406. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
  407. MODULE_PARM_DESC(swcrypto50,
  408. "using software crypto engine (default 0 [hardware])\n");
  409. module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
  410. MODULE_PARM_DESC(debug50, "50XX debug output mask");
  411. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
  412. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  413. module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
  414. MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
  415. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
  416. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");