iwl-5000.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 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/delay.h>
  30. #include <linux/sched.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/wireless.h>
  34. #include <net/mac80211.h>
  35. #include <linux/etherdevice.h>
  36. #include <asm/unaligned.h>
  37. #include <linux/stringify.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-helpers.h"
  44. #include "iwl-agn.h"
  45. #include "iwl-agn-hw.h"
  46. #include "iwl-5000-hw.h"
  47. /* Highest firmware API version supported */
  48. #define IWL5000_UCODE_API_MAX 5
  49. #define IWL5150_UCODE_API_MAX 2
  50. /* Lowest firmware API version supported */
  51. #define IWL5000_UCODE_API_MIN 1
  52. #define IWL5150_UCODE_API_MIN 1
  53. #define IWL5000_FW_PRE "iwlwifi-5000-"
  54. #define IWL5000_MODULE_FIRMWARE(api) IWL5000_FW_PRE __stringify(api) ".ucode"
  55. #define IWL5150_FW_PRE "iwlwifi-5150-"
  56. #define IWL5150_MODULE_FIRMWARE(api) IWL5150_FW_PRE __stringify(api) ".ucode"
  57. /* NIC configuration for 5000 series */
  58. static void iwl5000_nic_config(struct iwl_priv *priv)
  59. {
  60. unsigned long flags;
  61. iwl_rf_config(priv);
  62. spin_lock_irqsave(&priv->lock, flags);
  63. /* W/A : NIC is stuck in a reset state after Early PCIe power off
  64. * (PCIe power is lost before PERST# is asserted),
  65. * causing ME FW to lose ownership and not being able to obtain it back.
  66. */
  67. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  68. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  69. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  70. spin_unlock_irqrestore(&priv->lock, flags);
  71. }
  72. static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  73. .min_nrg_cck = 95,
  74. .max_nrg_cck = 0, /* not used, set to 0 */
  75. .auto_corr_min_ofdm = 90,
  76. .auto_corr_min_ofdm_mrc = 170,
  77. .auto_corr_min_ofdm_x1 = 120,
  78. .auto_corr_min_ofdm_mrc_x1 = 240,
  79. .auto_corr_max_ofdm = 120,
  80. .auto_corr_max_ofdm_mrc = 210,
  81. .auto_corr_max_ofdm_x1 = 120,
  82. .auto_corr_max_ofdm_mrc_x1 = 240,
  83. .auto_corr_min_cck = 125,
  84. .auto_corr_max_cck = 200,
  85. .auto_corr_min_cck_mrc = 170,
  86. .auto_corr_max_cck_mrc = 400,
  87. .nrg_th_cck = 95,
  88. .nrg_th_ofdm = 95,
  89. .barker_corr_th_min = 190,
  90. .barker_corr_th_min_mrc = 390,
  91. .nrg_th_cca = 62,
  92. };
  93. static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
  94. .min_nrg_cck = 95,
  95. .max_nrg_cck = 0, /* not used, set to 0 */
  96. .auto_corr_min_ofdm = 90,
  97. .auto_corr_min_ofdm_mrc = 170,
  98. .auto_corr_min_ofdm_x1 = 105,
  99. .auto_corr_min_ofdm_mrc_x1 = 220,
  100. .auto_corr_max_ofdm = 120,
  101. .auto_corr_max_ofdm_mrc = 210,
  102. /* max = min for performance bug in 5150 DSP */
  103. .auto_corr_max_ofdm_x1 = 105,
  104. .auto_corr_max_ofdm_mrc_x1 = 220,
  105. .auto_corr_min_cck = 125,
  106. .auto_corr_max_cck = 200,
  107. .auto_corr_min_cck_mrc = 170,
  108. .auto_corr_max_cck_mrc = 400,
  109. .nrg_th_cck = 95,
  110. .nrg_th_ofdm = 95,
  111. .barker_corr_th_min = 190,
  112. .barker_corr_th_min_mrc = 390,
  113. .nrg_th_cca = 62,
  114. };
  115. static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
  116. {
  117. const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
  118. s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
  119. iwl_temp_calib_to_offset(priv);
  120. priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
  121. }
  122. static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
  123. {
  124. /* want Celsius */
  125. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
  126. }
  127. static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  128. {
  129. if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
  130. iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
  131. priv->cfg->base_params->num_of_queues =
  132. iwlagn_mod_params.num_of_queues;
  133. priv->hw_params.max_txq_num = priv->cfg->base_params->num_of_queues;
  134. priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
  135. priv->hw_params.scd_bc_tbls_size =
  136. priv->cfg->base_params->num_of_queues *
  137. sizeof(struct iwlagn_scd_bc_tbl);
  138. priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
  139. priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
  140. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  141. priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE;
  142. priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE;
  143. priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  144. BIT(IEEE80211_BAND_5GHZ);
  145. priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
  146. priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
  147. priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
  148. priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
  149. iwl5000_set_ct_threshold(priv);
  150. /* Set initial sensitivity parameters */
  151. /* Set initial calibration set */
  152. priv->hw_params.sens = &iwl5000_sensitivity;
  153. priv->hw_params.calib_init_cfg =
  154. BIT(IWL_CALIB_XTAL) |
  155. BIT(IWL_CALIB_LO) |
  156. BIT(IWL_CALIB_TX_IQ) |
  157. BIT(IWL_CALIB_TX_IQ_PERD) |
  158. BIT(IWL_CALIB_BASE_BAND);
  159. priv->hw_params.beacon_time_tsf_bits = IWLAGN_EXT_BEACON_TIME_POS;
  160. return 0;
  161. }
  162. static int iwl5150_hw_set_hw_params(struct iwl_priv *priv)
  163. {
  164. if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
  165. iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
  166. priv->cfg->base_params->num_of_queues =
  167. iwlagn_mod_params.num_of_queues;
  168. priv->hw_params.max_txq_num = priv->cfg->base_params->num_of_queues;
  169. priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
  170. priv->hw_params.scd_bc_tbls_size =
  171. priv->cfg->base_params->num_of_queues *
  172. sizeof(struct iwlagn_scd_bc_tbl);
  173. priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
  174. priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
  175. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  176. priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE;
  177. priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE;
  178. priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  179. BIT(IEEE80211_BAND_5GHZ);
  180. priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
  181. priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
  182. priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
  183. priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
  184. iwl5150_set_ct_threshold(priv);
  185. /* Set initial sensitivity parameters */
  186. /* Set initial calibration set */
  187. priv->hw_params.sens = &iwl5150_sensitivity;
  188. priv->hw_params.calib_init_cfg =
  189. BIT(IWL_CALIB_LO) |
  190. BIT(IWL_CALIB_TX_IQ) |
  191. BIT(IWL_CALIB_BASE_BAND);
  192. if (priv->cfg->need_dc_calib)
  193. priv->hw_params.calib_init_cfg |= BIT(IWL_CALIB_DC);
  194. priv->hw_params.beacon_time_tsf_bits = IWLAGN_EXT_BEACON_TIME_POS;
  195. return 0;
  196. }
  197. static void iwl5150_temperature(struct iwl_priv *priv)
  198. {
  199. u32 vt = 0;
  200. s32 offset = iwl_temp_calib_to_offset(priv);
  201. vt = le32_to_cpu(priv->statistics.common.temperature);
  202. vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
  203. /* now vt hold the temperature in Kelvin */
  204. priv->temperature = KELVIN_TO_CELSIUS(vt);
  205. iwl_tt_handler(priv);
  206. }
  207. static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
  208. struct ieee80211_channel_switch *ch_switch)
  209. {
  210. /*
  211. * MULTI-FIXME
  212. * See iwl_mac_channel_switch.
  213. */
  214. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  215. struct iwl5000_channel_switch_cmd cmd;
  216. const struct iwl_channel_info *ch_info;
  217. u32 switch_time_in_usec, ucode_switch_time;
  218. u16 ch;
  219. u32 tsf_low;
  220. u8 switch_count;
  221. u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
  222. struct ieee80211_vif *vif = ctx->vif;
  223. struct iwl_host_cmd hcmd = {
  224. .id = REPLY_CHANNEL_SWITCH,
  225. .len = { sizeof(cmd), },
  226. .flags = CMD_SYNC,
  227. .data = { &cmd, },
  228. };
  229. cmd.band = priv->band == IEEE80211_BAND_2GHZ;
  230. ch = ch_switch->channel->hw_value;
  231. IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
  232. ctx->active.channel, ch);
  233. cmd.channel = cpu_to_le16(ch);
  234. cmd.rxon_flags = ctx->staging.flags;
  235. cmd.rxon_filter_flags = ctx->staging.filter_flags;
  236. switch_count = ch_switch->count;
  237. tsf_low = ch_switch->timestamp & 0x0ffffffff;
  238. /*
  239. * calculate the ucode channel switch time
  240. * adding TSF as one of the factor for when to switch
  241. */
  242. if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
  243. if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
  244. beacon_interval)) {
  245. switch_count -= (priv->ucode_beacon_time -
  246. tsf_low) / beacon_interval;
  247. } else
  248. switch_count = 0;
  249. }
  250. if (switch_count <= 1)
  251. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  252. else {
  253. switch_time_in_usec =
  254. vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
  255. ucode_switch_time = iwl_usecs_to_beacons(priv,
  256. switch_time_in_usec,
  257. beacon_interval);
  258. cmd.switch_time = iwl_add_beacon_time(priv,
  259. priv->ucode_beacon_time,
  260. ucode_switch_time,
  261. beacon_interval);
  262. }
  263. IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
  264. cmd.switch_time);
  265. ch_info = iwl_get_channel_info(priv, priv->band, ch);
  266. if (ch_info)
  267. cmd.expect_beacon = is_channel_radar(ch_info);
  268. else {
  269. IWL_ERR(priv, "invalid channel switch from %u to %u\n",
  270. ctx->active.channel, ch);
  271. return -EFAULT;
  272. }
  273. return iwl_send_cmd_sync(priv, &hcmd);
  274. }
  275. static struct iwl_lib_ops iwl5000_lib = {
  276. .set_hw_params = iwl5000_hw_set_hw_params,
  277. .rx_handler_setup = iwlagn_rx_handler_setup,
  278. .setup_deferred_work = iwlagn_setup_deferred_work,
  279. .is_valid_rtc_data_addr = iwlagn_hw_valid_rtc_data_addr,
  280. .update_chain_flags = iwl_update_chain_flags,
  281. .set_channel_switch = iwl5000_hw_channel_switch,
  282. .apm_ops = {
  283. .init = iwl_apm_init,
  284. .config = iwl5000_nic_config,
  285. },
  286. .eeprom_ops = {
  287. .regulatory_bands = {
  288. EEPROM_REG_BAND_1_CHANNELS,
  289. EEPROM_REG_BAND_2_CHANNELS,
  290. EEPROM_REG_BAND_3_CHANNELS,
  291. EEPROM_REG_BAND_4_CHANNELS,
  292. EEPROM_REG_BAND_5_CHANNELS,
  293. EEPROM_REG_BAND_24_HT40_CHANNELS,
  294. EEPROM_REG_BAND_52_HT40_CHANNELS
  295. },
  296. .query_addr = iwlagn_eeprom_query_addr,
  297. },
  298. .temp_ops = {
  299. .temperature = iwlagn_temperature,
  300. },
  301. };
  302. static struct iwl_lib_ops iwl5150_lib = {
  303. .set_hw_params = iwl5150_hw_set_hw_params,
  304. .rx_handler_setup = iwlagn_rx_handler_setup,
  305. .setup_deferred_work = iwlagn_setup_deferred_work,
  306. .is_valid_rtc_data_addr = iwlagn_hw_valid_rtc_data_addr,
  307. .update_chain_flags = iwl_update_chain_flags,
  308. .set_channel_switch = iwl5000_hw_channel_switch,
  309. .apm_ops = {
  310. .init = iwl_apm_init,
  311. .config = iwl5000_nic_config,
  312. },
  313. .eeprom_ops = {
  314. .regulatory_bands = {
  315. EEPROM_REG_BAND_1_CHANNELS,
  316. EEPROM_REG_BAND_2_CHANNELS,
  317. EEPROM_REG_BAND_3_CHANNELS,
  318. EEPROM_REG_BAND_4_CHANNELS,
  319. EEPROM_REG_BAND_5_CHANNELS,
  320. EEPROM_REG_BAND_24_HT40_CHANNELS,
  321. EEPROM_REG_BAND_52_HT40_CHANNELS
  322. },
  323. .query_addr = iwlagn_eeprom_query_addr,
  324. },
  325. .temp_ops = {
  326. .temperature = iwl5150_temperature,
  327. },
  328. };
  329. static const struct iwl_ops iwl5000_ops = {
  330. .lib = &iwl5000_lib,
  331. .utils = &iwlagn_hcmd_utils,
  332. };
  333. static const struct iwl_ops iwl5150_ops = {
  334. .lib = &iwl5150_lib,
  335. .utils = &iwlagn_hcmd_utils,
  336. };
  337. static struct iwl_base_params iwl5000_base_params = {
  338. .eeprom_size = IWLAGN_EEPROM_IMG_SIZE,
  339. .num_of_queues = IWLAGN_NUM_QUEUES,
  340. .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
  341. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  342. .led_compensation = 51,
  343. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  344. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  345. .chain_noise_scale = 1000,
  346. .wd_timeout = IWL_LONG_WD_TIMEOUT,
  347. .max_event_log_size = 512,
  348. };
  349. static struct iwl_ht_params iwl5000_ht_params = {
  350. .ht_greenfield_support = true,
  351. };
  352. #define IWL_DEVICE_5000 \
  353. .fw_name_pre = IWL5000_FW_PRE, \
  354. .ucode_api_max = IWL5000_UCODE_API_MAX, \
  355. .ucode_api_min = IWL5000_UCODE_API_MIN, \
  356. .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \
  357. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \
  358. .ops = &iwl5000_ops, \
  359. .base_params = &iwl5000_base_params, \
  360. .led_mode = IWL_LED_BLINK
  361. struct iwl_cfg iwl5300_agn_cfg = {
  362. .name = "Intel(R) Ultimate N WiFi Link 5300 AGN",
  363. IWL_DEVICE_5000,
  364. /* at least EEPROM 0x11A has wrong info */
  365. .valid_tx_ant = ANT_ABC, /* .cfg overwrite */
  366. .valid_rx_ant = ANT_ABC, /* .cfg overwrite */
  367. .ht_params = &iwl5000_ht_params,
  368. };
  369. struct iwl_cfg iwl5100_bgn_cfg = {
  370. .name = "Intel(R) WiFi Link 5100 BGN",
  371. IWL_DEVICE_5000,
  372. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  373. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  374. .ht_params = &iwl5000_ht_params,
  375. };
  376. struct iwl_cfg iwl5100_abg_cfg = {
  377. .name = "Intel(R) WiFi Link 5100 ABG",
  378. IWL_DEVICE_5000,
  379. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  380. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  381. };
  382. struct iwl_cfg iwl5100_agn_cfg = {
  383. .name = "Intel(R) WiFi Link 5100 AGN",
  384. IWL_DEVICE_5000,
  385. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  386. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  387. .ht_params = &iwl5000_ht_params,
  388. };
  389. struct iwl_cfg iwl5350_agn_cfg = {
  390. .name = "Intel(R) WiMAX/WiFi Link 5350 AGN",
  391. .fw_name_pre = IWL5000_FW_PRE,
  392. .ucode_api_max = IWL5000_UCODE_API_MAX,
  393. .ucode_api_min = IWL5000_UCODE_API_MIN,
  394. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  395. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  396. .ops = &iwl5000_ops,
  397. .base_params = &iwl5000_base_params,
  398. .ht_params = &iwl5000_ht_params,
  399. .led_mode = IWL_LED_BLINK,
  400. .internal_wimax_coex = true,
  401. };
  402. #define IWL_DEVICE_5150 \
  403. .fw_name_pre = IWL5150_FW_PRE, \
  404. .ucode_api_max = IWL5150_UCODE_API_MAX, \
  405. .ucode_api_min = IWL5150_UCODE_API_MIN, \
  406. .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \
  407. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \
  408. .ops = &iwl5150_ops, \
  409. .base_params = &iwl5000_base_params, \
  410. .need_dc_calib = true, \
  411. .led_mode = IWL_LED_BLINK, \
  412. .internal_wimax_coex = true
  413. struct iwl_cfg iwl5150_agn_cfg = {
  414. .name = "Intel(R) WiMAX/WiFi Link 5150 AGN",
  415. IWL_DEVICE_5150,
  416. .ht_params = &iwl5000_ht_params,
  417. };
  418. struct iwl_cfg iwl5150_abg_cfg = {
  419. .name = "Intel(R) WiMAX/WiFi Link 5150 ABG",
  420. IWL_DEVICE_5150,
  421. };
  422. MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
  423. MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));