iwl-5000.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2012 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 <net/mac80211.h>
  34. #include <linux/etherdevice.h>
  35. #include <asm/unaligned.h>
  36. #include <linux/stringify.h>
  37. #include "iwl-eeprom.h"
  38. #include "iwl-dev.h"
  39. #include "iwl-core.h"
  40. #include "iwl-io.h"
  41. #include "iwl-agn.h"
  42. #include "iwl-agn-hw.h"
  43. #include "iwl-trans.h"
  44. #include "iwl-shared.h"
  45. #include "iwl-cfg.h"
  46. #include "iwl-prph.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. iwl_rf_config(priv);
  61. /* W/A : NIC is stuck in a reset state after Early PCIe power off
  62. * (PCIe power is lost before PERST# is asserted),
  63. * causing ME FW to lose ownership and not being able to obtain it back.
  64. */
  65. iwl_set_bits_mask_prph(trans(priv), APMG_PS_CTRL_REG,
  66. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  67. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  68. }
  69. static const struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  70. .min_nrg_cck = 100,
  71. .auto_corr_min_ofdm = 90,
  72. .auto_corr_min_ofdm_mrc = 170,
  73. .auto_corr_min_ofdm_x1 = 105,
  74. .auto_corr_min_ofdm_mrc_x1 = 220,
  75. .auto_corr_max_ofdm = 120,
  76. .auto_corr_max_ofdm_mrc = 210,
  77. .auto_corr_max_ofdm_x1 = 120,
  78. .auto_corr_max_ofdm_mrc_x1 = 240,
  79. .auto_corr_min_cck = 125,
  80. .auto_corr_max_cck = 200,
  81. .auto_corr_min_cck_mrc = 200,
  82. .auto_corr_max_cck_mrc = 400,
  83. .nrg_th_cck = 100,
  84. .nrg_th_ofdm = 100,
  85. .barker_corr_th_min = 190,
  86. .barker_corr_th_min_mrc = 390,
  87. .nrg_th_cca = 62,
  88. };
  89. static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
  90. .min_nrg_cck = 95,
  91. .auto_corr_min_ofdm = 90,
  92. .auto_corr_min_ofdm_mrc = 170,
  93. .auto_corr_min_ofdm_x1 = 105,
  94. .auto_corr_min_ofdm_mrc_x1 = 220,
  95. .auto_corr_max_ofdm = 120,
  96. .auto_corr_max_ofdm_mrc = 210,
  97. /* max = min for performance bug in 5150 DSP */
  98. .auto_corr_max_ofdm_x1 = 105,
  99. .auto_corr_max_ofdm_mrc_x1 = 220,
  100. .auto_corr_min_cck = 125,
  101. .auto_corr_max_cck = 200,
  102. .auto_corr_min_cck_mrc = 170,
  103. .auto_corr_max_cck_mrc = 400,
  104. .nrg_th_cck = 95,
  105. .nrg_th_ofdm = 95,
  106. .barker_corr_th_min = 190,
  107. .barker_corr_th_min_mrc = 390,
  108. .nrg_th_cca = 62,
  109. };
  110. #define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF (-5)
  111. static s32 iwl_temp_calib_to_offset(struct iwl_shared *shrd)
  112. {
  113. u16 temperature, voltage;
  114. __le16 *temp_calib = (__le16 *)iwl_eeprom_query_addr(shrd,
  115. EEPROM_KELVIN_TEMPERATURE);
  116. temperature = le16_to_cpu(temp_calib[0]);
  117. voltage = le16_to_cpu(temp_calib[1]);
  118. /* offset = temp - volt / coeff */
  119. return (s32)(temperature - voltage / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF);
  120. }
  121. static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
  122. {
  123. const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
  124. s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
  125. iwl_temp_calib_to_offset(priv->shrd);
  126. hw_params(priv).ct_kill_threshold = threshold * volt2temp_coef;
  127. }
  128. static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
  129. {
  130. /* want Celsius */
  131. hw_params(priv).ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
  132. }
  133. static void iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  134. {
  135. hw_params(priv).max_txq_num = cfg(priv)->base_params->num_of_queues;
  136. hw_params(priv).ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  137. BIT(IEEE80211_BAND_5GHZ);
  138. hw_params(priv).tx_chains_num =
  139. num_of_ant(hw_params(priv).valid_tx_ant);
  140. hw_params(priv).rx_chains_num =
  141. num_of_ant(hw_params(priv).valid_rx_ant);
  142. iwl5000_set_ct_threshold(priv);
  143. /* Set initial sensitivity parameters */
  144. hw_params(priv).sens = &iwl5000_sensitivity;
  145. }
  146. static void iwl5150_hw_set_hw_params(struct iwl_priv *priv)
  147. {
  148. hw_params(priv).max_txq_num = cfg(priv)->base_params->num_of_queues;
  149. hw_params(priv).ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  150. BIT(IEEE80211_BAND_5GHZ);
  151. hw_params(priv).tx_chains_num =
  152. num_of_ant(hw_params(priv).valid_tx_ant);
  153. hw_params(priv).rx_chains_num =
  154. num_of_ant(hw_params(priv).valid_rx_ant);
  155. iwl5150_set_ct_threshold(priv);
  156. /* Set initial sensitivity parameters */
  157. hw_params(priv).sens = &iwl5150_sensitivity;
  158. }
  159. static void iwl5150_temperature(struct iwl_priv *priv)
  160. {
  161. u32 vt = 0;
  162. s32 offset = iwl_temp_calib_to_offset(priv->shrd);
  163. vt = le32_to_cpu(priv->statistics.common.temperature);
  164. vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
  165. /* now vt hold the temperature in Kelvin */
  166. priv->temperature = KELVIN_TO_CELSIUS(vt);
  167. iwl_tt_handler(priv);
  168. }
  169. static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
  170. struct ieee80211_channel_switch *ch_switch)
  171. {
  172. /*
  173. * MULTI-FIXME
  174. * See iwlagn_mac_channel_switch.
  175. */
  176. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  177. struct iwl5000_channel_switch_cmd cmd;
  178. const struct iwl_channel_info *ch_info;
  179. u32 switch_time_in_usec, ucode_switch_time;
  180. u16 ch;
  181. u32 tsf_low;
  182. u8 switch_count;
  183. u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
  184. struct ieee80211_vif *vif = ctx->vif;
  185. struct iwl_host_cmd hcmd = {
  186. .id = REPLY_CHANNEL_SWITCH,
  187. .len = { sizeof(cmd), },
  188. .flags = CMD_SYNC,
  189. .data = { &cmd, },
  190. };
  191. cmd.band = priv->band == IEEE80211_BAND_2GHZ;
  192. ch = ch_switch->channel->hw_value;
  193. IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
  194. ctx->active.channel, ch);
  195. cmd.channel = cpu_to_le16(ch);
  196. cmd.rxon_flags = ctx->staging.flags;
  197. cmd.rxon_filter_flags = ctx->staging.filter_flags;
  198. switch_count = ch_switch->count;
  199. tsf_low = ch_switch->timestamp & 0x0ffffffff;
  200. /*
  201. * calculate the ucode channel switch time
  202. * adding TSF as one of the factor for when to switch
  203. */
  204. if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
  205. if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
  206. beacon_interval)) {
  207. switch_count -= (priv->ucode_beacon_time -
  208. tsf_low) / beacon_interval;
  209. } else
  210. switch_count = 0;
  211. }
  212. if (switch_count <= 1)
  213. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  214. else {
  215. switch_time_in_usec =
  216. vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
  217. ucode_switch_time = iwl_usecs_to_beacons(priv,
  218. switch_time_in_usec,
  219. beacon_interval);
  220. cmd.switch_time = iwl_add_beacon_time(priv,
  221. priv->ucode_beacon_time,
  222. ucode_switch_time,
  223. beacon_interval);
  224. }
  225. IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
  226. cmd.switch_time);
  227. ch_info = iwl_get_channel_info(priv, priv->band, ch);
  228. if (ch_info)
  229. cmd.expect_beacon = is_channel_radar(ch_info);
  230. else {
  231. IWL_ERR(priv, "invalid channel switch from %u to %u\n",
  232. ctx->active.channel, ch);
  233. return -EFAULT;
  234. }
  235. return iwl_dvm_send_cmd(priv, &hcmd);
  236. }
  237. static struct iwl_lib_ops iwl5000_lib = {
  238. .set_hw_params = iwl5000_hw_set_hw_params,
  239. .set_channel_switch = iwl5000_hw_channel_switch,
  240. .nic_config = iwl5000_nic_config,
  241. .eeprom_ops = {
  242. .regulatory_bands = {
  243. EEPROM_REG_BAND_1_CHANNELS,
  244. EEPROM_REG_BAND_2_CHANNELS,
  245. EEPROM_REG_BAND_3_CHANNELS,
  246. EEPROM_REG_BAND_4_CHANNELS,
  247. EEPROM_REG_BAND_5_CHANNELS,
  248. EEPROM_REG_BAND_24_HT40_CHANNELS,
  249. EEPROM_REG_BAND_52_HT40_CHANNELS
  250. },
  251. },
  252. .temperature = iwlagn_temperature,
  253. };
  254. static struct iwl_lib_ops iwl5150_lib = {
  255. .set_hw_params = iwl5150_hw_set_hw_params,
  256. .set_channel_switch = iwl5000_hw_channel_switch,
  257. .nic_config = iwl5000_nic_config,
  258. .eeprom_ops = {
  259. .regulatory_bands = {
  260. EEPROM_REG_BAND_1_CHANNELS,
  261. EEPROM_REG_BAND_2_CHANNELS,
  262. EEPROM_REG_BAND_3_CHANNELS,
  263. EEPROM_REG_BAND_4_CHANNELS,
  264. EEPROM_REG_BAND_5_CHANNELS,
  265. EEPROM_REG_BAND_24_HT40_CHANNELS,
  266. EEPROM_REG_BAND_52_HT40_CHANNELS
  267. },
  268. },
  269. .temperature = iwl5150_temperature,
  270. };
  271. static const struct iwl_base_params iwl5000_base_params = {
  272. .eeprom_size = IWLAGN_EEPROM_IMG_SIZE,
  273. .num_of_queues = IWLAGN_NUM_QUEUES,
  274. .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
  275. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  276. .led_compensation = 51,
  277. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  278. .chain_noise_scale = 1000,
  279. .wd_timeout = IWL_LONG_WD_TIMEOUT,
  280. .max_event_log_size = 512,
  281. .no_idle_support = true,
  282. .wd_disable = true,
  283. };
  284. static const struct iwl_ht_params iwl5000_ht_params = {
  285. .ht_greenfield_support = true,
  286. };
  287. #define IWL_DEVICE_5000 \
  288. .fw_name_pre = IWL5000_FW_PRE, \
  289. .ucode_api_max = IWL5000_UCODE_API_MAX, \
  290. .ucode_api_min = IWL5000_UCODE_API_MIN, \
  291. .max_inst_size = IWLAGN_RTC_INST_SIZE, \
  292. .max_data_size = IWLAGN_RTC_DATA_SIZE, \
  293. .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \
  294. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \
  295. .lib = &iwl5000_lib, \
  296. .base_params = &iwl5000_base_params, \
  297. .led_mode = IWL_LED_BLINK
  298. const struct iwl_cfg iwl5300_agn_cfg = {
  299. .name = "Intel(R) Ultimate N WiFi Link 5300 AGN",
  300. IWL_DEVICE_5000,
  301. /* at least EEPROM 0x11A has wrong info */
  302. .valid_tx_ant = ANT_ABC, /* .cfg overwrite */
  303. .valid_rx_ant = ANT_ABC, /* .cfg overwrite */
  304. .ht_params = &iwl5000_ht_params,
  305. };
  306. const struct iwl_cfg iwl5100_bgn_cfg = {
  307. .name = "Intel(R) WiFi Link 5100 BGN",
  308. IWL_DEVICE_5000,
  309. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  310. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  311. .ht_params = &iwl5000_ht_params,
  312. };
  313. const struct iwl_cfg iwl5100_abg_cfg = {
  314. .name = "Intel(R) WiFi Link 5100 ABG",
  315. IWL_DEVICE_5000,
  316. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  317. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  318. };
  319. const struct iwl_cfg iwl5100_agn_cfg = {
  320. .name = "Intel(R) WiFi Link 5100 AGN",
  321. IWL_DEVICE_5000,
  322. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  323. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  324. .ht_params = &iwl5000_ht_params,
  325. };
  326. const struct iwl_cfg iwl5350_agn_cfg = {
  327. .name = "Intel(R) WiMAX/WiFi Link 5350 AGN",
  328. .fw_name_pre = IWL5000_FW_PRE,
  329. .ucode_api_max = IWL5000_UCODE_API_MAX,
  330. .ucode_api_min = IWL5000_UCODE_API_MIN,
  331. .max_inst_size = IWLAGN_RTC_INST_SIZE,
  332. .max_data_size = IWLAGN_RTC_DATA_SIZE,
  333. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  334. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  335. .lib = &iwl5000_lib,
  336. .base_params = &iwl5000_base_params,
  337. .ht_params = &iwl5000_ht_params,
  338. .led_mode = IWL_LED_BLINK,
  339. .internal_wimax_coex = true,
  340. };
  341. #define IWL_DEVICE_5150 \
  342. .fw_name_pre = IWL5150_FW_PRE, \
  343. .ucode_api_max = IWL5150_UCODE_API_MAX, \
  344. .ucode_api_min = IWL5150_UCODE_API_MIN, \
  345. .max_inst_size = IWLAGN_RTC_INST_SIZE, \
  346. .max_data_size = IWLAGN_RTC_DATA_SIZE, \
  347. .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \
  348. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \
  349. .lib = &iwl5150_lib, \
  350. .base_params = &iwl5000_base_params, \
  351. .no_xtal_calib = true, \
  352. .led_mode = IWL_LED_BLINK, \
  353. .internal_wimax_coex = true
  354. const struct iwl_cfg iwl5150_agn_cfg = {
  355. .name = "Intel(R) WiMAX/WiFi Link 5150 AGN",
  356. IWL_DEVICE_5150,
  357. .ht_params = &iwl5000_ht_params,
  358. };
  359. const struct iwl_cfg iwl5150_abg_cfg = {
  360. .name = "Intel(R) WiMAX/WiFi Link 5150 ABG",
  361. IWL_DEVICE_5150,
  362. };
  363. MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
  364. MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));