iwl-5000.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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-4965.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. /*
  75. * EEPROM
  76. */
  77. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  78. {
  79. u16 offset = 0;
  80. if ((address & INDIRECT_ADDRESS) == 0)
  81. return address;
  82. switch (address & INDIRECT_TYPE_MSK) {
  83. case INDIRECT_HOST:
  84. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
  85. break;
  86. case INDIRECT_GENERAL:
  87. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
  88. break;
  89. case INDIRECT_REGULATORY:
  90. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
  91. break;
  92. case INDIRECT_CALIBRATION:
  93. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
  94. break;
  95. case INDIRECT_PROCESS_ADJST:
  96. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
  97. break;
  98. case INDIRECT_OTHERS:
  99. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
  100. break;
  101. default:
  102. IWL_ERROR("illegal indirect type: 0x%X\n",
  103. address & INDIRECT_TYPE_MSK);
  104. break;
  105. }
  106. /* translate the offset from words to byte */
  107. return (address & ADDRESS_MSK) + (offset << 1);
  108. }
  109. static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
  110. size_t offset)
  111. {
  112. u32 address = eeprom_indirect_address(priv, offset);
  113. BUG_ON(address >= priv->cfg->eeprom_size);
  114. return &priv->eeprom[address];
  115. }
  116. static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  117. {
  118. if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
  119. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  120. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  121. IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
  122. return -EINVAL;
  123. }
  124. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  125. priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
  126. priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
  127. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  128. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  129. if (priv->cfg->mod_params->amsdu_size_8K)
  130. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
  131. else
  132. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
  133. priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
  134. priv->hw_params.max_stations = IWL5000_STATION_COUNT;
  135. priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
  136. priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
  137. priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
  138. priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
  139. priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
  140. BIT(IEEE80211_BAND_5GHZ);
  141. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  142. case CSR_HW_REV_TYPE_5100:
  143. case CSR_HW_REV_TYPE_5150:
  144. priv->hw_params.tx_chains_num = 1;
  145. priv->hw_params.rx_chains_num = 2;
  146. /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
  147. priv->hw_params.valid_tx_ant = IWL_ANTENNA_MAIN;
  148. priv->hw_params.valid_rx_ant = (IWL_ANTENNA_MAIN |
  149. IWL_ANTENNA_AUX);
  150. break;
  151. case CSR_HW_REV_TYPE_5300:
  152. case CSR_HW_REV_TYPE_5350:
  153. priv->hw_params.tx_chains_num = 3;
  154. priv->hw_params.rx_chains_num = 3;
  155. /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
  156. priv->hw_params.valid_tx_ant = (IWL_ANTENNA_MAIN |
  157. IWL_ANTENNA_AUX | 0x04);
  158. priv->hw_params.valid_rx_ant = (IWL_ANTENNA_MAIN |
  159. IWL_ANTENNA_AUX | 0x04);
  160. break;
  161. }
  162. return 0;
  163. }
  164. static struct iwl_hcmd_ops iwl5000_hcmd = {
  165. };
  166. static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  167. };
  168. static struct iwl_lib_ops iwl5000_lib = {
  169. .set_hw_params = iwl5000_hw_set_hw_params,
  170. .apm_ops = {
  171. .init = iwl5000_apm_init,
  172. .set_pwr_src = iwl4965_set_pwr_src,
  173. },
  174. .eeprom_ops = {
  175. .regulatory_bands = {
  176. EEPROM_5000_REG_BAND_1_CHANNELS,
  177. EEPROM_5000_REG_BAND_2_CHANNELS,
  178. EEPROM_5000_REG_BAND_3_CHANNELS,
  179. EEPROM_5000_REG_BAND_4_CHANNELS,
  180. EEPROM_5000_REG_BAND_5_CHANNELS,
  181. EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
  182. EEPROM_5000_REG_BAND_52_FAT_CHANNELS
  183. },
  184. .verify_signature = iwlcore_eeprom_verify_signature,
  185. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  186. .release_semaphore = iwlcore_eeprom_release_semaphore,
  187. .query_addr = iwl5000_eeprom_query_addr,
  188. },
  189. };
  190. static struct iwl_ops iwl5000_ops = {
  191. .lib = &iwl5000_lib,
  192. .hcmd = &iwl5000_hcmd,
  193. .utils = &iwl5000_hcmd_utils,
  194. };
  195. static struct iwl_mod_params iwl50_mod_params = {
  196. .num_of_queues = IWL50_NUM_QUEUES,
  197. .enable_qos = 1,
  198. .amsdu_size_8K = 1,
  199. /* the rest are 0 by default */
  200. };
  201. struct iwl_cfg iwl5300_agn_cfg = {
  202. .name = "5300AGN",
  203. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  204. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  205. .ops = &iwl5000_ops,
  206. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  207. .mod_params = &iwl50_mod_params,
  208. };
  209. struct iwl_cfg iwl5100_agn_cfg = {
  210. .name = "5100AGN",
  211. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  212. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  213. .ops = &iwl5000_ops,
  214. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  215. .mod_params = &iwl50_mod_params,
  216. };
  217. struct iwl_cfg iwl5350_agn_cfg = {
  218. .name = "5350AGN",
  219. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  220. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  221. .ops = &iwl5000_ops,
  222. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  223. .mod_params = &iwl50_mod_params,
  224. };
  225. module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
  226. MODULE_PARM_DESC(disable50,
  227. "manually disable the 50XX radio (default 0 [radio on])");
  228. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
  229. MODULE_PARM_DESC(swcrypto50,
  230. "using software crypto engine (default 0 [hardware])\n");
  231. module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
  232. MODULE_PARM_DESC(debug50, "50XX debug output mask");
  233. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
  234. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  235. module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
  236. MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
  237. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
  238. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");