iwl-5000.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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 int iwl5000_apm_init(struct iwl_priv *priv)
  46. {
  47. int ret = 0;
  48. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  49. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  50. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  51. /* set "initialization complete" bit to move adapter
  52. * D0U* --> D0A* state */
  53. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  54. /* wait for clock stabilization */
  55. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  56. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  57. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  58. if (ret < 0) {
  59. IWL_DEBUG_INFO("Failed to init the card\n");
  60. return ret;
  61. }
  62. ret = iwl_grab_nic_access(priv);
  63. if (ret)
  64. return ret;
  65. /* enable DMA */
  66. iwl_write_prph(priv, APMG_CLK_EN_REG,
  67. APMG_CLK_VAL_DMA_CLK_RQT);
  68. udelay(20);
  69. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  70. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  71. iwl_release_nic_access(priv);
  72. return ret;
  73. }
  74. static void iwl5000_nic_config(struct iwl_priv *priv)
  75. {
  76. unsigned long flags;
  77. u16 radio_cfg;
  78. u8 val_link;
  79. spin_lock_irqsave(&priv->lock, flags);
  80. pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
  81. /* disable L1 entry -- workaround for pre-B1 */
  82. pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
  83. radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
  84. /* write radio config values to register */
  85. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
  86. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  87. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  88. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  89. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  90. /* set CSR_HW_CONFIG_REG for uCode use */
  91. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  92. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  93. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  94. spin_unlock_irqrestore(&priv->lock, flags);
  95. }
  96. /*
  97. * EEPROM
  98. */
  99. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  100. {
  101. u16 offset = 0;
  102. if ((address & INDIRECT_ADDRESS) == 0)
  103. return address;
  104. switch (address & INDIRECT_TYPE_MSK) {
  105. case INDIRECT_HOST:
  106. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
  107. break;
  108. case INDIRECT_GENERAL:
  109. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
  110. break;
  111. case INDIRECT_REGULATORY:
  112. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
  113. break;
  114. case INDIRECT_CALIBRATION:
  115. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
  116. break;
  117. case INDIRECT_PROCESS_ADJST:
  118. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
  119. break;
  120. case INDIRECT_OTHERS:
  121. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
  122. break;
  123. default:
  124. IWL_ERROR("illegal indirect type: 0x%X\n",
  125. address & INDIRECT_TYPE_MSK);
  126. break;
  127. }
  128. /* translate the offset from words to byte */
  129. return (address & ADDRESS_MSK) + (offset << 1);
  130. }
  131. static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
  132. {
  133. u16 eeprom_ver;
  134. struct iwl_eeprom_calib_hdr {
  135. u8 version;
  136. u8 pa_type;
  137. u16 voltage;
  138. } *hdr;
  139. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  140. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  141. EEPROM_5000_CALIB_ALL);
  142. if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
  143. hdr->version < EEPROM_5000_TX_POWER_VERSION)
  144. goto err;
  145. return 0;
  146. err:
  147. IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
  148. eeprom_ver, EEPROM_5000_EEPROM_VERSION,
  149. hdr->version, EEPROM_5000_TX_POWER_VERSION);
  150. return -EINVAL;
  151. }
  152. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  153. static void iwl5000_gain_computation(struct iwl_priv *priv,
  154. u32 average_noise[NUM_RX_CHAINS],
  155. u16 min_average_noise_antenna_i,
  156. u32 min_average_noise)
  157. {
  158. int i;
  159. s32 delta_g;
  160. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  161. /* Find Gain Code for the antennas B and C */
  162. for (i = 1; i < NUM_RX_CHAINS; i++) {
  163. if ((data->disconn_array[i])) {
  164. data->delta_gain_code[i] = 0;
  165. continue;
  166. }
  167. delta_g = (1000 * ((s32)average_noise[0] -
  168. (s32)average_noise[i])) / 1500;
  169. /* bound gain by 2 bits value max, 3rd bit is sign */
  170. data->delta_gain_code[i] =
  171. min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  172. if (delta_g < 0)
  173. /* set negative sign */
  174. data->delta_gain_code[i] |= (1 << 2);
  175. }
  176. IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
  177. data->delta_gain_code[1], data->delta_gain_code[2]);
  178. if (!data->radio_write) {
  179. struct iwl5000_calibration_chain_noise_gain_cmd cmd;
  180. memset(&cmd, 0, sizeof(cmd));
  181. cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
  182. cmd.delta_gain_1 = data->delta_gain_code[1];
  183. cmd.delta_gain_2 = data->delta_gain_code[2];
  184. iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
  185. sizeof(cmd), &cmd, NULL);
  186. data->radio_write = 1;
  187. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  188. }
  189. data->chain_noise_a = 0;
  190. data->chain_noise_b = 0;
  191. data->chain_noise_c = 0;
  192. data->chain_signal_a = 0;
  193. data->chain_signal_b = 0;
  194. data->chain_signal_c = 0;
  195. data->beacon_count = 0;
  196. }
  197. static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
  198. {
  199. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  200. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  201. struct iwl5000_calibration_chain_noise_reset_cmd cmd;
  202. memset(&cmd, 0, sizeof(cmd));
  203. cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
  204. if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  205. sizeof(cmd), &cmd))
  206. IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
  207. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  208. IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
  209. }
  210. }
  211. static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  212. .min_nrg_cck = 95,
  213. .max_nrg_cck = 0,
  214. .auto_corr_min_ofdm = 90,
  215. .auto_corr_min_ofdm_mrc = 170,
  216. .auto_corr_min_ofdm_x1 = 120,
  217. .auto_corr_min_ofdm_mrc_x1 = 240,
  218. .auto_corr_max_ofdm = 120,
  219. .auto_corr_max_ofdm_mrc = 210,
  220. .auto_corr_max_ofdm_x1 = 155,
  221. .auto_corr_max_ofdm_mrc_x1 = 290,
  222. .auto_corr_min_cck = 125,
  223. .auto_corr_max_cck = 200,
  224. .auto_corr_min_cck_mrc = 170,
  225. .auto_corr_max_cck_mrc = 400,
  226. .nrg_th_cck = 95,
  227. .nrg_th_ofdm = 95,
  228. };
  229. #endif /* CONFIG_IWL5000_RUN_TIME_CALIB */
  230. static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
  231. size_t offset)
  232. {
  233. u32 address = eeprom_indirect_address(priv, offset);
  234. BUG_ON(address >= priv->cfg->eeprom_size);
  235. return &priv->eeprom[address];
  236. }
  237. /*
  238. * ucode
  239. */
  240. static int iwl5000_load_section(struct iwl_priv *priv,
  241. struct fw_desc *image,
  242. u32 dst_addr)
  243. {
  244. int ret = 0;
  245. unsigned long flags;
  246. dma_addr_t phy_addr = image->p_addr;
  247. u32 byte_cnt = image->len;
  248. spin_lock_irqsave(&priv->lock, flags);
  249. ret = iwl_grab_nic_access(priv);
  250. if (ret) {
  251. spin_unlock_irqrestore(&priv->lock, flags);
  252. return ret;
  253. }
  254. iwl_write_direct32(priv,
  255. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  256. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  257. iwl_write_direct32(priv,
  258. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
  259. iwl_write_direct32(priv,
  260. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  261. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  262. /* FIME: write the MSB of the phy_addr in CTRL1
  263. * iwl_write_direct32(priv,
  264. IWL_FH_TFDIB_CTRL1_REG(IWL_FH_SRVC_CHNL),
  265. ((phy_addr & MSB_MSK)
  266. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_count);
  267. */
  268. iwl_write_direct32(priv,
  269. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), byte_cnt);
  270. iwl_write_direct32(priv,
  271. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  272. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  273. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  274. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  275. iwl_write_direct32(priv,
  276. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  277. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  278. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL |
  279. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  280. iwl_release_nic_access(priv);
  281. spin_unlock_irqrestore(&priv->lock, flags);
  282. return 0;
  283. }
  284. static int iwl5000_load_given_ucode(struct iwl_priv *priv,
  285. struct fw_desc *inst_image,
  286. struct fw_desc *data_image)
  287. {
  288. int ret = 0;
  289. ret = iwl5000_load_section(
  290. priv, inst_image, RTC_INST_LOWER_BOUND);
  291. if (ret)
  292. return ret;
  293. IWL_DEBUG_INFO("INST uCode section being loaded...\n");
  294. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  295. priv->ucode_write_complete, 5 * HZ);
  296. if (ret == -ERESTARTSYS) {
  297. IWL_ERROR("Could not load the INST uCode section due "
  298. "to interrupt\n");
  299. return ret;
  300. }
  301. if (!ret) {
  302. IWL_ERROR("Could not load the INST uCode section\n");
  303. return -ETIMEDOUT;
  304. }
  305. priv->ucode_write_complete = 0;
  306. ret = iwl5000_load_section(
  307. priv, data_image, RTC_DATA_LOWER_BOUND);
  308. if (ret)
  309. return ret;
  310. IWL_DEBUG_INFO("DATA 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. } else if (!ret) {
  318. IWL_ERROR("Could not load the DATA uCode section\n");
  319. return -ETIMEDOUT;
  320. } else
  321. ret = 0;
  322. priv->ucode_write_complete = 0;
  323. return ret;
  324. }
  325. static int iwl5000_load_ucode(struct iwl_priv *priv)
  326. {
  327. int ret = 0;
  328. /* check whether init ucode should be loaded, or rather runtime ucode */
  329. if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
  330. IWL_DEBUG_INFO("Init ucode found. Loading init ucode...\n");
  331. ret = iwl5000_load_given_ucode(priv,
  332. &priv->ucode_init, &priv->ucode_init_data);
  333. if (!ret) {
  334. IWL_DEBUG_INFO("Init ucode load complete.\n");
  335. priv->ucode_type = UCODE_INIT;
  336. }
  337. } else {
  338. IWL_DEBUG_INFO("Init ucode not found, or already loaded. "
  339. "Loading runtime ucode...\n");
  340. ret = iwl5000_load_given_ucode(priv,
  341. &priv->ucode_code, &priv->ucode_data);
  342. if (!ret) {
  343. IWL_DEBUG_INFO("Runtime ucode load complete.\n");
  344. priv->ucode_type = UCODE_RT;
  345. }
  346. }
  347. return ret;
  348. }
  349. static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  350. {
  351. if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
  352. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  353. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  354. IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
  355. return -EINVAL;
  356. }
  357. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  358. priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
  359. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  360. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  361. if (priv->cfg->mod_params->amsdu_size_8K)
  362. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
  363. else
  364. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
  365. priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
  366. priv->hw_params.max_stations = IWL5000_STATION_COUNT;
  367. priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
  368. priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
  369. priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
  370. priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
  371. priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
  372. BIT(IEEE80211_BAND_5GHZ);
  373. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  374. priv->hw_params.sens = &iwl5000_sensitivity;
  375. #endif
  376. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  377. case CSR_HW_REV_TYPE_5100:
  378. case CSR_HW_REV_TYPE_5150:
  379. priv->hw_params.tx_chains_num = 1;
  380. priv->hw_params.rx_chains_num = 2;
  381. /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
  382. priv->hw_params.valid_tx_ant = ANT_A;
  383. priv->hw_params.valid_rx_ant = ANT_AB;
  384. break;
  385. case CSR_HW_REV_TYPE_5300:
  386. case CSR_HW_REV_TYPE_5350:
  387. priv->hw_params.tx_chains_num = 3;
  388. priv->hw_params.rx_chains_num = 3;
  389. priv->hw_params.valid_tx_ant = ANT_ABC;
  390. priv->hw_params.valid_rx_ant = ANT_ABC;
  391. break;
  392. }
  393. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  394. case CSR_HW_REV_TYPE_5100:
  395. case CSR_HW_REV_TYPE_5300:
  396. /* 5X00 wants in Celsius */
  397. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
  398. break;
  399. case CSR_HW_REV_TYPE_5150:
  400. case CSR_HW_REV_TYPE_5350:
  401. /* 5X50 wants in Kelvin */
  402. priv->hw_params.ct_kill_threshold =
  403. CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
  404. break;
  405. }
  406. return 0;
  407. }
  408. static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
  409. {
  410. priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
  411. sizeof(struct iwl5000_shared),
  412. &priv->shared_phys);
  413. if (!priv->shared_virt)
  414. return -ENOMEM;
  415. memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
  416. priv->rb_closed_offset = offsetof(struct iwl5000_shared, rb_closed);
  417. return 0;
  418. }
  419. static void iwl5000_free_shared_mem(struct iwl_priv *priv)
  420. {
  421. if (priv->shared_virt)
  422. pci_free_consistent(priv->pci_dev,
  423. sizeof(struct iwl5000_shared),
  424. priv->shared_virt,
  425. priv->shared_phys);
  426. }
  427. static int iwl5000_shared_mem_rx_idx(struct iwl_priv *priv)
  428. {
  429. struct iwl5000_shared *s = priv->shared_virt;
  430. return le32_to_cpu(s->rb_closed) & 0xFFF;
  431. }
  432. /**
  433. * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  434. */
  435. static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  436. struct iwl_tx_queue *txq,
  437. u16 byte_cnt)
  438. {
  439. struct iwl5000_shared *shared_data = priv->shared_virt;
  440. int txq_id = txq->q.id;
  441. u8 sec_ctl = 0;
  442. u8 sta = 0;
  443. int len;
  444. len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  445. if (txq_id != IWL_CMD_QUEUE_NUM) {
  446. sta = txq->cmd[txq->q.write_ptr].cmd.tx.sta_id;
  447. sec_ctl = txq->cmd[txq->q.write_ptr].cmd.tx.sec_ctl;
  448. switch (sec_ctl & TX_CMD_SEC_MSK) {
  449. case TX_CMD_SEC_CCM:
  450. len += CCMP_MIC_LEN;
  451. break;
  452. case TX_CMD_SEC_TKIP:
  453. len += TKIP_ICV_LEN;
  454. break;
  455. case TX_CMD_SEC_WEP:
  456. len += WEP_IV_LEN + WEP_ICV_LEN;
  457. break;
  458. }
  459. }
  460. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  461. tfd_offset[txq->q.write_ptr], byte_cnt, len);
  462. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  463. tfd_offset[txq->q.write_ptr], sta_id, sta);
  464. if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
  465. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  466. tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
  467. byte_cnt, len);
  468. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  469. tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
  470. sta_id, sta);
  471. }
  472. }
  473. static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
  474. {
  475. u16 size = (u16)sizeof(struct iwl_addsta_cmd);
  476. memcpy(data, cmd, size);
  477. return size;
  478. }
  479. static int iwl5000_disable_tx_fifo(struct iwl_priv *priv)
  480. {
  481. unsigned long flags;
  482. int ret;
  483. spin_lock_irqsave(&priv->lock, flags);
  484. ret = iwl_grab_nic_access(priv);
  485. if (unlikely(ret)) {
  486. IWL_ERROR("Tx fifo reset failed");
  487. spin_unlock_irqrestore(&priv->lock, flags);
  488. return ret;
  489. }
  490. iwl_write_prph(priv, IWL50_SCD_TXFACT, 0);
  491. iwl_release_nic_access(priv);
  492. spin_unlock_irqrestore(&priv->lock, flags);
  493. return 0;
  494. }
  495. /* Currently 5000 is the supperset of everything */
  496. static u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
  497. {
  498. return len;
  499. }
  500. static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
  501. {
  502. }
  503. static struct iwl_hcmd_ops iwl5000_hcmd = {
  504. };
  505. static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  506. .get_hcmd_size = iwl5000_get_hcmd_size,
  507. .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
  508. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  509. .gain_computation = iwl5000_gain_computation,
  510. .chain_noise_reset = iwl5000_chain_noise_reset,
  511. #endif
  512. };
  513. static struct iwl_lib_ops iwl5000_lib = {
  514. .set_hw_params = iwl5000_hw_set_hw_params,
  515. .alloc_shared_mem = iwl5000_alloc_shared_mem,
  516. .free_shared_mem = iwl5000_free_shared_mem,
  517. .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx,
  518. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  519. .disable_tx_fifo = iwl5000_disable_tx_fifo,
  520. .rx_handler_setup = iwl5000_rx_handler_setup,
  521. .load_ucode = iwl5000_load_ucode,
  522. .apm_ops = {
  523. .init = iwl5000_apm_init,
  524. .config = iwl5000_nic_config,
  525. .set_pwr_src = iwl4965_set_pwr_src,
  526. },
  527. .eeprom_ops = {
  528. .regulatory_bands = {
  529. EEPROM_5000_REG_BAND_1_CHANNELS,
  530. EEPROM_5000_REG_BAND_2_CHANNELS,
  531. EEPROM_5000_REG_BAND_3_CHANNELS,
  532. EEPROM_5000_REG_BAND_4_CHANNELS,
  533. EEPROM_5000_REG_BAND_5_CHANNELS,
  534. EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
  535. EEPROM_5000_REG_BAND_52_FAT_CHANNELS
  536. },
  537. .verify_signature = iwlcore_eeprom_verify_signature,
  538. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  539. .release_semaphore = iwlcore_eeprom_release_semaphore,
  540. .check_version = iwl5000_eeprom_check_version,
  541. .query_addr = iwl5000_eeprom_query_addr,
  542. },
  543. };
  544. static struct iwl_ops iwl5000_ops = {
  545. .lib = &iwl5000_lib,
  546. .hcmd = &iwl5000_hcmd,
  547. .utils = &iwl5000_hcmd_utils,
  548. };
  549. static struct iwl_mod_params iwl50_mod_params = {
  550. .num_of_queues = IWL50_NUM_QUEUES,
  551. .enable_qos = 1,
  552. .amsdu_size_8K = 1,
  553. .restart_fw = 1,
  554. /* the rest are 0 by default */
  555. };
  556. struct iwl_cfg iwl5300_agn_cfg = {
  557. .name = "5300AGN",
  558. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  559. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  560. .ops = &iwl5000_ops,
  561. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  562. .mod_params = &iwl50_mod_params,
  563. };
  564. struct iwl_cfg iwl5100_agn_cfg = {
  565. .name = "5100AGN",
  566. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  567. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  568. .ops = &iwl5000_ops,
  569. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  570. .mod_params = &iwl50_mod_params,
  571. };
  572. struct iwl_cfg iwl5350_agn_cfg = {
  573. .name = "5350AGN",
  574. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  575. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  576. .ops = &iwl5000_ops,
  577. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  578. .mod_params = &iwl50_mod_params,
  579. };
  580. module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
  581. MODULE_PARM_DESC(disable50,
  582. "manually disable the 50XX radio (default 0 [radio on])");
  583. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
  584. MODULE_PARM_DESC(swcrypto50,
  585. "using software crypto engine (default 0 [hardware])\n");
  586. module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
  587. MODULE_PARM_DESC(debug50, "50XX debug output mask");
  588. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
  589. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  590. module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
  591. MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
  592. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
  593. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
  594. module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
  595. MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");