iwl-5000.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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-dev.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 const u16 iwl5000_default_queue_to_tx_fifo[] = {
  46. IWL_TX_FIFO_AC3,
  47. IWL_TX_FIFO_AC2,
  48. IWL_TX_FIFO_AC1,
  49. IWL_TX_FIFO_AC0,
  50. IWL50_CMD_FIFO_NUM,
  51. IWL_TX_FIFO_HCCA_1,
  52. IWL_TX_FIFO_HCCA_2
  53. };
  54. /* FIXME: same implementation as 4965 */
  55. static int iwl5000_apm_stop_master(struct iwl_priv *priv)
  56. {
  57. int ret = 0;
  58. unsigned long flags;
  59. spin_lock_irqsave(&priv->lock, flags);
  60. /* set stop master bit */
  61. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  62. ret = iwl_poll_bit(priv, CSR_RESET,
  63. CSR_RESET_REG_FLAG_MASTER_DISABLED,
  64. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  65. if (ret < 0)
  66. goto out;
  67. out:
  68. spin_unlock_irqrestore(&priv->lock, flags);
  69. IWL_DEBUG_INFO("stop master\n");
  70. return ret;
  71. }
  72. static int iwl5000_apm_init(struct iwl_priv *priv)
  73. {
  74. int ret = 0;
  75. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  76. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  77. /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
  78. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  79. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  80. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  81. /* set "initialization complete" bit to move adapter
  82. * D0U* --> D0A* state */
  83. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  84. /* wait for clock stabilization */
  85. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  86. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  87. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  88. if (ret < 0) {
  89. IWL_DEBUG_INFO("Failed to init the card\n");
  90. return ret;
  91. }
  92. ret = iwl_grab_nic_access(priv);
  93. if (ret)
  94. return ret;
  95. /* enable DMA */
  96. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  97. udelay(20);
  98. /* disable L1-Active */
  99. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  100. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  101. iwl_release_nic_access(priv);
  102. return ret;
  103. }
  104. /* FIXME: this is indentical to 4965 */
  105. static void iwl5000_apm_stop(struct iwl_priv *priv)
  106. {
  107. unsigned long flags;
  108. iwl5000_apm_stop_master(priv);
  109. spin_lock_irqsave(&priv->lock, flags);
  110. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  111. udelay(10);
  112. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  113. spin_unlock_irqrestore(&priv->lock, flags);
  114. }
  115. static int iwl5000_apm_reset(struct iwl_priv *priv)
  116. {
  117. int ret = 0;
  118. unsigned long flags;
  119. iwl5000_apm_stop_master(priv);
  120. spin_lock_irqsave(&priv->lock, flags);
  121. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  122. udelay(10);
  123. /* FIXME: put here L1A -L0S w/a */
  124. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  125. /* set "initialization complete" bit to move adapter
  126. * D0U* --> D0A* state */
  127. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  128. /* wait for clock stabilization */
  129. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  130. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  131. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  132. if (ret < 0) {
  133. IWL_DEBUG_INFO("Failed to init the card\n");
  134. goto out;
  135. }
  136. ret = iwl_grab_nic_access(priv);
  137. if (ret)
  138. goto out;
  139. /* enable DMA */
  140. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  141. udelay(20);
  142. /* disable L1-Active */
  143. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  144. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  145. iwl_release_nic_access(priv);
  146. out:
  147. spin_unlock_irqrestore(&priv->lock, flags);
  148. return ret;
  149. }
  150. static void iwl5000_nic_config(struct iwl_priv *priv)
  151. {
  152. unsigned long flags;
  153. u16 radio_cfg;
  154. u8 val_link;
  155. spin_lock_irqsave(&priv->lock, flags);
  156. pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
  157. /* L1 is enabled by BIOS */
  158. if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
  159. /* diable L0S disabled L1A enabled */
  160. iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  161. else
  162. /* L0S enabled L1A disabled */
  163. iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  164. radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
  165. /* write radio config values to register */
  166. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
  167. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  168. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  169. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  170. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  171. /* set CSR_HW_CONFIG_REG for uCode use */
  172. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  173. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  174. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  175. spin_unlock_irqrestore(&priv->lock, flags);
  176. }
  177. /*
  178. * EEPROM
  179. */
  180. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  181. {
  182. u16 offset = 0;
  183. if ((address & INDIRECT_ADDRESS) == 0)
  184. return address;
  185. switch (address & INDIRECT_TYPE_MSK) {
  186. case INDIRECT_HOST:
  187. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
  188. break;
  189. case INDIRECT_GENERAL:
  190. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
  191. break;
  192. case INDIRECT_REGULATORY:
  193. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
  194. break;
  195. case INDIRECT_CALIBRATION:
  196. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
  197. break;
  198. case INDIRECT_PROCESS_ADJST:
  199. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
  200. break;
  201. case INDIRECT_OTHERS:
  202. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
  203. break;
  204. default:
  205. IWL_ERROR("illegal indirect type: 0x%X\n",
  206. address & INDIRECT_TYPE_MSK);
  207. break;
  208. }
  209. /* translate the offset from words to byte */
  210. return (address & ADDRESS_MSK) + (offset << 1);
  211. }
  212. static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
  213. {
  214. u16 eeprom_ver;
  215. struct iwl_eeprom_calib_hdr {
  216. u8 version;
  217. u8 pa_type;
  218. u16 voltage;
  219. } *hdr;
  220. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  221. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  222. EEPROM_5000_CALIB_ALL);
  223. if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
  224. hdr->version < EEPROM_5000_TX_POWER_VERSION)
  225. goto err;
  226. return 0;
  227. err:
  228. IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
  229. eeprom_ver, EEPROM_5000_EEPROM_VERSION,
  230. hdr->version, EEPROM_5000_TX_POWER_VERSION);
  231. return -EINVAL;
  232. }
  233. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  234. static void iwl5000_gain_computation(struct iwl_priv *priv,
  235. u32 average_noise[NUM_RX_CHAINS],
  236. u16 min_average_noise_antenna_i,
  237. u32 min_average_noise)
  238. {
  239. int i;
  240. s32 delta_g;
  241. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  242. /* Find Gain Code for the antennas B and C */
  243. for (i = 1; i < NUM_RX_CHAINS; i++) {
  244. if ((data->disconn_array[i])) {
  245. data->delta_gain_code[i] = 0;
  246. continue;
  247. }
  248. delta_g = (1000 * ((s32)average_noise[0] -
  249. (s32)average_noise[i])) / 1500;
  250. /* bound gain by 2 bits value max, 3rd bit is sign */
  251. data->delta_gain_code[i] =
  252. min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  253. if (delta_g < 0)
  254. /* set negative sign */
  255. data->delta_gain_code[i] |= (1 << 2);
  256. }
  257. IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
  258. data->delta_gain_code[1], data->delta_gain_code[2]);
  259. if (!data->radio_write) {
  260. struct iwl5000_calibration_chain_noise_gain_cmd cmd;
  261. memset(&cmd, 0, sizeof(cmd));
  262. cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
  263. cmd.delta_gain_1 = data->delta_gain_code[1];
  264. cmd.delta_gain_2 = data->delta_gain_code[2];
  265. iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
  266. sizeof(cmd), &cmd, NULL);
  267. data->radio_write = 1;
  268. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  269. }
  270. data->chain_noise_a = 0;
  271. data->chain_noise_b = 0;
  272. data->chain_noise_c = 0;
  273. data->chain_signal_a = 0;
  274. data->chain_signal_b = 0;
  275. data->chain_signal_c = 0;
  276. data->beacon_count = 0;
  277. }
  278. static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
  279. {
  280. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  281. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  282. struct iwl5000_calibration_chain_noise_reset_cmd cmd;
  283. memset(&cmd, 0, sizeof(cmd));
  284. cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
  285. if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  286. sizeof(cmd), &cmd))
  287. IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
  288. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  289. IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
  290. }
  291. }
  292. static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  293. .min_nrg_cck = 95,
  294. .max_nrg_cck = 0,
  295. .auto_corr_min_ofdm = 90,
  296. .auto_corr_min_ofdm_mrc = 170,
  297. .auto_corr_min_ofdm_x1 = 120,
  298. .auto_corr_min_ofdm_mrc_x1 = 240,
  299. .auto_corr_max_ofdm = 120,
  300. .auto_corr_max_ofdm_mrc = 210,
  301. .auto_corr_max_ofdm_x1 = 155,
  302. .auto_corr_max_ofdm_mrc_x1 = 290,
  303. .auto_corr_min_cck = 125,
  304. .auto_corr_max_cck = 200,
  305. .auto_corr_min_cck_mrc = 170,
  306. .auto_corr_max_cck_mrc = 400,
  307. .nrg_th_cck = 95,
  308. .nrg_th_ofdm = 95,
  309. };
  310. #endif /* CONFIG_IWL5000_RUN_TIME_CALIB */
  311. static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
  312. size_t offset)
  313. {
  314. u32 address = eeprom_indirect_address(priv, offset);
  315. BUG_ON(address >= priv->cfg->eeprom_size);
  316. return &priv->eeprom[address];
  317. }
  318. /*
  319. * ucode
  320. */
  321. static int iwl5000_load_section(struct iwl_priv *priv,
  322. struct fw_desc *image,
  323. u32 dst_addr)
  324. {
  325. int ret = 0;
  326. unsigned long flags;
  327. dma_addr_t phy_addr = image->p_addr;
  328. u32 byte_cnt = image->len;
  329. spin_lock_irqsave(&priv->lock, flags);
  330. ret = iwl_grab_nic_access(priv);
  331. if (ret) {
  332. spin_unlock_irqrestore(&priv->lock, flags);
  333. return ret;
  334. }
  335. iwl_write_direct32(priv,
  336. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  337. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  338. iwl_write_direct32(priv,
  339. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
  340. iwl_write_direct32(priv,
  341. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  342. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  343. /* FIME: write the MSB of the phy_addr in CTRL1
  344. * iwl_write_direct32(priv,
  345. IWL_FH_TFDIB_CTRL1_REG(IWL_FH_SRVC_CHNL),
  346. ((phy_addr & MSB_MSK)
  347. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_count);
  348. */
  349. iwl_write_direct32(priv,
  350. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), byte_cnt);
  351. iwl_write_direct32(priv,
  352. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  353. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  354. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  355. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  356. iwl_write_direct32(priv,
  357. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  358. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  359. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL |
  360. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  361. iwl_release_nic_access(priv);
  362. spin_unlock_irqrestore(&priv->lock, flags);
  363. return 0;
  364. }
  365. static int iwl5000_load_given_ucode(struct iwl_priv *priv,
  366. struct fw_desc *inst_image,
  367. struct fw_desc *data_image)
  368. {
  369. int ret = 0;
  370. ret = iwl5000_load_section(
  371. priv, inst_image, RTC_INST_LOWER_BOUND);
  372. if (ret)
  373. return ret;
  374. IWL_DEBUG_INFO("INST uCode section being loaded...\n");
  375. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  376. priv->ucode_write_complete, 5 * HZ);
  377. if (ret == -ERESTARTSYS) {
  378. IWL_ERROR("Could not load the INST uCode section due "
  379. "to interrupt\n");
  380. return ret;
  381. }
  382. if (!ret) {
  383. IWL_ERROR("Could not load the INST uCode section\n");
  384. return -ETIMEDOUT;
  385. }
  386. priv->ucode_write_complete = 0;
  387. ret = iwl5000_load_section(
  388. priv, data_image, RTC_DATA_LOWER_BOUND);
  389. if (ret)
  390. return ret;
  391. IWL_DEBUG_INFO("DATA uCode section being loaded...\n");
  392. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  393. priv->ucode_write_complete, 5 * HZ);
  394. if (ret == -ERESTARTSYS) {
  395. IWL_ERROR("Could not load the INST uCode section due "
  396. "to interrupt\n");
  397. return ret;
  398. } else if (!ret) {
  399. IWL_ERROR("Could not load the DATA uCode section\n");
  400. return -ETIMEDOUT;
  401. } else
  402. ret = 0;
  403. priv->ucode_write_complete = 0;
  404. return ret;
  405. }
  406. static int iwl5000_load_ucode(struct iwl_priv *priv)
  407. {
  408. int ret = 0;
  409. /* check whether init ucode should be loaded, or rather runtime ucode */
  410. if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
  411. IWL_DEBUG_INFO("Init ucode found. Loading init ucode...\n");
  412. ret = iwl5000_load_given_ucode(priv,
  413. &priv->ucode_init, &priv->ucode_init_data);
  414. if (!ret) {
  415. IWL_DEBUG_INFO("Init ucode load complete.\n");
  416. priv->ucode_type = UCODE_INIT;
  417. }
  418. } else {
  419. IWL_DEBUG_INFO("Init ucode not found, or already loaded. "
  420. "Loading runtime ucode...\n");
  421. ret = iwl5000_load_given_ucode(priv,
  422. &priv->ucode_code, &priv->ucode_data);
  423. if (!ret) {
  424. IWL_DEBUG_INFO("Runtime ucode load complete.\n");
  425. priv->ucode_type = UCODE_RT;
  426. }
  427. }
  428. return ret;
  429. }
  430. static void iwl5000_init_alive_start(struct iwl_priv *priv)
  431. {
  432. int ret = 0;
  433. /* Check alive response for "valid" sign from uCode */
  434. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  435. /* We had an error bringing up the hardware, so take it
  436. * all the way back down so we can try again */
  437. IWL_DEBUG_INFO("Initialize Alive failed.\n");
  438. goto restart;
  439. }
  440. /* initialize uCode was loaded... verify inst image.
  441. * This is a paranoid check, because we would not have gotten the
  442. * "initialize" alive if code weren't properly loaded. */
  443. if (iwl_verify_ucode(priv)) {
  444. /* Runtime instruction load was bad;
  445. * take it all the way back down so we can try again */
  446. IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
  447. goto restart;
  448. }
  449. iwlcore_clear_stations_table(priv);
  450. ret = priv->cfg->ops->lib->alive_notify(priv);
  451. if (ret) {
  452. IWL_WARNING("Could not complete ALIVE transition: %d\n", ret);
  453. goto restart;
  454. }
  455. return;
  456. restart:
  457. /* real restart (first load init_ucode) */
  458. queue_work(priv->workqueue, &priv->restart);
  459. }
  460. static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
  461. int txq_id, u32 index)
  462. {
  463. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  464. (index & 0xff) | (txq_id << 8));
  465. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
  466. }
  467. static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
  468. struct iwl_tx_queue *txq,
  469. int tx_fifo_id, int scd_retry)
  470. {
  471. int txq_id = txq->q.id;
  472. int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
  473. iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
  474. (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  475. (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
  476. (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
  477. IWL50_SCD_QUEUE_STTS_REG_MSK);
  478. txq->sched_retry = scd_retry;
  479. IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
  480. active ? "Activate" : "Deactivate",
  481. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  482. }
  483. static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
  484. {
  485. struct iwl_wimax_coex_cmd coex_cmd;
  486. memset(&coex_cmd, 0, sizeof(coex_cmd));
  487. return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
  488. sizeof(coex_cmd), &coex_cmd);
  489. }
  490. static int iwl5000_alive_notify(struct iwl_priv *priv)
  491. {
  492. u32 a;
  493. int i = 0;
  494. unsigned long flags;
  495. int ret;
  496. spin_lock_irqsave(&priv->lock, flags);
  497. ret = iwl_grab_nic_access(priv);
  498. if (ret) {
  499. spin_unlock_irqrestore(&priv->lock, flags);
  500. return ret;
  501. }
  502. priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
  503. a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
  504. for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
  505. a += 4)
  506. iwl_write_targ_mem(priv, a, 0);
  507. for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
  508. a += 4)
  509. iwl_write_targ_mem(priv, a, 0);
  510. for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
  511. iwl_write_targ_mem(priv, a, 0);
  512. iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
  513. (priv->shared_phys +
  514. offsetof(struct iwl5000_shared, queues_byte_cnt_tbls)) >> 10);
  515. iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
  516. IWL50_SCD_QUEUECHAIN_SEL_ALL(
  517. priv->hw_params.max_txq_num));
  518. iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
  519. /* initiate the queues */
  520. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  521. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
  522. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  523. iwl_write_targ_mem(priv, priv->scd_base_addr +
  524. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  525. iwl_write_targ_mem(priv, priv->scd_base_addr +
  526. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
  527. sizeof(u32),
  528. ((SCD_WIN_SIZE <<
  529. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  530. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  531. ((SCD_FRAME_LIMIT <<
  532. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  533. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  534. }
  535. iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
  536. IWL_MASK(0, priv->hw_params.max_txq_num));
  537. /* Activate all Tx DMA/FIFO channels */
  538. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
  539. iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  540. /* map qos queues to fifos one-to-one */
  541. for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
  542. int ac = iwl5000_default_queue_to_tx_fifo[i];
  543. iwl_txq_ctx_activate(priv, i);
  544. iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  545. }
  546. /* TODO - need to initialize those FIFOs inside the loop above,
  547. * not only mark them as active */
  548. iwl_txq_ctx_activate(priv, 4);
  549. iwl_txq_ctx_activate(priv, 7);
  550. iwl_txq_ctx_activate(priv, 8);
  551. iwl_txq_ctx_activate(priv, 9);
  552. iwl_release_nic_access(priv);
  553. spin_unlock_irqrestore(&priv->lock, flags);
  554. iwl5000_send_wimax_coex(priv);
  555. return 0;
  556. }
  557. static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  558. {
  559. if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
  560. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  561. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  562. IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
  563. return -EINVAL;
  564. }
  565. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  566. priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
  567. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  568. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  569. if (priv->cfg->mod_params->amsdu_size_8K)
  570. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
  571. else
  572. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
  573. priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
  574. priv->hw_params.max_stations = IWL5000_STATION_COUNT;
  575. priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
  576. priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
  577. priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
  578. priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
  579. priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
  580. BIT(IEEE80211_BAND_5GHZ);
  581. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  582. priv->hw_params.sens = &iwl5000_sensitivity;
  583. #endif
  584. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  585. case CSR_HW_REV_TYPE_5100:
  586. case CSR_HW_REV_TYPE_5150:
  587. priv->hw_params.tx_chains_num = 1;
  588. priv->hw_params.rx_chains_num = 2;
  589. /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
  590. priv->hw_params.valid_tx_ant = ANT_A;
  591. priv->hw_params.valid_rx_ant = ANT_AB;
  592. break;
  593. case CSR_HW_REV_TYPE_5300:
  594. case CSR_HW_REV_TYPE_5350:
  595. priv->hw_params.tx_chains_num = 3;
  596. priv->hw_params.rx_chains_num = 3;
  597. priv->hw_params.valid_tx_ant = ANT_ABC;
  598. priv->hw_params.valid_rx_ant = ANT_ABC;
  599. break;
  600. }
  601. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  602. case CSR_HW_REV_TYPE_5100:
  603. case CSR_HW_REV_TYPE_5300:
  604. /* 5X00 wants in Celsius */
  605. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
  606. break;
  607. case CSR_HW_REV_TYPE_5150:
  608. case CSR_HW_REV_TYPE_5350:
  609. /* 5X50 wants in Kelvin */
  610. priv->hw_params.ct_kill_threshold =
  611. CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
  612. break;
  613. }
  614. return 0;
  615. }
  616. static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
  617. {
  618. priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
  619. sizeof(struct iwl5000_shared),
  620. &priv->shared_phys);
  621. if (!priv->shared_virt)
  622. return -ENOMEM;
  623. memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
  624. priv->rb_closed_offset = offsetof(struct iwl5000_shared, rb_closed);
  625. return 0;
  626. }
  627. static void iwl5000_free_shared_mem(struct iwl_priv *priv)
  628. {
  629. if (priv->shared_virt)
  630. pci_free_consistent(priv->pci_dev,
  631. sizeof(struct iwl5000_shared),
  632. priv->shared_virt,
  633. priv->shared_phys);
  634. }
  635. static int iwl5000_shared_mem_rx_idx(struct iwl_priv *priv)
  636. {
  637. struct iwl5000_shared *s = priv->shared_virt;
  638. return le32_to_cpu(s->rb_closed) & 0xFFF;
  639. }
  640. /**
  641. * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  642. */
  643. static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  644. struct iwl_tx_queue *txq,
  645. u16 byte_cnt)
  646. {
  647. struct iwl5000_shared *shared_data = priv->shared_virt;
  648. int txq_id = txq->q.id;
  649. u8 sec_ctl = 0;
  650. u8 sta = 0;
  651. int len;
  652. len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  653. if (txq_id != IWL_CMD_QUEUE_NUM) {
  654. sta = txq->cmd[txq->q.write_ptr].cmd.tx.sta_id;
  655. sec_ctl = txq->cmd[txq->q.write_ptr].cmd.tx.sec_ctl;
  656. switch (sec_ctl & TX_CMD_SEC_MSK) {
  657. case TX_CMD_SEC_CCM:
  658. len += CCMP_MIC_LEN;
  659. break;
  660. case TX_CMD_SEC_TKIP:
  661. len += TKIP_ICV_LEN;
  662. break;
  663. case TX_CMD_SEC_WEP:
  664. len += WEP_IV_LEN + WEP_ICV_LEN;
  665. break;
  666. }
  667. }
  668. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  669. tfd_offset[txq->q.write_ptr], byte_cnt, len);
  670. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  671. tfd_offset[txq->q.write_ptr], sta_id, sta);
  672. if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
  673. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  674. tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
  675. byte_cnt, len);
  676. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  677. tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
  678. sta_id, sta);
  679. }
  680. }
  681. static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
  682. {
  683. u16 size = (u16)sizeof(struct iwl_addsta_cmd);
  684. memcpy(data, cmd, size);
  685. return size;
  686. }
  687. /*
  688. * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
  689. * must be called under priv->lock and mac access
  690. */
  691. static void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
  692. {
  693. iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
  694. }
  695. /* Currently 5000 is the supperset of everything */
  696. static u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
  697. {
  698. return len;
  699. }
  700. static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
  701. {
  702. }
  703. static int iwl5000_hw_valid_rtc_data_addr(u32 addr)
  704. {
  705. return (addr >= RTC_DATA_LOWER_BOUND) &&
  706. (addr < IWL50_RTC_DATA_UPPER_BOUND);
  707. }
  708. static struct iwl_hcmd_ops iwl5000_hcmd = {
  709. };
  710. static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  711. .get_hcmd_size = iwl5000_get_hcmd_size,
  712. .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
  713. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  714. .gain_computation = iwl5000_gain_computation,
  715. .chain_noise_reset = iwl5000_chain_noise_reset,
  716. #endif
  717. };
  718. static struct iwl_lib_ops iwl5000_lib = {
  719. .set_hw_params = iwl5000_hw_set_hw_params,
  720. .alloc_shared_mem = iwl5000_alloc_shared_mem,
  721. .free_shared_mem = iwl5000_free_shared_mem,
  722. .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx,
  723. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  724. .txq_set_sched = iwl5000_txq_set_sched,
  725. .rx_handler_setup = iwl5000_rx_handler_setup,
  726. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  727. .load_ucode = iwl5000_load_ucode,
  728. .init_alive_start = iwl5000_init_alive_start,
  729. .alive_notify = iwl5000_alive_notify,
  730. .apm_ops = {
  731. .init = iwl5000_apm_init,
  732. .reset = iwl5000_apm_reset,
  733. .stop = iwl5000_apm_stop,
  734. .config = iwl5000_nic_config,
  735. .set_pwr_src = iwl4965_set_pwr_src,
  736. },
  737. .eeprom_ops = {
  738. .regulatory_bands = {
  739. EEPROM_5000_REG_BAND_1_CHANNELS,
  740. EEPROM_5000_REG_BAND_2_CHANNELS,
  741. EEPROM_5000_REG_BAND_3_CHANNELS,
  742. EEPROM_5000_REG_BAND_4_CHANNELS,
  743. EEPROM_5000_REG_BAND_5_CHANNELS,
  744. EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
  745. EEPROM_5000_REG_BAND_52_FAT_CHANNELS
  746. },
  747. .verify_signature = iwlcore_eeprom_verify_signature,
  748. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  749. .release_semaphore = iwlcore_eeprom_release_semaphore,
  750. .check_version = iwl5000_eeprom_check_version,
  751. .query_addr = iwl5000_eeprom_query_addr,
  752. },
  753. };
  754. static struct iwl_ops iwl5000_ops = {
  755. .lib = &iwl5000_lib,
  756. .hcmd = &iwl5000_hcmd,
  757. .utils = &iwl5000_hcmd_utils,
  758. };
  759. static struct iwl_mod_params iwl50_mod_params = {
  760. .num_of_queues = IWL50_NUM_QUEUES,
  761. .enable_qos = 1,
  762. .amsdu_size_8K = 1,
  763. .restart_fw = 1,
  764. /* the rest are 0 by default */
  765. };
  766. struct iwl_cfg iwl5300_agn_cfg = {
  767. .name = "5300AGN",
  768. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  769. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  770. .ops = &iwl5000_ops,
  771. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  772. .mod_params = &iwl50_mod_params,
  773. };
  774. struct iwl_cfg iwl5100_agn_cfg = {
  775. .name = "5100AGN",
  776. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  777. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  778. .ops = &iwl5000_ops,
  779. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  780. .mod_params = &iwl50_mod_params,
  781. };
  782. struct iwl_cfg iwl5350_agn_cfg = {
  783. .name = "5350AGN",
  784. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  785. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  786. .ops = &iwl5000_ops,
  787. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  788. .mod_params = &iwl50_mod_params,
  789. };
  790. module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
  791. MODULE_PARM_DESC(disable50,
  792. "manually disable the 50XX radio (default 0 [radio on])");
  793. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
  794. MODULE_PARM_DESC(swcrypto50,
  795. "using software crypto engine (default 0 [hardware])\n");
  796. module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
  797. MODULE_PARM_DESC(debug50, "50XX debug output mask");
  798. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
  799. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  800. module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
  801. MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
  802. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
  803. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
  804. module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
  805. MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");