1 /******************************************************************************
3 * Copyright(c) 2008 - 2012 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 *****************************************************************************/
28 * DVM device-specific data & functions
32 #include "iwl-eeprom-parse.h"
45 * For 1000, use advance thermal throttling critical temperature threshold,
46 * but legacy thermal management implementation for now.
47 * This is for the reason of 1000 uCode using advance thermal throttling API
48 * but not implement ct_kill_exit based on ct_kill exit temperature
49 * so the thermal throttling will still based on legacy thermal throttling
51 * The code here need to be modified once 1000 uCode has the advanced thermal
52 * throttling algorithm in place
54 static void iwl1000_set_ct_threshold(struct iwl_priv
*priv
)
57 priv
->hw_params
.ct_kill_threshold
= CT_KILL_THRESHOLD_LEGACY
;
58 priv
->hw_params
.ct_kill_exit_threshold
= CT_KILL_EXIT_THRESHOLD
;
61 /* NIC configuration for 1000 series */
62 static void iwl1000_nic_config(struct iwl_priv
*priv
)
64 /* Setting digital SVR for 1000 card to 1.32V */
65 /* locking is acquired in iwl_set_bits_mask_prph() function */
66 iwl_set_bits_mask_prph(priv
->trans
, APMG_DIGITAL_SVR_REG
,
67 APMG_SVR_DIGITAL_VOLTAGE_1_32
,
68 ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK
);
72 * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time
73 * @priv -- pointer to iwl_priv data structure
74 * @tsf_bits -- number of bits need to shift for masking)
76 static inline u32
iwl_beacon_time_mask_low(struct iwl_priv
*priv
,
79 return (1 << tsf_bits
) - 1;
83 * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time
84 * @priv -- pointer to iwl_priv data structure
85 * @tsf_bits -- number of bits need to shift for masking)
87 static inline u32
iwl_beacon_time_mask_high(struct iwl_priv
*priv
,
90 return ((1 << (32 - tsf_bits
)) - 1) << tsf_bits
;
94 * extended beacon time format
95 * time in usec will be changed into a 32-bit value in extended:internal format
96 * the extended part is the beacon counts
97 * the internal part is the time in usec within one beacon interval
99 static u32
iwl_usecs_to_beacons(struct iwl_priv
*priv
, u32 usec
,
104 u32 interval
= beacon_interval
* TIME_UNIT
;
106 if (!interval
|| !usec
)
109 quot
= (usec
/ interval
) &
110 (iwl_beacon_time_mask_high(priv
, IWLAGN_EXT_BEACON_TIME_POS
) >>
111 IWLAGN_EXT_BEACON_TIME_POS
);
112 rem
= (usec
% interval
) & iwl_beacon_time_mask_low(priv
,
113 IWLAGN_EXT_BEACON_TIME_POS
);
115 return (quot
<< IWLAGN_EXT_BEACON_TIME_POS
) + rem
;
118 /* base is usually what we get from ucode with each received frame,
119 * the same as HW timer counter counting down
121 static __le32
iwl_add_beacon_time(struct iwl_priv
*priv
, u32 base
,
122 u32 addon
, u32 beacon_interval
)
124 u32 base_low
= base
& iwl_beacon_time_mask_low(priv
,
125 IWLAGN_EXT_BEACON_TIME_POS
);
126 u32 addon_low
= addon
& iwl_beacon_time_mask_low(priv
,
127 IWLAGN_EXT_BEACON_TIME_POS
);
128 u32 interval
= beacon_interval
* TIME_UNIT
;
129 u32 res
= (base
& iwl_beacon_time_mask_high(priv
,
130 IWLAGN_EXT_BEACON_TIME_POS
)) +
131 (addon
& iwl_beacon_time_mask_high(priv
,
132 IWLAGN_EXT_BEACON_TIME_POS
));
134 if (base_low
> addon_low
)
135 res
+= base_low
- addon_low
;
136 else if (base_low
< addon_low
) {
137 res
+= interval
+ base_low
- addon_low
;
138 res
+= (1 << IWLAGN_EXT_BEACON_TIME_POS
);
140 res
+= (1 << IWLAGN_EXT_BEACON_TIME_POS
);
142 return cpu_to_le32(res
);
145 static const struct iwl_sensitivity_ranges iwl1000_sensitivity
= {
147 .auto_corr_min_ofdm
= 90,
148 .auto_corr_min_ofdm_mrc
= 170,
149 .auto_corr_min_ofdm_x1
= 120,
150 .auto_corr_min_ofdm_mrc_x1
= 240,
152 .auto_corr_max_ofdm
= 120,
153 .auto_corr_max_ofdm_mrc
= 210,
154 .auto_corr_max_ofdm_x1
= 155,
155 .auto_corr_max_ofdm_mrc_x1
= 290,
157 .auto_corr_min_cck
= 125,
158 .auto_corr_max_cck
= 200,
159 .auto_corr_min_cck_mrc
= 170,
160 .auto_corr_max_cck_mrc
= 400,
164 .barker_corr_th_min
= 190,
165 .barker_corr_th_min_mrc
= 390,
169 static void iwl1000_hw_set_hw_params(struct iwl_priv
*priv
)
171 iwl1000_set_ct_threshold(priv
);
173 /* Set initial sensitivity parameters */
174 priv
->hw_params
.sens
= &iwl1000_sensitivity
;
177 struct iwl_lib_ops iwl1000_lib
= {
178 .set_hw_params
= iwl1000_hw_set_hw_params
,
179 .nic_config
= iwl1000_nic_config
,
180 .temperature
= iwlagn_temperature
,
189 static void iwl2000_set_ct_threshold(struct iwl_priv
*priv
)
192 priv
->hw_params
.ct_kill_threshold
= CT_KILL_THRESHOLD
;
193 priv
->hw_params
.ct_kill_exit_threshold
= CT_KILL_EXIT_THRESHOLD
;
196 /* NIC configuration for 2000 series */
197 static void iwl2000_nic_config(struct iwl_priv
*priv
)
199 iwl_set_bit(priv
->trans
, CSR_GP_DRIVER_REG
,
200 CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER
);
203 static const struct iwl_sensitivity_ranges iwl2000_sensitivity
= {
205 .auto_corr_min_ofdm
= 80,
206 .auto_corr_min_ofdm_mrc
= 128,
207 .auto_corr_min_ofdm_x1
= 105,
208 .auto_corr_min_ofdm_mrc_x1
= 192,
210 .auto_corr_max_ofdm
= 145,
211 .auto_corr_max_ofdm_mrc
= 232,
212 .auto_corr_max_ofdm_x1
= 110,
213 .auto_corr_max_ofdm_mrc_x1
= 232,
215 .auto_corr_min_cck
= 125,
216 .auto_corr_max_cck
= 175,
217 .auto_corr_min_cck_mrc
= 160,
218 .auto_corr_max_cck_mrc
= 310,
222 .barker_corr_th_min
= 190,
223 .barker_corr_th_min_mrc
= 390,
227 static void iwl2000_hw_set_hw_params(struct iwl_priv
*priv
)
229 iwl2000_set_ct_threshold(priv
);
231 /* Set initial sensitivity parameters */
232 priv
->hw_params
.sens
= &iwl2000_sensitivity
;
235 struct iwl_lib_ops iwl2000_lib
= {
236 .set_hw_params
= iwl2000_hw_set_hw_params
,
237 .nic_config
= iwl2000_nic_config
,
238 .temperature
= iwlagn_temperature
,
241 struct iwl_lib_ops iwl2030_lib
= {
242 .set_hw_params
= iwl2000_hw_set_hw_params
,
243 .nic_config
= iwl2000_nic_config
,
244 .temperature
= iwlagn_temperature
,
252 /* NIC configuration for 5000 series */
253 static const struct iwl_sensitivity_ranges iwl5000_sensitivity
= {
255 .auto_corr_min_ofdm
= 90,
256 .auto_corr_min_ofdm_mrc
= 170,
257 .auto_corr_min_ofdm_x1
= 105,
258 .auto_corr_min_ofdm_mrc_x1
= 220,
260 .auto_corr_max_ofdm
= 120,
261 .auto_corr_max_ofdm_mrc
= 210,
262 .auto_corr_max_ofdm_x1
= 120,
263 .auto_corr_max_ofdm_mrc_x1
= 240,
265 .auto_corr_min_cck
= 125,
266 .auto_corr_max_cck
= 200,
267 .auto_corr_min_cck_mrc
= 200,
268 .auto_corr_max_cck_mrc
= 400,
272 .barker_corr_th_min
= 190,
273 .barker_corr_th_min_mrc
= 390,
277 static struct iwl_sensitivity_ranges iwl5150_sensitivity
= {
279 .auto_corr_min_ofdm
= 90,
280 .auto_corr_min_ofdm_mrc
= 170,
281 .auto_corr_min_ofdm_x1
= 105,
282 .auto_corr_min_ofdm_mrc_x1
= 220,
284 .auto_corr_max_ofdm
= 120,
285 .auto_corr_max_ofdm_mrc
= 210,
286 /* max = min for performance bug in 5150 DSP */
287 .auto_corr_max_ofdm_x1
= 105,
288 .auto_corr_max_ofdm_mrc_x1
= 220,
290 .auto_corr_min_cck
= 125,
291 .auto_corr_max_cck
= 200,
292 .auto_corr_min_cck_mrc
= 170,
293 .auto_corr_max_cck_mrc
= 400,
297 .barker_corr_th_min
= 190,
298 .barker_corr_th_min_mrc
= 390,
302 #define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF (-5)
304 static s32
iwl_temp_calib_to_offset(struct iwl_priv
*priv
)
306 u16 temperature
, voltage
;
308 temperature
= le16_to_cpu(priv
->nvm_data
->kelvin_temperature
);
309 voltage
= le16_to_cpu(priv
->nvm_data
->kelvin_voltage
);
311 /* offset = temp - volt / coeff */
312 return (s32
)(temperature
-
313 voltage
/ IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF
);
316 static void iwl5150_set_ct_threshold(struct iwl_priv
*priv
)
318 const s32 volt2temp_coef
= IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF
;
319 s32 threshold
= (s32
)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY
) -
320 iwl_temp_calib_to_offset(priv
);
322 priv
->hw_params
.ct_kill_threshold
= threshold
* volt2temp_coef
;
325 static void iwl5000_set_ct_threshold(struct iwl_priv
*priv
)
328 priv
->hw_params
.ct_kill_threshold
= CT_KILL_THRESHOLD_LEGACY
;
331 static void iwl5000_hw_set_hw_params(struct iwl_priv
*priv
)
333 iwl5000_set_ct_threshold(priv
);
335 /* Set initial sensitivity parameters */
336 priv
->hw_params
.sens
= &iwl5000_sensitivity
;
339 static void iwl5150_hw_set_hw_params(struct iwl_priv
*priv
)
341 iwl5150_set_ct_threshold(priv
);
343 /* Set initial sensitivity parameters */
344 priv
->hw_params
.sens
= &iwl5150_sensitivity
;
347 static void iwl5150_temperature(struct iwl_priv
*priv
)
350 s32 offset
= iwl_temp_calib_to_offset(priv
);
352 vt
= le32_to_cpu(priv
->statistics
.common
.temperature
);
353 vt
= vt
/ IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF
+ offset
;
354 /* now vt hold the temperature in Kelvin */
355 priv
->temperature
= KELVIN_TO_CELSIUS(vt
);
356 iwl_tt_handler(priv
);
359 static int iwl5000_hw_channel_switch(struct iwl_priv
*priv
,
360 struct ieee80211_channel_switch
*ch_switch
)
364 * See iwlagn_mac_channel_switch.
366 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
367 struct iwl5000_channel_switch_cmd cmd
;
368 u32 switch_time_in_usec
, ucode_switch_time
;
372 u16 beacon_interval
= le16_to_cpu(ctx
->timing
.beacon_interval
);
373 struct ieee80211_vif
*vif
= ctx
->vif
;
374 struct iwl_host_cmd hcmd
= {
375 .id
= REPLY_CHANNEL_SWITCH
,
376 .len
= { sizeof(cmd
), },
381 cmd
.band
= priv
->band
== IEEE80211_BAND_2GHZ
;
382 ch
= ch_switch
->channel
->hw_value
;
383 IWL_DEBUG_11H(priv
, "channel switch from %d to %d\n",
384 ctx
->active
.channel
, ch
);
385 cmd
.channel
= cpu_to_le16(ch
);
386 cmd
.rxon_flags
= ctx
->staging
.flags
;
387 cmd
.rxon_filter_flags
= ctx
->staging
.filter_flags
;
388 switch_count
= ch_switch
->count
;
389 tsf_low
= ch_switch
->timestamp
& 0x0ffffffff;
391 * calculate the ucode channel switch time
392 * adding TSF as one of the factor for when to switch
394 if ((priv
->ucode_beacon_time
> tsf_low
) && beacon_interval
) {
395 if (switch_count
> ((priv
->ucode_beacon_time
- tsf_low
) /
397 switch_count
-= (priv
->ucode_beacon_time
-
398 tsf_low
) / beacon_interval
;
402 if (switch_count
<= 1)
403 cmd
.switch_time
= cpu_to_le32(priv
->ucode_beacon_time
);
405 switch_time_in_usec
=
406 vif
->bss_conf
.beacon_int
* switch_count
* TIME_UNIT
;
407 ucode_switch_time
= iwl_usecs_to_beacons(priv
,
410 cmd
.switch_time
= iwl_add_beacon_time(priv
,
411 priv
->ucode_beacon_time
,
415 IWL_DEBUG_11H(priv
, "uCode time for the switch is 0x%x\n",
417 cmd
.expect_beacon
= ch_switch
->channel
->flags
& IEEE80211_CHAN_RADAR
;
419 return iwl_dvm_send_cmd(priv
, &hcmd
);
422 struct iwl_lib_ops iwl5000_lib
= {
423 .set_hw_params
= iwl5000_hw_set_hw_params
,
424 .set_channel_switch
= iwl5000_hw_channel_switch
,
425 .temperature
= iwlagn_temperature
,
428 struct iwl_lib_ops iwl5150_lib
= {
429 .set_hw_params
= iwl5150_hw_set_hw_params
,
430 .set_channel_switch
= iwl5000_hw_channel_switch
,
431 .temperature
= iwl5150_temperature
,
441 static void iwl6000_set_ct_threshold(struct iwl_priv
*priv
)
444 priv
->hw_params
.ct_kill_threshold
= CT_KILL_THRESHOLD
;
445 priv
->hw_params
.ct_kill_exit_threshold
= CT_KILL_EXIT_THRESHOLD
;
448 /* NIC configuration for 6000 series */
449 static void iwl6000_nic_config(struct iwl_priv
*priv
)
451 switch (priv
->cfg
->device_family
) {
452 case IWL_DEVICE_FAMILY_6005
:
453 case IWL_DEVICE_FAMILY_6030
:
454 case IWL_DEVICE_FAMILY_6000
:
456 case IWL_DEVICE_FAMILY_6000i
:
457 /* 2x2 IPA phy type */
458 iwl_write32(priv
->trans
, CSR_GP_DRIVER_REG
,
459 CSR_GP_DRIVER_REG_BIT_RADIO_SKU_2x2_IPA
);
461 case IWL_DEVICE_FAMILY_6050
:
462 /* Indicate calibration version to uCode. */
463 if (priv
->nvm_data
->calib_version
>= 6)
464 iwl_set_bit(priv
->trans
, CSR_GP_DRIVER_REG
,
465 CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6
);
467 case IWL_DEVICE_FAMILY_6150
:
468 /* Indicate calibration version to uCode. */
469 if (priv
->nvm_data
->calib_version
>= 6)
470 iwl_set_bit(priv
->trans
, CSR_GP_DRIVER_REG
,
471 CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6
);
472 iwl_set_bit(priv
->trans
, CSR_GP_DRIVER_REG
,
473 CSR_GP_DRIVER_REG_BIT_6050_1x2
);
480 static const struct iwl_sensitivity_ranges iwl6000_sensitivity
= {
482 .auto_corr_min_ofdm
= 80,
483 .auto_corr_min_ofdm_mrc
= 128,
484 .auto_corr_min_ofdm_x1
= 105,
485 .auto_corr_min_ofdm_mrc_x1
= 192,
487 .auto_corr_max_ofdm
= 145,
488 .auto_corr_max_ofdm_mrc
= 232,
489 .auto_corr_max_ofdm_x1
= 110,
490 .auto_corr_max_ofdm_mrc_x1
= 232,
492 .auto_corr_min_cck
= 125,
493 .auto_corr_max_cck
= 175,
494 .auto_corr_min_cck_mrc
= 160,
495 .auto_corr_max_cck_mrc
= 310,
499 .barker_corr_th_min
= 190,
500 .barker_corr_th_min_mrc
= 336,
504 static void iwl6000_hw_set_hw_params(struct iwl_priv
*priv
)
506 iwl6000_set_ct_threshold(priv
);
508 /* Set initial sensitivity parameters */
509 priv
->hw_params
.sens
= &iwl6000_sensitivity
;
513 static int iwl6000_hw_channel_switch(struct iwl_priv
*priv
,
514 struct ieee80211_channel_switch
*ch_switch
)
518 * See iwlagn_mac_channel_switch.
520 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
521 struct iwl6000_channel_switch_cmd cmd
;
522 u32 switch_time_in_usec
, ucode_switch_time
;
526 u16 beacon_interval
= le16_to_cpu(ctx
->timing
.beacon_interval
);
527 struct ieee80211_vif
*vif
= ctx
->vif
;
528 struct iwl_host_cmd hcmd
= {
529 .id
= REPLY_CHANNEL_SWITCH
,
530 .len
= { sizeof(cmd
), },
535 cmd
.band
= priv
->band
== IEEE80211_BAND_2GHZ
;
536 ch
= ch_switch
->channel
->hw_value
;
537 IWL_DEBUG_11H(priv
, "channel switch from %u to %u\n",
538 ctx
->active
.channel
, ch
);
539 cmd
.channel
= cpu_to_le16(ch
);
540 cmd
.rxon_flags
= ctx
->staging
.flags
;
541 cmd
.rxon_filter_flags
= ctx
->staging
.filter_flags
;
542 switch_count
= ch_switch
->count
;
543 tsf_low
= ch_switch
->timestamp
& 0x0ffffffff;
545 * calculate the ucode channel switch time
546 * adding TSF as one of the factor for when to switch
548 if ((priv
->ucode_beacon_time
> tsf_low
) && beacon_interval
) {
549 if (switch_count
> ((priv
->ucode_beacon_time
- tsf_low
) /
551 switch_count
-= (priv
->ucode_beacon_time
-
552 tsf_low
) / beacon_interval
;
556 if (switch_count
<= 1)
557 cmd
.switch_time
= cpu_to_le32(priv
->ucode_beacon_time
);
559 switch_time_in_usec
=
560 vif
->bss_conf
.beacon_int
* switch_count
* TIME_UNIT
;
561 ucode_switch_time
= iwl_usecs_to_beacons(priv
,
564 cmd
.switch_time
= iwl_add_beacon_time(priv
,
565 priv
->ucode_beacon_time
,
569 IWL_DEBUG_11H(priv
, "uCode time for the switch is 0x%x\n",
571 cmd
.expect_beacon
= ch_switch
->channel
->flags
& IEEE80211_CHAN_RADAR
;
573 return iwl_dvm_send_cmd(priv
, &hcmd
);
576 struct iwl_lib_ops iwl6000_lib
= {
577 .set_hw_params
= iwl6000_hw_set_hw_params
,
578 .set_channel_switch
= iwl6000_hw_channel_switch
,
579 .nic_config
= iwl6000_nic_config
,
580 .temperature
= iwlagn_temperature
,
583 struct iwl_lib_ops iwl6030_lib
= {
584 .set_hw_params
= iwl6000_hw_set_hw_params
,
585 .set_channel_switch
= iwl6000_hw_channel_switch
,
586 .nic_config
= iwl6000_nic_config
,
587 .temperature
= iwlagn_temperature
,