iwl-2000.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2008 - 2011 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 Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include <linux/kernel.h>
  27. #include <linux/module.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-sta.h"
  43. #include "iwl-agn.h"
  44. #include "iwl-helpers.h"
  45. #include "iwl-agn-hw.h"
  46. #include "iwl-6000-hw.h"
  47. /* Highest firmware API version supported */
  48. #define IWL2030_UCODE_API_MAX 5
  49. #define IWL2000_UCODE_API_MAX 5
  50. #define IWL105_UCODE_API_MAX 5
  51. /* Lowest firmware API version supported */
  52. #define IWL2030_UCODE_API_MIN 5
  53. #define IWL2000_UCODE_API_MIN 5
  54. #define IWL105_UCODE_API_MIN 5
  55. #define IWL2030_FW_PRE "iwlwifi-2030-"
  56. #define IWL2030_MODULE_FIRMWARE(api) IWL2030_FW_PRE #api ".ucode"
  57. #define IWL2000_FW_PRE "iwlwifi-2000-"
  58. #define IWL2000_MODULE_FIRMWARE(api) IWL2000_FW_PRE #api ".ucode"
  59. #define IWL105_FW_PRE "iwlwifi-105-"
  60. #define IWL105_MODULE_FIRMWARE(api) IWL105_FW_PRE #api ".ucode"
  61. static void iwl2000_set_ct_threshold(struct iwl_priv *priv)
  62. {
  63. /* want Celsius */
  64. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
  65. priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
  66. }
  67. /* NIC configuration for 2000 series */
  68. static void iwl2000_nic_config(struct iwl_priv *priv)
  69. {
  70. u16 radio_cfg;
  71. radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
  72. /* write radio config values to register */
  73. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX)
  74. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  75. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  76. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  77. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  78. /* set CSR_HW_CONFIG_REG for uCode use */
  79. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  80. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  81. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  82. if (priv->cfg->iq_invert)
  83. iwl_set_bit(priv, CSR_GP_DRIVER_REG,
  84. CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER);
  85. if (priv->cfg->disable_otp_refresh)
  86. iwl_write_prph(priv, APMG_ANALOG_SVR_REG, 0x80000010);
  87. }
  88. static struct iwl_sensitivity_ranges iwl2000_sensitivity = {
  89. .min_nrg_cck = 97,
  90. .max_nrg_cck = 0, /* not used, set to 0 */
  91. .auto_corr_min_ofdm = 80,
  92. .auto_corr_min_ofdm_mrc = 128,
  93. .auto_corr_min_ofdm_x1 = 105,
  94. .auto_corr_min_ofdm_mrc_x1 = 192,
  95. .auto_corr_max_ofdm = 145,
  96. .auto_corr_max_ofdm_mrc = 232,
  97. .auto_corr_max_ofdm_x1 = 110,
  98. .auto_corr_max_ofdm_mrc_x1 = 232,
  99. .auto_corr_min_cck = 125,
  100. .auto_corr_max_cck = 175,
  101. .auto_corr_min_cck_mrc = 160,
  102. .auto_corr_max_cck_mrc = 310,
  103. .nrg_th_cck = 97,
  104. .nrg_th_ofdm = 100,
  105. .barker_corr_th_min = 190,
  106. .barker_corr_th_min_mrc = 390,
  107. .nrg_th_cca = 62,
  108. };
  109. static int iwl2000_hw_set_hw_params(struct iwl_priv *priv)
  110. {
  111. if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
  112. iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
  113. priv->cfg->base_params->num_of_queues =
  114. iwlagn_mod_params.num_of_queues;
  115. priv->hw_params.max_txq_num = priv->cfg->base_params->num_of_queues;
  116. priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
  117. priv->hw_params.scd_bc_tbls_size =
  118. priv->cfg->base_params->num_of_queues *
  119. sizeof(struct iwlagn_scd_bc_tbl);
  120. priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
  121. priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
  122. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  123. priv->hw_params.max_data_size = IWL60_RTC_DATA_SIZE;
  124. priv->hw_params.max_inst_size = IWL60_RTC_INST_SIZE;
  125. priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  126. BIT(IEEE80211_BAND_5GHZ);
  127. priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
  128. priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
  129. if (priv->cfg->rx_with_siso_diversity)
  130. priv->hw_params.rx_chains_num = 1;
  131. else
  132. priv->hw_params.rx_chains_num =
  133. num_of_ant(priv->cfg->valid_rx_ant);
  134. priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
  135. priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
  136. iwl2000_set_ct_threshold(priv);
  137. /* Set initial sensitivity parameters */
  138. /* Set initial calibration set */
  139. priv->hw_params.sens = &iwl2000_sensitivity;
  140. priv->hw_params.calib_init_cfg =
  141. BIT(IWL_CALIB_XTAL) |
  142. BIT(IWL_CALIB_LO) |
  143. BIT(IWL_CALIB_TX_IQ) |
  144. BIT(IWL_CALIB_BASE_BAND);
  145. if (priv->cfg->need_dc_calib)
  146. priv->hw_params.calib_rt_cfg |= BIT(IWL_CALIB_CFG_DC_IDX);
  147. if (priv->cfg->need_temp_offset_calib)
  148. priv->hw_params.calib_init_cfg |= BIT(IWL_CALIB_TEMP_OFFSET);
  149. priv->hw_params.beacon_time_tsf_bits = IWLAGN_EXT_BEACON_TIME_POS;
  150. return 0;
  151. }
  152. static int iwl2030_hw_channel_switch(struct iwl_priv *priv,
  153. struct ieee80211_channel_switch *ch_switch)
  154. {
  155. /*
  156. * MULTI-FIXME
  157. * See iwl_mac_channel_switch.
  158. */
  159. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  160. struct iwl6000_channel_switch_cmd cmd;
  161. const struct iwl_channel_info *ch_info;
  162. u32 switch_time_in_usec, ucode_switch_time;
  163. u16 ch;
  164. u32 tsf_low;
  165. u8 switch_count;
  166. u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
  167. struct ieee80211_vif *vif = ctx->vif;
  168. struct iwl_host_cmd hcmd = {
  169. .id = REPLY_CHANNEL_SWITCH,
  170. .len = { sizeof(cmd), },
  171. .flags = CMD_SYNC,
  172. .data = { &cmd, },
  173. };
  174. cmd.band = priv->band == IEEE80211_BAND_2GHZ;
  175. ch = ch_switch->channel->hw_value;
  176. IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
  177. ctx->active.channel, ch);
  178. cmd.channel = cpu_to_le16(ch);
  179. cmd.rxon_flags = ctx->staging.flags;
  180. cmd.rxon_filter_flags = ctx->staging.filter_flags;
  181. switch_count = ch_switch->count;
  182. tsf_low = ch_switch->timestamp & 0x0ffffffff;
  183. /*
  184. * calculate the ucode channel switch time
  185. * adding TSF as one of the factor for when to switch
  186. */
  187. if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
  188. if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
  189. beacon_interval)) {
  190. switch_count -= (priv->ucode_beacon_time -
  191. tsf_low) / beacon_interval;
  192. } else
  193. switch_count = 0;
  194. }
  195. if (switch_count <= 1)
  196. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  197. else {
  198. switch_time_in_usec =
  199. vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
  200. ucode_switch_time = iwl_usecs_to_beacons(priv,
  201. switch_time_in_usec,
  202. beacon_interval);
  203. cmd.switch_time = iwl_add_beacon_time(priv,
  204. priv->ucode_beacon_time,
  205. ucode_switch_time,
  206. beacon_interval);
  207. }
  208. IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
  209. cmd.switch_time);
  210. ch_info = iwl_get_channel_info(priv, priv->band, ch);
  211. if (ch_info)
  212. cmd.expect_beacon = is_channel_radar(ch_info);
  213. else {
  214. IWL_ERR(priv, "invalid channel switch from %u to %u\n",
  215. ctx->active.channel, ch);
  216. return -EFAULT;
  217. }
  218. priv->switch_rxon.channel = cmd.channel;
  219. priv->switch_rxon.switch_in_progress = true;
  220. return iwl_send_cmd_sync(priv, &hcmd);
  221. }
  222. static struct iwl_lib_ops iwl2000_lib = {
  223. .set_hw_params = iwl2000_hw_set_hw_params,
  224. .rx_handler_setup = iwlagn_rx_handler_setup,
  225. .setup_deferred_work = iwlagn_bt_setup_deferred_work,
  226. .cancel_deferred_work = iwlagn_bt_cancel_deferred_work,
  227. .is_valid_rtc_data_addr = iwlagn_hw_valid_rtc_data_addr,
  228. .send_tx_power = iwlagn_send_tx_power,
  229. .update_chain_flags = iwl_update_chain_flags,
  230. .set_channel_switch = iwl2030_hw_channel_switch,
  231. .apm_ops = {
  232. .init = iwl_apm_init,
  233. .config = iwl2000_nic_config,
  234. },
  235. .eeprom_ops = {
  236. .regulatory_bands = {
  237. EEPROM_REG_BAND_1_CHANNELS,
  238. EEPROM_REG_BAND_2_CHANNELS,
  239. EEPROM_REG_BAND_3_CHANNELS,
  240. EEPROM_REG_BAND_4_CHANNELS,
  241. EEPROM_REG_BAND_5_CHANNELS,
  242. EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
  243. EEPROM_REGULATORY_BAND_NO_HT40,
  244. },
  245. .query_addr = iwlagn_eeprom_query_addr,
  246. .update_enhanced_txpower = iwlcore_eeprom_enhanced_txpower,
  247. },
  248. .temp_ops = {
  249. .temperature = iwlagn_temperature,
  250. },
  251. .txfifo_flush = iwlagn_txfifo_flush,
  252. .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
  253. };
  254. static const struct iwl_ops iwl2000_ops = {
  255. .lib = &iwl2000_lib,
  256. .hcmd = &iwlagn_hcmd,
  257. .utils = &iwlagn_hcmd_utils,
  258. };
  259. static const struct iwl_ops iwl2030_ops = {
  260. .lib = &iwl2000_lib,
  261. .hcmd = &iwlagn_bt_hcmd,
  262. .utils = &iwlagn_hcmd_utils,
  263. };
  264. static const struct iwl_ops iwl105_ops = {
  265. .lib = &iwl2000_lib,
  266. .hcmd = &iwlagn_hcmd,
  267. .utils = &iwlagn_hcmd_utils,
  268. };
  269. static const struct iwl_ops iwl135_ops = {
  270. .lib = &iwl2000_lib,
  271. .hcmd = &iwlagn_bt_hcmd,
  272. .utils = &iwlagn_hcmd_utils,
  273. };
  274. static struct iwl_base_params iwl2000_base_params = {
  275. .eeprom_size = OTP_LOW_IMAGE_SIZE,
  276. .num_of_queues = IWLAGN_NUM_QUEUES,
  277. .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
  278. .pll_cfg_val = 0,
  279. .max_ll_items = OTP_MAX_LL_ITEMS_2x00,
  280. .shadow_ram_support = true,
  281. .led_compensation = 51,
  282. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  283. .adv_thermal_throttle = true,
  284. .support_ct_kill_exit = true,
  285. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
  286. .chain_noise_scale = 1000,
  287. .wd_timeout = IWL_DEF_WD_TIMEOUT,
  288. .max_event_log_size = 512,
  289. .shadow_reg_enable = true,
  290. };
  291. static struct iwl_base_params iwl2030_base_params = {
  292. .eeprom_size = OTP_LOW_IMAGE_SIZE,
  293. .num_of_queues = IWLAGN_NUM_QUEUES,
  294. .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
  295. .pll_cfg_val = 0,
  296. .max_ll_items = OTP_MAX_LL_ITEMS_2x00,
  297. .shadow_ram_support = true,
  298. .led_compensation = 57,
  299. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  300. .adv_thermal_throttle = true,
  301. .support_ct_kill_exit = true,
  302. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
  303. .chain_noise_scale = 1000,
  304. .wd_timeout = IWL_LONG_WD_TIMEOUT,
  305. .max_event_log_size = 512,
  306. .shadow_reg_enable = true,
  307. };
  308. static struct iwl_ht_params iwl2000_ht_params = {
  309. .ht_greenfield_support = true,
  310. .use_rts_for_aggregation = true, /* use rts/cts protection */
  311. };
  312. static struct iwl_bt_params iwl2030_bt_params = {
  313. /* Due to bluetooth, we transmit 2.4 GHz probes only on antenna A */
  314. .advanced_bt_coexist = true,
  315. .agg_time_limit = BT_AGG_THRESHOLD_DEF,
  316. .bt_init_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_NONE,
  317. .bt_prio_boost = IWLAGN_BT_PRIO_BOOST_DEFAULT,
  318. .bt_sco_disable = true,
  319. .bt_session_2 = true,
  320. };
  321. #define IWL_DEVICE_2000 \
  322. .fw_name_pre = IWL2000_FW_PRE, \
  323. .ucode_api_max = IWL2000_UCODE_API_MAX, \
  324. .ucode_api_min = IWL2000_UCODE_API_MIN, \
  325. .eeprom_ver = EEPROM_2000_EEPROM_VERSION, \
  326. .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \
  327. .ops = &iwl2000_ops, \
  328. .base_params = &iwl2000_base_params, \
  329. .need_dc_calib = true, \
  330. .need_temp_offset_calib = true, \
  331. .led_mode = IWL_LED_RF_STATE, \
  332. .iq_invert = true, \
  333. .disable_otp_refresh = true \
  334. struct iwl_cfg iwl2000_2bgn_cfg = {
  335. .name = "2000 Series 2x2 BGN",
  336. IWL_DEVICE_2000,
  337. .ht_params = &iwl2000_ht_params,
  338. };
  339. struct iwl_cfg iwl2000_2bg_cfg = {
  340. .name = "2000 Series 2x2 BG",
  341. IWL_DEVICE_2000,
  342. };
  343. #define IWL_DEVICE_2030 \
  344. .fw_name_pre = IWL2030_FW_PRE, \
  345. .ucode_api_max = IWL2030_UCODE_API_MAX, \
  346. .ucode_api_min = IWL2030_UCODE_API_MIN, \
  347. .eeprom_ver = EEPROM_2000_EEPROM_VERSION, \
  348. .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \
  349. .ops = &iwl2030_ops, \
  350. .base_params = &iwl2030_base_params, \
  351. .bt_params = &iwl2030_bt_params, \
  352. .need_dc_calib = true, \
  353. .need_temp_offset_calib = true, \
  354. .led_mode = IWL_LED_RF_STATE, \
  355. .adv_pm = true, \
  356. .iq_invert = true \
  357. struct iwl_cfg iwl2030_2bgn_cfg = {
  358. .name = "2000 Series 2x2 BGN/BT",
  359. IWL_DEVICE_2030,
  360. .ht_params = &iwl2000_ht_params,
  361. };
  362. struct iwl_cfg iwl2030_2bg_cfg = {
  363. .name = "2000 Series 2x2 BG/BT",
  364. IWL_DEVICE_2030,
  365. };
  366. #define IWL_DEVICE_105 \
  367. .fw_name_pre = IWL105_FW_PRE, \
  368. .ucode_api_max = IWL105_UCODE_API_MAX, \
  369. .ucode_api_min = IWL105_UCODE_API_MIN, \
  370. .eeprom_ver = EEPROM_2000_EEPROM_VERSION, \
  371. .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \
  372. .ops = &iwl105_ops, \
  373. .base_params = &iwl2000_base_params, \
  374. .need_dc_calib = true, \
  375. .need_temp_offset_calib = true, \
  376. .led_mode = IWL_LED_RF_STATE, \
  377. .adv_pm = true, \
  378. .rx_with_siso_diversity = true \
  379. struct iwl_cfg iwl105_bg_cfg = {
  380. .name = "105 Series 1x1 BG",
  381. IWL_DEVICE_105,
  382. };
  383. struct iwl_cfg iwl105_bgn_cfg = {
  384. .name = "105 Series 1x1 BGN",
  385. IWL_DEVICE_105,
  386. .ht_params = &iwl2000_ht_params,
  387. };
  388. #define IWL_DEVICE_135 \
  389. .fw_name_pre = IWL105_FW_PRE, \
  390. .ucode_api_max = IWL105_UCODE_API_MAX, \
  391. .ucode_api_min = IWL105_UCODE_API_MIN, \
  392. .eeprom_ver = EEPROM_2000_EEPROM_VERSION, \
  393. .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \
  394. .ops = &iwl135_ops, \
  395. .base_params = &iwl2030_base_params, \
  396. .bt_params = &iwl2030_bt_params, \
  397. .need_dc_calib = true, \
  398. .need_temp_offset_calib = true, \
  399. .led_mode = IWL_LED_RF_STATE, \
  400. .adv_pm = true, \
  401. .rx_with_siso_diversity = true \
  402. struct iwl_cfg iwl135_bg_cfg = {
  403. .name = "105 Series 1x1 BG/BT",
  404. IWL_DEVICE_135,
  405. };
  406. struct iwl_cfg iwl135_bgn_cfg = {
  407. .name = "105 Series 1x1 BGN/BT",
  408. IWL_DEVICE_135,
  409. .ht_params = &iwl2000_ht_params,
  410. };
  411. MODULE_FIRMWARE(IWL2000_MODULE_FIRMWARE(IWL2000_UCODE_API_MAX));
  412. MODULE_FIRMWARE(IWL2030_MODULE_FIRMWARE(IWL2030_UCODE_API_MAX));
  413. MODULE_FIRMWARE(IWL105_MODULE_FIRMWARE(IWL105_UCODE_API_MAX));