iwl-5000.c 13 KB

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