Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Jul 2013 10:45:19 +0200
From:      "Cedric GROSS" <cg@cgross.info>
To:        <freebsd-wireless@freebsd.org>
Subject:   [IWN] Centrino 2230 patch.
Message-ID:  <000301ce8b6e$cbca9dc0$635fd940$@info>

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

------=_NextPart_000_0004_01CE8B7F.8F536DC0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hello,

 

Here is the full patch against -HEAD for managing 2230 NIC and 6235.

 

You will need firmware file. It's too big for the ML.

 

Cedric


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

Index: sys/dev/iwn/if_iwn.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/dev/iwn/if_iwn.c	(revision 253707)=0A=
+++ sys/dev/iwn/if_iwn.c	(working copy)=0A=
@@ -1,4 +1,6 @@=0A=
 /*-=0A=
+ * Copyright (c) 2013 Cedric GROSS <c.gross@kreiz-it.fr>=0A=
+ * Copyright (c) 2011 Intel Corporation=0A=
  * Copyright (c) 2007-2009=0A=
  *	Damien Bergamini <damien.bergamini@free.fr>=0A=
  * Copyright (c) 2008=0A=
@@ -22,7 +24,7 @@=0A=
  * Driver for Intel WiFi Link 4965 and 1000/5000/6000 Series 802.11 =
network=0A=
  * adapters.=0A=
  */=0A=
-=0A=
+ =0A=
 #include <sys/cdefs.h>=0A=
 __FBSDID("$FreeBSD$");=0A=
 =0A=
@@ -74,6 +76,7 @@=0A=
 #include <dev/iwn/if_iwnreg.h>=0A=
 #include <dev/iwn/if_iwnvar.h>=0A=
 =0A=
+=0A=
 struct iwn_ident {=0A=
 	uint16_t	vendor;=0A=
 	uint16_t	device;=0A=
@@ -81,40 +84,42 @@=0A=
 };=0A=
 =0A=
 static const struct iwn_ident iwn_ident_table[] =3D {=0A=
-	{ 0x8086, 0x0082, "Intel Centrino Advanced-N 6205"		},=0A=
-	{ 0x8086, 0x0083, "Intel Centrino Wireless-N 1000"		},=0A=
-	{ 0x8086, 0x0084, "Intel Centrino Wireless-N 1000"		},=0A=
-	{ 0x8086, 0x0085, "Intel Centrino Advanced-N 6205"		},=0A=
-	{ 0x8086, 0x0087, "Intel Centrino Advanced-N + WiMAX 6250"	},=0A=
-	{ 0x8086, 0x0089, "Intel Centrino Advanced-N + WiMAX 6250"	},=0A=
-	{ 0x8086, 0x008a, "Intel Centrino Wireless-N 1030"		},=0A=
-	{ 0x8086, 0x008b, "Intel Centrino Wireless-N 1030"		},=0A=
-	{ 0x8086, 0x0090, "Intel Centrino Advanced-N 6230"		},=0A=
-	{ 0x8086, 0x0091, "Intel Centrino Advanced-N 6230"		},=0A=
-	{ 0x8086, 0x0885, "Intel Centrino Wireless-N + WiMAX 6150"	},=0A=
-	{ 0x8086, 0x0886, "Intel Centrino Wireless-N + WiMAX 6150"	},=0A=
-	{ 0x8086, 0x0887, "Intel Centrino Wireless-N 2230"		},=0A=
-	{ 0x8086, 0x0888, "Intel Centrino Wireless-N 2230"		},=0A=
-	{ 0x8086, 0x0896, "Intel Centrino Wireless-N 130"		},=0A=
-	{ 0x8086, 0x0897, "Intel Centrino Wireless-N 130"		},=0A=
-	{ 0x8086, 0x08ae, "Intel Centrino Wireless-N 100"		},=0A=
-	{ 0x8086, 0x08af, "Intel Centrino Wireless-N 100"		},=0A=
+	{ 0x8086, IWN_DID_6x05_1, "Intel Centrino Advanced-N 6205"		},=0A=
+	{ 0x8086, IWN_DID_1000_1, "Intel Centrino Wireless-N 1000"		},=0A=
+	{ 0x8086, IWN_DID_1000_2, "Intel Centrino Wireless-N 1000"		},=0A=
+	{ 0x8086, IWN_DID_6x05_2, "Intel Centrino Advanced-N 6205"		},=0A=
+	{ 0x8086, IWN_DID_6050_1, "Intel Centrino Advanced-N + WiMAX 6250"	},=0A=
+	{ 0x8086, IWN_DID_6050_2, "Intel Centrino Advanced-N + WiMAX 6250"	},=0A=
+	{ 0x8086, IWN_DID_x030_1, "Intel Centrino Wireless-N 1030"		},=0A=
+	{ 0x8086, IWN_DID_x030_2, "Intel Centrino Wireless-N 1030"		},=0A=
+	{ 0x8086, IWN_DID_x030_3, "Intel Centrino Advanced-N 6230"		},=0A=
+	{ 0x8086, IWN_DID_x030_4, "Intel Centrino Advanced-N 6230"		},=0A=
+	{ 0x8086, IWN_DID_6150_1, "Intel Centrino Wireless-N + WiMAX 6150"	},=0A=
+	{ 0x8086, IWN_DID_6150_2, "Intel Centrino Wireless-N + WiMAX 6150"	},=0A=
+	{ 0x8086, IWN_DID_2x30_1, "Intel Centrino Wireless-N 2230"},=0A=
+    { 0x8086, IWN_DID_2x30_2, "Intel Centrino Wireless-N 2230"},=0A=
+	{ 0x8086, IWN_DID_130_1, "Intel Centrino Wireless-N 130"		},=0A=
+	{ 0x8086, IWN_DID_130_2, "Intel Centrino Wireless-N 130"		},=0A=
+	{ 0x8086, IWN_DID_100_1, "Intel Centrino Wireless-N 100"		},=0A=
+	{ 0x8086, IWN_DID_100_2, "Intel Centrino Wireless-N 100"		},=0A=
 	{ 0x8086, 0x4229, "Intel Wireless WiFi Link 4965"		},=0A=
-	{ 0x8086, 0x422b, "Intel Centrino Ultimate-N 6300"		},=0A=
-	{ 0x8086, 0x422c, "Intel Centrino Advanced-N 6200"		},=0A=
+	{ 0x8086, IWN_DID_6x00_1, "Intel Centrino Ultimate-N 6300"		},=0A=
+	{ 0x8086, IWN_DID_6x00_2, "Intel Centrino Advanced-N 6200"		},=0A=
 	{ 0x8086, 0x422d, "Intel Wireless WiFi Link 4965"		},=0A=
 	{ 0x8086, 0x4230, "Intel Wireless WiFi Link 4965"		},=0A=
-	{ 0x8086, 0x4232, "Intel WiFi Link 5100"			},=0A=
+	{ 0x8086, IWN_DID_5x00_1, "Intel WiFi Link 5100"			},=0A=
 	{ 0x8086, 0x4233, "Intel Wireless WiFi Link 4965"		},=0A=
-	{ 0x8086, 0x4235, "Intel Ultimate N WiFi Link 5300"		},=0A=
-	{ 0x8086, 0x4236, "Intel Ultimate N WiFi Link 5300"		},=0A=
-	{ 0x8086, 0x4237, "Intel WiFi Link 5100"			},=0A=
-	{ 0x8086, 0x4238, "Intel Centrino Ultimate-N 6300"		},=0A=
-	{ 0x8086, 0x4239, "Intel Centrino Advanced-N 6200"		},=0A=
-	{ 0x8086, 0x423a, "Intel WiMAX/WiFi Link 5350"			},=0A=
-	{ 0x8086, 0x423b, "Intel WiMAX/WiFi Link 5350"			},=0A=
-	{ 0x8086, 0x423c, "Intel WiMAX/WiFi Link 5150"			},=0A=
-	{ 0x8086, 0x423d, "Intel WiMAX/WiFi Link 5150"			},=0A=
+	{ 0x8086, IWN_DID_5x00_3, "Intel Ultimate N WiFi Link 5300"		},=0A=
+	{ 0x8086, IWN_DID_5x00_4, "Intel Ultimate N WiFi Link 5300"		},=0A=
+	{ 0x8086, IWN_DID_5x00_2, "Intel WiFi Link 5100"			},=0A=
+	{ 0x8086, IWN_DID_6x00_3, "Intel Centrino Ultimate-N 6300"		},=0A=
+	{ 0x8086, IWN_DID_6x00_4, "Intel Centrino Advanced-N 6200"		},=0A=
+	{ 0x8086, IWN_DID_5x50_1, "Intel WiMAX/WiFi Link 5350"			},=0A=
+	{ 0x8086, IWN_DID_5x50_2, "Intel WiMAX/WiFi Link 5350"			},=0A=
+	{ 0x8086, IWN_DID_5x50_3, "Intel WiMAX/WiFi Link 5150"			},=0A=
+	{ 0x8086, IWN_DID_5x50_4, "Intel WiMAX/WiFi Link 5150"			},=0A=
+	{ 0x8086, IWN_DID_6035_1, "Centrino Advanced-N 6235"		},=0A=
+	{ 0x8086, IWN_DID_6035_2, "Centrino Advanced-N 6235"		},=0A=
 	{ 0, 0, NULL }=0A=
 };=0A=
 =0A=
@@ -160,7 +165,9 @@=0A=
 static int	iwn_read_eeprom(struct iwn_softc *,=0A=
 		    uint8_t macaddr[IEEE80211_ADDR_LEN]);=0A=
 static void	iwn4965_read_eeprom(struct iwn_softc *);=0A=
+#ifdef	IWN_DEBUG=0A=
 static void	iwn4965_print_power_group(struct iwn_softc *, int);=0A=
+#endif=0A=
 static void	iwn5000_read_eeprom(struct iwn_softc *);=0A=
 static uint32_t	iwn_eeprom_channel_flags(struct iwn_eeprom_chan *);=0A=
 static void	iwn_read_eeprom_band(struct iwn_softc *, int);=0A=
@@ -229,7 +236,7 @@=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 =
, 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=
@@ -255,7 +262,7 @@=0A=
 static int	iwn_set_pslevel(struct iwn_softc *, int, int, int);=0A=
 static int	iwn_send_btcoex(struct iwn_softc *);=0A=
 static int	iwn_send_advanced_btcoex(struct iwn_softc *);=0A=
-static int	iwn5000_runtime_calib(struct iwn_softc *);=0A=
+//static int	iwn5000_runtime_calib(struct iwn_softc *);=0A=
 static int	iwn_config(struct iwn_softc *);=0A=
 static uint8_t	*ieee80211_add_ssid(uint8_t *, const uint8_t *, u_int);=0A=
 static int	iwn_scan(struct iwn_softc *);=0A=
@@ -286,6 +293,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=
@@ -320,8 +328,27 @@=0A=
 static void	iwn_scan_curchan(struct ieee80211_scan_state *, unsigned =
long);=0A=
 static void	iwn_scan_mindwell(struct ieee80211_scan_state *);=0A=
 static void	iwn_hw_reset(void *, int);=0A=
+#ifdef	IWN_DEBUG=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_prepare_crystal_calib(struct iwn_softc *sc);=0A=
+static int iwn_set_statistics_request(struct iwn_softc *,bool ,bool =
,int );=0A=
+static int iwn_cfg_ucode_post_alive(struct iwn_softc *);=0A=
+static int iwn_iv_reset(struct ieee80211vap *, u_long );=0A=
+static int iwn_newstate_u1(struct ieee80211vap *, enum ieee80211_state =
, int );=0A=
+static int iwn_auth_u1(struct iwn_softc *, struct ieee80211vap *);=0A=
+static int iwn_run_u1(struct iwn_softc *, struct ieee80211vap *);=0A=
+static int iwn_set_timing_u1(struct iwn_softc *);=0A=
+static int iwn_config_u1(struct iwn_softc *);=0A=
+static int iwn_set_pan_params(struct iwn_softc *);=0A=
+static int iwn_updateedca_u1(struct ieee80211com *);=0A=
+static int iwn_add_broadcast_node_u1(struct iwn_softc *, int );=0A=
+static uint16_t iwn_get_active_dwell(struct iwn_softc *, struct =
ieee80211_channel *);=0A=
+static uint16_t iwn_get_passive_dwell(struct iwn_softc *, struct =
ieee80211_channel *);=0A=
+static void iwn_led_pattern(struct iwn_softc *);=0A=
 =0A=
-#define IWN_DEBUG=0A=
 #ifdef IWN_DEBUG=0A=
 enum {=0A=
 	IWN_DEBUG_XMIT		=3D 0x00000001,	/* basic xmit operation */=0A=
@@ -339,6 +366,7 @@=0A=
 	IWN_DEBUG_CMD		=3D 0x00001000,	/* cmd submission */=0A=
 	IWN_DEBUG_TXRATE	=3D 0x00002000,	/* TX rate debugging */=0A=
 	IWN_DEBUG_PWRSAVE	=3D 0x00004000,	/* Power save operations */=0A=
+	IWN_DEBUG_REGISTER	=3D 0x20000000,	/* print chipset register */=0A=
 	IWN_DEBUG_TRACE		=3D 0x40000000,	/* Print begin and start driver =
function */=0A=
 	IWN_DEBUG_FATAL		=3D 0x80000000,	/* fatal errors */=0A=
 	IWN_DEBUG_ANY		=3D 0xffffffff=0A=
@@ -345,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=
@@ -366,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=
@@ -388,6 +417,21 @@=0A=
 	case IWN_CMD_SET_CRITICAL_TEMP:	return "IWN_CMD_SET_CRITICAL_TEMP";=0A=
 	case IWN_CMD_SET_SENSITIVITY:	return "IWN_CMD_SET_SENSITIVITY";=0A=
 	case IWN_CMD_PHY_CALIB:		return "IWN_CMD_PHY_CALIB";=0A=
+	case IWN_CMD_BT_COEX_PRIOTABLE: return "IWN_CMD_BT_COEX_PRIOTABLE";=0A=
+	case IWN_CMD_BT_COEX_PROT:	return "IWN_CMD_BT_COEX_PROT";=0A=
+	case IWN_CMD_BT_COEX_NOTIF:	return "IWN_CMD_BT_COEX_NOTIF";=0A=
+		/* PAN commands */=0A=
+	case  IWN_CMD_WIPAN_PARAMS:	return "IWN_CMD_WIPAN_PARAMS";		=0A=
+	case  IWN_CMD_WIPAN_RXON:	return "IWN_CMD_WIPAN_RXON";		=0A=
+	case  IWN_CMD_WIPAN_RXON_TIMING:	return "IWN_CMD_WIPAN_RXON_TIMING";	=0A=
+	case  IWN_CMD_WIPAN_RXON_ASSOC:	return "IWN_CMD_WIPAN_RXON_ASSOC";	=0A=
+	case  IWN_CMD_WIPAN_QOS_PARAM:	return "IWN_CMD_WIPAN_QOS_PARAM";=0A=
+	case  IWN_CMD_WIPAN_WEPKEY:	return "IWN_CMD_WIPAN_WEPKEY";	=0A=
+	case  IWN_CMD_WIPAN_P2P_CHANNEL_SWITCH:	return =
"IWN_CMD_WIPAN_P2P_CHANNEL_SWITCH";=0A=
+	case  IWN_CMD_WIPAN_NOA_NOTIFICATION:	return =
"IWN_CMD_WIPAN_NOA_NOTIFICATION";	=0A=
+	case  IWN_CMD_WIPAN_DEACTIVATION_COMPLETE:	return =
"IWN_CMD_WIPAN_DEACTIVATION_COMPLETE";=0A=
+=0A=
+=0A=
 	}=0A=
 	return "UNKNOWN INTR NOTIF/CMD";=0A=
 }=0A=
@@ -421,6 +465,7 @@=0A=
 MODULE_DEPEND(iwn, pci, 1, 1, 1);=0A=
 MODULE_DEPEND(iwn, wlan, 1, 1, 1);=0A=
 =0A=
+/* Should be better to add subdevice dependency*/=0A=
 static int=0A=
 iwn_probe(device_t dev)=0A=
 {=0A=
@@ -436,6 +481,7 @@=0A=
 	return ENXIO;=0A=
 }=0A=
 =0A=
+/* Here we detect chipset */=0A=
 static int=0A=
 iwn_attach(device_t dev)=0A=
 {=0A=
@@ -446,8 +492,12 @@=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=
+	=0A=
 #ifdef	IWN_DEBUG=0A=
 	error =3D resource_int_value(device_get_name(sc->sc_dev),=0A=
 	    device_get_unit(sc->sc_dev), "debug", &(sc->sc_debug));=0A=
@@ -456,9 +506,9 @@=0A=
 #else=0A=
 	sc->sc_debug =3D 0;=0A=
 #endif=0A=
+	=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_RESET, "->%s: begin\n",__func__);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: begin\n",__func__);=0A=
-=0A=
 	/*=0A=
 	 * Get the offset of the PCI Express Capability Structure in PCI=0A=
 	 * Configuration Space.=0A=
@@ -511,7 +561,8 @@=0A=
 	IWN_LOCK_INIT(sc);=0A=
 =0A=
 	/* Read hardware revision and attach. */=0A=
-	sc->hw_type =3D (IWN_READ(sc, IWN_HW_REV) >> 4) & 0xf;=0A=
+	sc->hw_type =3D (IWN_READ(sc, IWN_HW_REV) >> 4) & 0xff;=0A=
+	sc->subdevice_id=3Dpci_get_subdevice(dev);=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=
@@ -603,6 +654,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=
@@ -686,14 +742,24 @@=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=
 =0A=
+	=0A=
 	iwn_sysctlattach(sc);=0A=
 =0A=
 	/*=0A=
@@ -706,14 +772,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=
@@ -722,7 +795,8 @@=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 iwn4965_load_firmware;=0A=
 	ops->read_eeprom =3D iwn4965_read_eeprom;=0A=
 	ops->post_alive =3D iwn4965_post_alive;=0A=
@@ -752,9 +826,10 @@=0A=
 	/* Override chains masks, ROM is known to be broken. */=0A=
 	sc->txchainmask =3D IWN_ANT_AB;=0A=
 	sc->rxchainmask =3D IWN_ANT_ABC;=0A=
+	sc->base_params =3D &iwn_default_base_params; /* !! TODO : Define =
something may be more specific */=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "%s: end\n",__func__);=0A=
-=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "%s: end\n",__func__);=0A=
+	=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -762,9 +837,9 @@=0A=
 iwn5000_attach(struct iwn_softc *sc, uint16_t pid)=0A=
 {=0A=
 	struct iwn_ops *ops =3D &sc->ops;=0A=
+	=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
 	ops->load_firmware =3D iwn5000_load_firmware;=0A=
 	ops->read_eeprom =3D iwn5000_read_eeprom;=0A=
 	ops->post_alive =3D iwn5000_post_alive;=0A=
@@ -792,59 +867,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=
@@ -855,15 +878,19 @@=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=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
+=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=
-}=0A=
 =0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", =
__func__);=0A=
+=0A=
+		}=0A=
+=0A=
 static void=0A=
 iwn_sysctlattach(struct iwn_softc *sc)=0A=
 {=0A=
@@ -885,19 +912,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=
@@ -910,7 +972,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=
@@ -924,6 +991,8 @@=0A=
 	struct ieee80211com *ic;=0A=
 	int qid;=0A=
 =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=
 =0A=
@@ -933,6 +1002,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=
@@ -961,7 +1031,8 @@=0A=
 	if (ifp !=3D NULL)=0A=
 		if_free(ifp);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s done\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=
@@ -980,8 +1051,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=
@@ -989,12 +1067,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=
@@ -1002,7 +1091,7 @@=0A=
 iwn_nic_lock(struct iwn_softc *sc)=0A=
 {=0A=
 	int ntries;=0A=
-=0A=
+	=0A=
 	/* Request exclusive access to NIC. */=0A=
 	IWN_SETBITS(sc, IWN_GP_CNTRL, IWN_GP_CNTRL_MAC_ACCESS_REQ);=0A=
 =0A=
@@ -1011,9 +1100,11 @@=0A=
 		if ((IWN_READ(sc, IWN_GP_CNTRL) &=0A=
 		     (IWN_GP_CNTRL_MAC_ACCESS_ENA | IWN_GP_CNTRL_SLEEP)) =3D=3D=0A=
 		    IWN_GP_CNTRL_MAC_ACCESS_ENA)=0A=
-			return 0;=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=
@@ -1122,7 +1213,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=
@@ -1142,8 +1233,8 @@=0A=
 	uint16_t prev, base, next;=0A=
 	int count, error;=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=
+	=0A=
 	/* Wait for clock stabilization before accessing prph. */=0A=
 	if ((error =3D iwn_clock_wait(sc)) !=3D 0)=0A=
 		return error;=0A=
@@ -1156,7 +1247,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=
@@ -1169,11 +1260,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=
@@ -1182,14 +1273,12 @@=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=
-=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -1200,7 +1289,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=
@@ -1235,7 +1324,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=
@@ -1293,7 +1382,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=
@@ -1367,7 +1456,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=
@@ -1417,7 +1506,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=
@@ -1443,13 +1532,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=
@@ -1459,7 +1548,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=
@@ -1480,7 +1569,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=
@@ -1515,7 +1604,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=
@@ -1566,12 +1655,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=
@@ -1580,7 +1669,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=
@@ -1607,7 +1696,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=
@@ -1633,6 +1722,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=
@@ -1653,6 +1745,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, "->%s end\n", __func__);=0A=
 }=0A=
 =0A=
 static int=0A=
@@ -1662,8 +1757,8 @@=0A=
 	uint16_t val;=0A=
 	int error;=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=
+	=0A=
 	/* Check whether adapter has an EEPROM or an OTPROM. */=0A=
 	if (sc->hw_type >=3D IWN_HW_REV_TYPE_1000 &&=0A=
 	    (IWN_READ(sc, IWN_OTP_GP) & IWN_OTP_GP_DEV_SEL_OTP))=0A=
@@ -1698,6 +1793,7 @@=0A=
 	}=0A=
 =0A=
 	iwn_read_prom_data(sc, IWN_EEPROM_SKU_CAP, &val, 2);=0A=
+	=0A=
 	DPRINTF(sc, IWN_DEBUG_RESET, "SKU capabilities=3D0x%04x\n", =
le16toh(val));=0A=
 	/* Check if HT support is bonded out. */=0A=
 	if (val & htole16(IWN_EEPROM_SKU_CAP_11N))=0A=
@@ -1722,8 +1818,8 @@=0A=
 =0A=
 	iwn_eeprom_unlock(sc);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
-=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s end\n", __func__);=0A=
+	=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -1734,7 +1830,7 @@=0A=
 	uint16_t val;=0A=
 	int i;=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=
 	/* Read regulatory domain (4 ASCII characters). */=0A=
 	iwn_read_prom_data(sc, IWN4965_EEPROM_DOMAIN, sc->eeprom_domain, 4);=0A=
@@ -1775,7 +1871,7 @@=0A=
 	}=0A=
 #endif=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=
 #ifdef IWN_DEBUG=0A=
@@ -1818,12 +1914,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=
@@ -1831,16 +1926,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=
@@ -1850,6 +1941,14 @@=0A=
 	    "%s: calib version=3D%u pa type=3D%u voltage=3D%u\n", __func__,=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=
@@ -1867,9 +1966,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=
@@ -1905,7 +2003,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=
@@ -1950,7 +2048,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=
@@ -1967,8 +2065,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=
@@ -2019,7 +2117,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=
@@ -2104,7 +2202,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=
@@ -2157,7 +2255,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=
@@ -2230,12 +2328,12 @@=0A=
 		/*=0A=
 		 * Set the channel width and guard interval.=0A=
 		 */=0A=
-		if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {=0A=
-			plcp |=3D IWN_RFLAG_HT40;=0A=
-			if (ni->ni_htcap & IEEE80211_HTCAP_SHORTGI40)=0A=
+			if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {=0A=
+				plcp |=3D IWN_RFLAG_HT40;=0A=
+				if (ni->ni_htcap & IEEE80211_HTCAP_SHORTGI40)=0A=
+					plcp |=3D IWN_RFLAG_SGI;=0A=
+		} else if (ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20) {=0A=
 				plcp |=3D IWN_RFLAG_SGI;=0A=
-		} else if (ni->ni_htcap & IEEE80211_HTCAP_SHORTGI20) {=0A=
-			plcp |=3D IWN_RFLAG_SGI;=0A=
 		}=0A=
 =0A=
 		/*=0A=
@@ -2245,9 +2343,9 @@=0A=
 		 * XXX three stream rates?=0A=
 		 */=0A=
 		if (rate > 0x87)=0A=
-			plcp |=3D IWN_RFLAG_ANT(txant1 | txant2);=0A=
-		else=0A=
-			plcp |=3D IWN_RFLAG_ANT(txant1);=0A=
+				plcp |=3D IWN_RFLAG_ANT(txant1 | txant2);=0A=
+			else=0A=
+				plcp |=3D IWN_RFLAG_ANT(txant1);=0A=
 	} else {=0A=
 		/*=0A=
 		 * Set the initial PLCP - fine for both=0A=
@@ -2264,13 +2362,13 @@=0A=
 		 */=0A=
 		ridx =3D ieee80211_legacy_rate_lookup(ic->ic_rt,=0A=
 		    rate & IEEE80211_RATE_VAL);=0A=
-		if (ridx < IWN_RIDX_OFDM6 &&=0A=
-		    IEEE80211_IS_CHAN_2GHZ(ni->ni_chan))=0A=
-			plcp |=3D IWN_RFLAG_CCK;=0A=
+			if (ridx < IWN_RIDX_OFDM6 &&=0A=
+			    IEEE80211_IS_CHAN_2GHZ(ni->ni_chan))=0A=
+				plcp |=3D IWN_RFLAG_CCK;=0A=
 =0A=
 		/* Set antenna configuration */=0A=
-		plcp |=3D IWN_RFLAG_ANT(txant1);=0A=
-	}=0A=
+			plcp |=3D IWN_RFLAG_ANT(txant1);=0A=
+		}=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TXRATE, "%s: rate=3D0x%02x, plcp=3D0x%08x\n",=0A=
 	    __func__,=0A=
@@ -2305,8 +2403,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=
@@ -2313,6 +2410,8 @@=0A=
 	IEEE80211_UNLOCK(ic);=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=
@@ -2327,8 +2426,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=
@@ -2367,11 +2466,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=
@@ -2385,12 +2484,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=
@@ -2436,7 +2530,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=
@@ -2483,7 +2577,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=
@@ -2577,7 +2671,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=
@@ -2600,7 +2694,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=
@@ -2674,7 +2768,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=
@@ -2689,11 +2783,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=
@@ -2702,29 +2795,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=
@@ -2740,6 +2834,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=
@@ -2756,18 +2851,60 @@=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=
+		=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=
@@ -2805,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=
@@ -2881,21 +3018,38 @@=0A=
 	struct ifnet *ifp =3D sc->sc_ifp;=0A=
 	struct iwn_tx_ring *ring =3D &sc->txq[desc->qid & 0xf];=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=
+	uint8_t ridx;=0A=
 	bus_dmamap_sync(ring->data_dmat, data->map, BUS_DMASYNC_POSTWRITE);=0A=
 	bus_dmamap_unload(ring->data_dmat, data->map);=0A=
 	m =3D data->m, data->m =3D NULL;=0A=
 	ni =3D data->ni, data->ni =3D NULL;=0A=
+	uint8_t type;=0A=
 	vap =3D ni->ni_vap;=0A=
 =0A=
+	cmd =3D &ring->cmd[desc->idx];=0A=
+	tx =3D (struct iwn_cmd_data *)cmd->data;=0A=
+	wh =3D (struct ieee80211_frame *)(tx + 1);=0A=
+=0A=
+	struct ieee80211com *ic =3D ni->ni_ic;=0A=
+=0A=
+	type =3D wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK;=0A=
+=0A=
+	=0A=
+	=0A=
 	if (m->m_flags & M_TXCB) {=0A=
 		/*=0A=
 		 * Channels marked for "radar" require traffic to be received=0A=
@@ -2919,6 +3073,9 @@=0A=
 			    (status & IWN_TX_FAIL) !=3D 0);=0A=
 	}=0A=
 =0A=
+	=0A=
+	ridx =3D ic->ic_rt->rateCodeToIndex[ni->ni_txrate];=0A=
+	=0A=
 	/*=0A=
 	 * Update rate control statistics for the node.=0A=
 	 */=0A=
@@ -2944,7 +3101,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=
@@ -2955,12 +3112,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 & 0xf),(sc->sc_flags & IWN_FLAG_PAN_SUPPORT) =
);=0A=
+		=0A=
+	=0A=
+	if ((desc->qid & 0xf) !=3D cmd_queue_num)=0A=
 		return;	/* Not a command ack. */=0A=
-=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=
@@ -2993,7 +3162,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=
@@ -3082,7 +3251,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=
@@ -3095,7 +3264,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=
@@ -3150,7 +3321,12 @@=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=
@@ -3158,15 +3334,28 @@=0A=
 			DPRINTF(sc, IWN_DEBUG_STATE,=0A=
 			    "%s: beacons missed %d/%d\n", __func__,=0A=
 			    misses, le32toh(miss->total));=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=
@@ -3176,6 +3365,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=
@@ -3210,36 +3406,62 @@=0A=
 			 * get both the enable/disble intr.=0A=
 			 */=0A=
 			bus_dmamap_sync(sc->rxq.data_dmat, data->map,=0A=
-			    BUS_DMASYNC_POSTREAD);=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=
 			break;=0A=
 		}=0A=
 		case IWN_START_SCAN:=0A=
 		{=0A=
+			bus_dmamap_sync(sc->rxq.data_dmat, data->map,=0A=
+			    BUS_DMASYNC_POSTREAD);=0A=
+#ifdef	IWN_DEBUG=0A=
 			struct iwn_start_scan *scan =3D=0A=
 			    (struct iwn_start_scan *)(desc + 1);=0A=
-=0A=
-			bus_dmamap_sync(sc->rxq.data_dmat, data->map,=0A=
-			    BUS_DMASYNC_POSTREAD);=0A=
 			DPRINTF(sc, IWN_DEBUG_ANY,=0A=
 			    "%s: scanning channel %d status %x\n",=0A=
 			    __func__, scan->chan, le32toh(scan->status));=0A=
+#endif=0A=
 			break;=0A=
 		}=0A=
 		case IWN_STOP_SCAN:=0A=
 		{=0A=
+			bus_dmamap_sync(sc->rxq.data_dmat, data->map,=0A=
+			    BUS_DMASYNC_POSTREAD);=0A=
+#ifdef	IWN_DEBUG=0A=
 			struct iwn_stop_scan *scan =3D=0A=
 			    (struct iwn_stop_scan *)(desc + 1);=0A=
-=0A=
-			bus_dmamap_sync(sc->rxq.data_dmat, data->map,=0A=
-			    BUS_DMASYNC_POSTREAD);=0A=
 			DPRINTF(sc, IWN_DEBUG_STATE,=0A=
 			    "scan finished nchan=3D%d status=3D%d chan=3D%d\n",=0A=
 			    scan->nchan, scan->status, scan->chan);=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=
@@ -3251,7 +3473,11 @@=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=
 =0A=
 		sc->rxq.cur =3D (sc->rxq.cur + 1) % IWN_RX_RING_COUNT;=0A=
 	}=0A=
@@ -3309,6 +3535,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=
@@ -3358,6 +3585,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=
@@ -3394,9 +3622,7 @@=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=
+	=0A=
 	if (r1 =3D=3D 0 && r2 =3D=3D 0)=0A=
 		goto done;	/* Interrupt not for us. */=0A=
 =0A=
@@ -3405,6 +3631,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=
@@ -3413,9 +3642,13 @@=0A=
 		device_printf(sc->sc_dev, "%s: critical temperature reached!\n",=0A=
 		    __func__);=0A=
 	}=0A=
+	/* Todo : Make separate action for HW Error and SW_error. SW Error =
maybe require just a restart */=0A=
 	if (r1 & (IWN_INT_SW_ERR | IWN_INT_HW_ERR)) {=0A=
 		device_printf(sc->sc_dev, "%s: fatal firmware error\n",=0A=
 		    __func__);=0A=
+#ifdef	IWN_DEBUG=0A=
+		iwn_debug_register(sc);=0A=
+#endif=0A=
 		/* Dump firmware error log and stop. */=0A=
 		iwn_fatal_intr(sc);=0A=
 		ifp->if_flags &=3D ~IFF_UP;=0A=
@@ -3504,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=
@@ -3539,9 +3772,10 @@=0A=
 	bus_dma_segment_t *seg, segs[IWN_MAX_SCATTER];=0A=
 	uint8_t tid, ridx, txant, type;=0A=
 	int ac, i, totlen, error, pad, nsegs =3D 0, rate;=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_XMIT, "->%s begin\n", =
__func__);=0A=
+	=0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
 	wh =3D mtod(m, struct ieee80211_frame *);=0A=
@@ -3556,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=
@@ -3662,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_BCAST_ID;=0A=
+		else=0A=
+			tx->id =3D IWN_BROADCAST_ID;=0A=
+	} else=0A=
 		tx->id =3D wn->id;=0A=
 =0A=
 	if (type =3D=3D IEEE80211_FC0_TYPE_MGT) {=0A=
@@ -3695,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_BCAST_ID) || (tx->id =3D=3D =
IWN_BROADCAST_ID)) {=0A=
 		/* Group or management frame. */=0A=
 		tx->linkq =3D 0;=0A=
 		/* XXX Alternate between antenna A and B? */=0A=
@@ -3727,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=
@@ -3786,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=
@@ -3812,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=
@@ -3902,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_BCAST_ID;=0A=
+	else=0A=
+		tx->id =3D IWN_BROADCAST_ID;=0A=
 	tx->rts_ntries =3D params->ibp_try1;=0A=
 	tx->data_ntries =3D params->ibp_try0;=0A=
 	tx->lifetime =3D htole32(IWN_LIFETIME_INFINITE);=0A=
@@ -3912,12 +4153,10 @@=0A=
 	if (ridx < IWN_RIDX_OFDM6 &&=0A=
 	    IEEE80211_IS_CHAN_2GHZ(ni->ni_chan))=0A=
 		tx->rate |=3D htole32(IWN_RFLAG_CCK);=0A=
-=0A=
 	/* Group or management frame. */=0A=
 	tx->linkq =3D 0;=0A=
 	txant =3D IWN_LSB(sc->txchainmask);=0A=
 	tx->rate |=3D htole32(IWN_RFLAG_ANT(txant));=0A=
-=0A=
 	/* Set physical address of "scratch area". */=0A=
 	tx->loaddr =3D htole32(IWN_LOADDR(data->scratch_paddr));=0A=
 	tx->hiaddr =3D IWN_HIADDR(data->scratch_paddr);=0A=
@@ -3940,7 +4179,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=
@@ -4000,7 +4239,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=
@@ -4014,7 +4253,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=
@@ -4045,7 +4284,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=
@@ -4097,12 +4336,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=
@@ -4111,6 +4353,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=
@@ -4163,7 +4411,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=
@@ -4170,12 +4418,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=
@@ -4184,7 +4445,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=
@@ -4210,8 +4471,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=
@@ -4228,7 +4489,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=
@@ -4267,6 +4528,10 @@=0A=
 static int=0A=
 iwn_set_link_quality(struct iwn_softc *sc, struct ieee80211_node *ni)=0A=
 {=0A=
+	=0A=
+	DPRINTF(sc,IWN_DEBUG_RESET,"Disabled %s reached\n",__func__);=0A=
+	return 0;=0A=
+	=0A=
 #define	RV(v)	((v) & IEEE80211_RATE_VAL)=0A=
 	struct iwn_node *wn =3D (void *)ni;=0A=
 	struct ieee80211_rateset *rs =3D &ni->ni_rates;=0A=
@@ -4334,11 +4599,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 IWN_BROADCAST_ID;=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=
@@ -4347,7 +4614,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 IWN_BROADCAST_ID;=0A=
 	linkq.antmsk_1stream =3D txant;=0A=
 	linkq.antmsk_2stream =3D IWN_ANT_AB;=0A=
 	linkq.ampdu_max =3D 64;=0A=
@@ -4365,7 +4632,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=
@@ -4409,23 +4676,31 @@=0A=
 	/* Ignore */=0A=
 }=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=
+=0A=
 /*=0A=
  * Set the critical temperature at which the firmware will stop the =
radio=0A=
  * and notify us.=0A=
@@ -4434,21 +4709,30 @@=0A=
 iwn_set_critical_temp(struct iwn_softc *sc)=0A=
 {=0A=
 	struct iwn_critical_temp crit;=0A=
-	int32_t temp;=0A=
+	int32_t ct_enter,ct_exit;=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
+	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=
+	} else if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_4965) {=0A=
+		ct_enter =3D IWN_CTOK(IWN_CT_KILL_THRESHOLD);=0A=
+		ct_exit =3D 0;=0A=
+	} else {=0A=
+		ct_enter =3D IWN_CT_KILL_THRESHOLD;=0A=
+		ct_exit =3D IWN_CT_KILL_EXIT_THRESHOLD;=0A=
+	}=0A=
+=0A=
 	memset(&crit, 0, sizeof crit);=0A=
-	crit.tempR =3D htole32(temp);=0A=
-	DPRINTF(sc, IWN_DEBUG_RESET, "setting critical temp to %d\n", temp);=0A=
+	crit.tempR =3D htole32(ct_enter);=0A=
+	crit.tempM =3D htole32(ct_exit);		=0A=
+	DPRINTF(sc, IWN_DEBUG_RESET, "setting critical temp to %d and exit to =
%d \n", ct_enter,ct_exit);=0A=
 	return iwn_cmd(sc, IWN_CMD_SET_CRITICAL_TEMP, &crit, sizeof crit, 0);=0A=
 }=0A=
 =0A=
@@ -4457,9 +4741,9 @@=0A=
 {=0A=
 	struct iwn_cmd_timing cmd;=0A=
 	uint64_t val, mod;=0A=
+	=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->Doing %s\n", =
__func__);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
-=0A=
 	memset(&cmd, 0, sizeof cmd);=0A=
 	memcpy(&cmd.tstamp, ni->ni_tstamp.data, sizeof (uint64_t));=0A=
 	cmd.bintval =3D htole16(ni->ni_intval);=0A=
@@ -4470,10 +4754,12 @@=0A=
 	mod =3D le64toh(cmd.tstamp) % val;=0A=
 	cmd.binitval =3D htole32((uint32_t)(val - mod));=0A=
 =0A=
+//	cmd.dtim_period=3D1; //XXX It's defined in linux kernel=0A=
+	=0A=
 	DPRINTF(sc, IWN_DEBUG_RESET, "timing bintval=3D%u tstamp=3D%ju, =
init=3D%u\n",=0A=
-	    ni->ni_intval, le64toh(cmd.tstamp), (uint32_t)(val - mod));=0A=
+	    le16toh(cmd.bintval), le64toh(cmd.tstamp), (uint32_t)(val - mod));=0A=
 =0A=
-	return iwn_cmd(sc, IWN_CMD_TIMING, &cmd, sizeof cmd, 1);=0A=
+	return iwn_cmd(sc, IWN_CMD_TIMING | IWN_DEBUG_RESET, &cmd, sizeof cmd, =
0);=0A=
 }=0A=
 =0A=
 static void=0A=
@@ -4482,7 +4768,7 @@=0A=
 	struct ifnet *ifp =3D sc->sc_ifp;=0A=
 	struct ieee80211com *ic =3D ifp->if_l2com;=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=
 	/* Adjust TX power if need be (delta >=3D 3 degC). */=0A=
 	DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s: temperature %d->%d\n",=0A=
@@ -4519,8 +4805,9 @@=0A=
 	int i, c, grp, maxpwr;=0A=
 	uint8_t chan;=0A=
 =0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_BSS_CTX];=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=
@@ -4649,6 +4936,11 @@=0A=
 #undef fdivround=0A=
 }=0A=
 =0A=
+/*=0A=
+ * Set TX power for current channel (each rate has its own power =
settings).=0A=
+ * This function takes into account the regulatory information from =
EEPROM,=0A=
+ * the current temperature and the current voltage.=0A=
+ */=0A=
 static int=0A=
 iwn5000_set_txpower(struct iwn_softc *sc, struct ieee80211_channel *ch,=0A=
     int async)=0A=
@@ -4655,7 +4947,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=
@@ -4679,7 +4971,7 @@=0A=
 	uint8_t mask, agc;=0A=
 	int rssi;=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=
 	mask =3D (le16toh(phy->antenna) >> 4) & IWN_ANT_ABC;=0A=
 	agc  =3D (le16toh(phy->agc) >> 7) & 0x7f;=0A=
@@ -4706,7 +4998,7 @@=0A=
 	uint8_t agc;=0A=
 	int rssi;=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=
 =0A=
@@ -4775,7 +5067,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=
@@ -4786,6 +5078,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=
@@ -4797,10 +5091,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=
@@ -4811,9 +5104,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=
@@ -4824,10 +5118,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=
@@ -4846,7 +5137,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=
@@ -4879,8 +5170,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=
@@ -4887,7 +5178,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=
@@ -4911,7 +5202,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=
@@ -4929,7 +5220,7 @@=0A=
 	struct iwn_phy_calib_gain cmd;=0A=
 	int i, delta, noise;=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=
 	/* Get minimal noise among connected antennas. */=0A=
 	noise =3D INT_MAX;	/* NB: There's at least one antenna. */=0A=
@@ -4964,7 +5255,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=
@@ -5024,11 +5315,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=
@@ -5149,7 +5440,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=
@@ -5170,15 +5461,15 @@=0A=
 	cmd.corr_ofdm_mrc_x1   =3D htole16(calib->ofdm_mrc_x1);=0A=
 	cmd.corr_ofdm_x4       =3D htole16(calib->ofdm_x4);=0A=
 	cmd.corr_ofdm_mrc_x4   =3D htole16(calib->ofdm_mrc_x4);=0A=
-	cmd.energy_ofdm        =3D htole16(sc->limits->energy_ofdm);=0A=
-	cmd.energy_ofdm_th     =3D htole16(62);=0A=
+	cmd.energy_ofdm        =3D htole16(calib->energy_ofdm);=0A=
+	cmd.energy_ofdm_th     =3D htole16(62); //Value doesn't change in =
linux Kernel=0A=
 	/* CCK modulation. */=0A=
 	cmd.corr_cck_x4        =3D htole16(calib->cck_x4);=0A=
 	cmd.corr_cck_mrc_x4    =3D htole16(calib->cck_mrc_x4);=0A=
 	cmd.energy_cck         =3D htole16(calib->energy_cck);=0A=
 	/* Barker modulation: use default values. */=0A=
-	cmd.corr_barker        =3D htole16(190);=0A=
-	cmd.corr_barker_mrc    =3D htole16(390);=0A=
+	cmd.corr_barker        =3D htole16(190); //Value doesn't change in =
linux Kernel=0A=
+	cmd.corr_barker_mrc    =3D htole16(calib->corr_barker_mrc);=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_CALIBRATE,=0A=
 	    "%s: set sensitivity %d/%d/%d/%d/%d/%d/%d\n", __func__,=0A=
@@ -5205,6 +5496,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=
@@ -5213,8 +5506,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=
@@ -5221,7 +5531,7 @@=0A=
 	    dtim,=0A=
 	    level,=0A=
 	    async);=0A=
-=0A=
+	=0A=
 	/* Select which PS parameters to use. */=0A=
 	if (dtim <=3D 2)=0A=
 		pmgt =3D &iwn_pmgt[0][level];=0A=
@@ -5232,7 +5542,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=
@@ -5259,9 +5569,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=
@@ -5286,26 +5605,63 @@=0A=
 		0xcc00ff28, 0x0000aaaa, 0xcc00aaaa, 0x0000aaaa,=0A=
 		0xc0004000, 0x00004000, 0xf0005000, 0xf0005000,=0A=
 	};=0A=
+=0A=
 	struct iwn6000_btcoex_config btconfig;=0A=
+	struct iwn2000_btcoex_config btconfig2k;=0A=
 	struct iwn_btcoex_priotable btprio;=0A=
 	struct iwn_btcoex_prot btprot;=0A=
 	int error, i;=0A=
-=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=
@@ -5336,19 +5692,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=
@@ -5357,34 +5700,47 @@=0A=
 	uint32_t txmask;=0A=
 	uint16_t rxchain;=0A=
 	int error;=0A=
+	=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE | IWN_DEBUG_RESET, "->%s begin\n", =
__func__);=0A=
 =0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
-	if (sc->hw_type =3D=3D IWN_HW_REV_TYPE_6005) {=0A=
-		/* Set radio temperature sensor offset. */=0A=
+	if ((sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET) =
 && (sc->base_params->calib_need & =
IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2)) {=0A=
+		device_printf(sc->sc_dev,"%s: temp_offset and temp_offsetv2 are =
exclusive each together. Review NIC config file. Conf :  0x%08x Flags :  =
0x%08x  \n", =
__func__,sc->base_params->calib_need,(IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET =
| IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2));=0A=
+		return EINVAL;=0A=
+	}=0A=
+	/* Compute temperature calib if needed. Will be send by send calib */=0A=
+	if (sc->base_params->calib_need & IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET) {=0A=
 		error =3D iwn5000_temp_offset_calib(sc);=0A=
 		if (error !=3D 0) {=0A=
 			device_printf(sc->sc_dev,=0A=
-			    "%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=
 	if (sc->hw_type !=3D IWN_HW_REV_TYPE_4965) {=0A=
 		txmask =3D htole32(sc->txchainmask);=0A=
-		DPRINTF(sc, IWN_DEBUG_RESET,=0A=
+		DPRINTF(sc, IWN_DEBUG_RESET ,=0A=
 		    "%s: configuring valid TX chains 0x%x\n", __func__, txmask);=0A=
 		error =3D iwn_cmd(sc, IWN5000_CMD_TX_ANT_CONFIG, &txmask,=0A=
 		    sizeof txmask, 0);=0A=
@@ -5396,34 +5752,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=
+	=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=
@@ -5430,24 +5776,26 @@=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=
 		return error;=0A=
 	}=0A=
-=0A=
+	=0A=
 	if ((error =3D iwn_add_broadcast_node(sc, 0)) !=3D 0) {=0A=
 		device_printf(sc->sc_dev, "%s: could not add broadcast node\n",=0A=
 		    __func__);=0A=
@@ -5467,14 +5815,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=
@@ -5509,9 +5867,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=
@@ -5543,7 +5912,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_BCAST_ID;=0A=
+	else=0A=
+		tx->id =3D IWN_BROADCAST_ID;=0A=
+=0A=
 	tx->lifetime =3D htole32(IWN_LIFETIME_INFINITE);=0A=
 =0A=
 	if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan)) {=0A=
@@ -5553,7 +5926,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=
@@ -5580,7 +5953,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=
@@ -5602,36 +5975,65 @@=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=
+=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=
+	=0A=
+	chan->active  =3D htole16(iwn_get_active_dwell(sc, c));=0A=
+	chan->passive =3D htole16(iwn_get_passive_dwell(sc, c));=0A=
+=0A=
+	=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=
@@ -5645,6 +6047,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=
@@ -5664,31 +6069,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=
@@ -5705,7 +6111,7 @@=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(sc, 1)) !=3D 0) {=0A=
+	if ((error =3D iwn_add_broadcast_node(sc, 0)) !=3D 0) {=0A=
 		device_printf(sc->sc_dev,=0A=
 		    "%s: could not add broadcast node, error %d\n", __func__,=0A=
 		    error);=0A=
@@ -5730,9 +6136,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=
@@ -5742,26 +6159,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=
@@ -5778,11 +6195,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=
@@ -5820,12 +6237,13 @@=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=
 		return error;=0A=
 	}=0A=
+	/*XXX Not done in iwl =0A=
 	DPRINTF(sc, IWN_DEBUG_STATE, "%s: setting link quality for node %d\n",=0A=
 	    __func__, node.id);=0A=
 	if ((error =3D iwn_set_link_quality(sc, ni)) !=3D 0) {=0A=
@@ -5841,18 +6259,26 @@=0A=
 		    error);=0A=
 		return error;=0A=
 	}=0A=
-	/* Start periodic calibration timer. */=0A=
+	// Start periodic calibration timer. =0A=
 	sc->calib.state =3D IWN_CALIB_STATE_ASSOC;=0A=
 	sc->calib_cnt =3D 0;=0A=
 	callout_reset(&sc->calib_to, msecs_to_ticks(500), iwn_calib_timeout,=0A=
 	    sc);=0A=
 =0A=
+	*/=0A=
+	=0A=
 	/* Link LED always on while associated. */=0A=
-	iwn_set_led(sc, IWN_LED_LINK, 0, 1);=0A=
+	iwn_set_led(sc, IWN_LED_LINK, 0, 1,IWN_LED_STATIC_ON);=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
 =0A=
-	return 0;=0A=
+#ifdef IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP=0A=
+		return iwn_set_pslevel(sc, IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE,=0A=
+			sc->desired_pwrsave_level, 0);=0A=
+#else=0A=
+		return 0;=0A=
+#endif=0A=
+=0A=
 }=0A=
 =0A=
 /*=0A=
@@ -5986,7 +6412,7 @@=0A=
 iwn_ampdu_tx_start(struct ieee80211com *ic, struct ieee80211_node *ni,=0A=
     uint8_t tid)=0A=
 {=0A=
-	struct ieee80211_tx_ampdu *tap =3D &ni->ni_tx_ampdu[tid];=0A=
+	struct ieee80211_tx_ampdu *tap =3D =
&ni->ni_tx_ampdu[TID_TO_WME_AC(tid)];=0A=
 	struct iwn_softc *sc =3D ni->ni_ic->ic_ifp->if_softc;=0A=
 	struct iwn_ops *ops =3D &sc->ops;=0A=
 	struct iwn_node *wn =3D (void *)ni;=0A=
@@ -6205,9 +6631,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=
@@ -6279,11 +6711,43 @@=0A=
 		cmd.offset =3D htole16(sc->eeprom_temp);=0A=
 	else=0A=
 		cmd.offset =3D htole16(IWN_DEFAULT_TEMP_OFFSET);=0A=
+		=0A=
+=0A=
 	DPRINTF(sc, IWN_DEBUG_CALIBRATE, "setting radio sensor offset to %d\n",=0A=
 	    le16toh(cmd.offset));=0A=
 	return iwn_cmd(sc, IWN_CMD_PHY_CALIB, &cmd, sizeof cmd, 0);=0A=
+		=0A=
+			=0A=
+	=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.burntVoltageRef =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.burntVoltageRef));=0A=
+	=0A=
+	return iwn_cmd(sc, IWN_CMD_PHY_CALIB, &cmd, sizeof cmd, 0);=0A=
+}=0A=
+=0A=
+=0A=
 /*=0A=
  * This function is called after the runtime firmware notifies us of its=0A=
  * readiness (called in a process context).=0A=
@@ -6353,10 +6817,8 @@=0A=
 	/* Switch to using ICT interrupt mode. */=0A=
 	iwn5000_ict_reset(sc);=0A=
 =0A=
-	if ((error =3D iwn_nic_lock(sc)) !=3D 0){=0A=
-		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end in error\n", __func__);=0A=
+	if ((error =3D iwn_nic_lock(sc)) !=3D 0)=0A=
 		return error;=0A=
-	}=0A=
 =0A=
 	/* Clear TX scheduler state in SRAM. */=0A=
 	sc->sched_base =3D iwn_prph_read(sc, IWN_SCHED_SRAM_ADDR);=0A=
@@ -6369,7 +6831,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=
@@ -6389,32 +6855,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=
@@ -6423,6 +6886,7 @@=0A=
 			    __func__, error);=0A=
 			return error;=0A=
 		}=0A=
+=0A=
 		/*=0A=
 		 * We have the calibration results now, reboot with the=0A=
 		 * runtime firmware (call ourselves recursively!)=0A=
@@ -6432,10 +6896,9 @@=0A=
 	} else {=0A=
 		/* Send calibration results to runtime firmware. */=0A=
 		error =3D iwn5000_send_calibration(sc);=0A=
+		=0A=
 	}=0A=
-=0A=
-	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s: end\n",__func__);=0A=
-=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
 	return error;=0A=
 }=0A=
 =0A=
@@ -6764,6 +7227,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=
@@ -6885,9 +7367,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=
@@ -6931,13 +7412,20 @@=0A=
 static void=0A=
 iwn_apm_stop(struct iwn_softc *sc)=0A=
 {=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
 	iwn_apm_stop_master(sc);=0A=
 =0A=
+=0A=
 	/* Reset the entire device. */=0A=
 	IWN_SETBITS(sc, IWN_RESET, IWN_RESET_SW);=0A=
 	DELAY(10);=0A=
 	/* Clear "initialization complete" bit. */=0A=
 	IWN_CLRBITS(sc, IWN_GP_CNTRL, IWN_GP_CNTRL_INIT_DONE);=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+=0A=
+	=0A=
 }=0A=
 =0A=
 static int=0A=
@@ -6999,13 +7487,15 @@=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=
+/*	if (sc->base_params->iq_invert) =0A=
+		IWN_SETBITS(sc, IWN_GP_DRIVER, IWN_GP_DRIVER_REG_BIT_RADIO_IQ_INVERT);=0A=
+*/	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
 	return 0;=0A=
 }=0A=
 =0A=
@@ -7018,13 +7508,15 @@=0A=
 	int ntries;=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->Doing %s\n", __func__);=0A=
-=0A=
+		=0A=
 	/* Check if hardware is ready. */=0A=
 	IWN_SETBITS(sc, IWN_HW_IF_CONFIG, IWN_HW_IF_CONFIG_NIC_READY);=0A=
 	for (ntries =3D 0; ntries < 5; ntries++) {=0A=
 		if (IWN_READ(sc, IWN_HW_IF_CONFIG) &=0A=
-		    IWN_HW_IF_CONFIG_NIC_READY)=0A=
-			return 0;=0A=
+		    IWN_HW_IF_CONFIG_NIC_READY) {=0A=
+				DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+				return 0;=0A=
+			}=0A=
 		DELAY(10);=0A=
 	}=0A=
 =0A=
@@ -7036,18 +7528,24 @@=0A=
 			break;=0A=
 		DELAY(10);=0A=
 	}=0A=
-	if (ntries =3D=3D 15000)=0A=
+	if (ntries =3D=3D 15000) {=0A=
+		DPRINTF(sc, IWN_DEBUG_RESET, "->%s end timeout\n", __func__);=0A=
 		return ETIMEDOUT;=0A=
+	}=0A=
 =0A=
 	/* Hardware should be ready now. */=0A=
 	IWN_SETBITS(sc, IWN_HW_IF_CONFIG, IWN_HW_IF_CONFIG_NIC_READY);=0A=
 	for (ntries =3D 0; ntries < 5; ntries++) {=0A=
 		if (IWN_READ(sc, IWN_HW_IF_CONFIG) &=0A=
-		    IWN_HW_IF_CONFIG_NIC_READY)=0A=
-			return 0;=0A=
+		    IWN_HW_IF_CONFIG_NIC_READY) {=0A=
+				DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+				return 0;=0A=
+			}=0A=
 		DELAY(10);=0A=
 	}=0A=
+	DPRINTF(sc, IWN_DEBUG_RESET, "->%s end timeout\n", __func__);=0A=
 	return ETIMEDOUT;=0A=
+	=0A=
 }=0A=
 =0A=
 static int=0A=
@@ -7060,7 +7558,7 @@=0A=
 =0A=
 	/* Clear pending interrupts. */=0A=
 	IWN_WRITE(sc, IWN_INT, 0xffffffff);=0A=
-=0A=
+	=0A=
 	if ((error =3D iwn_apm_init(sc)) !=3D 0) {=0A=
 		device_printf(sc->sc_dev,=0A=
 		    "%s: could not power ON adapter, error %d\n", __func__,=0A=
@@ -7140,7 +7638,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=
@@ -7211,6 +7709,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=
@@ -7259,7 +7763,6 @@=0A=
 	int error;=0A=
 =0A=
 	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
-=0A=
 	IWN_LOCK_ASSERT(sc);=0A=
 =0A=
 	if ((error =3D iwn_hw_prepare(sc)) !=3D 0) {=0A=
@@ -7329,6 +7832,7 @@=0A=
 	struct ifnet *ifp =3D sc->sc_ifp;=0A=
 	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
 =0A=
+	=0A=
 	IWN_LOCK(sc);=0A=
 	iwn_init_locked(sc);=0A=
 	IWN_UNLOCK(sc);=0A=
@@ -7345,6 +7849,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=
@@ -7369,10 +7874,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=
@@ -7384,12 +7903,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=
@@ -7437,10 +7964,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=
@@ -7467,3 +7998,1140 @@=0A=
 	iwn_init(sc);=0A=
 	ieee80211_notify_radio(ic, 1);=0A=
 }=0A=
+#ifdef	IWN_DEBUG=0A=
+#define IWN_DESC(x) case x:	return #x=0A=
+#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))=0A=
+=0A=
+/*=0A=
+ * Transate CSR code to string=0A=
+ */=0A=
+static char *iwn_get_csr_string(int csr)=0A=
+{=0A=
+	switch (csr) {=0A=
+		IWN_DESC(IWN_HW_IF_CONFIG);	=0A=
+		IWN_DESC(IWN_INT_COALESCING);	=0A=
+		IWN_DESC(IWN_INT);=0A=
+		IWN_DESC(IWN_INT_MASK);=0A=
+		IWN_DESC(IWN_FH_INT);=0A=
+		IWN_DESC(IWN_GPIO_IN);=0A=
+		IWN_DESC(IWN_RESET);=0A=
+		IWN_DESC(IWN_GP_CNTRL);=0A=
+		IWN_DESC(IWN_HW_REV);	=0A=
+		IWN_DESC(IWN_EEPROM);	=0A=
+		IWN_DESC(IWN_EEPROM_GP);=0A=
+		IWN_DESC(IWN_OTP_GP);	=0A=
+		IWN_DESC(IWN_GIO);=0A=
+		IWN_DESC(IWN_GP_UCODE);=0A=
+		IWN_DESC(IWN_GP_DRIVER);		=0A=
+		IWN_DESC(IWN_UCODE_GP1);=0A=
+		IWN_DESC(IWN_UCODE_GP2);   =0A=
+		IWN_DESC(IWN_LED);=0A=
+		IWN_DESC(IWN_DRAM_INT_TBL);=0A=
+		IWN_DESC(IWN_GIO_CHICKEN);	=0A=
+		IWN_DESC(IWN_ANA_PLL);	=0A=
+		IWN_DESC(IWN_HW_REV_WA);=0A=
+		IWN_DESC(IWN_DBG_HPET_MEM);=0A=
+	default:=0A=
+		return "UNKNOWN CSR";=0A=
+	}=0A=
+}=0A=
+=0A=
+/*=0A=
+ * This function print firmawre register=0A=
+ */=0A=
+static void=0A=
+iwn_debug_register(struct iwn_softc *sc)=0A=
+{=0A=
+	int i;=0A=
+	static const uint32_t csr_tbl[] =3D {=0A=
+		IWN_HW_IF_CONFIG,	=0A=
+		IWN_INT_COALESCING,	=0A=
+		IWN_INT,=0A=
+		IWN_INT_MASK,=0A=
+		IWN_FH_INT,=0A=
+		IWN_GPIO_IN,=0A=
+		IWN_RESET,		=0A=
+		IWN_GP_CNTRL,		=0A=
+		IWN_HW_REV,		=0A=
+		IWN_EEPROM,=0A=
+		IWN_EEPROM_GP,		=0A=
+		IWN_OTP_GP,		=0A=
+		IWN_GIO,=0A=
+		IWN_GP_UCODE, =0A=
+		IWN_GP_DRIVER,		=0A=
+		IWN_UCODE_GP1,	=0A=
+		IWN_UCODE_GP2,   =0A=
+		IWN_LED,			=0A=
+		IWN_DRAM_INT_TBL,=0A=
+		IWN_GIO_CHICKEN,		=0A=
+		IWN_ANA_PLL,	=0A=
+		IWN_HW_REV_WA,	=0A=
+		IWN_DBG_HPET_MEM,=0A=
+	};=0A=
+	DPRINTF(sc, IWN_DEBUG_REGISTER,=0A=
+    "CSR values: (2nd byte of IWN_INT_COALESCING is =
IWN_INT_PERIODIC)%s",=0A=
+    "\n");=0A=
+	for (i =3D 0; i <  COUNTOF(csr_tbl); i++){=0A=
+		DPRINTF(sc, IWN_DEBUG_REGISTER,"  %10s: 0x%08x ",=0A=
+			iwn_get_csr_string(csr_tbl[i]), IWN_READ(sc, csr_tbl[i]));=0A=
+		if ((i+1) % 3 =3D=3D 0)=0A=
+			DPRINTF(sc, IWN_DEBUG_REGISTER,"%s","\n");=0A=
+	}=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=
+static int=0A=
+iwn_config_specific(struct iwn_softc *sc,uint16_t pid)=0A=
+{=0A=
+	switch(pid) {=0A=
+/* 1000 Series */=0A=
+	case IWN_DID_1000_1:=0A=
+	case IWN_DID_1000_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case	IWN_SDID_1000_1:=0A=
+			case	IWN_SDID_1000_2:=0A=
+			case	IWN_SDID_1000_3:=0A=
+			case	IWN_SDID_1000_4:=0A=
+			case	IWN_SDID_1000_5:=0A=
+			case	IWN_SDID_1000_6:=0A=
+			case	IWN_SDID_1000_7:=0A=
+			case	IWN_SDID_1000_8:=0A=
+			case	IWN_SDID_1000_9:=0A=
+			case	IWN_SDID_1000_10:=0A=
+			case	IWN_SDID_1000_11:=0A=
+			case	IWN_SDID_1000_12:=0A=
+				sc->limits =3D &iwn1000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_1000_base_params; =0A=
+				sc->fwname =3D "iwn1000fw";=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6x00 Series */=0A=
+	case IWN_DID_6x00_2:=0A=
+	case IWN_DID_6x00_4:=0A=
+	case IWN_DID_6x00_1:=0A=
+	case IWN_DID_6x00_3:=0A=
+		sc->fwname =3D "iwn6000fw";=0A=
+		sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+		switch(sc->subdevice_id) {=0A=
+=0A=
+		case IWN_SDID_6x00_1:=0A=
+		case IWN_SDID_6x00_2:=0A=
+		case IWN_SDID_6x00_8:=0A=
+			//iwl6000_3agn_cfg=0A=
+			sc->base_params =3D &iwn_6000_base_params;=0A=
+			break;=0A=
+		case IWN_SDID_6x00_3:=0A=
+		case IWN_SDID_6x00_6:=0A=
+		case IWN_SDID_6x00_9:=0A=
+			////iwl6000i_2agn=0A=
+		case IWN_SDID_6x00_4:=0A=
+		case IWN_SDID_6x00_7:=0A=
+		case IWN_SDID_6x00_10:	=0A=
+			//iwl6000i_2abg_cfg=0A=
+		case IWN_SDID_6x00_5:=0A=
+			//iwl6000i_2bg_cfg=0A=
+			sc->base_params =3D &iwn_6000i_base_params;=0A=
+			sc->sc_flags |=3D IWN_FLAG_INTERNAL_PA;=0A=
+			sc->txchainmask =3D IWN_ANT_BC;=0A=
+			sc->rxchainmask =3D IWN_ANT_BC;=0A=
+			break;=0A=
+		default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6x05 Series */=0A=
+	case IWN_DID_6x05_1:  =0A=
+	case IWN_DID_6x05_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_6x05_1:=0A=
+			case IWN_SDID_6x05_4:=0A=
+			case IWN_SDID_6x05_6:=0A=
+				//iwl6005_2agn_cfg=0A=
+			case IWN_SDID_6x05_2:=0A=
+			case IWN_SDID_6x05_5:=0A=
+			case IWN_SDID_6x05_7:=0A=
+				//iwl6005_2abg_cfg=0A=
+			case IWN_SDID_6x05_3:=0A=
+				//iwl6005_2bg_cfg=0A=
+			case IWN_SDID_6x05_8:=0A=
+			case IWN_SDID_6x05_9:=0A=
+				//iwl6005_2agn_sff_cfg=0A=
+			case IWN_SDID_6x05_10:=0A=
+				//iwl6005_2agn_d_cfg=0A=
+			case IWN_SDID_6x05_11:=0A=
+				//iwl6005_2agn_mow1_cfg=0A=
+			case IWN_SDID_6x05_12:=0A=
+				//iwl6005_2agn_mow2_cfg=0A=
+				sc->fwname =3D "iwn6000g2afw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6000g2_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6x35 Series */=0A=
+	case IWN_DID_6035_1:=0A=
+	case IWN_DID_6035_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_6035_1:=0A=
+			case IWN_SDID_6035_2:=0A=
+			case IWN_SDID_6035_3:=0A=
+			case IWN_SDID_6035_4:=0A=
+				sc->fwname =3D "iwn6000g2bfw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6000g2b_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6x50 WiFi/WiMax Series */=0A=
+	case IWN_DID_6050_1:=0A=
+	case IWN_DID_6050_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_6050_1:=0A=
+			case IWN_SDID_6050_3:=0A=
+			case IWN_SDID_6050_5:=0A=
+				//iwl6050_2agn_cfg=0A=
+			case IWN_SDID_6050_2:=0A=
+			case IWN_SDID_6050_4:=0A=
+			case IWN_SDID_6050_6:=0A=
+				//iwl6050_2abg_cfg=0A=
+				sc->fwname =3D "iwn6050fw";=0A=
+				sc->txchainmask =3D IWN_ANT_AB;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6050_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6150 WiFi/WiMax Series */=0A=
+ 	case IWN_DID_6150_1:=0A=
+	case IWN_DID_6150_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_6150_1:=0A=
+			case IWN_SDID_6150_3:=0A=
+			case IWN_SDID_6150_5:=0A=
+				// iwl6150_bgn_cfg=0A=
+			case IWN_SDID_6150_2:=0A=
+			case IWN_SDID_6150_4:=0A=
+			case IWN_SDID_6150_6:=0A=
+				//iwl6150_bg_cfg=0A=
+				sc->fwname =3D "iwn6050fw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6150_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 6030 Series and 1030 Series */=0A=
+ 	case IWN_DID_x030_1:=0A=
+ 	case IWN_DID_x030_2:=0A=
+ 	case IWN_DID_x030_3:=0A=
+ 	case IWN_DID_x030_4:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_x030_1:=0A=
+			case IWN_SDID_x030_3:=0A=
+			case IWN_SDID_x030_5:=0A=
+			// iwl1030_bgn_cfg=0A=
+			=0A=
+			case IWN_SDID_x030_2:=0A=
+			case IWN_SDID_x030_4:=0A=
+			case IWN_SDID_x030_6:=0A=
+			//iwl1030_bg_cfg=0A=
+			=0A=
+			case IWN_SDID_x030_7:=0A=
+			case IWN_SDID_x030_10:=0A=
+			case IWN_SDID_x030_14:=0A=
+			//iwl6030_2agn_cfg=0A=
+			=0A=
+			case IWN_SDID_x030_8:=0A=
+			case IWN_SDID_x030_11:=0A=
+			case IWN_SDID_x030_15:=0A=
+			// iwl6030_2bgn_cfg=0A=
+			=0A=
+			case IWN_SDID_x030_9:=0A=
+			case IWN_SDID_x030_12:=0A=
+			case IWN_SDID_x030_16:=0A=
+			// iwl6030_2abg_cfg=0A=
+			=0A=
+			case IWN_SDID_x030_13:=0A=
+			//iwl6030_2bg_cfg=0A=
+				sc->fwname =3D "iwn6000g2bfw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6000g2b_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 130 Series WiFi */=0A=
+/* XXX: This series will need adjustement for rate see =
rx_with_siso_diversity in linux kernel */=0A=
+ 	case IWN_DID_130_1:=0A=
+ 	case IWN_DID_130_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_130_1: =0A=
+			case IWN_SDID_130_3:=0A=
+			case IWN_SDID_130_5:=0A=
+			//iwl130_bgn_cfg=0A=
+			case IWN_SDID_130_2:=0A=
+			case IWN_SDID_130_4:=0A=
+			case IWN_SDID_130_6:=0A=
+			//iwl130_bg_cfg=0A=
+				sc->fwname =3D "iwn6000g2bfw";=0A=
+				sc->limits =3D &iwn6000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_6000g2b_base_params;=0A=
+				break;=0A=
+			default:=0A=
+					device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : =
0x%04x rev %d not supported (subdevice) =
\n",pid,sc->subdevice_id,sc->hw_type);=0A=
+					return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 100 Series WiFi */=0A=
+ 	case IWN_DID_100_1:=0A=
+ 	case IWN_DID_100_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_100_1:=0A=
+			case IWN_SDID_100_2:=0A=
+			case IWN_SDID_100_3:=0A=
+			case IWN_SDID_100_4:=0A=
+			case IWN_SDID_100_5:=0A=
+			case IWN_SDID_100_6:=0A=
+				sc->limits =3D &iwn1000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_1000_base_params; =0A=
+				sc->fwname =3D "iwn100fw";=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+=0A=
+/* 2x30 Series */=0A=
+	case IWN_DID_2x30_1:=0A=
+	case IWN_DID_2x30_2:=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_2x30_1:=0A=
+			case IWN_SDID_2x30_3:=0A=
+			case IWN_SDID_2x30_5:=0A=
+			//iwl100_bgn_cfg=0A=
+			case IWN_SDID_2x30_2:=0A=
+			case IWN_SDID_2x30_4:=0A=
+			case IWN_SDID_2x30_6:=0A=
+			//iwl100_bg_cfg=0A=
+				sc->limits =3D &iwn2030_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn2030_base_params; =0A=
+				sc->fwname =3D "iwn2030fw";=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 5x00 Series */=0A=
+	case IWN_DID_5x00_1:=0A=
+	case IWN_DID_5x00_2:=0A=
+	case IWN_DID_5x00_3:=0A=
+	case IWN_DID_5x00_4:=0A=
+		sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+		sc->base_params =3D &iwn_default_base_params; =0A=
+		sc->fwname =3D "iwn5000fw";=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_5x00_1:=0A=
+			case IWN_SDID_5x00_2:=0A=
+			case IWN_SDID_5x00_3:=0A=
+			case IWN_SDID_5x00_4:=0A=
+			case IWN_SDID_5x00_9:=0A=
+			case IWN_SDID_5x00_10:=0A=
+			case IWN_SDID_5x00_11:=0A=
+			case IWN_SDID_5x00_12:=0A=
+			case IWN_SDID_5x00_17:=0A=
+			case IWN_SDID_5x00_18:=0A=
+			case IWN_SDID_5x00_19:=0A=
+			case IWN_SDID_5x00_20:=0A=
+			//iwl5100_agn_cfg=0A=
+				sc->txchainmask =3D IWN_ANT_B;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				break;			=0A=
+			case IWN_SDID_5x00_5:=0A=
+			case IWN_SDID_5x00_6:=0A=
+			case IWN_SDID_5x00_13:=0A=
+			case IWN_SDID_5x00_14:=0A=
+			case IWN_SDID_5x00_21:=0A=
+			case IWN_SDID_5x00_22:=0A=
+			//iwl5100_bgn_cfg=0A=
+				sc->txchainmask =3D IWN_ANT_B;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				break;=0A=
+			case IWN_SDID_5x00_7:=0A=
+			case IWN_SDID_5x00_8:=0A=
+			case IWN_SDID_5x00_15:=0A=
+			case IWN_SDID_5x00_16:=0A=
+			case IWN_SDID_5x00_23:=0A=
+			case IWN_SDID_5x00_24:=0A=
+			//iwl5100_abg_cfg=0A=
+				sc->txchainmask =3D IWN_ANT_B;=0A=
+				sc->rxchainmask =3D IWN_ANT_AB;=0A=
+				break;=0A=
+			=0A=
+			case IWN_SDID_5x00_25:=0A=
+			case IWN_SDID_5x00_26:=0A=
+			case IWN_SDID_5x00_27:=0A=
+			case IWN_SDID_5x00_28:=0A=
+			case IWN_SDID_5x00_29:=0A=
+			case IWN_SDID_5x00_30:=0A=
+			case IWN_SDID_5x00_31:=0A=
+			case IWN_SDID_5x00_32:=0A=
+			case IWN_SDID_5x00_33:=0A=
+			case IWN_SDID_5x00_34:=0A=
+			case IWN_SDID_5x00_35:=0A=
+			case IWN_SDID_5x00_36:=0A=
+			//iwl5300_agn_cfg=0A=
+				sc->txchainmask =3D IWN_ANT_ABC;=0A=
+				sc->rxchainmask =3D IWN_ANT_ABC;=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+/* 5x50 Series */=0A=
+	case IWN_DID_5x50_1:=0A=
+	case IWN_DID_5x50_2:=0A=
+	case IWN_DID_5x50_3:=0A=
+	case IWN_DID_5x50_4:=0A=
+		sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+		sc->base_params =3D &iwn_default_base_params; =0A=
+		sc->fwname =3D "iwn5000fw";=0A=
+		switch(sc->subdevice_id) {=0A=
+			case IWN_SDID_5x50_1:=0A=
+			case IWN_SDID_5x50_2:=0A=
+			case IWN_SDID_5x50_3:=0A=
+			//iwl5350_agn_cfg=0A=
+				sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+				sc->base_params =3D &iwn_default_base_params; =0A=
+				sc->fwname =3D "iwn5000fw";=0A=
+			break;=0A=
+=0A=
+			case IWN_SDID_5x50_4:=0A=
+			case IWN_SDID_5x50_5:=0A=
+			case IWN_SDID_5x50_8:=0A=
+			case IWN_SDID_5x50_9:=0A=
+			case IWN_SDID_5x50_10:=0A=
+			case IWN_SDID_5x50_11:=0A=
+			//iwl5150_agn_cfg=0A=
+			case IWN_SDID_5x50_6:=0A=
+			case IWN_SDID_5x50_7:=0A=
+			case IWN_SDID_5x50_12:=0A=
+			case IWN_SDID_5x50_13:=0A=
+			//iwl5150_abg_cfg=0A=
+				sc->limits =3D &iwn5000_sensitivity_limits;=0A=
+				sc->fwname =3D "iwn5150fw";=0A=
+				sc->base_params =3D &iwn_5x50_base_params;=0A=
+				break;=0A=
+			default:=0A=
+				device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev %d not supported (subdevice) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+				return ENOTSUP;=0A=
+		}=0A=
+		break;=0A=
+	default:=0A=
+			device_printf(sc->sc_dev, "adapter type id : 0x%04x sub id : 0x%04x =
rev 0x%08x not supported (device) \n",pid,sc->subdevice_id,sc->hw_type);=0A=
+			return ENOTSUP;=0A=
+	}=0A=
+	return 0;		=0A=
+}=0A=
+/*=0A=
+ *	Send IWN_CMD_GET_STATISTICS to ucode.=0A=
+ *  @enable: activate sending statistics from uCode=0A=
+ *	@clear : ask uCode to clear internal counter=0A=
+ *	@async : Sync mode for command (1=3D ASYNC, 0=3DSYNC)=0A=
+*/=0A=
+static int =0A=
+iwn_set_statistics_request(struct iwn_softc *sc,bool enable,bool =
clear,int async)=0A=
+{=0A=
+	struct iwn_statistics_cmd cmd;=0A=
+	=0A=
+	if (enable) =0A=
+		cmd.configuration_flags=3D clear ? IWN_STATS_CONF_CLEAR_STATS :0;=0A=
+	else=0A=
+		cmd.configuration_flags=3D IWN_STATS_CONF_DISABLE_NOTIF;=0A=
+		=0A=
+	=0A=
+	DPRINTF(sc, IWN_DEBUG_CALIBRATE, "%s: sending request for statistics =
flags : 0x%x\n",=0A=
+	    __func__,cmd.configuration_flags);=0A=
+	return iwn_cmd(sc, IWN_CMD_GET_STATISTICS, &cmd, sizeof cmd, async ? =
1:0);=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_cfg_ucode_post_alive(struct iwn_softc *sc)=0A=
+{=0A=
+	int error;=0A=
+	=0A=
+	/* Configure WiMAX coexistence for combo adapters. */=0A=
+	error =3D iwn5000_send_wimax_coex(sc);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not configure WiMAX coexistence, error %d\n",=0A=
+		    __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	if (!(sc->base_params->no_crystal_calibration)) {=0A=
+		DPRINTF(sc, IWN_DEBUG_RESET, "Doing calib in %s\n",__func__);=0A=
+		error =3D iwn5000_crystal_calib(sc);=0A=
+		if (error !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+				"%s: crystal calibration failed, error %d\n",=0A=
+				__func__, error);=0A=
+			return error;=0A=
+		}=0A=
+	} else {=0A=
+		DPRINTF(sc, IWN_DEBUG_RESET, "Crystal calibration disable in =
%s\n",__func__);=0A=
+	}=0A=
+	=0A=
+	return 0;=0A=
+}=0A=
+//----------------- NEW----------------------=0A=
+/*=0A=
+ * Handles ioctl change requests for power management state etc.=0A=
+ */=0A=
+static int iwn_iv_reset(struct ieee80211vap *vap, u_long cmd)=0A=
+{=0A=
+	int error =3D 0;=0A=
+	switch (cmd) {=0A=
+	case IEEE80211_IOC_POWERSAVE:{=0A=
+		struct iwn_softc * sc =3D (struct iwn_softc *)=0A=
+				(vap->iv_ic->ic_ifp->if_softc);=0A=
+		IWN_LOCK(sc);=0A=
+=0A=
+		/* XXX to discuss */=0A=
+		int dtim =3D IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE;=0A=
+=0A=
+		int async =3D 0;=0A=
+=0A=
+		/*=0A=
+		 * At present the powersave level is set to 0 (receiver=0A=
+		 * continuously on) if power save is disabled, and set to=0A=
+		 * IWN_POWERSAVE_LVL_VOIP_COMPATIBLE otherwise.=0A=
+		 * Later the power levels 0-5 could be exposed to the user.=0A=
+		 */=0A=
+		if (vap->iv_flags & IEEE80211_F_PMGTON) {=0A=
+			/*=0A=
+			 * In ieee80211_vap_setup() we have:=0A=
+			 *  vap->iv_flags =3D ic->ic_flags;=0A=
+			 * i.e. any vap's iv_flags initialize to ic->ic_flags.=0A=
+			 * Setting the flags on ic will allow a vap to get=0A=
+			 * the correct powersave level once it is created.=0A=
+			 */=0A=
+			vap->iv_ic->ic_flags |=3D IEEE80211_F_PMGTON;=0A=
+			sc->desired_pwrsave_level =3D=0A=
+					IWN_POWERSAVE_LVL_VOIP_COMPATIBLE;=0A=
+		} else {=0A=
+			vap->iv_ic->ic_flags &=3D ~IEEE80211_F_PMGTON;=0A=
+			sc->desired_pwrsave_level =3D IWN_POWERSAVE_LVL_NONE;=0A=
+		}=0A=
+		error =3D iwn_set_pslevel(sc, dtim, sc->desired_pwrsave_level,=0A=
+				async);=0A=
+		IWN_UNLOCK(sc);=0A=
+		}=0A=
+		break;=0A=
+	default:=0A=
+		/*=0A=
+		 * For unhandled ioctls, ENETRESET has to be passed back to=0A=
+		 * net80211 layer, which will in turn call the function to=0A=
+		 * reinitialize the entire device.=0A=
+		 */=0A=
+		error =3D ENETRESET;=0A=
+		break;=0A=
+	}=0A=
+	return error;=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_newstate_u1(struct ieee80211vap *vap, enum ieee80211_state nstate, =
int arg)=0A=
+{=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+	struct ieee80211com *ic =3D vap->iv_ic;=0A=
+	struct iwn_softc *sc =3D ic->ic_ifp->if_softc;=0A=
+=0A=
+	int error =3D 0;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	=0A=
+	DPRINTF(sc, IWN_DEBUG_STATE, "%s: %s -> %s\n", __func__,=0A=
+	    ieee80211_state_name[vap->iv_state], ieee80211_state_name[nstate]);=0A=
+=0A=
+	IEEE80211_UNLOCK(ic);=0A=
+	IWN_LOCK(sc);=0A=
+	callout_stop(&sc->calib_to);=0A=
+=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+=0A=
+	switch (nstate) {=0A=
+	case IEEE80211_S_ASSOC:=0A=
+		if (vap->iv_state !=3D IEEE80211_S_RUN)=0A=
+			break;=0A=
+		/* FALLTHROUGH */=0A=
+	case IEEE80211_S_AUTH:=0A=
+		if (vap->iv_state =3D=3D IEEE80211_S_AUTH)=0A=
+			break;=0A=
+=0A=
+		/*=0A=
+		 * !AUTH -> AUTH transition requires state reset to handle=0A=
+		 * reassociations correctly.=0A=
+		 */=0A=
+		sc->rxon->associd =3D 0;=0A=
+		sc->rxon->filter &=3D ~htole32(IWN_FILTER_BSS);=0A=
+		sc->calib.state =3D IWN_CALIB_STATE_INIT;=0A=
+=0A=
+		if ((error =3D iwn_auth_u1(sc, vap)) !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+			    "%s: could not move to auth state\n", __func__);=0A=
+		}=0A=
+		break;=0A=
+=0A=
+	case IEEE80211_S_SCAN:=0A=
+=0A=
+=0A=
+		if ((error =3D iwn_set_timing_u1(sc)) !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+			    "%s: iwn_set_timing_u1 error %d\n", __func__, error);=0A=
+			return error;=0A=
+		}=0A=
+=0A=
+		break;=0A=
+=0A=
+	case IEEE80211_S_RUN:=0A=
+=0A=
+		/*=0A=
+		 * RUN -> RUN transition; Just restart the timers.=0A=
+		 */=0A=
+		if (vap->iv_state =3D=3D IEEE80211_S_RUN) {=0A=
+			sc->calib_cnt =3D 0;=0A=
+			break;=0A=
+		}=0A=
+=0A=
+		/*=0A=
+		 * !RUN -> RUN requires setting the association id=0A=
+		 * which is done with a firmware cmd.  We also defer=0A=
+		 * starting the timers until that work is done.=0A=
+		 */=0A=
+		if ((error =3D iwn_run_u1(sc, vap)) !=3D 0) {=0A=
+			device_printf(sc->sc_dev,=0A=
+			    "%s: could not move to run state\n", __func__);=0A=
+		}=0A=
+		break;=0A=
+=0A=
+	case IEEE80211_S_INIT:=0A=
+		sc->calib.state =3D IWN_CALIB_STATE_INIT;=0A=
+		break;=0A=
+=0A=
+	default:=0A=
+		break;=0A=
+	}=0A=
+	IWN_UNLOCK(sc);=0A=
+	IEEE80211_LOCK(ic);=0A=
+	if (error !=3D 0) {=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end in error\n", __func__);=0A=
+		return error;=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	return ivp->iv_newstate(vap, nstate, arg);=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_auth_u1(struct iwn_softc *sc, struct ieee80211vap *vap)=0A=
+{=0A=
+	struct iwn_ops *ops =3D &sc->ops;=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	struct ieee80211_node *ni =3D vap->iv_bss;=0A=
+	int error;=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+	=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->myaddr, ivp->macaddr);=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->wlap, IF_LLADDR(ifp));=0A=
+	/* Update adapter configuration. */=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->bssid, ni->ni_bssid);=0A=
+	sc->rxon->chan =3D ieee80211_chan2ieee(ic, ni->ni_chan);=0A=
+	sc->rxon->flags =3D htole32(IWN_RXON_TSF | IWN_RXON_CTS_TO_SELF);=0A=
+	if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan))=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);=0A=
+	if (ic->ic_flags & IEEE80211_F_SHSLOT)=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_SHSLOT);=0A=
+	if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_SHPREAMBLE);=0A=
+	if (IEEE80211_IS_CHAN_A(ni->ni_chan)) {=0A=
+		sc->rxon->cck_mask  =3D 0;=0A=
+		sc->rxon->ofdm_mask =3D 0x15;=0A=
+	} else if (IEEE80211_IS_CHAN_B(ni->ni_chan)) {=0A=
+		sc->rxon->cck_mask  =3D 0x03;=0A=
+		sc->rxon->ofdm_mask =3D 0;=0A=
+	} else {=0A=
+		/* Assume 802.11b/g. */=0A=
+		sc->rxon->cck_mask  =3D 0x0f;=0A=
+		sc->rxon->ofdm_mask =3D 0x15;=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_STATE, "rxon chan %d flags %x cck %x ofdm %x\n",=0A=
+	    sc->rxon->chan, sc->rxon->flags, sc->rxon->cck_mask,=0A=
+	    sc->rxon->ofdm_mask);=0A=
+	sc->rxon->mode =3D IWN_MODE_2STA;=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_WIPAN_RXON, sc->rxon, sc->rxonsz, 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev, "%s: RXON command failed, error %d\n",=0A=
+		    __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	/* Configuration has changed, set TX power accordingly. */=0A=
+	if ((error =3D ops->set_txpower(sc, ni->ni_chan, 1)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not set TX power, error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+	/*=0A=
+	 * Reconfiguring RXON clears the firmware nodes table so we must=0A=
+	 * add the broadcast node again.=0A=
+	 */=0A=
+	if ((error =3D iwn_add_broadcast_node_u1(sc, 0)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not add broadcast node, error %d\n", __func__,=0A=
+		    error);=0A=
+		return error;=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	=0A=
+	return 0;=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_run_u1(struct iwn_softc *sc, struct ieee80211vap *vap)=0A=
+{=0A=
+	struct iwn_ops *ops =3D &sc->ops;=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	struct ieee80211_node *ni =3D vap->iv_bss;=0A=
+	struct iwn_node_info node;=0A=
+	uint32_t htflags =3D 0;=0A=
+	int error;=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	=0A=
+	if (ic->ic_opmode =3D=3D IEEE80211_M_MONITOR) {=0A=
+		/* Link LED blinks while monitoring. */=0A=
+		return 0;=0A=
+	}=0A=
+=0A=
+	if ((error =3D iwn_set_timing_u1(sc)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not set timing, error %d\n", __func__, error);=0A=
+	}=0A=
+=0A=
+	if ((error =3D iwn_updateedca_u1(ic)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: iwn_updateedca_u1, error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->myaddr, ivp->macaddr);=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->wlap, IF_LLADDR(ifp));=0A=
+	/* Update adapter configuration. */=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->bssid, ni->ni_bssid);=0A=
+	sc->rxon->associd =3D htole16(IEEE80211_AID(ni->ni_associd));=0A=
+	sc->rxon->chan =3D ieee80211_chan2ieee(ic, ni->ni_chan);=0A=
+	sc->rxon->flags =3D htole32(IWN_RXON_TSF | IWN_RXON_CTS_TO_SELF);=0A=
+	if (IEEE80211_IS_CHAN_2GHZ(ni->ni_chan))=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);=0A=
+	if (ic->ic_flags & IEEE80211_F_SHSLOT)=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_SHSLOT);=0A=
+	if (ic->ic_flags & IEEE80211_F_SHPREAMBLE)=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_SHPREAMBLE);=0A=
+	if (IEEE80211_IS_CHAN_A(ni->ni_chan)) {=0A=
+		sc->rxon->cck_mask  =3D 0;=0A=
+		sc->rxon->ofdm_mask =3D 0x15;=0A=
+	} else if (IEEE80211_IS_CHAN_B(ni->ni_chan)) {=0A=
+		sc->rxon->cck_mask  =3D 0x03;=0A=
+		sc->rxon->ofdm_mask =3D 0;=0A=
+	} else {=0A=
+		/* Assume 802.11b/g. */=0A=
+		sc->rxon->cck_mask  =3D 0x0f;=0A=
+		sc->rxon->ofdm_mask =3D 0x15;=0A=
+	}=0A=
+	if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {=0A=
+		htflags |=3D IWN_RXON_HT_PROTMODE(ic->ic_curhtprotmode);=0A=
+		if (IEEE80211_IS_CHAN_HT40(ni->ni_chan)) {=0A=
+			switch (ic->ic_curhtprotmode) {=0A=
+			case IEEE80211_HTINFO_OPMODE_HT20PR:=0A=
+				htflags |=3D IWN_RXON_HT_MODEPURE40;=0A=
+				break;=0A=
+			default:=0A=
+				htflags |=3D IWN_RXON_HT_MODEMIXED;=0A=
+				break;=0A=
+			}=0A=
+		}=0A=
+		if (IEEE80211_IS_CHAN_HT40D(ni->ni_chan))=0A=
+			htflags |=3D IWN_RXON_HT_HT40MINUS;=0A=
+	}=0A=
+	sc->rxon->flags |=3D htole32(htflags);=0A=
+	sc->rxon->filter |=3D htole32(IWN_FILTER_BSS);=0A=
+	DPRINTF(sc, IWN_DEBUG_STATE, "rxon chan %d flags %x\n",=0A=
+	    sc->rxon->chan, sc->rxon->flags);=0A=
+	sc->rxon->mode =3D IWN_MODE_2STA;=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_WIPAN_RXON, sc->rxon, sc->rxonsz, 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not update configuration, error %d\n", __func__,=0A=
+		    error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	/* Configuration has changed, set TX power accordingly. */=0A=
+	if ((error =3D ops->set_txpower(sc, ni->ni_chan, 1)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not set TX power, error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	/* Fake a join to initialize the TX rate. */=0A=
+	((struct iwn_node *)ni)->id =3D IWN_STA_ID;=0A=
+	iwn_newassoc(ni, 1);=0A=
+=0A=
+	/* Add BSS node. */=0A=
+	memset(&node, 0, sizeof node);=0A=
+	node.htflags |=3D htole32(IWN_STA_FLAG_PAN_STATION);=0A=
+	IEEE80211_ADDR_COPY(node.macaddr, ni->ni_macaddr);=0A=
+	node.id =3D IWN_STA_ID;=0A=
+	if (IEEE80211_IS_CHAN_HT(ni->ni_chan)) {=0A=
+		switch (ni->ni_htcap & IEEE80211_HTCAP_SMPS) {=0A=
+		case IEEE80211_HTCAP_SMPS_ENA:=0A=
+			node.htflags |=3D htole32(IWN_SMPS_MIMO_DIS);=0A=
+			break;=0A=
+		case IEEE80211_HTCAP_SMPS_DYNAMIC:=0A=
+			node.htflags |=3D htole32(IWN_SMPS_MIMO_PROT);=0A=
+			break;=0A=
+		}=0A=
+		node.htflags |=3D htole32(IWN_AMDPU_SIZE_FACTOR(3) |=0A=
+		    IWN_AMDPU_DENSITY(5));	/* 4us */=0A=
+		if (IEEE80211_IS_CHAN_HT40(ni->ni_chan))=0A=
+			node.htflags |=3D htole32(IWN_NODE_HT40);=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_STATE, "%s: adding BSS node1\n", __func__);=0A=
+	error =3D ops->add_node(sc, &node, 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: could not add BSS node1, error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	/* Setting the initial rate for node */=0A=
+	ni->ni_txrate =3D ni->ni_rates.rs_rates[0];=0A=
+=0A=
+	/* XXX: init rate scaling */=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	=0A=
+	#ifdef IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP=0A=
+		return iwn_set_pslevel(sc, IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE,=0A=
+			sc->desired_pwrsave_level, 0);=0A=
+	#else=0A=
+		return 0;=0A=
+	#endif=0A=
+=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_set_timing_u1(struct iwn_softc *sc)=0A=
+{=0A=
+	struct iwn_cmd_timing cmd;=0A=
+	int error =3D 0;=0A=
+	struct ieee80211vap *vap;=0A=
+	struct iwn_vap *ivp;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	=0A=
+	vap =3D sc->ivap[IWN_RXON_PAN_CTX];=0A=
+	ivp =3D IWN_VAP(vap);=0A=
+=0A=
+	if ((error =3D iwn_config_u1(sc)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: iwn_config1 error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	if ((error =3D iwn_set_pan_params(sc)) !=3D 0) {=0A=
+		device_printf(sc->sc_dev,=0A=
+		    "%s: iwn_set_pan_params error %d\n", __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	memset(&cmd, 0, sizeof cmd);=0A=
+	cmd.lintval =3D htole16(10);=0A=
+	cmd.bintval =3D htole16(IWN_BEACON_INTERVAL_DEFAULT);=0A=
+	ivp->beacon_int =3D cmd.bintval;=0A=
+	cmd.binitval =3D htole32(0x032000);=0A=
+	cmd.dtim_period =3D 1;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	=0A=
+	return iwn_cmd(sc, IWN_CMD_WIPAN_RXON_TIMING, &cmd, sizeof cmd, 0);=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_config_u1(struct iwn_softc *sc)=0A=
+{=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	uint16_t rxchain;=0A=
+	int error;=0A=
+	struct ieee80211vap *vap =3D sc->ivap[IWN_RXON_PAN_CTX];=0A=
+	struct iwn_vap *ivp =3D IWN_VAP(vap);=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->myaddr, ivp->macaddr);=0A=
+	IEEE80211_ADDR_COPY(sc->rxon->wlap, IF_LLADDR(ifp));=0A=
+	sc->rxon->chan =3D ieee80211_chan2ieee(ic, ic->ic_curchan);=0A=
+	sc->rxon->flags =3D htole32(IWN_RXON_TSF);=0A=
+	if (IEEE80211_IS_CHAN_2GHZ(ic->ic_curchan))=0A=
+		sc->rxon->flags |=3D htole32(IWN_RXON_AUTO | IWN_RXON_24GHZ);=0A=
+	sc->rxon->mode =3D IWN_MODE_P2P;=0A=
+	sc->rxon->filter =3D htole32(IWN_FILTER_MULTICAST);=0A=
+	sc->rxon->cck_mask  =3D 0x0f;	/* not yet negotiated */=0A=
+	sc->rxon->ofdm_mask =3D 0xff;	/* not yet negotiated */=0A=
+	sc->rxon->ht_single_mask =3D 0xff;=0A=
+	sc->rxon->ht_dual_mask =3D 0xff;=0A=
+	sc->rxon->ht_triple_mask =3D 0xff;=0A=
+	rxchain =3D=0A=
+	    IWN_RXCHAIN_VALID(sc->rxchainmask) |=0A=
+	    IWN_RXCHAIN_MIMO_COUNT(2) |=0A=
+	    IWN_RXCHAIN_IDLE_COUNT(2);=0A=
+	sc->rxon->rxchain =3D htole16(rxchain);=0A=
+	sc->rxon->associd =3D 0;=0A=
+	sc->rxon->filter &=3D ~htole32(IWN_FILTER_BSS);=0A=
+=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_WIPAN_RXON, sc->rxon, sc->rxonsz, 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev, "%s: IWN_CMD_WIPAN_RXON command failed\n",=0A=
+		    __func__);=0A=
+		return error;=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	=0A=
+	return 0;=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_set_pan_params(struct iwn_softc *sc)=0A=
+{=0A=
+	struct iwn_pan_params_cmd cmd;=0A=
+	int slot0 =3D 300, slot1 =3D 0;=0A=
+	int bcnint;=0A=
+	int error =3D 0;=0A=
+	=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	=0A=
+	/*=0A=
+	 * If the PAN context is inactive, then we don't need=0A=
+	 * to update the PAN parameters=0A=
+	 */=0A=
+	if (sc->ctx !=3D IWN_RXON_PAN_CTX) {=0A=
+		DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end with no need to do that\n", =
__func__);=0A=
+		return 0;=0A=
+	}=0A=
+=0A=
+	memset(&cmd, 0, sizeof(cmd));=0A=
+=0A=
+	/* only 2 slots are currently allowed */=0A=
+	cmd.num_slots =3D 2;=0A=
+=0A=
+	cmd.slots[0].type =3D IWN_RXON_BSS_CTX; /* BSS */=0A=
+	cmd.slots[1].type =3D IWN_RXON_PAN_CTX; /* PAN */=0A=
+=0A=
+	cmd.flags |=3D htole16(IWN_PAN_PARAMS_FLG_SLOTTED_MODE);=0A=
+	bcnint =3D IWN_BEACON_INTERVAL_DEFAULT;=0A=
+	slot0 =3D (bcnint >> 1);=0A=
+	slot1 =3D (bcnint - slot0);=0A=
+=0A=
+	if(sc->uc_scan_progress =3D=3D 1) {=0A=
+		slot0 =3D bcnint * 3 - IWN_SLOT_TIME_MIN;=0A=
+		slot1 =3D IWN_SLOT_TIME_MIN;=0A=
+	}=0A=
+	cmd.slots[0].time =3D htole16(slot0);=0A=
+	cmd.slots[1].time =3D htole16(slot1);=0A=
+=0A=
+	error =3D iwn_cmd(sc, IWN_CMD_WIPAN_PARAMS, &cmd, sizeof(cmd), 0);=0A=
+	if (error !=3D 0) {=0A=
+		device_printf(sc->sc_dev, "%s: IWN_CMD_WIPAN_PARAMS command failed, =
error %d\n",=0A=
+		    __func__, error);=0A=
+		return error;=0A=
+	}=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	=0A=
+	return 0;=0A=
+}=0A=
+=0A=
+static int=0A=
+iwn_updateedca_u1(struct ieee80211com *ic)=0A=
+{=0A=
+#define IWN_EXP2(x)	((1 << (x)) - 1)	/* CWmin =3D 2^ECWmin - 1 */=0A=
+	struct iwn_softc *sc =3D ic->ic_ifp->if_softc;=0A=
+	struct iwn_edca_params cmd;=0A=
+	int aci;=0A=
+=0A=
+	memset(&cmd, 0, sizeof cmd);=0A=
+	cmd.flags =3D htole32(IWN_EDCA_UPDATE);=0A=
+	for (aci =3D 0; aci < WME_NUM_AC; aci++) {=0A=
+		const struct wmeParams *ac =3D=0A=
+		    &ic->ic_wme.wme_chanParams.cap_wmeParams[aci];=0A=
+		cmd.ac[aci].aifsn =3D ac->wmep_aifsn;=0A=
+		cmd.ac[aci].cwmin =3D htole16(IWN_EXP2(ac->wmep_logcwmin));=0A=
+		cmd.ac[aci].cwmax =3D htole16(IWN_EXP2(ac->wmep_logcwmax));=0A=
+		cmd.ac[aci].txoplimit =3D=0A=
+		    htole16(IEEE80211_TXOP_TO_US(ac->wmep_txopLimit));=0A=
+	}=0A=
+	return iwn_cmd(sc, IWN_CMD_WIPAN_QOS_PARAM, &cmd, sizeof cmd, 1);=0A=
+#undef IWN_EXP2=0A=
+}=0A=
+=0A=
+/*=0A=
+ * Broadcast node is used to send group-addressed and management frames.=0A=
+ */=0A=
+static int=0A=
+iwn_add_broadcast_node_u1(struct iwn_softc *sc, int async)=0A=
+{=0A=
+	struct iwn_ops *ops =3D &sc->ops;=0A=
+	struct ifnet *ifp =3D sc->sc_ifp;=0A=
+	struct ieee80211com *ic =3D ifp->if_l2com;=0A=
+	struct iwn_node_info node;=0A=
+	struct iwn_cmd_link_quality linkq;=0A=
+	uint8_t txant;=0A=
+	int i, error;=0A=
+=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s begin\n", __func__);=0A=
+	=0A=
+	sc->rxon =3D &sc->rx_on[IWN_RXON_PAN_CTX];=0A=
+=0A=
+	memset(&node, 0, sizeof node);=0A=
+	IEEE80211_ADDR_COPY(node.macaddr, ifp->if_broadcastaddr);=0A=
+=0A=
+	node.id =3D IWN_PAN_BCAST_ID;=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_BCAST_ID;=0A=
+	linkq.antmsk_1stream =3D txant;=0A=
+	linkq.antmsk_2stream =3D IWN_ANT_AB;=0A=
+	linkq.ampdu_max =3D 64;=0A=
+	linkq.ampdu_threshold =3D 3;=0A=
+	linkq.ampdu_limit =3D htole16(4000);	/* 4ms */=0A=
+=0A=
+	/* Use lowest mandatory bit-rate. */=0A=
+	if (IEEE80211_IS_CHAN_5GHZ(ic->ic_curchan))=0A=
+		linkq.retry[0] =3D htole32(0xd);=0A=
+	else=0A=
+		linkq.retry[0] =3D htole32(10 | IWN_RFLAG_CCK);=0A=
+	linkq.retry[0] |=3D htole32(IWN_RFLAG_ANT(txant));=0A=
+	/* Use same bit-rate for all TX retries. */=0A=
+	for (i =3D 1; i < IWN_MAX_TX_RETRIES; i++) {=0A=
+		linkq.retry[i] =3D linkq.retry[0];=0A=
+	}=0A=
+	DPRINTF(sc, IWN_DEBUG_TRACE, "->%s end\n", __func__);=0A=
+	=0A=
+	return iwn_cmd(sc, IWN_CMD_LINK_QUALITY, &linkq, sizeof linkq, async);=0A=
+}=0A=
+=0A=
+static uint16_t=0A=
+iwn_get_active_dwell(struct iwn_softc *sc, struct ieee80211_channel *c)=0A=
+{=0A=
+	int n_probes =3D 1;=0A=
+=0A=
+	if (IEEE80211_IS_CHAN_5GHZ(c))=0A=
+		return IWN_ACTIVE_DWELL_TIME_52 +=0A=
+			IWN_ACTIVE_DWELL_FACTOR_52 * (n_probes + 1);=0A=
+	else=0A=
+		return IWN_ACTIVE_DWELL_TIME_24 +=0A=
+			IWN_ACTIVE_DWELL_FACTOR_24 * (n_probes + 1);=0A=
+}=0A=
+=0A=
+static uint16_t=0A=
+iwn_get_passive_dwell(struct iwn_softc *sc, struct ieee80211_channel *c)=0A=
+{=0A=
+	uint8_t ctx_id =3D 0;=0A=
+	uint16_t beacon_int;=0A=
+	struct ieee80211vap *vap;=0A=
+	struct iwn_vap *ivp;=0A=
+	uint16_t dwell_time;=0A=
+=0A=
+	dwell_time =3D (IEEE80211_IS_CHAN_2GHZ(c)) ?=0A=
+			    IWN_PASSIVE_DWELL_BASE + IWN_PASSIVE_DWELL_TIME_24 :=0A=
+			    IWN_PASSIVE_DWELL_BASE + IWN_PASSIVE_DWELL_TIME_52;=0A=
+=0A=
+	for (ctx_id =3D 0; ctx_id < IWN_NUM_RXON_CTX; ctx_id++) {=0A=
+		vap =3D sc->ivap[ctx_id];=0A=
+		ivp =3D IWN_VAP(vap);=0A=
+		sc->rxon =3D &sc->rx_on[ctx_id];=0A=
+		if (!sc->rxon->associd)=0A=
+			continue;=0A=
+		beacon_int =3D ivp->beacon_int;=0A=
+		if (!beacon_int)=0A=
+			beacon_int =3D IWN_PASSIVE_DWELL_BASE;=0A=
+		beacon_int =3D (beacon_int * 98) / 100 - IWN_CHANNEL_TUNE_TIME * 2;=0A=
+		dwell_time =3D min(beacon_int, dwell_time);=0A=
+		if(sc->ctx !=3D IWN_RXON_PAN_CTX) break;=0A=
+	}=0A=
+=0A=
+	return dwell_time;=0A=
+}=0A=
+static void=0A=
+iwn_led_pattern(struct iwn_softc *sc)=0A=
+{=0A=
+	int i,j;=0A=
+=0A=
+	for(i =3D 0; i < IWN_MAX_BLINK_TBL; i++) {=0A=
+		if((sc->sc_led.led_last_tpt) > (blink_tbl[i].tpt * 1024 * 1024))=0A=
+			break;=0A=
+	}=0A=
+=0A=
+	for(j =3D 0; j < IWN_MAX_BLINK_TBL; j++) {=0A=
+		if((sc->sc_led.led_cur_tpt) > (blink_tbl[j].tpt * 1024 * 1024))=0A=
+			break;=0A=
+	}=0A=
+=0A=
+	if (i !=3D j)=0A=
+		iwn_set_led(sc, IWN_LED_LINK,blink_tbl[j].off_time,=0A=
+		    blink_tbl[j].on_time, IWN_LED_INT_BLINK);=0A=
+}=0A=
+=0A=
+=0A=
+	=0A=
Index: sys/dev/iwn/if_iwnreg.h=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/dev/iwn/if_iwnreg.h	(revision 253707)=0A=
+++ sys/dev/iwn/if_iwnreg.h	(working copy)=0A=
@@ -2,6 +2,8 @@=0A=
 /*	$OpenBSD: if_iwnreg.h,v 1.40 2010/05/05 19:41:57 damien Exp $	*/=0A=
 =0A=
 /*-=0A=
+ * Copyright (c) 2013 Cedric GROSS <c.gross@kreiz-it.fr>=0A=
+ * Copyright (c) 2011 Intel Corporation=0A=
  * Copyright (c) 2007, 2008=0A=
  *	Damien Bergamini <damien.bergamini@free.fr>=0A=
  *=0A=
@@ -17,7 +19,267 @@=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=
+ =0A=
+#define IWN_CT_KILL_THRESHOLD              114             /* in =
Celsius */=0A=
+#define IWN_CT_KILL_EXIT_THRESHOLD         95              /* in =
Celsius */=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=3D=
=3D=0A=
+ *							DEVICE ID BLOCK=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=3D=
=3D =0A=
+*/ =0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 2x30 series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_2x30_1 	0x0887 =0A=
+#define IWN_DID_2x30_2 	0x0888 =0A=
+/* SubDevice ID */=0A=
+#define IWN_SDID_2x30_1		0x4062 // "2000 Series 2x2 BGN/BT"=0A=
+#define IWN_SDID_2x30_2 	0x4262 // "2000 Series 2x2 BGN/BT"=0A=
+#define IWN_SDID_2x30_3 	0x4462 // "2000 Series 2x2 BGN/BT"=0A=
+#define IWN_SDID_2x30_4		0x4066 // "2000 Series 2x2 BG/BT"=0A=
+#define IWN_SDID_2x30_5		0x4266 // "2000 Series 2x2 BG/BT"=0A=
+#define IWN_SDID_2x30_6 	0x4466 // "2000 Series 2x2 BG/BT"=0A=
+ =0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 1000 series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_1000_1 0x0083=0A=
+#define IWN_DID_1000_2 0x0084=0A=
+=0A=
+/* SubDevice ID */=0A=
+#define IWN_SDID_1000_1 0x1205 // iwl1000_bgn_cfg=0A=
+#define IWN_SDID_1000_2 0x1305 //  iwl1000_bgn_cfg=0A=
+#define IWN_SDID_1000_3 0x1225 //  iwl1000_bgn_cfg=0A=
+#define IWN_SDID_1000_4 0x1325 //  iwl1000_bgn_cfg=0A=
+#define IWN_SDID_1000_5 0x1215 //  iwl1000_bgn_cfg=0A=
+#define IWN_SDID_1000_6 0x1315 //  iwl1000_bgn_cfg=0A=
+=0A=
+#define IWN_SDID_1000_7 0x1206 // 	iwl1000_bg_cfg=0A=
+#define IWN_SDID_1000_8 0x1306 //  iwl1000_bg_cfg=0A=
+#define IWN_SDID_1000_9 0x1226 //  iwl1000_bg_cfg=0A=
+#define IWN_SDID_1000_10 0x1326 //  iwl1000_bg_cfg=0A=
+#define IWN_SDID_1000_11 0x1216 //  iwl1000_bg_cfg=0A=
+#define IWN_SDID_1000_12 0x1316 //  iwl1000_bg_cfg=0A=
+=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 6x00 series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_6x00_1	0x422B=0A=
+#define IWN_DID_6x00_2  0x422C=0A=
+#define IWN_DID_6x00_3	0x4238=0A=
+#define IWN_DID_6x00_4	0x4239=0A=
+/* SubDevice ID */=0A=
+#define IWN_SDID_6x00_1 0x1101 //  iwl6000_3agn_cfg=0A=
+#define IWN_SDID_6x00_2 0x1121 //  iwl6000_3agn_cfg=0A=
+#define IWN_SDID_6x00_3 0x1301 //  iwl6000i_2agn_cfg=0A=
+#define IWN_SDID_6x00_4 0x1306 //  iwl6000i_2abg_cfg=0A=
+#define IWN_SDID_6x00_5 0x1307 //  iwl6000i_2bg_cfg=0A=
+#define IWN_SDID_6x00_6 0x1321 //  iwl6000i_2agn_cfg=0A=
+#define IWN_SDID_6x00_7 0x1326 //  iwl6000i_2abg_cfg=0A=
+#define IWN_SDID_6x00_8 0x1111 //  iwl6000_3agn_cfg=0A=
+#define IWN_SDID_6x00_9 0x1311 //  iwl6000i_2agn_cfg=0A=
+#define IWN_SDID_6x00_10 0x1316 //  iwl6000i_2abg_cfg=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 6x05 series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_6x05_1	0x0082=0A=
+#define IWN_DID_6x05_2 	0x0085=0A=
+/* SubDevice ID */=0A=
+#define IWN_SDID_6x05_1 	0x1301 //iwl6005_2agn_cfg=0A=
+#define IWN_SDID_6x05_2 	0x1306 //iwl6005_2abg_cfg=0A=
+#define IWN_SDID_6x05_3 	0x1307 //iwl6005_2bg_cfg=0A=
+#define IWN_SDID_6x05_4 	0x1321 //iwl6005_2agn_cfg=0A=
+#define IWN_SDID_6x05_5 	0x1326 //iwl6005_2abg_cfg=0A=
+#define IWN_SDID_6x05_6 	0x1311 //iwl6005_2agn_cfg=0A=
+#define IWN_SDID_6x05_7 	0x1316 //iwl6005_2abg_cfg=0A=
+#define IWN_SDID_6x05_8 	0xC020 //iwl6005_2agn_sff_cfg=0A=
+#define IWN_SDID_6x05_9 	0xC220 //iwl6005_2agn_sff_cfg=0A=
+#define IWN_SDID_6x05_10 	0x4820 //iwl6005_2agn_d_cfg=0A=
+#define IWN_SDID_6x05_11 	0x1304 //iwl6005_2agn_mow1_cfg/* low 5GHz =
active */=0A=
+#define IWN_SDID_6x05_12 	0x1305 //iwl6005_2agn_mow2_cfg/* high 5GHz =
active */=0A=
+=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 6050 WiFi/WiMax Series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_6050_1 0x0087=0A=
+#define IWN_DID_6050_2 0x0089=0A=
+=0A=
+#define IWN_SDID_6050_1 0x1301 //iwl6050_2agn_cfg=0A=
+#define IWN_SDID_6050_2 0x1306 //iwl6050_2abg_cfg=0A=
+#define IWN_SDID_6050_3 0x1321 //iwl6050_2agn_cfg=0A=
+#define IWN_SDID_6050_4 0x1326 //iwl6050_2abg_cfg=0A=
+#define IWN_SDID_6050_5 0x1311 //iwl6050_2agn_cfg=0A=
+#define IWN_SDID_6050_6 0x1316 //iwl6050_2abg_cfg=0A=
+=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 6150 Series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+=0A=
+#define IWN_DID_6150_1 	0x0885 =0A=
+#define IWN_DID_6150_2 	0x0886=0A=
+=0A=
+#define IWN_SDID_6150_1	0x1305 // iwl6150_bgn_cfg=0A=
+#define IWN_SDID_6150_2	0x1307 // iwl6150_bg_cfg)=0A=
+#define IWN_SDID_6150_3	0x1325 // iwl6150_bgn_cfg=0A=
+#define IWN_SDID_6150_4	0x1327 // iwl6150_bg_cfg)=0A=
+#define IWN_SDID_6150_5	0x1315 // iwl6150_bgn_cfg=0A=
+#define IWN_SDID_6150_6	0x1317 // iwl6150_bg_cfg) =0A=
+ =0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 6035 Series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_6035_1 	0x088E=0A=
+#define IWN_DID_6035_2 	0x088F=0A=
+ =0A=
+#define IWN_SDID_6035_1 0x4060 // iwl6035_2agn_cfg=0A=
+#define IWN_SDID_6035_2 0x4260 // iwl6035_2agn_cfg=0A=
+#define IWN_SDID_6035_3 0x4460 // iwl6035_2agn_cfg=0A=
+#define IWN_SDID_6035_4 0x4860 // iwl6035_2agn_cfg=0A=
+=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 1030 and 6030 Series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_x030_1 		0x008A =0A=
+#define IWN_DID_x030_2 		0x008B=0A=
+#define IWN_DID_x030_3 		0x0090=0A=
+#define IWN_DID_x030_4 		0x0091=0A=
+=0A=
+#define IWN_SDID_x030_1 	0x5305 // iwl1030_bgn_cfg=0A=
+#define IWN_SDID_x030_2 	0x5307 // iwl1030_bg_cfg=0A=
+#define IWN_SDID_x030_3 	0x5325 // iwl1030_bgn_cfg=0A=
+#define IWN_SDID_x030_4 	0x5327 // iwl1030_bg_cfg=0A=
+#define IWN_SDID_x030_5 	0x5315 // iwl1030_bgn_cfg=0A=
+#define IWN_SDID_x030_6 	0x5317 // iwl1030_bg_cfg=0A=
+#define IWN_SDID_x030_7 	0x5211 // iwl6030_2agn_cfg=0A=
+#define IWN_SDID_x030_8 	0x5215 // iwl6030_2bgn_cfg=0A=
+#define IWN_SDID_x030_9 	0x5216 // iwl6030_2abg_cfg=0A=
+#define IWN_SDID_x030_10 	0x5201 // iwl6030_2agn_cfg=0A=
+#define IWN_SDID_x030_11 	0x5205 // iwl6030_2bgn_cfg=0A=
+#define IWN_SDID_x030_12 	0x5206 // iwl6030_2abg_cfg=0A=
+#define IWN_SDID_x030_13 	0x5207 // iwl6030_2bg_cfg)=0A=
+#define IWN_SDID_x030_14 	0x5221 // iwl6030_2agn_cfg=0A=
+#define IWN_SDID_x030_15 	0x5225 // iwl6030_2bgn_cfg=0A=
+#define IWN_SDID_x030_16 	0x5226 // iwl6030_2abg_cfg=0A=
+=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 130 Series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_130_1 		0x0896=0A=
+#define IWN_DID_130_2 		0x0897=0A=
+=0A=
+#define IWN_SDID_130_1 		0x5005 //iwl130_bgn_cfg=0A=
+#define IWN_SDID_130_2 		0x5007 //iwl130_bg_cfg=0A=
+#define IWN_SDID_130_3 		0x5015 //iwl130_bgn_cfg=0A=
+#define IWN_SDID_130_4 		0x5017 //iwl130_bg_cfg=0A=
+#define IWN_SDID_130_5 		0x5025 //iwl130_bgn_cfg=0A=
+#define IWN_SDID_130_6 		0x5027 //iwl130_bg_cfg=0A=
+=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 100 Series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_100_1 		0x08AE=0A=
+#define IWN_DID_100_2 		0x08AF=0A=
+=0A=
+#define IWN_SDID_100_1 		0x1005 //iwl100_bgn_cfg)=0A=
+#define IWN_SDID_100_2 		0x1007 //iwl100_bg_cfg)}=0A=
+#define IWN_SDID_100_3 		0x1015 //iwl100_bgn_cfg)=0A=
+#define IWN_SDID_100_4 		0x1017 //iwl100_bg_cfg)}=0A=
+#define IWN_SDID_100_5 		0x1025 //iwl100_bgn_cfg)=0A=
+#define IWN_SDID_100_6 		0x1027 //iwl100_bg_cfg)}=0A=
+=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 5x00 Series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_5x00_1 		0x4232=0A=
+#define IWN_DID_5x00_2 		0x4237=0A=
+#define IWN_DID_5x00_3 		0x4235=0A=
+#define IWN_DID_5x00_4 		0x4236=0A=
+=0A=
+#define IWN_SDID_5x00_1 		0x1201 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_2 		0x1301 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_3 		0x1204 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_4 		0x1304 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_5 		0x1205 //iwl5100_bgn_cfg=0A=
+#define IWN_SDID_5x00_6 		0x1305 //iwl5100_bgn_cfg=0A=
+#define IWN_SDID_5x00_7 		0x1206 //iwl5100_abg_cfg=0A=
+#define IWN_SDID_5x00_8 		0x1306 //iwl5100_abg_cfg=0A=
+#define IWN_SDID_5x00_9 		0x1221 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_10 		0x1321 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_11		0x1224 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_12 		0x1324 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_13 		0x1225 //iwl5100_bgn_cfg=0A=
+#define IWN_SDID_5x00_14 		0x1325 //iwl5100_bgn_cfg=0A=
+#define IWN_SDID_5x00_15 		0x1226 //iwl5100_abg_cfg=0A=
+#define IWN_SDID_5x00_16 		0x1326 //iwl5100_abg_cfg=0A=
+#define IWN_SDID_5x00_17 		0x1211 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_18 		0x1311 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_19 		0x1214 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_20 		0x1314 //iwl5100_agn_cfg=0A=
+#define IWN_SDID_5x00_21 		0x1215 //iwl5100_bgn_cfg=0A=
+#define IWN_SDID_5x00_22 		0x1315 //iwl5100_bgn_cfg=0A=
+#define IWN_SDID_5x00_23 		0x1216 //iwl5100_abg_cfg=0A=
+#define IWN_SDID_5x00_24 		0x1316 //iwl5100_abg_cfg=0A=
+#define IWN_SDID_5x00_25 		0x1021 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_26 		0x1121 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_27 		0x1024 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_28 		0x1124 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_29 		0x1001 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_30 		0x1101 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_31 		0x1004 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_32 		0x1104 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_33 		0x1011 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_34 		0x1111 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_35 		0x1014 //iwl5300_agn_cfg=0A=
+#define IWN_SDID_5x00_36 		0x1114 //iwl5300_agn_cfg=0A=
+=0A=
+/*=0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ * Device ID for 5x50 Series =0A=
+ * =
-------------------------------------------------------------------------=
----=0A=
+ */=0A=
+#define IWN_DID_5x50_1			0x423A=0A=
+#define IWN_DID_5x50_2			0x423B=0A=
+#define IWN_DID_5x50_3			0x423C=0A=
+#define IWN_DID_5x50_4			0x423D=0A=
+=0A=
+#define IWN_SDID_5x50_1 		0x1001 //iwl5350_agn_cfg=0A=
+#define IWN_SDID_5x50_2 		0x1021 //iwl5350_agn_cfg=0A=
+#define IWN_SDID_5x50_3 		0x1011 //iwl5350_agn_cfg=0A=
+#define IWN_SDID_5x50_4 		0x1201 //iwl5150_agn_cfg=0A=
+#define IWN_SDID_5x50_5 		0x1301 //iwl5150_agn_cfg=0A=
+#define IWN_SDID_5x50_6 		0x1206 //iwl5150_abg_cfg=0A=
+#define IWN_SDID_5x50_7 		0x1306 //iwl5150_abg_cfg=0A=
+#define IWN_SDID_5x50_8 		0x1221 //iwl5150_agn_cfg=0A=
+#define IWN_SDID_5x50_9 		0x1321 //iwl5150_agn_cfg=0A=
+#define IWN_SDID_5x50_10 		0x1211 //iwl5150_agn_cfg=0A=
+#define IWN_SDID_5x50_11 		0x1311 //iwl5150_agn_cfg=0A=
+#define IWN_SDID_5x50_12 		0x1216 //iwl5150_abg_cfg=0A=
+#define IWN_SDID_5x50_13 		0x1316 //iwl5150_abg_cfg=0A=
+=0A=
+=0A=
 #define IWN_TX_RING_COUNT	256=0A=
 #define IWN_TX_RING_LOMARK	192=0A=
 #define IWN_TX_RING_HIMARK	224=0A=
@@ -38,6 +300,11 @@=0A=
 #define IWN_ICT_SIZE		4096=0A=
 #define IWN_ICT_COUNT		(IWN_ICT_SIZE / sizeof (uint32_t))=0A=
 =0A=
+/* For cards with PAN command default is IWN_CMD_QUEUE_NUM */=0A=
+#define	IWN_CMD_QUEUE_NUM		4=0A=
+#define	IWN_PAN_CMD_QUEUE		9=0A=
+=0A=
+=0A=
 /* Maximum number of DMA segments for TX. */=0A=
 #define IWN_MAX_SCATTER	20=0A=
 =0A=
@@ -62,6 +329,7 @@=0A=
 #define IWN_INT			0x008=0A=
 #define IWN_INT_MASK		0x00c=0A=
 #define IWN_FH_INT		0x010=0A=
+#define IWN_GPIO_IN			0x018 /* read external chip pins */=0A=
 #define IWN_RESET		0x020=0A=
 #define IWN_GP_CNTRL		0x024=0A=
 #define IWN_HW_REV		0x028=0A=
@@ -69,8 +337,12 @@=0A=
 #define IWN_EEPROM_GP		0x030=0A=
 #define IWN_OTP_GP		0x034=0A=
 #define IWN_GIO			0x03c=0A=
+#define IWN_GP_UCODE	0x048 =0A=
 #define IWN_GP_DRIVER		0x050=0A=
+#define IWN_UCODE_GP1		0x054=0A=
+#define IWN_UCODE_GP1_SET   0x058=0A=
 #define IWN_UCODE_GP1_CLR	0x05c=0A=
+#define IWN_UCODE_GP2   	0x060 =0A=
 #define IWN_LED			0x094=0A=
 #define IWN_DRAM_INT_TBL	0x0a0=0A=
 #define IWN_SHADOW_REG_CTRL	0x0a8=0A=
@@ -79,10 +351,12 @@=0A=
 #define IWN_HW_REV_WA		0x22c=0A=
 #define IWN_DBG_HPET_MEM	0x240=0A=
 #define IWN_DBG_LINK_PWR_MGMT	0x250=0A=
+// Need nic_lock for use above=0A=
 #define IWN_MEM_RADDR		0x40c=0A=
 #define IWN_MEM_WADDR		0x410=0A=
 #define IWN_MEM_WDATA		0x418=0A=
 #define IWN_MEM_RDATA		0x41c=0A=
+#define IWN_TARG_MBX_C		0x430=0A=
 #define IWN_PRPH_WADDR  	0x444=0A=
 #define IWN_PRPH_RADDR   	0x448=0A=
 #define IWN_PRPH_WDATA  	0x44c=0A=
@@ -187,12 +461,50 @@=0A=
 #define IWN_RESET_LINK_PWR_MGMT_DIS	(1 << 31)=0A=
 =0A=
 /* Possible flags for register IWN_GP_CNTRL. */=0A=
-#define IWN_GP_CNTRL_MAC_ACCESS_ENA	(1 << 0)=0A=
+/*=0A=
+ * GP (general purpose) CONTROL REGISTER=0A=
+ * Bit fields:=0A=
+ *    27:  HW_RF_KILL_SW=0A=
+ *         Indicates state of (platform's) hardware RF-Kill switch=0A=
+ * 26-24:  POWER_SAVE_TYPE=0A=
+ *         Indicates current power-saving mode:=0A=
+ *         000 -- No power saving=0A=
+ *         001 -- MAC power-down=0A=
+ *         010 -- PHY (radio) power-down=0A=
+ *         011 -- Error=0A=
+ *   9-6:  SYS_CONFIG=0A=
+ *         Indicates current system configuration, reflecting pins on =
chip=0A=
+ *         as forced high/low by device circuit board.=0A=
+ *     4:  GOING_TO_SLEEP=0A=
+ *         Indicates MAC is entering a power-saving sleep power-down.=0A=
+ *         Not a good time to access device-internal resources.=0A=
+ *     3:  MAC_ACCESS_REQ=0A=
+ *         Host sets this to request and maintain MAC wakeup, to allow =
host=0A=
+ *         access to device-internal resources.  Host must wait for=0A=
+ *         MAC_CLOCK_READY (and !GOING_TO_SLEEP) before accessing =
non-CSR=0A=
+ *         device registers.=0A=
+ *     2:  INIT_DONE=0A=
+ *         Host sets this to put device into fully operational D0 power =
mode.=0A=
+ *         Host resets this after SW_RESET to put device into low power =
mode.=0A=
+ *     0:  MAC_CLOCK_READY=0A=
+ *         Indicates MAC (ucode processor, etc.) is powered up and can =
run.=0A=
+ *         Internal resources are accessible.=0A=
+ *         NOTE:  This does not indicate that the processor is actually =
running.=0A=
+ *         NOTE:  This does not indicate that device has completed=0A=
+ *                init or post-power-down restore of internal SRAM =
memory.=0A=
+ *                Use CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP as indication that=0A=
+ *                SRAM is restored and uCode is in normal operation =
mode.=0A=
+ *                Later devices (5xxx/6xxx/1xxx) use non-volatile SRAM, =
and=0A=
+ *                do not need to save/restore it.=0A=
+ *         NOTE:  After device reset, this bit remains "0" until host =
sets=0A=
+ *                INIT_DONE=0A=
+ */=0A=
+#define IWN_GP_CNTRL_MAC_ACCESS_ENA	(1 << 0) 		//x00000001=0A=
 #define IWN_GP_CNTRL_MAC_CLOCK_READY	(1 << 0)=0A=
-#define IWN_GP_CNTRL_INIT_DONE		(1 << 2)=0A=
-#define IWN_GP_CNTRL_MAC_ACCESS_REQ	(1 << 3)=0A=
-#define IWN_GP_CNTRL_SLEEP		(1 << 4)=0A=
-#define IWN_GP_CNTRL_RFKILL		(1 << 27)=0A=
+#define IWN_GP_CNTRL_INIT_DONE		(1 << 2)		//x00000004=0A=
+#define IWN_GP_CNTRL_MAC_ACCESS_REQ	(1 << 3)		//x00000008=0A=
+#define IWN_GP_CNTRL_SLEEP		(1 << 4)			//x00000010=0A=
+#define IWN_GP_CNTRL_RFKILL		(1 << 27)			//x08000000=0A=
 =0A=
 /* Possible flags for register IWN_HW_REV. */=0A=
 #define IWN_HW_REV_TYPE_SHIFT	4=0A=
@@ -206,6 +518,7 @@=0A=
 #define IWN_HW_REV_TYPE_6000	7=0A=
 #define IWN_HW_REV_TYPE_6050	8=0A=
 #define IWN_HW_REV_TYPE_6005	11=0A=
+#define IWN_HW_REV_TYPE_2230	12=0A=
 =0A=
 /* Possible flags for register IWN_GIO_CHICKEN. */=0A=
 #define IWN_GIO_CHICKEN_L1A_NO_L0S_RX	(1 << 23)=0A=
@@ -215,16 +528,20 @@=0A=
 #define IWN_GIO_L0S_ENA		(1 << 1)=0A=
 =0A=
 /* Possible flags for register IWN_GP_DRIVER. */=0A=
-#define IWN_GP_DRIVER_RADIO_3X3_HYB	(0 << 0)=0A=
-#define IWN_GP_DRIVER_RADIO_2X2_HYB	(1 << 0)=0A=
-#define IWN_GP_DRIVER_RADIO_2X2_IPA	(2 << 0)=0A=
-#define IWN_GP_DRIVER_CALIB_VER6	(1 << 2)=0A=
-#define IWN_GP_DRIVER_6050_1X2		(1 << 3)=0A=
+#define IWN_GP_DRIVER_RADIO_3X3_HYB				(0 << 0)=0A=
+#define IWN_GP_DRIVER_RADIO_2X2_HYB				(1 << 0)=0A=
+#define IWN_GP_DRIVER_RADIO_2X2_IPA				(2 << 0)=0A=
+#define IWN_GP_DRIVER_RADIO_MSK					(0x00000003)=0A=
+#define IWN_GP_DRIVER_CALIB_VER6				(1 << 2)=0A=
+#define IWN_GP_DRIVER_6050_1X2					(1 << 3)=0A=
+#define IWN_GP_DRIVER_REG_BIT_RADIO_IQ_INVERT 	(0x00000080)=0A=
 =0A=
+=0A=
 /* Possible flags for register IWN_UCODE_GP1_CLR. */=0A=
 #define IWN_UCODE_GP1_RFKILL		(1 << 1)=0A=
 #define IWN_UCODE_GP1_CMD_BLOCKED	(1 << 2)=0A=
 #define IWN_UCODE_GP1_CTEMP_STOP_RF	(1 << 3)=0A=
+#define IWN_UCODE_GP1_CFG_COMPLETE  (1 << 5)=0A=
 =0A=
 /* Possible flags/values for register IWN_LED. */=0A=
 #define IWN_LED_BSM_CTRL	(1 << 5)=0A=
@@ -231,6 +548,32 @@=0A=
 #define IWN_LED_OFF		0x00000038=0A=
 #define IWN_LED_ON		0x00000078=0A=
 =0A=
+#define	IWN_MAX_BLINK_TBL	10=0A=
+#define	IWN_LED_STATIC_ON	0=0A=
+#define	IWN_LED_STATIC_OFF	1=0A=
+#define	IWN_LED_SLOW_BLINK	2=0A=
+#define	IWN_LED_INT_BLINK	3=0A=
+#define	IWN_LED_UNIT		0x1388 /* 5 ms */=0A=
+=0A=
+static const struct {=0A=
+	uint16_t tpt;	/* Mb/s */=0A=
+	uint8_t on_time;=0A=
+	uint8_t off_time;=0A=
+} blink_tbl[] =3D=0A=
+{=0A=
+	{300, 5,  5},=0A=
+	{200, 8,  8},=0A=
+	{100, 11, 11},=0A=
+	{70,  13, 13},=0A=
+	{50,  15, 15},=0A=
+	{20,  17, 17},=0A=
+	{10,  19, 19},=0A=
+	{5,   22, 22},=0A=
+	{1,   26, 26},=0A=
+	{0,   33, 33},=0A=
+	/* SOLID_ON */=0A=
+};=0A=
+=0A=
 /* Possible flags for register IWN_DRAM_INT_TBL. */=0A=
 #define IWN_DRAM_INT_TBL_WRAP_CHECK	(1 << 27)=0A=
 #define IWN_DRAM_INT_TBL_ENABLE		(1 << 31)=0A=
@@ -246,18 +589,19 @@=0A=
 #define IWN_BSM_WR_CTRL_START		(1 << 31)=0A=
 =0A=
 /* Possible flags for register IWN_INT. */=0A=
-#define IWN_INT_ALIVE		(1 <<  0)=0A=
-#define IWN_INT_WAKEUP		(1 <<  1)=0A=
-#define IWN_INT_SW_RX		(1 <<  3)=0A=
-#define IWN_INT_CT_REACHED	(1 <<  6)=0A=
-#define IWN_INT_RF_TOGGLED	(1 <<  7)=0A=
-#define IWN_INT_SW_ERR		(1 << 25)=0A=
-#define IWN_INT_SCHED		(1 << 26)=0A=
-#define IWN_INT_FH_TX		(1 << 27)=0A=
-#define IWN_INT_RX_PERIODIC	(1 << 28)=0A=
-#define IWN_INT_HW_ERR		(1 << 29)=0A=
-#define IWN_INT_FH_RX		(1 << 31)=0A=
+#define IWN_INT_ALIVE		(1 <<  0) // x00000001=0A=
+#define IWN_INT_WAKEUP		(1 <<  1) // x00000002=0A=
+#define IWN_INT_SW_RX		(1 <<  3) // x00000008=0A=
+#define IWN_INT_CT_REACHED	(1 <<  6) // x00000040=0A=
+#define IWN_INT_RF_TOGGLED	(1 <<  7) // x00000080=0A=
+#define IWN_INT_SW_ERR		(1 << 25) // x02000000=0A=
+#define IWN_INT_SCHED		(1 << 26) // x04000000=0A=
+#define IWN_INT_FH_TX		(1 << 27) // x08000000=0A=
+#define IWN_INT_RX_PERIODIC	(1 << 28) // x10000000=0A=
+#define IWN_INT_HW_ERR		(1 << 29) // x20000000=0A=
+#define IWN_INT_FH_RX		(1 << 31) // x80000000=0A=
 =0A=
+=0A=
 /* Shortcut. */=0A=
 #define IWN_INT_MASK_DEF						\=0A=
 	(IWN_INT_SW_ERR | IWN_INT_HW_ERR | IWN_INT_FH_TX |		\=0A=
@@ -400,6 +744,12 @@=0A=
 	uint8_t		qid;=0A=
 } __packed;=0A=
 =0A=
+/* CARD_STATE_NOTIFICATION */ =0A=
+#define IWN_STATE_CHANGE_HW_CARD_DISABLED               0x01=0A=
+#define IWN_STATE_CHANGE_SW_CARD_DISABLED               0x02=0A=
+#define IWN_STATE_CHANGE_CT_CARD_DISABLED               0x04=0A=
+#define IWN_STATE_CHANGE_RXON_CARD_DISABLED             0x10=0A=
+=0A=
 /* Possible RX status flags. */=0A=
 #define IWN_RX_NO_CRC_ERR	(1 <<  0)=0A=
 #define IWN_RX_NO_OVFL_ERR	(1 <<  1)=0A=
@@ -423,7 +773,8 @@=0A=
 #define IWN_CMD_LINK_QUALITY		 78=0A=
 #define IWN_CMD_SET_LED			 72=0A=
 #define IWN5000_CMD_WIMAX_COEX		 90=0A=
-#define IWN5000_CMD_CALIB_CONFIG	101=0A=
+#define IWN_TEMP_NOTIFICATION		98=0A=
+#define IWN5000_CMD_CALIB_CONFIG	101 // CALIBRATION_CFG_CMD=0A=
 #define IWN5000_CMD_CALIB_RESULT	102=0A=
 #define IWN5000_CMD_CALIB_COMPLETE	103=0A=
 #define IWN_CMD_SET_POWER_MODE		119=0A=
@@ -436,9 +787,20 @@=0A=
 #define IWN_CMD_GET_STATISTICS		156=0A=
 #define IWN_CMD_SET_CRITICAL_TEMP	164=0A=
 #define IWN_CMD_SET_SENSITIVITY		168=0A=
-#define IWN_CMD_PHY_CALIB		176=0A=
+#define IWN_CMD_PHY_CALIB		    176=0A=
 #define IWN_CMD_BT_COEX_PRIOTABLE	204=0A=
 #define IWN_CMD_BT_COEX_PROT		205=0A=
+#define IWN_CMD_BT_COEX_NOTIF		206=0A=
+/* PAN commands */=0A=
+#define IWN_CMD_WIPAN_PARAMS			0xb2=0A=
+#define IWN_CMD_WIPAN_RXON			0xb3=0A=
+#define IWN_CMD_WIPAN_RXON_TIMING		0xb4=0A=
+#define IWN_CMD_WIPAN_RXON_ASSOC		0xb6=0A=
+#define IWN_CMD_WIPAN_QOS_PARAM			0xb7=0A=
+#define IWN_CMD_WIPAN_WEPKEY			0xb8=0A=
+#define IWN_CMD_WIPAN_P2P_CHANNEL_SWITCH	0xb9=0A=
+#define IWN_CMD_WIPAN_NOA_NOTIFICATION		0xbc=0A=
+#define IWN_CMD_WIPAN_DEACTIVATION_COMPLETE	0xbd=0A=
 =0A=
 	uint8_t	flags;=0A=
 	uint8_t	idx;=0A=
@@ -446,6 +808,28 @@=0A=
 	uint8_t	data[136];=0A=
 } __packed;=0A=
 =0A=
+/*=0A=
+ * Structure for IWN_CMD_GET_STATISTICS =3D (0x9c) 156=0A=
+ * all devices identical.=0A=
+ *=0A=
+ * This command triggers an immediate response containing uCode =
statistics.=0A=
+ * The response is in the same format as IWN_BEACON_STATISTICS (0x9d) =
157.=0A=
+ *=0A=
+ * If the CLEAR_STATS configuration flag is set, uCode will clear its=0A=
+ * internal copy of the statistics (counters) after issuing the =
response.=0A=
+ * This flag does not affect IWN_BEACON_STATISTICS after beacons (see =
below).=0A=
+ *=0A=
+ * If the DISABLE_NOTIF configuration flag is set, uCode will not issue=0A=
+ * IWN_BEACON_STATISTICS after received beacons.  This flag=0A=
+ * does not affect the response to the IWN_CMD_GET_STATISTICS 0x9c =
itself.=0A=
+ */=0A=
+struct iwn_statistics_cmd {=0A=
+	uint32_t configuration_flags;	/* IWN_STATS_CONF_* */=0A=
+#define IWN_STATS_CONF_CLEAR_STATS htole32(0x1)	=0A=
+#define IWN_STATS_CONF_DISABLE_NOTIF htole32(0x2)=0A=
+=0A=
+} __packed;=0A=
+=0A=
 /* Antenna flags, used in various commands. */=0A=
 #define IWN_ANT_A	(1 << 0)=0A=
 #define IWN_ANT_B	(1 << 1)=0A=
@@ -452,6 +836,7 @@=0A=
 #define IWN_ANT_C	(1 << 2)=0A=
 /* Shortcuts. */=0A=
 #define IWN_ANT_AB	(IWN_ANT_A | IWN_ANT_B)=0A=
+#define IWN_ANT_AC	(IWN_ANT_A | IWN_ANT_C)=0A=
 #define IWN_ANT_BC	(IWN_ANT_B | IWN_ANT_C)=0A=
 #define IWN_ANT_ABC	(IWN_ANT_A | IWN_ANT_B | IWN_ANT_C)=0A=
 =0A=
@@ -468,6 +853,8 @@=0A=
 #define IWN_MODE_STA		3=0A=
 #define IWN_MODE_IBSS		4=0A=
 #define IWN_MODE_MONITOR	6=0A=
+#define IWN_MODE_2STA		8=0A=
+#define IWN_MODE_P2P		9=0A=
 =0A=
 	uint8_t		air;=0A=
 	uint16_t	rxchain;=0A=
@@ -551,7 +938,8 @@=0A=
 	uint16_t	atim;=0A=
 	uint32_t	binitval;=0A=
 	uint16_t	lintval;=0A=
-	uint16_t	reserved;=0A=
+	uint8_t		dtim_period;=0A=
+	uint8_t		delta_cp_bss_tbtts;=0A=
 } __packed;=0A=
 =0A=
 /* Structure for command IWN_CMD_ADD_NODE. */=0A=
@@ -565,6 +953,11 @@=0A=
 	uint16_t	reserved2;=0A=
 	uint8_t		id;=0A=
 #define IWN_ID_BSS		 0=0A=
+#define IWN_STA_ID			1=0A=
+=0A=
+#define	IWN_PAN_BCAST_ID		14=0A=
+#define	IWN_BROADCAST_ID		15=0A=
+=0A=
 #define IWN5000_ID_BROADCAST	15=0A=
 #define IWN4965_ID_BROADCAST	31=0A=
 =0A=
@@ -766,7 +1159,13 @@=0A=
 #define IWN_PS_SLEEP_OVER_DTIM	(1 << 2)=0A=
 #define IWN_PS_PCI_PMGT		(1 << 3)=0A=
 #define IWN_PS_FAST_PD		(1 << 4)=0A=
+#define IWN_PS_BEACON_FILTERING	(1 << 5)=0A=
+#define IWN_PS_SHADOW_REG	(1 << 6)=0A=
+#define IWN_PS_CT_KILL		(1 << 7)=0A=
+#define IWN_PS_BT_SCD		(1 << 8)=0A=
+#define IWN_PS_ADVANCED_PM	(1 << 9)=0A=
 =0A=
+=0A=
 	uint8_t		keepalive;=0A=
 	uint8_t		debug;=0A=
 	uint32_t	rxtimeout;=0A=
@@ -803,6 +1202,7 @@=0A=
 =0A=
 struct iwn_scan_chan {=0A=
 	uint32_t	flags;=0A=
+#define IWN_CHAN_PASSIVE	(0 << 0)=0A=
 #define IWN_CHAN_ACTIVE		(1 << 0)=0A=
 #define IWN_CHAN_NPBREQS(x)	(((1 << (x)) - 1) << 1)=0A=
 =0A=
@@ -813,9 +1213,26 @@=0A=
 	uint16_t	passive;	/* msecs */=0A=
 } __packed;=0A=
 =0A=
+#define	IWN_SCAN_CRC_TH_DISABLED	0=0A=
+#define	IWN_SCAN_CRC_TH_DEFAULT		htole16(1)=0A=
+#define	IWN_SCAN_CRC_TH_NEVER		htole16(0xffff)=0A=
+=0A=
+=0A=
 /* Maximum size of a scan command. */=0A=
 #define IWN_SCAN_MAXSZ	(MCLBYTES - 4)=0A=
 =0A=
+#define IWN_ACTIVE_DWELL_TIME_24	(30)	/* all times in msec */=0A=
+#define IWN_ACTIVE_DWELL_TIME_52	(20)=0A=
+#define IWN_ACTIVE_DWELL_FACTOR_24	(3)=0A=
+#define IWN_ACTIVE_DWELL_FACTOR_52	(2)=0A=
+=0A=
+#define IWN_PASSIVE_DWELL_TIME_24	(20)	/* all times in msec */=0A=
+#define IWN_PASSIVE_DWELL_TIME_52	(10)=0A=
+#define IWN_PASSIVE_DWELL_BASE		(100)=0A=
+#define IWN_CHANNEL_TUNE_TIME		(5)=0A=
+=0A=
+#define IWN_SCAN_CHAN_TIMEOUT		2=0A=
+=0A=
 /* Structure for command IWN_CMD_TXPOWER (4965AGN only.) */=0A=
 #define IWN_RIDX_MAX	32=0A=
 struct iwn4965_cmd_txpower {=0A=
@@ -860,8 +1277,20 @@=0A=
 	uint32_t	kill_cts;=0A=
 } __packed;=0A=
 =0A=
+/* Structures for enhanced command IWN_CMD_BLUETOOTH. */=0A=
 struct iwn6000_btcoex_config {=0A=
 	uint8_t		flags;=0A=
+#define IWN_BT_FLAG_COEX6000_CHAN_INHIBITION	1=0A=
+#define IWN_BT_FLAG_COEX6000_MODE_MASK			( (1 << 3) | (1 << 4) | (1 <<5 =
))=0A=
+#define IWN_BT_FLAG_COEX6000_MODE_SHIFT			3=0A=
+#define IWN_BT_FLAG_COEX6000_MODE_DISABLED		0=0A=
+#define IWN_BT_FLAG_COEX6000_MODE_LEGACY_2W		1=0A=
+#define IWN_BT_FLAG_COEX6000_MODE_3W			2=0A=
+#define IWN_BT_FLAG_COEX6000_MODE_4W			3=0A=
+=0A=
+#define IWN_BT_FLAG_UCODE_DEFAULT		(1 << 6)=0A=
+/* Disable Sync PSPoll on SCO/eSCO */=0A=
+#define IWN_BT_FLAG_SYNC_2_BT_DISABLE	(1 << 7)=0A=
 	uint8_t		lead_time;=0A=
 	uint8_t		max_kill;=0A=
 	uint8_t		bt3_t7_timer;=0A=
@@ -878,6 +1307,29 @@=0A=
 	uint16_t	rx_prio_boost;=0A=
 } __packed;=0A=
 =0A=
+/* Structures for enhanced command IWN_CMD_BLUETOOTH for 2000 Series. */=0A=
+struct iwn2000_btcoex_config {=0A=
+	uint8_t		flags; // Cf Flags in iwn6000_btcoex_config=0A=
+	uint8_t		lead_time;=0A=
+	uint8_t		max_kill;=0A=
+	uint8_t		bt3_t7_timer;=0A=
+	uint32_t	kill_ack;=0A=
+	uint32_t	kill_cts;=0A=
+	uint8_t		sample_time;=0A=
+	uint8_t		bt3_t2_timer;=0A=
+	uint16_t	bt4_reaction;=0A=
+	uint32_t	lookup_table[12];=0A=
+	uint16_t	bt4_decision;=0A=
+	uint16_t	valid;=0A=
+	=0A=
+	uint32_t	prio_boost; // size change prior to iwn6000_btcoex_config=0A=
+	uint8_t		reserved; // added prior to iwn6000_btcoex_config=0A=
+	=0A=
+	uint8_t		tx_prio_boost;=0A=
+	uint16_t	rx_prio_boost;=0A=
+} __packed;=0A=
+=0A=
+=0A=
 struct iwn_btcoex_priotable {=0A=
 	uint8_t		calib_init1;=0A=
 	uint8_t		calib_init2;=0A=
@@ -899,8 +1351,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=
@@ -955,6 +1407,10 @@=0A=
 	uint16_t	reserved;=0A=
 } __packed;=0A=
 =0A=
+/* Define maximal number of calib result send to runtime firmware =0A=
+PS: TEMP_OFFSET count for 2 (std and v2)=0A=
+*/=0A=
+#define IWN5000_PHY_CALIB_MAX_RESULT	8=0A=
 /* Structures for command IWN_CMD_PHY_CALIB. */=0A=
 struct iwn_phy_calib {=0A=
 	uint8_t	code;=0A=
@@ -962,7 +1418,7 @@=0A=
 #define IWN5000_PHY_CALIB_DC			 8=0A=
 #define IWN5000_PHY_CALIB_LO			 9=0A=
 #define IWN5000_PHY_CALIB_TX_IQ			11=0A=
-#define IWN5000_PHY_CALIB_CRYSTAL		15=0A=
+#define IWN5000_PHY_CALIB_CRYSTAL		15 //Linux =3D =
IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD=0A=
 #define IWN5000_PHY_CALIB_BASE_BAND		16=0A=
 #define IWN5000_PHY_CALIB_TX_IQ_PERIODIC	17=0A=
 #define IWN5000_PHY_CALIB_TEMP_OFFSET		18=0A=
@@ -975,6 +1431,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=
@@ -996,6 +1461,17 @@=0A=
 	uint16_t	reserved;=0A=
 } __packed;=0A=
 =0A=
+struct iwn5000_phy_calib_temp_offsetv2 {=0A=
+	uint8_t		code;=0A=
+	uint8_t		group;=0A=
+	uint8_t		ngroups;=0A=
+	uint8_t		isvalid;=0A=
+	int16_t 	offset_high;=0A=
+	int16_t		offset_low;=0A=
+	int16_t		burntVoltageRef;=0A=
+	int16_t		reserved;=0A=
+} __packed;=0A=
+=0A=
 struct iwn_phy_calib_gain {=0A=
 	uint8_t	code;=0A=
 	uint8_t	group;=0A=
@@ -1366,13 +1842,25 @@=0A=
 #define IWN_FW_TLV_INIT_DATA		4=0A=
 #define IWN_FW_TLV_BOOT_TEXT		5=0A=
 #define IWN_FW_TLV_PBREQ_MAXLEN		6=0A=
-#define IWN_FW_TLV_ENH_SENS		14=0A=
+#define IWN_FW_TLV_PAN				7=0A=
+#define	IWN_FW_TLV_RUNT_EVTLOG_PTR	8=0A=
+#define	IWN_FW_TLV_RUNT_EVTLOG_SIZE	9=0A=
+#define	IWN_FW_TLV_RUNT_ERRLOG_PTR	10=0A=
+#define	IWN_FW_TLV_INIT_EVTLOG_PTR	11=0A=
+#define	IWN_FW_TLV_INIT_EVTLOG_SIZE	12=0A=
+#define	IWN_FW_TLV_INIT_ERRLOG_PTR	13=0A=
+#define IWN_FW_TLV_ENH_SENS			14=0A=
 #define IWN_FW_TLV_PHY_CALIB		15=0A=
+#define	IWN_FW_TLV_WOWLAN_INST		16=0A=
+#define	IWN_FW_TLV_WOWLAN_DATA		17=0A=
+#define	IWN_FW_TLV_FLAGS			18=0A=
 =0A=
 	uint16_t	alt;=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=
@@ -1389,8 +1877,8 @@=0A=
 #define IWN_EEPROM_RFCFG	0x048=0A=
 #define IWN4965_EEPROM_DOMAIN	0x060=0A=
 #define IWN4965_EEPROM_BAND1	0x063=0A=
-#define IWN5000_EEPROM_REG	0x066=0A=
-#define IWN5000_EEPROM_CAL	0x067=0A=
+#define IWN5000_EEPROM_REG		0x066=0A=
+#define IWN5000_EEPROM_CAL		0x067=0A=
 #define IWN4965_EEPROM_BAND2	0x072=0A=
 #define IWN4965_EEPROM_BAND3	0x080=0A=
 #define IWN4965_EEPROM_BAND4	0x08d=0A=
@@ -1402,18 +1890,10 @@=0A=
 #define IWN4965_EEPROM_BANDS	0x0ea=0A=
 /* Indirect offsets. */=0A=
 #define IWN5000_EEPROM_DOMAIN	0x001=0A=
-#define IWN5000_EEPROM_BAND1	0x004=0A=
-#define IWN5000_EEPROM_BAND2	0x013=0A=
-#define IWN5000_EEPROM_BAND3	0x021=0A=
-#define IWN5000_EEPROM_BAND4	0x02e=0A=
-#define IWN5000_EEPROM_BAND5	0x03a=0A=
-#define IWN5000_EEPROM_BAND6	0x041=0A=
-#define IWN6000_EEPROM_BAND6	0x040=0A=
-#define IWN5000_EEPROM_BAND7	0x049=0A=
 #define IWN6000_EEPROM_ENHINFO	0x054=0A=
-#define IWN5000_EEPROM_CRYSTAL	0x128=0A=
-#define IWN5000_EEPROM_TEMP	0x12a=0A=
-#define IWN5000_EEPROM_VOLT	0x12b=0A=
+#define IWN5000_EEPROM_CRYSTAL	0x128 //XTAL in linux 3.2=0A=
+#define IWN5000_EEPROM_TEMP		0x12a //KELVIN_TEMPERATURE in linux 3.2=0A=
+#define IWN5000_EEPROM_VOLT		0x12b //RAW_TEMPERATURE  in linux 3.2=0A=
 =0A=
 /* Possible flags for IWN_EEPROM_SKU_CAP. */=0A=
 #define IWN_EEPROM_SKU_CAP_11N	(1 << 6)=0A=
@@ -1479,9 +1959,29 @@=0A=
 	struct	iwn4965_eeprom_chan_samples chans[2];=0A=
 } __packed;=0A=
 =0A=
+/* ADD / MODIFY STATION Command (Op Code 18) -  byte 76-18 -bit13=0A=
+	STA_FLAG_PAN_STATION bit:=0A=
+	This bit is set (1) for a station in PAN mode */=0A=
+#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=
+=0A=
 /*=0A=
  * Offsets of channels descriptions in EEPROM.=0A=
  */=0A=
+#define IWN5000_EEPROM_NO_HT40	0x000 //EEPROM_REGULATORY_BAND_NO_HT40=0A=
+#define IWN5000_EEPROM_BAND1	0x004 //EEPROM_REG_BAND_1_CHANNELS=0A=
+#define IWN5000_EEPROM_BAND2	0x013 //EEPROM_REG_BAND_2_CHANNELS=0A=
+#define IWN5000_EEPROM_BAND3	0x021 //EEPROM_REG_BAND_3_CHANNELS=0A=
+#define IWN5000_EEPROM_BAND4	0x02e //EEPROM_REG_BAND_4_CHANNELS=0A=
+#define IWN5000_EEPROM_BAND5	0x03a //EEPROM_REG_BAND_5_CHANNELS=0A=
+#define IWN5000_EEPROM_BAND6	0x041 //EEPROM_REG_BAND_24_HT40_CHANNELS=0A=
+#define IWN6000_EEPROM_BAND6	0x040 =
//EEPROM_6000_REG_BAND_24_HT40_CHANNELS=0A=
+#define IWN5000_EEPROM_BAND7	0x049 //EEPROM_REG_BAND_52_HT40_CHANNELS=0A=
+=0A=
 static const uint32_t iwn4965_regulatory_bands[IWN_NBANDS] =3D {=0A=
 	IWN4965_EEPROM_BAND1,=0A=
 	IWN4965_EEPROM_BAND2,=0A=
@@ -1489,7 +1989,7 @@=0A=
 	IWN4965_EEPROM_BAND4,=0A=
 	IWN4965_EEPROM_BAND5,=0A=
 	IWN4965_EEPROM_BAND6,=0A=
-	IWN4965_EEPROM_BAND7=0A=
+	IWN4965_EEPROM_BAND7 // Should be IWN5000_EEPRON_NO_HT40=0A=
 };=0A=
 =0A=
 static const uint32_t iwn5000_regulatory_bands[IWN_NBANDS] =3D {=0A=
@@ -1512,6 +2012,16 @@=0A=
 	IWN5000_EEPROM_BAND7=0A=
 };=0A=
 =0A=
+static const uint32_t iwn1000_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=
+	IWN5000_EEPROM_BAND6,=0A=
+	IWN5000_EEPROM_NO_HT40,=0A=
+};=0A=
+=0A=
 #define IWN_CHAN_BANDS_COUNT	 7=0A=
 #define IWN_MAX_CHAN_PER_BAND	14=0A=
 static const struct iwn_chan_band {=0A=
@@ -1531,6 +2041,20 @@=0A=
 	{ 11, { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 } }=0A=
 };=0A=
 =0A=
+static const uint8_t iwn_bss_ac_to_queue[] =3D {=0A=
+	2, 3, 1, 0,=0A=
+};=0A=
+=0A=
+static const uint8_t iwn_pan_ac_to_queue[] =3D {=0A=
+	5, 4, 6, 7,=0A=
+};=0A=
+=0A=
+=0A=
+/* OTP */=0A=
+/* lower blocks contain EEPROM image and calibration data */=0A=
+#define OTP_LOW_IMAGE_SIZE		(2 * 512 * sizeof(int)) /* 2 KB */=0A=
+=0A=
+=0A=
 #define IWN1000_OTP_NBLOCKS	3 =0A=
 #define IWN6000_OTP_NBLOCKS	4 =0A=
 #define IWN6050_OTP_NBLOCKS	7=0A=
@@ -1541,7 +2065,33 @@=0A=
 =0A=
 #define IWN4965_MAX_PWR_INDEX	107=0A=
 =0A=
+#define IWN_POWERSAVE_LVL_NONE 			0=0A=
+#define IWN_POWERSAVE_LVL_VOIP_COMPATIBLE 	1=0A=
+#define IWN_POWERSAVE_LVL_MAX 			5=0A=
+=0A=
+#define IWN_POWERSAVE_LVL_DEFAULT IWN_POWERSAVE_LVL_NONE=0A=
+=0A=
+/* DTIM value to pass in for IWN_POWERSAVE_LVL_VOIP_COMPATIBLE */=0A=
+#define IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE 2=0A=
+=0A=
+=0A=
 /*=0A=
+ * If IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP is defined, then power =
saving=0A=
+ * (including the power saving done for unicast traffic) becomes =
proportional=0A=
+ * to the DTIM period received from the AP. Otherwise the constant DTIM=0A=
+ * period IWN_POWERSAVE_DTIM_VOIP_COMPATIBLE is used.=0A=
+ *=0A=
+ * Per the 802.11 spec DTIM value as applicable to power saving seems =
to be=0A=
+ * relevant only for indicating the frequency at which =
broadcast/multicast=0A=
+ * data is sent to the PS STAs.=0A=
+ * However in practice some APs may also send the unicast traffic along =
with=0A=
+ * the DTIM.=0A=
+ */=0A=
+#define IWN_DTIM_INDICATES_UNICAST_PENDING_AT_AP=0A=
+=0A=
+=0A=
+=0A=
+/*=0A=
  * RF Tx gain values from highest to lowest power (values obtained from=0A=
  * the reference driver.)=0A=
  */=0A=
@@ -1657,6 +2207,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=
@@ -1671,7 +2222,8 @@=0A=
 	200, 400,=0A=
 	 97,=0A=
 	100,=0A=
-	100=0A=
+	100,=0A=
+	390=0A=
 };=0A=
 =0A=
 static const struct iwn_sensitivity_limits iwn5000_sensitivity_limits =
=3D {=0A=
@@ -1683,7 +2235,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=
@@ -1695,7 +2248,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=
@@ -1707,10 +2261,23 @@=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=
+/*min_ofdm_x1;  // auto_corr_min_ofdm_x1 , max_ofdm_x1; =
//auto_corr_max_ofdm_x1=0A=
+min_ofdm_mrc_x1; //auto_corr_min_ofdm_mrc_x1, max_ofdm_mrc_x1; =
//auto_corr_max_ofdm_mrc=0A=
+min_ofdm_x4; //auto_corr_min_ofdm, max_ofdm_x4; //auto_corr_max_ofdm =0A=
+min_ofdm_mrc_x4; //auto_corr_min_ofdm_mrc, max_ofdm_mrc_x4 =
//max_ofdm_mrc_x4=0A=
+min_cck_x4; //auto_corr_min_cck, max_cck_x4:auto_corr_max_cck=0A=
+min_cck_mrc_x4 : auto_corr_min_cck_mrc max_cck_mrc_x4: =
auto_corr_max_cck_mrc=0A=
+min_energy_cck: min_nrg_cck=0A=
+energy_cck:nrg_th_cck=0A=
+energy_ofdm:nrg_th_ofdm=0A=
+corr_barker_mrc :barker_corr_th_min_mrc=0A=
+*/=0A=
+ /* Define several specific values for Intel 6000 series */=0A=
+ static const struct iwn_sensitivity_limits iwn6000_sensitivity_limits =
=3D {=0A=
 	105, 110,=0A=
 	192, 232,=0A=
 	 80, 145,=0A=
@@ -1717,11 +2284,13 @@=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=
+=0A=
 /* Map TID to TX scheduler's FIFO. */=0A=
 static const uint8_t iwn_tid2fifo[] =3D {=0A=
 	1, 0, 0, 1, 2, 2, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 3=0A=
@@ -1805,3 +2374,364 @@=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=
+		=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=
+ /* Get value from linux kernel 3.2.+ in =
Drivers/net/wireless/iwlwifi/iwl-2000.c*/=0A=
+static const struct iwn_sensitivity_limits iwn2030_sensitivity_limits =
=3D {=0A=
+    105,110,=0A=
+    128,232,=0A=
+	80,145,=0A=
+	128,232,=0A=
+	125,175,=0A=
+	160,310,=0A=
+	97,=0A=
+	97,=0A=
+	110=0A=
+};		=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=3D=
=3D=3D=0A=
+ *                                  NIC PARAMETERS=0A=
+ *=0A=
+ * =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=0A=
+ */=0A=
+ =0A=
+/* Flags for managing calibration result. See calib_need in =
iwn_base_params struct */=0A=
+#define IWN_FLG_NEED_PHY_CALIB_DC				(1<<0)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_LO				(1<<1)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_TX_IQ			(1<<2)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_CRYSTAL			(1<<3)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_BASE_BAND		(1<<4)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_TX_IQ_PERIODIC	(1<<5)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET		(1<<6)=0A=
+#define IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSETv2	(1<<7)=0A=
+=0A=
+		=0A=
+/* Define some parameters for managing different NIC.=0A=
+ * Refer to linux specific file like iwl-xxxx.c to determine correct =
value for NIC=0A=
+ *=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 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' =
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 =
calibration data ucode need. See calib_init_cfg in iwl-xxxx.c linux =
kernel file=0A=
+ * additional_gp_drv_bit : Specific bit to defined during nic_config=0A=
+ */=0A=
+struct iwn_base_params {=0A=
+	uint32_t pll_cfg_val;=0A=
+	const uint16_t max_ll_items;=0A=
+#define IWN_OTP_MAX_LL_ITEMS_1000		(3)	/* OTP blocks for 1000 */=0A=
+#define IWN_OTP_MAX_LL_ITEMS_6x00		(4)	/* OTP blocks for 6x00 */=0A=
+#define IWN_OTP_MAX_LL_ITEMS_6x50		(7)	/* OTP blocks for 6x50 */=0A=
+#define IWN_OTP_MAX_LL_ITEMS_2x00		(4)	/* OTP blocks for 2x00 */=0A=
+	const bool shadow_ram_support;=0A=
+	uint16_t led_compensation;=0A=
+	bool adv_thermal_throttle;=0A=
+	bool support_ct_kill_exit;=0A=
+	uint8_t plcp_delta_threshold;=0A=
+	int chain_noise_scale;=0A=
+	unsigned int wd_timeout;=0A=
+	uint32_t max_event_log_size;=0A=
+	const bool shadow_reg_enable;=0A=
+	const bool hd_v2;=0A=
+	const bool advanced_bt_coexist;=0A=
+	const bool bt_session_2;=0A=
+	const bool bt_sco_disable;=0A=
+	const bool additional_nic_config;=0A=
+	const uint32_t *regulatory_bands;=0A=
+	const bool enhanced_TX_power; // See iwl-agn-devices.c file to =
determine that(enhanced_txpower). =0A=
+	const uint16_t calib_need;=0A=
+	const bool no_crystal_calibration; // see no_xtal_calib in linux=0A=
+	const bool support_hostap; //Define IEEE80211_C_HOSTAP for ic_caps=0A=
+	const bool no_multi_vaps; // see iwn_vap_create=0A=
+	uint8_t additional_gp_drv_bit; //=0A=
+	=0A=
+};=0A=
+=0A=
+/* NOTA : Values with comments BEFORE are not yet used in driver */=0A=
+static struct iwn_base_params iwn_default_base_params =3D {=0A=
+	IWN_ANA_PLL_INIT, // pll_cfg_val=0A=
+	4,  //max_ll_items=0A=
+	true, // shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, // bt_session_2=0A=
+	true, // bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn5000_regulatory_bands, //regulatory_bands=0A=
+	false, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, // no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+=0A=
+static struct iwn_base_params iwn2030_base_params =3D {=0A=
+	 0, //pll_cfg_val=0A=
+	 IWN_OTP_MAX_LL_ITEMS_2x00, //max_ll_items=0A=
+	 true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */ 57,=0A=
+	/*.adv_thermal_throttle =3D */ true,=0A=
+	/*.support_ct_kill_exit =3D */ true,=0A=
+	/*.plcp_delta_threshold =3D */ 50,=0A=
+	/*.chain_noise_scale =3D */ 1000,=0A=
+	/*.wd_timeout =3D */ 2000,=0A=
+	/*.max_event_log_size =3D */ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */ true,=0A=
+	true, //advanced_bt_coexist=0A=
+	true, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn2030_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND | =
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=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, //advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	false, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn5000_regulatory_bands, //regulatory_bands=0A=
+	false, //enhanced_TX_power=0A=
+	( IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6000_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x00, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	false, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6000i_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x00, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6000g2_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x00, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | =
IWN_FLG_NEED_PHY_CALIB_BASE_BAND|IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6050_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x50, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	true, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | =
IWN_FLG_NEED_PHY_CALIB_BASE_BAND|IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_6150_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x50, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	true, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | =
IWN_FLG_NEED_PHY_CALIB_BASE_BAND|IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	IWN_GP_DRIVER_6050_1X2, //additional_gp_drv_bit=0A=
+};=0A=
+//IWL_DEVICE_6035 & IWL_DEVICE_6030=0A=
+static struct iwn_base_params iwn_6000g2b_base_params =3D {=0A=
+	0, //pll_cfg_val=0A=
+	IWN_OTP_MAX_LL_ITEMS_6x00, // max_ll_items=0A=
+	true, //shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	true, // advanced_bt_coexist=0A=
+	false, //bt_session_2=0A=
+	true, //bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn6000_regulatory_bands, //regulatory_bands=0A=
+	true, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | =
IWN_FLG_NEED_PHY_CALIB_BASE_BAND|IWN_FLG_NEED_PHY_CALIB_TEMP_OFFSET ), =
//calib_need=0A=
+	false, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, //no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+static struct iwn_base_params iwn_5x50_base_params =3D {=0A=
+	IWN_ANA_PLL_INIT, // pll_cfg_val=0A=
+	4,  //max_ll_items=0A=
+	true, // shadow_ram_support=0A=
+	/*.led_compensation =3D */57,=0A=
+	/*.adv_thermal_throttle =3D*/ true,=0A=
+	/*.support_ct_kill_exit =3D */true,=0A=
+	/*.plcp_delta_threshold =3D*/ 50, /*IWL_MAX_PLCP_ERR_THRESHOLD_DEF,*/=0A=
+	/*.chain_noise_scale =3D*/ 1000,=0A=
+	/*.wd_timeout =3D */2000, /* IWL_LONG_WD_TIMEOUT,*/=0A=
+	/*.max_event_log_size =3D*/ 512,=0A=
+	false, //shadow_reg_enable=0A=
+	/*.hd_v2 =3D */true,=0A=
+	false, // advanced_bt_coexist=0A=
+	false, // bt_session_2=0A=
+	true, // bt_sco_disable=0A=
+	false, //additional_nic_config=0A=
+	iwn5000_regulatory_bands, //regulatory_bands=0A=
+	false, //enhanced_TX_power=0A=
+	(IWN_FLG_NEED_PHY_CALIB_DC | IWN_FLG_NEED_PHY_CALIB_LO | =
IWN_FLG_NEED_PHY_CALIB_TX_IQ | IWN_FLG_NEED_PHY_CALIB_BASE_BAND ), =
//calib_need=0A=
+	true, //no_crystal_calibration=0A=
+	false, //support_hostap=0A=
+	true, // no_multi_vaps=0A=
+	0, //additional_gp_drv_bit=0A=
+};=0A=
+=0A=
Index: sys/dev/iwn/if_iwnvar.h=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/dev/iwn/if_iwnvar.h	(revision 253707)=0A=
+++ sys/dev/iwn/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 <lenine@bsdfrance.fr>=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,42 @@=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=
+=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=
+=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=
+ =0A=
 struct iwn_rx_radiotap_header {=0A=
 	struct ieee80211_radiotap_header wr_ihdr;=0A=
 	uint64_t	wr_tsft;=0A=
@@ -140,6 +177,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 +231,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=
@@ -203,15 +247,18 @@=0A=
 	struct mtx		sc_mtx;=0A=
 =0A=
 	u_int			sc_flags;=0A=
-#define IWN_FLAG_HAS_OTPROM	(1 << 1)=0A=
-#define IWN_FLAG_CALIB_DONE	(1 << 2)=0A=
-#define IWN_FLAG_USE_ICT	(1 << 3)=0A=
+#define IWN_FLAG_HAS_OTPROM		(1 << 1)=0A=
+#define IWN_FLAG_CALIB_DONE		(1 << 2)=0A=
+#define IWN_FLAG_USE_ICT		(1 << 3)=0A=
 #define IWN_FLAG_INTERNAL_PA	(1 << 4)=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_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 +319,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 +347,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 +364,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 +379,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=
@@ -335,3 +404,5 @@=0A=
 #define IWN_LOCK_ASSERT(_sc)		mtx_assert(&(_sc)->sc_mtx, MA_OWNED)=0A=
 #define IWN_UNLOCK(_sc)			mtx_unlock(&(_sc)->sc_mtx)=0A=
 #define IWN_LOCK_DESTROY(_sc)		mtx_destroy(&(_sc)->sc_mtx)=0A=
+#define IWN_UC_PAN_PRESENT		1=0A=
+=0A=
Index: sys/modules/iwn/Makefile=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/modules/iwn/Makefile	(revision 253707)=0A=
+++ sys/modules/iwn/Makefile	(working copy)=0A=
@@ -5,4 +5,12 @@=0A=
 KMOD    =3D if_iwn=0A=
 SRCS    =3D if_iwn.c device_if.h bus_if.h pci_if.h=0A=
 =0A=
+.if !defined(KERNBUILDDIR)=0A=
+opt_wlan.h:=0A=
+	echo "#define IEEE80211_DEBUG 1" > ${.TARGET}=0A=
+.endif=0A=
+.if IWN_DEBUG=0A=
+CFLAGS+=3D-DIWN_DEBUG=0A=
+.endif=0A=
+=0A=
 .include <bsd.kmod.mk>=0A=
Index: sys/modules/iwnfw/Makefile=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/modules/iwnfw/Makefile	(revision 253707)=0A=
+++ sys/modules/iwnfw/Makefile	(working copy)=0A=
@@ -1,5 +1,5 @@=0A=
 # $FreeBSD$=0A=
 =0A=
-SUBDIR=3D	iwn1000 iwn4965 iwn5000 iwn5150 iwn6000 iwn6000g2a iwn6000g2b =
iwn6050=0A=
+SUBDIR=3D	iwn1000 iwn4965 iwn5000 iwn5150 iwn6000 iwn6000g2a iwn6000g2b =
iwn6050 iwn2030=0A=
 =0A=
 .include <bsd.subdir.mk>=0A=
Index: sys/modules/iwnfw/iwn2030/Makefile=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
--- sys/modules/iwnfw/iwn2030/Makefile	(revision 0)=0A=
+++ sys/modules/iwnfw/iwn2030/Makefile	(working copy)=0A=
@@ -0,0 +1,6 @@=0A=
+# $FreeBSD$=0A=
+=0A=
+KMOD=3D	iwn2030fw=0A=
+IMG=3D	iwnwifi-2030-18.168.6.1=0A=
+=0A=
+.include <bsd.kmod.mk>=0A=

------=_NextPart_000_0004_01CE8B7F.8F536DC0--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000301ce8b6e$cbca9dc0$635fd940$>