Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Aug 2013 12:22:41 +0200
From:      "Cedric GROSS" <cg@cgross.info>
To:        "'Adrian Chadd'" <adrian@freebsd.org>
Cc:        freebsd-wireless@freebsd.org
Subject:   RE: iwn(4) changes, net80211(4) changes, things may be odd
Message-ID:  <000301ce967c$b8092040$281b60c0$@info>
In-Reply-To: <CAJ-Vmo=xn5iTQsiHLhAxypSKROD7JnoUT8A8Mhof0%2BZoqbW-rQ@mail.gmail.com>
References:  <CAJ-Vmo=xn5iTQsiHLhAxypSKROD7JnoUT8A8Mhof0%2BZoqbW-rQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

------=_NextPart_000_0004_01CE968D.7B91F040
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

> De=A0: adrian.chadd@gmail.com [mailto:adrian.chadd@gmail.com] De la =
part
> de Adrian Chadd
> Envoy=E9=A0: dimanche 11 ao=FBt 2013 04:04
> =C0=A0: freebsd-wireless@freebsd.org; Cedric GROSS
> Objet=A0: iwn(4) changes, net80211(4) changes, things may be odd
>=20
>=20
> Cedric - would you please update your git repository and post an
> updated diff to -wireless?
>=20
Yep. Here is the updated diff.

> -adrian

Cedric

------=_NextPart_000_0004_01CE968D.7B91F040
Content-Type: application/octet-stream;
	name="full_a5.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="full_a5.patch"

Index: sys/dev/iwn/if_iwn.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/dev/iwn/if_iwn.c	(revision 254210)=0A=
+++ sys/dev/iwn/if_iwn.c	(working copy)=0A=
@@ -119,6 +119,8 @@=0A=
 	{ 0x8086, IWN_DID_5x50_2, "Intel WiMAX/WiFi Link 5350"			},=0A=
 	{ 0x8086, IWN_DID_5x50_3, "Intel WiMAX/WiFi Link 5150"			},=0A=
 	{ 0x8086, IWN_DID_5x50_4, "Intel WiMAX/WiFi Link 5150"			},=0A=
+	{ 0x8086, IWN_DID_6035_1, "Centrino Advanced-N 6235"		},=0A=
+	{ 0x8086, IWN_DID_6035_2, "Centrino Advanced-N 6235"		},=0A=
 	{ 0, 0, NULL }=0A=
 };=0A=
 =0A=
@@ -235,7 +237,8 @@=0A=
 static int	iwn_add_broadcast_node(struct iwn_softc *, int);=0A=
 static int	iwn_updateedca(struct ieee80211com *);=0A=
 static void	iwn_update_mcast(struct ifnet *);=0A=
-static void	iwn_set_led(struct iwn_softc *, uint8_t, uint8_t, uint8_t);=0A=
+static void	iwn_set_led(struct iwn_softc *, uint8_t, uint8_t, uint8_t,=0A=
+		    uint8_t);=0A=
 static int	iwn_set_critical_temp(struct iwn_softc *);=0A=
 static int	iwn_set_timing(struct iwn_softc *, struct ieee80211_node *);=0A=
 static void	iwn4965_power_calibration(struct iwn_softc *, int);=0A=
@@ -261,7 +264,7 @@=0A=
 static int	iwn_set_pslevel(struct iwn_softc *, int, int, int);=0A=
 static int	iwn_send_btcoex(struct iwn_softc *);=0A=
 static int	iwn_send_advanced_btcoex(struct iwn_softc *);=0A=
-static int	iwn5000_runtime_calib(struct iwn_softc *);=0A=
+//static int	iwn5000_runtime_calib(struct iwn_softc *);=0A=
 static int	iwn_config(struct iwn_softc *);=0A=
 static uint8_t	*ieee80211_add_ssid(uint8_t *, const uint8_t *, u_int);=0A=
 static int	iwn_scan(struct iwn_softc *);=0A=
@@ -292,6 +295,7 @@=0A=
 static int	iwn5000_send_wimax_coex(struct iwn_softc *);=0A=
 static int	iwn5000_crystal_calib(struct iwn_softc *);=0A=
 static int	iwn5000_temp_offset_calib(struct iwn_softc *);=0A=
+static int	iwn5000_temp_offset_calibv2(struct iwn_softc *);=0A=
 static int	iwn4965_post_alive(struct iwn_softc *);=0A=
 static int	iwn5000_post_alive(struct iwn_softc *);=0A=
 static int	iwn4965_load_bootcode(struct iwn_softc *, const uint8_t *,=0A=
@@ -330,6 +334,21 @@=0A=
 static char	*iwn_get_csr_string(int);=0A=
 static void	iwn_debug_register(struct iwn_softc *);=0A=
 #endif=0A=
+static int iwn_config_specific(struct iwn_softc *,uint16_t);=0A=
+static int iwn_set_statistics_request(struct iwn_softc *,bool ,bool =
,int);=0A=
+static int iwn_cfg_ucode_post_alive(struct iwn_softc *);=0A=
+static int iwn_iv_reset(struct ieee80211vap *, u_long);=0A=
+static int iwn_newstate_u1(struct ieee80211vap *, enum ieee80211_state =
, int);=0A=
+static int iwn_auth_u1(struct iwn_softc *, struct ieee80211vap *);=0A=
+static int iwn_run_u1(struct iwn_softc *, struct ieee80211vap *);=0A=
+static int iwn_set_timing_u1(struct iwn_softc *);=0A=
+static int iwn_config_u1(struct iwn_softc *);=0A=
+static int iwn_set_pan_params(struct iwn_softc *);=0A=
+static int iwn_updateedca_u1(struct ieee80211com *);=0A=
+static int iwn_add_broadcast_node_u1(struct iwn_softc *, int);=0A=
+static uint16_t iwn_get_active_dwell(struct iwn_softc *, struct =
ieee80211_channel *);=0A=
+static uint16_t iwn_get_passive_dwell(struct iwn_softc *, struct =
ieee80211_channel *);=0A=
+static void iwn_led_pattern(struct iwn_softc *);=0A=
 =0A=
 #ifdef	IWN_DEBUG=0A=
 enum {=0A=
@@ -376,6 +395,7 @@=0A=
 	case IWN_RX_PHY:		return "RX_PHY";=0A=
 	case IWN_MPDU_RX_DONE:		return "MPDU_RX_DONE";=0A=
 	case IWN_RX_DONE:		return "RX_DONE";=0A=
+	case IWN_TEMP_NOTIFICATION: return "TEMPERATURE_NOTIFICATION";=0A=
 =0A=
 	/* Command Notifications */=0A=
 	case IWN_CMD_RXON:		return "IWN_CMD_RXON";=0A=
@@ -398,6 +418,19 @@=0A=
 	case IWN_CMD_SET_CRITICAL_TEMP:	return "IWN_CMD_SET_CRITICAL_TEMP";=0A=
 	case IWN_CMD_SET_SENSITIVITY:	return "IWN_CMD_SET_SENSITIVITY";=0A=
 	case IWN_CMD_PHY_CALIB:		return "IWN_CMD_PHY_CALIB";=0A=
+	case IWN_CMD_BT_COEX_PRIOTABLE:	return "IWN_CMD_BT_COEX_PRIOTABLE";=0A=
+	case IWN_CMD_BT_COEX_PROT:	return "IWN_CMD_BT_COEX_PROT";=0A=
+	case IWN_CMD_BT_COEX_NOTIF:	return "IWN_CMD_BT_COEX_NOTIF";=0A=
+		/* PAN commands */=0A=
+	case IWN_CMD_WIPAN_PARAMS:	return "IWN_CMD_WIPAN_PARAMS";=0A=
+	case IWN_CMD_WIPAN_RXON:	return "IWN_CMD_WIPAN_RXON";=0A=
+	case IWN_CMD_WIPAN_RXON_TIMING:	return "IWN_CMD_WIPAN_RXON_TIMING";=0A=
+	case IWN_CMD_WIPAN_RXON_ASSOC:	return "IWN_CMD_WIPAN_RXON_ASSOC";=0A=
+	case IWN_CMD_WIPAN_QOS_PARAM:	return "IWN_CMD_WIPAN_QOS_PARAM";=0A=
+	case IWN_CMD_WIPAN_WEPKEY:	return "IWN_CMD_WIPAN_WEPKEY";=0A=
+	case IWN_CMD_WIPAN_P2P_CHANNEL_SWITCH:	return =
"IWN_CMD_WIPAN_P2P_CHANNEL_SWITCH";=0A=
+	case IWN_CMD_WIPAN_NOA_NOTIFICATION:	return =
"IWN_CMD_WIPAN_NOA_NOTIFICATION";=0A=
+	case IWN_CMD_WIPAN_DEACTIVATION_COMPLETE:	return =
"IWN_CMD_WIPAN_DEACTIVATION_COMPLETE";=0A=
 	}=0A=
 	return "UNKNOWN INTR NOTIF/CMD";=0A=
 }=0A=
@@ -456,6 +489,9 @@=0A=
 	int i, error, result;=0A=
 	uint8_t macaddr[IEEE80211_ADDR_LEN];=0A=
 =0A=
+	sc->desired_pwrsave_level =3D IWN_POWERSAVE_LVL_DEFAULT;=0A=
+	sc->current_pwrsave_level =3D -1;  /* signifies uninitialized */=0A=
+=0A=
 	sc->sc_dev =3D dev;=0A=
 =0A=
 #ifdef	IWN_DEBUG=0A=
@@ -615,6 +651,11 @@=0A=
 		| IEEE80211_C_WME		/* WME */=0A=
 		| IEEE80211_C_PMGT		/* Station-side power mgmt */=0A=
 		;=0A=
+	if (sc->base_params->support_hostap) {=0A=
+		ic->ic_caps |=3D IEEE80211_C_HOSTAP ;/* HOSTAP mode  supported  */=0A=
+	} else {=0A=
+		ic->ic_caps &=3D ~ IEEE80211_C_HOSTAP ; /* HOSTAP mode not supported =
*/=0A=
+	}=0A=
 =0A=
 	/* Read MAC address, channels, etc from EEPROM. */=0A=
 	if ((error =3D iwn_read_eeprom(sc, macaddr)) !=3D 0) {=0A=
@@ -712,10 +753,17 @@=0A=
 	ic->ic_scan_mindwell =3D iwn_scan_mindwell;=0A=
 	ic->ic_setregdomain =3D iwn_setregdomain;=0A=
 =0A=
+	sc->sc_led.led_cur_mode =3D IWN_LED_STATIC_OFF;=0A=
+	sc->sc_led.led_cur_tpt =3D 0;=0A=
+	sc->sc_led.led_last_tpt =3D 0;=0A=
+	sc->sc_led.led_cur_time =3D 0;=0A=
+	sc->sc_led.led_last_time =3D 0;=0A=
+=0A=
 	iwn_radiotap_attach(sc);=0A=
 =0A=
 	callout_init_mtx(&sc->calib_to, &sc->sc_mtx, 0);=0A=
 	callout_init_mtx(&sc->watchdog_to, &sc->sc_mtx, 0);=0A=
+	callout_init_mtx(&sc->ct_kill_exit_to, &sc->sc_mtx, 0);=0A=
 	TASK_INIT(&sc->sc_reinit_task, 0, iwn_hw_reset, sc);=0A=
 	TASK_INIT(&sc->sc_radioon_task, 0, iwn_radio_on, sc);=0A=
 	TASK_INIT(&sc->sc_radiooff_task, 0, iwn_radio_off, sc);=0A=
@@ -732,6 +780,11 @@=0A=
 		    error);=0A=
 		goto fail;=0A=
 	}=0A=
+	/* update ic->ic_flags to the default power save mode */=0A=
+	if (IWN_POWERSAVE_LVL_DEFAULT !=3D IWN_POWERSAVE_LVL_NONE)=0A=
+		ic->ic_flags |=3D IEEE80211_F_PMGTON;=0A=
+	else=0A=
+		ic->ic_flags &=3D ~IEEE80211_F_PMGTON;=0A=
 =0A=
 	if (bootverbose)=0A=
 		ieee80211_announce(ic);=0A=
@@ -778,6 +831,7 @@=0A=
 	/* Override chains masks, ROM is known to be broken. */=0A=
 	sc->txchainmask =3D IWN_ANT_AB;=0A=
 	sc->rxchainmask =3D IWN_ANT_ABC;=0A=
+	sc->base_params =3D &iwn_default_base_params; /* !! TODO : Define =
something may be more specific */=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "%s: end\n",__func__);=0A=
 =0A=
@@ -818,59 +872,7 @@=0A=
 	sc->reset_noise_gain =3D IWN5000_PHY_CALIB_RESET_NOISE_GAIN;=0A=
 	sc->noise_gain =3D IWN5000_PHY_CALIB_NOISE_GAIN;=0A=
 =0A=
-	switch (sc->hw_type) {=0A=
-	case IWN_HW_REV_TYPE_5100:=0A=
-		sc->limits =3D &iwn5000_sensitivity_limits;=0A=
-		sc->fwname =3D "iwn5000fw";=0A=
-		/* Override chains masks, ROM is known to be broken. */=0A=
-		sc->txchainmask =3D IWN_ANT_B;=0A=
-		sc->rxchainmask =3D IWN_ANT_AB;=0A=
-		break;=0A=
-	case IWN_HW_REV_TYPE_5150:=0A=
-		sc->limits =3D &iwn5150_sensitivity_limits;=0A=
-		sc->fwname =3D "iwn5150fw";=0A=
-		break;=0A=
-	case IWN_HW_REV_TYPE_5300:=0A=
-	case IWN_HW_REV_TYPE_5350:=0A=
-		sc->limits =3D &iwn5000_sensitivity_limits;=0A=
-		sc->fwname =3D "iwn5000fw";=0A=
-		break;=0A=
-	case IWN_HW_REV_TYPE_1000:=0A=
-		sc->limits =3D &iwn1000_sensitivity_limits;=0A=
-		sc->fwname =3D "iwn1000fw";=0A=
-		break;=0A=
-	case IWN_HW_REV_TYPE_6000:=0A=
-		sc->limits =3D &iwn6000_sensitivity_limits;=0A=
-		sc->fwname =3D "iwn6000fw";=0A=
-		if (pid =3D=3D 0x422c || pid =3D=3D 0x4239) {=0A=
-			sc->sc_flags |=3D IWN_FLAG_INTERNAL_PA;=0A=
-			/* Override chains masks, ROM is known to be broken. */=0A=
-			sc->txchainmask =3D IWN_ANT_BC;=0A=
-			sc->rxchainmask =3D IWN_ANT_BC;=0A=
-		}=0A=
-		break;=0A=
-	case IWN_HW_REV_TYPE_6050:=0A=
-		sc->limits =3D &iwn6000_sensitivity_limits;=0A=
-		sc->fwname =3D "iwn6050fw";=0A=
-		/* Override chains masks, ROM is known to be broken. */=0A=
-		sc->txchainmask =3D IWN_ANT_AB;=0A=
-		sc->rxchainmask =3D IWN_ANT_AB;=0A=
-		break;=0A=
-	case IWN_HW_REV_TYPE_6005:=0A=
-		sc->limits =3D &iwn6000_sensitivity_limits;=0A=
-		if (pid !=3D 0x0082 && pid !=3D 0x0085) {=0A=
-			sc->fwname =3D "iwn6000g2bfw";=0A=
-			sc->sc_flags |=3D IWN_FLAG_ADV_BTCOEX;=0A=
-		} else=0A=
-			sc->fwname =3D "iwn6000g2afw";=0A=
-		break;=0A=
-	default:=0A=
-		device_printf(sc->sc_dev, "adapter type %d not supported\n",=0A=
-		    sc->hw_type);=0A=
-		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end in error\n",__func__);=0A=
-		return ENOTSUP;=0A=
-	}=0A=
-	return 0;=0A=
+	return iwn_config_specific(sc,pid);=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -914,24 +916,50 @@=0A=
 	uint8_t mac1[IEEE80211_ADDR_LEN];=0A=
 	struct iwn_softc *sc =3D ic->ic_ifp->if_softc;=0A=
 =0A=
-	if (!TAILQ_EMPTY(&ic->ic_vaps))		/* only one at a time */=0A=
-		return NULL;=0A=
+	if (sc->base_params->no_multi_vaps) {=0A=
+		if (!TAILQ_EMPTY(&ic->ic_vaps))		/* only one at a time */=0A=
+			return NULL;=0A=
+	}=0A=
 =0A=
 	IEEE80211_ADDR_COPY(mac1, mac);=0A=
 =0A=
+	if(unit =3D=3D 1) {=0A=
+		if(!(sc->sc_flags & IWN_FLAG_PAN_SUPPORT))=0A=
+			return NULL;=0A=
+		mac1[5] +=3D 1;=0A=
+		sc->ctx	=3D IWN_RXON_PAN_CTX;=0A=
+	}=0A=
+=0A=
 	ivp =3D (struct iwn_vap *) malloc(sizeof(struct iwn_vap),=0A=
 	    M_80211_VAP, M_NOWAIT | M_ZERO);=0A=
 	if (ivp =3D=3D NULL)=0A=
 		return NULL;=0A=
 	vap =3D &ivp->iv_vap;=0A=
+=0A=
 	ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac1);=0A=
-	ivp->ctx =3D IWN_RXON_BSS_CTX;=0A=
-	IEEE80211_ADDR_COPY(ivp->macaddr, mac1);=0A=
+=0A=
+	if(unit =3D=3D 1) {=0A=
+		ivp->ctx =3D IWN_RXON_PAN_CTX;=0A=
+		ivp->iv_newstate =3D vap->iv_newstate;=0A=
+		vap->iv_newstate =3D iwn_newstate_u1;=0A=
+		IEEE80211_ADDR_COPY(ivp->macaddr, mac1);=0A=
+		memset(&sc->rx_on[IWN_RXON_PAN_CTX], 0, sizeof (struct iwn_rxon));=0A=
+		memcpy(&sc->rx_on[IWN_RXON_PAN_CTX], &sc->rx_on[IWN_RXON_BSS_CTX], =
sc->rxonsz);=0A=
+		IEEE80211_ADDR_COPY(sc->rx_on[IWN_RXON_PAN_CTX].myaddr, mac1);=0A=
+		sc->rx_on[IWN_RXON_PAN_CTX].mode =3D IWN_MODE_2STA;=0A=
+		sc->ivap[IWN_RXON_PAN_CTX] =3D vap;=0A=
+	}=0A=
+	else {=0A=
+		ivp->ctx =3D IWN_RXON_BSS_CTX;=0A=
+		IEEE80211_ADDR_COPY(ivp->macaddr, mac1);=0A=
+		ivp->iv_newstate =3D vap->iv_newstate;=0A=
+		vap->iv_newstate =3D iwn_newstate;=0A=
+		sc->ivap[IWN_RXON_BSS_CTX] =3D vap;=0A=
+	}=0A=
+=0A=
 	vap->iv_bmissthreshold =3D 10;		/* override default */=0A=
-	/* Override with driver methods. */=0A=
-	ivp->iv_newstate =3D vap->iv_newstate;=0A=
-	vap->iv_newstate =3D iwn_newstate;=0A=
-	sc->ivap[IWN_RXON_BSS_CTX] =3D vap;=0A=
+	/* handler for setting change (partial 're'set) requested via ioctl */=0A=
+	vap->iv_reset =3D iwn_iv_reset;=0A=
 =0A=
 	ieee80211_ratectl_init(vap);=0A=
 	/* Complete setup. */=0A=
@@ -944,7 +972,11 @@=0A=
 iwn_vap_delete(struct ieee80211vap *vap)=0A=
 {=0A=
 	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+	struct iwn_softc *sc =3D vap->iv_ic->ic_ifp->if_softc;=0A=
 =0A=
+	if(ivp->ctx =3D=3D IWN_RXON_PAN_CTX)=0A=
+		sc->ctx =3D 0;=0A=
+=0A=
 	ieee80211_ratectl_deinit(vap);=0A=
 	ieee80211_vap_detach(vap);=0A=
 	free(ivp, M_80211_VAP);=0A=
@@ -969,6 +1001,7 @@=0A=
 =0A=
 		iwn_stop(sc);=0A=
 		callout_drain(&sc->watchdog_to);=0A=
+		callout_drain(&sc->ct_kill_exit_to);=0A=
 		callout_drain(&sc->calib_to);=0A=
 		ieee80211_ifdetach(ic);=0A=
 	}=0A=
@@ -1016,8 +1049,13 @@=0A=
 {=0A=
 	struct iwn_softc *sc =3D device_get_softc(dev);=0A=
 	struct ieee80211com *ic =3D sc->sc_ifp->if_l2com;=0A=
+	struct ieee80211vap *vap =3D TAILQ_FIRST(&ic->ic_vaps);=0A=
 =0A=
 	ieee80211_suspend_all(ic);=0A=
+	iwn_stop(sc);=0A=
+	if (vap !=3D NULL)=0A=
+		ieee80211_stop(vap);=0A=
+=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -1025,12 +1063,22 @@=0A=
 iwn_resume(device_t dev)=0A=
 {=0A=
 	struct iwn_softc *sc =3D device_get_softc(dev);=0A=
-	struct ieee80211com *ic =3D sc->sc_ifp->if_l2com;=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	struct ieee80211vap *vap =3D TAILQ_FIRST(&ic->ic_vaps);=0A=
 =0A=
 	/* Clear device-specific "PCI retry timeout" register (41h). */=0A=
 	pci_write_config(dev, 0x41, 0, 1);=0A=
 =0A=
 	ieee80211_resume_all(ic);=0A=
+	if (ifp->if_flags & IFF_UP) {=0A=
+		iwn_init(sc);=0A=
+		if (vap !=3D NULL)=0A=
+			ieee80211_init(vap);=0A=
+		if (ifp->if_drv_flags & IFF_DRV_RUNNING)=0A=
+			iwn_start(ifp);=0A=
+	}=0A=
+=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -1192,7 +1240,7 @@=0A=
 	iwn_nic_unlock(sc);=0A=
 =0A=
 	/* Set auto clock gate disable bit for HW with OTP shadow RAM. */=0A=
-	if (sc->hw_type !=3D IWN_HW_REV_TYPE_1000) {=0A=
+	if (sc->base_params->shadow_ram_support) {=0A=
 		IWN_SETBITS(sc, IWN_DBG_LINK_PWR_MGMT,=0A=
 		    IWN_RESET_LINK_PWR_MGMT_DIS);=0A=
 	}=0A=
@@ -1205,11 +1253,11 @@=0A=
 	 * Find the block before last block (contains the EEPROM image)=0A=
 	 * for HW without OTP shadow RAM.=0A=
 	 */=0A=
-	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_1000) {=0A=
+	if (!(sc->base_params->shadow_ram_support)) {=0A=
 		/* Switch to absolute addressing mode. */=0A=
 		IWN_CLRBITS(sc, IWN_OTP_GP, IWN_OTP_GP_RELATIVE_ACCESS);=0A=
 		base =3D prev =3D 0;=0A=
-		for (count =3D 0; count < IWN1000_OTP_NBLOCKS; count++) {=0A=
+		for (count =3D 0; count < sc->base_params->max_ll_items; count++) {=0A=
 			error =3D iwn_read_prom_data(sc, base, &next, 2);=0A=
 			if (error !=3D 0)=0A=
 				return error;=0A=
@@ -1218,7 +1266,7 @@=0A=
 			prev =3D base;=0A=
 			base =3D le16toh(next);=0A=
 		}=0A=
-		if (count =3D=3D 0 || count =3D=3D IWN1000_OTP_NBLOCKS)=0A=
+		if (count =3D=3D 0 || count =3D=3D sc->base_params->max_ll_items)=0A=
 			return EIO;=0A=
 		/* Skip "next" word. */=0A=
 		sc->prom_base =3D prev + 1;=0A=
@@ -1453,7 +1501,7 @@=0A=
 			goto fail;=0A=
 		}=0A=
 =0A=
-		data->m =3D m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR,=0A=
+		data->m =3D m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR,=0A=
 		    IWN_RBUF_SIZE);=0A=
 		if (data->m =3D=3D NULL) {=0A=
 			device_printf(sc->sc_dev,=0A=
@@ -1854,7 +1902,7 @@=0A=
 {=0A=
 	struct iwn5000_eeprom_calib_hdr hdr;=0A=
 	int32_t volt;=0A=
-	uint32_t base, addr;=0A=
+	uint32_t base;=0A=
 	uint16_t val;=0A=
 	int i;=0A=
 =0A=
@@ -1867,16 +1915,12 @@=0A=
 	    sc->eeprom_domain, 4);=0A=
 =0A=
 	/* Read the list of authorized channels (20MHz ones only). */=0A=
-	for (i =3D 0; i < 7; i++) {=0A=
-		if (sc->hw_type >=3D IWN_HW_REV_TYPE_6000)=0A=
-			addr =3D base + iwn6000_regulatory_bands[i];=0A=
-		else=0A=
-			addr =3D base + iwn5000_regulatory_bands[i];=0A=
-		iwn_read_eeprom_channels(sc, i, addr);=0A=
+	for (i =3D 0; i < (IWN_NBANDS - 1); i++) {=0A=
+		iwn_read_eeprom_channels(sc, i, =
base+sc->base_params->regulatory_bands[i]);=0A=
 	}=0A=
 =0A=
 	/* Read enhanced TX power information for 6000 Series. */=0A=
-	if (sc->hw_type >=3D IWN_HW_REV_TYPE_6000)=0A=
+	if (sc->base_params->enhanced_TX_power)=0A=
 		iwn_read_eeprom_enhinfo(sc);=0A=
 =0A=
 	iwn_read_prom_data(sc, IWN5000_EEPROM_CAL, &val, 2);=0A=
@@ -1887,6 +1931,14 @@=0A=
 	    hdr.version, hdr.pa_type, le16toh(hdr.volt));=0A=
 	sc->calib_ver =3D hdr.version;=0A=
 =0A=
+	if (sc->base_params->calib_need & =
IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2) {=0A=
+		sc->eeprom_voltage =3D le16toh(hdr.volt);=0A=
+		iwn_read_prom_data(sc, base + IWN5000_EEPROM_TEMP, &val, 2);=0A=
+		sc->eeprom_temp_high=3Dle16toh(val);=0A=
+		iwn_read_prom_data(sc, base + IWN5000_EEPROM_VOLT, &val, 2);=0A=
+		sc->eeprom_temp =3D le16toh(val);=0A=
+	}=0A=
+=0A=
 	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_5150) {=0A=
 		/* Compute temperature offset. */=0A=
 		iwn_read_prom_data(sc, base + IWN5000_EEPROM_TEMP, &val, 2);=0A=
@@ -2423,12 +2475,7 @@=0A=
 =0A=
 	/* Force automatic TX power calibration every 60 secs. */=0A=
 	if (++sc->calib_cnt >=3D 120) {=0A=
-		uint32_t flags =3D 0;=0A=
-=0A=
-		DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s\n",=0A=
-		    "sending request for statistics");=0A=
-		(void)iwn_cmd(sc, IWN_CMD_GET_STATISTICS, &flags,=0A=
-		    sizeof flags, 1);=0A=
+		iwn_set_statistics_request(sc,true,false,1);=0A=
 		sc->calib_cnt =3D 0;=0A=
 	}=0A=
 	callout_reset(&sc->calib_to, msecs_to_ticks(500), iwn_calib_timeout,=0A=
@@ -2521,7 +2568,7 @@=0A=
 		return;=0A=
 	}=0A=
 =0A=
-	m1 =3D m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, IWN_RBUF_SIZE);=0A=
+	m1 =3D m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, IWN_RBUF_SIZE);=0A=
 	if (m1 =3D=3D NULL) {=0A=
 		DPRINTF(sc, IWN_DEBUG_ANY, "%s: no mbuf to restock ring\n",=0A=
 		    __func__);=0A=
@@ -2581,6 +2628,7 @@=0A=
 		tap->wr_dbm_antsignal =3D (int8_t)rssi;=0A=
 		tap->wr_dbm_antnoise =3D (int8_t)nf;=0A=
 		tap->wr_tsft =3D stat->tstamp;=0A=
+		/* XXX rate contain also antenna information */=0A=
 		switch (stat->rate) {=0A=
 		/* CCK rates. */=0A=
 		case  10: tap->wr_rate =3D   2; break;=0A=
@@ -2597,7 +2645,10 @@=0A=
 		case 0x1: tap->wr_rate =3D  96; break;=0A=
 		case 0x3: tap->wr_rate =3D 108; break;=0A=
 		/* Unknown rate: should not happen. */=0A=
-		default:  tap->wr_rate =3D   0;=0A=
+		default:  =0A=
+			tap->wr_rate =3D   0;=0A=
+			DPRINTF(sc, IWN_DEBUG_RECV, =0A=
+			    "Rate found: 0x%08x and not translated\n", stat->rate);=0A=
 		}=0A=
 	}=0A=
 =0A=
@@ -2740,29 +2791,30 @@=0A=
 =0A=
 	switch (calib->code) {=0A=
 	case IWN5000_PHY_CALIB_DC:=0A=
-		if ((sc->sc_flags & IWN_FLAG_INTERNAL_PA) =3D=3D 0 &&=0A=
-		    (sc->hw_type =3D=3D IWN_HW_REV_TYPE_5150 ||=0A=
-		     sc->hw_type >=3D IWN_HW_REV_TYPE_6000) &&=0A=
-		     sc->hw_type !=3D IWN_HW_REV_TYPE_6050)=0A=
+		if (sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_DC)=0A=
 			idx =3D 0;=0A=
 		break;=0A=
 	case IWN5000_PHY_CALIB_LO:=0A=
-		idx =3D 1;=0A=
+		if (sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_LO)=0A=
+			idx =3D 1;=0A=
 		break;=0A=
 	case IWN5000_PHY_CALIB_TX_IQ:=0A=
-		idx =3D 2;=0A=
+		if (sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TX_IQ)=0A=
+			idx =3D 2;=0A=
 		break;=0A=
 	case IWN5000_PHY_CALIB_TX_IQ_PERIODIC:=0A=
-		if (sc->hw_type < IWN_HW_REV_TYPE_6000 &&=0A=
-		    sc->hw_type !=3D IWN_HW_REV_TYPE_5150)=0A=
+		if (sc->base_params->calib_need & =
IWN_FLG_NEED_PHY_CALIB_TX_IQ_PERIODIC)=0A=
 			idx =3D 3;=0A=
 		break;=0A=
 	case IWN5000_PHY_CALIB_BASE_BAND:=0A=
-		idx =3D 4;=0A=
+		if (sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_BASE_BAND)=0A=
+			idx =3D 4;=0A=
 		break;=0A=
 	}=0A=
-	if (idx =3D=3D -1)	/* Ignore other results. */=0A=
+	if (idx =3D=3D -1)	{	/* Ignore other results. */=0A=
+		DPRINTF(sc,IWN_DEBUG_CALIBRATE,"Ignoring calib result =
%d",calib->code);=0A=
 		return;=0A=
+	}=0A=
 =0A=
 	/* Save calibration result. */=0A=
 	if (sc->calibcmd[idx].buf !=3D NULL)=0A=
@@ -2778,6 +2830,7 @@=0A=
 	    "saving calibration result code=3D%d len=3D%d\n", calib->code, =
len);=0A=
 	sc->calibcmd[idx].len =3D len;=0A=
 	memcpy(sc->calibcmd[idx].buf, calib, len);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -2794,6 +2847,12 @@=0A=
 	struct ieee80211vap *vap =3D TAILQ_FIRST(&ic->ic_vaps);=0A=
 	struct iwn_calib_state *calib =3D &sc->calib;=0A=
 	struct iwn_stats *stats =3D (struct iwn_stats *)(desc + 1);=0A=
+	struct ieee80211_node *ni =3D vap->iv_bss;=0A=
+	struct ieee80211_nodestats ns =3D ni->ni_stats;=0A=
+	struct bintime bt;=0A=
+=0A=
+	struct ieee80211vap *vap1;=0A=
+=0A=
 	int temp;=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
@@ -2805,7 +2864,42 @@=0A=
 	    __func__);=0A=
 		return;=0A=
 	}=0A=
+	if(sc->ctx =3D=3D IWN_RXON_PAN_CTX) {=0A=
+		vap1 =3D sc->ivap[IWN_RXON_PAN_CTX];=0A=
+		/* Ignore statistics received during a scan. */=0A=
+		if (vap1->iv_state !=3D IEEE80211_S_RUN ||=0A=
+		    (ic->ic_flags & IEEE80211_F_SCAN))=0A=
+			return;=0A=
+	}=0A=
 =0A=
+	getbinuptime(&bt);=0A=
+	sc->sc_led.led_cur_time =3D bt.sec;=0A=
+	int time_diff =3D (sc->sc_led.led_cur_time - sc->sc_led.led_last_time);=0A=
+=0A=
+	if(time_diff >=3D 4) {=0A=
+		if(vap->iv_state =3D=3D IEEE80211_S_RUN) {=0A=
+			sc->sc_led.led_cur_bt =3D (ns.ns_rx_bytes + ns.ns_tx_bytes);=0A=
+			if(sc->sc_led.led_cur_bt < sc->sc_led.led_last_bt) {=0A=
+				sc->sc_led.led_cur_bt =3D 0;=0A=
+				sc->sc_led.led_last_bt =3D 0;=0A=
+			}=0A=
+			sc->sc_led.led_bt_diff =3D (sc->sc_led.led_cur_bt - =
sc->sc_led.led_last_bt);=0A=
+			sc->sc_led.led_last_bt =3D sc->sc_led.led_cur_bt;=0A=
+			sc->sc_led.led_cur_tpt =3D (sc->sc_led.led_bt_diff / time_diff);=0A=
+			sc->sc_led.led_last_time =3D sc->sc_led.led_cur_time;=0A=
+=0A=
+			if(sc->sc_led.led_cur_tpt > 0) {=0A=
+				sc->sc_led.led_cur_mode =3D IWN_LED_INT_BLINK;=0A=
+				iwn_led_pattern(sc);=0A=
+			} else {=0A=
+				sc->sc_led.led_cur_mode =3D IWN_LED_STATIC_ON;=0A=
+				iwn_set_led(sc, IWN_LED_LINK, 0, 1, IWN_LED_STATIC_ON);=0A=
+			}=0A=
+=0A=
+			sc->sc_led.led_last_tpt =3D sc->sc_led.led_cur_tpt;=0A=
+		}=0A=
+	}=0A=
+=0A=
 	bus_dmamap_sync(sc->rxq.data_dmat, data->map, BUS_DMASYNC_POSTREAD);=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s: received statistics, cmd %d\n",=0A=
@@ -2896,7 +2990,7 @@=0A=
 =0A=
 #ifdef notyet=0A=
 	/* Reset TX scheduler slot. */=0A=
-	iwn5000_reset_sched(sc, desc->qid & 0xf, desc->idx);=0A=
+	iwn5000_reset_sched(sc, desc->qid & IWN_RX_DESC_QID_MSK, desc->idx);=0A=
 #endif=0A=
 =0A=
 	bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTREAD);=0A=
@@ -2905,7 +2999,7 @@=0A=
 		    &stat->status);=0A=
 	} else {=0A=
 		iwn_tx_done(sc, desc, stat->ackfailcnt,=0A=
-		    le16toh(stat->status) & 0xff);=0A=
+		    le16toh(stat->status) & IWN_TX_STATUS_MSK);=0A=
 	}=0A=
 }=0A=
 =0A=
@@ -2917,11 +3011,16 @@=0A=
     uint8_t status)=0A=
 {=0A=
 	struct ifnet *ifp =3D sc->sc_ifp;=0A=
-	struct iwn_tx_ring *ring =3D &sc->txq[desc->qid & 0xf];=0A=
+	struct iwn_tx_ring *ring =3D &sc->txq[desc->qid & IWN_RX_DESC_QID_MSK];=0A=
 	struct iwn_tx_data *data =3D &ring->data[desc->idx];=0A=
+=0A=
+	struct iwn_tx_cmd *cmd;=0A=
+	struct iwn_cmd_data *tx;=0A=
+=0A=
 	struct mbuf *m;=0A=
 	struct ieee80211_node *ni;=0A=
 	struct ieee80211vap *vap;=0A=
+	struct ieee80211_frame *wh;=0A=
 =0A=
 	KASSERT(data->ni !=3D NULL, ("no node"));=0A=
 =0A=
@@ -2928,12 +3027,21 @@=0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 =0A=
 	/* Unmap and free mbuf. */=0A=
+	uint8_t ridx;=0A=
 	bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTWRITE);=0A=
 	bus_dmamap_unload(ring->data_dmat, data->map);=0A=
 	m =3D data->m, data->m =3D NULL;=0A=
 	ni =3D data->ni, data->ni =3D NULL;=0A=
+	uint8_t type;=0A=
 	vap =3D ni->ni_vap;=0A=
 =0A=
+	cmd =3D &ring->cmd[desc->idx];=0A=
+	tx =3D (struct iwn_cmd_data *)cmd->data;=0A=
+	wh =3D (struct ieee80211_frame *)(tx + 1);=0A=
+=0A=
+	struct ieee80211com *ic =3D ni->ni_ic;=0A=
+=0A=
+	type =3D wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;=0A=
 	if (m->m_flags & M_TXCB) {=0A=
 		/*=0A=
 		 * Channels marked for "radar" require traffic to be received=0A=
@@ -2957,6 +3065,7 @@=0A=
 			    (status & IWN_TX_FAIL) !=3D 0);=0A=
 	}=0A=
 =0A=
+	ridx =3D ic->ic_rt->rateCodeToIndex[ni->ni_txrate];=0A=
 	/*=0A=
 	 * Update rate control statistics for the node.=0A=
 	 */=0A=
@@ -2993,12 +3102,24 @@=0A=
 static void=0A=
 iwn_cmd_done(struct iwn_softc *sc, struct iwn_rx_desc *desc)=0A=
 {=0A=
-	struct iwn_tx_ring *ring =3D &sc->txq[4];=0A=
+	struct iwn_tx_ring *ring;=0A=
 	struct iwn_tx_data *data;=0A=
+	int cmd_queue_num;=0A=
 =0A=
-	if ((desc->qid & 0xf) !=3D 4)=0A=
+	if(sc->sc_flags & IWN_FLAG_PAN_SUPPORT)=0A=
+		cmd_queue_num =3D IWN_PAN_CMD_QUEUE;=0A=
+	else=0A=
+		cmd_queue_num =3D IWN_CMD_QUEUE_NUM;=0A=
+=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_CMD, "%s: qid: %d\n",=0A=
+	    __func__, (desc->qid & IWN_RX_DESC_QID_MSK));=0A=
+=0A=
+=0A=
+	if ((desc->qid & IWN_RX_DESC_QID_MSK) !=3D cmd_queue_num)=0A=
 		return;	/* Not a command ack. */=0A=
 =0A=
+	ring =3D &sc->txq[cmd_queue_num];=0A=
 	data =3D &ring->data[desc->idx];=0A=
 =0A=
 	/* If the command was mapped in an mbuf, free it. */=0A=
@@ -3133,7 +3254,9 @@=0A=
 	struct iwn_ops *ops =3D &sc->ops;=0A=
 	struct ifnet *ifp =3D sc->sc_ifp;=0A=
 	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
-	struct ieee80211vap *vap =3D TAILQ_FIRST(&ic->ic_vaps);=0A=
+	struct ieee80211_scan_state *ss =3D ic->ic_scan;=0A=
+	struct ieee80211vap *vapscan =3D ss->ss_vap;=0A=
+=0A=
 	uint16_t hw;=0A=
 =0A=
 	bus_dmamap_sync(sc->rxq.stat_dma.tag, sc->rxq.stat_dma.map,=0A=
@@ -3153,8 +3276,10 @@=0A=
 		    __func__, desc->qid & 0xf, desc->idx, desc->flags,=0A=
 		    desc->type, iwn_intr_str(desc->type),=0A=
 		    le16toh(desc->len));=0A=
-=0A=
-		if (!(desc->qid & 0x80))	/* Reply to a command. */=0A=
+		if (le16toh(desc->len) =3D=3D 8 && desc->qid =3D=3D 0)=0A=
+			DPRINTF(sc, IWN_DEBUG_RECV, "%s: strange inter values: 0x%08x\n",=0A=
+		    __func__,le32toh(desc->len));=0A=
+		if (!(desc->qid & IWN_UNSOLICITED_RX_NOTIF))	/* Reply to a command. */=0A=
 			iwn_cmd_done(sc, desc);=0A=
 =0A=
 		switch (desc->type) {=0A=
@@ -3188,6 +3313,10 @@=0A=
 			struct iwn_beacon_missed *miss =3D=0A=
 			    (struct iwn_beacon_missed *)(desc + 1);=0A=
 			int misses;=0A=
+			int iv_bmissthreshold;=0A=
+			int DoReinit =3D0 ;=0A=
+			struct ieee80211vap *vap0 =3D sc->ivap[IWN_RXON_BSS_CTX];=0A=
+			struct ieee80211vap *vap1 =3D sc->ivap[IWN_RXON_PAN_CTX];=0A=
 =0A=
 			bus_dmamap_sync(sc->rxq.data_dmat, data->map,=0A=
 			    BUS_DMASYNC_POSTREAD);=0A=
@@ -3194,17 +3323,31 @@=0A=
 			misses =3D le32toh(miss->consecutive);=0A=
 =0A=
 			DPRINTF(sc, IWN_DEBUG_STATE,=0A=
-			    "%s: beacons missed %d/%d\n", __func__,=0A=
-			    misses, le32toh(miss->total));=0A=
+			    "%s: beacons missed %d/%d rcv %d expect %d\n", __func__,=0A=
+			    misses, le32toh(miss->total), le32toh(miss->received),=0A=
+			    le32toh(miss->expected));=0A=
+=0A=
+			iv_bmissthreshold =3D vap0->iv_bmissthreshold;=0A=
+=0A=
+			if(sc->ctx =3D=3D IWN_RXON_PAN_CTX) {=0A=
+				iv_bmissthreshold =3D vap1->iv_bmissthreshold;=0A=
+				if (vap0->iv_state =3D=3D IEEE80211_S_RUN &&=0A=
+				    vap1->iv_state =3D=3D IEEE80211_S_RUN &&=0A=
+				    (ic->ic_flags & IEEE80211_F_SCAN) =3D=3D 0)=0A=
+					DoReinit =3D 1;=0A=
+			}=0A=
+			else if (vap0->iv_state =3D=3D IEEE80211_S_RUN &&=0A=
+				 (ic->ic_flags & IEEE80211_F_SCAN) =3D=3D 0)=0A=
+					DoReinit =3D 1;=0A=
+=0A=
 			/*=0A=
 			 * If more than 5 consecutive beacons are missed,=0A=
 			 * reinitialize the sensitivity state machine.=0A=
 			 */=0A=
-			if (vap->iv_state =3D=3D IEEE80211_S_RUN &&=0A=
-			    (ic->ic_flags & IEEE80211_F_SCAN) =3D=3D 0) {=0A=
+			if (DoReinit=3D=3D1) {=0A=
 				if (misses > 5)=0A=
 					(void)iwn_init_sensitivity(sc);=0A=
-				if (misses >=3D vap->iv_bmissthreshold) {=0A=
+				if (misses >=3D iv_bmissthreshold) {=0A=
 					IWN_UNLOCK(sc);=0A=
 					ieee80211_beacon_miss(ic);=0A=
 					IWN_LOCK(sc);=0A=
@@ -3214,6 +3357,13 @@=0A=
 		}=0A=
 		case IWN_UC_READY:=0A=
 		{=0A=
+/**=0A=
+ * uCode issues this "alive" notification once the runtime image is =
ready=0A=
+ * to receive commands from the driver.  This is the *second* "alive"=0A=
+ * notification that the driver will receive after rebooting uCode;=0A=
+ * this "alive" is indicated by subtype field !=3D 9.=0A=
+ *=0A=
+ **/=0A=
 			struct iwn_ucode_info *uc =3D=0A=
 			    (struct iwn_ucode_info *)(desc + 1);=0A=
 =0A=
@@ -3240,6 +3390,8 @@=0A=
 		}=0A=
 		case IWN_STATE_CHANGED:=0A=
 		{=0A=
+			uint32_t *status =3D (uint32_t *)(desc + 1);=0A=
+=0A=
 			/*=0A=
 			 * State change allows hardware switch change to be=0A=
 			 * noted. However, we handle this in iwn_intr as we=0A=
@@ -3246,12 +3398,33 @@=0A=
 			 * get both the enable/disble intr.=0A=
 			 */=0A=
 			bus_dmamap_sync(sc->rxq.data_dmat, data->map,=0A=
-			    BUS_DMASYNC_POSTREAD);=0A=
-#ifdef	IWN_DEBUG=0A=
-			uint32_t *status =3D (uint32_t *)(desc + 1);=0A=
-			DPRINTF(sc, IWN_DEBUG_INTR, "state changed to %x\n",=0A=
+				BUS_DMASYNC_POSTREAD);=0A=
+		if (*status & (IWN_STATE_CHANGE_HW_CARD_DISABLED | =
IWN_STATE_CHANGE_CT_CARD_DISABLED |IWN_STATE_CHANGE_SW_CARD_DISABLED)){=0A=
+			IWN_WRITE(sc, IWN_UCODE_GP1_SET, IWN_UCODE_GP1_CMD_BLOCKED);=0A=
+			IWN_WRITE(sc,IWN_TARG_MBX_C, 0x00000004);=0A=
+=0A=
+			if (!(*status & IWN_STATE_CHANGE_RXON_CARD_DISABLED)) {=0A=
+				IWN_WRITE(sc, IWN_UCODE_GP1_CLR, IWN_UCODE_GP1_CMD_BLOCKED);=0A=
+				IWN_WRITE(sc, IWN_TARG_MBX_C, 0x00000004);=0A=
+			}=0A=
+			   =0A=
+			if(*status & IWN_STATE_CHANGE_CT_CARD_DISABLED) {=0A=
+				device_printf(sc->sc_dev,"critical temp. reached\n");=0A=
+				/* XXX: enter CT kill */=0A=
+			}=0A=
+		}  =0A=
+		if(!(*status & IWN_STATE_CHANGE_CT_CARD_DISABLED)){=0A=
+			callout_stop(&sc->ct_kill_exit_to);=0A=
+			/* XXX: exit CT kill */=0A=
+		}=0A=
+			/*=0A=
+			 * State change allows hardware switch change to be=0A=
+			 * noted. However, we handle this in iwn_intr as we=0A=
+			 * get both the enable/disble intr.=0A=
+			 */=0A=
+=0A=
+		DPRINTF(sc, IWN_DEBUG_INTR, "state changed to %x\n",=0A=
 			    le32toh(*status));=0A=
-#endif=0A=
 			break;=0A=
 		}=0A=
 		case IWN_START_SCAN:=0A=
@@ -3280,7 +3453,7 @@=0A=
 #endif=0A=
 =0A=
 			IWN_UNLOCK(sc);=0A=
-			ieee80211_scan_next(vap);=0A=
+			ieee80211_scan_next(vapscan);=0A=
 			IWN_LOCK(sc);=0A=
 			break;=0A=
 		}=0A=
@@ -3292,6 +3465,9 @@=0A=
 			sc->sc_flags |=3D IWN_FLAG_CALIB_DONE;=0A=
 			wakeup(sc);=0A=
 			break;=0A=
+		default:=0A=
+			DPRINTF(sc,IWN_DEBUG_INTR,"Interrupt type %d not managed\n",=0A=
+			    desc->type);=0A=
 		}=0A=
 =0A=
 		sc->rxq.cur =3D (sc->rxq.cur + 1) % IWN_RX_RING_COUNT;=0A=
@@ -3435,8 +3611,6 @@=0A=
 		r2 =3D IWN_READ(sc, IWN_FH_INT);=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_INTR, "interrupt reg1=3D0x%08x reg2=3D0x%08x\n"=0A=
-    , r1, r2);=0A=
 =0A=
 	if (r1 =3D=3D 0 && r2 =3D=3D 0)=0A=
 		goto done;	/* Interrupt not for us. */=0A=
@@ -3446,6 +3620,8 @@=0A=
 	if (!(sc->sc_flags & IWN_FLAG_USE_ICT))=0A=
 		IWN_WRITE(sc, IWN_FH_INT, r2);=0A=
 =0A=
+	DPRINTF(sc, IWN_DEBUG_INTR, "Acked interupt reg1=3D0x%08x =
reg2=3D0x%08x\n", r1, r2);=0A=
+=0A=
 	if (r1 & IWN_INT_RF_TOGGLED) {=0A=
 		iwn_rftoggle_intr(sc);=0A=
 		goto done;=0A=
@@ -3454,6 +3630,7 @@=0A=
 		device_printf(sc->sc_dev, "%s: critical temperature reached!\n",=0A=
 		    __func__);=0A=
 	}=0A=
+	/* Todo : Make separate action for HW Error and SW_error. SW Error =
maybe require just a restart */=0A=
 	if (r1 & (IWN_INT_SW_ERR | IWN_INT_HW_ERR)) {=0A=
 		device_printf(sc->sc_dev, "%s: fatal firmware error\n",=0A=
 		    __func__);=0A=
@@ -3583,6 +3760,7 @@=0A=
 	bus_dma_segment_t *seg, segs[IWN_MAX_SCATTER];=0A=
 	uint8_t tid, ridx, txant, type;=0A=
 	int ac, i, totlen, error, pad, nsegs =3D 0, rate;=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 =0A=
@@ -3600,21 +3778,23 @@=0A=
 		qos =3D 0;=0A=
 		tid =3D 0;=0A=
 	}=0A=
-	ac =3D M_WME_GETAC(m);=0A=
-	if (m->m_flags & M_AMPDU_MPDU) {=0A=
+=0A=
+	if(ivp->ctx =3D=3D IWN_RXON_PAN_CTX)=0A=
+		ac =3D iwn_pan_ac_to_queue[M_WME_GETAC(m)];=0A=
+	else=0A=
+		ac =3D iwn_bss_ac_to_queue[M_WME_GETAC(m)];=0A=
+=0A=
+	if (IEEE80211_QOS_HAS_SEQ(wh) &&=0A=
+	    IEEE80211_AMPDU_RUNNING(&ni->ni_tx_ampdu[ac])) {=0A=
 		struct ieee80211_tx_ampdu *tap =3D &ni->ni_tx_ampdu[ac];=0A=
 =0A=
-		if (!IEEE80211_AMPDU_RUNNING(tap)) {=0A=
-			m_freem(m);=0A=
-			return EINVAL;=0A=
-		}=0A=
-=0A=
-		ac =3D *(int *)tap->txa_private;=0A=
+		ring =3D &sc->txq[*(int *)tap->txa_private];=0A=
 		*(uint16_t *)wh->i_seq =3D=0A=
 		    htole16(ni->ni_txseqs[tid] << IEEE80211_SEQ_SEQ_SHIFT);=0A=
 		ni->ni_txseqs[tid]++;=0A=
-	}=0A=
-	ring =3D &sc->txq[ac];=0A=
+	} else=0A=
+		ring =3D &sc->txq[ac];=0A=
+=0A=
 	desc =3D &ring->desc[ring->cur];=0A=
 	data =3D &ring->data[ring->cur];=0A=
 =0A=
@@ -3706,10 +3886,12 @@=0A=
 		}=0A=
 	}=0A=
 =0A=
-	if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||=0A=
-	    type !=3D IEEE80211_FC0_TYPE_DATA)=0A=
-		tx->id =3D sc->broadcast_id;=0A=
-	else=0A=
+	if (IEEE80211_IS_MULTICAST(wh->i_addr1) || type !=3D =
IEEE80211_FC0_TYPE_DATA) {=0A=
+		if(ivp->ctx =3D=3D IWN_RXON_PAN_CTX)=0A=
+			tx->id =3D IWN_PAN_ID_BCAST;=0A=
+		else=0A=
+			tx->id =3D sc->broadcast_id;=0A=
+	} else=0A=
 		tx->id =3D wn->id;=0A=
 =0A=
 	if (type =3D=3D IEEE80211_FC0_TYPE_MGT) {=0A=
@@ -3739,7 +3921,7 @@=0A=
 	tx->data_ntries =3D 15;=0A=
 	tx->lifetime =3D htole32(IWN_LIFETIME_INFINITE);=0A=
 	tx->rate =3D iwn_rate_to_plcp(sc, ni, rate);=0A=
-	if (tx->id =3D=3D sc->broadcast_id) {=0A=
+	if ((tx->id =3D=3D IWN_PAN_ID_BCAST) || (tx->id =3D=3D =
sc->broadcast_id)) {=0A=
 		/* Group or management frame. */=0A=
 		tx->linkq =3D 0;=0A=
 		/* XXX Alternate between antenna A and B? */=0A=
@@ -3771,7 +3953,7 @@=0A=
 			return error;=0A=
 		}=0A=
 		/* Too many DMA segments, linearize mbuf. */=0A=
-		m1 =3D m_collapse(m, M_NOWAIT, IWN_MAX_SCATTER);=0A=
+		m1 =3D m_collapse(m, M_DONTWAIT, IWN_MAX_SCATTER);=0A=
 		if (m1 =3D=3D NULL) {=0A=
 			device_printf(sc->sc_dev,=0A=
 			    "%s: could not defrag mbuf\n", __func__);=0A=
@@ -3856,7 +4038,7 @@=0A=
 	u_int hdrlen;=0A=
 	int ac, totlen, error, pad, nsegs =3D 0, i, rate;=0A=
 	uint8_t ridx, type, txant;=0A=
-=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 =0A=
 	IWN_LOCK_ASSERT(sc);=0A=
@@ -3946,7 +4128,10 @@=0A=
 =0A=
 	tx->len =3D htole16(totlen);=0A=
 	tx->tid =3D 0;=0A=
-	tx->id =3D sc->broadcast_id;=0A=
+	if(ivp->ctx =3D=3D IWN_RXON_PAN_CTX)=0A=
+		tx->id =3D IWN_PAN_ID_BCAST;=0A=
+	else=0A=
+		tx->id =3D sc->broadcast_id;=0A=
 	tx->rts_ntries =3D params->ibp_try1;=0A=
 	tx->data_ntries =3D params->ibp_try0;=0A=
 	tx->lifetime =3D htole32(IWN_LIFETIME_INFINITE);=0A=
@@ -3956,12 +4141,10 @@=0A=
 	if (ridx < IWN_RIDX_OFDM6 &&=0A=
 	    IEEE80211_IS_CHAN_2GHZ(ni->ni_chan))=0A=
 		tx->rate |=3D htole32(IWN_RFLAG_CCK);=0A=
-=0A=
 	/* Group or management frame. */=0A=
 	tx->linkq =3D 0;=0A=
 	txant =3D IWN_LSB(sc->txchainmask);=0A=
 	tx->rate |=3D htole32(IWN_RFLAG_ANT(txant));=0A=
-=0A=
 	/* Set physical address of "scratch area". */=0A=
 	tx->loaddr =3D htole32(IWN_LOADDR(data->scratch_paddr));=0A=
 	tx->hiaddr =3D IWN_HIADDR(data->scratch_paddr);=0A=
@@ -3984,7 +4167,7 @@=0A=
 			return error;=0A=
 		}=0A=
 		/* Too many DMA segments, linearize mbuf. */=0A=
-		m1 =3D m_collapse(m, M_NOWAIT, IWN_MAX_SCATTER);=0A=
+		m1 =3D m_collapse(m, M_DONTWAIT, IWN_MAX_SCATTER);=0A=
 		if (m1 =3D=3D NULL) {=0A=
 			device_printf(sc->sc_dev,=0A=
 			    "%s: could not defrag mbuf\n", __func__);=0A=
@@ -4141,6 +4324,8 @@=0A=
 	struct iwn_softc *sc =3D arg;=0A=
 	struct ifnet *ifp =3D sc->sc_ifp;=0A=
 	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	struct ieee80211_scan_state *ss =3D ic->ic_scan;=0A=
+	struct ieee80211vap *vapscan =3D ss->ss_vap;=0A=
 =0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
@@ -4155,6 +4340,12 @@=0A=
 			return;=0A=
 		}=0A=
 	}=0A=
+=0A=
+	if (sc->sc_scan_timer > 0) {=0A=
+		if (--sc->sc_scan_timer =3D=3D 0)=0A=
+			ieee80211_scan_next(vapscan);=0A=
+	}=0A=
+=0A=
 	callout_reset(&sc->watchdog_to, hz, iwn_watchdog, sc);=0A=
 }=0A=
 =0A=
@@ -4207,7 +4398,7 @@=0A=
 static int=0A=
 iwn_cmd(struct iwn_softc *sc, int code, const void *buf, int size, int =
async)=0A=
 {=0A=
-	struct iwn_tx_ring *ring =3D &sc->txq[4];=0A=
+	struct iwn_tx_ring *ring ;=0A=
 	struct iwn_tx_desc *desc;=0A=
 	struct iwn_tx_data *data;=0A=
 	struct iwn_tx_cmd *cmd;=0A=
@@ -4214,12 +4405,25 @@=0A=
 	struct mbuf *m;=0A=
 	bus_addr_t paddr;=0A=
 	int totlen, error;=0A=
+	int cmd_queue_num;=0A=
 =0A=
+	if((sc->uc_scan_progress =3D=3D 1) && (code !=3D IWN_CMD_SCAN)) {=0A=
+		DPRINTF(sc,IWN_DEBUG_CMD,"Scanning in progress..not sending cmd =
%x.\n",code);=0A=
+		return 0;=0A=
+	}=0A=
+=0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 =0A=
 	if (async =3D=3D 0)=0A=
 		IWN_LOCK_ASSERT(sc);=0A=
 =0A=
+	if(sc->sc_flags & IWN_FLAG_PAN_SUPPORT)=0A=
+		cmd_queue_num =3D IWN_PAN_CMD_QUEUE;=0A=
+	else=0A=
+		cmd_queue_num =3D IWN_CMD_QUEUE_NUM;=0A=
+=0A=
+	ring =3D &sc->txq[cmd_queue_num];=0A=
+=0A=
 	desc =3D &ring->desc[ring->cur];=0A=
 	data =3D &ring->data[ring->cur];=0A=
 	totlen =3D 4 + size;=0A=
@@ -4228,7 +4432,7 @@=0A=
 		/* Command is too large to fit in a descriptor. */=0A=
 		if (totlen > MCLBYTES)=0A=
 			return EINVAL;=0A=
-		m =3D m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);=0A=
+		m =3D m_getjcl(M_DONTWAIT, MT_DATA, M_PKTHDR, MJUMPAGESIZE);=0A=
 		if (m =3D=3D NULL)=0A=
 			return ENOMEM;=0A=
 		cmd =3D mtod(m, struct iwn_tx_cmd *);=0A=
@@ -4303,7 +4507,14 @@=0A=
 {=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
-=0A=
+	if (node->control =3D=3D 0)=0A=
+		DPRINTF(sc, IWN_DEBUG_NODE, =0A=
+		    "Adding node id : %d MAC : %6D flags: 0x%x\n", node->id,=0A=
+		    node->macaddr,":", node->flags);=0A=
+	else=0A=
+		DPRINTF(sc, IWN_DEBUG_NODE, =0A=
+		    "Updating node id : %d MAC : %6D flags: 0x%x\n", node->id,=0A=
+		    node->macaddr,":", node->flags);=0A=
 	/* Direct mapping. */=0A=
 	return iwn_cmd(sc, IWN_CMD_ADD_NODE, node, sizeof (*node), async);=0A=
 }=0A=
@@ -4311,6 +4522,10 @@=0A=
 static int=0A=
 iwn_set_link_quality(struct iwn_softc *sc, struct ieee80211_node *ni)=0A=
 {=0A=
+=0A=
+	DPRINTF(sc,IWN_DEBUG_RESET,"Disabled %s reached\n",__func__);=0A=
+	return 0;=0A=
+=0A=
 #define	RV(v)	((v) & IEEE80211_RATE_VAL)=0A=
 	struct iwn_node *wn =3D (void *)ni;=0A=
 	struct ieee80211_rateset *rs =3D &ni->ni_rates;=0A=
@@ -4456,7 +4671,8 @@=0A=
 }=0A=
 =0A=
 static void=0A=
-iwn_set_led(struct iwn_softc *sc, uint8_t which, uint8_t off, uint8_t =
on)=0A=
+iwn_set_led(struct iwn_softc *sc, uint8_t which, uint8_t off, uint8_t =
on,=0A=
+    uint8_t mode)=0A=
 {=0A=
 	struct iwn_cmd_led led;=0A=
 =0A=
@@ -4466,7 +4682,12 @@=0A=
 	IWN_CLRBITS(sc, IWN_LED, IWN_LED_BSM_CTRL);=0A=
 =0A=
 	led.which =3D which;=0A=
-	led.unit =3D htole32(10000);	/* on/off in unit of 100ms */=0A=
+=0A=
+	if(mode =3D=3D IWN_LED_SLOW_BLINK)=0A=
+		led.unit =3D htole32(IWN_LED_UNIT * 5); /* on/off in unit of 10ms */=0A=
+	else=0A=
+		led.unit =3D htole32(IWN_LED_UNIT);=0A=
+=0A=
 	led.off =3D off;=0A=
 	led.on =3D on;=0A=
 	(void)iwn_cmd(sc, IWN_CMD_SET_LED, &led, sizeof led, 1);=0A=
@@ -4480,21 +4701,30 @@=0A=
 iwn_set_critical_temp(struct iwn_softc *sc)=0A=
 {=0A=
 	struct iwn_critical_temp crit;=0A=
-	int32_t temp;=0A=
+	int32_t ct_enter,ct_exit;=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
 =0A=
 	IWN_WRITE(sc, IWN_UCODE_GP1_CLR, IWN_UCODE_GP1_CTEMP_STOP_RF);=0A=
 =0A=
-	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_5150)=0A=
-		temp =3D (IWN_CTOK(110) - sc->temp_off) * -5;=0A=
-	else if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_4965)=0A=
-		temp =3D IWN_CTOK(110);=0A=
-	else=0A=
-		temp =3D 110;=0A=
+	ct_enter =3D IWN_CT_KILL_THRESHOLD;=0A=
+	ct_exit =3D IWN_CT_KILL_EXIT_THRESHOLD;=0A=
+=0A=
+	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_5150) {=0A=
+		ct_enter =3D (IWN_CTOK(IWN_CT_KILL_THRESHOLD) - sc->temp_off) * -5;=0A=
+		ct_exit =3D 0;=0A=
+	} else if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_4965) {=0A=
+		ct_enter =3D IWN_CTOK(IWN_CT_KILL_THRESHOLD);=0A=
+		ct_exit =3D 0;=0A=
+	} else {=0A=
+		ct_enter =3D IWN_CT_KILL_THRESHOLD;=0A=
+		ct_exit =3D IWN_CT_KILL_EXIT_THRESHOLD;=0A=
+	}=0A=
+=0A=
 	memset(&crit, 0, sizeof crit);=0A=
-	crit.tempR =3D htole32(temp);=0A=
-	DPRINTF(sc, IWN_DEBUG_RESET, "setting critical temp to %d\n", temp);=0A=
+	crit.tempR =3D htole32(ct_enter);=0A=
+	crit.tempM =3D htole32(ct_exit);=0A=
+	DPRINTF(sc, IWN_DEBUG_RESET, "setting critical temp to %d and exit to =
%d \n", ct_enter,ct_exit);=0A=
 	return iwn_cmd(sc, IWN_CMD_SET_CRITICAL_TEMP, &crit, sizeof crit, 0);=0A=
 }=0A=
 =0A=
@@ -4516,10 +4746,12 @@=0A=
 	mod =3D le64toh(cmd.tstamp) % val;=0A=
 	cmd.binitval =3D htole32((uint32_t)(val - mod));=0A=
 =0A=
+//	cmd.dtim_period=3D1; //XXX It's defined in linux kernel=0A=
+=0A=
 	DPRINTF(sc, IWN_DEBUG_RESET, "timing bintval=3D%u tstamp=3D%ju, =
init=3D%u\n",=0A=
-	    ni->ni_intval, le64toh(cmd.tstamp), (uint32_t)(val - mod));=0A=
+	    le16toh(cmd.bintval), le64toh(cmd.tstamp), (uint32_t)(val - mod));=0A=
 =0A=
-	return iwn_cmd(sc, IWN_CMD_TIMING, &cmd, sizeof cmd, 1);=0A=
+	return iwn_cmd(sc, IWN_CMD_TIMING | IWN_DEBUG_RESET, &cmd, sizeof cmd, =
0);=0A=
 }=0A=
 =0A=
 static void=0A=
@@ -4696,6 +4928,11 @@=0A=
 #undef fdivround=0A=
 }=0A=
 =0A=
+/*=0A=
+ * Set TX power for current channel (each rate has its own power =
settings).=0A=
+ * This function takes into account the regulatory information from =
EEPROM,=0A=
+ * the current temperature and the current voltage.=0A=
+ */=0A=
 static int=0A=
 iwn5000_set_txpower(struct iwn_softc *sc, struct ieee80211_channel *ch,=0A=
     int async)=0A=
@@ -4751,19 +4988,22 @@=0A=
 {=0A=
 	struct iwn5000_rx_phystat *phy =3D (void *)stat->phybuf;=0A=
 	uint8_t agc;=0A=
-	int rssi;=0A=
+	int rssi, rssi_a, rssi_b, rssi_c;=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
 =0A=
-	agc =3D (le32toh(phy->agc) >> 9) & 0x7f;=0A=
+	agc =3D (le32toh(phy->agc) >> 9) & 0x7f;	/* 0x7f =3D=3D (0xfe00 >> 9) =
*/=0A=
 =0A=
-	rssi =3D MAX(le16toh(phy->rssi[0]) & 0xff,=0A=
-		   le16toh(phy->rssi[1]) & 0xff);=0A=
-	rssi =3D MAX(le16toh(phy->rssi[2]) & 0xff, rssi);=0A=
+	rssi_a =3D le16toh(phy->rssi[0]) & 0xff;=0A=
+	rssi_b =3D le16toh(phy->rssi[1]) & 0xff;=0A=
+	rssi_c =3D le16toh(phy->rssi[2]) & 0xff;=0A=
 =0A=
+	rssi =3D MAX(rssi_a, rssi_b); =0A=
+	rssi =3D MAX(rssi_c, rssi);=0A=
+=0A=
 	DPRINTF(sc, IWN_DEBUG_RECV,=0A=
-	    "%s: agc %d rssi %d %d %d result %d\n", __func__, agc,=0A=
-	    phy->rssi[0], phy->rssi[1], phy->rssi[2],=0A=
+	    "%s: agc %d rssi ANT_A:%d ANT_B:%d ANT_C:%d result %d dBm\n", =
__func__, agc,=0A=
+	    rssi_a, rssi_b, rssi_c,=0A=
 	    rssi - agc - IWN_RSSI_TO_DBM);=0A=
 	return rssi - agc - IWN_RSSI_TO_DBM;=0A=
 }=0A=
@@ -4833,6 +5073,8 @@=0A=
 		temp =3D (temp / -5) + sc->temp_off;=0A=
 		temp =3D IWN_KTOC(temp);=0A=
 	}=0A=
+	DPRINTF(sc,IWN_DEBUG_CALIBRATE,"Temperature %d\n",temp);=0A=
+	//XXX: handle thermal throttling state machine=0A=
 	return temp;=0A=
 }=0A=
 =0A=
@@ -4844,7 +5086,6 @@=0A=
 {=0A=
 	struct iwn_ops *ops =3D &sc->ops;=0A=
 	struct iwn_calib_state *calib =3D &sc->calib;=0A=
-	uint32_t flags;=0A=
 	int error;=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
@@ -4858,9 +5099,10 @@=0A=
 	calib->ofdm_mrc_x1 =3D sc->limits->min_ofdm_mrc_x1;=0A=
 	calib->ofdm_x4     =3D sc->limits->min_ofdm_x4;=0A=
 	calib->ofdm_mrc_x4 =3D sc->limits->min_ofdm_mrc_x4;=0A=
-	calib->cck_x4      =3D 125;=0A=
+	calib->cck_x4      =3D sc->limits->min_cck_x4;=0A=
 	calib->cck_mrc_x4  =3D sc->limits->min_cck_mrc_x4;=0A=
 	calib->energy_cck  =3D sc->limits->energy_cck;=0A=
+	calib->corr_barker_mrc  =3D sc->limits->min_corr_barker_mrc;=0A=
 =0A=
 	/* Write initial sensitivity. */=0A=
 	if ((error =3D iwn_send_sensitivity(sc)) !=3D 0)=0A=
@@ -4871,10 +5113,7 @@=0A=
 		return error;=0A=
 =0A=
 	/* Request statistics at each beacon interval. */=0A=
-	flags =3D 0;=0A=
-	DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s: sending request for =
statistics\n",=0A=
-	    __func__);=0A=
-	return iwn_cmd(sc, IWN_CMD_GET_STATISTICS, &flags, sizeof flags, 1);=0A=
+	return iwn_set_statistics_request(sc,true,false,1);=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -5217,15 +5456,15 @@=0A=
 	cmd.corr_ofdm_mrc_x1   =3D htole16(calib->ofdm_mrc_x1);=0A=
 	cmd.corr_ofdm_x4       =3D htole16(calib->ofdm_x4);=0A=
 	cmd.corr_ofdm_mrc_x4   =3D htole16(calib->ofdm_mrc_x4);=0A=
-	cmd.energy_ofdm        =3D htole16(sc->limits->energy_ofdm);=0A=
-	cmd.energy_ofdm_th     =3D htole16(62);=0A=
+	cmd.energy_ofdm        =3D htole16(calib->energy_ofdm);=0A=
+	cmd.energy_ofdm_th     =3D htole16(62); //Value doesn't change in =
linux Kernel=0A=
 	/* CCK modulation. */=0A=
 	cmd.corr_cck_x4        =3D htole16(calib->cck_x4);=0A=
 	cmd.corr_cck_mrc_x4    =3D htole16(calib->cck_mrc_x4);=0A=
 	cmd.energy_cck         =3D htole16(calib->energy_cck);=0A=
 	/* Barker modulation: use default values. */=0A=
-	cmd.corr_barker        =3D htole16(190);=0A=
-	cmd.corr_barker_mrc    =3D htole16(390);=0A=
+	cmd.corr_barker        =3D htole16(190); //Value doesn't change in =
linux Kernel=0A=
+	cmd.corr_barker_mrc    =3D htole16(calib->corr_barker_mrc);=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_CALIBRATE,=0A=
 	    "%s: set sensitivity %d/%d/%d/%d/%d/%d/%d\n", __func__,=0A=
@@ -5252,6 +5491,8 @@=0A=
 /*=0A=
  * Set STA mode power saving level (between 0 and 5).=0A=
  * Level 0 is CAM (Continuously Aware Mode), 5 is for maximum power =
saving.=0A=
+ * DTIM value passed in will if so configured, be ignored and taken from=0A=
+ * the value set at the AP.=0A=
  */=0A=
 static int=0A=
 iwn_set_pslevel(struct iwn_softc *sc, int dtim, int level, int async)=0A=
@@ -5260,8 +5501,25 @@=0A=
 	const struct iwn_pmgt *pmgt;=0A=
 	uint32_t max, skip_dtim;=0A=
 	uint32_t reg;=0A=
-	int i;=0A=
+	int i, retval;=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
 =0A=
+	if(!TAILQ_EMPTY(&ic->ic_vaps)) {=0A=
+		/* At present the driver supports only a single vap. */=0A=
+		struct ieee80211vap *vap =3D TAILQ_FIRST(&ic->ic_vaps);=0A=
+=0A=
+		/* XXX confirm PS level setting validity for various modes */=0A=
+		if(vap->iv_opmode =3D=3D IEEE80211_M_HOSTAP ||=0A=
+		    vap->iv_opmode =3D=3D IEEE80211_M_MONITOR)=0A=
+			return 0;=0A=
+=0A=
+		#ifdef IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP=0A=
+			if (vap->iv_state =3D=3D IEEE80211_S_RUN)=0A=
+				dtim =3D vap->iv_bss->ni_dtim_period;=0A=
+		#endif=0A=
+	}=0A=
+=0A=
 	DPRINTF(sc, IWN_DEBUG_PWRSAVE,=0A=
 	    "%s: dtim=3D%d, level=3D%d, async=3D%d\n",=0A=
 	    __func__,=0A=
@@ -5279,7 +5537,7 @@=0A=
 =0A=
 	memset(&cmd, 0, sizeof cmd);=0A=
 	if (level !=3D 0)	/* not CAM */=0A=
-		cmd.flags |=3D htole16(IWN_PS_ALLOW_SLEEP);=0A=
+		cmd.flags |=3D =
htole16(IWN_PS_ALLOW_SLEEP)|htole16(IWN_PS_ADVANCED_PM);=0A=
 	if (level =3D=3D 5)=0A=
 		cmd.flags |=3D htole16(IWN_PS_FAST_PD);=0A=
 	/* Retrieve PCIe Active State Power Management (ASPM). */=0A=
@@ -5306,9 +5564,18 @@=0A=
 	for (i =3D 0; i < 5; i++)=0A=
 		cmd.intval[i] =3D htole32(MIN(max, pmgt->intval[i]));=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_RESET, "setting power saving level to %d\n",=0A=
+	DPRINTF(sc, IWN_DEBUG_PWRSAVE, "setting power saving level to %d\n",=0A=
 	    level);=0A=
-	return iwn_cmd(sc, IWN_CMD_SET_POWER_MODE, &cmd, sizeof cmd, async);=0A=
+	retval =3D  iwn_cmd(sc, IWN_CMD_SET_POWER_MODE, &cmd, sizeof cmd, =
async);=0A=
+	/*=0A=
+	 * XXX: update current_pwrsave_level using completion notification=0A=
+	 * in case of async mode=0A=
+	 */=0A=
+	if(retval=3D=3D0)=0A=
+		sc->current_pwrsave_level =3D level;=0A=
+=0A=
+	return retval;=0A=
+=0A=
 }=0A=
 =0A=
 static int=0A=
@@ -5333,26 +5600,63 @@=0A=
 		0xcc00ff28, 0x0000aaaa, 0xcc00aaaa, 0x0000aaaa,=0A=
 		0xc0004000, 0x00004000, 0xf0005000, 0xf0005000,=0A=
 	};=0A=
+=0A=
 	struct iwn6000_btcoex_config btconfig;=0A=
+	struct iwn2000_btcoex_config btconfig2k;=0A=
 	struct iwn_btcoex_priotable btprio;=0A=
 	struct iwn_btcoex_prot btprot;=0A=
 	int error, i;=0A=
+	uint8_t		flags;=0A=
 =0A=
 	memset(&btconfig, 0, sizeof btconfig);=0A=
-	btconfig.flags =3D 145;=0A=
-	btconfig.max_kill =3D 5;=0A=
-	btconfig.bt3_t7_timer =3D 1;=0A=
-	btconfig.kill_ack =3D htole32(0xffff0000);=0A=
-	btconfig.kill_cts =3D htole32(0xffff0000);=0A=
-	btconfig.sample_time =3D 2;=0A=
-	btconfig.bt3_t2_timer =3D 0xc;=0A=
-	for (i =3D 0; i < 12; i++)=0A=
-		btconfig.lookup_table[i] =3D htole32(btcoex_3wire[i]);=0A=
-	btconfig.valid =3D htole16(0xff);=0A=
-	btconfig.prio_boost =3D 0xf0;=0A=
-	DPRINTF(sc, IWN_DEBUG_RESET,=0A=
-	    "%s: configuring advanced bluetooth coexistence\n", __func__);=0A=
-	error =3D iwn_cmd(sc, IWN_CMD_BT_COEX, &btconfig, sizeof(btconfig), 1);=0A=
+	memset(&btconfig2k, 0, sizeof btconfig2k);=0A=
+=0A=
+	flags =3D IWN_BT_FLAG_COEX6000_MODE_3W << =
IWN_BT_FLAG_COEX6000_MODE_SHIFT; // Done as is in linux kernel 3.2=0A=
+=0A=
+	if (sc->base_params->bt_sco_disable)=0A=
+		flags &=3D ~IWN_BT_FLAG_SYNC_2_BT_DISABLE; =0A=
+	else=0A=
+		flags |=3D IWN_BT_FLAG_SYNC_2_BT_DISABLE; =0A=
+=0A=
+	flags |=3D IWN_BT_FLAG_COEX6000_CHAN_INHIBITION;=0A=
+=0A=
+=0A=
+	/* Default flags result is 145 as old value */=0A=
+=0A=
+	/* Flags value has to be review. Values must change if we which to =
disable it */=0A=
+	if (sc->base_params->bt_session_2) {=0A=
+		btconfig2k.flags =3D flags; =0A=
+		btconfig2k.max_kill =3D 5;=0A=
+		btconfig2k.bt3_t7_timer =3D 1;=0A=
+		btconfig2k.kill_ack =3D htole32(0xffff0000);=0A=
+		btconfig2k.kill_cts =3D htole32(0xffff0000);=0A=
+		btconfig2k.sample_time =3D 2;=0A=
+		btconfig2k.bt3_t2_timer =3D 0xc;=0A=
+=0A=
+		for (i =3D 0; i < 12; i++)=0A=
+			btconfig2k.lookup_table[i] =3D htole32(btcoex_3wire[i]);=0A=
+		btconfig2k.valid =3D htole16(0xff);=0A=
+		btconfig2k.prio_boost =3D htole32(0xf0);=0A=
+		DPRINTF(sc, IWN_DEBUG_RESET,=0A=
+			"%s: configuring advanced bluetooth coexistence session 2, flags : =
0X%x\n", __func__,flags);=0A=
+		error =3D iwn_cmd(sc, IWN_CMD_BT_COEX, &btconfig2k, =
sizeof(btconfig2k), 1);=0A=
+	} else {=0A=
+		btconfig.flags =3D flags;=0A=
+		btconfig.max_kill =3D 5;=0A=
+		btconfig.bt3_t7_timer =3D 1;=0A=
+		btconfig.kill_ack =3D htole32(0xffff0000);=0A=
+		btconfig.kill_cts =3D htole32(0xffff0000);=0A=
+		btconfig.sample_time =3D 2;=0A=
+		btconfig.bt3_t2_timer =3D 0xc;=0A=
+=0A=
+		for (i =3D 0; i < 12; i++)=0A=
+			btconfig.lookup_table[i] =3D htole32(btcoex_3wire[i]);=0A=
+		btconfig.valid =3D htole16(0xff);=0A=
+		btconfig.prio_boost =3D 0xf0;=0A=
+		DPRINTF(sc, IWN_DEBUG_RESET,=0A=
+			"%s: configuring advanced bluetooth coexistence, flags : 0X%x\n", =
__func__,flags);=0A=
+		error =3D iwn_cmd(sc, IWN_CMD_BT_COEX, &btconfig, sizeof(btconfig), =
1);=0A=
+	}=0A=
 	if (error !=3D 0)=0A=
 		return error;=0A=
 =0A=
@@ -5383,19 +5687,6 @@=0A=
 }=0A=
 =0A=
 static int=0A=
-iwn5000_runtime_calib(struct iwn_softc *sc)=0A=
-{=0A=
-	struct iwn5000_calib_config cmd;=0A=
-=0A=
-	memset(&cmd, 0, sizeof cmd);=0A=
-	cmd.ucode.once.enable =3D 0xffffffff;=0A=
-	cmd.ucode.once.start =3D IWN5000_CALIB_DC;=0A=
-	DPRINTF(sc, IWN_DEBUG_CALIBRATE,=0A=
-	    "%s: configuring runtime calibration\n", __func__);=0A=
-	return iwn_cmd(sc, IWN5000_CMD_CALIB_CONFIG, &cmd, sizeof(cmd), 0);=0A=
-}=0A=
-=0A=
-static int=0A=
 iwn_config(struct iwn_softc *sc)=0A=
 {=0A=
 	struct iwn_ops *ops =3D &sc->ops;=0A=
@@ -5407,8 +5698,12 @@=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 =0A=
-	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_6005) {=0A=
-		/* Set radio temperature sensor offset. */=0A=
+	if ((sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET) =
 && (sc->base_params->calib_need & =
IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2)) {=0A=
+		device_printf(sc->sc_dev,"%s: temp_offset and temp_offsetv2 are =
exclusive each together. Review NIC config file. Conf :  0x%08x Flags :  =
0x%08x  \n", =
__func__,sc->base_params->calib_need,(IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET =
| IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2));=0A=
+		return EINVAL;=0A=
+	}=0A=
+	/* Compute temperature calib if needed. Will be send by send calib */=0A=
+	if (sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET) {=0A=
 		error =3D iwn5000_temp_offset_calib(sc);=0A=
 		if (error !=3D 0) {=0A=
 			device_printf(sc->sc_dev,=0A=
@@ -5415,19 +5710,28 @@=0A=
 			    "%s: could not set temperature offset\n", __func__);=0A=
 			return error;=0A=
 		}=0A=
-	}=0A=
-=0A=
-	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_6050) {=0A=
-		/* Configure runtime DC calibration. */=0A=
-		error =3D iwn5000_runtime_calib(sc);=0A=
+	} else if (sc->base_params->calib_need & =
IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2) {=0A=
+		error =3D iwn5000_temp_offset_calibv2(sc);=0A=
 		if (error !=3D 0) {=0A=
 			device_printf(sc->sc_dev,=0A=
-			    "%s: could not configure runtime calibration\n",=0A=
-			    __func__);=0A=
+				"%s: could not compute temperature offset v2\n", __func__);=0A=
 			return error;=0A=
 		}=0A=
 	}=0A=
 =0A=
+	/* Configure bluetooth coexistence. */=0A=
+	if (sc->base_params->advanced_bt_coexist) =0A=
+		error =3D iwn_send_advanced_btcoex(sc);=0A=
+	else=0A=
+		error =3D iwn_send_btcoex(sc);=0A=
+=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not configure bluetooth coexistence, error %d\n",=0A=
+		    __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
 	/* Configure valid TX chains for >=3D5000 Series. */=0A=
 	if (sc->hw_type !=3D IWN_HW_REV_TYPE_4965) {=0A=
 		txmask =3D htole32(sc->txchainmask);=0A=
@@ -5443,17 +5747,6 @@=0A=
 		}=0A=
 	}=0A=
 =0A=
-	/* Configure bluetooth coexistence. */=0A=
-	if (sc->sc_flags & IWN_FLAG_ADV_BTCOEX)=0A=
-		error =3D iwn_send_advanced_btcoex(sc);=0A=
-	else=0A=
-		error =3D iwn_send_btcoex(sc);=0A=
-	if (error !=3D 0) {=0A=
-		device_printf(sc->sc_dev,=0A=
-		    "%s: could not configure bluetooth coexistence, error %d\n",=0A=
-		    __func__, error);=0A=
-		return error;=0A=
-	}=0A=
 =0A=
 	/* Set mode, channel, RX filter and enable RX. */=0A=
 	sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=0A=
@@ -5515,8 +5808,18 @@=0A=
 		return error;=0A=
 	}=0A=
 =0A=
-	/* Set power saving level to CAM during initialization. */=0A=
-	if ((error =3D iwn_set_pslevel(sc, 0, 0, 0)) !=3D 0) {=0A=
+	/*=0A=
+	 * Any vap's iv_flags are cloned from ic->ic_flags. Setting the flags=0A=
+	 * on ic will allow a vap to get the correct powersave level once=0A=
+	 * it is created.=0A=
+	 */=0A=
+	if(sc->desired_pwrsave_level!=3DIWN_POWERSAVE_LVL_NONE)=0A=
+		ic->ic_flags |=3D IEEE80211_F_PMGTON;=0A=
+	else=0A=
+		ic->ic_flags &=3D ~IEEE80211_F_PMGTON;=0A=
+=0A=
+	if ((error =3D iwn_set_pslevel(sc, IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE,=0A=
+			sc->desired_pwrsave_level, 0)) !=3D 0) {=0A=
 		device_printf(sc->sc_dev,=0A=
 		    "%s: could not set power saving level\n", __func__);=0A=
 		return error;=0A=
@@ -5557,10 +5860,20 @@=0A=
 	uint16_t rxchain;=0A=
 	uint8_t txant;=0A=
 	int buflen, error;=0A=
+	uint8_t new_scan_threshold;=0A=
+	struct iwn_eeprom_chan *channel;=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 =0A=
-	sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=0A=
+=0A=
+	struct ieee80211vap *vap =3D ni->ni_vap;=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+=0A=
+	if(ivp->ctx =3D=3D IWN_RXON_BSS_CTX)=0A=
+		sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=0A=
+	else if(ivp->ctx =3D=3D IWN_RXON_PAN_CTX)=0A=
+		sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+=0A=
 	buf =3D malloc(IWN_SCAN_MAXSZ, M_DEVBUF, M_NOWAIT | M_ZERO);=0A=
 	if (buf =3D=3D NULL) {=0A=
 		device_printf(sc->sc_dev,=0A=
@@ -5592,7 +5905,11 @@=0A=
 =0A=
 	tx =3D (struct iwn_cmd_data *)(hdr + 1);=0A=
 	tx->flags =3D htole32(IWN_TX_AUTO_SEQ);=0A=
-	tx->id =3D sc->broadcast_id;=0A=
+	if(ivp->ctx =3D=3D IWN_RXON_PAN_CTX)=0A=
+		tx->id =3D IWN_PAN_ID_BCAST;=0A=
+	else=0A=
+		tx->id =3D sc->broadcast_id;=0A=
+=0A=
 	tx->lifetime =3D htole32(IWN_LIFETIME_INFINITE);=0A=
 =0A=
 	if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan)) {=0A=
@@ -5629,7 +5946,7 @@=0A=
 	    IEEE80211_FC0_SUBTYPE_PROBE_REQ;=0A=
 	wh->i_fc[1] =3D IEEE80211_FC1_DIR_NODS;=0A=
 	IEEE80211_ADDR_COPY(wh->i_addr1, ifp->if_broadcastaddr);=0A=
-	IEEE80211_ADDR_COPY(wh->i_addr2, IF_LLADDR(ifp));=0A=
+	IEEE80211_ADDR_COPY(wh->i_addr2, ivp->macaddr);=0A=
 	IEEE80211_ADDR_COPY(wh->i_addr3, ifp->if_broadcastaddr);=0A=
 	*(uint16_t *)&wh->i_dur[0] =3D 0;	/* filled by HW */=0A=
 	*(uint16_t *)&wh->i_seq[0] =3D 0;	/* filled by HW */=0A=
@@ -5651,36 +5968,61 @@=0A=
 	chan->flags =3D 0;=0A=
 	if (ss->ss_nssid > 0)=0A=
 		chan->flags |=3D htole32(IWN_CHAN_NPBREQS(1));=0A=
-	chan->dsp_gain =3D 0x6e;=0A=
-	if (IEEE80211_IS_CHAN_5GHZ(c) &&=0A=
-	    !(c->ic_flags & IEEE80211_CHAN_PASSIVE)) {=0A=
-		chan->rf_gain =3D 0x3b;=0A=
-		chan->active  =3D htole16(24);=0A=
-		chan->passive =3D htole16(110);=0A=
-		chan->flags |=3D htole32(IWN_CHAN_ACTIVE);=0A=
-	} else if (IEEE80211_IS_CHAN_5GHZ(c)) {=0A=
-		chan->rf_gain =3D 0x3b;=0A=
-		chan->active  =3D htole16(24);=0A=
-		if (sc->rxon->associd)=0A=
-			chan->passive =3D htole16(78);=0A=
+		/*=0A=
+	 * If active scanning is requested but a certain channel is=0A=
+	 * marked passive, we can do active scanning if we detect=0A=
+	 * transmissions.=0A=
+	 *=0A=
+	 * There is an issue with some firmware versions that triggers=0A=
+	 * a sysassert on a "good CRC threshold" of zero (=3D=3D disabled),=0A=
+	 * on a radar channel even though this means that we should NOT=0A=
+	 * send probes.=0A=
+	 *=0A=
+	 * The "good CRC threshold" is the number of frames that we=0A=
+	 * need to receive during our dwell time on a channel before=0A=
+	 * sending out probes -- setting this to a huge value will=0A=
+	 * mean we never reach it, but at the same time work around=0A=
+	 * the aforementioned issue. Thus use IWN_SCAN_CRC_TH_NEVER=0A=
+	 * here instead of IWN_SCAN_CRC_TH_DISABLED.=0A=
+	 *=0A=
+	 * This was fixed in later versions along with some other=0A=
+	 * scan changes, and the threshold behaves as a flag in those=0A=
+	 * versions.=0A=
+	 */=0A=
+=0A=
+	channel =3D iwn_find_eeprom_channel(sc, c);=0A=
+	if (channel =3D=3D NULL) {=0A=
+		if_printf(ic->ic_ifp,=0A=
+		    "%s: invalid channel %u freq %u/0x%x\n",=0A=
+		    __func__, c->ic_ieee, c->ic_freq, c->ic_flags);=0A=
+		return EINVAL;=0A=
+	}=0A=
+=0A=
+	new_scan_threshold =3D ((sc->tlv_feature_flags &=0A=
+	    (1<<IWN_FW_TLV_FLAGS_NEW_SCAN_BITPOS)) >> =
IWN_FW_TLV_FLAGS_NEW_SCAN_BITPOS);=0A=
+=0A=
+	/* Selection criteria for Active/Passive scanning */=0A=
+	if ((ss->ss_nssid =3D=3D 0) || ((channel->flags & =
IWN_EEPROM_CHAN_ACTIVE) =3D=3D 0) ||=0A=
+	    (c->ic_flags & IEEE80211_CHAN_PASSIVE)) {=0A=
+		chan->flags |=3D htole32(IWN_CHAN_PASSIVE);=0A=
+		if (new_scan_threshold =3D=3D 1)=0A=
+			hdr->crc_threshold =3D IWN_SCAN_CRC_TH_DISABLED;=0A=
 		else=0A=
-			chan->passive =3D htole16(110);=0A=
-		hdr->crc_threshold =3D 0xffff;=0A=
-	} else if (!(c->ic_flags & IEEE80211_CHAN_PASSIVE)) {=0A=
-		chan->rf_gain =3D 0x28;=0A=
-		chan->active  =3D htole16(36);=0A=
-		chan->passive =3D htole16(120);=0A=
+			hdr->crc_threshold =3D IWN_SCAN_CRC_TH_NEVER;=0A=
+	} else {=0A=
 		chan->flags |=3D htole32(IWN_CHAN_ACTIVE);=0A=
-	} else {=0A=
-		chan->rf_gain =3D 0x28;=0A=
-		chan->active  =3D htole16(36);=0A=
-		if (sc->rxon->associd)=0A=
-			chan->passive =3D htole16(88);=0A=
-		else=0A=
-			chan->passive =3D htole16(120);=0A=
-		hdr->crc_threshold =3D 0xffff;=0A=
+		hdr->crc_threshold =3D IWN_SCAN_CRC_TH_DEFAULT;=0A=
 	}=0A=
 =0A=
+	chan->dsp_gain =3D 0x6e;=0A=
+		if (IEEE80211_IS_CHAN_5GHZ(c))=0A=
+		chan->rf_gain =3D 0x3b;=0A=
+	else=0A=
+		chan->rf_gain =3D 0x28;=0A=
+=0A=
+	chan->active  =3D htole16(iwn_get_active_dwell(sc, c));=0A=
+	chan->passive =3D htole16(iwn_get_passive_dwell(sc, c));=0A=
+=0A=
 	DPRINTF(sc, IWN_DEBUG_STATE,=0A=
 	    "%s: chan %u flags 0x%x rf_gain 0x%x "=0A=
 	    "dsp_gain 0x%x active 0x%x passive 0x%x\n", __func__,=0A=
@@ -5694,6 +6036,9 @@=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_STATE, "sending scan command nchan=3D%d\n",=0A=
 	    hdr->nchan);=0A=
+=0A=
+	sc->sc_scan_timer =3D IWN_SCAN_CHAN_TIMEOUT;=0A=
+=0A=
 	error =3D iwn_cmd(sc, IWN_CMD_SCAN, buf, buflen, 1);=0A=
 	free(buf, M_DEVBUF);=0A=
 =0A=
@@ -5781,9 +6126,18 @@=0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 =0A=
 	sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=0A=
+=0A=
+	if(sc->ctx =3D=3D IWN_RXON_PAN_CTX) {=0A=
+		if ((error =3D iwn_set_pan_params(sc)) !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+			   "%s: iwn_set_pan_params error %d\n", __func__, error);=0A=
+			return error;=0A=
+		}=0A=
+	}=0A=
+=0A=
 	if (ic->ic_opmode =3D=3D IEEE80211_M_MONITOR) {=0A=
 		/* Link LED blinks while monitoring. */=0A=
-		iwn_set_led(sc, IWN_LED_LINK, 5, 5);=0A=
+		iwn_set_led(sc, IWN_LED_LINK, 5, 5,IWN_LED_INT_BLINK);=0A=
 		return 0;=0A=
 	}=0A=
 	if ((error =3D iwn_set_timing(sc, ni)) !=3D 0) {=0A=
@@ -5877,6 +6231,7 @@=0A=
 		    "%s: could not add BSS node, error %d\n", __func__, error);=0A=
 		return error;=0A=
 	}=0A=
+	/*XXX Not done in iwl and lead to instability with 6235=0A=
 	DPRINTF(sc, IWN_DEBUG_STATE, "%s: setting link quality for node %d\n",=0A=
 	    __func__, node.id);=0A=
 	if ((error =3D iwn_set_link_quality(sc, ni)) !=3D 0) {=0A=
@@ -5892,18 +6247,26 @@=0A=
 		    error);=0A=
 		return error;=0A=
 	}=0A=
-	/* Start periodic calibration timer. */=0A=
+	// Start periodic calibration timer. =0A=
 	sc->calib.state =3D IWN_CALIB_STATE_ASSOC;=0A=
 	sc->calib_cnt =3D 0;=0A=
 	callout_reset(&sc->calib_to, msecs_to_ticks(500), iwn_calib_timeout,=0A=
 	    sc);=0A=
 =0A=
+	*/=0A=
+=0A=
 	/* Link LED always on while associated. */=0A=
-	iwn_set_led(sc, IWN_LED_LINK, 0, 1);=0A=
+	iwn_set_led(sc, IWN_LED_LINK, 0, 1,IWN_LED_STATIC_ON);=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
 =0A=
-	return 0;=0A=
+#ifdef IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP=0A=
+		return iwn_set_pslevel(sc, IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE,=0A=
+			sc->desired_pwrsave_level, 0);=0A=
+#else=0A=
+		return 0;=0A=
+#endif=0A=
+=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -6037,7 +6400,7 @@=0A=
 iwn_ampdu_tx_start(struct ieee80211com *ic, struct ieee80211_node *ni,=0A=
     uint8_t tid)=0A=
 {=0A=
-	struct ieee80211_tx_ampdu *tap =3D &ni->ni_tx_ampdu[tid];=0A=
+	struct ieee80211_tx_ampdu *tap =3D =
&ni->ni_tx_ampdu[TID_TO_WME_AC(tid)];=0A=
 	struct iwn_softc *sc =3D ni->ni_ic->ic_ifp->if_softc;=0A=
 	struct iwn_ops *ops =3D &sc->ops;=0A=
 	struct iwn_node *wn =3D (void *)ni;=0A=
@@ -6256,9 +6619,15 @@=0A=
 {=0A=
 	int idx, error;=0A=
 =0A=
-	for (idx =3D 0; idx < 5; idx++) {=0A=
-		if (sc->calibcmd[idx].buf =3D=3D NULL)=0A=
-			continue;	/* No results available. */=0A=
+	for (idx =3D 0; idx < IWN5000_PHY_CALIB_MAX_RESULT  ; idx++) {=0A=
+		if (!(sc->base_params->calib_need & (1<<idx))) {=0A=
+			DPRINTF(sc,IWN_DEBUG_CALIBRATE, "No need of calib %d\n",idx);=0A=
+			continue; /* no need for this calib */=0A=
+		}=0A=
+		if (sc->calibcmd[idx].buf =3D=3D NULL) {=0A=
+			DPRINTF(sc, IWN_DEBUG_CALIBRATE, "Need calib idx : %d but no =
available data\n",idx);=0A=
+			continue;=0A=
+		}=0A=
 		DPRINTF(sc, IWN_DEBUG_CALIBRATE,=0A=
 		    "send calibration result idx=3D%d len=3D%d\n", idx,=0A=
 		    sc->calibcmd[idx].len);=0A=
@@ -6335,6 +6704,32 @@=0A=
 	return iwn_cmd(sc, IWN_CMD_PHY_CALIB, &cmd, sizeof cmd, 0);=0A=
 }=0A=
 =0A=
+static int=0A=
+iwn5000_temp_offset_calibv2(struct iwn_softc *sc)=0A=
+{=0A=
+	struct iwn5000_phy_calib_temp_offsetv2 cmd;=0A=
+=0A=
+	memset(&cmd, 0, sizeof cmd);=0A=
+	cmd.code =3D IWN5000_PHY_CALIB_TEMP_OFFSET;=0A=
+	cmd.ngroups =3D 1;=0A=
+	cmd.isvalid =3D 1;=0A=
+	if (sc->eeprom_temp !=3D 0) {=0A=
+		cmd.offset_low =3D htole16(sc->eeprom_temp);=0A=
+		cmd.offset_high =3D htole16(sc->eeprom_temp_high);=0A=
+	} else {=0A=
+		cmd.offset_low =3D htole16(IWN_DEFAULT_TEMP_OFFSET);=0A=
+		cmd.offset_high =3D htole16(IWN_DEFAULT_TEMP_OFFSET);=0A=
+	}=0A=
+	cmd.burnt_voltage_ref =3D htole16(sc->eeprom_voltage);=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_CALIBRATE, "setting radio sensor low offset to =
%d, high offset to %d, voltage to %d\n",=0A=
+	    le16toh(cmd.offset_low),=0A=
+		le16toh(cmd.offset_high),=0A=
+		le16toh(cmd.burnt_voltage_ref));=0A=
+=0A=
+	return iwn_cmd(sc, IWN_CMD_PHY_CALIB, &cmd, sizeof cmd, 0);=0A=
+}=0A=
+=0A=
 /*=0A=
  * This function is called after the runtime firmware notifies us of its=0A=
  * readiness (called in a process context).=0A=
@@ -6420,7 +6815,11 @@=0A=
 	IWN_SETBITS(sc, IWN_FH_TX_CHICKEN, IWN_FH_TX_CHICKEN_SCHED_RETRY);=0A=
 =0A=
 	/* Enable chain mode for all queues, except command queue. */=0A=
-	iwn_prph_write(sc, IWN5000_SCHED_QCHAIN_SEL, 0xfffef);=0A=
+	if(sc->sc_flags & IWN_FLAG_PAN_SUPPORT)=0A=
+		iwn_prph_write(sc, IWN5000_SCHED_QCHAIN_SEL, 0xffdff);=0A=
+	else=0A=
+		iwn_prph_write(sc, IWN5000_SCHED_QCHAIN_SEL, 0xfffef);=0A=
+=0A=
 	iwn_prph_write(sc, IWN5000_SCHED_AGGR_SEL, 0);=0A=
 =0A=
 	for (qid =3D 0; qid < IWN5000_NTXQUEUES; qid++) {=0A=
@@ -6440,32 +6839,29 @@=0A=
 	/* Identify TX FIFO rings (0-7). */=0A=
 	iwn_prph_write(sc, IWN5000_SCHED_TXFACT, 0xff);=0A=
 =0A=
-	/* Mark TX rings (4 EDCA + cmd + 2 HCCA) as active. */=0A=
-	for (qid =3D 0; qid < 7; qid++) {=0A=
-		static uint8_t qid2fifo[] =3D { 3, 2, 1, 0, 7, 5, 6 };=0A=
-		iwn_prph_write(sc, IWN5000_SCHED_QUEUE_STATUS(qid),=0A=
-		    IWN5000_TXQ_STATUS_ACTIVE | qid2fifo[qid]);=0A=
+	if(sc->sc_flags & IWN_FLAG_PAN_SUPPORT) {=0A=
+		/* Mark TX rings as active. */=0A=
+		for (qid =3D 0; qid < 11; qid++) {=0A=
+			static uint8_t qid2fifo[] =3D { 3, 2, 1, 0, 0, 4, 2, 5, 4, 7, 5 };=0A=
+			iwn_prph_write(sc, IWN5000_SCHED_QUEUE_STATUS(qid),=0A=
+			    IWN5000_TXQ_STATUS_ACTIVE | qid2fifo[qid]);=0A=
+		}=0A=
+	} else {=0A=
+		/* Mark TX rings (4 EDCA + cmd + 2 HCCA) as active. */=0A=
+		for (qid =3D 0; qid < 7; qid++) {=0A=
+			static uint8_t qid2fifo[] =3D { 3, 2, 1, 0, 7, 5, 6 };=0A=
+			iwn_prph_write(sc, IWN5000_SCHED_QUEUE_STATUS(qid),=0A=
+				IWN5000_TXQ_STATUS_ACTIVE | qid2fifo[qid]);=0A=
+		}=0A=
 	}=0A=
 	iwn_nic_unlock(sc);=0A=
 =0A=
-	/* Configure WiMAX coexistence for combo adapters. */=0A=
-	error =3D iwn5000_send_wimax_coex(sc);=0A=
-	if (error !=3D 0) {=0A=
-		device_printf(sc->sc_dev,=0A=
-		    "%s: could not configure WiMAX coexistence, error %d\n",=0A=
-		    __func__, error);=0A=
+=0A=
+	if ((error=3Diwn_cfg_ucode_post_alive(sc))!=3D0) {=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end in error\n", __func__);=0A=
 		return error;=0A=
 	}=0A=
-	if (sc->hw_type !=3D IWN_HW_REV_TYPE_5150) {=0A=
-		/* Perform crystal calibration. */=0A=
-		error =3D iwn5000_crystal_calib(sc);=0A=
-		if (error !=3D 0) {=0A=
-			device_printf(sc->sc_dev,=0A=
-			    "%s: crystal calibration failed, error %d\n",=0A=
-			    __func__, error);=0A=
-			return error;=0A=
-		}=0A=
-	}=0A=
+=0A=
 	if (!(sc->sc_flags & IWN_FLAG_CALIB_DONE)) {=0A=
 		/* Query calibration from the initialization firmware. */=0A=
 		if ((error =3D iwn5000_query_calibration(sc)) !=3D 0) {=0A=
@@ -6474,6 +6870,7 @@=0A=
 			    __func__, error);=0A=
 			return error;=0A=
 		}=0A=
+=0A=
 		/*=0A=
 		 * We have the calibration results now, reboot with the=0A=
 		 * runtime firmware (call ourselves recursively!)=0A=
@@ -6957,9 +7354,8 @@=0A=
 	else=0A=
 		IWN_CLRBITS(sc, IWN_GIO, IWN_GIO_L0S_ENA);=0A=
 =0A=
-	if (sc->hw_type !=3D IWN_HW_REV_TYPE_4965 &&=0A=
-	    sc->hw_type <=3D IWN_HW_REV_TYPE_1000)=0A=
-		IWN_SETBITS(sc, IWN_ANA_PLL, IWN_ANA_PLL_INIT);=0A=
+	if (sc->base_params->pll_cfg_val)=0A=
+		IWN_SETBITS(sc, IWN_ANA_PLL, sc->base_params->pll_cfg_val);=0A=
 =0A=
 	/* Wait for clock stabilization before accessing prph. */=0A=
 	if ((error =3D iwn_clock_wait(sc)) !=3D 0)=0A=
@@ -7071,13 +7467,12 @@=0A=
 		/* Use internal power amplifier only. */=0A=
 		IWN_WRITE(sc, IWN_GP_DRIVER, IWN_GP_DRIVER_RADIO_2X2_IPA);=0A=
 	}=0A=
-	if ((sc->hw_type =3D=3D IWN_HW_REV_TYPE_6050 ||=0A=
-	     sc->hw_type =3D=3D IWN_HW_REV_TYPE_6005) && sc->calib_ver >=3D 6) =
{=0A=
+	if (sc->base_params->additional_nic_config && sc->calib_ver >=3D 6) {=0A=
 		/* Indicate that ROM calibration version is >=3D6. */=0A=
 		IWN_SETBITS(sc, IWN_GP_DRIVER, IWN_GP_DRIVER_CALIB_VER6);=0A=
 	}=0A=
-	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_6005)=0A=
-		IWN_SETBITS(sc, IWN_GP_DRIVER, IWN_GP_DRIVER_6050_1X2);=0A=
+	if (sc->base_params->additional_gp_drv_bit) =0A=
+		IWN_SETBITS(sc, IWN_GP_DRIVER, =
sc->base_params->additional_gp_drv_bit);=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -7212,7 +7607,7 @@=0A=
 	IWN_WRITE(sc, IWN_UCODE_GP1_CLR, IWN_UCODE_GP1_RFKILL);=0A=
 =0A=
 	/* Enable shadow registers. */=0A=
-	if (sc->hw_type >=3D IWN_HW_REV_TYPE_6000)=0A=
+	if (sc->base_params->shadow_reg_enable)=0A=
 		IWN_SETBITS(sc, IWN_SHADOW_REG_CTRL, 0x800fffff);=0A=
 =0A=
 	if ((error =3D ops->load_firmware(sc)) !=3D 0) {=0A=
@@ -7283,6 +7678,12 @@=0A=
 		iwn_nic_unlock(sc);=0A=
 	}=0A=
 	DELAY(5);=0A=
+=0A=
+	if (sc->sc_led.led_cur_mode !=3D IWN_LED_STATIC_OFF) {=0A=
+		sc->sc_led.led_cur_mode =3D IWN_LED_STATIC_OFF;=0A=
+		iwn_set_led(sc, IWN_LED_LINK, 1, 0, IWN_LED_STATIC_OFF);=0A=
+	}=0A=
+=0A=
 	/* Power OFF adapter. */=0A=
 	iwn_apm_stop(sc);=0A=
 }=0A=
@@ -7331,7 +7732,6 @@=0A=
 	int error;=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
 	if ((error =3D iwn_hw_prepare(sc)) !=3D 0) {=0A=
@@ -7417,6 +7817,7 @@=0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
 	sc->sc_tx_timer =3D 0;=0A=
+	sc->sc_scan_timer =3D 0;=0A=
 	callout_stop(&sc->watchdog_to);=0A=
 	callout_stop(&sc->calib_to);=0A=
 	ifp->if_drv_flags &=3D ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);=0A=
@@ -7441,10 +7842,23 @@=0A=
 {=0A=
 	struct ifnet *ifp =3D ic->ic_ifp;=0A=
 	struct iwn_softc *sc =3D ifp->if_softc;=0A=
+	struct ieee80211_scan_state *ss =3D ic->ic_scan;=0A=
+	struct ieee80211vap *vap =3D ss->ss_vap;=0A=
 =0A=
 	IWN_LOCK(sc);=0A=
+=0A=
+	sc->uc_scan_progress =3D 1;=0A=
+	if(sc->ctx =3D=3D IWN_RXON_PAN_CTX)=0A=
+		iwn_set_pan_params(sc);=0A=
+=0A=
 	/* make the link LED blink while we're scanning */=0A=
-	iwn_set_led(sc, IWN_LED_LINK, 20, 2);=0A=
+	if (vap->iv_state  !=3D IEEE80211_S_RUN) {=0A=
+		if(sc->sc_led.led_cur_mode !=3D IWN_LED_SLOW_BLINK) {=0A=
+			sc->sc_led.led_cur_mode =3D IWN_LED_SLOW_BLINK;=0A=
+			iwn_set_led(sc, IWN_LED_LINK, 190, 10,IWN_LED_SLOW_BLINK);=0A=
+		}=0A=
+	}=0A=
+=0A=
 	IWN_UNLOCK(sc);=0A=
 }=0A=
 =0A=
@@ -7456,12 +7870,19 @@=0A=
 {=0A=
 	struct ifnet *ifp =3D ic->ic_ifp;=0A=
 	struct iwn_softc *sc =3D ifp->if_softc;=0A=
-	struct ieee80211vap *vap =3D TAILQ_FIRST(&ic->ic_vaps);=0A=
+	struct ieee80211_scan_state *ss =3D ic->ic_scan;=0A=
+	struct ieee80211vap *vap =3D ss->ss_vap;=0A=
 =0A=
 	IWN_LOCK(sc);=0A=
+=0A=
+	sc->uc_scan_progress =3D 0;=0A=
+	sc->sc_scan_timer =3D 0;=0A=
+	if(sc->ctx =3D=3D IWN_RXON_PAN_CTX)=0A=
+		iwn_set_pan_params(sc);=0A=
+=0A=
 	if (vap->iv_state =3D=3D IEEE80211_S_RUN) {=0A=
-		/* Set link LED to ON status if we are associated */=0A=
-		iwn_set_led(sc, IWN_LED_LINK, 0, 1);=0A=
+		sc->sc_led.led_cur_mode =3D IWN_LED_STATIC_ON;=0A=
+		iwn_set_led(sc, IWN_LED_LINK, 0, 1,IWN_LED_STATIC_ON);=0A=
 	}=0A=
 	IWN_UNLOCK(sc);=0A=
 }=0A=
@@ -7509,10 +7930,14 @@=0A=
 	int error;=0A=
 =0A=
 	IWN_LOCK(sc);=0A=
+	sc->sc_scan_timer =3D 0;=0A=
 	error =3D iwn_scan(sc);=0A=
 	IWN_UNLOCK(sc);=0A=
-	if (error !=3D 0)=0A=
+	if (error !=3D 0) {=0A=
+		sc->uc_scan_progress =3D 0;=0A=
+		sc->sc_scan_timer =3D 0;=0A=
 		ieee80211_cancel_scan(vap);=0A=
+	}=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -7621,3 +8046,1058 @@=0A=
 	DPRINTF(sc, IWN_DEBUG_REGISTER,"%s","\n");=0A=
 }=0A=
 #endif=0A=
+=0A=
+/*=0A=
+ * Define specific configuration based on device id and subdevice id=0A=
+ * pid : PCI device id=0A=
+ */=0A=
+static int=0A=
+iwn_config_specific(struct iwn_softc *sc,uint16_t pid)=0A=
+{=0A=
+	switch(pid) {=0A=
+/* 1000 Series */=0A=
+	case IWN_DID_1000_1:=0A=
+	case IWN_DID_1000_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case	IWN_SDID_1000_1:=0A=
+			case	IWN_SDID_1000_2:=0A=
+			case	IWN_SDID_1000_3:=0A=
+			case	IWN_SDID_1000_4:=0A=
+			case	IWN_SDID_1000_5:=0A=
+			case	IWN_SDID_1000_6:=0A=
+			case	IWN_SDID_1000_7:=0A=
+			case	IWN_SDID_1000_8:=0A=
+			case	IWN_SDID_1000_9:=0A=
+			case	IWN_SDID_1000_10:=0A=
+			case	IWN_SDID_1000_11:=0A=
+			case	IWN_SDID_1000_12:=0A=
+				sc->limits =3D &iwn1000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_1000_base_params; =0A=
+				sc->fwname =3D "iwn1000fw";=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6x00 Series */=0A=
+	case IWN_DID_6x00_2:=0A=
+	case IWN_DID_6x00_4:=0A=
+	case IWN_DID_6x00_1:=0A=
+	case IWN_DID_6x00_3:=0A=
+		sc->fwname =3D "iwn6000fw";=0A=
+		sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+		switch(sc->subdevice_id) {=0A=
+=0A=
+		case IWN_SDID_6x00_1:=0A=
+		case IWN_SDID_6x00_2:=0A=
+		case IWN_SDID_6x00_8:=0A=
+			//iwl6000_3agn_cfg=0A=
+			sc->base_params =3D &iwn_6000_base_params;=0A=
+			break;=0A=
+		case IWN_SDID_6x00_3:=0A=
+		case IWN_SDID_6x00_6:=0A=
+		case IWN_SDID_6x00_9:=0A=
+			////iwl6000i_2agn=0A=
+		case IWN_SDID_6x00_4:=0A=
+		case IWN_SDID_6x00_7:=0A=
+		case IWN_SDID_6x00_10:=0A=
+			//iwl6000i_2abg_cfg=0A=
+		case IWN_SDID_6x00_5:=0A=
+			//iwl6000i_2bg_cfg=0A=
+			sc->base_params =3D &iwn_6000i_base_params;=0A=
+			sc->sc_flags |=3D IWN_FLAG_INTERNAL_PA;=0A=
+			sc->txchainmask =3D IWN_ANT_BC;=0A=
+			sc->rxchainmask =3D IWN_ANT_BC;=0A=
+			break;=0A=
+		default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6x05 Series */=0A=
+	case IWN_DID_6x05_1:  =0A=
+	case IWN_DID_6x05_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_6x05_1:=0A=
+			case IWN_SDID_6x05_4:=0A=
+			case IWN_SDID_6x05_6:=0A=
+				//iwl6005_2agn_cfg=0A=
+			case IWN_SDID_6x05_2:=0A=
+			case IWN_SDID_6x05_5:=0A=
+			case IWN_SDID_6x05_7:=0A=
+				//iwl6005_2abg_cfg=0A=
+			case IWN_SDID_6x05_3:=0A=
+				//iwl6005_2bg_cfg=0A=
+			case IWN_SDID_6x05_8:=0A=
+			case IWN_SDID_6x05_9:=0A=
+				//iwl6005_2agn_sff_cfg=0A=
+			case IWN_SDID_6x05_10:=0A=
+				//iwl6005_2agn_d_cfg=0A=
+			case IWN_SDID_6x05_11:=0A=
+				//iwl6005_2agn_mow1_cfg=0A=
+			case IWN_SDID_6x05_12:=0A=
+				//iwl6005_2agn_mow2_cfg=0A=
+				sc->fwname =3D "iwn6000g2afw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6000g2_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6x35 Series */=0A=
+	case IWN_DID_6035_1:=0A=
+	case IWN_DID_6035_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_6035_1:=0A=
+			case IWN_SDID_6035_2:=0A=
+			case IWN_SDID_6035_3:=0A=
+			case IWN_SDID_6035_4:=0A=
+				sc->fwname =3D "iwn6000g2bfw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6000g2b_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6x50 WiFi/WiMax Series */=0A=
+	case IWN_DID_6050_1:=0A=
+	case IWN_DID_6050_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_6050_1:=0A=
+			case IWN_SDID_6050_3:=0A=
+			case IWN_SDID_6050_5:=0A=
+				//iwl6050_2agn_cfg=0A=
+			case IWN_SDID_6050_2:=0A=
+			case IWN_SDID_6050_4:=0A=
+			case IWN_SDID_6050_6:=0A=
+				//iwl6050_2abg_cfg=0A=
+				sc->fwname =3D "iwn6050fw";=0A=
+				sc->txchainmask =3D IWN_ANT_AB;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6050_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6150 WiFi/WiMax Series */=0A=
+	case IWN_DID_6150_1:=0A=
+	case IWN_DID_6150_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_6150_1:=0A=
+			case IWN_SDID_6150_3:=0A=
+			case IWN_SDID_6150_5:=0A=
+				// iwl6150_bgn_cfg=0A=
+			case IWN_SDID_6150_2:=0A=
+			case IWN_SDID_6150_4:=0A=
+			case IWN_SDID_6150_6:=0A=
+				//iwl6150_bg_cfg=0A=
+				sc->fwname =3D "iwn6050fw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6150_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6030 Series and 1030 Series */=0A=
+	case IWN_DID_x030_1:=0A=
+	case IWN_DID_x030_2:=0A=
+	case IWN_DID_x030_3:=0A=
+	case IWN_DID_x030_4:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_x030_1:=0A=
+			case IWN_SDID_x030_3:=0A=
+			case IWN_SDID_x030_5:=0A=
+			// iwl1030_bgn_cfg=0A=
+	=0A=
+			case IWN_SDID_x030_2:=0A=
+			case IWN_SDID_x030_4:=0A=
+			case IWN_SDID_x030_6:=0A=
+			//iwl1030_bg_cfg=0A=
+	=0A=
+			case IWN_SDID_x030_7:=0A=
+			case IWN_SDID_x030_10:=0A=
+			case IWN_SDID_x030_14:=0A=
+			//iwl6030_2agn_cfg=0A=
+	=0A=
+			case IWN_SDID_x030_8:=0A=
+			case IWN_SDID_x030_11:=0A=
+			case IWN_SDID_x030_15:=0A=
+			// iwl6030_2bgn_cfg=0A=
+	=0A=
+			case IWN_SDID_x030_9:=0A=
+			case IWN_SDID_x030_12:=0A=
+			case IWN_SDID_x030_16:=0A=
+			// iwl6030_2abg_cfg=0A=
+	=0A=
+			case IWN_SDID_x030_13:=0A=
+			//iwl6030_2bg_cfg=0A=
+				sc->fwname =3D "iwn6000g2bfw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6000g2b_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 130 Series WiFi */=0A=
+/* XXX: This series will need adjustement for rate see =
rx_with_siso_diversity in linux kernel */=0A=
+	case IWN_DID_130_1:=0A=
+	case IWN_DID_130_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_130_1: =0A=
+			case IWN_SDID_130_3:=0A=
+			case IWN_SDID_130_5:=0A=
+			//iwl130_bgn_cfg=0A=
+			case IWN_SDID_130_2:=0A=
+			case IWN_SDID_130_4:=0A=
+			case IWN_SDID_130_6:=0A=
+			//iwl130_bg_cfg=0A=
+				sc->fwname =3D "iwn6000g2bfw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6000g2b_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 100 Series WiFi */=0A=
+	case IWN_DID_100_1:=0A=
+	case IWN_DID_100_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_100_1:=0A=
+			case IWN_SDID_100_2:=0A=
+			case IWN_SDID_100_3:=0A=
+			case IWN_SDID_100_4:=0A=
+			case IWN_SDID_100_5:=0A=
+			case IWN_SDID_100_6:=0A=
+				sc->limits =3D &iwn1000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_1000_base_params; =0A=
+				sc->fwname =3D "iwn100fw";=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+=0A=
+/* 2x30 Series */=0A=
+	case IWN_DID_2x30_1:=0A=
+	case IWN_DID_2x30_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_2x30_1:=0A=
+			case IWN_SDID_2x30_3:=0A=
+			case IWN_SDID_2x30_5:=0A=
+			//iwl100_bgn_cfg=0A=
+			case IWN_SDID_2x30_2:=0A=
+			case IWN_SDID_2x30_4:=0A=
+			case IWN_SDID_2x30_6:=0A=
+			//iwl100_bg_cfg=0A=
+				sc->limits =3D &iwn2030_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn2030_base_params; =0A=
+				sc->fwname =3D "iwn2030fw";=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 5x00 Series */=0A=
+	case IWN_DID_5x00_1:=0A=
+	case IWN_DID_5x00_2:=0A=
+	case IWN_DID_5x00_3:=0A=
+	case IWN_DID_5x00_4:=0A=
+		sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+		sc->base_params =3D &iwn_default_base_params; =0A=
+		sc->fwname =3D "iwn5000fw";=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_5x00_1:=0A=
+			case IWN_SDID_5x00_2:=0A=
+			case IWN_SDID_5x00_3:=0A=
+			case IWN_SDID_5x00_4:=0A=
+			case IWN_SDID_5x00_9:=0A=
+			case IWN_SDID_5x00_10:=0A=
+			case IWN_SDID_5x00_11:=0A=
+			case IWN_SDID_5x00_12:=0A=
+			case IWN_SDID_5x00_17:=0A=
+			case IWN_SDID_5x00_18:=0A=
+			case IWN_SDID_5x00_19:=0A=
+			case IWN_SDID_5x00_20:=0A=
+			//iwl5100_agn_cfg=0A=
+				sc->txchainmask =3D IWN_ANT_B;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				break;	=0A=
+			case IWN_SDID_5x00_5:=0A=
+			case IWN_SDID_5x00_6:=0A=
+			case IWN_SDID_5x00_13:=0A=
+			case IWN_SDID_5x00_14:=0A=
+			case IWN_SDID_5x00_21:=0A=
+			case IWN_SDID_5x00_22:=0A=
+			//iwl5100_bgn_cfg=0A=
+				sc->txchainmask =3D IWN_ANT_B;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				break;=0A=
+			case IWN_SDID_5x00_7:=0A=
+			case IWN_SDID_5x00_8:=0A=
+			case IWN_SDID_5x00_15:=0A=
+			case IWN_SDID_5x00_16:=0A=
+			case IWN_SDID_5x00_23:=0A=
+			case IWN_SDID_5x00_24:=0A=
+			//iwl5100_abg_cfg=0A=
+				sc->txchainmask =3D IWN_ANT_B;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				break;=0A=
+	=0A=
+			case IWN_SDID_5x00_25:=0A=
+			case IWN_SDID_5x00_26:=0A=
+			case IWN_SDID_5x00_27:=0A=
+			case IWN_SDID_5x00_28:=0A=
+			case IWN_SDID_5x00_29:=0A=
+			case IWN_SDID_5x00_30:=0A=
+			case IWN_SDID_5x00_31:=0A=
+			case IWN_SDID_5x00_32:=0A=
+			case IWN_SDID_5x00_33:=0A=
+			case IWN_SDID_5x00_34:=0A=
+			case IWN_SDID_5x00_35:=0A=
+			case IWN_SDID_5x00_36:=0A=
+			//iwl5300_agn_cfg=0A=
+				sc->txchainmask =3D IWN_ANT_ABC;=0A=
+				sc->rxchainmask =3D IWN_ANT_ABC;=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 5x50 Series */=0A=
+	case IWN_DID_5x50_1:=0A=
+	case IWN_DID_5x50_2:=0A=
+	case IWN_DID_5x50_3:=0A=
+	case IWN_DID_5x50_4:=0A=
+		sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+		sc->base_params =3D &iwn_default_base_params; =0A=
+		sc->fwname =3D "iwn5000fw";=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_5x50_1:=0A=
+			case IWN_SDID_5x50_2:=0A=
+			case IWN_SDID_5x50_3:=0A=
+			//iwl5350_agn_cfg=0A=
+				sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_default_base_params; =0A=
+				sc->fwname =3D "iwn5000fw";=0A=
+			break;=0A=
+=0A=
+			case IWN_SDID_5x50_4:=0A=
+			case IWN_SDID_5x50_5:=0A=
+			case IWN_SDID_5x50_8:=0A=
+			case IWN_SDID_5x50_9:=0A=
+			case IWN_SDID_5x50_10:=0A=
+			case IWN_SDID_5x50_11:=0A=
+			//iwl5150_agn_cfg=0A=
+			case IWN_SDID_5x50_6:=0A=
+			case IWN_SDID_5x50_7:=0A=
+			case IWN_SDID_5x50_12:=0A=
+			case IWN_SDID_5x50_13:=0A=
+			//iwl5150_abg_cfg=0A=
+				sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+				sc->fwname =3D "iwn5150fw";=0A=
+				sc->base_params =3D &iwn_5x50_base_params;=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+	default:=0A=
+			device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev 0x%08x not supported (device) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+			return ENOTSUP;=0A=
+	}=0A=
+	return 0;=0A=
+}=0A=
+/*=0A=
+ *	Send IWN_CMD_GET_STATISTICS to ucode.=0A=
+ *  @enable: activate sending statistics from uCode=0A=
+ *	@clear : ask uCode to clear internal counter=0A=
+ *	@async : Sync mode for command (1=3D ASYNC, 0=3DSYNC)=0A=
+*/=0A=
+static int =0A=
+iwn_set_statistics_request(struct iwn_softc *sc,bool enable,bool =
clear,int async)=0A=
+{=0A=
+	struct iwn_statistics_cmd cmd;=0A=
+=0A=
+	if (enable) =0A=
+		cmd.configuration_flags=3D clear ? IWN_STATS_CONF_CLEAR_STATS :0;=0A=
+	else=0A=
+		cmd.configuration_flags=3D IWN_STATS_CONF_DISABLE_NOTIF;=0A=
+=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s: sending request for statistics =
flags : 0x%x\n",=0A=
+	    __func__,cmd.configuration_flags);=0A=
+	return iwn_cmd(sc, IWN_CMD_GET_STATISTICS, &cmd, sizeof cmd, async ? =
1:0);=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_cfg_ucode_post_alive(struct iwn_softc *sc)=0A=
+{=0A=
+	int error;=0A=
+=0A=
+	/* Configure WiMAX coexistence for combo adapters. */=0A=
+	error =3D iwn5000_send_wimax_coex(sc);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not configure WiMAX coexistence, error %d\n",=0A=
+		    __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	if (!(sc->base_params->no_crystal_calibration)) {=0A=
+		DPRINTF(sc, IWN_DEBUG_RESET, "Doing calib in %s\n",__func__);=0A=
+		error =3D iwn5000_crystal_calib(sc);=0A=
+		if (error !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+				"%s: crystal calibration failed, error %d\n",=0A=
+				__func__, error);=0A=
+			return error;=0A=
+		}=0A=
+	} else {=0A=
+		DPRINTF(sc, IWN_DEBUG_RESET, "Crystal calibration disable in =
%s\n",__func__);=0A=
+	}=0A=
+=0A=
+	return 0;=0A=
+}=0A=
+//----------------- NEW----------------------=0A=
+/*=0A=
+ * Handles ioctl change requests for power management state etc.=0A=
+ */=0A=
+static int iwn_iv_reset(struct ieee80211vap *vap, u_long cmd)=0A=
+{=0A=
+	int error =3D 0;=0A=
+	switch (cmd) {=0A=
+	case IEEE80211_IOC_POWERSAVE:{=0A=
+		struct iwn_softc * sc =3D (struct iwn_softc *)=0A=
+				(vap->iv_ic->ic_ifp->if_softc);=0A=
+		IWN_LOCK(sc);=0A=
+=0A=
+		/* XXX to discuss */=0A=
+		int dtim =3D IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE;=0A=
+=0A=
+		int async =3D 0;=0A=
+=0A=
+		/*=0A=
+		 * At present the powersave level is set to 0 (receiver=0A=
+		 * continuously on) if power save is disabled, and set to=0A=
+		 * IWN_POWERSAVE_LVL_VOIP_COMPATIBLE otherwise.=0A=
+		 * Later the power levels 0-5 could be exposed to the user.=0A=
+		 */=0A=
+		if (vap->iv_flags & IEEE80211_F_PMGTON) {=0A=
+			/*=0A=
+			 * In ieee80211_vap_setup() we have:=0A=
+			 *  vap->iv_flags =3D ic->ic_flags;=0A=
+			 * i.e. any vap's iv_flags initialize to ic->ic_flags.=0A=
+			 * Setting the flags on ic will allow a vap to get=0A=
+			 * the correct powersave level once it is created.=0A=
+			 */=0A=
+			vap->iv_ic->ic_flags |=3D IEEE80211_F_PMGTON;=0A=
+			sc->desired_pwrsave_level =3D=0A=
+					IWN_POWERSAVE_LVL_VOIP_COMPATIBLE;=0A=
+		} else {=0A=
+			vap->iv_ic->ic_flags &=3D ~IEEE80211_F_PMGTON;=0A=
+			sc->desired_pwrsave_level =3D IWN_POWERSAVE_LVL_NONE;=0A=
+		}=0A=
+		error =3D iwn_set_pslevel(sc, dtim, sc->desired_pwrsave_level,=0A=
+				async);=0A=
+		IWN_UNLOCK(sc);=0A=
+		}=0A=
+		break;=0A=
+	default:=0A=
+		/*=0A=
+		 * For unhandled ioctls, ENETRESET has to be passed back to=0A=
+		 * net80211 layer, which will in turn call the function to=0A=
+		 * reinitialize the entire device.=0A=
+		 */=0A=
+		error =3D ENETRESET;=0A=
+		break;=0A=
+	}=0A=
+	return error;=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_newstate_u1(struct ieee80211vap *vap, enum ieee80211_state nstate, =
int arg)=0A=
+{=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+	struct ieee80211com *ic =3D vap->iv_ic;=0A=
+	struct iwn_softc *sc =3D ic->ic_ifp->if_softc;=0A=
+=0A=
+	int error =3D 0;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_STATE, "%s: %s -> %s\n", __func__,=0A=
+	    ieee80211_state_name[vap->iv_state], ieee80211_state_name[nstate]);=0A=
+=0A=
+	IEEE80211_UNLOCK(ic);=0A=
+	IWN_LOCK(sc);=0A=
+	callout_stop(&sc->calib_to);=0A=
+=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+=0A=
+	switch (nstate) {=0A=
+	case IEEE80211_S_ASSOC:=0A=
+		if (vap->iv_state !=3D IEEE80211_S_RUN)=0A=
+			break;=0A=
+		/* FALLTHROUGH */=0A=
+	case IEEE80211_S_AUTH:=0A=
+		if (vap->iv_state =3D=3D IEEE80211_S_AUTH)=0A=
+			break;=0A=
+=0A=
+		/*=0A=
+		 * !AUTH -> AUTH transition requires state reset to handle=0A=
+		 * reassociations correctly.=0A=
+		 */=0A=
+		sc->rxon->associd =3D 0;=0A=
+		sc->rxon->filter &=3D ~htole32(IWN_FILTER_BSS);=0A=
+		sc->calib.state =3D IWN_CALIB_STATE_INIT;=0A=
+=0A=
+		if ((error =3D iwn_auth_u1(sc, vap)) !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+			    "%s: could not move to auth state\n", __func__);=0A=
+		}=0A=
+		break;=0A=
+=0A=
+	case IEEE80211_S_SCAN:=0A=
+=0A=
+=0A=
+		if ((error =3D iwn_set_timing_u1(sc)) !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+			    "%s: iwn_set_timing_u1 error %d\n", __func__, error);=0A=
+			return error;=0A=
+		}=0A=
+=0A=
+		break;=0A=
+=0A=
+	case IEEE80211_S_RUN:=0A=
+=0A=
+		/*=0A=
+		 * RUN -> RUN transition; Just restart the timers.=0A=
+		 */=0A=
+		if (vap->iv_state =3D=3D IEEE80211_S_RUN) {=0A=
+			sc->calib_cnt =3D 0;=0A=
+			break;=0A=
+		}=0A=
+=0A=
+		/*=0A=
+		 * !RUN -> RUN requires setting the association id=0A=
+		 * which is done with a firmware cmd.  We also defer=0A=
+		 * starting the timers until that work is done.=0A=
+		 */=0A=
+		if ((error =3D iwn_run_u1(sc, vap)) !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+			    "%s: could not move to run state\n", __func__);=0A=
+		}=0A=
+		break;=0A=
+=0A=
+	case IEEE80211_S_INIT:=0A=
+		sc->calib.state =3D IWN_CALIB_STATE_INIT;=0A=
+		break;=0A=
+=0A=
+	default:=0A=
+		break;=0A=
+	}=0A=
+	IWN_UNLOCK(sc);=0A=
+	IEEE80211_LOCK(ic);=0A=
+	if (error !=3D 0) {=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end in error\n", __func__);=0A=
+		return error;=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	return ivp->iv_newstate(vap, nstate, arg);=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_auth_u1(struct iwn_softc *sc, struct ieee80211vap *vap)=0A=
+{=0A=
+	struct iwn_ops *ops =3D &sc->ops;=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	struct ieee80211_node *ni =3D vap->iv_bss;=0A=
+	int error;=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->myaddr, ivp->macaddr);=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->wlap, IF_LLADDR(ifp));=0A=
+	/* Update adapter configuration. */=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->bssid, ni->ni_bssid);=0A=
+	sc->rxon->chan =3D ieee80211_chan2ieee(ic, ni->ni_chan);=0A=
+	sc->rxon->flags =3D htole32(IWN_RXON_TSF | IWN_RXON_CTS_TO_SELF);=0A=
+	if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan))=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);=0A=
+	if (ic->ic_flags & IEEE80211_F_SHSLOT)=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_SHSLOT);=0A=
+	if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_SHPREAMBLE);=0A=
+	if (IEEE80211_IS_CHAN_A(ni->ni_chan)) {=0A=
+		sc->rxon->cck_mask  =3D 0;=0A=
+		sc->rxon->ofdm_mask =3D 0x15;=0A=
+	} else if (IEEE80211_IS_CHAN_B(ni->ni_chan)) {=0A=
+		sc->rxon->cck_mask  =3D 0x03;=0A=
+		sc->rxon->ofdm_mask =3D 0;=0A=
+	} else {=0A=
+		/* Assume 802.11b/g. */=0A=
+		sc->rxon->cck_mask  =3D 0x0f;=0A=
+		sc->rxon->ofdm_mask =3D 0x15;=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_STATE, "rxon chan %d flags %x cck %x ofdm %x\n",=0A=
+	    sc->rxon->chan, sc->rxon->flags, sc->rxon->cck_mask,=0A=
+	    sc->rxon->ofdm_mask);=0A=
+	sc->rxon->mode =3D IWN_MODE_2STA;=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_WIPAN_RXON, sc->rxon, sc->rxonsz, 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev, "%s: RXON command failed, error %d\n",=0A=
+		    __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	/* Configuration has changed, set TX power accordingly. */=0A=
+	if ((error =3D ops->set_txpower(sc, ni->ni_chan, 1)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not set TX power, error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+	/*=0A=
+	 * Reconfiguring RXON clears the firmware nodes table so we must=0A=
+	 * add the broadcast node again.=0A=
+	 */=0A=
+	if ((error =3D iwn_add_broadcast_node_u1(sc, 0)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not add broadcast node, error %d\n", __func__,=0A=
+		    error);=0A=
+		return error;=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+=0A=
+	return 0;=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_run_u1(struct iwn_softc *sc, struct ieee80211vap *vap)=0A=
+{=0A=
+	struct iwn_ops *ops =3D &sc->ops;=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	struct ieee80211_node *ni =3D vap->iv_bss;=0A=
+	struct iwn_node_info node;=0A=
+	uint32_t htflags =3D 0;=0A=
+	int error;=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
+	if (ic->ic_opmode =3D=3D IEEE80211_M_MONITOR) {=0A=
+		/* Link LED blinks while monitoring. */=0A=
+		return 0;=0A=
+	}=0A=
+=0A=
+	if ((error =3D iwn_set_timing_u1(sc)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not set timing, error %d\n", __func__, error);=0A=
+	}=0A=
+=0A=
+	if ((error =3D iwn_updateedca_u1(ic)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: iwn_updateedca_u1, error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->myaddr, ivp->macaddr);=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->wlap, IF_LLADDR(ifp));=0A=
+	/* Update adapter configuration. */=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->bssid, ni->ni_bssid);=0A=
+	sc->rxon->associd =3D htole16(IEEE80211_AID(ni->ni_associd));=0A=
+	sc->rxon->chan =3D ieee80211_chan2ieee(ic, ni->ni_chan);=0A=
+	sc->rxon->flags =3D htole32(IWN_RXON_TSF | IWN_RXON_CTS_TO_SELF);=0A=
+	if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan))=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);=0A=
+	if (ic->ic_flags & IEEE80211_F_SHSLOT)=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_SHSLOT);=0A=
+	if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_SHPREAMBLE);=0A=
+	if (IEEE80211_IS_CHAN_A(ni->ni_chan)) {=0A=
+		sc->rxon->cck_mask  =3D 0;=0A=
+		sc->rxon->ofdm_mask =3D 0x15;=0A=
+	} else if (IEEE80211_IS_CHAN_B(ni->ni_chan)) {=0A=
+		sc->rxon->cck_mask  =3D 0x03;=0A=
+		sc->rxon->ofdm_mask =3D 0;=0A=
+	} else {=0A=
+		/* Assume 802.11b/g. */=0A=
+		sc->rxon->cck_mask  =3D 0x0f;=0A=
+		sc->rxon->ofdm_mask =3D 0x15;=0A=
+	}=0A=
+	if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {=0A=
+		htflags |=3D IWN_RXON_HT_PROTMODE(ic->ic_curhtprotmode);=0A=
+		if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {=0A=
+			switch (ic->ic_curhtprotmode) {=0A=
+			case IEEE80211_HTINFO_OPMODE_HT20PR:=0A=
+				htflags |=3D IWN_RXON_HT_MODEPURE40;=0A=
+				break;=0A=
+			default:=0A=
+				htflags |=3D IWN_RXON_HT_MODEMIXED;=0A=
+				break;=0A=
+			}=0A=
+		}=0A=
+		if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))=0A=
+			htflags |=3D IWN_RXON_HT_HT40MINUS;=0A=
+	}=0A=
+	sc->rxon->flags |=3D htole32(htflags);=0A=
+	sc->rxon->filter |=3D htole32(IWN_FILTER_BSS);=0A=
+	DPRINTF(sc, IWN_DEBUG_STATE, "rxon chan %d flags %x\n",=0A=
+	    sc->rxon->chan, sc->rxon->flags);=0A=
+	sc->rxon->mode =3D IWN_MODE_2STA;=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_WIPAN_RXON, sc->rxon, sc->rxonsz, 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not update configuration, error %d\n", __func__,=0A=
+		    error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	/* Configuration has changed, set TX power accordingly. */=0A=
+	if ((error =3D ops->set_txpower(sc, ni->ni_chan, 1)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not set TX power, error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	/* Fake a join to initialize the TX rate. */=0A=
+	((struct iwn_node *)ni)->id =3D IWN_STA_ID;=0A=
+	iwn_newassoc(ni, 1);=0A=
+=0A=
+	/* Add BSS node. */=0A=
+	memset(&node, 0, sizeof node);=0A=
+	node.htflags |=3D htole32(IWN_STA_FLAG_PAN_STATION);=0A=
+	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr);=0A=
+	node.id =3D IWN_STA_ID;=0A=
+	if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {=0A=
+		switch (ni->ni_htcap & IEEE80211_HTCAP_SMPS) {=0A=
+		case IEEE80211_HTCAP_SMPS_ENA:=0A=
+			node.htflags |=3D htole32(IWN_SMPS_MIMO_DIS);=0A=
+			break;=0A=
+		case IEEE80211_HTCAP_SMPS_DYNAMIC:=0A=
+			node.htflags |=3D htole32(IWN_SMPS_MIMO_PROT);=0A=
+			break;=0A=
+		}=0A=
+		node.htflags |=3D htole32(IWN_AMDPU_SIZE_FACTOR(3) |=0A=
+		    IWN_AMDPU_DENSITY(5));	/* 4us */=0A=
+		if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))=0A=
+			node.htflags |=3D htole32(IWN_NODE_HT40);=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_STATE, "%s: adding BSS node1\n", __func__);=0A=
+	error =3D ops->add_node(sc, &node, 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not add BSS node1, error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	/* Setting the initial rate for node */=0A=
+	ni->ni_txrate =3D ni->ni_rates.rs_rates[0];=0A=
+=0A=
+	/* XXX: init rate scaling */=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+=0A=
+	#ifdef IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP=0A=
+		return iwn_set_pslevel(sc, IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE,=0A=
+			sc->desired_pwrsave_level, 0);=0A=
+	#else=0A=
+		return 0;=0A=
+	#endif=0A=
+=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_set_timing_u1(struct iwn_softc *sc)=0A=
+{=0A=
+	struct iwn_cmd_timing cmd;=0A=
+	int error =3D 0;=0A=
+	struct ieee80211vap *vap;=0A=
+	struct iwn_vap *ivp;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
+	vap =3D sc->ivap[IWN_RXON_PAN_CTX];=0A=
+	ivp =3D IWN_VAP(vap);=0A=
+=0A=
+	if ((error =3D iwn_config_u1(sc)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: iwn_config1 error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	if ((error =3D iwn_set_pan_params(sc)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: iwn_set_pan_params error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	memset(&cmd, 0, sizeof cmd);=0A=
+	cmd.lintval =3D htole16(10);=0A=
+	cmd.bintval =3D htole16(IWN_BEACON_INTERVAL_DEFAULT);=0A=
+	ivp->beacon_int =3D cmd.bintval;=0A=
+	cmd.binitval =3D htole32(0x032000);=0A=
+	cmd.dtim_period =3D 1;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+=0A=
+	return iwn_cmd(sc, IWN_CMD_WIPAN_RXON_TIMING, &cmd, sizeof cmd, 0);=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_config_u1(struct iwn_softc *sc)=0A=
+{=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	uint16_t rxchain;=0A=
+	int error;=0A=
+	struct ieee80211vap *vap =3D sc->ivap[IWN_RXON_PAN_CTX];=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->myaddr, ivp->macaddr);=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->wlap, IF_LLADDR(ifp));=0A=
+	sc->rxon->chan =3D ieee80211_chan2ieee(ic, ic->ic_curchan);=0A=
+	sc->rxon->flags =3D htole32(IWN_RXON_TSF);=0A=
+	if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan))=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);=0A=
+	sc->rxon->mode =3D IWN_MODE_P2P;=0A=
+	sc->rxon->filter =3D htole32(IWN_FILTER_MULTICAST);=0A=
+	sc->rxon->cck_mask  =3D 0x0f;	/* not yet negotiated */=0A=
+	sc->rxon->ofdm_mask =3D 0xff;	/* not yet negotiated */=0A=
+	sc->rxon->ht_single_mask =3D 0xff;=0A=
+	sc->rxon->ht_dual_mask =3D 0xff;=0A=
+	sc->rxon->ht_triple_mask =3D 0xff;=0A=
+	rxchain =3D=0A=
+	    IWN_RXCHAIN_VALID(sc->rxchainmask) |=0A=
+	    IWN_RXCHAIN_MIMO_COUNT(2) |=0A=
+	    IWN_RXCHAIN_IDLE_COUNT(2);=0A=
+	sc->rxon->rxchain =3D htole16(rxchain);=0A=
+	sc->rxon->associd =3D 0;=0A=
+	sc->rxon->filter &=3D ~htole32(IWN_FILTER_BSS);=0A=
+=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_WIPAN_RXON, sc->rxon, sc->rxonsz, 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev, "%s: IWN_CMD_WIPAN_RXON command failed\n",=0A=
+		    __func__);=0A=
+		return error;=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+=0A=
+	return 0;=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_set_pan_params(struct iwn_softc *sc)=0A=
+{=0A=
+	struct iwn_pan_params_cmd cmd;=0A=
+	int slot0 =3D 300, slot1 =3D 0;=0A=
+	int bcnint;=0A=
+	int error =3D 0;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
+	/*=0A=
+	 * If the PAN context is inactive, then we don't need=0A=
+	 * to update the PAN parameters=0A=
+	 */=0A=
+	if (sc->ctx !=3D IWN_RXON_PAN_CTX) {=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end with no need to do that\n", =
__func__);=0A=
+		return 0;=0A=
+	}=0A=
+=0A=
+	memset(&cmd, 0, sizeof(cmd));=0A=
+=0A=
+	/* only 2 slots are currently allowed */=0A=
+	cmd.num_slots =3D 2;=0A=
+=0A=
+	cmd.slots[0].type =3D IWN_RXON_BSS_CTX; /* BSS */=0A=
+	cmd.slots[1].type =3D IWN_RXON_PAN_CTX; /* PAN */=0A=
+=0A=
+	cmd.flags |=3D htole16(IWN_PAN_PARAMS_FLG_SLOTTED_MODE);=0A=
+	bcnint =3D IWN_BEACON_INTERVAL_DEFAULT;=0A=
+	slot0 =3D (bcnint >> 1);=0A=
+	slot1 =3D (bcnint - slot0);=0A=
+=0A=
+	if(sc->uc_scan_progress =3D=3D 1) {=0A=
+		slot0 =3D bcnint * 3 - IWN_SLOT_TIME_MIN;=0A=
+		slot1 =3D IWN_SLOT_TIME_MIN;=0A=
+	}=0A=
+	cmd.slots[0].time =3D htole16(slot0);=0A=
+	cmd.slots[1].time =3D htole16(slot1);=0A=
+=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_WIPAN_PARAMS, &cmd, sizeof(cmd), 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev, "%s: IWN_CMD_WIPAN_PARAMS command failed, =
error %d\n",=0A=
+		    __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+=0A=
+	return 0;=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_updateedca_u1(struct ieee80211com *ic)=0A=
+{=0A=
+#define IWN_EXP2(x)	((1 << (x)) - 1)	/* CWmin =3D 2^ECWmin - 1 */=0A=
+	struct iwn_softc *sc =3D ic->ic_ifp->if_softc;=0A=
+	struct iwn_edca_params cmd;=0A=
+	int aci;=0A=
+=0A=
+	memset(&cmd, 0, sizeof cmd);=0A=
+	cmd.flags =3D htole32(IWN_EDCA_UPDATE);=0A=
+	for (aci =3D 0; aci < WME_NUM_AC; aci++) {=0A=
+		const struct wmeParams *ac =3D=0A=
+		    &ic->ic_wme.wme_chanParams.cap_wmeParams[aci];=0A=
+		cmd.ac[aci].aifsn =3D ac->wmep_aifsn;=0A=
+		cmd.ac[aci].cwmin =3D htole16(IWN_EXP2(ac->wmep_logcwmin));=0A=
+		cmd.ac[aci].cwmax =3D htole16(IWN_EXP2(ac->wmep_logcwmax));=0A=
+		cmd.ac[aci].txoplimit =3D=0A=
+		    htole16(IEEE80211_TXOP_TO_US(ac->wmep_txopLimit));=0A=
+	}=0A=
+	return iwn_cmd(sc, IWN_CMD_WIPAN_QOS_PARAM, &cmd, sizeof cmd, 1);=0A=
+#undef IWN_EXP2=0A=
+}=0A=
+=0A=
+/*=0A=
+ * Broadcast node is used to send group-addressed and management frames.=0A=
+ */=0A=
+static int=0A=
+iwn_add_broadcast_node_u1(struct iwn_softc *sc, int async)=0A=
+{=0A=
+	struct iwn_ops *ops =3D &sc->ops;=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	struct iwn_node_info node;=0A=
+	struct iwn_cmd_link_quality linkq;=0A=
+	uint8_t txant;=0A=
+	int i, error;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+=0A=
+	memset(&node, 0, sizeof node);=0A=
+	IEEE80211_ADDR_COPY(node.macaddr, ifp->if_broadcastaddr);=0A=
+=0A=
+	node.id =3D IWN_PAN_ID_BCAST;=0A=
+	node.htflags |=3D htole32(IWN_STA_FLAG_PAN_STATION);=0A=
+	DPRINTF(sc, IWN_DEBUG_RESET, "%s: adding broadcast node1\n", __func__);=0A=
+	if ((error =3D ops->add_node(sc, &node, async)) !=3D 0)=0A=
+		return error;=0A=
+=0A=
+	/* Use the first valid TX antenna. */=0A=
+	txant =3D IWN_LSB(sc->txchainmask);=0A=
+=0A=
+	memset(&linkq, 0, sizeof linkq);=0A=
+	linkq.id =3D IWN_PAN_ID_BCAST;=0A=
+	linkq.antmsk_1stream =3D txant;=0A=
+	linkq.antmsk_2stream =3D IWN_ANT_AB;=0A=
+	linkq.ampdu_max =3D 64;=0A=
+	linkq.ampdu_threshold =3D 3;=0A=
+	linkq.ampdu_limit =3D htole16(4000);	/* 4ms */=0A=
+=0A=
+	/* Use lowest mandatory bit-rate. */=0A=
+	if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan))=0A=
+		linkq.retry[0] =3D htole32(0xd);=0A=
+	else=0A=
+		linkq.retry[0] =3D htole32(10 | IWN_RFLAG_CCK);=0A=
+	linkq.retry[0] |=3D htole32(IWN_RFLAG_ANT(txant));=0A=
+	/* Use same bit-rate for all TX retries. */=0A=
+	for (i =3D 1; i < IWN_MAX_TX_RETRIES; i++) {=0A=
+		linkq.retry[i] =3D linkq.retry[0];=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+=0A=
+	return iwn_cmd(sc, IWN_CMD_LINK_QUALITY, &linkq, sizeof linkq, async);=0A=
+}=0A=
+=0A=
+static uint16_t=0A=
+iwn_get_active_dwell(struct iwn_softc *sc, struct ieee80211_channel *c)=0A=
+{=0A=
+	int n_probes =3D 1;=0A=
+=0A=
+	if (IEEE80211_IS_CHAN_5GHZ(c))=0A=
+		return IWN_ACTIVE_DWELL_TIME_52 +=0A=
+			IWN_ACTIVE_DWELL_FACTOR_52 * (n_probes + 1);=0A=
+	else=0A=
+		return IWN_ACTIVE_DWELL_TIME_24 +=0A=
+			IWN_ACTIVE_DWELL_FACTOR_24 * (n_probes + 1);=0A=
+}=0A=
+=0A=
+static uint16_t=0A=
+iwn_get_passive_dwell(struct iwn_softc *sc, struct ieee80211_channel *c)=0A=
+{=0A=
+	uint8_t ctx_id =3D 0;=0A=
+	uint16_t beacon_int;=0A=
+	struct ieee80211vap *vap;=0A=
+	struct iwn_vap *ivp;=0A=
+	uint16_t dwell_time;=0A=
+=0A=
+	dwell_time =3D (IEEE80211_IS_CHAN_2GHZ(c)) ?=0A=
+			    IWN_PASSIVE_DWELL_BASE + IWN_PASSIVE_DWELL_TIME_24 :=0A=
+			    IWN_PASSIVE_DWELL_BASE + IWN_PASSIVE_DWELL_TIME_52;=0A=
+=0A=
+	for (ctx_id =3D 0; ctx_id < IWN_NUM_RXON_CTX; ctx_id++) {=0A=
+		vap =3D sc->ivap[ctx_id];=0A=
+		ivp =3D IWN_VAP(vap);=0A=
+		sc->rxon =3D &sc->rx_on[ctx_id];=0A=
+		if (!sc->rxon->associd)=0A=
+			continue;=0A=
+		beacon_int =3D ivp->beacon_int;=0A=
+		if (!beacon_int)=0A=
+			beacon_int =3D IWN_PASSIVE_DWELL_BASE;=0A=
+		beacon_int =3D (beacon_int * 98) / 100 - IWN_CHANNEL_TUNE_TIME * 2;=0A=
+		dwell_time =3D min(beacon_int, dwell_time);=0A=
+		if(sc->ctx !=3D IWN_RXON_PAN_CTX) break;=0A=
+	}=0A=
+=0A=
+	return dwell_time;=0A=
+}=0A=
+static void=0A=
+iwn_led_pattern(struct iwn_softc *sc)=0A=
+{=0A=
+	int i,j;=0A=
+=0A=
+	for(i =3D 0; i < IWN_MAX_BLINK_TBL; i++) {=0A=
+		if((sc->sc_led.led_last_tpt) > (blink_tbl[i].tpt * 1024 * 1024))=0A=
+			break;=0A=
+	}=0A=
+=0A=
+	for(j =3D 0; j < IWN_MAX_BLINK_TBL; j++) {=0A=
+		if((sc->sc_led.led_cur_tpt) > (blink_tbl[j].tpt * 1024 * 1024))=0A=
+			break;=0A=
+	}=0A=
+=0A=
+	if (i !=3D j)=0A=
+		iwn_set_led(sc, IWN_LED_LINK,blink_tbl[j].off_time,=0A=
+		    blink_tbl[j].on_time, IWN_LED_INT_BLINK);=0A=
+}=0A=
+=0A=
+=0A=
Index: sys/dev/iwn/if_iwnreg.h=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/dev/iwn/if_iwnreg.h	(revision 254210)=0A=
+++ sys/dev/iwn/if_iwnreg.h	(working copy)=0A=
@@ -2,6 +2,8 @@=0A=
 /*	$OpenBSD: if_iwnreg.h,v 1.40 2010/05/05 19:41:57 damien Exp $	*/=0A=
 =0A=
 /*-=0A=
+ * Copyright (c) 2013 Cedric GROSS <c.gross@kreiz-it.fr>=0A=
+ * Copyright (c) 2011 Intel Corporation=0A=
  * Copyright (c) 2007, 2008=0A=
  *	Damien Bergamini <damien.bergamini@free.fr>=0A=
  *=0A=
@@ -1046,8 +1048,8 @@=0A=
 =0A=
 /* Structure for command IWN_CMD_SET_CRITICAL_TEMP. */=0A=
 struct iwn_critical_temp {=0A=
+	uint32_t	tempM;=0A=
 	uint32_t	reserved;=0A=
-	uint32_t	tempM;=0A=
 	uint32_t	tempR;=0A=
 /* degK <-> degC conversion macros. */=0A=
 #define IWN_CTOK(c)	((c) + 273)=0A=
@@ -1102,6 +1104,10 @@=0A=
 	uint16_t	reserved;=0A=
 } __packed;=0A=
 =0A=
+/* Define maximal number of calib result send to runtime firmware =0A=
+ * PS: TEMP_OFFSET count for 2 (std and v2)=0A=
+ */=0A=
+#define IWN5000_PHY_CALIB_MAX_RESULT	8=0A=
 /* Structures for command IWN_CMD_PHY_CALIB. */=0A=
 struct iwn_phy_calib {=0A=
 	uint8_t	code;=0A=
@@ -1122,6 +1128,15 @@=0A=
 	uint8_t	isvalid;=0A=
 } __packed;=0A=
 =0A=
+#define IWN_BUF_IX_PHY_CALIB_DC				0=0A=
+#define IWN_BUF_IX_PHY_CALIB_LO			 	1=0A=
+#define IWN_BUF_IX_PHY_CALIB_TX_IQ			2=0A=
+#define IWN_BUF_IX_PHY_CALIB_CRYSTAL		3=0A=
+#define IWN_BUF_IX_PHY_CALIB_BASE_BAND		4=0A=
+#define IWN_BUF_IX_PHY_CALIB_TX_IQ_PERIODIC	5=0A=
+#define IWN_BUF_IX_PHY_CALIB_TEMP_OFFSET	6 =0A=
+#define IWN_BUF_IX_PHY_CALIB_TEMP_OFFSETv2	7=0A=
+=0A=
 struct iwn5000_phy_calib_crystal {=0A=
 	uint8_t	code;=0A=
 	uint8_t	group;=0A=
@@ -1581,6 +1596,8 @@=0A=
 	uint32_t	len;=0A=
 } __packed;=0A=
 =0A=
+#define IWN_FW_TLV_FLAGS_NEW_SCAN_BITPOS 1=0A=
+=0A=
 #define IWN4965_FW_TEXT_MAXSZ	( 96 * 1024)=0A=
 #define IWN4965_FW_DATA_MAXSZ	( 40 * 1024)=0A=
 #define IWN5000_FW_TEXT_MAXSZ	(256 * 1024)=0A=
@@ -1688,6 +1705,16 @@=0A=
 	struct	iwn4965_eeprom_chan_samples chans[2];=0A=
 } __packed;=0A=
 =0A=
+/* =0A=
+ * ADD / MODIFY STATION Command (Op Code 18) -  byte 76-18 -bit13=0A=
+ * STA_FLAG_PAN_STATION bit:=0A=
+ * This bit is set (1) for a station in PAN mode =0A=
+ */=0A=
+#define IWN_STA_FLAG_PAN_STATION		(1 << 13)=0A=
+=0A=
+#define IWN_BEACON_INTERVAL_DEFAULT		200=0A=
+#define IWN_SLOT_TIME_MIN		20=0A=
+=0A=
 /*=0A=
  * Offsets of channels descriptions in EEPROM.=0A=
  */=0A=
@@ -1731,6 +1758,16 @@=0A=
 	IWN5000_EEPROM_NO_HT40,=0A=
 };=0A=
 =0A=
+static const uint32_t iwn2030_regulatory_bands[IWN_NBANDS] =3D {=0A=
+	IWN5000_EEPROM_BAND1,=0A=
+	IWN5000_EEPROM_BAND2,=0A=
+	IWN5000_EEPROM_BAND3,=0A=
+	IWN5000_EEPROM_BAND4,=0A=
+	IWN5000_EEPROM_BAND5,=0A=
+	IWN6000_EEPROM_BAND6,=0A=
+	IWN5000_EEPROM_BAND7=0A=
+};=0A=
+=0A=
 #define IWN_CHAN_BANDS_COUNT	 7=0A=
 #define IWN_MAX_CHAN_PER_BAND	14=0A=
 static const struct iwn_chan_band {=0A=
@@ -1775,6 +1812,8 @@=0A=
 /* DTIM value to pass in for IWN_POWERSAVE_LVL_VOIP_COMPATIBLE */=0A=
 #define	IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE	2=0A=
 =0A=
+#define IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP=0A=
+=0A=
 /*=0A=
  * RF Tx gain values from highest to lowest power (values obtained from=0A=
  * the reference driver.)=0A=
@@ -1891,6 +1930,7 @@=0A=
 	uint32_t	min_energy_cck;=0A=
 	uint32_t	energy_cck;=0A=
 	uint32_t	energy_ofdm;=0A=
+	uint32_t	min_corr_barker_mrc;=0A=
 };=0A=
 =0A=
 /*=0A=
@@ -1917,7 +1957,8 @@=0A=
 	170, 400,=0A=
 	 95,=0A=
 	 95,=0A=
-	 95=0A=
+	 95,=0A=
+	 390=0A=
 };=0A=
 =0A=
 static const struct iwn_sensitivity_limits iwn5150_sensitivity_limits =
=3D {=0A=
@@ -1929,7 +1970,8 @@=0A=
 	170, 400,=0A=
 	 95,=0A=
 	 95,=0A=
-	 95=0A=
+	 95,=0A=
+	 390=0A=
 };=0A=
 =0A=
 static const struct iwn_sensitivity_limits iwn1000_sensitivity_limits =
=3D {=0A=
@@ -1941,7 +1983,8 @@=0A=
 	170, 400,=0A=
 	 95,=0A=
 	 95,=0A=
-	 95=0A=
+	 95,=0A=
+	 390=0A=
 };=0A=
 =0A=
 static const struct iwn_sensitivity_limits iwn6000_sensitivity_limits =
=3D {=0A=
@@ -1951,9 +1994,10 @@=0A=
 	128, 232,=0A=
 	125, 175,=0A=
 	160, 310,=0A=
-	 97,=0A=
-	 97,=0A=
-	100=0A=
+	110,=0A=
+	110,=0A=
+	110,=0A=
+	336=0A=
 };=0A=
 =0A=
 /* Get value from linux kernel 3.2.+ in =
Drivers/net/wireless/iwlwifi/iwl-2000.c*/=0A=
@@ -2052,3 +2096,360 @@=0A=
 #define IWN_BARRIER_READ_WRITE(sc)					\=0A=
 	bus_space_barrier((sc)->sc_st, (sc)->sc_sh, 0, (sc)->sc_sz,	\=0A=
 	    BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE)=0A=
+=0A=
+/* =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
+ *                                  NIC PARAMETERS=0A=
+ *=0A=
+ * =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
+ */=0A=
+ =0A=
+/* Flags for managing calibration result. See calib_need =0A=
+ * in iwn_base_params struct =0A=
+ */=0A=
+#define IWN_FLG_NEED_PHY_CALIB_DC				(1<<0)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_LO				(1<<1)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_TX_IQ			(1<<2)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_CRYSTAL			(1<<3)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_BASE_BAND		(1<<4)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_TX_IQ_PERIODIC	(1<<5)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET		(1<<6)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2	(1<<7)=0A=
+=0A=
+		=0A=
+/* Define some parameters for managing different NIC.=0A=
+ * Refer to linux specific file like iwl-xxxx.c to determine correct =
value =0A=
+ * for NIC.=0A=
+ *=0A=
+ * @max_ll_items: max number of OTP blocks=0A=
+ * @shadow_ram_support: shadow support for OTP memory=0A=
+ * @led_compensation: compensate on the led on/off time per HW according=0A=
+ *     to the deviation to achieve the desired led frequency.=0A=
+ *     The detail algorithm is described in iwl-led.c=0A=
+ * @chain_noise_num_beacons: number of beacons used to compute chain =
noise=0A=
+ * @adv_thermal_throttle: support advance thermal throttle=0A=
+ * @support_ct_kill_exit: support ct kill exit condition=0A=
+ * @support_wimax_coexist: support wimax/wifi co-exist=0A=
+ * @plcp_delta_threshold: plcp error rate threshold used to trigger=0A=
+ *	radio tuning when there is a high receiving plcp error rate=0A=
+ * @chain_noise_scale: default chain noise scale used for gain =
computation=0A=
+ * @wd_timeout: TX queues watchdog timeout=0A=
+ * @max_event_log_size: size of event log buffer size for ucode event =
logging=0A=
+ * @shadow_reg_enable: HW shadhow register bit=0A=
+ * @no_idle_support: do not support idle mode=0A=
+ * @hd_v2: v2 of enhanced sensitivity value, used for 2000 series and up=0A=
+ * advanced_bt_coexist : Advanced BT management=0A=
+ * bt_session_2 : NIC need a new struct for configure BT coexistence. =
Needed =0A=
+ *   only if advanced_bt_coexist is true =0A=
+ * bt_sco_disable :=0A=
+ * additional_nic_config: For 6005 series=0A=
+ * iq_invert : ? But need it for N 2000 series=0A=
+ * regulatory_bands :=0A=
+ * enhanced_TX_power : EEPROM Has advanced TX power options. Set 'True'=0A=
+ *  if update_enhanced_txpower =3D iwl_eeprom_enhanced_txpower =0A=
+ * need_temp_offset_calib : Need to compute some temp offset for =
calibration.=0A=
+ * calib_need : Use IWN_FLG_NEED_PHY_CALIB_* flags to specify which =0A=
+ *    calibration data ucode need. See calib_init_cfg in iwl-xxxx.c =0A=
+ *    linux kernel file=0A=
+ * additional_gp_drv_bit : Specific bit to defined during nic_config=0A=
+ */=0A=
+struct iwn_base_params {=0A=
+	uint32_t pll_cfg_val;=0A=
+	const uint16_t max_ll_items;=0A=
+#define IWN_OTP_MAX_LL_ITEMS_1000		(3)	/* OTP blocks for 1000 */=0A=
+#define IWN_OTP_MAX_LL_ITEMS_6x00		(4)	/* OTP blocks for 6x00 */=0A=
+#define IWN_OTP_MAX_LL_ITEMS_6x50		(7)	/* OTP blocks for 6x50 */=0A=
+#define IWN_OTP_MAX_LL_ITEMS_2x00		(4)	/* OTP blocks for 2x00 */=0A=
+	const bool shadow_ram_support;=0A=
+	uint16_t led_compensation;=0A=
+	bool adv_thermal_throttle;=0A=
+	bool support_ct_kill_exit;=0A=
+	uint8_t plcp_delta_threshold;=0A=
+	int chain_noise_scale;=0A=
+	unsigned int wd_timeout;=0A=
+	uint32_t max_event_log_size;=0A=
+	const bool shadow_reg_enable;=0A=
+	const bool hd_v2;=0A=
+	const bool advanced_bt_coexist;=0A=
+	const bool bt_session_2;=0A=
+	const bool bt_sco_disable;=0A=
+	const bool additional_nic_config;=0A=
+	const uint32_t *regulatory_bands;=0A=
+	const bool enhanced_TX_power; // See iwl-agn-devices.c file to =
determine that(enhanced_txpower). =0A=
+	const uint16_t calib_need;=0A=
+	const bool no_crystal_calibration; // see no_xtal_calib in linux=0A=
+	const bool support_hostap; //Define IEEE80211_C_HOSTAP for ic_caps=0A=
+	const bool no_multi_vaps; // see iwn_vap_create=0A=
+	uint8_t additional_gp_drv_bit; //=0A=
+	=0A=
+};=0A=
+=0A=
+/* NOTA : Values with comments BEFORE are not yet used in driver */=0A=
+static struct iwn_base_params iwn_default_base_params =3D {=0A=
+	IWN_ANA_PLL_INIT, // pll_cfg_val=0A=
+	4,  //max_ll_items=0A=
+	true, // shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, // bt_session_2=0A=
+	true, // bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn5000_regulatory_bands, //regulatory_bands=0A=
+	false, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO =0A=
+	    | IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND =
), //calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, // no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+=0A=
+static struct iwn_base_params iwn2030_base_params =3D {=0A=
+	 0, //pll_cfg_val=0A=
+	 IWN_OTP_MAX_LL_ITEMS_2x00, //max_ll_items=0A=
+	 true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */ 57,=0A=
+	/*.adv_thermal_throttle =3D */ true,=0A=
+	/*.support_ct_kill_exit =3D */ true,=0A=
+	/*.plcp_delta_threshold =3D */ 50,=0A=
+	/*.chain_noise_scale =3D */ 1000,=0A=
+	/*.wd_timeout =3D */ 2000,=0A=
+	/*.max_event_log_size =3D */ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */ true,=0A=
+	true, //advanced_bt_coexist=0A=
+	true, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn2030_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2 ), //calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	true, //support_hostap=0A=
+	false, //no_multi_vaps=0A=
+	IWN_GP_DRIVER_REG_BIT_RADIO_IQ_INVERT, // additional_gp_drv_bit=0A=
+};=0A=
+=0A=
+static struct iwn_base_params iwn_1000_base_params =3D {=0A=
+	IWN_ANA_PLL_INIT, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_1000, //max_ll_items=0A=
+	false, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, //advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	false, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn5000_regulatory_bands, //regulatory_bands=0A=
+	false, //enhanced_TX_power=0A=
+	( IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6000_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x00, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	false, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6000i_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x00, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6000g2_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x00, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET ), //calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6050_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x50, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	true, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET ), //calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6150_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x50, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	true, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET ), //calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	IWN_GP_DRIVER_6050_1X2, //additional_gp_drv_bit=0A=
+};=0A=
+//IWL_DEVICE_6035 & IWL_DEVICE_6030=0A=
+static struct iwn_base_params iwn_6000g2b_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x00, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	true, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET ), //calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_5x50_base_params =3D {=0A=
+	IWN_ANA_PLL_INIT, // pll_cfg_val=0A=
+	4,  //max_ll_items=0A=
+	true, // shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, // bt_session_2=0A=
+	true, // bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn5000_regulatory_bands, //regulatory_bands=0A=
+	false, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO |=0A=
+	    IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	true, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, // no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+=0A=
Index: sys/dev/iwn/if_iwnvar.h=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/dev/iwn/if_iwnvar.h	(revision 254210)=0A=
+++ sys/dev/iwn/if_iwnvar.h	(working copy)=0A=
@@ -136,6 +136,7 @@=0A=
 	struct	ieee80211_node		ni;	/* must be the first */=0A=
 	uint16_t			disable_tid;=0A=
 	uint8_t				id;=0A=
+	uint32_t			ridx[256];=0A=
 	struct {=0A=
 		uint64_t		bitmap;=0A=
 		int			startidx;=0A=
@@ -174,6 +175,9 @@=0A=
 	uint32_t	energy_samples[10];=0A=
 	u_int		cur_energy_sample;=0A=
 	uint32_t	energy_cck;=0A=
+=0A=
+	uint32_t	corr_barker_mrc;=0A=
+	uint32_t	energy_ofdm;=0A=
 };=0A=
 =0A=
 struct iwn_calib_info {=0A=
@@ -315,7 +319,7 @@=0A=
 	struct callout		watchdog_to;=0A=
 	struct callout		ct_kill_exit_to;=0A=
 	struct iwn_fw_info	fw;=0A=
-	struct iwn_calib_info	calibcmd[5];=0A=
+	struct iwn_calib_info	calibcmd[IWN5000_PHY_CALIB_MAX_RESULT];=0A=
 	uint32_t		errptr;=0A=
 =0A=
 	struct iwn_rx_stat	last_rx_stat;=0A=

------=_NextPart_000_0004_01CE968D.7B91F040--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000301ce967c$b8092040$281b60c0$>