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_shared
*shrd
)
143 u16 temperature
, voltage
;
144 __le16
*temp_calib
= (__le16
*)iwl_eeprom_query_addr(shrd
,
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
->shrd
);
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 cfg(priv
)->base_params
->num_of_queues
=
174 iwlagn_mod_params
.num_of_queues
;
176 hw_params(priv
).max_txq_num
= cfg(priv
)->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(cfg(priv
)->valid_tx_ant
);
186 hw_params(priv
).rx_chains_num
= num_of_ant(cfg(priv
)->valid_rx_ant
);
187 hw_params(priv
).valid_tx_ant
= cfg(priv
)->valid_tx_ant
;
188 hw_params(priv
).valid_rx_ant
= cfg(priv
)->valid_rx_ant
;
190 iwl5000_set_ct_threshold(priv
);
192 /* Set initial sensitivity parameters */
193 hw_params(priv
).sens
= &iwl5000_sensitivity
;
198 static int iwl5150_hw_set_hw_params(struct iwl_priv
*priv
)
200 if (iwlagn_mod_params
.num_of_queues
>= IWL_MIN_NUM_QUEUES
&&
201 iwlagn_mod_params
.num_of_queues
<= IWLAGN_NUM_QUEUES
)
202 cfg(priv
)->base_params
->num_of_queues
=
203 iwlagn_mod_params
.num_of_queues
;
205 hw_params(priv
).max_txq_num
= cfg(priv
)->base_params
->num_of_queues
;
206 priv
->contexts
[IWL_RXON_CTX_BSS
].bcast_sta_id
= IWLAGN_BROADCAST_ID
;
208 hw_params(priv
).max_data_size
= IWLAGN_RTC_DATA_SIZE
;
209 hw_params(priv
).max_inst_size
= IWLAGN_RTC_INST_SIZE
;
211 hw_params(priv
).ht40_channel
= BIT(IEEE80211_BAND_2GHZ
) |
212 BIT(IEEE80211_BAND_5GHZ
);
214 hw_params(priv
).tx_chains_num
= num_of_ant(cfg(priv
)->valid_tx_ant
);
215 hw_params(priv
).rx_chains_num
= num_of_ant(cfg(priv
)->valid_rx_ant
);
216 hw_params(priv
).valid_tx_ant
= cfg(priv
)->valid_tx_ant
;
217 hw_params(priv
).valid_rx_ant
= cfg(priv
)->valid_rx_ant
;
219 iwl5150_set_ct_threshold(priv
);
221 /* Set initial sensitivity parameters */
222 hw_params(priv
).sens
= &iwl5150_sensitivity
;
227 static void iwl5150_temperature(struct iwl_priv
*priv
)
230 s32 offset
= iwl_temp_calib_to_offset(priv
->shrd
);
232 vt
= le32_to_cpu(priv
->statistics
.common
.temperature
);
233 vt
= vt
/ IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF
+ offset
;
234 /* now vt hold the temperature in Kelvin */
235 priv
->temperature
= KELVIN_TO_CELSIUS(vt
);
236 iwl_tt_handler(priv
);
239 static int iwl5000_hw_channel_switch(struct iwl_priv
*priv
,
240 struct ieee80211_channel_switch
*ch_switch
)
244 * See iwlagn_mac_channel_switch.
246 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
247 struct iwl5000_channel_switch_cmd cmd
;
248 const struct iwl_channel_info
*ch_info
;
249 u32 switch_time_in_usec
, ucode_switch_time
;
253 u16 beacon_interval
= le16_to_cpu(ctx
->timing
.beacon_interval
);
254 struct ieee80211_vif
*vif
= ctx
->vif
;
255 struct iwl_host_cmd hcmd
= {
256 .id
= REPLY_CHANNEL_SWITCH
,
257 .len
= { sizeof(cmd
), },
262 cmd
.band
= priv
->band
== IEEE80211_BAND_2GHZ
;
263 ch
= ch_switch
->channel
->hw_value
;
264 IWL_DEBUG_11H(priv
, "channel switch from %d to %d\n",
265 ctx
->active
.channel
, ch
);
266 cmd
.channel
= cpu_to_le16(ch
);
267 cmd
.rxon_flags
= ctx
->staging
.flags
;
268 cmd
.rxon_filter_flags
= ctx
->staging
.filter_flags
;
269 switch_count
= ch_switch
->count
;
270 tsf_low
= ch_switch
->timestamp
& 0x0ffffffff;
272 * calculate the ucode channel switch time
273 * adding TSF as one of the factor for when to switch
275 if ((priv
->ucode_beacon_time
> tsf_low
) && beacon_interval
) {
276 if (switch_count
> ((priv
->ucode_beacon_time
- tsf_low
) /
278 switch_count
-= (priv
->ucode_beacon_time
-
279 tsf_low
) / beacon_interval
;
283 if (switch_count
<= 1)
284 cmd
.switch_time
= cpu_to_le32(priv
->ucode_beacon_time
);
286 switch_time_in_usec
=
287 vif
->bss_conf
.beacon_int
* switch_count
* TIME_UNIT
;
288 ucode_switch_time
= iwl_usecs_to_beacons(priv
,
291 cmd
.switch_time
= iwl_add_beacon_time(priv
,
292 priv
->ucode_beacon_time
,
296 IWL_DEBUG_11H(priv
, "uCode time for the switch is 0x%x\n",
298 ch_info
= iwl_get_channel_info(priv
, priv
->band
, ch
);
300 cmd
.expect_beacon
= is_channel_radar(ch_info
);
302 IWL_ERR(priv
, "invalid channel switch from %u to %u\n",
303 ctx
->active
.channel
, ch
);
307 return iwl_trans_send_cmd(trans(priv
), &hcmd
);
310 static struct iwl_lib_ops iwl5000_lib
= {
311 .set_hw_params
= iwl5000_hw_set_hw_params
,
312 .set_channel_switch
= iwl5000_hw_channel_switch
,
313 .nic_config
= iwl5000_nic_config
,
315 .regulatory_bands
= {
316 EEPROM_REG_BAND_1_CHANNELS
,
317 EEPROM_REG_BAND_2_CHANNELS
,
318 EEPROM_REG_BAND_3_CHANNELS
,
319 EEPROM_REG_BAND_4_CHANNELS
,
320 EEPROM_REG_BAND_5_CHANNELS
,
321 EEPROM_REG_BAND_24_HT40_CHANNELS
,
322 EEPROM_REG_BAND_52_HT40_CHANNELS
325 .temperature
= iwlagn_temperature
,
328 static struct iwl_lib_ops iwl5150_lib
= {
329 .set_hw_params
= iwl5150_hw_set_hw_params
,
330 .set_channel_switch
= iwl5000_hw_channel_switch
,
331 .nic_config
= iwl5000_nic_config
,
333 .regulatory_bands
= {
334 EEPROM_REG_BAND_1_CHANNELS
,
335 EEPROM_REG_BAND_2_CHANNELS
,
336 EEPROM_REG_BAND_3_CHANNELS
,
337 EEPROM_REG_BAND_4_CHANNELS
,
338 EEPROM_REG_BAND_5_CHANNELS
,
339 EEPROM_REG_BAND_24_HT40_CHANNELS
,
340 EEPROM_REG_BAND_52_HT40_CHANNELS
343 .temperature
= iwl5150_temperature
,
346 static struct iwl_base_params iwl5000_base_params
= {
347 .eeprom_size
= IWLAGN_EEPROM_IMG_SIZE
,
348 .num_of_queues
= IWLAGN_NUM_QUEUES
,
349 .num_of_ampdu_queues
= IWLAGN_NUM_AMPDU_QUEUES
,
350 .pll_cfg_val
= CSR50_ANA_PLL_CFG_VAL
,
351 .led_compensation
= 51,
352 .plcp_delta_threshold
= IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF
,
353 .chain_noise_scale
= 1000,
354 .wd_timeout
= IWL_LONG_WD_TIMEOUT
,
355 .max_event_log_size
= 512,
356 .no_idle_support
= true,
359 static struct iwl_ht_params iwl5000_ht_params
= {
360 .ht_greenfield_support
= true,
363 #define IWL_DEVICE_5000 \
364 .fw_name_pre = IWL5000_FW_PRE, \
365 .ucode_api_max = IWL5000_UCODE_API_MAX, \
366 .ucode_api_ok = IWL5000_UCODE_API_OK, \
367 .ucode_api_min = IWL5000_UCODE_API_MIN, \
368 .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \
369 .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \
370 .lib = &iwl5000_lib, \
371 .base_params = &iwl5000_base_params, \
372 .led_mode = IWL_LED_BLINK
374 struct iwl_cfg iwl5300_agn_cfg
= {
375 .name
= "Intel(R) Ultimate N WiFi Link 5300 AGN",
377 /* at least EEPROM 0x11A has wrong info */
378 .valid_tx_ant
= ANT_ABC
, /* .cfg overwrite */
379 .valid_rx_ant
= ANT_ABC
, /* .cfg overwrite */
380 .ht_params
= &iwl5000_ht_params
,
383 struct iwl_cfg iwl5100_bgn_cfg
= {
384 .name
= "Intel(R) WiFi Link 5100 BGN",
386 .valid_tx_ant
= ANT_B
, /* .cfg overwrite */
387 .valid_rx_ant
= ANT_AB
, /* .cfg overwrite */
388 .ht_params
= &iwl5000_ht_params
,
391 struct iwl_cfg iwl5100_abg_cfg
= {
392 .name
= "Intel(R) WiFi Link 5100 ABG",
394 .valid_tx_ant
= ANT_B
, /* .cfg overwrite */
395 .valid_rx_ant
= ANT_AB
, /* .cfg overwrite */
398 struct iwl_cfg iwl5100_agn_cfg
= {
399 .name
= "Intel(R) WiFi Link 5100 AGN",
401 .valid_tx_ant
= ANT_B
, /* .cfg overwrite */
402 .valid_rx_ant
= ANT_AB
, /* .cfg overwrite */
403 .ht_params
= &iwl5000_ht_params
,
406 struct iwl_cfg iwl5350_agn_cfg
= {
407 .name
= "Intel(R) WiMAX/WiFi Link 5350 AGN",
408 .fw_name_pre
= IWL5000_FW_PRE
,
409 .ucode_api_max
= IWL5000_UCODE_API_MAX
,
410 .ucode_api_ok
= IWL5000_UCODE_API_OK
,
411 .ucode_api_min
= IWL5000_UCODE_API_MIN
,
412 .eeprom_ver
= EEPROM_5050_EEPROM_VERSION
,
413 .eeprom_calib_ver
= EEPROM_5050_TX_POWER_VERSION
,
415 .base_params
= &iwl5000_base_params
,
416 .ht_params
= &iwl5000_ht_params
,
417 .led_mode
= IWL_LED_BLINK
,
418 .internal_wimax_coex
= true,
421 #define IWL_DEVICE_5150 \
422 .fw_name_pre = IWL5150_FW_PRE, \
423 .ucode_api_max = IWL5150_UCODE_API_MAX, \
424 .ucode_api_ok = IWL5150_UCODE_API_OK, \
425 .ucode_api_min = IWL5150_UCODE_API_MIN, \
426 .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \
427 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \
428 .lib = &iwl5150_lib, \
429 .base_params = &iwl5000_base_params, \
430 .no_xtal_calib = true, \
431 .led_mode = IWL_LED_BLINK, \
432 .internal_wimax_coex = true
434 struct iwl_cfg iwl5150_agn_cfg
= {
435 .name
= "Intel(R) WiMAX/WiFi Link 5150 AGN",
437 .ht_params
= &iwl5000_ht_params
,
441 struct iwl_cfg iwl5150_abg_cfg
= {
442 .name
= "Intel(R) WiMAX/WiFi Link 5150 ABG",
446 MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_OK
));
447 MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_OK
));