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 <linux/wireless.h>
35 #include <net/mac80211.h>
36 #include <linux/etherdevice.h>
37 #include <asm/unaligned.h>
39 #include "iwl-eeprom.h"
44 #include "iwl-helpers.h"
46 #include "iwl-agn-hw.h"
47 #include "iwl-5000-hw.h"
49 /* Highest firmware API version supported */
50 #define IWL5000_UCODE_API_MAX 5
51 #define IWL5150_UCODE_API_MAX 2
53 /* Lowest firmware API version supported */
54 #define IWL5000_UCODE_API_MIN 1
55 #define IWL5150_UCODE_API_MIN 1
57 #define IWL5000_FW_PRE "iwlwifi-5000-"
58 #define IWL5000_MODULE_FIRMWARE(api) IWL5000_FW_PRE #api ".ucode"
60 #define IWL5150_FW_PRE "iwlwifi-5150-"
61 #define IWL5150_MODULE_FIRMWARE(api) IWL5150_FW_PRE #api ".ucode"
63 /* NIC configuration for 5000 series */
64 static void iwl5000_nic_config(struct iwl_priv
*priv
)
70 spin_lock_irqsave(&priv
->lock
, flags
);
72 /* W/A : NIC is stuck in a reset state after Early PCIe power off
73 * (PCIe power is lost before PERST# is asserted),
74 * causing ME FW to lose ownership and not being able to obtain it back.
76 iwl_set_bits_mask_prph(priv
, APMG_PS_CTRL_REG
,
77 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS
,
78 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS
);
81 spin_unlock_irqrestore(&priv
->lock
, flags
);
84 static struct iwl_sensitivity_ranges iwl5000_sensitivity
= {
86 .max_nrg_cck
= 0, /* not used, set to 0 */
87 .auto_corr_min_ofdm
= 90,
88 .auto_corr_min_ofdm_mrc
= 170,
89 .auto_corr_min_ofdm_x1
= 120,
90 .auto_corr_min_ofdm_mrc_x1
= 240,
92 .auto_corr_max_ofdm
= 120,
93 .auto_corr_max_ofdm_mrc
= 210,
94 .auto_corr_max_ofdm_x1
= 120,
95 .auto_corr_max_ofdm_mrc_x1
= 240,
97 .auto_corr_min_cck
= 125,
98 .auto_corr_max_cck
= 200,
99 .auto_corr_min_cck_mrc
= 170,
100 .auto_corr_max_cck_mrc
= 400,
104 .barker_corr_th_min
= 190,
105 .barker_corr_th_min_mrc
= 390,
109 static struct iwl_sensitivity_ranges iwl5150_sensitivity
= {
111 .max_nrg_cck
= 0, /* not used, set to 0 */
112 .auto_corr_min_ofdm
= 90,
113 .auto_corr_min_ofdm_mrc
= 170,
114 .auto_corr_min_ofdm_x1
= 105,
115 .auto_corr_min_ofdm_mrc_x1
= 220,
117 .auto_corr_max_ofdm
= 120,
118 .auto_corr_max_ofdm_mrc
= 210,
119 /* max = min for performance bug in 5150 DSP */
120 .auto_corr_max_ofdm_x1
= 105,
121 .auto_corr_max_ofdm_mrc_x1
= 220,
123 .auto_corr_min_cck
= 125,
124 .auto_corr_max_cck
= 200,
125 .auto_corr_min_cck_mrc
= 170,
126 .auto_corr_max_cck_mrc
= 400,
130 .barker_corr_th_min
= 190,
131 .barker_corr_th_min_mrc
= 390,
135 static void iwl5150_set_ct_threshold(struct iwl_priv
*priv
)
137 const s32 volt2temp_coef
= IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF
;
138 s32 threshold
= (s32
)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY
) -
139 iwl_temp_calib_to_offset(priv
);
141 priv
->hw_params
.ct_kill_threshold
= threshold
* volt2temp_coef
;
144 static void iwl5000_set_ct_threshold(struct iwl_priv
*priv
)
147 priv
->hw_params
.ct_kill_threshold
= CT_KILL_THRESHOLD_LEGACY
;
150 static int iwl5000_hw_set_hw_params(struct iwl_priv
*priv
)
152 if (iwlagn_mod_params
.num_of_queues
>= IWL_MIN_NUM_QUEUES
&&
153 iwlagn_mod_params
.num_of_queues
<= IWLAGN_NUM_QUEUES
)
154 priv
->cfg
->base_params
->num_of_queues
=
155 iwlagn_mod_params
.num_of_queues
;
157 priv
->hw_params
.max_txq_num
= priv
->cfg
->base_params
->num_of_queues
;
158 priv
->hw_params
.dma_chnl_num
= FH50_TCSR_CHNL_NUM
;
159 priv
->hw_params
.scd_bc_tbls_size
=
160 priv
->cfg
->base_params
->num_of_queues
*
161 sizeof(struct iwlagn_scd_bc_tbl
);
162 priv
->hw_params
.tfd_size
= sizeof(struct iwl_tfd
);
163 priv
->hw_params
.max_stations
= IWLAGN_STATION_COUNT
;
164 priv
->contexts
[IWL_RXON_CTX_BSS
].bcast_sta_id
= IWLAGN_BROADCAST_ID
;
166 priv
->hw_params
.max_data_size
= IWLAGN_RTC_DATA_SIZE
;
167 priv
->hw_params
.max_inst_size
= IWLAGN_RTC_INST_SIZE
;
169 priv
->hw_params
.ht40_channel
= BIT(IEEE80211_BAND_2GHZ
) |
170 BIT(IEEE80211_BAND_5GHZ
);
171 priv
->hw_params
.rx_wrt_ptr_reg
= FH_RSCSR_CHNL0_WPTR
;
173 priv
->hw_params
.tx_chains_num
= num_of_ant(priv
->cfg
->valid_tx_ant
);
174 priv
->hw_params
.rx_chains_num
= num_of_ant(priv
->cfg
->valid_rx_ant
);
175 priv
->hw_params
.valid_tx_ant
= priv
->cfg
->valid_tx_ant
;
176 priv
->hw_params
.valid_rx_ant
= priv
->cfg
->valid_rx_ant
;
178 iwl5000_set_ct_threshold(priv
);
180 /* Set initial sensitivity parameters */
181 /* Set initial calibration set */
182 priv
->hw_params
.sens
= &iwl5000_sensitivity
;
183 priv
->hw_params
.calib_init_cfg
=
184 BIT(IWL_CALIB_XTAL
) |
186 BIT(IWL_CALIB_TX_IQ
) |
187 BIT(IWL_CALIB_TX_IQ_PERD
) |
188 BIT(IWL_CALIB_BASE_BAND
);
190 priv
->hw_params
.beacon_time_tsf_bits
= IWLAGN_EXT_BEACON_TIME_POS
;
195 static int iwl5150_hw_set_hw_params(struct iwl_priv
*priv
)
197 if (iwlagn_mod_params
.num_of_queues
>= IWL_MIN_NUM_QUEUES
&&
198 iwlagn_mod_params
.num_of_queues
<= IWLAGN_NUM_QUEUES
)
199 priv
->cfg
->base_params
->num_of_queues
=
200 iwlagn_mod_params
.num_of_queues
;
202 priv
->hw_params
.max_txq_num
= priv
->cfg
->base_params
->num_of_queues
;
203 priv
->hw_params
.dma_chnl_num
= FH50_TCSR_CHNL_NUM
;
204 priv
->hw_params
.scd_bc_tbls_size
=
205 priv
->cfg
->base_params
->num_of_queues
*
206 sizeof(struct iwlagn_scd_bc_tbl
);
207 priv
->hw_params
.tfd_size
= sizeof(struct iwl_tfd
);
208 priv
->hw_params
.max_stations
= IWLAGN_STATION_COUNT
;
209 priv
->contexts
[IWL_RXON_CTX_BSS
].bcast_sta_id
= IWLAGN_BROADCAST_ID
;
211 priv
->hw_params
.max_data_size
= IWLAGN_RTC_DATA_SIZE
;
212 priv
->hw_params
.max_inst_size
= IWLAGN_RTC_INST_SIZE
;
214 priv
->hw_params
.ht40_channel
= BIT(IEEE80211_BAND_2GHZ
) |
215 BIT(IEEE80211_BAND_5GHZ
);
216 priv
->hw_params
.rx_wrt_ptr_reg
= FH_RSCSR_CHNL0_WPTR
;
218 priv
->hw_params
.tx_chains_num
= num_of_ant(priv
->cfg
->valid_tx_ant
);
219 priv
->hw_params
.rx_chains_num
= num_of_ant(priv
->cfg
->valid_rx_ant
);
220 priv
->hw_params
.valid_tx_ant
= priv
->cfg
->valid_tx_ant
;
221 priv
->hw_params
.valid_rx_ant
= priv
->cfg
->valid_rx_ant
;
223 iwl5150_set_ct_threshold(priv
);
225 /* Set initial sensitivity parameters */
226 /* Set initial calibration set */
227 priv
->hw_params
.sens
= &iwl5150_sensitivity
;
228 priv
->hw_params
.calib_init_cfg
=
230 BIT(IWL_CALIB_TX_IQ
) |
231 BIT(IWL_CALIB_BASE_BAND
);
232 if (priv
->cfg
->need_dc_calib
)
233 priv
->hw_params
.calib_init_cfg
|= BIT(IWL_CALIB_DC
);
235 priv
->hw_params
.beacon_time_tsf_bits
= IWLAGN_EXT_BEACON_TIME_POS
;
240 static void iwl5150_temperature(struct iwl_priv
*priv
)
243 s32 offset
= iwl_temp_calib_to_offset(priv
);
245 vt
= le32_to_cpu(priv
->statistics
.common
.temperature
);
246 vt
= vt
/ IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF
+ offset
;
247 /* now vt hold the temperature in Kelvin */
248 priv
->temperature
= KELVIN_TO_CELSIUS(vt
);
249 iwl_tt_handler(priv
);
252 static int iwl5000_hw_channel_switch(struct iwl_priv
*priv
,
253 struct ieee80211_channel_switch
*ch_switch
)
257 * See iwl_mac_channel_switch.
259 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
260 struct iwl5000_channel_switch_cmd cmd
;
261 const struct iwl_channel_info
*ch_info
;
262 u32 switch_time_in_usec
, ucode_switch_time
;
266 u16 beacon_interval
= le16_to_cpu(ctx
->timing
.beacon_interval
);
267 struct ieee80211_vif
*vif
= ctx
->vif
;
268 struct iwl_host_cmd hcmd
= {
269 .id
= REPLY_CHANNEL_SWITCH
,
270 .len
= { sizeof(cmd
), },
275 cmd
.band
= priv
->band
== IEEE80211_BAND_2GHZ
;
276 ch
= ch_switch
->channel
->hw_value
;
277 IWL_DEBUG_11H(priv
, "channel switch from %d to %d\n",
278 ctx
->active
.channel
, ch
);
279 cmd
.channel
= cpu_to_le16(ch
);
280 cmd
.rxon_flags
= ctx
->staging
.flags
;
281 cmd
.rxon_filter_flags
= ctx
->staging
.filter_flags
;
282 switch_count
= ch_switch
->count
;
283 tsf_low
= ch_switch
->timestamp
& 0x0ffffffff;
285 * calculate the ucode channel switch time
286 * adding TSF as one of the factor for when to switch
288 if ((priv
->ucode_beacon_time
> tsf_low
) && beacon_interval
) {
289 if (switch_count
> ((priv
->ucode_beacon_time
- tsf_low
) /
291 switch_count
-= (priv
->ucode_beacon_time
-
292 tsf_low
) / beacon_interval
;
296 if (switch_count
<= 1)
297 cmd
.switch_time
= cpu_to_le32(priv
->ucode_beacon_time
);
299 switch_time_in_usec
=
300 vif
->bss_conf
.beacon_int
* switch_count
* TIME_UNIT
;
301 ucode_switch_time
= iwl_usecs_to_beacons(priv
,
304 cmd
.switch_time
= iwl_add_beacon_time(priv
,
305 priv
->ucode_beacon_time
,
309 IWL_DEBUG_11H(priv
, "uCode time for the switch is 0x%x\n",
311 ch_info
= iwl_get_channel_info(priv
, priv
->band
, ch
);
313 cmd
.expect_beacon
= is_channel_radar(ch_info
);
315 IWL_ERR(priv
, "invalid channel switch from %u to %u\n",
316 ctx
->active
.channel
, ch
);
320 return iwl_send_cmd_sync(priv
, &hcmd
);
323 static struct iwl_lib_ops iwl5000_lib
= {
324 .set_hw_params
= iwl5000_hw_set_hw_params
,
325 .rx_handler_setup
= iwlagn_rx_handler_setup
,
326 .setup_deferred_work
= iwlagn_setup_deferred_work
,
327 .is_valid_rtc_data_addr
= iwlagn_hw_valid_rtc_data_addr
,
328 .update_chain_flags
= iwl_update_chain_flags
,
329 .set_channel_switch
= iwl5000_hw_channel_switch
,
331 .init
= iwl_apm_init
,
332 .config
= iwl5000_nic_config
,
335 .regulatory_bands
= {
336 EEPROM_REG_BAND_1_CHANNELS
,
337 EEPROM_REG_BAND_2_CHANNELS
,
338 EEPROM_REG_BAND_3_CHANNELS
,
339 EEPROM_REG_BAND_4_CHANNELS
,
340 EEPROM_REG_BAND_5_CHANNELS
,
341 EEPROM_REG_BAND_24_HT40_CHANNELS
,
342 EEPROM_REG_BAND_52_HT40_CHANNELS
344 .query_addr
= iwlagn_eeprom_query_addr
,
347 .temperature
= iwlagn_temperature
,
351 static struct iwl_lib_ops iwl5150_lib
= {
352 .set_hw_params
= iwl5150_hw_set_hw_params
,
353 .rx_handler_setup
= iwlagn_rx_handler_setup
,
354 .setup_deferred_work
= iwlagn_setup_deferred_work
,
355 .is_valid_rtc_data_addr
= iwlagn_hw_valid_rtc_data_addr
,
356 .update_chain_flags
= iwl_update_chain_flags
,
357 .set_channel_switch
= iwl5000_hw_channel_switch
,
359 .init
= iwl_apm_init
,
360 .config
= iwl5000_nic_config
,
363 .regulatory_bands
= {
364 EEPROM_REG_BAND_1_CHANNELS
,
365 EEPROM_REG_BAND_2_CHANNELS
,
366 EEPROM_REG_BAND_3_CHANNELS
,
367 EEPROM_REG_BAND_4_CHANNELS
,
368 EEPROM_REG_BAND_5_CHANNELS
,
369 EEPROM_REG_BAND_24_HT40_CHANNELS
,
370 EEPROM_REG_BAND_52_HT40_CHANNELS
372 .query_addr
= iwlagn_eeprom_query_addr
,
375 .temperature
= iwl5150_temperature
,
379 static const struct iwl_ops iwl5000_ops
= {
381 .hcmd
= &iwlagn_hcmd
,
382 .utils
= &iwlagn_hcmd_utils
,
385 static const struct iwl_ops iwl5150_ops
= {
387 .hcmd
= &iwlagn_hcmd
,
388 .utils
= &iwlagn_hcmd_utils
,
391 static struct iwl_base_params iwl5000_base_params
= {
392 .eeprom_size
= IWLAGN_EEPROM_IMG_SIZE
,
393 .num_of_queues
= IWLAGN_NUM_QUEUES
,
394 .num_of_ampdu_queues
= IWLAGN_NUM_AMPDU_QUEUES
,
395 .pll_cfg_val
= CSR50_ANA_PLL_CFG_VAL
,
396 .led_compensation
= 51,
397 .chain_noise_num_beacons
= IWL_CAL_NUM_BEACONS
,
398 .plcp_delta_threshold
= IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF
,
399 .chain_noise_scale
= 1000,
400 .wd_timeout
= IWL_LONG_WD_TIMEOUT
,
401 .max_event_log_size
= 512,
403 static struct iwl_ht_params iwl5000_ht_params
= {
404 .ht_greenfield_support
= true,
407 #define IWL_DEVICE_5000 \
408 .fw_name_pre = IWL5000_FW_PRE, \
409 .ucode_api_max = IWL5000_UCODE_API_MAX, \
410 .ucode_api_min = IWL5000_UCODE_API_MIN, \
411 .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \
412 .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \
413 .ops = &iwl5000_ops, \
414 .base_params = &iwl5000_base_params, \
415 .led_mode = IWL_LED_BLINK
417 struct iwl_cfg iwl5300_agn_cfg
= {
418 .name
= "Intel(R) Ultimate N WiFi Link 5300 AGN",
420 /* at least EEPROM 0x11A has wrong info */
421 .valid_tx_ant
= ANT_ABC
, /* .cfg overwrite */
422 .valid_rx_ant
= ANT_ABC
, /* .cfg overwrite */
423 .ht_params
= &iwl5000_ht_params
,
426 struct iwl_cfg iwl5100_bgn_cfg
= {
427 .name
= "Intel(R) WiFi Link 5100 BGN",
429 .valid_tx_ant
= ANT_B
, /* .cfg overwrite */
430 .valid_rx_ant
= ANT_AB
, /* .cfg overwrite */
431 .ht_params
= &iwl5000_ht_params
,
434 struct iwl_cfg iwl5100_abg_cfg
= {
435 .name
= "Intel(R) WiFi Link 5100 ABG",
437 .valid_tx_ant
= ANT_B
, /* .cfg overwrite */
438 .valid_rx_ant
= ANT_AB
, /* .cfg overwrite */
441 struct iwl_cfg iwl5100_agn_cfg
= {
442 .name
= "Intel(R) WiFi Link 5100 AGN",
444 .valid_tx_ant
= ANT_B
, /* .cfg overwrite */
445 .valid_rx_ant
= ANT_AB
, /* .cfg overwrite */
446 .ht_params
= &iwl5000_ht_params
,
449 struct iwl_cfg iwl5350_agn_cfg
= {
450 .name
= "Intel(R) WiMAX/WiFi Link 5350 AGN",
451 .fw_name_pre
= IWL5000_FW_PRE
,
452 .ucode_api_max
= IWL5000_UCODE_API_MAX
,
453 .ucode_api_min
= IWL5000_UCODE_API_MIN
,
454 .eeprom_ver
= EEPROM_5050_EEPROM_VERSION
,
455 .eeprom_calib_ver
= EEPROM_5050_TX_POWER_VERSION
,
457 .base_params
= &iwl5000_base_params
,
458 .ht_params
= &iwl5000_ht_params
,
459 .led_mode
= IWL_LED_BLINK
,
460 .internal_wimax_coex
= true,
463 #define IWL_DEVICE_5150 \
464 .fw_name_pre = IWL5150_FW_PRE, \
465 .ucode_api_max = IWL5150_UCODE_API_MAX, \
466 .ucode_api_min = IWL5150_UCODE_API_MIN, \
467 .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \
468 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \
469 .ops = &iwl5150_ops, \
470 .base_params = &iwl5000_base_params, \
471 .need_dc_calib = true, \
472 .led_mode = IWL_LED_BLINK, \
473 .internal_wimax_coex = true
475 struct iwl_cfg iwl5150_agn_cfg
= {
476 .name
= "Intel(R) WiMAX/WiFi Link 5150 AGN",
478 .ht_params
= &iwl5000_ht_params
,
482 struct iwl_cfg iwl5150_abg_cfg
= {
483 .name
= "Intel(R) WiMAX/WiFi Link 5150 ABG",
487 MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX
));
488 MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX
));