1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
3 *
4 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
5 * Copyright (C) 2019 Intel Corporation
6 *
7 * Contact Information:
8 * Intel Linux Wireless <linuxwifi@intel.com>
9 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
10 *
11 *****************************************************************************/
12
13 /*
14 * DVM device-specific data & functions
15 */
16 #include "iwl-io.h"
17 #include "iwl-prph.h"
18 #include "iwl-eeprom-parse.h"
19
20 #include "agn.h"
21 #include "dev.h"
22 #include "commands.h"
23
24
25 /*
26 * 1000 series
27 * ===========
28 */
29
30 /*
31 * For 1000, use advance thermal throttling critical temperature threshold,
32 * but legacy thermal management implementation for now.
33 * This is for the reason of 1000 uCode using advance thermal throttling API
34 * but not implement ct_kill_exit based on ct_kill exit temperature
35 * so the thermal throttling will still based on legacy thermal throttling
36 * management.
37 * The code here need to be modified once 1000 uCode has the advanced thermal
38 * throttling algorithm in place
39 */
iwl1000_set_ct_threshold(struct iwl_priv * priv)40 static void iwl1000_set_ct_threshold(struct iwl_priv *priv)
41 {
42 /* want Celsius */
43 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
44 priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
45 }
46
47 /* NIC configuration for 1000 series */
iwl1000_nic_config(struct iwl_priv * priv)48 static void iwl1000_nic_config(struct iwl_priv *priv)
49 {
50 /* Setting digital SVR for 1000 card to 1.32V */
51 /* locking is acquired in iwl_set_bits_mask_prph() function */
52 iwl_set_bits_mask_prph(priv->trans, APMG_DIGITAL_SVR_REG,
53 APMG_SVR_DIGITAL_VOLTAGE_1_32,
54 ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK);
55 }
56
57 /**
58 * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time
59 * @priv -- pointer to iwl_priv data structure
60 * @tsf_bits -- number of bits need to shift for masking)
61 */
iwl_beacon_time_mask_low(struct iwl_priv * priv,u16 tsf_bits)62 static inline u32 iwl_beacon_time_mask_low(struct iwl_priv *priv,
63 u16 tsf_bits)
64 {
65 return (1 << tsf_bits) - 1;
66 }
67
68 /**
69 * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time
70 * @priv -- pointer to iwl_priv data structure
71 * @tsf_bits -- number of bits need to shift for masking)
72 */
iwl_beacon_time_mask_high(struct iwl_priv * priv,u16 tsf_bits)73 static inline u32 iwl_beacon_time_mask_high(struct iwl_priv *priv,
74 u16 tsf_bits)
75 {
76 return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
77 }
78
79 /*
80 * extended beacon time format
81 * time in usec will be changed into a 32-bit value in extended:internal format
82 * the extended part is the beacon counts
83 * the internal part is the time in usec within one beacon interval
84 */
iwl_usecs_to_beacons(struct iwl_priv * priv,u32 usec,u32 beacon_interval)85 static u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec,
86 u32 beacon_interval)
87 {
88 u32 quot;
89 u32 rem;
90 u32 interval = beacon_interval * TIME_UNIT;
91
92 if (!interval || !usec)
93 return 0;
94
95 quot = (usec / interval) &
96 (iwl_beacon_time_mask_high(priv, IWLAGN_EXT_BEACON_TIME_POS) >>
97 IWLAGN_EXT_BEACON_TIME_POS);
98 rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
99 IWLAGN_EXT_BEACON_TIME_POS);
100
101 return (quot << IWLAGN_EXT_BEACON_TIME_POS) + rem;
102 }
103
104 /* base is usually what we get from ucode with each received frame,
105 * the same as HW timer counter counting down
106 */
iwl_add_beacon_time(struct iwl_priv * priv,u32 base,u32 addon,u32 beacon_interval)107 static __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
108 u32 addon, u32 beacon_interval)
109 {
110 u32 base_low = base & iwl_beacon_time_mask_low(priv,
111 IWLAGN_EXT_BEACON_TIME_POS);
112 u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
113 IWLAGN_EXT_BEACON_TIME_POS);
114 u32 interval = beacon_interval * TIME_UNIT;
115 u32 res = (base & iwl_beacon_time_mask_high(priv,
116 IWLAGN_EXT_BEACON_TIME_POS)) +
117 (addon & iwl_beacon_time_mask_high(priv,
118 IWLAGN_EXT_BEACON_TIME_POS));
119
120 if (base_low > addon_low)
121 res += base_low - addon_low;
122 else if (base_low < addon_low) {
123 res += interval + base_low - addon_low;
124 res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
125 } else
126 res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
127
128 return cpu_to_le32(res);
129 }
130
131 static const struct iwl_sensitivity_ranges iwl1000_sensitivity = {
132 .min_nrg_cck = 95,
133 .auto_corr_min_ofdm = 90,
134 .auto_corr_min_ofdm_mrc = 170,
135 .auto_corr_min_ofdm_x1 = 120,
136 .auto_corr_min_ofdm_mrc_x1 = 240,
137
138 .auto_corr_max_ofdm = 120,
139 .auto_corr_max_ofdm_mrc = 210,
140 .auto_corr_max_ofdm_x1 = 155,
141 .auto_corr_max_ofdm_mrc_x1 = 290,
142
143 .auto_corr_min_cck = 125,
144 .auto_corr_max_cck = 200,
145 .auto_corr_min_cck_mrc = 170,
146 .auto_corr_max_cck_mrc = 400,
147 .nrg_th_cck = 95,
148 .nrg_th_ofdm = 95,
149
150 .barker_corr_th_min = 190,
151 .barker_corr_th_min_mrc = 390,
152 .nrg_th_cca = 62,
153 };
154
iwl1000_hw_set_hw_params(struct iwl_priv * priv)155 static void iwl1000_hw_set_hw_params(struct iwl_priv *priv)
156 {
157 iwl1000_set_ct_threshold(priv);
158
159 /* Set initial sensitivity parameters */
160 priv->hw_params.sens = &iwl1000_sensitivity;
161 }
162
163 const struct iwl_dvm_cfg iwl_dvm_1000_cfg = {
164 .set_hw_params = iwl1000_hw_set_hw_params,
165 .nic_config = iwl1000_nic_config,
166 .temperature = iwlagn_temperature,
167 .support_ct_kill_exit = true,
168 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF,
169 .chain_noise_scale = 1000,
170 };
171
172
173 /*
174 * 2000 series
175 * ===========
176 */
177
iwl2000_set_ct_threshold(struct iwl_priv * priv)178 static void iwl2000_set_ct_threshold(struct iwl_priv *priv)
179 {
180 /* want Celsius */
181 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
182 priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
183 }
184
185 /* NIC configuration for 2000 series */
iwl2000_nic_config(struct iwl_priv * priv)186 static void iwl2000_nic_config(struct iwl_priv *priv)
187 {
188 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG,
189 CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER);
190 }
191
192 static const struct iwl_sensitivity_ranges iwl2000_sensitivity = {
193 .min_nrg_cck = 97,
194 .auto_corr_min_ofdm = 80,
195 .auto_corr_min_ofdm_mrc = 128,
196 .auto_corr_min_ofdm_x1 = 105,
197 .auto_corr_min_ofdm_mrc_x1 = 192,
198
199 .auto_corr_max_ofdm = 145,
200 .auto_corr_max_ofdm_mrc = 232,
201 .auto_corr_max_ofdm_x1 = 110,
202 .auto_corr_max_ofdm_mrc_x1 = 232,
203
204 .auto_corr_min_cck = 125,
205 .auto_corr_max_cck = 175,
206 .auto_corr_min_cck_mrc = 160,
207 .auto_corr_max_cck_mrc = 310,
208 .nrg_th_cck = 97,
209 .nrg_th_ofdm = 100,
210
211 .barker_corr_th_min = 190,
212 .barker_corr_th_min_mrc = 390,
213 .nrg_th_cca = 62,
214 };
215
iwl2000_hw_set_hw_params(struct iwl_priv * priv)216 static void iwl2000_hw_set_hw_params(struct iwl_priv *priv)
217 {
218 iwl2000_set_ct_threshold(priv);
219
220 /* Set initial sensitivity parameters */
221 priv->hw_params.sens = &iwl2000_sensitivity;
222 }
223
224 const struct iwl_dvm_cfg iwl_dvm_2000_cfg = {
225 .set_hw_params = iwl2000_hw_set_hw_params,
226 .nic_config = iwl2000_nic_config,
227 .temperature = iwlagn_temperature,
228 .adv_thermal_throttle = true,
229 .support_ct_kill_exit = true,
230 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
231 .chain_noise_scale = 1000,
232 .hd_v2 = true,
233 .need_temp_offset_calib = true,
234 .temp_offset_v2 = true,
235 };
236
237 const struct iwl_dvm_cfg iwl_dvm_105_cfg = {
238 .set_hw_params = iwl2000_hw_set_hw_params,
239 .nic_config = iwl2000_nic_config,
240 .temperature = iwlagn_temperature,
241 .adv_thermal_throttle = true,
242 .support_ct_kill_exit = true,
243 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
244 .chain_noise_scale = 1000,
245 .hd_v2 = true,
246 .need_temp_offset_calib = true,
247 .temp_offset_v2 = true,
248 .adv_pm = true,
249 };
250
251 static const struct iwl_dvm_bt_params iwl2030_bt_params = {
252 /* Due to bluetooth, we transmit 2.4 GHz probes only on antenna A */
253 .advanced_bt_coexist = true,
254 .agg_time_limit = BT_AGG_THRESHOLD_DEF,
255 .bt_init_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_NONE,
256 .bt_prio_boost = IWLAGN_BT_PRIO_BOOST_DEFAULT32,
257 .bt_sco_disable = true,
258 .bt_session_2 = true,
259 };
260
261 const struct iwl_dvm_cfg iwl_dvm_2030_cfg = {
262 .set_hw_params = iwl2000_hw_set_hw_params,
263 .nic_config = iwl2000_nic_config,
264 .temperature = iwlagn_temperature,
265 .adv_thermal_throttle = true,
266 .support_ct_kill_exit = true,
267 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
268 .chain_noise_scale = 1000,
269 .hd_v2 = true,
270 .bt_params = &iwl2030_bt_params,
271 .need_temp_offset_calib = true,
272 .temp_offset_v2 = true,
273 .adv_pm = true,
274 };
275
276 /*
277 * 5000 series
278 * ===========
279 */
280
281 /* NIC configuration for 5000 series */
282 static const struct iwl_sensitivity_ranges iwl5000_sensitivity = {
283 .min_nrg_cck = 100,
284 .auto_corr_min_ofdm = 90,
285 .auto_corr_min_ofdm_mrc = 170,
286 .auto_corr_min_ofdm_x1 = 105,
287 .auto_corr_min_ofdm_mrc_x1 = 220,
288
289 .auto_corr_max_ofdm = 120,
290 .auto_corr_max_ofdm_mrc = 210,
291 .auto_corr_max_ofdm_x1 = 120,
292 .auto_corr_max_ofdm_mrc_x1 = 240,
293
294 .auto_corr_min_cck = 125,
295 .auto_corr_max_cck = 200,
296 .auto_corr_min_cck_mrc = 200,
297 .auto_corr_max_cck_mrc = 400,
298 .nrg_th_cck = 100,
299 .nrg_th_ofdm = 100,
300
301 .barker_corr_th_min = 190,
302 .barker_corr_th_min_mrc = 390,
303 .nrg_th_cca = 62,
304 };
305
306 static const struct iwl_sensitivity_ranges iwl5150_sensitivity = {
307 .min_nrg_cck = 95,
308 .auto_corr_min_ofdm = 90,
309 .auto_corr_min_ofdm_mrc = 170,
310 .auto_corr_min_ofdm_x1 = 105,
311 .auto_corr_min_ofdm_mrc_x1 = 220,
312
313 .auto_corr_max_ofdm = 120,
314 .auto_corr_max_ofdm_mrc = 210,
315 /* max = min for performance bug in 5150 DSP */
316 .auto_corr_max_ofdm_x1 = 105,
317 .auto_corr_max_ofdm_mrc_x1 = 220,
318
319 .auto_corr_min_cck = 125,
320 .auto_corr_max_cck = 200,
321 .auto_corr_min_cck_mrc = 170,
322 .auto_corr_max_cck_mrc = 400,
323 .nrg_th_cck = 95,
324 .nrg_th_ofdm = 95,
325
326 .barker_corr_th_min = 190,
327 .barker_corr_th_min_mrc = 390,
328 .nrg_th_cca = 62,
329 };
330
331 #define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF (-5)
332
iwl_temp_calib_to_offset(struct iwl_priv * priv)333 static s32 iwl_temp_calib_to_offset(struct iwl_priv *priv)
334 {
335 u16 temperature, voltage;
336
337 temperature = le16_to_cpu(priv->nvm_data->kelvin_temperature);
338 voltage = le16_to_cpu(priv->nvm_data->kelvin_voltage);
339
340 /* offset = temp - volt / coeff */
341 return (s32)(temperature -
342 voltage / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF);
343 }
344
iwl5150_set_ct_threshold(struct iwl_priv * priv)345 static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
346 {
347 const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
348 s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
349 iwl_temp_calib_to_offset(priv);
350
351 priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
352 }
353
iwl5000_set_ct_threshold(struct iwl_priv * priv)354 static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
355 {
356 /* want Celsius */
357 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
358 }
359
iwl5000_hw_set_hw_params(struct iwl_priv * priv)360 static void iwl5000_hw_set_hw_params(struct iwl_priv *priv)
361 {
362 iwl5000_set_ct_threshold(priv);
363
364 /* Set initial sensitivity parameters */
365 priv->hw_params.sens = &iwl5000_sensitivity;
366 }
367
iwl5150_hw_set_hw_params(struct iwl_priv * priv)368 static void iwl5150_hw_set_hw_params(struct iwl_priv *priv)
369 {
370 iwl5150_set_ct_threshold(priv);
371
372 /* Set initial sensitivity parameters */
373 priv->hw_params.sens = &iwl5150_sensitivity;
374 }
375
iwl5150_temperature(struct iwl_priv * priv)376 static void iwl5150_temperature(struct iwl_priv *priv)
377 {
378 u32 vt = 0;
379 s32 offset = iwl_temp_calib_to_offset(priv);
380
381 vt = le32_to_cpu(priv->statistics.common.temperature);
382 vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
383 /* now vt hold the temperature in Kelvin */
384 priv->temperature = KELVIN_TO_CELSIUS(vt);
385 iwl_tt_handler(priv);
386 }
387
iwl5000_hw_channel_switch(struct iwl_priv * priv,struct ieee80211_channel_switch * ch_switch)388 static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
389 struct ieee80211_channel_switch *ch_switch)
390 {
391 /*
392 * MULTI-FIXME
393 * See iwlagn_mac_channel_switch.
394 */
395 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
396 struct iwl5000_channel_switch_cmd cmd;
397 u32 switch_time_in_usec, ucode_switch_time;
398 u16 ch;
399 u32 tsf_low;
400 u8 switch_count;
401 u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
402 struct ieee80211_vif *vif = ctx->vif;
403 struct iwl_host_cmd hcmd = {
404 .id = REPLY_CHANNEL_SWITCH,
405 .len = { sizeof(cmd), },
406 .data = { &cmd, },
407 };
408
409 cmd.band = priv->band == NL80211_BAND_2GHZ;
410 ch = ch_switch->chandef.chan->hw_value;
411 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
412 ctx->active.channel, ch);
413 cmd.channel = cpu_to_le16(ch);
414 cmd.rxon_flags = ctx->staging.flags;
415 cmd.rxon_filter_flags = ctx->staging.filter_flags;
416 switch_count = ch_switch->count;
417 tsf_low = ch_switch->timestamp & 0x0ffffffff;
418 /*
419 * calculate the ucode channel switch time
420 * adding TSF as one of the factor for when to switch
421 */
422 if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
423 if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
424 beacon_interval)) {
425 switch_count -= (priv->ucode_beacon_time -
426 tsf_low) / beacon_interval;
427 } else
428 switch_count = 0;
429 }
430 if (switch_count <= 1)
431 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
432 else {
433 switch_time_in_usec =
434 vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
435 ucode_switch_time = iwl_usecs_to_beacons(priv,
436 switch_time_in_usec,
437 beacon_interval);
438 cmd.switch_time = iwl_add_beacon_time(priv,
439 priv->ucode_beacon_time,
440 ucode_switch_time,
441 beacon_interval);
442 }
443 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
444 cmd.switch_time);
445 cmd.expect_beacon =
446 ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
447
448 return iwl_dvm_send_cmd(priv, &hcmd);
449 }
450
451 const struct iwl_dvm_cfg iwl_dvm_5000_cfg = {
452 .set_hw_params = iwl5000_hw_set_hw_params,
453 .set_channel_switch = iwl5000_hw_channel_switch,
454 .temperature = iwlagn_temperature,
455 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
456 .chain_noise_scale = 1000,
457 .no_idle_support = true,
458 };
459
460 const struct iwl_dvm_cfg iwl_dvm_5150_cfg = {
461 .set_hw_params = iwl5150_hw_set_hw_params,
462 .set_channel_switch = iwl5000_hw_channel_switch,
463 .temperature = iwl5150_temperature,
464 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
465 .chain_noise_scale = 1000,
466 .no_idle_support = true,
467 .no_xtal_calib = true,
468 };
469
470
471
472 /*
473 * 6000 series
474 * ===========
475 */
476
iwl6000_set_ct_threshold(struct iwl_priv * priv)477 static void iwl6000_set_ct_threshold(struct iwl_priv *priv)
478 {
479 /* want Celsius */
480 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
481 priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
482 }
483
484 /* NIC configuration for 6000 series */
iwl6000_nic_config(struct iwl_priv * priv)485 static void iwl6000_nic_config(struct iwl_priv *priv)
486 {
487 switch (priv->trans->trans_cfg->device_family) {
488 case IWL_DEVICE_FAMILY_6005:
489 case IWL_DEVICE_FAMILY_6030:
490 case IWL_DEVICE_FAMILY_6000:
491 break;
492 case IWL_DEVICE_FAMILY_6000i:
493 /* 2x2 IPA phy type */
494 iwl_write32(priv->trans, CSR_GP_DRIVER_REG,
495 CSR_GP_DRIVER_REG_BIT_RADIO_SKU_2x2_IPA);
496 break;
497 case IWL_DEVICE_FAMILY_6050:
498 /* Indicate calibration version to uCode. */
499 if (priv->nvm_data->calib_version >= 6)
500 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG,
501 CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6);
502 break;
503 case IWL_DEVICE_FAMILY_6150:
504 /* Indicate calibration version to uCode. */
505 if (priv->nvm_data->calib_version >= 6)
506 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG,
507 CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6);
508 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG,
509 CSR_GP_DRIVER_REG_BIT_6050_1x2);
510 break;
511 default:
512 WARN_ON(1);
513 }
514 }
515
516 static const struct iwl_sensitivity_ranges iwl6000_sensitivity = {
517 .min_nrg_cck = 110,
518 .auto_corr_min_ofdm = 80,
519 .auto_corr_min_ofdm_mrc = 128,
520 .auto_corr_min_ofdm_x1 = 105,
521 .auto_corr_min_ofdm_mrc_x1 = 192,
522
523 .auto_corr_max_ofdm = 145,
524 .auto_corr_max_ofdm_mrc = 232,
525 .auto_corr_max_ofdm_x1 = 110,
526 .auto_corr_max_ofdm_mrc_x1 = 232,
527
528 .auto_corr_min_cck = 125,
529 .auto_corr_max_cck = 175,
530 .auto_corr_min_cck_mrc = 160,
531 .auto_corr_max_cck_mrc = 310,
532 .nrg_th_cck = 110,
533 .nrg_th_ofdm = 110,
534
535 .barker_corr_th_min = 190,
536 .barker_corr_th_min_mrc = 336,
537 .nrg_th_cca = 62,
538 };
539
iwl6000_hw_set_hw_params(struct iwl_priv * priv)540 static void iwl6000_hw_set_hw_params(struct iwl_priv *priv)
541 {
542 iwl6000_set_ct_threshold(priv);
543
544 /* Set initial sensitivity parameters */
545 priv->hw_params.sens = &iwl6000_sensitivity;
546
547 }
548
iwl6000_hw_channel_switch(struct iwl_priv * priv,struct ieee80211_channel_switch * ch_switch)549 static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
550 struct ieee80211_channel_switch *ch_switch)
551 {
552 /*
553 * MULTI-FIXME
554 * See iwlagn_mac_channel_switch.
555 */
556 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
557 struct iwl6000_channel_switch_cmd *cmd;
558 u32 switch_time_in_usec, ucode_switch_time;
559 u16 ch;
560 u32 tsf_low;
561 u8 switch_count;
562 u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
563 struct ieee80211_vif *vif = ctx->vif;
564 struct iwl_host_cmd hcmd = {
565 .id = REPLY_CHANNEL_SWITCH,
566 .len = { sizeof(*cmd), },
567 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
568 };
569 int err;
570
571 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
572 if (!cmd)
573 return -ENOMEM;
574
575 hcmd.data[0] = cmd;
576
577 cmd->band = priv->band == NL80211_BAND_2GHZ;
578 ch = ch_switch->chandef.chan->hw_value;
579 IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
580 ctx->active.channel, ch);
581 cmd->channel = cpu_to_le16(ch);
582 cmd->rxon_flags = ctx->staging.flags;
583 cmd->rxon_filter_flags = ctx->staging.filter_flags;
584 switch_count = ch_switch->count;
585 tsf_low = ch_switch->timestamp & 0x0ffffffff;
586 /*
587 * calculate the ucode channel switch time
588 * adding TSF as one of the factor for when to switch
589 */
590 if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
591 if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
592 beacon_interval)) {
593 switch_count -= (priv->ucode_beacon_time -
594 tsf_low) / beacon_interval;
595 } else
596 switch_count = 0;
597 }
598 if (switch_count <= 1)
599 cmd->switch_time = cpu_to_le32(priv->ucode_beacon_time);
600 else {
601 switch_time_in_usec =
602 vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
603 ucode_switch_time = iwl_usecs_to_beacons(priv,
604 switch_time_in_usec,
605 beacon_interval);
606 cmd->switch_time = iwl_add_beacon_time(priv,
607 priv->ucode_beacon_time,
608 ucode_switch_time,
609 beacon_interval);
610 }
611 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
612 cmd->switch_time);
613 cmd->expect_beacon =
614 ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
615
616 err = iwl_dvm_send_cmd(priv, &hcmd);
617 kfree(cmd);
618 return err;
619 }
620
621 const struct iwl_dvm_cfg iwl_dvm_6000_cfg = {
622 .set_hw_params = iwl6000_hw_set_hw_params,
623 .set_channel_switch = iwl6000_hw_channel_switch,
624 .nic_config = iwl6000_nic_config,
625 .temperature = iwlagn_temperature,
626 .adv_thermal_throttle = true,
627 .support_ct_kill_exit = true,
628 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
629 .chain_noise_scale = 1000,
630 };
631
632 const struct iwl_dvm_cfg iwl_dvm_6005_cfg = {
633 .set_hw_params = iwl6000_hw_set_hw_params,
634 .set_channel_switch = iwl6000_hw_channel_switch,
635 .nic_config = iwl6000_nic_config,
636 .temperature = iwlagn_temperature,
637 .adv_thermal_throttle = true,
638 .support_ct_kill_exit = true,
639 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
640 .chain_noise_scale = 1000,
641 .need_temp_offset_calib = true,
642 };
643
644 const struct iwl_dvm_cfg iwl_dvm_6050_cfg = {
645 .set_hw_params = iwl6000_hw_set_hw_params,
646 .set_channel_switch = iwl6000_hw_channel_switch,
647 .nic_config = iwl6000_nic_config,
648 .temperature = iwlagn_temperature,
649 .adv_thermal_throttle = true,
650 .support_ct_kill_exit = true,
651 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
652 .chain_noise_scale = 1500,
653 };
654
655 static const struct iwl_dvm_bt_params iwl6000_bt_params = {
656 /* Due to bluetooth, we transmit 2.4 GHz probes only on antenna A */
657 .advanced_bt_coexist = true,
658 .agg_time_limit = BT_AGG_THRESHOLD_DEF,
659 .bt_init_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_NONE,
660 .bt_prio_boost = IWLAGN_BT_PRIO_BOOST_DEFAULT,
661 .bt_sco_disable = true,
662 };
663
664 const struct iwl_dvm_cfg iwl_dvm_6030_cfg = {
665 .set_hw_params = iwl6000_hw_set_hw_params,
666 .set_channel_switch = iwl6000_hw_channel_switch,
667 .nic_config = iwl6000_nic_config,
668 .temperature = iwlagn_temperature,
669 .adv_thermal_throttle = true,
670 .support_ct_kill_exit = true,
671 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
672 .chain_noise_scale = 1000,
673 .bt_params = &iwl6000_bt_params,
674 .need_temp_offset_calib = true,
675 .adv_pm = true,
676 };
677