iwl-5000.c 25 KB

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