Linux Audio

Check our new training course

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