Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Aug 2013 13:23:36 +0200
From:      "Cedric GROSS" <cg@cgross.info>
To:        "'Adrian Chadd'" <adrian@freebsd.org>
Cc:        freebsd-wireless@freebsd.org
Subject:   RE: [IWN] Reviw split 2
Message-ID:  <001001ce903b$e77a5f70$b66f1e50$@info>
In-Reply-To: <CAJ-VmoniUozz48U0MHhF4sAsrJt6sd06Q9UESRFG9kOXSB2ObQ@mail.gmail.com>
References:  <51f3f0ce.055a420a.2e1e.fffff220SMTPIN_ADDED_BROKEN@mx.google.com>	<CAJ-VmokCVB5kNY44hJLbAfOb1DMSHmJAG3QTUZYhmPL1gHwMwA@mail.gmail.com>	<002d01ce8c46$a13b23d0$e3b16b70$@info>	<CAJ-Vmon4hMbgFKaWva3-HhcJv=eUXKwX7s0uPcD9Nu9g86QEbA@mail.gmail.com>	<002701ce8e03$c033f640$409be2c0$@info>	<CAJ-Vmo=yZXdKuXZ85bXs-uG2tAmcZFMAgFXCswnVBk2PUmaXfQ@mail.gmail.com>	<002401ce8f5f$fc5ad780$f5108680$@info> <CAJ-VmoniUozz48U0MHhF4sAsrJt6sd06Q9UESRFG9kOXSB2ObQ@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_0011_01CE904C.AB032F70
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: vendredi 2 ao=FBt 2013 23:30
>=20
> I've committed -3 and -4 from your work.

Great.

>=20
> Can you please post an updated diff against what's in -HEAD now?

As requested here is full patch.

>=20
> I have updated firmware here that I'm going to commit soon, including
> the newer device firmware. But I do want to test on the 4965 first =
just
> to make sure it still 'works'.

It should. 4965 part was not impacted. But Don't you said that full =
patch
break your 5100 ?

>=20
> Thanks!
>=20
>=20
> -adrian

Cedric

------=_NextPart_000_0011_01CE904C.AB032F70
Content-Type: application/octet-stream;
	name="full.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="full.patch"

Index: 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=
--- if_iwn.c	(revision 253911)=0A=
+++ if_iwn.c	(working copy)=0A=
@@ -1,4 +1,6 @@=0A=
 /*-=0A=
+ * Copyright (c) 2013 Cedric GROSS <cg@cgross.info>=0A=
+ * Copyright (c) 2011 Intel Corporation=0A=
  * Copyright (c) 2007-2009=0A=
  *	Damien Bergamini <damien.bergamini@free.fr>=0A=
  * Copyright (c) 2008=0A=
@@ -233,7 +235,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=
@@ -259,7 +262,6 @@=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	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=
@@ -290,6 +292,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=
@@ -328,6 +331,23 @@=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 *,=0A=
+			    struct ieee80211_channel *);=0A=
+static uint16_t	iwn_get_passive_dwell(struct iwn_softc *,=0A=
+			    struct ieee80211_channel *);=0A=
+static void	iwn_led_pattern(struct iwn_softc *);=0A=
 =0A=
 #ifdef	IWN_DEBUG=0A=
 enum {=0A=
@@ -353,7 +373,7 @@=0A=
 };=0A=
 =0A=
 #define DPRINTF(sc, m, fmt, ...) do {			\=0A=
-	if (sc->sc_debug & (m))				\=0A=
+	if ((sc->sc_debug & (m))=3D=3D (m))				\=0A=
 		printf(fmt, __VA_ARGS__);		\=0A=
 } while (0)=0A=
 =0A=
@@ -374,6 +394,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=
@@ -396,6 +417,23 @@=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:=0A=
+		return "IWN_CMD_WIPAN_P2P_CHANNEL_SWITCH";=0A=
+	case IWN_CMD_WIPAN_NOA_NOTIFICATION:=0A=
+		return "IWN_CMD_WIPAN_NOA_NOTIFICATION";=0A=
+	case IWN_CMD_WIPAN_DEACTIVATION_COMPLETE:=0A=
+		return "IWN_CMD_WIPAN_DEACTIVATION_COMPLETE";=0A=
+=0A=
 	}=0A=
 	return "UNKNOWN INTR NOTIF/CMD";=0A=
 }=0A=
@@ -454,6 +492,10 @@=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=
+=0A=
 	sc->sc_dev =3D dev;=0A=
 =0A=
 #ifdef	IWN_DEBUG=0A=
@@ -465,7 +507,7 @@=0A=
 	sc->sc_debug =3D 0;=0A=
 #endif=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: begin\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_RESET, "->%s: begin\n",__func__);=0A=
 =0A=
 	/*=0A=
 	 * Get the offset of the PCI Express Capability Structure in PCI=0A=
@@ -521,6 +563,8 @@=0A=
 	/* Read hardware revision and attach. */=0A=
 	sc->hw_type =3D (IWN_READ(sc, IWN_HW_REV) >> IWN_HW_REV_TYPE_SHIFT)=0A=
 	    & IWN_HW_REV_TYPE_MASK;=0A=
+	sc->subdevice_id=3Dpci_get_subdevice(dev);=0A=
+=0A=
 	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_4965)=0A=
 		error =3D iwn4965_attach(sc, pci_get_device(dev));=0A=
 	else=0A=
@@ -612,6 +656,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=
@@ -695,10 +744,19 @@=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=
+=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=
@@ -715,14 +773,21 @@=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=
+=0A=
 	if (bootverbose)=0A=
 		ieee80211_announce(ic);=0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s: end\n",__func__);=0A=
 	return 0;=0A=
 fail:=0A=
 	iwn_detach(dev);=0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end in error\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET | IWN_DEBUG_FATAL,=0A=
+	    "->%s: end in error\n",__func__);=0A=
 	return error;=0A=
 }=0A=
 =0A=
@@ -772,7 +837,7 @@=0A=
 {=0A=
 	struct iwn_ops *ops =3D &sc->ops;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	ops->load_firmware =3D iwn5000_load_firmware;=0A=
 	ops->read_eeprom =3D iwn5000_read_eeprom;=0A=
@@ -801,59 +866,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=
@@ -864,13 +877,13 @@=0A=
 {=0A=
 	struct ifnet *ifp =3D sc->sc_ifp;=0A=
 	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 	ieee80211_radiotap_attach(ic,=0A=
 	    &sc->sc_txtap.wt_ihdr, sizeof(sc->sc_txtap),=0A=
 		IWN_TX_RADIOTAP_PRESENT,=0A=
 	    &sc->sc_rxtap.wr_ihdr, sizeof(sc->sc_rxtap),=0A=
 		IWN_RX_RADIOTAP_PRESENT);=0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 }=0A=
 =0A=
 static void=0A=
@@ -894,19 +907,54 @@=0A=
 {=0A=
 	struct iwn_vap *ivp;=0A=
 	struct ieee80211vap *vap;=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=
+=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=
-	ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, mac);=0A=
+=0A=
+	ieee80211_vap_setup(ic, vap, name, unit, opmode, flags, bssid, 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=
+	/* 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=
@@ -919,7 +967,12 @@=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=
+=0A=
 	ieee80211_ratectl_deinit(vap);=0A=
 	ieee80211_vap_detach(vap);=0A=
 	free(ivp, M_80211_VAP);=0A=
@@ -933,7 +986,7 @@=0A=
 	struct ieee80211com *ic;=0A=
 	int qid;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	if (ifp !=3D NULL) {=0A=
 		ic =3D ifp->if_l2com;=0A=
@@ -944,6 +997,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=
@@ -972,7 +1026,8 @@=0A=
 	if (ifp !=3D NULL)=0A=
 		if_free(ifp);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s: end\n",__func__);=0A=
+=0A=
 	IWN_LOCK_DESTROY(sc);=0A=
 	return 0;=0A=
 }=0A=
@@ -991,8 +1046,15 @@=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=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing =
%s\n",__func__);=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=
@@ -1000,12 +1062,23 @@=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=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s\n", =
__func__);=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=
@@ -1025,6 +1098,8 @@=0A=
 			return 0;=0A=
 		DELAY(10);=0A=
 	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_FATAL, "->%s timeout\n", =
__func__);=0A=
+=0A=
 	return ETIMEDOUT;=0A=
 }=0A=
 =0A=
@@ -1133,7 +1208,7 @@=0A=
 			DELAY(10);=0A=
 		}=0A=
 	}=0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end timeout\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_FATAL, "->%s end timeout\n", =
__func__);=0A=
 	return ETIMEDOUT;=0A=
 }=0A=
 =0A=
@@ -1153,7 +1228,7 @@=0A=
 	uint16_t prev, base, next;=0A=
 	int count, error;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE| IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	/* Wait for clock stabilization before accessing prph. */=0A=
 	if ((error =3D iwn_clock_wait(sc)) !=3D 0)=0A=
@@ -1167,7 +1242,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=
@@ -1180,11 +1255,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=
@@ -1193,13 +1268,13 @@=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=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 =0A=
 	return 0;=0A=
 }=0A=
@@ -1211,7 +1286,7 @@=0A=
 	uint32_t val, tmp;=0A=
 	int ntries;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	addr +=3D sc->prom_base;=0A=
 	for (; count > 0; count -=3D 2, addr++) {=0A=
@@ -1246,7 +1321,7 @@=0A=
 			*out++ =3D val >> 24;=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 =0A=
 	return 0;=0A=
 }=0A=
@@ -1304,7 +1379,7 @@=0A=
 			bus_dmamap_sync(dma->tag, dma->map,=0A=
 			    BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);=0A=
 			bus_dmamap_unload(dma->tag, dma->map);=0A=
-			bus_dmamem_free(dma->tag, dma->vaddr, dma->map);=0A=
+			bus_dmamem_free(dma->tag, &dma->vaddr, dma->map);=0A=
 			dma->vaddr =3D NULL;=0A=
 		}=0A=
 		bus_dmamap_destroy(dma->tag, dma->map);=0A=
@@ -1378,7 +1453,7 @@=0A=
 =0A=
 	ring->cur =3D 0;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	/* Allocate RX descriptors (256-byte aligned). */=0A=
 	size =3D IWN_RX_RING_COUNT * sizeof (uint32_t);=0A=
@@ -1428,7 +1503,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=
@@ -1454,13 +1529,13 @@=0A=
 	bus_dmamap_sync(ring->desc_dma.tag, ring->desc_dma.map,=0A=
 	    BUS_DMASYNC_PREWRITE);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s: end\n",__func__);=0A=
 =0A=
 	return 0;=0A=
 =0A=
 fail:	iwn_free_rx_ring(sc, ring);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end in error\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s: end in =
error\n",__func__);=0A=
 =0A=
 	return error;=0A=
 }=0A=
@@ -1470,7 +1545,7 @@=0A=
 {=0A=
 	int ntries;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	if (iwn_nic_lock(sc) =3D=3D 0) {=0A=
 		IWN_WRITE(sc, IWN_FH_RX_CONFIG, 0);=0A=
@@ -1491,7 +1566,7 @@=0A=
 {=0A=
 	int i;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s \n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s \n", =
__func__);=0A=
 =0A=
 	iwn_dma_contig_free(&ring->desc_dma);=0A=
 	iwn_dma_contig_free(&ring->stat_dma);=0A=
@@ -1526,7 +1601,7 @@=0A=
 	ring->queued =3D 0;=0A=
 	ring->cur =3D 0;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	/* Allocate TX descriptors (256-byte aligned). */=0A=
 	size =3D IWN_TX_RING_COUNT * sizeof (struct iwn_tx_desc);=0A=
@@ -1577,12 +1652,12 @@=0A=
 		}=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 =0A=
 	return 0;=0A=
 =0A=
 fail:	iwn_free_tx_ring(sc, ring);=0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end in error\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end in error\n", =
__func__);=0A=
 	return error;=0A=
 }=0A=
 =0A=
@@ -1591,7 +1666,7 @@=0A=
 {=0A=
 	int i;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->doing %s \n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->doing %s \n", =
__func__);=0A=
 =0A=
 	for (i =3D 0; i < IWN_TX_RING_COUNT; i++) {=0A=
 		struct iwn_tx_data *data =3D &ring->data[i];=0A=
@@ -1618,7 +1693,7 @@=0A=
 {=0A=
 	int i;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s \n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s \n", =
__func__);=0A=
 =0A=
 	iwn_dma_contig_free(&ring->desc_dma);=0A=
 	iwn_dma_contig_free(&ring->cmd_dma);=0A=
@@ -1644,6 +1719,9 @@=0A=
 static void=0A=
 iwn5000_ict_reset(struct iwn_softc *sc)=0A=
 {=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
+=0A=
 	/* Disable interrupts. */=0A=
 	IWN_WRITE(sc, IWN_INT_MASK, 0);=0A=
 =0A=
@@ -1664,6 +1742,9 @@=0A=
 	/* Re-enable interrupts. */=0A=
 	IWN_WRITE(sc, IWN_INT, 0xffffffff);=0A=
 	IWN_WRITE(sc, IWN_INT_MASK, sc->int_mask);=0A=
+=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 }=0A=
 =0A=
 static int=0A=
@@ -1673,7 +1754,7 @@=0A=
 	uint16_t val;=0A=
 	int error;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	/* Check whether adapter has an EEPROM or an OTPROM. */=0A=
 	if (sc->hw_type >=3D IWN_HW_REV_TYPE_1000 &&=0A=
@@ -1733,7 +1814,7 @@=0A=
 =0A=
 	iwn_eeprom_unlock(sc);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 =0A=
 	return 0;=0A=
 }=0A=
@@ -1829,12 +1910,11 @@=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=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 	/* Read regulatory domain (4 ASCII characters). */=0A=
 	iwn_read_prom_data(sc, IWN5000_EEPROM_REG, &val, 2);=0A=
 	base =3D le16toh(val);=0A=
@@ -1842,16 +1922,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=
@@ -1862,6 +1938,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=
@@ -1878,9 +1962,8 @@=0A=
 		DPRINTF(sc, IWN_DEBUG_CALIBRATE, "crystal calibration 0x%08x\n",=0A=
 		    le32toh(sc->eeprom_crystal));=0A=
 	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
-=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -1916,7 +1999,7 @@=0A=
 	uint8_t chan;=0A=
 	int i, nflags;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	for (i =3D 0; i < band->nchan; i++) {=0A=
 		if (!(channels[i].flags & IWN_EEPROM_CHAN_VALID)) {=0A=
@@ -1961,7 +2044,7 @@=0A=
 		}=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 =0A=
 }=0A=
 =0A=
@@ -1978,8 +2061,8 @@=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s start\n", __func__);=0A=
 =0A=
-	if (!(sc->sc_flags & IWN_FLAG_HAS_11N)) {=0A=
-		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end no 11n\n", __func__);=0A=
+	if (!(sc->sc_flags & IWN_FLAG_HAS_11N)){=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end no 11n\n", =
__func__);=0A=
 		return;=0A=
 	}=0A=
 =0A=
@@ -2030,7 +2113,7 @@=0A=
 		c->ic_flags |=3D IEEE80211_CHAN_HT40D | nflags;=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 =0A=
 }=0A=
 =0A=
@@ -2115,7 +2198,7 @@=0A=
 	uint8_t flags;=0A=
 	int i, j;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
 	iwn_read_prom_data(sc, IWN5000_EEPROM_REG, &val, 2);=0A=
 	base =3D le16toh(val);=0A=
@@ -2168,7 +2251,7 @@=0A=
 		}=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 =0A=
 }=0A=
 =0A=
@@ -2316,8 +2399,7 @@=0A=
 	struct iwn_softc *sc =3D ic->ic_ifp->if_softc;=0A=
 	int error =3D 0;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_STATE, "->%s begin\n", =
__func__);=0A=
 	DPRINTF(sc, IWN_DEBUG_STATE, "%s: %s -> %s\n", __func__,=0A=
 	    ieee80211_state_name[vap->iv_state], ieee80211_state_name[nstate]);=0A=
 =0A=
@@ -2325,6 +2407,8 @@=0A=
 	IWN_LOCK(sc);=0A=
 	callout_stop(&sc->calib_to);=0A=
 =0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=0A=
+=0A=
 	switch (nstate) {=0A=
 	case IEEE80211_S_ASSOC:=0A=
 		if (vap->iv_state !=3D IEEE80211_S_RUN)=0A=
@@ -2338,8 +2422,8 @@=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->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(sc, vap)) !=3D 0) {=0A=
@@ -2378,11 +2462,11 @@=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=
+		DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_STATE, "->%s end in error\n", =
__func__);=0A=
 		return error;=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_STATE, "->%s: end\n",__func__);=0A=
 =0A=
 	return ivp->iv_newstate(vap, nstate, arg);=0A=
 }=0A=
@@ -2396,12 +2480,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=
@@ -2447,7 +2526,7 @@=0A=
 	uint32_t flags;=0A=
 	int error, len, rssi, nf;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RECV, "->%s begin\n", =
__func__);=0A=
 =0A=
 	if (desc->type =3D=3D IWN_MPDU_RX_DONE) {=0A=
 		/* Check for prior RX_PHY notification. */=0A=
@@ -2494,7 +2573,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=
@@ -2554,6 +2633,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=
@@ -2570,9 +2650,13 @@=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=
+	DPRINTF(sc, IWN_DEBUG_RECV, "Tstmp : %lu\n",stat->tstamp);=0A=
 =0A=
 	IWN_UNLOCK(sc);=0A=
 =0A=
@@ -2588,7 +2672,7 @@=0A=
 =0A=
 	IWN_LOCK(sc);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RECV, "->%s: end\n",__func__);=0A=
 =0A=
 }=0A=
 =0A=
@@ -2611,7 +2695,7 @@=0A=
 	uint8_t tid;=0A=
 	int ackfailcnt =3D 0, i, lastidx, qid, *res, shift;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RECV, "->%s begin\n", =
__func__);=0A=
 =0A=
 	bus_dmamap_sync(sc->rxq.data_dmat, data->map, BUS_DMASYNC_POSTREAD);=0A=
 =0A=
@@ -2685,7 +2769,7 @@=0A=
 		bitmap >>=3D 1;=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RECV, "->%s: end\n",__func__);=0A=
 =0A=
 }=0A=
 =0A=
@@ -2700,11 +2784,10 @@=0A=
 	struct iwn_phy_calib *calib =3D (struct iwn_phy_calib *)(desc + 1);=0A=
 	int len, idx =3D -1;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s begin\n", =
__func__);=0A=
 	/* Runtime firmware should not send such a notification. */=0A=
 	if (sc->sc_flags & IWN_FLAG_CALIB_DONE){=0A=
-		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s received after clib done\n",=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s received =
after clib done\n",=0A=
 	    __func__);=0A=
 		return;=0A=
 	}=0A=
@@ -2713,29 +2796,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=
@@ -2751,6 +2835,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 | IWN_DEBUG_CALIBRATE, "->%s end\n", =
__func__);=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -2767,18 +2852,59 @@=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=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s begin\n", =
__func__);=0A=
 =0A=
 	/* Ignore statistics received during a scan. */=0A=
 	if (vap->iv_state !=3D IEEE80211_S_RUN ||=0A=
 	    (ic->ic_flags & IEEE80211_F_SCAN)){=0A=
-		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s received during calib\n",=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s received =
during calib\n",=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=
@@ -2816,7 +2942,7 @@=0A=
 	else if (calib->state =3D=3D IWN_CALIB_STATE_RUN)=0A=
 		iwn_tune_sensitivity(sc, &stats->rx);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s: =
end\n",__func__);=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -2858,7 +2984,7 @@=0A=
 	struct iwn_tx_ring *ring;=0A=
 	int qid;=0A=
 =0A=
-	qid =3D desc->qid & 0xf;=0A=
+	qid =3D desc->qid & IWN_RX_DESC_QID_MSK;=0A=
 	ring =3D &sc->txq[qid];=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_XMIT, "%s: "=0A=
@@ -2865,11 +2991,11 @@=0A=
 	    "qid %d idx %d retries %d nkill %d rate %x duration %d status =
%x\n",=0A=
 	    __func__, desc->qid, desc->idx, stat->ackfailcnt,=0A=
 	    stat->btkillcnt, stat->rate, le16toh(stat->duration),=0A=
-	    le32toh(stat->status));=0A=
-=0A=
+	    le16toh(stat->status) & IWN_TX_STATUS_MSK);=0A=
+	DPRINTF(sc, IWN_DEBUG_XMIT, "%s: Agg : %d\n", __func__, stat->nframes);=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=
@@ -2878,7 +3004,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=
@@ -2890,15 +3016,20 @@=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=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s begin\n", =
__func__);=0A=
 =0A=
 	/* Unmap and free mbuf. */=0A=
 	bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTWRITE);=0A=
@@ -2905,9 +3036,19 @@=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=
+	type =3D wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;=0A=
+=0A=
+=0A=
+=0A=
 	if (m->m_flags & M_TXCB) {=0A=
+		DPRINTF(sc, IWN_DEBUG_XMIT, "%s: M_TXCB found\n",__func__);=0A=
 		/*=0A=
 		 * Channels marked for "radar" require traffic to be received=0A=
 		 * to unlock before we can transmit.  Until traffic is seen=0A=
@@ -2934,10 +3075,14 @@=0A=
 	 * Update rate control statistics for the node.=0A=
 	 */=0A=
 	if (status & IWN_TX_FAIL) {=0A=
+		DPRINTF(sc, IWN_DEBUG_XMIT, "%s: Status failed ackcnt: %d\n",=0A=
+	    __func__, ackfailcnt);=0A=
 		ifp->if_oerrors++;=0A=
 		ieee80211_ratectl_tx_complete(vap, ni,=0A=
 		    IEEE80211_RATECTL_TX_FAILURE, &ackfailcnt, NULL);=0A=
 	} else {=0A=
+		DPRINTF(sc, IWN_DEBUG_XMIT, "%s: Status OK ackcnt: %d\n",=0A=
+	    __func__, ackfailcnt);=0A=
 		ifp->if_opackets++;=0A=
 		ieee80211_ratectl_tx_complete(vap, ni,=0A=
 		    IEEE80211_RATECTL_TX_SUCCESS, &ackfailcnt, NULL);=0A=
@@ -2955,7 +3100,7 @@=0A=
 		}=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s: end\n",__func__);=0A=
 =0A=
 }=0A=
 =0A=
@@ -2966,12 +3111,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 PAN Active : %d\n",=0A=
+	    __func__, (desc->qid & IWN_RX_DESC_QID_MSK),(sc->sc_flags & =
IWN_FLAG_PAN_SUPPORT) );=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=
@@ -3004,7 +3161,7 @@=0A=
 	uint8_t tid;=0A=
 	int bit, i, lastidx, *res, seqno, shift, start;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s begin\n", =
__func__);=0A=
 =0A=
 #ifdef NOT_YET=0A=
 	if (nframes =3D=3D 1) {=0A=
@@ -3093,7 +3250,7 @@=0A=
 		}=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s: end\n",__func__);=0A=
 =0A=
 }=0A=
 =0A=
@@ -3106,7 +3263,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=
@@ -3123,11 +3282,13 @@=0A=
 =0A=
 		DPRINTF(sc, IWN_DEBUG_RECV,=0A=
 		    "%s: qid %x idx %d flags %x type %d(%s) len %d\n",=0A=
-		    __func__, desc->qid & 0xf, desc->idx, desc->flags,=0A=
+		    __func__, desc->qid & IWN_RX_DESC_QID_MSK, 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)=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=
@@ -3161,23 +3322,42 @@=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=
+=0A=
 			bus_dmamap_sync(sc->rxq.data_dmat, data->map,=0A=
 			    BUS_DMASYNC_POSTREAD);=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=
@@ -3187,6 +3367,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=
@@ -3213,6 +3400,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=
@@ -3219,12 +3408,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=
@@ -3253,7 +3463,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=
@@ -3265,6 +3475,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=
@@ -3323,6 +3536,7 @@=0A=
 	struct iwn_fw_dump dump;=0A=
 	int i;=0A=
 =0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
 	/* Force a complete recalibration on next init. */=0A=
@@ -3372,6 +3586,7 @@=0A=
 		    i, ring->qid, ring->cur, ring->queued);=0A=
 	}=0A=
 	printf("  rx ring: cur=3D%d\n", sc->rxq.cur);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
 }=0A=
 =0A=
 static void=0A=
@@ -3408,8 +3623,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=
@@ -3419,6 +3632,9 @@=0A=
 	if (!(sc->sc_flags & IWN_FLAG_USE_ICT))=0A=
 		IWN_WRITE(sc, IWN_FH_INT, r2);=0A=
 =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=
@@ -3521,7 +3737,7 @@=0A=
 {=0A=
 	uint16_t *w =3D &sc->sched[qid * IWN5000_SCHED_COUNT + idx];=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	*w =3D (*w & htole16(0xf000)) | htole16(1);=0A=
 	bus_dmamap_sync(sc->sched_dma.tag, sc->sched_dma.map,=0A=
@@ -3556,8 +3772,9 @@=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=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s begin\n", =
__func__);=0A=
 =0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
@@ -3573,21 +3790,24 @@=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=
+=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=
@@ -3679,10 +3899,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 IWN5000_ID_BROADCAST;=0A=
+	} else=0A=
 		tx->id =3D wn->id;=0A=
 =0A=
 	if (type =3D=3D IEEE80211_FC0_TYPE_MGT) {=0A=
@@ -3712,7 +3934,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 =
IWN5000_ID_BROADCAST)) {=0A=
 		/* Group or management frame. */=0A=
 		tx->linkq =3D 0;=0A=
 		/* XXX Alternate between antenna A and B? */=0A=
@@ -3744,7 +3966,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=
@@ -3803,9 +4025,8 @@=0A=
 	/* Mark TX ring as full if we reach a certain threshold. */=0A=
 	if (++ring->queued > IWN_TX_RING_HIMARK)=0A=
 		sc->qfullmsk |=3D 1 << ring->qid;=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE  | IWN_DEBUG_XMIT, "->%s: end\n",__func__);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
-=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -3829,9 +4050,9 @@=0A=
 	u_int hdrlen;=0A=
 	int ac, totlen, error, pad, nsegs =3D 0, i, rate;=0A=
 	uint8_t ridx, type, txant;=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s begin\n", =
__func__);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
 	wh =3D mtod(m, struct ieee80211_frame *);=0A=
@@ -3919,7 +4140,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 IWN5000_ID_BROADCAST;=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=
@@ -3957,7 +4181,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=
@@ -4017,7 +4241,7 @@=0A=
 	if (++ring->queued > IWN_TX_RING_HIMARK)=0A=
 		sc->qfullmsk |=3D 1 << ring->qid;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s: end\n",__func__);=0A=
 =0A=
 	return 0;=0A=
 }=0A=
@@ -4031,7 +4255,7 @@=0A=
 	struct iwn_softc *sc =3D ifp->if_softc;=0A=
 	int error =3D 0;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s begin\n", =
__func__);=0A=
 =0A=
 	if ((ifp->if_drv_flags & IFF_DRV_RUNNING) =3D=3D 0) {=0A=
 		ieee80211_free_node(ni);=0A=
@@ -4062,7 +4286,7 @@=0A=
 =0A=
 	IWN_UNLOCK(sc);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s: end\n",__func__);=0A=
 =0A=
 	return error;=0A=
 }=0A=
@@ -4114,12 +4338,15 @@=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=
+=0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
 	KASSERT(ifp->if_drv_flags & IFF_DRV_RUNNING, ("not running"));=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	if (sc->sc_tx_timer > 0) {=0A=
 		if (--sc->sc_tx_timer =3D=3D 0) {=0A=
@@ -4128,6 +4355,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=
@@ -4180,7 +4413,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=
@@ -4187,12 +4420,25 @@=0A=
 	struct mbuf *m;=0A=
 	bus_addr_t paddr;=0A=
 	int totlen, error;=0A=
+	int cmd_queue_num;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=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 | IWN_DEBUG_CMD, "->%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=
@@ -4201,7 +4447,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=
@@ -4227,8 +4473,8 @@=0A=
 	desc->segs[0].addr =3D htole32(IWN_LOADDR(paddr));=0A=
 	desc->segs[0].len  =3D htole16(IWN_HIADDR(paddr) | totlen << 4);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_CMD, "%s: %s (0x%x) flags %d qid %d idx %d\n",=0A=
-	    __func__, iwn_intr_str(cmd->code), cmd->code,=0A=
+	DPRINTF(sc, IWN_DEBUG_CMD, "Sending %s (0x%x) flags %d qid %d idx =
%d\n",=0A=
+	    iwn_intr_str(cmd->code), cmd->code,=0A=
 	    cmd->flags, cmd->qid, cmd->idx);=0A=
 =0A=
 	if (size > sizeof cmd->data) {=0A=
@@ -4245,7 +4491,7 @@=0A=
 	ring->cur =3D (ring->cur + 1) % IWN_TX_RING_COUNT;=0A=
 	IWN_WRITE(sc, IWN_HBUS_TARG_WRPTR, ring->qid << 8 | ring->cur);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CMD, "->%s: end\n",__func__);=0A=
 =0A=
 	return async ? 0 : msleep(desc, &sc->sc_mtx, PCATCH, "iwncmd", hz);=0A=
 }=0A=
@@ -4276,7 +4522,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=
@@ -4351,11 +4604,13 @@=0A=
 	uint8_t txant;=0A=
 	int i, error;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s: =
begin\n",__func__);=0A=
 =0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=0A=
+=0A=
 	memset(&node, 0, sizeof node);=0A=
 	IEEE80211_ADDR_COPY(node.macaddr, ifp->if_broadcastaddr);=0A=
-	node.id =3D sc->broadcast_id;=0A=
+	node.id =3D IWN5000_ID_BROADCAST;=0A=
 	DPRINTF(sc, IWN_DEBUG_RESET, "%s: adding broadcast node\n", __func__);=0A=
 	if ((error =3D ops->add_node(sc, &node, async)) !=3D 0)=0A=
 		return error;=0A=
@@ -4364,7 +4619,7 @@=0A=
 	txant =3D IWN_LSB(sc->txchainmask);=0A=
 =0A=
 	memset(&linkq, 0, sizeof linkq);=0A=
-	linkq.id =3D sc->broadcast_id;=0A=
+	linkq.id =3D IWN5000_ID_BROADCAST;=0A=
 	linkq.antmsk_1stream =3D txant;=0A=
 	linkq.antmsk_2stream =3D IWN_ANT_AB;=0A=
 	linkq.ampdu_max =3D 64;=0A=
@@ -4382,7 +4637,7 @@=0A=
 		linkq.retry[i] =3D linkq.retry[0];=0A=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s: end\n",__func__);=0A=
 =0A=
 	return iwn_cmd(sc, IWN_CMD_LINK_QUALITY, &linkq, sizeof linkq, async);=0A=
 }=0A=
@@ -4427,19 +4682,25 @@=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, uint8_t mode)=0A=
 {=0A=
 	struct iwn_cmd_led led;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_LED, "->Doing %s\n", __func__);=0A=
 =0A=
 	/* Clear microcode LED ownership. */=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=
+	led.on  =3D on;=0A=
+=0A=
 	(void)iwn_cmd(sc, IWN_CMD_SET_LED, &led, sizeof led, 1);=0A=
 }=0A=
 =0A=
@@ -4451,21 +4712,32 @@=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=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->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=
+#ifdef IWN_4569=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=
+#endif=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=
@@ -4475,7 +4747,7 @@=0A=
 	struct iwn_cmd_timing cmd;=0A=
 	uint64_t val, mod;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	memset(&cmd, 0, sizeof cmd);=0A=
 	memcpy(&cmd.tstamp, ni->ni_tstamp.data, sizeof (uint64_t));=0A=
@@ -4487,8 +4759,10 @@=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=
 }=0A=
@@ -4537,7 +4811,7 @@=0A=
 	uint8_t chan;=0A=
 =0A=
 	/* Retrieve current channel from last RXON. */=0A=
-	chan =3D sc->rxon.chan;=0A=
+	chan =3D sc->rxon->chan;=0A=
 	DPRINTF(sc, IWN_DEBUG_RESET, "setting TX power for channel %d\n",=0A=
 	    chan);=0A=
 =0A=
@@ -4672,7 +4946,7 @@=0A=
 {=0A=
 	struct iwn5000_cmd_txpower cmd;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_TXPOW, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	/*=0A=
 	 * TX power calibration is handled automatically by the firmware=0A=
@@ -4721,19 +4995,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=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RECV, "->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=
@@ -4792,7 +5069,7 @@=0A=
 {=0A=
 	int32_t temp;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	/*=0A=
 	 * Temperature is not used by the driver for 5000 Series because=0A=
@@ -4803,6 +5080,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=
@@ -4814,10 +5093,9 @@=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=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	/* Reset calibration state machine. */=0A=
 	memset(calib, 0, sizeof (*calib));=0A=
@@ -4828,9 +5106,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=
@@ -4841,10 +5120,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=
@@ -4863,7 +5139,7 @@=0A=
 	uint32_t val;=0A=
 	int i;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s begin\n", =
__func__);=0A=
 =0A=
 	/* Accumulate RSSI and noise for all 3 antennas. */=0A=
 	for (i =3D 0; i < 3; i++) {=0A=
@@ -4896,8 +5172,8 @@=0A=
 =0A=
 #ifdef notyet=0A=
 	/* XXX Disable RX chains with no antennas connected. */=0A=
-	sc->rxon.rxchain =3D htole16(IWN_RXCHAIN_SEL(sc->chainmask));=0A=
-	(void)iwn_cmd(sc, IWN_CMD_RXON, &sc->rxon, sc->rxonsz, 1);=0A=
+	sc->rxon->rxchain =3D htole16(IWN_RXCHAIN_SEL(sc->chainmask));=0A=
+	(void)iwn_cmd(sc, IWN_CMD_RXON, sc->rxon, sc->rxonsz, 1);=0A=
 #endif=0A=
 =0A=
 	/* Enable power-saving mode if requested by user. */=0A=
@@ -4904,7 +5180,7 @@=0A=
 	if (ic->ic_flags & IEEE80211_F_PMGTON)=0A=
 		(void)iwn_set_pslevel(sc, 0, 3, 1);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s: =
end\n",__func__);=0A=
 =0A=
 }=0A=
 =0A=
@@ -4928,7 +5204,7 @@=0A=
 {=0A=
 	struct iwn_phy_calib cmd;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	memset(&cmd, 0, sizeof cmd);=0A=
 	cmd.code =3D sc->reset_noise_gain;=0A=
@@ -4981,7 +5257,7 @@=0A=
 	struct iwn_phy_calib_gain cmd;=0A=
 	int i, ant, div, delta;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->Doing %s\n", =
__func__);=0A=
 =0A=
 	/* We collected 20 beacons and !=3D6050 need a 1.5 factor. */=0A=
 	div =3D (sc->hw_type =3D=3D IWN_HW_REV_TYPE_6050) ? 20 : 30;=0A=
@@ -5041,11 +5317,11 @@=0A=
 	uint8_t noise[3], noise_ref;=0A=
 	int i, needs_update =3D 0;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s begin\n", =
__func__);=0A=
 =0A=
 	/* Check that we've been enabled long enough. */=0A=
 	if ((rxena =3D le32toh(stats->general.load)) =3D=3D 0){=0A=
-		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end not so long\n", __func__);=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s end not so =
long\n", __func__);=0A=
 		return;=0A=
 	}=0A=
 =0A=
@@ -5166,7 +5442,7 @@=0A=
 	if (needs_update)=0A=
 		(void)iwn_send_sensitivity(sc);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_CALIBRATE, "->%s: =
end\n",__func__);=0A=
 =0A=
 #undef dec=0A=
 #undef inc=0A=
@@ -5187,7 +5463,8 @@=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        =3D htole16(calib->energy_ofdm);=0A=
+	/* Value energy_ofdm_th doesn't change across series in linux Kernel */=0A=
 	cmd.energy_ofdm_th     =3D htole16(62);=0A=
 	/* CCK modulation. */=0A=
 	cmd.corr_cck_x4        =3D htole16(calib->cck_x4);=0A=
@@ -5195,7 +5472,7 @@=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_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=
@@ -5222,6 +5499,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=
@@ -5230,8 +5509,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=
@@ -5249,7 +5545,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=
@@ -5276,9 +5572,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=
@@ -5304,25 +5609,61 @@=0A=
 		0xc0004000, 0x00004000, 0xf0005000, 0xf0005000,=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=
@@ -5353,19 +5694,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=
@@ -5375,30 +5703,44 @@=0A=
 	uint16_t rxchain;=0A=
 	int error;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%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=
-			    "%s: could not set temperature offset\n", __func__);=0A=
+				"%s: could not compute 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=
+=0A=
 	if (sc->hw_type !=3D IWN_HW_REV_TYPE_4965) {=0A=
 		txmask =3D htole32(sc->txchainmask);=0A=
 		DPRINTF(sc, IWN_DEBUG_RESET,=0A=
@@ -5413,34 +5755,24 @@=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=
-	memset(&sc->rxon, 0, sizeof (struct iwn_rxon));=0A=
-	IEEE80211_ADDR_COPY(sc->rxon.myaddr, IF_LLADDR(ifp));=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 | IWN_RXON_CTS_TO_SELF);=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=0A=
+	memset(sc->rxon, 0, sizeof (struct iwn_rxon));=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->myaddr, IF_LLADDR(ifp));=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 | IWN_RXON_CTS_TO_SELF);=0A=
 	if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan))=0A=
-		sc->rxon.flags |=3D htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);=0A=
 	switch (ic->ic_opmode) {=0A=
 	case IEEE80211_M_STA:=0A=
-		sc->rxon.mode =3D IWN_MODE_STA;=0A=
-		sc->rxon.filter =3D htole32(IWN_FILTER_MULTICAST);=0A=
+		sc->rxon->mode =3D IWN_MODE_STA;=0A=
+		sc->rxon->filter =3D htole32(IWN_FILTER_MULTICAST);=0A=
 		break;=0A=
 	case IEEE80211_M_MONITOR:=0A=
-		sc->rxon.mode =3D IWN_MODE_MONITOR;=0A=
-		sc->rxon.filter =3D htole32(IWN_FILTER_MULTICAST |=0A=
+		sc->rxon->mode =3D IWN_MODE_MONITOR;=0A=
+		sc->rxon->filter =3D htole32(IWN_FILTER_MULTICAST |=0A=
 		    IWN_FILTER_CTL | IWN_FILTER_PROMISC);=0A=
 		break;=0A=
 	default:=0A=
@@ -5447,18 +5779,20 @@=0A=
 		/* Should not get there. */=0A=
 		break;=0A=
 	}=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=
+=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->rxchain =3D htole16(rxchain);=0A=
+=0A=
 	DPRINTF(sc, IWN_DEBUG_RESET, "%s: setting configuration\n", __func__);=0A=
-	error =3D iwn_cmd(sc, IWN_CMD_RXON, &sc->rxon, sc->rxonsz, 0);=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_RXON, sc->rxon, sc->rxonsz, 0);=0A=
 	if (error !=3D 0) {=0A=
 		device_printf(sc->sc_dev, "%s: RXON command failed\n",=0A=
 		    __func__);=0A=
@@ -5484,14 +5818,24 @@=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=
 	}=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s: end\n",__func__);=0A=
 =0A=
 	return 0;=0A=
 }=0A=
@@ -5526,9 +5870,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=
+=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=
@@ -5560,7 +5915,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 IWN5000_ID_BROADCAST;=0A=
+=0A=
 	tx->lifetime =3D htole32(IWN_LIFETIME_INFINITE);=0A=
 =0A=
 	if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan)) {=0A=
@@ -5570,7 +5929,7 @@=0A=
 	} else {=0A=
 		hdr->flags =3D htole32(IWN_RXON_24GHZ | IWN_RXON_AUTO);=0A=
 		if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_4965 &&=0A=
-		    sc->rxon.associd && sc->rxon.chan > 14)=0A=
+		    sc->rxon->associd && sc->rxon->chan > 14)=0A=
 			tx->rate =3D htole32(0xd);=0A=
 		else {=0A=
 			/* Send probe requests at 1Mbps. */=0A=
@@ -5597,7 +5956,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=
@@ -5619,36 +5978,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=
@@ -5662,6 +6046,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=
@@ -5681,31 +6068,32 @@=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
 =0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=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=
+	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=
+		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=
+		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=
+		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=
+		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=
+		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=
+		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=
-	error =3D iwn_cmd(sc, IWN_CMD_RXON, &sc->rxon, sc->rxonsz, 1);=0A=
+	    sc->rxon->chan, sc->rxon->flags, sc->rxon->cck_mask,=0A=
+	    sc->rxon->ofdm_mask);=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_RXON, sc->rxon, sc->rxonsz, 1);=0A=
 	if (error !=3D 0) {=0A=
 		device_printf(sc->sc_dev, "%s: RXON command failed, error %d\n",=0A=
 		    __func__, error);=0A=
@@ -5747,9 +6135,20 @@=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=
+	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=
+=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=
@@ -5759,26 +6158,26 @@=0A=
 	}=0A=
 =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=
+	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=
+		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=
+		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=
+		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=
+		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=
+		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=
+		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=
@@ -5795,11 +6194,11 @@=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=
+	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=
-	error =3D iwn_cmd(sc, IWN_CMD_RXON, &sc->rxon, sc->rxonsz, 1);=0A=
+	    sc->rxon->chan, sc->rxon->flags);=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_RXON, sc->rxon, sc->rxonsz, 1);=0A=
 	if (error !=3D 0) {=0A=
 		device_printf(sc->sc_dev,=0A=
 		    "%s: could not update configuration, error %d\n", __func__,=0A=
@@ -5837,7 +6236,7 @@=0A=
 			node.htflags |=3D htole32(IWN_NODE_HT40);=0A=
 	}=0A=
 	DPRINTF(sc, IWN_DEBUG_STATE, "%s: adding BSS node\n", __func__);=0A=
-	error =3D ops->add_node(sc, &node, 1);=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 node, error %d\n", __func__, error);=0A=
@@ -5865,11 +6264,17 @@=0A=
 	    sc);=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=
@@ -6222,9 +6627,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=
@@ -6356,6 +6767,32 @@=0A=
 	return 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 initialization or runtime firmware=0A=
  * notifies us of its readiness (called in a process context).=0A=
@@ -6386,7 +6823,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=
@@ -6406,32 +6847,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=
@@ -6781,6 +7219,25 @@=0A=
 				sc->noise_gain =3D tmp + 1;=0A=
 			}=0A=
 			break;=0A=
+		case IWN_FW_TLV_PAN:=0A=
+			sc->sc_flags |=3D IWN_FLAG_PAN_SUPPORT;=0A=
+			DPRINTF(sc, IWN_DEBUG_RESET,"PAN Support found : %d\n", 1);=0A=
+			break;=0A=
+		case IWN_FW_TLV_FLAGS :=0A=
+			sc->tlv_feature_flags =3D htole32(*ptr);=0A=
+			break;=0A=
+		case IWN_FW_TLV_PBREQ_MAXLEN:=0A=
+		case IWN_FW_TLV_RUNT_EVTLOG_PTR:=0A=
+		case IWN_FW_TLV_RUNT_EVTLOG_SIZE:=0A=
+		case IWN_FW_TLV_RUNT_ERRLOG_PTR:=0A=
+		case IWN_FW_TLV_INIT_EVTLOG_PTR:=0A=
+		case IWN_FW_TLV_INIT_EVTLOG_SIZE:=0A=
+		case IWN_FW_TLV_INIT_ERRLOG_PTR:=0A=
+		case IWN_FW_TLV_WOWLAN_INST:=0A=
+		case IWN_FW_TLV_WOWLAN_DATA:=0A=
+			DPRINTF(sc, IWN_DEBUG_RESET,=0A=
+			    "TLV type %d reconized but not handled\n", le16toh(tlv->type));=0A=
+			break;=0A=
 		default:=0A=
 			DPRINTF(sc, IWN_DEBUG_RESET,=0A=
 			    "TLV type %d not handled\n", le16toh(tlv->type));=0A=
@@ -6902,9 +7359,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=
@@ -7016,13 +7472,13 @@=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=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -7157,7 +7613,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=
@@ -7228,6 +7684,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=
@@ -7362,6 +7824,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=
@@ -7386,10 +7849,24 @@=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=
+=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=
@@ -7401,12 +7878,20 @@=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=
+=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=
@@ -7454,10 +7939,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=
@@ -7566,3 +8055,1018 @@=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=
+			case IWN_SDID_6x00_1:=0A=
+			case IWN_SDID_6x00_2:=0A=
+			case IWN_SDID_6x00_8:=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=
+			case IWN_SDID_6x00_4:=0A=
+			case IWN_SDID_6x00_7:=0A=
+			case IWN_SDID_6x00_10:=0A=
+			case IWN_SDID_6x00_5:=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=
+			case IWN_SDID_6x05_2:=0A=
+			case IWN_SDID_6x05_5:=0A=
+			case IWN_SDID_6x05_7:=0A=
+			case IWN_SDID_6x05_3:=0A=
+			case IWN_SDID_6x05_8:=0A=
+			case IWN_SDID_6x05_9:=0A=
+			case IWN_SDID_6x05_10:=0A=
+			case IWN_SDID_6x05_11:=0A=
+			case IWN_SDID_6x05_12:=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=
+			case IWN_SDID_6050_2:=0A=
+			case IWN_SDID_6050_4:=0A=
+			case IWN_SDID_6050_6:=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=
+			case IWN_SDID_6150_2:=0A=
+			case IWN_SDID_6150_4:=0A=
+			case IWN_SDID_6150_6:=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=
+			case IWN_SDID_x030_2:=0A=
+			case IWN_SDID_x030_4:=0A=
+			case IWN_SDID_x030_6:=0A=
+			case IWN_SDID_x030_7:=0A=
+			case IWN_SDID_x030_10:=0A=
+			case IWN_SDID_x030_14:=0A=
+			case IWN_SDID_x030_8:=0A=
+			case IWN_SDID_x030_11:=0A=
+			case IWN_SDID_x030_15:=0A=
+			case IWN_SDID_x030_9:=0A=
+			case IWN_SDID_x030_12:=0A=
+			case IWN_SDID_x030_16:=0A=
+			case IWN_SDID_x030_13:=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=0A=
+ * see rx_with_siso_diversity in linux kernel=0A=
+ */=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=
+			case IWN_SDID_130_2:=0A=
+			case IWN_SDID_130_4:=0A=
+			case IWN_SDID_130_6:=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=
+			case IWN_SDID_2x30_2:=0A=
+			case IWN_SDID_2x30_4:=0A=
+			case IWN_SDID_2x30_6:=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=
+				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=
+				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=
+				sc->txchainmask =3D IWN_ANT_B;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				break;=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=
+				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=
+				sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_default_base_params;=0A=
+				sc->fwname =3D "iwn5000fw";=0A=
+				break;=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=
+			case IWN_SDID_5x50_6:=0A=
+			case IWN_SDID_5x50_7:=0A=
+			case IWN_SDID_5x50_12:=0A=
+			case IWN_SDID_5x50_13:=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=
+	DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s: sending request for statistics"=0A=
+	    " flags : 0x%x\n", __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",=0A=
+		    __func__);=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=
Index: 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=
--- if_iwnreg.h	(revision 253911)=0A=
+++ 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=
+ * Nota : 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=
@@ -1687,7 +1704,14 @@=0A=
 	uint8_t	hi;	/* high channel number */=0A=
 	struct	iwn4965_eeprom_chan_samples chans[2];=0A=
 } __packed;=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=
+#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=
@@ -1834,6 +1858,7 @@=0A=
 	0x62, 0x6e, 0x68, 0x62, 0x6e, 0x68, 0x62, 0x6e, 0x68, 0x62, 0x6e,=0A=
 	0x68, 0x62, 0x6e, 0x68, 0x62, 0x5d, 0x58, 0x53, 0x4e=0A=
 };=0A=
+#define IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP=0A=
 =0A=
 /*=0A=
  * Power saving settings (values obtained from the reference driver.)=0A=
@@ -1891,6 +1916,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 +1943,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 +1956,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 +1969,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 +1980,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 +2082,281 @@=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=
+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=
+/* =
=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=
+ * =
=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=
+/* 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=
+	const bool		shadow_reg_enable;=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=0A=
+	    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=
+/* 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=
+	false, //shadow_reg_enable=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=
+	false, //shadow_reg_enable=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=
+=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=
+	false, //shadow_reg_enable=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=
+	false, //shadow_reg_enable=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=
+	false, //shadow_reg_enable=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=
+	false, //shadow_reg_enable=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=
+	false, //shadow_reg_enable=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=
+	false, //shadow_reg_enable=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=
+	false, //shadow_reg_enable=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=
+	false, //shadow_reg_enable=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: 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=
--- if_iwnvar.h	(revision 253911)=0A=
+++ if_iwnvar.h	(working copy)=0A=
@@ -2,6 +2,8 @@=0A=
 /*	$OpenBSD: if_iwnvar.h,v 1.18 2010/04/30 16:06:46 damien Exp $	*/=0A=
 =0A=
 /*-=0A=
+ * Copyright (c) 2013 Cedric GROSS <cg@cgross.info>=0A=
+ * Copyright (c) 2011 Intel Corporation=0A=
  * Copyright (c) 2007, 2008=0A=
  *	Damien Bergamini <damien.bergamini@free.fr>=0A=
  * Copyright (c) 2008 Sam Leffler, Errno Consulting=0A=
@@ -18,7 +20,39 @@=0A=
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT =
OF=0A=
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.=0A=
  */=0A=
+enum iwn_rxon_ctx_id {=0A=
+        IWN_RXON_BSS_CTX,=0A=
+        IWN_RXON_PAN_CTX,=0A=
+        IWN_NUM_RXON_CTX=0A=
+};=0A=
 =0A=
+struct iwn_pan_slot {=0A=
+	uint16_t time;=0A=
+	uint8_t type;=0A=
+	uint8_t reserved;=0A=
+} __packed;=0A=
+=0A=
+struct iwn_pan_params_cmd {=0A=
+	uint16_t flags;=0A=
+#define	IWN_PAN_PARAMS_FLG_SLOTTED_MODE	(1 << 3)=0A=
+=0A=
+	uint8_t reserved;=0A=
+	uint8_t num_slots;=0A=
+	struct iwn_pan_slot slots[10];=0A=
+} __packed;=0A=
+=0A=
+struct iwn_led_mode=0A=
+{=0A=
+	uint8_t		led_cur_mode;=0A=
+	uint64_t	led_cur_bt;=0A=
+	uint64_t	led_last_bt;=0A=
+	uint64_t	led_cur_tpt;=0A=
+	uint64_t	led_last_tpt;=0A=
+	uint64_t	led_bt_diff;=0A=
+	int		led_cur_time;=0A=
+	int		led_last_time;=0A=
+};=0A=
+=0A=
 struct iwn_rx_radiotap_header {=0A=
 	struct ieee80211_radiotap_header wr_ihdr;=0A=
 	uint64_t	wr_tsft;=0A=
@@ -140,6 +174,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=
@@ -191,6 +228,10 @@=0A=
 =0A=
 	int			(*iv_newstate)(struct ieee80211vap *,=0A=
 				    enum ieee80211_state, int);=0A=
+	int			ctx;=0A=
+	int			beacon_int;=0A=
+	uint8_t			macaddr[IEEE80211_ADDR_LEN];=0A=
+=0A=
 };=0A=
 #define	IWN_VAP(_vap)	((struct iwn_vap *)(_vap))=0A=
 =0A=
@@ -210,8 +251,11 @@=0A=
 #define IWN_FLAG_HAS_11N	(1 << 6)=0A=
 #define IWN_FLAG_ENH_SENS	(1 << 7)=0A=
 #define IWN_FLAG_ADV_BTCOEX	(1 << 8)=0A=
+#define IWN_FLAG_PAN_SUPPORT	(1 << 9)=0A=
 =0A=
 	uint8_t 		hw_type;=0A=
+	/* subdevice_id used to adjust configuration */=0A=
+	uint16_t			subdevice_id;=0A=
 =0A=
 	struct iwn_ops		ops;=0A=
 	const char		*fwname;=0A=
@@ -272,15 +316,20 @@=0A=
 	int			calib_cnt;=0A=
 	struct iwn_calib_state	calib;=0A=
 	struct callout		watchdog_to;=0A=
-=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=
 	int			last_rx_valid;=0A=
 	struct iwn_ucode_info	ucode_info;=0A=
-	struct iwn_rxon		rxon;=0A=
+	struct iwn_rxon		rx_on[IWN_NUM_RXON_CTX];=0A=
+	struct iwn_rxon		*rxon;=0A=
+	int			ctx;=0A=
+	struct ieee80211vap	*ivap[IWN_NUM_RXON_CTX];=0A=
+	uint8_t			uc_pan_support; /*CG: PAN support */=0A=
+	uint8_t			uc_scan_progress;=0A=
 	uint32_t		rawtemp;=0A=
 	int			temp;=0A=
 	int			noise;=0A=
@@ -295,11 +344,14 @@=0A=
 	char			eeprom_domain[4];=0A=
 	uint32_t		eeprom_crystal;=0A=
 	int16_t			eeprom_temp;=0A=
+	int16_t			eeprom_temp_high;=0A=
 	int16_t			eeprom_voltage;=0A=
 	int8_t			maxpwr2GHz;=0A=
 	int8_t			maxpwr5GHz;=0A=
 	int8_t			maxpwr[IEEE80211_CHAN_MAX];=0A=
 =0A=
+	uint32_t		tlv_feature_flags;=0A=
+=0A=
 	int32_t			temp_off;=0A=
 	uint32_t		int_mask;=0A=
 	uint8_t			ntxchains;=0A=
@@ -309,6 +361,7 @@=0A=
 	uint8_t			chainmask;=0A=
 =0A=
 	int			sc_tx_timer;=0A=
+	int			sc_scan_timer;=0A=
 =0A=
 	struct ieee80211_tx_ampdu *qid2tap[IWN5000_NTXQUEUES];=0A=
 =0A=
@@ -323,9 +376,22 @@=0A=
 	void			(*sc_addba_stop)(struct ieee80211_node *,=0A=
 				    struct ieee80211_tx_ampdu *);=0A=
 =0A=
+	struct	iwn_led_mode sc_led;=0A=
 =0A=
 	struct iwn_rx_radiotap_header sc_rxtap;=0A=
 	struct iwn_tx_radiotap_header sc_txtap;=0A=
+=0A=
+=0A=
+	/* The power save level originally configured by user */=0A=
+	int			desired_pwrsave_level;=0A=
+=0A=
+	/* The current power save level, this may differ from the configured =
value due to=0A=
+	 * thermal throttling etc.=0A=
+	 * */=0A=
+	int			current_pwrsave_level;=0A=
+=0A=
+	/* For specifique params */=0A=
+	struct iwn_base_params *base_params;=0A=
 };=0A=
 =0A=
 #define IWN_LOCK_INIT(_sc) \=0A=

------=_NextPart_000_0011_01CE904C.AB032F70--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001001ce903b$e77a5f70$b66f1e50$>