iwl-5000.c 14 KB

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