1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Intel Corporation. All rights reserved.
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.
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
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * Intel Linux Wireless <ilw@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *****************************************************************************/
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <linux/sched.h>
32 #include <linux/skbuff.h>
33 #include <linux/netdevice.h>
34 #include <net/mac80211.h>
35 #include <linux/etherdevice.h>
36 #include <asm/unaligned.h>
37 #include <linux/stringify.h>
39 #include "iwl-eeprom.h"
44 #include "iwl-agn-hw.h"
45 #include "iwl-trans.h"
46 #include "iwl-shared.h"
49 /* Highest firmware API version supported */
50 #define IWL5000_UCODE_API_MAX 5
51 #define IWL5150_UCODE_API_MAX 2
53 /* Oldest version we won't warn about */
54 #define IWL5000_UCODE_API_OK 5
55 #define IWL5150_UCODE_API_OK 2
57 /* Lowest firmware API version supported */
58 #define IWL5000_UCODE_API_MIN 1
59 #define IWL5150_UCODE_API_MIN 1
61 #define IWL5000_FW_PRE "iwlwifi-5000-"
62 #define IWL5000_MODULE_FIRMWARE(api) IWL5000_FW_PRE __stringify(api) ".ucode"
64 #define IWL5150_FW_PRE "iwlwifi-5150-"
65 #define IWL5150_MODULE_FIRMWARE(api) IWL5150_FW_PRE __stringify(api) ".ucode"
67 /* NIC configuration for 5000 series */
68 static void iwl5000_nic_config(struct iwl_priv *priv)
74 spin_lock_irqsave(&priv->shrd->lock, flags);
76 /* W/A : NIC is stuck in a reset state after Early PCIe power off
77 * (PCIe power is lost before PERST# is asserted),
78 * causing ME FW to lose ownership and not being able to obtain it back.
80 iwl_set_bits_mask_prph(bus(priv), APMG_PS_CTRL_REG,
81 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
82 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
85 spin_unlock_irqrestore(&priv->shrd->lock, flags);
88 static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
90 .max_nrg_cck = 0, /* not used, set to 0 */
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,
96 .auto_corr_max_ofdm = 120,
97 .auto_corr_max_ofdm_mrc = 210,
98 .auto_corr_max_ofdm_x1 = 120,
99 .auto_corr_max_ofdm_mrc_x1 = 240,
101 .auto_corr_min_cck = 125,
102 .auto_corr_max_cck = 200,
103 .auto_corr_min_cck_mrc = 200,
104 .auto_corr_max_cck_mrc = 400,
108 .barker_corr_th_min = 190,
109 .barker_corr_th_min_mrc = 390,
113 static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
115 .max_nrg_cck = 0, /* not used, set to 0 */
116 .auto_corr_min_ofdm = 90,
117 .auto_corr_min_ofdm_mrc = 170,
118 .auto_corr_min_ofdm_x1 = 105,
119 .auto_corr_min_ofdm_mrc_x1 = 220,
121 .auto_corr_max_ofdm = 120,
122 .auto_corr_max_ofdm_mrc = 210,
123 /* max = min for performance bug in 5150 DSP */
124 .auto_corr_max_ofdm_x1 = 105,
125 .auto_corr_max_ofdm_mrc_x1 = 220,
127 .auto_corr_min_cck = 125,
128 .auto_corr_max_cck = 200,
129 .auto_corr_min_cck_mrc = 170,
130 .auto_corr_max_cck_mrc = 400,
134 .barker_corr_th_min = 190,
135 .barker_corr_th_min_mrc = 390,
139 #define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF (-5)
141 static s32 iwl_temp_calib_to_offset(struct iwl_priv *priv)
143 u16 temperature, voltage;
144 __le16 *temp_calib = (__le16 *)iwl_eeprom_query_addr(priv,
145 EEPROM_KELVIN_TEMPERATURE);
147 temperature = le16_to_cpu(temp_calib[0]);
148 voltage = le16_to_cpu(temp_calib[1]);
150 /* offset = temp - volt / coeff */
151 return (s32)(temperature - voltage / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF);
154 static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
156 const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
157 s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
158 iwl_temp_calib_to_offset(priv);
160 hw_params(priv).ct_kill_threshold = threshold * volt2temp_coef;
163 static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
166 hw_params(priv).ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
169 static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
171 if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
172 iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
173 priv->cfg->base_params->num_of_queues =
174 iwlagn_mod_params.num_of_queues;
176 hw_params(priv).max_txq_num = priv->cfg->base_params->num_of_queues;
177 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
179 hw_params(priv).max_data_size = IWLAGN_RTC_DATA_SIZE;
180 hw_params(priv).max_inst_size = IWLAGN_RTC_INST_SIZE;
182 hw_params(priv).ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
183 BIT(IEEE80211_BAND_5GHZ);
185 hw_params(priv).tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
186 hw_params(priv).rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
187 hw_params(priv).valid_tx_ant = priv->cfg->valid_tx_ant;
188 hw_params(priv).valid_rx_ant = priv->cfg->valid_rx_ant;
190 iwl5000_set_ct_threshold(priv);
192 /* Set initial sensitivity parameters */
193 /* Set initial calibration set */
194 hw_params(priv).sens = &iwl5000_sensitivity;
195 hw_params(priv).calib_init_cfg =
196 BIT(IWL_CALIB_XTAL) |
198 BIT(IWL_CALIB_TX_IQ) |
199 BIT(IWL_CALIB_TX_IQ_PERD) |
200 BIT(IWL_CALIB_BASE_BAND);
205 static int iwl5150_hw_set_hw_params(struct iwl_priv *priv)
207 if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
208 iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
209 priv->cfg->base_params->num_of_queues =
210 iwlagn_mod_params.num_of_queues;
212 hw_params(priv).max_txq_num = priv->cfg->base_params->num_of_queues;
213 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
215 hw_params(priv).max_data_size = IWLAGN_RTC_DATA_SIZE;
216 hw_params(priv).max_inst_size = IWLAGN_RTC_INST_SIZE;
218 hw_params(priv).ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
219 BIT(IEEE80211_BAND_5GHZ);
221 hw_params(priv).tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
222 hw_params(priv).rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
223 hw_params(priv).valid_tx_ant = priv->cfg->valid_tx_ant;
224 hw_params(priv).valid_rx_ant = priv->cfg->valid_rx_ant;
226 iwl5150_set_ct_threshold(priv);
228 /* Set initial sensitivity parameters */
229 /* Set initial calibration set */
230 hw_params(priv).sens = &iwl5150_sensitivity;
231 hw_params(priv).calib_init_cfg =
233 BIT(IWL_CALIB_TX_IQ) |
234 BIT(IWL_CALIB_BASE_BAND);
235 if (priv->cfg->need_dc_calib)
236 hw_params(priv).calib_init_cfg |= BIT(IWL_CALIB_DC);
241 static void iwl5150_temperature(struct iwl_priv *priv)
244 s32 offset = iwl_temp_calib_to_offset(priv);
246 vt = le32_to_cpu(priv->statistics.common.temperature);
247 vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
248 /* now vt hold the temperature in Kelvin */
249 priv->temperature = KELVIN_TO_CELSIUS(vt);
250 iwl_tt_handler(priv);
253 static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
254 struct ieee80211_channel_switch *ch_switch)
258 * See iwlagn_mac_channel_switch.
260 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
261 struct iwl5000_channel_switch_cmd cmd;
262 const struct iwl_channel_info *ch_info;
263 u32 switch_time_in_usec, ucode_switch_time;
267 u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
268 struct ieee80211_vif *vif = ctx->vif;
269 struct iwl_host_cmd hcmd = {
270 .id = REPLY_CHANNEL_SWITCH,
271 .len = { sizeof(cmd), },
276 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
277 ch = ch_switch->channel->hw_value;
278 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
279 ctx->active.channel, ch);
280 cmd.channel = cpu_to_le16(ch);
281 cmd.rxon_flags = ctx->staging.flags;
282 cmd.rxon_filter_flags = ctx->staging.filter_flags;
283 switch_count = ch_switch->count;
284 tsf_low = ch_switch->timestamp & 0x0ffffffff;
286 * calculate the ucode channel switch time
287 * adding TSF as one of the factor for when to switch
289 if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
290 if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
292 switch_count -= (priv->ucode_beacon_time -
293 tsf_low) / beacon_interval;
297 if (switch_count <= 1)
298 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
300 switch_time_in_usec =
301 vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
302 ucode_switch_time = iwl_usecs_to_beacons(priv,
305 cmd.switch_time = iwl_add_beacon_time(priv,
306 priv->ucode_beacon_time,
310 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
312 ch_info = iwl_get_channel_info(priv, priv->band, ch);
314 cmd.expect_beacon = is_channel_radar(ch_info);
316 IWL_ERR(priv, "invalid channel switch from %u to %u\n",
317 ctx->active.channel, ch);
321 return iwl_trans_send_cmd(trans(priv), &hcmd);
324 static struct iwl_lib_ops iwl5000_lib = {
325 .set_hw_params = iwl5000_hw_set_hw_params,
326 .set_channel_switch = iwl5000_hw_channel_switch,
327 .nic_config = iwl5000_nic_config,
329 .regulatory_bands = {
330 EEPROM_REG_BAND_1_CHANNELS,
331 EEPROM_REG_BAND_2_CHANNELS,
332 EEPROM_REG_BAND_3_CHANNELS,
333 EEPROM_REG_BAND_4_CHANNELS,
334 EEPROM_REG_BAND_5_CHANNELS,
335 EEPROM_REG_BAND_24_HT40_CHANNELS,
336 EEPROM_REG_BAND_52_HT40_CHANNELS
339 .temperature = iwlagn_temperature,
342 static struct iwl_lib_ops iwl5150_lib = {
343 .set_hw_params = iwl5150_hw_set_hw_params,
344 .set_channel_switch = iwl5000_hw_channel_switch,
345 .nic_config = iwl5000_nic_config,
347 .regulatory_bands = {
348 EEPROM_REG_BAND_1_CHANNELS,
349 EEPROM_REG_BAND_2_CHANNELS,
350 EEPROM_REG_BAND_3_CHANNELS,
351 EEPROM_REG_BAND_4_CHANNELS,
352 EEPROM_REG_BAND_5_CHANNELS,
353 EEPROM_REG_BAND_24_HT40_CHANNELS,
354 EEPROM_REG_BAND_52_HT40_CHANNELS
357 .temperature = iwl5150_temperature,
360 static struct iwl_base_params iwl5000_base_params = {
361 .eeprom_size = IWLAGN_EEPROM_IMG_SIZE,
362 .num_of_queues = IWLAGN_NUM_QUEUES,
363 .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
364 .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
365 .led_compensation = 51,
366 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
367 .chain_noise_scale = 1000,
368 .wd_timeout = IWL_LONG_WD_TIMEOUT,
369 .max_event_log_size = 512,
370 .no_idle_support = true,
373 static struct iwl_ht_params iwl5000_ht_params = {
374 .ht_greenfield_support = true,
377 #define IWL_DEVICE_5000 \
378 .fw_name_pre = IWL5000_FW_PRE, \
379 .ucode_api_max = IWL5000_UCODE_API_MAX, \
380 .ucode_api_ok = IWL5000_UCODE_API_OK, \
381 .ucode_api_min = IWL5000_UCODE_API_MIN, \
382 .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \
383 .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \
384 .lib = &iwl5000_lib, \
385 .base_params = &iwl5000_base_params, \
386 .led_mode = IWL_LED_BLINK
388 struct iwl_cfg iwl5300_agn_cfg = {
389 .name = "Intel(R) Ultimate N WiFi Link 5300 AGN",
391 /* at least EEPROM 0x11A has wrong info */
392 .valid_tx_ant = ANT_ABC, /* .cfg overwrite */
393 .valid_rx_ant = ANT_ABC, /* .cfg overwrite */
394 .ht_params = &iwl5000_ht_params,
397 struct iwl_cfg iwl5100_bgn_cfg = {
398 .name = "Intel(R) WiFi Link 5100 BGN",
400 .valid_tx_ant = ANT_B, /* .cfg overwrite */
401 .valid_rx_ant = ANT_AB, /* .cfg overwrite */
402 .ht_params = &iwl5000_ht_params,
405 struct iwl_cfg iwl5100_abg_cfg = {
406 .name = "Intel(R) WiFi Link 5100 ABG",
408 .valid_tx_ant = ANT_B, /* .cfg overwrite */
409 .valid_rx_ant = ANT_AB, /* .cfg overwrite */
412 struct iwl_cfg iwl5100_agn_cfg = {
413 .name = "Intel(R) WiFi Link 5100 AGN",
415 .valid_tx_ant = ANT_B, /* .cfg overwrite */
416 .valid_rx_ant = ANT_AB, /* .cfg overwrite */
417 .ht_params = &iwl5000_ht_params,
420 struct iwl_cfg iwl5350_agn_cfg = {
421 .name = "Intel(R) WiMAX/WiFi Link 5350 AGN",
422 .fw_name_pre = IWL5000_FW_PRE,
423 .ucode_api_max = IWL5000_UCODE_API_MAX,
424 .ucode_api_ok = IWL5000_UCODE_API_OK,
425 .ucode_api_min = IWL5000_UCODE_API_MIN,
426 .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
427 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
429 .base_params = &iwl5000_base_params,
430 .ht_params = &iwl5000_ht_params,
431 .led_mode = IWL_LED_BLINK,
432 .internal_wimax_coex = true,
435 #define IWL_DEVICE_5150 \
436 .fw_name_pre = IWL5150_FW_PRE, \
437 .ucode_api_max = IWL5150_UCODE_API_MAX, \
438 .ucode_api_ok = IWL5150_UCODE_API_OK, \
439 .ucode_api_min = IWL5150_UCODE_API_MIN, \
440 .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \
441 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \
442 .lib = &iwl5150_lib, \
443 .base_params = &iwl5000_base_params, \
444 .need_dc_calib = true, \
445 .led_mode = IWL_LED_BLINK, \
446 .internal_wimax_coex = true
448 struct iwl_cfg iwl5150_agn_cfg = {
449 .name = "Intel(R) WiMAX/WiFi Link 5150 AGN",
451 .ht_params = &iwl5000_ht_params,
455 struct iwl_cfg iwl5150_abg_cfg = {
456 .name = "Intel(R) WiMAX/WiFi Link 5150 ABG",
460 MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_OK));
461 MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_OK));