iwl-5000.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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).ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  136. BIT(IEEE80211_BAND_5GHZ);
  137. hw_params(priv).tx_chains_num =
  138. num_of_ant(hw_params(priv).valid_tx_ant);
  139. hw_params(priv).rx_chains_num =
  140. num_of_ant(hw_params(priv).valid_rx_ant);
  141. iwl5000_set_ct_threshold(priv);
  142. /* Set initial sensitivity parameters */
  143. hw_params(priv).sens = &iwl5000_sensitivity;
  144. }
  145. static void iwl5150_hw_set_hw_params(struct iwl_priv *priv)
  146. {
  147. hw_params(priv).ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  148. BIT(IEEE80211_BAND_5GHZ);
  149. hw_params(priv).tx_chains_num =
  150. num_of_ant(hw_params(priv).valid_tx_ant);
  151. hw_params(priv).rx_chains_num =
  152. num_of_ant(hw_params(priv).valid_rx_ant);
  153. iwl5150_set_ct_threshold(priv);
  154. /* Set initial sensitivity parameters */
  155. hw_params(priv).sens = &iwl5150_sensitivity;
  156. }
  157. static void iwl5150_temperature(struct iwl_priv *priv)
  158. {
  159. u32 vt = 0;
  160. s32 offset = iwl_temp_calib_to_offset(priv->shrd);
  161. vt = le32_to_cpu(priv->statistics.common.temperature);
  162. vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
  163. /* now vt hold the temperature in Kelvin */
  164. priv->temperature = KELVIN_TO_CELSIUS(vt);
  165. iwl_tt_handler(priv);
  166. }
  167. static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
  168. struct ieee80211_channel_switch *ch_switch)
  169. {
  170. /*
  171. * MULTI-FIXME
  172. * See iwlagn_mac_channel_switch.
  173. */
  174. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  175. struct iwl5000_channel_switch_cmd cmd;
  176. const struct iwl_channel_info *ch_info;
  177. u32 switch_time_in_usec, ucode_switch_time;
  178. u16 ch;
  179. u32 tsf_low;
  180. u8 switch_count;
  181. u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
  182. struct ieee80211_vif *vif = ctx->vif;
  183. struct iwl_host_cmd hcmd = {
  184. .id = REPLY_CHANNEL_SWITCH,
  185. .len = { sizeof(cmd), },
  186. .flags = CMD_SYNC,
  187. .data = { &cmd, },
  188. };
  189. cmd.band = priv->band == IEEE80211_BAND_2GHZ;
  190. ch = ch_switch->channel->hw_value;
  191. IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
  192. ctx->active.channel, ch);
  193. cmd.channel = cpu_to_le16(ch);
  194. cmd.rxon_flags = ctx->staging.flags;
  195. cmd.rxon_filter_flags = ctx->staging.filter_flags;
  196. switch_count = ch_switch->count;
  197. tsf_low = ch_switch->timestamp & 0x0ffffffff;
  198. /*
  199. * calculate the ucode channel switch time
  200. * adding TSF as one of the factor for when to switch
  201. */
  202. if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
  203. if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
  204. beacon_interval)) {
  205. switch_count -= (priv->ucode_beacon_time -
  206. tsf_low) / beacon_interval;
  207. } else
  208. switch_count = 0;
  209. }
  210. if (switch_count <= 1)
  211. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  212. else {
  213. switch_time_in_usec =
  214. vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
  215. ucode_switch_time = iwl_usecs_to_beacons(priv,
  216. switch_time_in_usec,
  217. beacon_interval);
  218. cmd.switch_time = iwl_add_beacon_time(priv,
  219. priv->ucode_beacon_time,
  220. ucode_switch_time,
  221. beacon_interval);
  222. }
  223. IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
  224. cmd.switch_time);
  225. ch_info = iwl_get_channel_info(priv, priv->band, ch);
  226. if (ch_info)
  227. cmd.expect_beacon = is_channel_radar(ch_info);
  228. else {
  229. IWL_ERR(priv, "invalid channel switch from %u to %u\n",
  230. ctx->active.channel, ch);
  231. return -EFAULT;
  232. }
  233. return iwl_dvm_send_cmd(priv, &hcmd);
  234. }
  235. static struct iwl_lib_ops iwl5000_lib = {
  236. .set_hw_params = iwl5000_hw_set_hw_params,
  237. .set_channel_switch = iwl5000_hw_channel_switch,
  238. .nic_config = iwl5000_nic_config,
  239. .eeprom_ops = {
  240. .regulatory_bands = {
  241. EEPROM_REG_BAND_1_CHANNELS,
  242. EEPROM_REG_BAND_2_CHANNELS,
  243. EEPROM_REG_BAND_3_CHANNELS,
  244. EEPROM_REG_BAND_4_CHANNELS,
  245. EEPROM_REG_BAND_5_CHANNELS,
  246. EEPROM_REG_BAND_24_HT40_CHANNELS,
  247. EEPROM_REG_BAND_52_HT40_CHANNELS
  248. },
  249. },
  250. .temperature = iwlagn_temperature,
  251. };
  252. static struct iwl_lib_ops iwl5150_lib = {
  253. .set_hw_params = iwl5150_hw_set_hw_params,
  254. .set_channel_switch = iwl5000_hw_channel_switch,
  255. .nic_config = iwl5000_nic_config,
  256. .eeprom_ops = {
  257. .regulatory_bands = {
  258. EEPROM_REG_BAND_1_CHANNELS,
  259. EEPROM_REG_BAND_2_CHANNELS,
  260. EEPROM_REG_BAND_3_CHANNELS,
  261. EEPROM_REG_BAND_4_CHANNELS,
  262. EEPROM_REG_BAND_5_CHANNELS,
  263. EEPROM_REG_BAND_24_HT40_CHANNELS,
  264. EEPROM_REG_BAND_52_HT40_CHANNELS
  265. },
  266. },
  267. .temperature = iwl5150_temperature,
  268. };
  269. static const struct iwl_base_params iwl5000_base_params = {
  270. .eeprom_size = IWLAGN_EEPROM_IMG_SIZE,
  271. .num_of_queues = IWLAGN_NUM_QUEUES,
  272. .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
  273. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  274. .led_compensation = 51,
  275. .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
  276. .chain_noise_scale = 1000,
  277. .wd_timeout = IWL_LONG_WD_TIMEOUT,
  278. .max_event_log_size = 512,
  279. .no_idle_support = true,
  280. .wd_disable = true,
  281. };
  282. static const struct iwl_ht_params iwl5000_ht_params = {
  283. .ht_greenfield_support = true,
  284. };
  285. #define IWL_DEVICE_5000 \
  286. .fw_name_pre = IWL5000_FW_PRE, \
  287. .ucode_api_max = IWL5000_UCODE_API_MAX, \
  288. .ucode_api_min = IWL5000_UCODE_API_MIN, \
  289. .max_inst_size = IWLAGN_RTC_INST_SIZE, \
  290. .max_data_size = IWLAGN_RTC_DATA_SIZE, \
  291. .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \
  292. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \
  293. .lib = &iwl5000_lib, \
  294. .base_params = &iwl5000_base_params, \
  295. .led_mode = IWL_LED_BLINK
  296. const struct iwl_cfg iwl5300_agn_cfg = {
  297. .name = "Intel(R) Ultimate N WiFi Link 5300 AGN",
  298. IWL_DEVICE_5000,
  299. /* at least EEPROM 0x11A has wrong info */
  300. .valid_tx_ant = ANT_ABC, /* .cfg overwrite */
  301. .valid_rx_ant = ANT_ABC, /* .cfg overwrite */
  302. .ht_params = &iwl5000_ht_params,
  303. };
  304. const struct iwl_cfg iwl5100_bgn_cfg = {
  305. .name = "Intel(R) WiFi Link 5100 BGN",
  306. IWL_DEVICE_5000,
  307. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  308. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  309. .ht_params = &iwl5000_ht_params,
  310. };
  311. const struct iwl_cfg iwl5100_abg_cfg = {
  312. .name = "Intel(R) WiFi Link 5100 ABG",
  313. IWL_DEVICE_5000,
  314. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  315. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  316. };
  317. const struct iwl_cfg iwl5100_agn_cfg = {
  318. .name = "Intel(R) WiFi Link 5100 AGN",
  319. IWL_DEVICE_5000,
  320. .valid_tx_ant = ANT_B, /* .cfg overwrite */
  321. .valid_rx_ant = ANT_AB, /* .cfg overwrite */
  322. .ht_params = &iwl5000_ht_params,
  323. };
  324. const struct iwl_cfg iwl5350_agn_cfg = {
  325. .name = "Intel(R) WiMAX/WiFi Link 5350 AGN",
  326. .fw_name_pre = IWL5000_FW_PRE,
  327. .ucode_api_max = IWL5000_UCODE_API_MAX,
  328. .ucode_api_min = IWL5000_UCODE_API_MIN,
  329. .max_inst_size = IWLAGN_RTC_INST_SIZE,
  330. .max_data_size = IWLAGN_RTC_DATA_SIZE,
  331. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  332. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  333. .lib = &iwl5000_lib,
  334. .base_params = &iwl5000_base_params,
  335. .ht_params = &iwl5000_ht_params,
  336. .led_mode = IWL_LED_BLINK,
  337. .internal_wimax_coex = true,
  338. };
  339. #define IWL_DEVICE_5150 \
  340. .fw_name_pre = IWL5150_FW_PRE, \
  341. .ucode_api_max = IWL5150_UCODE_API_MAX, \
  342. .ucode_api_min = IWL5150_UCODE_API_MIN, \
  343. .max_inst_size = IWLAGN_RTC_INST_SIZE, \
  344. .max_data_size = IWLAGN_RTC_DATA_SIZE, \
  345. .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \
  346. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \
  347. .lib = &iwl5150_lib, \
  348. .base_params = &iwl5000_base_params, \
  349. .no_xtal_calib = true, \
  350. .led_mode = IWL_LED_BLINK, \
  351. .internal_wimax_coex = true
  352. const struct iwl_cfg iwl5150_agn_cfg = {
  353. .name = "Intel(R) WiMAX/WiFi Link 5150 AGN",
  354. IWL_DEVICE_5150,
  355. .ht_params = &iwl5000_ht_params,
  356. };
  357. const struct iwl_cfg iwl5150_abg_cfg = {
  358. .name = "Intel(R) WiMAX/WiFi Link 5150 ABG",
  359. IWL_DEVICE_5150,
  360. };
  361. MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
  362. MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));