iwl-5000.c 13 KB

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