iwl-5000.c 13 KB

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