iwl-5000.c 13 KB

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