iwl-5000.c 24 KB

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