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/pci.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/delay.h>
33 #include <linux/sched.h>
34 #include <linux/skbuff.h>
35 #include <linux/netdevice.h>
36 #include <linux/wireless.h>
37 #include <net/mac80211.h>
38 #include <linux/etherdevice.h>
39 #include <asm/unaligned.h>
40 #include <linux/stringify.h>
42 #include "iwl-eeprom.h"
47 #include "iwl-helpers.h"
49 #include "iwl-agn-hw.h"
50 #include "iwl-5000-hw.h"
52 /* Highest firmware API version supported */
53 #define IWL5000_UCODE_API_MAX 5
54 #define IWL5150_UCODE_API_MAX 2
56 /* Lowest firmware API version supported */
57 #define IWL5000_UCODE_API_MIN 1
58 #define IWL5150_UCODE_API_MIN 1
60 #define IWL5000_FW_PRE "iwlwifi-5000-"
61 #define IWL5000_MODULE_FIRMWARE(api) IWL5000_FW_PRE __stringify(api) ".ucode"
63 #define IWL5150_FW_PRE "iwlwifi-5150-"
64 #define IWL5150_MODULE_FIRMWARE(api) IWL5150_FW_PRE __stringify(api) ".ucode"
66 /* NIC configuration for 5000 series */
67 static void iwl5000_nic_config(struct iwl_priv *priv)
72 spin_lock_irqsave(&priv->lock, flags);
74 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
76 /* write radio config values to register */
77 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_RF_CONFIG_TYPE_MAX)
78 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
79 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
80 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
81 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
83 /* set CSR_HW_CONFIG_REG for uCode use */
84 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
85 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
86 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
88 /* W/A : NIC is stuck in a reset state after Early PCIe power off
89 * (PCIe power is lost before PERST# is asserted),
90 * causing ME FW to lose ownership and not being able to obtain it back.
92 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
93 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
94 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
97 spin_unlock_irqrestore(&priv->lock, flags);
100 static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
102 .max_nrg_cck = 0, /* not used, set to 0 */
103 .auto_corr_min_ofdm = 90,
104 .auto_corr_min_ofdm_mrc = 170,
105 .auto_corr_min_ofdm_x1 = 120,
106 .auto_corr_min_ofdm_mrc_x1 = 240,
108 .auto_corr_max_ofdm = 120,
109 .auto_corr_max_ofdm_mrc = 210,
110 .auto_corr_max_ofdm_x1 = 120,
111 .auto_corr_max_ofdm_mrc_x1 = 240,
113 .auto_corr_min_cck = 125,
114 .auto_corr_max_cck = 200,
115 .auto_corr_min_cck_mrc = 170,
116 .auto_corr_max_cck_mrc = 400,
120 .barker_corr_th_min = 190,
121 .barker_corr_th_min_mrc = 390,
125 static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
127 .max_nrg_cck = 0, /* not used, set to 0 */
128 .auto_corr_min_ofdm = 90,
129 .auto_corr_min_ofdm_mrc = 170,
130 .auto_corr_min_ofdm_x1 = 105,
131 .auto_corr_min_ofdm_mrc_x1 = 220,
133 .auto_corr_max_ofdm = 120,
134 .auto_corr_max_ofdm_mrc = 210,
135 /* max = min for performance bug in 5150 DSP */
136 .auto_corr_max_ofdm_x1 = 105,
137 .auto_corr_max_ofdm_mrc_x1 = 220,
139 .auto_corr_min_cck = 125,
140 .auto_corr_max_cck = 200,
141 .auto_corr_min_cck_mrc = 170,
142 .auto_corr_max_cck_mrc = 400,
146 .barker_corr_th_min = 190,
147 .barker_corr_th_min_mrc = 390,
151 static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
153 const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
154 s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
155 iwl_temp_calib_to_offset(priv);
157 priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
160 static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
163 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
166 static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
168 if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
169 iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
170 priv->cfg->base_params->num_of_queues =
171 iwlagn_mod_params.num_of_queues;
173 priv->hw_params.max_txq_num = priv->cfg->base_params->num_of_queues;
174 priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
175 priv->hw_params.scd_bc_tbls_size =
176 priv->cfg->base_params->num_of_queues *
177 sizeof(struct iwlagn_scd_bc_tbl);
178 priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
179 priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
180 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
182 priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE;
183 priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE;
185 priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
186 BIT(IEEE80211_BAND_5GHZ);
187 priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
189 priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
190 priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
191 priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
192 priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
194 iwl5000_set_ct_threshold(priv);
196 /* Set initial sensitivity parameters */
197 /* Set initial calibration set */
198 priv->hw_params.sens = &iwl5000_sensitivity;
199 priv->hw_params.calib_init_cfg =
200 BIT(IWL_CALIB_XTAL) |
202 BIT(IWL_CALIB_TX_IQ) |
203 BIT(IWL_CALIB_TX_IQ_PERD) |
204 BIT(IWL_CALIB_BASE_BAND);
206 priv->hw_params.beacon_time_tsf_bits = IWLAGN_EXT_BEACON_TIME_POS;
211 static int iwl5150_hw_set_hw_params(struct iwl_priv *priv)
213 if (iwlagn_mod_params.num_of_queues >= IWL_MIN_NUM_QUEUES &&
214 iwlagn_mod_params.num_of_queues <= IWLAGN_NUM_QUEUES)
215 priv->cfg->base_params->num_of_queues =
216 iwlagn_mod_params.num_of_queues;
218 priv->hw_params.max_txq_num = priv->cfg->base_params->num_of_queues;
219 priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
220 priv->hw_params.scd_bc_tbls_size =
221 priv->cfg->base_params->num_of_queues *
222 sizeof(struct iwlagn_scd_bc_tbl);
223 priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
224 priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
225 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
227 priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE;
228 priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE;
230 priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
231 BIT(IEEE80211_BAND_5GHZ);
232 priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
234 priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
235 priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
236 priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
237 priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
239 iwl5150_set_ct_threshold(priv);
241 /* Set initial sensitivity parameters */
242 /* Set initial calibration set */
243 priv->hw_params.sens = &iwl5150_sensitivity;
244 priv->hw_params.calib_init_cfg =
246 BIT(IWL_CALIB_TX_IQ) |
247 BIT(IWL_CALIB_BASE_BAND);
248 if (priv->cfg->need_dc_calib)
249 priv->hw_params.calib_init_cfg |= BIT(IWL_CALIB_DC);
251 priv->hw_params.beacon_time_tsf_bits = IWLAGN_EXT_BEACON_TIME_POS;
256 static void iwl5150_temperature(struct iwl_priv *priv)
259 s32 offset = iwl_temp_calib_to_offset(priv);
261 vt = le32_to_cpu(priv->statistics.common.temperature);
262 vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
263 /* now vt hold the temperature in Kelvin */
264 priv->temperature = KELVIN_TO_CELSIUS(vt);
265 iwl_tt_handler(priv);
268 static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
269 struct ieee80211_channel_switch *ch_switch)
273 * See iwl_mac_channel_switch.
275 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
276 struct iwl5000_channel_switch_cmd cmd;
277 const struct iwl_channel_info *ch_info;
278 u32 switch_time_in_usec, ucode_switch_time;
282 u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
283 struct ieee80211_vif *vif = ctx->vif;
284 struct iwl_host_cmd hcmd = {
285 .id = REPLY_CHANNEL_SWITCH,
286 .len = { sizeof(cmd), },
291 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
292 ch = ch_switch->channel->hw_value;
293 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
294 ctx->active.channel, ch);
295 cmd.channel = cpu_to_le16(ch);
296 cmd.rxon_flags = ctx->staging.flags;
297 cmd.rxon_filter_flags = ctx->staging.filter_flags;
298 switch_count = ch_switch->count;
299 tsf_low = ch_switch->timestamp & 0x0ffffffff;
301 * calculate the ucode channel switch time
302 * adding TSF as one of the factor for when to switch
304 if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
305 if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
307 switch_count -= (priv->ucode_beacon_time -
308 tsf_low) / beacon_interval;
312 if (switch_count <= 1)
313 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
315 switch_time_in_usec =
316 vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
317 ucode_switch_time = iwl_usecs_to_beacons(priv,
320 cmd.switch_time = iwl_add_beacon_time(priv,
321 priv->ucode_beacon_time,
325 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
327 ch_info = iwl_get_channel_info(priv, priv->band, ch);
329 cmd.expect_beacon = is_channel_radar(ch_info);
331 IWL_ERR(priv, "invalid channel switch from %u to %u\n",
332 ctx->active.channel, ch);
336 return iwl_send_cmd_sync(priv, &hcmd);
339 static struct iwl_lib_ops iwl5000_lib = {
340 .set_hw_params = iwl5000_hw_set_hw_params,
341 .rx_handler_setup = iwlagn_rx_handler_setup,
342 .setup_deferred_work = iwlagn_setup_deferred_work,
343 .is_valid_rtc_data_addr = iwlagn_hw_valid_rtc_data_addr,
344 .send_tx_power = iwlagn_send_tx_power,
345 .update_chain_flags = iwl_update_chain_flags,
346 .set_channel_switch = iwl5000_hw_channel_switch,
348 .init = iwl_apm_init,
349 .config = iwl5000_nic_config,
352 .regulatory_bands = {
353 EEPROM_REG_BAND_1_CHANNELS,
354 EEPROM_REG_BAND_2_CHANNELS,
355 EEPROM_REG_BAND_3_CHANNELS,
356 EEPROM_REG_BAND_4_CHANNELS,
357 EEPROM_REG_BAND_5_CHANNELS,
358 EEPROM_REG_BAND_24_HT40_CHANNELS,
359 EEPROM_REG_BAND_52_HT40_CHANNELS
361 .query_addr = iwlagn_eeprom_query_addr,
364 .temperature = iwlagn_temperature,
366 .txfifo_flush = iwlagn_txfifo_flush,
367 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
370 static struct iwl_lib_ops iwl5150_lib = {
371 .set_hw_params = iwl5150_hw_set_hw_params,
372 .rx_handler_setup = iwlagn_rx_handler_setup,
373 .setup_deferred_work = iwlagn_setup_deferred_work,
374 .is_valid_rtc_data_addr = iwlagn_hw_valid_rtc_data_addr,
375 .send_tx_power = iwlagn_send_tx_power,
376 .update_chain_flags = iwl_update_chain_flags,
377 .set_channel_switch = iwl5000_hw_channel_switch,
379 .init = iwl_apm_init,
380 .config = iwl5000_nic_config,
383 .regulatory_bands = {
384 EEPROM_REG_BAND_1_CHANNELS,
385 EEPROM_REG_BAND_2_CHANNELS,
386 EEPROM_REG_BAND_3_CHANNELS,
387 EEPROM_REG_BAND_4_CHANNELS,
388 EEPROM_REG_BAND_5_CHANNELS,
389 EEPROM_REG_BAND_24_HT40_CHANNELS,
390 EEPROM_REG_BAND_52_HT40_CHANNELS
392 .query_addr = iwlagn_eeprom_query_addr,
395 .temperature = iwl5150_temperature,
397 .txfifo_flush = iwlagn_txfifo_flush,
398 .dev_txfifo_flush = iwlagn_dev_txfifo_flush,
401 static const struct iwl_ops iwl5000_ops = {
403 .hcmd = &iwlagn_hcmd,
404 .utils = &iwlagn_hcmd_utils,
407 static const struct iwl_ops iwl5150_ops = {
409 .hcmd = &iwlagn_hcmd,
410 .utils = &iwlagn_hcmd_utils,
413 static struct iwl_base_params iwl5000_base_params = {
414 .eeprom_size = IWLAGN_EEPROM_IMG_SIZE,
415 .num_of_queues = IWLAGN_NUM_QUEUES,
416 .num_of_ampdu_queues = IWLAGN_NUM_AMPDU_QUEUES,
417 .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
418 .led_compensation = 51,
419 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
420 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
421 .chain_noise_scale = 1000,
422 .wd_timeout = IWL_LONG_WD_TIMEOUT,
423 .max_event_log_size = 512,
425 static struct iwl_ht_params iwl5000_ht_params = {
426 .ht_greenfield_support = true,
429 #define IWL_DEVICE_5000 \
430 .fw_name_pre = IWL5000_FW_PRE, \
431 .ucode_api_max = IWL5000_UCODE_API_MAX, \
432 .ucode_api_min = IWL5000_UCODE_API_MIN, \
433 .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \
434 .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \
435 .ops = &iwl5000_ops, \
436 .base_params = &iwl5000_base_params, \
437 .led_mode = IWL_LED_BLINK
439 struct iwl_cfg iwl5300_agn_cfg = {
440 .name = "Intel(R) Ultimate N WiFi Link 5300 AGN",
442 /* at least EEPROM 0x11A has wrong info */
443 .valid_tx_ant = ANT_ABC, /* .cfg overwrite */
444 .valid_rx_ant = ANT_ABC, /* .cfg overwrite */
445 .ht_params = &iwl5000_ht_params,
448 struct iwl_cfg iwl5100_bgn_cfg = {
449 .name = "Intel(R) WiFi Link 5100 BGN",
451 .valid_tx_ant = ANT_B, /* .cfg overwrite */
452 .valid_rx_ant = ANT_AB, /* .cfg overwrite */
453 .ht_params = &iwl5000_ht_params,
456 struct iwl_cfg iwl5100_abg_cfg = {
457 .name = "Intel(R) WiFi Link 5100 ABG",
459 .valid_tx_ant = ANT_B, /* .cfg overwrite */
460 .valid_rx_ant = ANT_AB, /* .cfg overwrite */
463 struct iwl_cfg iwl5100_agn_cfg = {
464 .name = "Intel(R) WiFi Link 5100 AGN",
466 .valid_tx_ant = ANT_B, /* .cfg overwrite */
467 .valid_rx_ant = ANT_AB, /* .cfg overwrite */
468 .ht_params = &iwl5000_ht_params,
471 struct iwl_cfg iwl5350_agn_cfg = {
472 .name = "Intel(R) WiMAX/WiFi Link 5350 AGN",
473 .fw_name_pre = IWL5000_FW_PRE,
474 .ucode_api_max = IWL5000_UCODE_API_MAX,
475 .ucode_api_min = IWL5000_UCODE_API_MIN,
476 .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
477 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
479 .base_params = &iwl5000_base_params,
480 .ht_params = &iwl5000_ht_params,
481 .led_mode = IWL_LED_BLINK,
482 .internal_wimax_coex = true,
485 #define IWL_DEVICE_5150 \
486 .fw_name_pre = IWL5150_FW_PRE, \
487 .ucode_api_max = IWL5150_UCODE_API_MAX, \
488 .ucode_api_min = IWL5150_UCODE_API_MIN, \
489 .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \
490 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \
491 .ops = &iwl5150_ops, \
492 .base_params = &iwl5000_base_params, \
493 .need_dc_calib = true, \
494 .led_mode = IWL_LED_BLINK, \
495 .internal_wimax_coex = true
497 struct iwl_cfg iwl5150_agn_cfg = {
498 .name = "Intel(R) WiMAX/WiFi Link 5150 AGN",
500 .ht_params = &iwl5000_ht_params,
504 struct iwl_cfg iwl5150_abg_cfg = {
505 .name = "Intel(R) WiMAX/WiFi Link 5150 ABG",
509 MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
510 MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));