iwl-5000.c 26 KB

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