aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2009-04-25 19:36:46 -0400
committerDavid S. Miller <davem@davemloft.net>2009-04-25 19:36:46 -0400
commit495a1b4eff1a216a3ea171ac137f1807e6555f52 (patch)
tree72d059d6d66fac6a74df33bac2eb40dcd0ea0732 /drivers/net
parentad8affd972a705a38e769859c50ee8e749b631da (diff)
parentd3feaf5ad12259927039a675cfb25dc342b403ab (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6
Conflicts: net/mac80211/pm.c
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/usb/hso.c4
-rw-r--r--drivers/net/wireless/Kconfig16
-rw-r--r--drivers/net/wireless/Makefile4
-rw-r--r--drivers/net/wireless/at76c50x-usb.c1
-rw-r--r--drivers/net/wireless/ath/Kconfig8
-rw-r--r--drivers/net/wireless/ath/Makefile6
-rw-r--r--drivers/net/wireless/ath/ar9170/Kconfig (renamed from drivers/net/wireless/ar9170/Kconfig)1
-rw-r--r--drivers/net/wireless/ath/ar9170/Makefile (renamed from drivers/net/wireless/ar9170/Makefile)0
-rw-r--r--drivers/net/wireless/ath/ar9170/ar9170.h (renamed from drivers/net/wireless/ar9170/ar9170.h)32
-rw-r--r--drivers/net/wireless/ath/ar9170/cmd.c (renamed from drivers/net/wireless/ar9170/cmd.c)0
-rw-r--r--drivers/net/wireless/ath/ar9170/cmd.h (renamed from drivers/net/wireless/ar9170/cmd.h)0
-rw-r--r--drivers/net/wireless/ath/ar9170/eeprom.h (renamed from drivers/net/wireless/ar9170/eeprom.h)0
-rw-r--r--drivers/net/wireless/ath/ar9170/hw.h (renamed from drivers/net/wireless/ar9170/hw.h)15
-rw-r--r--drivers/net/wireless/ath/ar9170/led.c (renamed from drivers/net/wireless/ar9170/led.c)0
-rw-r--r--drivers/net/wireless/ath/ar9170/mac.c (renamed from drivers/net/wireless/ar9170/mac.c)0
-rw-r--r--drivers/net/wireless/ath/ar9170/main.c (renamed from drivers/net/wireless/ar9170/main.c)613
-rw-r--r--drivers/net/wireless/ath/ar9170/phy.c (renamed from drivers/net/wireless/ar9170/phy.c)0
-rw-r--r--drivers/net/wireless/ath/ar9170/usb.c (renamed from drivers/net/wireless/ar9170/usb.c)0
-rw-r--r--drivers/net/wireless/ath/ar9170/usb.h (renamed from drivers/net/wireless/ar9170/usb.h)2
-rw-r--r--drivers/net/wireless/ath/ath5k/Kconfig (renamed from drivers/net/wireless/ath5k/Kconfig)1
-rw-r--r--drivers/net/wireless/ath/ath5k/Makefile (renamed from drivers/net/wireless/ath5k/Makefile)0
-rw-r--r--drivers/net/wireless/ath/ath5k/ath5k.h (renamed from drivers/net/wireless/ath5k/ath5k.h)5
-rw-r--r--drivers/net/wireless/ath/ath5k/attach.c (renamed from drivers/net/wireless/ath5k/attach.c)0
-rw-r--r--drivers/net/wireless/ath/ath5k/base.c (renamed from drivers/net/wireless/ath5k/base.c)74
-rw-r--r--drivers/net/wireless/ath/ath5k/base.h (renamed from drivers/net/wireless/ath5k/base.h)1
-rw-r--r--drivers/net/wireless/ath/ath5k/caps.c (renamed from drivers/net/wireless/ath5k/caps.c)0
-rw-r--r--drivers/net/wireless/ath/ath5k/debug.c (renamed from drivers/net/wireless/ath5k/debug.c)0
-rw-r--r--drivers/net/wireless/ath/ath5k/debug.h (renamed from drivers/net/wireless/ath5k/debug.h)0
-rw-r--r--drivers/net/wireless/ath/ath5k/desc.c (renamed from drivers/net/wireless/ath5k/desc.c)0
-rw-r--r--drivers/net/wireless/ath/ath5k/desc.h (renamed from drivers/net/wireless/ath5k/desc.h)0
-rw-r--r--drivers/net/wireless/ath/ath5k/dma.c (renamed from drivers/net/wireless/ath5k/dma.c)2
-rw-r--r--drivers/net/wireless/ath/ath5k/eeprom.c (renamed from drivers/net/wireless/ath5k/eeprom.c)0
-rw-r--r--drivers/net/wireless/ath/ath5k/eeprom.h (renamed from drivers/net/wireless/ath5k/eeprom.h)0
-rw-r--r--drivers/net/wireless/ath/ath5k/gpio.c (renamed from drivers/net/wireless/ath5k/gpio.c)0
-rw-r--r--drivers/net/wireless/ath/ath5k/initvals.c (renamed from drivers/net/wireless/ath5k/initvals.c)8
-rw-r--r--drivers/net/wireless/ath/ath5k/led.c (renamed from drivers/net/wireless/ath5k/led.c)4
-rw-r--r--drivers/net/wireless/ath/ath5k/pcu.c (renamed from drivers/net/wireless/ath5k/pcu.c)0
-rw-r--r--drivers/net/wireless/ath/ath5k/phy.c (renamed from drivers/net/wireless/ath5k/phy.c)49
-rw-r--r--drivers/net/wireless/ath/ath5k/qcu.c (renamed from drivers/net/wireless/ath5k/qcu.c)0
-rw-r--r--drivers/net/wireless/ath/ath5k/reg.h (renamed from drivers/net/wireless/ath5k/reg.h)0
-rw-r--r--drivers/net/wireless/ath/ath5k/reset.c (renamed from drivers/net/wireless/ath5k/reset.c)2
-rw-r--r--drivers/net/wireless/ath/ath5k/rfbuffer.h (renamed from drivers/net/wireless/ath5k/rfbuffer.h)0
-rw-r--r--drivers/net/wireless/ath/ath5k/rfgain.h (renamed from drivers/net/wireless/ath5k/rfgain.h)0
-rw-r--r--drivers/net/wireless/ath/ath9k/Kconfig (renamed from drivers/net/wireless/ath9k/Kconfig)1
-rw-r--r--drivers/net/wireless/ath/ath9k/Makefile (renamed from drivers/net/wireless/ath9k/Makefile)1
-rw-r--r--drivers/net/wireless/ath/ath9k/ahb.c (renamed from drivers/net/wireless/ath9k/ahb.c)0
-rw-r--r--drivers/net/wireless/ath/ath9k/ani.c (renamed from drivers/net/wireless/ath9k/ani.c)8
-rw-r--r--drivers/net/wireless/ath/ath9k/ani.h (renamed from drivers/net/wireless/ath9k/ani.h)0
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h (renamed from drivers/net/wireless/ath9k/ath9k.h)65
-rw-r--r--drivers/net/wireless/ath/ath9k/beacon.c (renamed from drivers/net/wireless/ath9k/beacon.c)17
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c (renamed from drivers/net/wireless/ath9k/calib.c)123
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.h (renamed from drivers/net/wireless/ath9k/calib.h)33
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c (renamed from drivers/net/wireless/ath9k/debug.c)3
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.h (renamed from drivers/net/wireless/ath9k/debug.h)24
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom.c (renamed from drivers/net/wireless/ath9k/eeprom.c)24
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom.h (renamed from drivers/net/wireless/ath9k/eeprom.h)2
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c (renamed from drivers/net/wireless/ath9k/hw.c)179
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h (renamed from drivers/net/wireless/ath9k/hw.h)90
-rw-r--r--drivers/net/wireless/ath/ath9k/initvals.h (renamed from drivers/net/wireless/ath9k/initvals.h)0
-rw-r--r--drivers/net/wireless/ath/ath9k/mac.c (renamed from drivers/net/wireless/ath9k/mac.c)63
-rw-r--r--drivers/net/wireless/ath/ath9k/mac.h (renamed from drivers/net/wireless/ath9k/mac.h)0
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c (renamed from drivers/net/wireless/ath9k/main.c)374
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c (renamed from drivers/net/wireless/ath9k/pci.c)0
-rw-r--r--drivers/net/wireless/ath/ath9k/phy.c (renamed from drivers/net/wireless/ath9k/phy.c)4
-rw-r--r--drivers/net/wireless/ath/ath9k/phy.h (renamed from drivers/net/wireless/ath9k/phy.h)3
-rw-r--r--drivers/net/wireless/ath/ath9k/rc.c (renamed from drivers/net/wireless/ath9k/rc.c)26
-rw-r--r--drivers/net/wireless/ath/ath9k/rc.h (renamed from drivers/net/wireless/ath9k/rc.h)4
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c (renamed from drivers/net/wireless/ath9k/recv.c)85
-rw-r--r--drivers/net/wireless/ath/ath9k/reg.h (renamed from drivers/net/wireless/ath9k/reg.h)0
-rw-r--r--drivers/net/wireless/ath/ath9k/virtual.c (renamed from drivers/net/wireless/ath9k/virtual.c)0
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c (renamed from drivers/net/wireless/ath9k/xmit.c)64
-rw-r--r--drivers/net/wireless/ath/main.c22
-rw-r--r--drivers/net/wireless/ath/regd.c (renamed from drivers/net/wireless/ath9k/regd.c)241
-rw-r--r--drivers/net/wireless/ath/regd.h (renamed from drivers/net/wireless/ath9k/regd.h)40
-rw-r--r--drivers/net/wireless/ath/regd_common.h (renamed from drivers/net/wireless/ath9k/regd_common.h)0
-rw-r--r--drivers/net/wireless/b43/Kconfig8
-rw-r--r--drivers/net/wireless/b43/b43.h8
-rw-r--r--drivers/net/wireless/b43/main.c69
-rw-r--r--drivers/net/wireless/b43/rfkill.c1
-rw-r--r--drivers/net/wireless/b43legacy/Kconfig8
-rw-r--r--drivers/net/wireless/b43legacy/b43legacy.h8
-rw-r--r--drivers/net/wireless/b43legacy/main.c193
-rw-r--r--drivers/net/wireless/b43legacy/rfkill.c1
-rw-r--r--drivers/net/wireless/b43legacy/xmit.c2
-rw-r--r--drivers/net/wireless/b43legacy/xmit.h4
-rw-r--r--drivers/net/wireless/hostap/hostap_plx.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c206
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c17
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c410
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.h25
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c791
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c751
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h59
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c96
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h23
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rfkill.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c196
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c25
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c1017
-rw-r--r--drivers/net/wireless/libertas/cmd.c26
-rw-r--r--drivers/net/wireless/libertas/defs.h21
-rw-r--r--drivers/net/wireless/libertas/dev.h1
-rw-r--r--drivers/net/wireless/libertas/host.h3
-rw-r--r--drivers/net/wireless/libertas/hostcmd.h28
-rw-r--r--drivers/net/wireless/libertas/if_cs.c34
-rw-r--r--drivers/net/wireless/libertas/if_sdio.c17
-rw-r--r--drivers/net/wireless/libertas/if_sdio.h2
-rw-r--r--drivers/net/wireless/libertas/if_spi.c6
-rw-r--r--drivers/net/wireless/libertas/main.c44
-rw-r--r--drivers/net/wireless/libertas/rx.c48
-rw-r--r--drivers/net/wireless/libertas/tx.c8
-rw-r--r--drivers/net/wireless/libertas/types.h2
-rw-r--r--drivers/net/wireless/p54/p54.h78
-rw-r--r--drivers/net/wireless/p54/p54common.c216
-rw-r--r--drivers/net/wireless/p54/p54spi.c127
-rw-r--r--drivers/net/wireless/rndis_wlan.c666
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h18
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00link.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00pci.c16
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c7
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.h6
-rw-r--r--drivers/net/wireless/rtl818x/Makefile2
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187.h7
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187_dev.c21
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187_leds.c218
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187_leds.h57
136 files changed, 4335 insertions, 3664 deletions
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index f84b78d94c4..d696e5fbc17 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -2484,7 +2484,7 @@ static int add_net_device(struct hso_device *hso_dev)
2484static int hso_radio_toggle(void *data, enum rfkill_state state) 2484static int hso_radio_toggle(void *data, enum rfkill_state state)
2485{ 2485{
2486 struct hso_device *hso_dev = data; 2486 struct hso_device *hso_dev = data;
2487 int enabled = (state == RFKILL_STATE_ON); 2487 int enabled = (state == RFKILL_STATE_UNBLOCKED);
2488 int rv; 2488 int rv;
2489 2489
2490 mutex_lock(&hso_dev->mutex); 2490 mutex_lock(&hso_dev->mutex);
@@ -2522,7 +2522,7 @@ static void hso_create_rfkill(struct hso_device *hso_dev,
2522 snprintf(rfkn, 20, "hso-%d", 2522 snprintf(rfkn, 20, "hso-%d",
2523 interface->altsetting->desc.bInterfaceNumber); 2523 interface->altsetting->desc.bInterfaceNumber);
2524 hso_net->rfkill->name = rfkn; 2524 hso_net->rfkill->name = rfkn;
2525 hso_net->rfkill->state = RFKILL_STATE_ON; 2525 hso_net->rfkill->state = RFKILL_STATE_UNBLOCKED;
2526 hso_net->rfkill->data = hso_dev; 2526 hso_net->rfkill->data = hso_dev;
2527 hso_net->rfkill->toggle_radio = hso_radio_toggle; 2527 hso_net->rfkill->toggle_radio = hso_radio_toggle;
2528 if (rfkill_register(hso_net->rfkill) < 0) { 2528 if (rfkill_register(hso_net->rfkill) < 0) {
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 8a0823588c5..2d8434f409b 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -146,10 +146,10 @@ config LIBERTAS_CS
146 A driver for Marvell Libertas 8385 CompactFlash devices. 146 A driver for Marvell Libertas 8385 CompactFlash devices.
147 147
148config LIBERTAS_SDIO 148config LIBERTAS_SDIO
149 tristate "Marvell Libertas 8385 and 8686 SDIO 802.11b/g cards" 149 tristate "Marvell Libertas 8385/8686/8688 SDIO 802.11b/g cards"
150 depends on LIBERTAS && MMC 150 depends on LIBERTAS && MMC
151 ---help--- 151 ---help---
152 A driver for Marvell Libertas 8385 and 8686 SDIO devices. 152 A driver for Marvell Libertas 8385/8686/8688 SDIO devices.
153 153
154config LIBERTAS_SPI 154config LIBERTAS_SPI
155 tristate "Marvell Libertas 8686 SPI 802.11b/g cards" 155 tristate "Marvell Libertas 8686 SPI 802.11b/g cards"
@@ -337,6 +337,7 @@ config USB_NET_RNDIS_WLAN
337 select USB_NET_CDCETHER 337 select USB_NET_CDCETHER
338 select USB_NET_RNDIS_HOST 338 select USB_NET_RNDIS_HOST
339 select WIRELESS_EXT 339 select WIRELESS_EXT
340 select CFG80211
340 ---help--- 341 ---help---
341 This is a driver for wireless RNDIS devices. 342 This is a driver for wireless RNDIS devices.
342 These are USB based adapters found in devices such as: 343 These are USB based adapters found in devices such as:
@@ -433,6 +434,13 @@ config RTL8187
433 434
434 Thanks to Realtek for their support! 435 Thanks to Realtek for their support!
435 436
437# If possible, automatically enable LEDs for RTL8187.
438
439config RTL8187_LEDS
440 bool
441 depends on RTL8187 && MAC80211_LEDS && (LEDS_CLASS = y || LEDS_CLASS = RTL8187)
442 default y
443
436config ADM8211 444config ADM8211
437 tristate "ADMtek ADM8211 support" 445 tristate "ADMtek ADM8211 support"
438 depends on MAC80211 && PCI && WLAN_80211 && EXPERIMENTAL 446 depends on MAC80211 && PCI && WLAN_80211 && EXPERIMENTAL
@@ -483,9 +491,7 @@ config MWL8K
483 will be called mwl8k. If unsure, say N. 491 will be called mwl8k. If unsure, say N.
484 492
485source "drivers/net/wireless/p54/Kconfig" 493source "drivers/net/wireless/p54/Kconfig"
486source "drivers/net/wireless/ath5k/Kconfig" 494source "drivers/net/wireless/ath/Kconfig"
487source "drivers/net/wireless/ath9k/Kconfig"
488source "drivers/net/wireless/ar9170/Kconfig"
489source "drivers/net/wireless/ipw2x00/Kconfig" 495source "drivers/net/wireless/ipw2x00/Kconfig"
490source "drivers/net/wireless/iwlwifi/Kconfig" 496source "drivers/net/wireless/iwlwifi/Kconfig"
491source "drivers/net/wireless/hostap/Kconfig" 497source "drivers/net/wireless/hostap/Kconfig"
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 50e7fba7f0e..0625e91b599 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -55,8 +55,6 @@ obj-$(CONFIG_RT2X00) += rt2x00/
55 55
56obj-$(CONFIG_P54_COMMON) += p54/ 56obj-$(CONFIG_P54_COMMON) += p54/
57 57
58obj-$(CONFIG_ATH5K) += ath5k/ 58obj-$(CONFIG_ATH_COMMON) += ath/
59obj-$(CONFIG_ATH9K) += ath9k/
60obj-$(CONFIG_AR9170_USB) += ar9170/
61 59
62obj-$(CONFIG_MAC80211_HWSIM) += mac80211_hwsim.o 60obj-$(CONFIG_MAC80211_HWSIM) += mac80211_hwsim.o
diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
index 69248ded510..55f947ac56d 100644
--- a/drivers/net/wireless/at76c50x-usb.c
+++ b/drivers/net/wireless/at76c50x-usb.c
@@ -2250,6 +2250,7 @@ static int at76_init_new_device(struct at76_priv *priv,
2250 2250
2251 /* mac80211 initialisation */ 2251 /* mac80211 initialisation */
2252 priv->hw->wiphy->max_scan_ssids = 1; 2252 priv->hw->wiphy->max_scan_ssids = 1;
2253 priv->hw->wiphy->max_scan_ie_len = 0;
2253 priv->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); 2254 priv->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
2254 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &at76_supported_band; 2255 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &at76_supported_band;
2255 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS | 2256 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
diff --git a/drivers/net/wireless/ath/Kconfig b/drivers/net/wireless/ath/Kconfig
new file mode 100644
index 00000000000..d26e7b48531
--- /dev/null
+++ b/drivers/net/wireless/ath/Kconfig
@@ -0,0 +1,8 @@
1config ATH_COMMON
2 tristate "Atheros Wireless Cards"
3 depends on ATH5K || ATH9K || AR9170_USB
4
5source "drivers/net/wireless/ath/ath5k/Kconfig"
6source "drivers/net/wireless/ath/ath9k/Kconfig"
7source "drivers/net/wireless/ath/ar9170/Kconfig"
8
diff --git a/drivers/net/wireless/ath/Makefile b/drivers/net/wireless/ath/Makefile
new file mode 100644
index 00000000000..4bb0132ada3
--- /dev/null
+++ b/drivers/net/wireless/ath/Makefile
@@ -0,0 +1,6 @@
1obj-$(CONFIG_ATH5K) += ath5k/
2obj-$(CONFIG_ATH9K) += ath9k/
3obj-$(CONFIG_AR9170_USB) += ar9170/
4
5obj-$(CONFIG_ATH_COMMON) += ath.o
6ath-objs := main.o regd.o
diff --git a/drivers/net/wireless/ar9170/Kconfig b/drivers/net/wireless/ath/ar9170/Kconfig
index de4281fda12..b99e3263ee6 100644
--- a/drivers/net/wireless/ar9170/Kconfig
+++ b/drivers/net/wireless/ath/ar9170/Kconfig
@@ -2,6 +2,7 @@ config AR9170_USB
2 tristate "Atheros AR9170 802.11n USB support" 2 tristate "Atheros AR9170 802.11n USB support"
3 depends on USB && MAC80211 && WLAN_80211 && EXPERIMENTAL 3 depends on USB && MAC80211 && WLAN_80211 && EXPERIMENTAL
4 select FW_LOADER 4 select FW_LOADER
5 select ATH_COMMON
5 help 6 help
6 This is a driver for the Atheros "otus" 802.11n USB devices. 7 This is a driver for the Atheros "otus" 802.11n USB devices.
7 8
diff --git a/drivers/net/wireless/ar9170/Makefile b/drivers/net/wireless/ath/ar9170/Makefile
index 8d91c7ee321..8d91c7ee321 100644
--- a/drivers/net/wireless/ar9170/Makefile
+++ b/drivers/net/wireless/ath/ar9170/Makefile
diff --git a/drivers/net/wireless/ar9170/ar9170.h b/drivers/net/wireless/ath/ar9170/ar9170.h
index f4fb2e94aea..17bd3eaf3e0 100644
--- a/drivers/net/wireless/ar9170/ar9170.h
+++ b/drivers/net/wireless/ath/ar9170/ar9170.h
@@ -40,7 +40,7 @@
40 40
41#include <linux/completion.h> 41#include <linux/completion.h>
42#include <linux/spinlock.h> 42#include <linux/spinlock.h>
43#include <net/wireless.h> 43#include <net/cfg80211.h>
44#include <net/mac80211.h> 44#include <net/mac80211.h>
45#ifdef CONFIG_AR9170_LEDS 45#ifdef CONFIG_AR9170_LEDS
46#include <linux/leds.h> 46#include <linux/leds.h>
@@ -48,6 +48,8 @@
48#include "eeprom.h" 48#include "eeprom.h"
49#include "hw.h" 49#include "hw.h"
50 50
51#include "../regd.h"
52
51#define PAYLOAD_MAX (AR9170_MAX_CMD_LEN/4 - 1) 53#define PAYLOAD_MAX (AR9170_MAX_CMD_LEN/4 - 1)
52 54
53enum ar9170_bw { 55enum ar9170_bw {
@@ -58,6 +60,21 @@ enum ar9170_bw {
58 __AR9170_NUM_BW, 60 __AR9170_NUM_BW,
59}; 61};
60 62
63static inline enum ar9170_bw nl80211_to_ar9170(enum nl80211_channel_type type)
64{
65 switch (type) {
66 case NL80211_CHAN_NO_HT:
67 case NL80211_CHAN_HT20:
68 return AR9170_BW_20;
69 case NL80211_CHAN_HT40MINUS:
70 return AR9170_BW_40_BELOW;
71 case NL80211_CHAN_HT40PLUS:
72 return AR9170_BW_40_ABOVE;
73 default:
74 BUG();
75 }
76}
77
61enum ar9170_rf_init_mode { 78enum ar9170_rf_init_mode {
62 AR9170_RFI_NONE, 79 AR9170_RFI_NONE,
63 AR9170_RFI_WARM, 80 AR9170_RFI_WARM,
@@ -87,10 +104,16 @@ enum ar9170_device_state {
87 AR9170_ASSOCIATED, 104 AR9170_ASSOCIATED,
88}; 105};
89 106
107struct ar9170_rxstream_mpdu_merge {
108 struct ar9170_rx_head plcp;
109 bool has_plcp;
110};
111
90struct ar9170 { 112struct ar9170 {
91 struct ieee80211_hw *hw; 113 struct ieee80211_hw *hw;
92 struct mutex mutex; 114 struct mutex mutex;
93 enum ar9170_device_state state; 115 enum ar9170_device_state state;
116 unsigned long bad_hw_nagger;
94 117
95 int (*open)(struct ar9170 *); 118 int (*open)(struct ar9170 *);
96 void (*stop)(struct ar9170 *); 119 void (*stop)(struct ar9170 *);
@@ -118,6 +141,7 @@ struct ar9170 {
118 u64 cur_mc_hash, want_mc_hash; 141 u64 cur_mc_hash, want_mc_hash;
119 u32 cur_filter, want_filter; 142 u32 cur_filter, want_filter;
120 unsigned int filter_changed; 143 unsigned int filter_changed;
144 unsigned int filter_state;
121 bool sniffer_enabled; 145 bool sniffer_enabled;
122 146
123 /* PHY */ 147 /* PHY */
@@ -151,11 +175,17 @@ struct ar9170 {
151 175
152 /* EEPROM */ 176 /* EEPROM */
153 struct ar9170_eeprom eeprom; 177 struct ar9170_eeprom eeprom;
178 struct ath_regulatory regulatory;
154 179
155 /* global tx status for unregistered Stations. */ 180 /* global tx status for unregistered Stations. */
156 struct sk_buff_head global_tx_status; 181 struct sk_buff_head global_tx_status;
157 struct sk_buff_head global_tx_status_waste; 182 struct sk_buff_head global_tx_status_waste;
158 struct delayed_work tx_status_janitor; 183 struct delayed_work tx_status_janitor;
184
185 /* rxstream mpdu merge */
186 struct ar9170_rxstream_mpdu_merge rx_mpdu;
187 struct sk_buff *rx_failover;
188 int rx_failover_missing;
159}; 189};
160 190
161struct ar9170_sta_info { 191struct ar9170_sta_info {
diff --git a/drivers/net/wireless/ar9170/cmd.c b/drivers/net/wireless/ath/ar9170/cmd.c
index f57a6200167..f57a6200167 100644
--- a/drivers/net/wireless/ar9170/cmd.c
+++ b/drivers/net/wireless/ath/ar9170/cmd.c
diff --git a/drivers/net/wireless/ar9170/cmd.h b/drivers/net/wireless/ath/ar9170/cmd.h
index a4f0e50e52b..a4f0e50e52b 100644
--- a/drivers/net/wireless/ar9170/cmd.h
+++ b/drivers/net/wireless/ath/ar9170/cmd.h
diff --git a/drivers/net/wireless/ar9170/eeprom.h b/drivers/net/wireless/ath/ar9170/eeprom.h
index d2c8cc83f1d..d2c8cc83f1d 100644
--- a/drivers/net/wireless/ar9170/eeprom.h
+++ b/drivers/net/wireless/ath/ar9170/eeprom.h
diff --git a/drivers/net/wireless/ar9170/hw.h b/drivers/net/wireless/ath/ar9170/hw.h
index 53e250a4278..95bf812d6fc 100644
--- a/drivers/net/wireless/ar9170/hw.h
+++ b/drivers/net/wireless/ath/ar9170/hw.h
@@ -312,7 +312,7 @@ struct ar9170_rx_head {
312 u8 plcp[12]; 312 u8 plcp[12];
313} __packed; 313} __packed;
314 314
315struct ar9170_rx_tail { 315struct ar9170_rx_phystatus {
316 union { 316 union {
317 struct { 317 struct {
318 u8 rssi_ant0, rssi_ant1, rssi_ant2, 318 u8 rssi_ant0, rssi_ant1, rssi_ant2,
@@ -324,6 +324,9 @@ struct ar9170_rx_tail {
324 324
325 u8 evm_stream0[6], evm_stream1[6]; 325 u8 evm_stream0[6], evm_stream1[6];
326 u8 phy_err; 326 u8 phy_err;
327} __packed;
328
329struct ar9170_rx_macstatus {
327 u8 SAidx, DAidx; 330 u8 SAidx, DAidx;
328 u8 error; 331 u8 error;
329 u8 status; 332 u8 status;
@@ -339,7 +342,7 @@ struct ar9170_rx_tail {
339 342
340#define AR9170_RX_ENC_SOFTWARE 0x8 343#define AR9170_RX_ENC_SOFTWARE 0x8
341 344
342static inline u8 ar9170_get_decrypt_type(struct ar9170_rx_tail *t) 345static inline u8 ar9170_get_decrypt_type(struct ar9170_rx_macstatus *t)
343{ 346{
344 return (t->SAidx & 0xc0) >> 4 | 347 return (t->SAidx & 0xc0) >> 4 |
345 (t->DAidx & 0xc0) >> 6; 348 (t->DAidx & 0xc0) >> 6;
@@ -357,10 +360,9 @@ static inline u8 ar9170_get_decrypt_type(struct ar9170_rx_tail *t)
357 360
358#define AR9170_RX_STATUS_MPDU_MASK 0x30 361#define AR9170_RX_STATUS_MPDU_MASK 0x30
359#define AR9170_RX_STATUS_MPDU_SINGLE 0x00 362#define AR9170_RX_STATUS_MPDU_SINGLE 0x00
360#define AR9170_RX_STATUS_MPDU_FIRST 0x10 363#define AR9170_RX_STATUS_MPDU_FIRST 0x20
361#define AR9170_RX_STATUS_MPDU_MIDDLE 0x20 364#define AR9170_RX_STATUS_MPDU_MIDDLE 0x30
362#define AR9170_RX_STATUS_MPDU_LAST 0x30 365#define AR9170_RX_STATUS_MPDU_LAST 0x10
363
364 366
365#define AR9170_RX_ERROR_RXTO 0x01 367#define AR9170_RX_ERROR_RXTO 0x01
366#define AR9170_RX_ERROR_OVERRUN 0x02 368#define AR9170_RX_ERROR_OVERRUN 0x02
@@ -369,6 +371,7 @@ static inline u8 ar9170_get_decrypt_type(struct ar9170_rx_tail *t)
369#define AR9170_RX_ERROR_WRONG_RA 0x10 371#define AR9170_RX_ERROR_WRONG_RA 0x10
370#define AR9170_RX_ERROR_PLCP 0x20 372#define AR9170_RX_ERROR_PLCP 0x20
371#define AR9170_RX_ERROR_MMIC 0x40 373#define AR9170_RX_ERROR_MMIC 0x40
374#define AR9170_RX_ERROR_FATAL 0x80
372 375
373struct ar9170_cmd_tx_status { 376struct ar9170_cmd_tx_status {
374 __le16 unkn; 377 __le16 unkn;
diff --git a/drivers/net/wireless/ar9170/led.c b/drivers/net/wireless/ath/ar9170/led.c
index 341cead7f60..341cead7f60 100644
--- a/drivers/net/wireless/ar9170/led.c
+++ b/drivers/net/wireless/ath/ar9170/led.c
diff --git a/drivers/net/wireless/ar9170/mac.c b/drivers/net/wireless/ath/ar9170/mac.c
index c8fa3073169..c8fa3073169 100644
--- a/drivers/net/wireless/ar9170/mac.c
+++ b/drivers/net/wireless/ath/ar9170/mac.c
diff --git a/drivers/net/wireless/ar9170/main.c b/drivers/net/wireless/ath/ar9170/main.c
index 5996ff9f7f4..1b60906b80c 100644
--- a/drivers/net/wireless/ar9170/main.c
+++ b/drivers/net/wireless/ath/ar9170/main.c
@@ -142,11 +142,36 @@ static struct ieee80211_channel ar9170_5ghz_chantable[] = {
142}; 142};
143#undef CHAN 143#undef CHAN
144 144
145#define AR9170_HT_CAP \
146{ \
147 .ht_supported = true, \
148 .cap = IEEE80211_HT_CAP_MAX_AMSDU | \
149 IEEE80211_HT_CAP_SM_PS | \
150 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
151 IEEE80211_HT_CAP_SGI_40 | \
152 IEEE80211_HT_CAP_DSSSCCK40 | \
153 IEEE80211_HT_CAP_SM_PS, \
154 .ampdu_factor = 3, /* ?? */ \
155 .ampdu_density = 7, /* ?? */ \
156 .mcs = { \
157 .rx_mask = { 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, }, \
158 }, \
159}
160
145static struct ieee80211_supported_band ar9170_band_2GHz = { 161static struct ieee80211_supported_band ar9170_band_2GHz = {
146 .channels = ar9170_2ghz_chantable, 162 .channels = ar9170_2ghz_chantable,
147 .n_channels = ARRAY_SIZE(ar9170_2ghz_chantable), 163 .n_channels = ARRAY_SIZE(ar9170_2ghz_chantable),
148 .bitrates = ar9170_g_ratetable, 164 .bitrates = ar9170_g_ratetable,
149 .n_bitrates = ar9170_g_ratetable_size, 165 .n_bitrates = ar9170_g_ratetable_size,
166 .ht_cap = AR9170_HT_CAP,
167};
168
169static struct ieee80211_supported_band ar9170_band_5GHz = {
170 .channels = ar9170_5ghz_chantable,
171 .n_channels = ARRAY_SIZE(ar9170_5ghz_chantable),
172 .bitrates = ar9170_a_ratetable,
173 .n_bitrates = ar9170_a_ratetable_size,
174 .ht_cap = AR9170_HT_CAP,
150}; 175};
151 176
152#ifdef AR9170_QUEUE_DEBUG 177#ifdef AR9170_QUEUE_DEBUG
@@ -190,13 +215,6 @@ static void ar9170_dump_station_tx_status_queue(struct ar9170 *ar,
190} 215}
191#endif /* AR9170_QUEUE_DEBUG */ 216#endif /* AR9170_QUEUE_DEBUG */
192 217
193static struct ieee80211_supported_band ar9170_band_5GHz = {
194 .channels = ar9170_5ghz_chantable,
195 .n_channels = ARRAY_SIZE(ar9170_5ghz_chantable),
196 .bitrates = ar9170_a_ratetable,
197 .n_bitrates = ar9170_a_ratetable_size,
198};
199
200void ar9170_handle_tx_status(struct ar9170 *ar, struct sk_buff *skb, 218void ar9170_handle_tx_status(struct ar9170 *ar, struct sk_buff *skb,
201 bool valid_status, u16 tx_status) 219 bool valid_status, u16 tx_status)
202{ 220{
@@ -436,214 +454,430 @@ static void ar9170_handle_command_response(struct ar9170 *ar,
436 } 454 }
437} 455}
438 456
439/* 457static void ar9170_rx_reset_rx_mpdu(struct ar9170 *ar)
440 * If the frame alignment is right (or the kernel has
441 * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there
442 * is only a single MPDU in the USB frame, then we can
443 * submit to mac80211 the SKB directly. However, since
444 * there may be multiple packets in one SKB in stream
445 * mode, and we need to observe the proper ordering,
446 * this is non-trivial.
447 */
448static void ar9170_handle_mpdu(struct ar9170 *ar, u8 *buf, int len)
449{ 458{
450 struct sk_buff *skb; 459 memset(&ar->rx_mpdu.plcp, 0, sizeof(struct ar9170_rx_head));
451 struct ar9170_rx_head *head = (void *)buf; 460 ar->rx_mpdu.has_plcp = false;
452 struct ar9170_rx_tail *tail; 461}
453 struct ieee80211_rx_status status;
454 int mpdu_len, i;
455 u8 error, antennas = 0, decrypt;
456 __le16 fc;
457 int reserved;
458 462
459 if (unlikely(!IS_STARTED(ar))) 463static int ar9170_nag_limiter(struct ar9170 *ar)
460 return ; 464{
465 bool print_message;
466
467 /*
468 * we expect all sorts of errors in promiscuous mode.
469 * don't bother with it, it's OK!
470 */
471 if (ar->sniffer_enabled)
472 return false;
473
474 /*
475 * only go for frequent errors! The hardware tends to
476 * do some stupid thing once in a while under load, in
477 * noisy environments or just for fun!
478 */
479 if (time_before(jiffies, ar->bad_hw_nagger) && net_ratelimit())
480 print_message = true;
481 else
482 print_message = false;
483
484 /* reset threshold for "once in a while" */
485 ar->bad_hw_nagger = jiffies + HZ / 4;
486 return print_message;
487}
488
489static int ar9170_rx_mac_status(struct ar9170 *ar,
490 struct ar9170_rx_head *head,
491 struct ar9170_rx_macstatus *mac,
492 struct ieee80211_rx_status *status)
493{
494 u8 error, decrypt;
461 495
462 /* Received MPDU */
463 mpdu_len = len;
464 mpdu_len -= sizeof(struct ar9170_rx_head);
465 mpdu_len -= sizeof(struct ar9170_rx_tail);
466 BUILD_BUG_ON(sizeof(struct ar9170_rx_head) != 12); 496 BUILD_BUG_ON(sizeof(struct ar9170_rx_head) != 12);
467 BUILD_BUG_ON(sizeof(struct ar9170_rx_tail) != 24); 497 BUILD_BUG_ON(sizeof(struct ar9170_rx_macstatus) != 4);
468 498
469 if (mpdu_len <= FCS_LEN) 499 error = mac->error;
470 return; 500 if (error & AR9170_RX_ERROR_MMIC) {
501 status->flag |= RX_FLAG_MMIC_ERROR;
502 error &= ~AR9170_RX_ERROR_MMIC;
503 }
471 504
472 tail = (void *)(buf + sizeof(struct ar9170_rx_head) + mpdu_len); 505 if (error & AR9170_RX_ERROR_PLCP) {
506 status->flag |= RX_FLAG_FAILED_PLCP_CRC;
507 error &= ~AR9170_RX_ERROR_PLCP;
473 508
474 for (i = 0; i < 3; i++) 509 if (!(ar->filter_state & FIF_PLCPFAIL))
475 if (tail->rssi[i] != 0x80) 510 return -EINVAL;
476 antennas |= BIT(i); 511 }
477 512
478 /* post-process RSSI */ 513 if (error & AR9170_RX_ERROR_FCS) {
479 for (i = 0; i < 7; i++) 514 status->flag |= RX_FLAG_FAILED_FCS_CRC;
480 if (tail->rssi[i] & 0x80) 515 error &= ~AR9170_RX_ERROR_FCS;
481 tail->rssi[i] = ((tail->rssi[i] & 0x7f) + 1) & 0x7f;
482 516
483 memset(&status, 0, sizeof(status)); 517 if (!(ar->filter_state & FIF_FCSFAIL))
518 return -EINVAL;
519 }
520
521 decrypt = ar9170_get_decrypt_type(mac);
522 if (!(decrypt & AR9170_RX_ENC_SOFTWARE) &&
523 decrypt != AR9170_ENC_ALG_NONE)
524 status->flag |= RX_FLAG_DECRYPTED;
484 525
485 status.band = ar->channel->band; 526 /* ignore wrong RA errors */
486 status.freq = ar->channel->center_freq; 527 error &= ~AR9170_RX_ERROR_WRONG_RA;
487 status.signal = ar->noise[0] + tail->rssi_combined; 528
488 status.noise = ar->noise[0]; 529 if (error & AR9170_RX_ERROR_DECRYPT) {
489 status.antenna = antennas; 530 error &= ~AR9170_RX_ERROR_DECRYPT;
531 /*
532 * Rx decryption is done in place,
533 * the original data is lost anyway.
534 */
535
536 return -EINVAL;
537 }
538
539 /* drop any other error frames */
540 if (unlikely(error)) {
541 /* TODO: update netdevice's RX dropped/errors statistics */
542
543 if (ar9170_nag_limiter(ar))
544 printk(KERN_DEBUG "%s: received frame with "
545 "suspicious error code (%#x).\n",
546 wiphy_name(ar->hw->wiphy), error);
547
548 return -EINVAL;
549 }
550
551 status->band = ar->channel->band;
552 status->freq = ar->channel->center_freq;
490 553
491 switch (tail->status & AR9170_RX_STATUS_MODULATION_MASK) { 554 switch (mac->status & AR9170_RX_STATUS_MODULATION_MASK) {
492 case AR9170_RX_STATUS_MODULATION_CCK: 555 case AR9170_RX_STATUS_MODULATION_CCK:
493 if (tail->status & AR9170_RX_STATUS_SHORT_PREAMBLE) 556 if (mac->status & AR9170_RX_STATUS_SHORT_PREAMBLE)
494 status.flag |= RX_FLAG_SHORTPRE; 557 status->flag |= RX_FLAG_SHORTPRE;
495 switch (head->plcp[0]) { 558 switch (head->plcp[0]) {
496 case 0x0a: 559 case 0x0a:
497 status.rate_idx = 0; 560 status->rate_idx = 0;
498 break; 561 break;
499 case 0x14: 562 case 0x14:
500 status.rate_idx = 1; 563 status->rate_idx = 1;
501 break; 564 break;
502 case 0x37: 565 case 0x37:
503 status.rate_idx = 2; 566 status->rate_idx = 2;
504 break; 567 break;
505 case 0x6e: 568 case 0x6e:
506 status.rate_idx = 3; 569 status->rate_idx = 3;
507 break; 570 break;
508 default: 571 default:
509 if ((!ar->sniffer_enabled) && (net_ratelimit())) 572 if (ar9170_nag_limiter(ar))
510 printk(KERN_ERR "%s: invalid plcp cck rate " 573 printk(KERN_ERR "%s: invalid plcp cck rate "
511 "(%x).\n", wiphy_name(ar->hw->wiphy), 574 "(%x).\n", wiphy_name(ar->hw->wiphy),
512 head->plcp[0]); 575 head->plcp[0]);
513 return; 576 return -EINVAL;
514 } 577 }
515 break; 578 break;
579
516 case AR9170_RX_STATUS_MODULATION_OFDM: 580 case AR9170_RX_STATUS_MODULATION_OFDM:
517 switch (head->plcp[0] & 0xF) { 581 switch (head->plcp[0] & 0xf) {
518 case 0xB: 582 case 0xb:
519 status.rate_idx = 0; 583 status->rate_idx = 0;
520 break; 584 break;
521 case 0xF: 585 case 0xf:
522 status.rate_idx = 1; 586 status->rate_idx = 1;
523 break; 587 break;
524 case 0xA: 588 case 0xa:
525 status.rate_idx = 2; 589 status->rate_idx = 2;
526 break; 590 break;
527 case 0xE: 591 case 0xe:
528 status.rate_idx = 3; 592 status->rate_idx = 3;
529 break; 593 break;
530 case 0x9: 594 case 0x9:
531 status.rate_idx = 4; 595 status->rate_idx = 4;
532 break; 596 break;
533 case 0xD: 597 case 0xd:
534 status.rate_idx = 5; 598 status->rate_idx = 5;
535 break; 599 break;
536 case 0x8: 600 case 0x8:
537 status.rate_idx = 6; 601 status->rate_idx = 6;
538 break; 602 break;
539 case 0xC: 603 case 0xc:
540 status.rate_idx = 7; 604 status->rate_idx = 7;
541 break; 605 break;
542 default: 606 default:
543 if ((!ar->sniffer_enabled) && (net_ratelimit())) 607 if (ar9170_nag_limiter(ar))
544 printk(KERN_ERR "%s: invalid plcp ofdm rate " 608 printk(KERN_ERR "%s: invalid plcp ofdm rate "
545 "(%x).\n", wiphy_name(ar->hw->wiphy), 609 "(%x).\n", wiphy_name(ar->hw->wiphy),
546 head->plcp[0]); 610 head->plcp[0]);
547 return; 611 return -EINVAL;
548 } 612 }
549 if (status.band == IEEE80211_BAND_2GHZ) 613 if (status->band == IEEE80211_BAND_2GHZ)
550 status.rate_idx += 4; 614 status->rate_idx += 4;
551 break; 615 break;
616
552 case AR9170_RX_STATUS_MODULATION_HT: 617 case AR9170_RX_STATUS_MODULATION_HT:
618 if (head->plcp[3] & 0x80)
619 status->flag |= RX_FLAG_40MHZ;
620 if (head->plcp[6] & 0x80)
621 status->flag |= RX_FLAG_SHORT_GI;
622
623 status->rate_idx = clamp(0, 75, head->plcp[6] & 0x7f);
624 status->flag |= RX_FLAG_HT;
625 break;
626
553 case AR9170_RX_STATUS_MODULATION_DUPOFDM: 627 case AR9170_RX_STATUS_MODULATION_DUPOFDM:
554 /* XXX */ 628 /* XXX */
555 629 if (ar9170_nag_limiter(ar))
556 if (net_ratelimit())
557 printk(KERN_ERR "%s: invalid modulation\n", 630 printk(KERN_ERR "%s: invalid modulation\n",
558 wiphy_name(ar->hw->wiphy)); 631 wiphy_name(ar->hw->wiphy));
559 return; 632 return -EINVAL;
560 } 633 }
561 634
562 error = tail->error; 635 return 0;
636}
563 637
564 if (error & AR9170_RX_ERROR_MMIC) { 638static void ar9170_rx_phy_status(struct ar9170 *ar,
565 status.flag |= RX_FLAG_MMIC_ERROR; 639 struct ar9170_rx_phystatus *phy,
566 error &= ~AR9170_RX_ERROR_MMIC; 640 struct ieee80211_rx_status *status)
567 } 641{
642 int i;
568 643
569 if (error & AR9170_RX_ERROR_PLCP) { 644 BUILD_BUG_ON(sizeof(struct ar9170_rx_phystatus) != 20);
570 status.flag |= RX_FLAG_FAILED_PLCP_CRC; 645
571 error &= ~AR9170_RX_ERROR_PLCP; 646 for (i = 0; i < 3; i++)
647 if (phy->rssi[i] != 0x80)
648 status->antenna |= BIT(i);
649
650 /* post-process RSSI */
651 for (i = 0; i < 7; i++)
652 if (phy->rssi[i] & 0x80)
653 phy->rssi[i] = ((phy->rssi[i] & 0x7f) + 1) & 0x7f;
654
655 /* TODO: we could do something with phy_errors */
656 status->signal = ar->noise[0] + phy->rssi_combined;
657 status->noise = ar->noise[0];
658}
659
660static struct sk_buff *ar9170_rx_copy_data(u8 *buf, int len)
661{
662 struct sk_buff *skb;
663 int reserved = 0;
664 struct ieee80211_hdr *hdr = (void *) buf;
665
666 if (ieee80211_is_data_qos(hdr->frame_control)) {
667 u8 *qc = ieee80211_get_qos_ctl(hdr);
668 reserved += NET_IP_ALIGN;
669
670 if (*qc & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
671 reserved += NET_IP_ALIGN;
572 } 672 }
573 673
574 if (error & AR9170_RX_ERROR_FCS) { 674 if (ieee80211_has_a4(hdr->frame_control))
575 status.flag |= RX_FLAG_FAILED_FCS_CRC; 675 reserved += NET_IP_ALIGN;
576 error &= ~AR9170_RX_ERROR_FCS; 676
677 reserved = 32 + (reserved & NET_IP_ALIGN);
678
679 skb = dev_alloc_skb(len + reserved);
680 if (likely(skb)) {
681 skb_reserve(skb, reserved);
682 memcpy(skb_put(skb, len), buf, len);
577 } 683 }
578 684
579 decrypt = ar9170_get_decrypt_type(tail); 685 return skb;
580 if (!(decrypt & AR9170_RX_ENC_SOFTWARE) && 686}
581 decrypt != AR9170_ENC_ALG_NONE)
582 status.flag |= RX_FLAG_DECRYPTED;
583 687
584 /* ignore wrong RA errors */ 688/*
585 error &= ~AR9170_RX_ERROR_WRONG_RA; 689 * If the frame alignment is right (or the kernel has
690 * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there
691 * is only a single MPDU in the USB frame, then we could
692 * submit to mac80211 the SKB directly. However, since
693 * there may be multiple packets in one SKB in stream
694 * mode, and we need to observe the proper ordering,
695 * this is non-trivial.
696 */
586 697
587 if (error & AR9170_RX_ERROR_DECRYPT) { 698static void ar9170_handle_mpdu(struct ar9170 *ar, u8 *buf, int len)
588 error &= ~AR9170_RX_ERROR_DECRYPT; 699{
700 struct ar9170_rx_head *head;
701 struct ar9170_rx_macstatus *mac;
702 struct ar9170_rx_phystatus *phy = NULL;
703 struct ieee80211_rx_status status;
704 struct sk_buff *skb;
705 int mpdu_len;
706
707 if (unlikely(!IS_STARTED(ar) || len < (sizeof(*mac))))
708 return ;
709
710 /* Received MPDU */
711 mpdu_len = len - sizeof(*mac);
712
713 mac = (void *)(buf + mpdu_len);
714 if (unlikely(mac->error & AR9170_RX_ERROR_FATAL)) {
715 /* this frame is too damaged and can't be used - drop it */
589 716
590 /*
591 * Rx decryption is done in place,
592 * the original data is lost anyway.
593 */
594 return ; 717 return ;
595 } 718 }
596 719
597 /* drop any other error frames */ 720 switch (mac->status & AR9170_RX_STATUS_MPDU_MASK) {
598 if ((error) && (net_ratelimit())) { 721 case AR9170_RX_STATUS_MPDU_FIRST:
599 printk(KERN_DEBUG "%s: errors: %#x\n", 722 /* first mpdu packet has the plcp header */
600 wiphy_name(ar->hw->wiphy), error); 723 if (likely(mpdu_len >= sizeof(struct ar9170_rx_head))) {
601 return; 724 head = (void *) buf;
725 memcpy(&ar->rx_mpdu.plcp, (void *) buf,
726 sizeof(struct ar9170_rx_head));
727
728 mpdu_len -= sizeof(struct ar9170_rx_head);
729 buf += sizeof(struct ar9170_rx_head);
730 ar->rx_mpdu.has_plcp = true;
731 } else {
732 if (ar9170_nag_limiter(ar))
733 printk(KERN_ERR "%s: plcp info is clipped.\n",
734 wiphy_name(ar->hw->wiphy));
735 return ;
736 }
737 break;
738
739 case AR9170_RX_STATUS_MPDU_LAST:
740 /* last mpdu has a extra tail with phy status information */
741
742 if (likely(mpdu_len >= sizeof(struct ar9170_rx_phystatus))) {
743 mpdu_len -= sizeof(struct ar9170_rx_phystatus);
744 phy = (void *)(buf + mpdu_len);
745 } else {
746 if (ar9170_nag_limiter(ar))
747 printk(KERN_ERR "%s: frame tail is clipped.\n",
748 wiphy_name(ar->hw->wiphy));
749 return ;
750 }
751
752 case AR9170_RX_STATUS_MPDU_MIDDLE:
753 /* middle mpdus are just data */
754 if (unlikely(!ar->rx_mpdu.has_plcp)) {
755 if (!ar9170_nag_limiter(ar))
756 return ;
757
758 printk(KERN_ERR "%s: rx stream did not start "
759 "with a first_mpdu frame tag.\n",
760 wiphy_name(ar->hw->wiphy));
761
762 return ;
763 }
764
765 head = &ar->rx_mpdu.plcp;
766 break;
767
768 case AR9170_RX_STATUS_MPDU_SINGLE:
769 /* single mpdu - has plcp (head) and phy status (tail) */
770 head = (void *) buf;
771
772 mpdu_len -= sizeof(struct ar9170_rx_head);
773 mpdu_len -= sizeof(struct ar9170_rx_phystatus);
774
775 buf += sizeof(struct ar9170_rx_head);
776 phy = (void *)(buf + mpdu_len);
777 break;
778
779 default:
780 BUG_ON(1);
781 break;
602 } 782 }
603 783
604 buf += sizeof(struct ar9170_rx_head); 784 if (unlikely(mpdu_len < FCS_LEN))
605 fc = *(__le16 *)buf; 785 return ;
606 786
607 if (ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc)) 787 memset(&status, 0, sizeof(status));
608 reserved = 32 + 2; 788 if (unlikely(ar9170_rx_mac_status(ar, head, mac, &status)))
609 else 789 return ;
610 reserved = 32;
611 790
612 skb = dev_alloc_skb(mpdu_len + reserved); 791 if (phy)
613 if (!skb) 792 ar9170_rx_phy_status(ar, phy, &status);
614 return;
615 793
616 skb_reserve(skb, reserved); 794 skb = ar9170_rx_copy_data(buf, mpdu_len);
617 memcpy(skb_put(skb, mpdu_len), buf, mpdu_len); 795 if (likely(skb))
618 ieee80211_rx_irqsafe(ar->hw, skb, &status); 796 ieee80211_rx_irqsafe(ar->hw, skb, &status);
619} 797}
620 798
621void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb) 799void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb)
622{ 800{
623 unsigned int i, tlen, resplen; 801 unsigned int i, tlen, resplen, wlen = 0, clen = 0;
624 u8 *tbuf, *respbuf; 802 u8 *tbuf, *respbuf;
625 803
626 tbuf = skb->data; 804 tbuf = skb->data;
627 tlen = skb->len; 805 tlen = skb->len;
628 806
629 while (tlen >= 4) { 807 while (tlen >= 4) {
630 int clen = tbuf[1] << 8 | tbuf[0]; 808 clen = tbuf[1] << 8 | tbuf[0];
631 int wlen = (clen + 3) & ~3; 809 wlen = ALIGN(clen, 4);
632 810
633 /* 811 /* check if this is stream has a valid tag.*/
634 * parse stream (if any)
635 */
636 if (tbuf[2] != 0 || tbuf[3] != 0x4e) { 812 if (tbuf[2] != 0 || tbuf[3] != 0x4e) {
637 printk(KERN_ERR "%s: missing tag!\n", 813 /*
638 wiphy_name(ar->hw->wiphy)); 814 * TODO: handle the highly unlikely event that the
815 * corrupted stream has the TAG at the right position.
816 */
817
818 /* check if the frame can be repaired. */
819 if (!ar->rx_failover_missing) {
820 /* this is no "short read". */
821 if (ar9170_nag_limiter(ar)) {
822 printk(KERN_ERR "%s: missing tag!\n",
823 wiphy_name(ar->hw->wiphy));
824 goto err_telluser;
825 } else
826 goto err_silent;
827 }
828
829 if (ar->rx_failover_missing > tlen) {
830 if (ar9170_nag_limiter(ar)) {
831 printk(KERN_ERR "%s: possible multi "
832 "stream corruption!\n",
833 wiphy_name(ar->hw->wiphy));
834 goto err_telluser;
835 } else
836 goto err_silent;
837 }
838
839 memcpy(skb_put(ar->rx_failover, tlen), tbuf, tlen);
840 ar->rx_failover_missing -= tlen;
841
842 if (ar->rx_failover_missing <= 0) {
843 /*
844 * nested ar9170_rx call!
845 * termination is guranteed, even when the
846 * combined frame also have a element with
847 * a bad tag.
848 */
849
850 ar->rx_failover_missing = 0;
851 ar9170_rx(ar, ar->rx_failover);
852
853 skb_reset_tail_pointer(ar->rx_failover);
854 skb_trim(ar->rx_failover, 0);
855 }
856
639 return ; 857 return ;
640 } 858 }
859
860 /* check if stream is clipped */
641 if (wlen > tlen - 4) { 861 if (wlen > tlen - 4) {
642 printk(KERN_ERR "%s: invalid RX (%d, %d, %d)\n", 862 if (ar->rx_failover_missing) {
643 wiphy_name(ar->hw->wiphy), clen, wlen, tlen); 863 /* TODO: handle double stream corruption. */
644 print_hex_dump(KERN_DEBUG, "data: ", 864 if (ar9170_nag_limiter(ar)) {
645 DUMP_PREFIX_OFFSET, 865 printk(KERN_ERR "%s: double rx stream "
646 16, 1, tbuf, tlen, true); 866 "corruption!\n",
867 wiphy_name(ar->hw->wiphy));
868 goto err_telluser;
869 } else
870 goto err_silent;
871 }
872
873 /*
874 * save incomplete data set.
875 * the firmware will resend the missing bits when
876 * the rx - descriptor comes round again.
877 */
878
879 memcpy(skb_put(ar->rx_failover, tlen), tbuf, tlen);
880 ar->rx_failover_missing = clen - tlen;
647 return ; 881 return ;
648 } 882 }
649 resplen = clen; 883 resplen = clen;
@@ -668,12 +902,44 @@ void ar9170_rx(struct ar9170 *ar, struct sk_buff *skb)
668 if (i == 12) 902 if (i == 12)
669 ar9170_handle_command_response(ar, respbuf, resplen); 903 ar9170_handle_command_response(ar, respbuf, resplen);
670 else 904 else
671 ar9170_handle_mpdu(ar, respbuf, resplen); 905 ar9170_handle_mpdu(ar, respbuf, clen);
672 } 906 }
673 907
674 if (tlen) 908 if (tlen) {
675 printk(KERN_ERR "%s: buffer remains!\n", 909 if (net_ratelimit())
676 wiphy_name(ar->hw->wiphy)); 910 printk(KERN_ERR "%s: %d bytes of unprocessed "
911 "data left in rx stream!\n",
912 wiphy_name(ar->hw->wiphy), tlen);
913
914 goto err_telluser;
915 }
916
917 return ;
918
919err_telluser:
920 printk(KERN_ERR "%s: damaged RX stream data [want:%d, "
921 "data:%d, rx:%d, pending:%d ]\n",
922 wiphy_name(ar->hw->wiphy), clen, wlen, tlen,
923 ar->rx_failover_missing);
924
925 if (ar->rx_failover_missing)
926 print_hex_dump_bytes("rxbuf:", DUMP_PREFIX_OFFSET,
927 ar->rx_failover->data,
928 ar->rx_failover->len);
929
930 print_hex_dump_bytes("stream:", DUMP_PREFIX_OFFSET,
931 skb->data, skb->len);
932
933 printk(KERN_ERR "%s: please check your hardware and cables, if "
934 "you see this message frequently.\n",
935 wiphy_name(ar->hw->wiphy));
936
937err_silent:
938 if (ar->rx_failover_missing) {
939 skb_reset_tail_pointer(ar->rx_failover);
940 skb_trim(ar->rx_failover, 0);
941 ar->rx_failover_missing = 0;
942 }
677} 943}
678 944
679#define AR9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \ 945#define AR9170_FILL_QUEUE(queue, ai_fs, cwmin, cwmax, _txop) \
@@ -703,6 +969,8 @@ static int ar9170_op_start(struct ieee80211_hw *hw)
703 AR9170_FILL_QUEUE(ar->edcf[3], 2, 3, 7, 47); /* VOICE */ 969 AR9170_FILL_QUEUE(ar->edcf[3], 2, 3, 7, 47); /* VOICE */
704 AR9170_FILL_QUEUE(ar->edcf[4], 2, 3, 7, 0); /* SPECIAL */ 970 AR9170_FILL_QUEUE(ar->edcf[4], 2, 3, 7, 0); /* SPECIAL */
705 971
972 ar->bad_hw_nagger = jiffies;
973
706 err = ar->open(ar); 974 err = ar->open(ar);
707 if (err) 975 if (err)
708 goto out; 976 goto out;
@@ -742,8 +1010,9 @@ static void ar9170_op_stop(struct ieee80211_hw *hw)
742 if (IS_STARTED(ar)) 1010 if (IS_STARTED(ar))
743 ar->state = AR9170_IDLE; 1011 ar->state = AR9170_IDLE;
744 1012
745 mutex_lock(&ar->mutex); 1013 flush_workqueue(ar->hw->workqueue);
746 1014
1015 mutex_lock(&ar->mutex);
747 cancel_delayed_work_sync(&ar->tx_status_janitor); 1016 cancel_delayed_work_sync(&ar->tx_status_janitor);
748 cancel_work_sync(&ar->filter_config_work); 1017 cancel_work_sync(&ar->filter_config_work);
749 cancel_work_sync(&ar->beacon_work); 1018 cancel_work_sync(&ar->beacon_work);
@@ -1076,7 +1345,8 @@ static int ar9170_op_config(struct ieee80211_hw *hw, u32 changed)
1076 1345
1077 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 1346 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1078 err = ar9170_set_channel(ar, hw->conf.channel, 1347 err = ar9170_set_channel(ar, hw->conf.channel,
1079 AR9170_RFI_NONE, AR9170_BW_20); 1348 AR9170_RFI_NONE,
1349 nl80211_to_ar9170(hw->conf.channel_type));
1080 if (err) 1350 if (err)
1081 goto out; 1351 goto out;
1082 /* adjust slot time for 5 GHz */ 1352 /* adjust slot time for 5 GHz */
@@ -1123,10 +1393,10 @@ static void ar9170_set_filters(struct work_struct *work)
1123 filter_config_work); 1393 filter_config_work);
1124 int err; 1394 int err;
1125 1395
1126 mutex_lock(&ar->mutex);
1127 if (unlikely(!IS_STARTED(ar))) 1396 if (unlikely(!IS_STARTED(ar)))
1128 goto unlock; 1397 return ;
1129 1398
1399 mutex_lock(&ar->mutex);
1130 if (ar->filter_changed & AR9170_FILTER_CHANGED_PROMISC) { 1400 if (ar->filter_changed & AR9170_FILTER_CHANGED_PROMISC) {
1131 err = ar9170_set_operating_mode(ar); 1401 err = ar9170_set_operating_mode(ar);
1132 if (err) 1402 if (err)
@@ -1155,8 +1425,8 @@ static void ar9170_op_configure_filter(struct ieee80211_hw *hw,
1155 1425
1156 /* mask supported flags */ 1426 /* mask supported flags */
1157 *new_flags &= FIF_ALLMULTI | FIF_CONTROL | FIF_BCN_PRBRESP_PROMISC | 1427 *new_flags &= FIF_ALLMULTI | FIF_CONTROL | FIF_BCN_PRBRESP_PROMISC |
1158 FIF_PROMISC_IN_BSS; 1428 FIF_PROMISC_IN_BSS | FIF_FCSFAIL | FIF_PLCPFAIL;
1159 1429 ar->filter_state = *new_flags;
1160 /* 1430 /*
1161 * We can support more by setting the sniffer bit and 1431 * We can support more by setting the sniffer bit and
1162 * then checking the error flags, later. 1432 * then checking the error flags, later.
@@ -1498,6 +1768,24 @@ static int ar9170_conf_tx(struct ieee80211_hw *hw, u16 queue,
1498 return ret; 1768 return ret;
1499} 1769}
1500 1770
1771static int ar9170_ampdu_action(struct ieee80211_hw *hw,
1772 enum ieee80211_ampdu_mlme_action action,
1773 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1774{
1775 switch (action) {
1776 case IEEE80211_AMPDU_RX_START:
1777 case IEEE80211_AMPDU_RX_STOP:
1778 /*
1779 * Something goes wrong -- RX locks up
1780 * after a while of receiving aggregated
1781 * frames -- not enabling for now.
1782 */
1783 return -EOPNOTSUPP;
1784 default:
1785 return -EOPNOTSUPP;
1786 }
1787}
1788
1501static const struct ieee80211_ops ar9170_ops = { 1789static const struct ieee80211_ops ar9170_ops = {
1502 .start = ar9170_op_start, 1790 .start = ar9170_op_start,
1503 .stop = ar9170_op_stop, 1791 .stop = ar9170_op_stop,
@@ -1514,26 +1802,40 @@ static const struct ieee80211_ops ar9170_ops = {
1514 .sta_notify = ar9170_sta_notify, 1802 .sta_notify = ar9170_sta_notify,
1515 .get_stats = ar9170_get_stats, 1803 .get_stats = ar9170_get_stats,
1516 .get_tx_stats = ar9170_get_tx_stats, 1804 .get_tx_stats = ar9170_get_tx_stats,
1805 .ampdu_action = ar9170_ampdu_action,
1517}; 1806};
1518 1807
1519void *ar9170_alloc(size_t priv_size) 1808void *ar9170_alloc(size_t priv_size)
1520{ 1809{
1521 struct ieee80211_hw *hw; 1810 struct ieee80211_hw *hw;
1522 struct ar9170 *ar; 1811 struct ar9170 *ar;
1812 struct sk_buff *skb;
1523 int i; 1813 int i;
1524 1814
1815 /*
1816 * this buffer is used for rx stream reconstruction.
1817 * Under heavy load this device (or the transport layer?)
1818 * tends to split the streams into seperate rx descriptors.
1819 */
1820
1821 skb = __dev_alloc_skb(AR9170_MAX_RX_BUFFER_SIZE, GFP_KERNEL);
1822 if (!skb)
1823 goto err_nomem;
1824
1525 hw = ieee80211_alloc_hw(priv_size, &ar9170_ops); 1825 hw = ieee80211_alloc_hw(priv_size, &ar9170_ops);
1526 if (!hw) 1826 if (!hw)
1527 return ERR_PTR(-ENOMEM); 1827 goto err_nomem;
1528 1828
1529 ar = hw->priv; 1829 ar = hw->priv;
1530 ar->hw = hw; 1830 ar->hw = hw;
1831 ar->rx_failover = skb;
1531 1832
1532 mutex_init(&ar->mutex); 1833 mutex_init(&ar->mutex);
1533 spin_lock_init(&ar->cmdlock); 1834 spin_lock_init(&ar->cmdlock);
1534 spin_lock_init(&ar->tx_stats_lock); 1835 spin_lock_init(&ar->tx_stats_lock);
1535 skb_queue_head_init(&ar->global_tx_status); 1836 skb_queue_head_init(&ar->global_tx_status);
1536 skb_queue_head_init(&ar->global_tx_status_waste); 1837 skb_queue_head_init(&ar->global_tx_status_waste);
1838 ar9170_rx_reset_rx_mpdu(ar);
1537 INIT_WORK(&ar->filter_config_work, ar9170_set_filters); 1839 INIT_WORK(&ar->filter_config_work, ar9170_set_filters);
1538 INIT_WORK(&ar->beacon_work, ar9170_new_beacon); 1840 INIT_WORK(&ar->beacon_work, ar9170_new_beacon);
1539 INIT_DELAYED_WORK(&ar->tx_status_janitor, ar9170_tx_status_janitor); 1841 INIT_DELAYED_WORK(&ar->tx_status_janitor, ar9170_tx_status_janitor);
@@ -1561,6 +1863,10 @@ void *ar9170_alloc(size_t priv_size)
1561 ar->noise[i] = -95; /* ATH_DEFAULT_NOISE_FLOOR */ 1863 ar->noise[i] = -95; /* ATH_DEFAULT_NOISE_FLOOR */
1562 1864
1563 return ar; 1865 return ar;
1866
1867err_nomem:
1868 kfree_skb(skb);
1869 return ERR_PTR(-ENOMEM);
1564} 1870}
1565 1871
1566static int ar9170_read_eeprom(struct ar9170 *ar) 1872static int ar9170_read_eeprom(struct ar9170 *ar)
@@ -1619,12 +1925,24 @@ static int ar9170_read_eeprom(struct ar9170 *ar)
1619 else 1925 else
1620 ar->hw->channel_change_time = 80 * 1000; 1926 ar->hw->channel_change_time = 80 * 1000;
1621 1927
1928 ar->regulatory.current_rd = le16_to_cpu(ar->eeprom.reg_domain[0]);
1929 ar->regulatory.current_rd_ext = le16_to_cpu(ar->eeprom.reg_domain[1]);
1930
1622 /* second part of wiphy init */ 1931 /* second part of wiphy init */
1623 SET_IEEE80211_PERM_ADDR(ar->hw, addr); 1932 SET_IEEE80211_PERM_ADDR(ar->hw, addr);
1624 1933
1625 return bands ? 0 : -EINVAL; 1934 return bands ? 0 : -EINVAL;
1626} 1935}
1627 1936
1937static int ar9170_reg_notifier(struct wiphy *wiphy,
1938 struct regulatory_request *request)
1939{
1940 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1941 struct ar9170 *ar = hw->priv;
1942
1943 return ath_reg_notifier_apply(wiphy, request, &ar->regulatory);
1944}
1945
1628int ar9170_register(struct ar9170 *ar, struct device *pdev) 1946int ar9170_register(struct ar9170 *ar, struct device *pdev)
1629{ 1947{
1630 int err; 1948 int err;
@@ -1634,10 +1952,18 @@ int ar9170_register(struct ar9170 *ar, struct device *pdev)
1634 if (err) 1952 if (err)
1635 goto err_out; 1953 goto err_out;
1636 1954
1955 err = ath_regd_init(&ar->regulatory, ar->hw->wiphy,
1956 ar9170_reg_notifier);
1957 if (err)
1958 goto err_out;
1959
1637 err = ieee80211_register_hw(ar->hw); 1960 err = ieee80211_register_hw(ar->hw);
1638 if (err) 1961 if (err)
1639 goto err_out; 1962 goto err_out;
1640 1963
1964 if (!ath_is_world_regd(&ar->regulatory))
1965 regulatory_hint(ar->hw->wiphy, ar->regulatory.alpha2);
1966
1641 err = ar9170_init_leds(ar); 1967 err = ar9170_init_leds(ar);
1642 if (err) 1968 if (err)
1643 goto err_unreg; 1969 goto err_unreg;
@@ -1666,6 +1992,7 @@ void ar9170_unregister(struct ar9170 *ar)
1666 ar9170_unregister_leds(ar); 1992 ar9170_unregister_leds(ar);
1667#endif /* CONFIG_AR9170_LEDS */ 1993#endif /* CONFIG_AR9170_LEDS */
1668 1994
1995 kfree_skb(ar->rx_failover);
1669 ieee80211_unregister_hw(ar->hw); 1996 ieee80211_unregister_hw(ar->hw);
1670 mutex_destroy(&ar->mutex); 1997 mutex_destroy(&ar->mutex);
1671} 1998}
diff --git a/drivers/net/wireless/ar9170/phy.c b/drivers/net/wireless/ath/ar9170/phy.c
index 6ce20754b8e..6ce20754b8e 100644
--- a/drivers/net/wireless/ar9170/phy.c
+++ b/drivers/net/wireless/ath/ar9170/phy.c
diff --git a/drivers/net/wireless/ar9170/usb.c b/drivers/net/wireless/ath/ar9170/usb.c
index fddda477095..fddda477095 100644
--- a/drivers/net/wireless/ar9170/usb.c
+++ b/drivers/net/wireless/ath/ar9170/usb.c
diff --git a/drivers/net/wireless/ar9170/usb.h b/drivers/net/wireless/ath/ar9170/usb.h
index f5852924cd6..ac42586495d 100644
--- a/drivers/net/wireless/ar9170/usb.h
+++ b/drivers/net/wireless/ath/ar9170/usb.h
@@ -43,7 +43,7 @@
43#include <linux/completion.h> 43#include <linux/completion.h>
44#include <linux/spinlock.h> 44#include <linux/spinlock.h>
45#include <linux/leds.h> 45#include <linux/leds.h>
46#include <net/wireless.h> 46#include <net/cfg80211.h>
47#include <net/mac80211.h> 47#include <net/mac80211.h>
48#include <linux/firmware.h> 48#include <linux/firmware.h>
49#include "eeprom.h" 49#include "eeprom.h"
diff --git a/drivers/net/wireless/ath5k/Kconfig b/drivers/net/wireless/ath/ath5k/Kconfig
index 75383a5df99..509b6f94f73 100644
--- a/drivers/net/wireless/ath5k/Kconfig
+++ b/drivers/net/wireless/ath/ath5k/Kconfig
@@ -1,6 +1,7 @@
1config ATH5K 1config ATH5K
2 tristate "Atheros 5xxx wireless cards support" 2 tristate "Atheros 5xxx wireless cards support"
3 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL 3 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL
4 select ATH_COMMON
4 select MAC80211_LEDS 5 select MAC80211_LEDS
5 select LEDS_CLASS 6 select LEDS_CLASS
6 select NEW_LEDS 7 select NEW_LEDS
diff --git a/drivers/net/wireless/ath5k/Makefile b/drivers/net/wireless/ath/ath5k/Makefile
index 84a74c5248e..84a74c5248e 100644
--- a/drivers/net/wireless/ath5k/Makefile
+++ b/drivers/net/wireless/ath/ath5k/Makefile
diff --git a/drivers/net/wireless/ath5k/ath5k.h b/drivers/net/wireless/ath/ath5k/ath5k.h
index 0b616e72fe0..60c6d2edc4b 100644
--- a/drivers/net/wireless/ath5k/ath5k.h
+++ b/drivers/net/wireless/ath/ath5k/ath5k.h
@@ -27,6 +27,8 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <net/mac80211.h> 28#include <net/mac80211.h>
29 29
30#include "../regd.h"
31
30/* RX/TX descriptor hw structs 32/* RX/TX descriptor hw structs
31 * TODO: Driver part should only see sw structs */ 33 * TODO: Driver part should only see sw structs */
32#include "desc.h" 34#include "desc.h"
@@ -1039,8 +1041,6 @@ struct ath5k_hw {
1039 bool ah_5ghz; 1041 bool ah_5ghz;
1040 bool ah_2ghz; 1042 bool ah_2ghz;
1041 1043
1042#define ah_regdomain ah_capabilities.cap_regdomain.reg_current
1043#define ah_regdomain_hw ah_capabilities.cap_regdomain.reg_hw
1044#define ah_modes ah_capabilities.cap_mode 1044#define ah_modes ah_capabilities.cap_mode
1045#define ah_ee_version ah_capabilities.cap_eeprom.ee_version 1045#define ah_ee_version ah_capabilities.cap_eeprom.ee_version
1046 1046
@@ -1065,6 +1065,7 @@ struct ath5k_hw {
1065 u32 ah_gpio[AR5K_MAX_GPIO]; 1065 u32 ah_gpio[AR5K_MAX_GPIO];
1066 int ah_gpio_npins; 1066 int ah_gpio_npins;
1067 1067
1068 struct ath_regulatory ah_regulatory;
1068 struct ath5k_capabilities ah_capabilities; 1069 struct ath5k_capabilities ah_capabilities;
1069 1070
1070 struct ath5k_txq_info ah_txq[AR5K_NUM_TX_QUEUES]; 1071 struct ath5k_txq_info ah_txq[AR5K_NUM_TX_QUEUES];
diff --git a/drivers/net/wireless/ath5k/attach.c b/drivers/net/wireless/ath/ath5k/attach.c
index 70d376c63aa..70d376c63aa 100644
--- a/drivers/net/wireless/ath5k/attach.c
+++ b/drivers/net/wireless/ath/ath5k/attach.c
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
index a08bc8a4fb6..c8c658bfcf9 100644
--- a/drivers/net/wireless/ath5k/base.c
+++ b/drivers/net/wireless/ath/ath5k/base.c
@@ -61,9 +61,13 @@
61 61
62static int ath5k_calinterval = 10; /* Calibrate PHY every 10 secs (TODO: Fixme) */ 62static int ath5k_calinterval = 10; /* Calibrate PHY every 10 secs (TODO: Fixme) */
63static int modparam_nohwcrypt; 63static int modparam_nohwcrypt;
64module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444); 64module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
65MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption."); 65MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
66 66
67static int modparam_all_channels;
68module_param_named(all_channels, modparam_all_channels, bool, S_IRUGO);
69MODULE_PARM_DESC(all_channels, "Expose all channels the device can use.");
70
67 71
68/******************\ 72/******************\
69* Internal defines * 73* Internal defines *
@@ -705,6 +709,15 @@ err_no_irq:
705* Driver Initialization * 709* Driver Initialization *
706\***********************/ 710\***********************/
707 711
712static int ath5k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
713{
714 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
715 struct ath5k_softc *sc = hw->priv;
716 struct ath_regulatory *reg = &sc->ah->ah_regulatory;
717
718 return ath_reg_notifier_apply(wiphy, request, reg);
719}
720
708static int 721static int
709ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw) 722ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
710{ 723{
@@ -793,12 +806,23 @@ ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
793 memset(sc->bssidmask, 0xff, ETH_ALEN); 806 memset(sc->bssidmask, 0xff, ETH_ALEN);
794 ath5k_hw_set_bssid_mask(sc->ah, sc->bssidmask); 807 ath5k_hw_set_bssid_mask(sc->ah, sc->bssidmask);
795 808
809 ah->ah_regulatory.current_rd =
810 ah->ah_capabilities.cap_eeprom.ee_regdomain;
811 ret = ath_regd_init(&ah->ah_regulatory, hw->wiphy, ath5k_reg_notifier);
812 if (ret) {
813 ATH5K_ERR(sc, "can't initialize regulatory system\n");
814 goto err_queues;
815 }
816
796 ret = ieee80211_register_hw(hw); 817 ret = ieee80211_register_hw(hw);
797 if (ret) { 818 if (ret) {
798 ATH5K_ERR(sc, "can't register ieee80211 hw\n"); 819 ATH5K_ERR(sc, "can't register ieee80211 hw\n");
799 goto err_queues; 820 goto err_queues;
800 } 821 }
801 822
823 if (!ath_is_world_regd(&sc->ah->ah_regulatory))
824 regulatory_hint(hw->wiphy, sc->ah->ah_regulatory.alpha2);
825
802 ath5k_init_leds(sc); 826 ath5k_init_leds(sc);
803 827
804 return 0; 828 return 0;
@@ -862,6 +886,20 @@ ath5k_ieee2mhz(short chan)
862 return 2212 + chan * 20; 886 return 2212 + chan * 20;
863} 887}
864 888
889/*
890 * Returns true for the channel numbers used without all_channels modparam.
891 */
892static bool ath5k_is_standard_channel(short chan)
893{
894 return ((chan <= 14) ||
895 /* UNII 1,2 */
896 ((chan & 3) == 0 && chan >= 36 && chan <= 64) ||
897 /* midband */
898 ((chan & 3) == 0 && chan >= 100 && chan <= 140) ||
899 /* UNII-3 */
900 ((chan & 3) == 1 && chan >= 149 && chan <= 165));
901}
902
865static unsigned int 903static unsigned int
866ath5k_copy_channels(struct ath5k_hw *ah, 904ath5k_copy_channels(struct ath5k_hw *ah,
867 struct ieee80211_channel *channels, 905 struct ieee80211_channel *channels,
@@ -899,6 +937,9 @@ ath5k_copy_channels(struct ath5k_hw *ah,
899 if (!ath5k_channel_ok(ah, freq, chfreq)) 937 if (!ath5k_channel_ok(ah, freq, chfreq))
900 continue; 938 continue;
901 939
940 if (!modparam_all_channels && !ath5k_is_standard_channel(ch))
941 continue;
942
902 /* Write channel info and increment counter */ 943 /* Write channel info and increment counter */
903 channels[count].center_freq = freq; 944 channels[count].center_freq = freq;
904 channels[count].band = (chfreq == CHANNEL_2GHZ) ? 945 channels[count].band = (chfreq == CHANNEL_2GHZ) ?
@@ -1577,9 +1618,8 @@ ath5k_rx_start(struct ath5k_softc *sc)
1577 ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "cachelsz %u rxbufsize %u\n", 1618 ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "cachelsz %u rxbufsize %u\n",
1578 sc->cachelsz, sc->rxbufsize); 1619 sc->cachelsz, sc->rxbufsize);
1579 1620
1580 sc->rxlink = NULL;
1581
1582 spin_lock_bh(&sc->rxbuflock); 1621 spin_lock_bh(&sc->rxbuflock);
1622 sc->rxlink = NULL;
1583 list_for_each_entry(bf, &sc->rxbuf, list) { 1623 list_for_each_entry(bf, &sc->rxbuf, list) {
1584 ret = ath5k_rxbuf_setup(sc, bf); 1624 ret = ath5k_rxbuf_setup(sc, bf);
1585 if (ret != 0) { 1625 if (ret != 0) {
@@ -1588,9 +1628,9 @@ ath5k_rx_start(struct ath5k_softc *sc)
1588 } 1628 }
1589 } 1629 }
1590 bf = list_first_entry(&sc->rxbuf, struct ath5k_buf, list); 1630 bf = list_first_entry(&sc->rxbuf, struct ath5k_buf, list);
1631 ath5k_hw_set_rxdp(ah, bf->daddr);
1591 spin_unlock_bh(&sc->rxbuflock); 1632 spin_unlock_bh(&sc->rxbuflock);
1592 1633
1593 ath5k_hw_set_rxdp(ah, bf->daddr);
1594 ath5k_hw_start_rx_dma(ah); /* enable recv descriptors */ 1634 ath5k_hw_start_rx_dma(ah); /* enable recv descriptors */
1595 ath5k_mode_setup(sc); /* set filters, etc. */ 1635 ath5k_mode_setup(sc); /* set filters, etc. */
1596 ath5k_hw_start_rx_pcu(ah); /* re-enable PCU/DMA engine */ 1636 ath5k_hw_start_rx_pcu(ah); /* re-enable PCU/DMA engine */
@@ -1739,7 +1779,7 @@ ath5k_tasklet_rx(unsigned long data)
1739 struct sk_buff *skb, *next_skb; 1779 struct sk_buff *skb, *next_skb;
1740 dma_addr_t next_skb_addr; 1780 dma_addr_t next_skb_addr;
1741 struct ath5k_softc *sc = (void *)data; 1781 struct ath5k_softc *sc = (void *)data;
1742 struct ath5k_buf *bf, *bf_last; 1782 struct ath5k_buf *bf;
1743 struct ath5k_desc *ds; 1783 struct ath5k_desc *ds;
1744 int ret; 1784 int ret;
1745 int hdrlen; 1785 int hdrlen;
@@ -1750,7 +1790,6 @@ ath5k_tasklet_rx(unsigned long data)
1750 ATH5K_WARN(sc, "empty rx buf pool\n"); 1790 ATH5K_WARN(sc, "empty rx buf pool\n");
1751 goto unlock; 1791 goto unlock;
1752 } 1792 }
1753 bf_last = list_entry(sc->rxbuf.prev, struct ath5k_buf, list);
1754 do { 1793 do {
1755 rxs.flag = 0; 1794 rxs.flag = 0;
1756 1795
@@ -1759,24 +1798,9 @@ ath5k_tasklet_rx(unsigned long data)
1759 skb = bf->skb; 1798 skb = bf->skb;
1760 ds = bf->desc; 1799 ds = bf->desc;
1761 1800
1762 /* 1801 /* bail if HW is still using self-linked descriptor */
1763 * last buffer must not be freed to ensure proper hardware 1802 if (ath5k_hw_get_rxdp(sc->ah) == bf->daddr)
1764 * function. When the hardware finishes also a packet next to 1803 break;
1765 * it, we are sure, it doesn't use it anymore and we can go on.
1766 */
1767 if (bf_last == bf)
1768 bf->flags |= 1;
1769 if (bf->flags) {
1770 struct ath5k_buf *bf_next = list_entry(bf->list.next,
1771 struct ath5k_buf, list);
1772 ret = sc->ah->ah_proc_rx_desc(sc->ah, bf_next->desc,
1773 &rs);
1774 if (ret)
1775 break;
1776 bf->flags &= ~1;
1777 /* skip the overwritten one (even status is martian) */
1778 goto next;
1779 }
1780 1804
1781 ret = sc->ah->ah_proc_rx_desc(sc->ah, ds, &rs); 1805 ret = sc->ah->ah_proc_rx_desc(sc->ah, ds, &rs);
1782 if (unlikely(ret == -EINPROGRESS)) 1806 if (unlikely(ret == -EINPROGRESS))
@@ -2455,7 +2479,7 @@ ath5k_intr(int irq, void *dev_id)
2455 tasklet_schedule(&sc->restq); 2479 tasklet_schedule(&sc->restq);
2456 } else { 2480 } else {
2457 if (status & AR5K_INT_SWBA) { 2481 if (status & AR5K_INT_SWBA) {
2458 tasklet_schedule(&sc->beacontq); 2482 tasklet_hi_schedule(&sc->beacontq);
2459 } 2483 }
2460 if (status & AR5K_INT_RXEOL) { 2484 if (status & AR5K_INT_RXEOL) {
2461 /* 2485 /*
diff --git a/drivers/net/wireless/ath5k/base.h b/drivers/net/wireless/ath/ath5k/base.h
index 822956114cd..852b2c189fd 100644
--- a/drivers/net/wireless/ath5k/base.h
+++ b/drivers/net/wireless/ath/ath5k/base.h
@@ -56,7 +56,6 @@
56 56
57struct ath5k_buf { 57struct ath5k_buf {
58 struct list_head list; 58 struct list_head list;
59 unsigned int flags; /* rx descriptor flags */
60 struct ath5k_desc *desc; /* virtual addr of desc */ 59 struct ath5k_desc *desc; /* virtual addr of desc */
61 dma_addr_t daddr; /* physical addr of desc */ 60 dma_addr_t daddr; /* physical addr of desc */
62 struct sk_buff *skb; /* skbuff for buf */ 61 struct sk_buff *skb; /* skbuff for buf */
diff --git a/drivers/net/wireless/ath5k/caps.c b/drivers/net/wireless/ath/ath5k/caps.c
index 367a6c7d3cc..367a6c7d3cc 100644
--- a/drivers/net/wireless/ath5k/caps.c
+++ b/drivers/net/wireless/ath/ath5k/caps.c
diff --git a/drivers/net/wireless/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
index 9770bb3d40f..9770bb3d40f 100644
--- a/drivers/net/wireless/ath5k/debug.c
+++ b/drivers/net/wireless/ath/ath5k/debug.c
diff --git a/drivers/net/wireless/ath5k/debug.h b/drivers/net/wireless/ath/ath5k/debug.h
index 66f69f04e55..66f69f04e55 100644
--- a/drivers/net/wireless/ath5k/debug.h
+++ b/drivers/net/wireless/ath/ath5k/debug.h
diff --git a/drivers/net/wireless/ath5k/desc.c b/drivers/net/wireless/ath/ath5k/desc.c
index dc30a2b70a6..dc30a2b70a6 100644
--- a/drivers/net/wireless/ath5k/desc.c
+++ b/drivers/net/wireless/ath/ath5k/desc.c
diff --git a/drivers/net/wireless/ath5k/desc.h b/drivers/net/wireless/ath/ath5k/desc.h
index 56158c804e3..56158c804e3 100644
--- a/drivers/net/wireless/ath5k/desc.h
+++ b/drivers/net/wireless/ath/ath5k/desc.h
diff --git a/drivers/net/wireless/ath5k/dma.c b/drivers/net/wireless/ath/ath5k/dma.c
index b65b4feb2d2..941b51130a6 100644
--- a/drivers/net/wireless/ath5k/dma.c
+++ b/drivers/net/wireless/ath/ath5k/dma.c
@@ -80,8 +80,6 @@ int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
80 * ath5k_hw_get_rxdp - Get RX Descriptor's address 80 * ath5k_hw_get_rxdp - Get RX Descriptor's address
81 * 81 *
82 * @ah: The &struct ath5k_hw 82 * @ah: The &struct ath5k_hw
83 *
84 * XXX: Is RXDP read and clear ?
85 */ 83 */
86u32 ath5k_hw_get_rxdp(struct ath5k_hw *ah) 84u32 ath5k_hw_get_rxdp(struct ath5k_hw *ah)
87{ 85{
diff --git a/drivers/net/wireless/ath5k/eeprom.c b/drivers/net/wireless/ath/ath5k/eeprom.c
index c0fb3b09ba4..c0fb3b09ba4 100644
--- a/drivers/net/wireless/ath5k/eeprom.c
+++ b/drivers/net/wireless/ath/ath5k/eeprom.c
diff --git a/drivers/net/wireless/ath5k/eeprom.h b/drivers/net/wireless/ath/ath5k/eeprom.h
index b0c0606dea0..b0c0606dea0 100644
--- a/drivers/net/wireless/ath5k/eeprom.h
+++ b/drivers/net/wireless/ath/ath5k/eeprom.h
diff --git a/drivers/net/wireless/ath5k/gpio.c b/drivers/net/wireless/ath/ath5k/gpio.c
index 64a27e73d02..64a27e73d02 100644
--- a/drivers/net/wireless/ath5k/gpio.c
+++ b/drivers/net/wireless/ath/ath5k/gpio.c
diff --git a/drivers/net/wireless/ath5k/initvals.c b/drivers/net/wireless/ath/ath5k/initvals.c
index 61fb621ed20..18eb5190ce4 100644
--- a/drivers/net/wireless/ath5k/initvals.c
+++ b/drivers/net/wireless/ath/ath5k/initvals.c
@@ -537,8 +537,6 @@ static const struct ath5k_ini ar5212_ini_common_start[] = {
537 { AR5K_DCU_TX_FILTER_1(15), 0x00000000 }, 537 { AR5K_DCU_TX_FILTER_1(15), 0x00000000 },
538 { AR5K_DCU_TX_FILTER_CLR, 0x00000000 }, 538 { AR5K_DCU_TX_FILTER_CLR, 0x00000000 },
539 { AR5K_DCU_TX_FILTER_SET, 0x00000000 }, 539 { AR5K_DCU_TX_FILTER_SET, 0x00000000 },
540 { AR5K_DCU_TX_FILTER_CLR, 0x00000000 },
541 { AR5K_DCU_TX_FILTER_SET, 0x00000000 },
542 { AR5K_STA_ID1, 0x00000000 }, 540 { AR5K_STA_ID1, 0x00000000 },
543 { AR5K_BSS_ID0, 0x00000000 }, 541 { AR5K_BSS_ID0, 0x00000000 },
544 { AR5K_BSS_ID1, 0x00000000 }, 542 { AR5K_BSS_ID1, 0x00000000 },
@@ -669,7 +667,7 @@ static const struct ath5k_ini ar5212_ini_common_start[] = {
669 /*{ AR5K_PHY(650), 0x000001b5 },*/ 667 /*{ AR5K_PHY(650), 0x000001b5 },*/
670 { AR5K_PHY(651), 0x00000000 }, 668 { AR5K_PHY(651), 0x00000000 },
671 { AR5K_PHY_TXPOWER_RATE3, 0x20202020 }, 669 { AR5K_PHY_TXPOWER_RATE3, 0x20202020 },
672 { AR5K_PHY_TXPOWER_RATE2, 0x20202020 }, 670 { AR5K_PHY_TXPOWER_RATE4, 0x20202020 },
673 /*{ AR5K_PHY(655), 0x13c889af },*/ 671 /*{ AR5K_PHY(655), 0x13c889af },*/
674 { AR5K_PHY(656), 0x38490a20 }, 672 { AR5K_PHY(656), 0x38490a20 },
675 { AR5K_PHY(657), 0x00007bb6 }, 673 { AR5K_PHY(657), 0x00007bb6 },
@@ -718,7 +716,7 @@ static const struct ath5k_ini_mode ar5212_ini_mode_start[] = {
718 { AR5K_PHY_SETTLING, 716 { AR5K_PHY_SETTLING,
719 { 0x1372161c, 0x13721c25, 0x13721722, 0x137216a2, 0x13721c25 } }, 717 { 0x1372161c, 0x13721c25, 0x13721722, 0x137216a2, 0x13721c25 } },
720 { AR5K_PHY_AGCCTL, 718 { AR5K_PHY_AGCCTL,
721 { 0x00009d10, 0x00009d10, 0x00009d18, 0x00009d18, 0x00009d18 } }, 719 { 0x00009d10, 0x00009d10, 0x00009d18, 0x00009d18, 0x00009d10 } },
722 { AR5K_PHY_NF, 720 { AR5K_PHY_NF,
723 { 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00 } }, 721 { 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00, 0x0001ce00 } },
724 { AR5K_PHY_WEAK_OFDM_HIGH_THR, 722 { AR5K_PHY_WEAK_OFDM_HIGH_THR,
@@ -799,7 +797,7 @@ static const struct ath5k_ini_mode rf5112_ini_mode_end[] = {
799 { AR5K_PHY_DESIRED_SIZE, 797 { AR5K_PHY_DESIRED_SIZE,
800 { 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0 } }, 798 { 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0, 0x0de8b4e0 } },
801 { AR5K_PHY_SIG, 799 { AR5K_PHY_SIG,
802 { 0x7e800d2e, 0x7e800d2e, 0x7ee80d2e, 0x7ee80d2e, 0x7ee80d2e } }, 800 { 0x7e800d2e, 0x7e800d2e, 0x7ee80d2e, 0x7ee80d2e, 0x7e800d2e } },
803 { AR5K_PHY_AGCCOARSE, 801 { AR5K_PHY_AGCCOARSE,
804 { 0x3137665e, 0x3137665e, 0x3137665e, 0x3137665e, 0x3137665e } }, 802 { 0x3137665e, 0x3137665e, 0x3137665e, 0x3137665e, 0x3137665e } },
805 { AR5K_PHY_WEAK_OFDM_LOW_THR, 803 { AR5K_PHY_WEAK_OFDM_LOW_THR,
diff --git a/drivers/net/wireless/ath5k/led.c b/drivers/net/wireless/ath/ath5k/led.c
index 19555fb79c9..cbdc0b30842 100644
--- a/drivers/net/wireless/ath5k/led.c
+++ b/drivers/net/wireless/ath/ath5k/led.c
@@ -67,6 +67,8 @@ static const struct pci_device_id ath5k_led_devices[] = {
67 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) }, 67 { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) },
68 /* Acer Extensa 5620z (nekoreeve@gmail.com) */ 68 /* Acer Extensa 5620z (nekoreeve@gmail.com) */
69 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) }, 69 { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) },
70 /* Fukato Datacask Jupiter 1014a (mrb74@gmx.at) */
71 { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) },
70 { } 72 { }
71}; 73};
72 74
@@ -78,7 +80,7 @@ void ath5k_led_enable(struct ath5k_softc *sc)
78 } 80 }
79} 81}
80 82
81void ath5k_led_on(struct ath5k_softc *sc) 83static void ath5k_led_on(struct ath5k_softc *sc)
82{ 84{
83 if (!test_bit(ATH_STAT_LEDSOFT, sc->status)) 85 if (!test_bit(ATH_STAT_LEDSOFT, sc->status))
84 return; 86 return;
diff --git a/drivers/net/wireless/ath5k/pcu.c b/drivers/net/wireless/ath/ath5k/pcu.c
index 55122f1e198..55122f1e198 100644
--- a/drivers/net/wireless/ath5k/pcu.c
+++ b/drivers/net/wireless/ath/ath5k/pcu.c
diff --git a/drivers/net/wireless/ath5k/phy.c b/drivers/net/wireless/ath/ath5k/phy.c
index 9e2faae5ae9..b48b29dca3d 100644
--- a/drivers/net/wireless/ath5k/phy.c
+++ b/drivers/net/wireless/ath/ath5k/phy.c
@@ -1487,28 +1487,35 @@ ath5k_get_linear_pcdac_min(const u8 *stepL, const u8 *stepR,
1487{ 1487{
1488 s8 tmp; 1488 s8 tmp;
1489 s16 min_pwrL, min_pwrR; 1489 s16 min_pwrL, min_pwrR;
1490 s16 pwr_i = pwrL[0]; 1490 s16 pwr_i;
1491 1491
1492 do { 1492 if (pwrL[0] == pwrL[1])
1493 pwr_i--; 1493 min_pwrL = pwrL[0];
1494 tmp = (s8) ath5k_get_interpolated_value(pwr_i, 1494 else {
1495 pwrL[0], pwrL[1], 1495 pwr_i = pwrL[0];
1496 stepL[0], stepL[1]); 1496 do {
1497 1497 pwr_i--;
1498 } while (tmp > 1); 1498 tmp = (s8) ath5k_get_interpolated_value(pwr_i,
1499 1499 pwrL[0], pwrL[1],
1500 min_pwrL = pwr_i; 1500 stepL[0], stepL[1]);
1501 1501 } while (tmp > 1);
1502 pwr_i = pwrR[0]; 1502
1503 do { 1503 min_pwrL = pwr_i;
1504 pwr_i--; 1504 }
1505 tmp = (s8) ath5k_get_interpolated_value(pwr_i,
1506 pwrR[0], pwrR[1],
1507 stepR[0], stepR[1]);
1508
1509 } while (tmp > 1);
1510 1505
1511 min_pwrR = pwr_i; 1506 if (pwrR[0] == pwrR[1])
1507 min_pwrR = pwrR[0];
1508 else {
1509 pwr_i = pwrR[0];
1510 do {
1511 pwr_i--;
1512 tmp = (s8) ath5k_get_interpolated_value(pwr_i,
1513 pwrR[0], pwrR[1],
1514 stepR[0], stepR[1]);
1515 } while (tmp > 1);
1516
1517 min_pwrR = pwr_i;
1518 }
1512 1519
1513 /* Keep the right boundary so that it works for both curves */ 1520 /* Keep the right boundary so that it works for both curves */
1514 return max(min_pwrL, min_pwrR); 1521 return max(min_pwrL, min_pwrR);
diff --git a/drivers/net/wireless/ath5k/qcu.c b/drivers/net/wireless/ath/ath5k/qcu.c
index 5094c394a4b..5094c394a4b 100644
--- a/drivers/net/wireless/ath5k/qcu.c
+++ b/drivers/net/wireless/ath/ath5k/qcu.c
diff --git a/drivers/net/wireless/ath5k/reg.h b/drivers/net/wireless/ath/ath5k/reg.h
index 7070d1543cd..7070d1543cd 100644
--- a/drivers/net/wireless/ath5k/reg.h
+++ b/drivers/net/wireless/ath/ath5k/reg.h
diff --git a/drivers/net/wireless/ath5k/reset.c b/drivers/net/wireless/ath/ath5k/reset.c
index cb5e15f9709..775fdf78554 100644
--- a/drivers/net/wireless/ath5k/reset.c
+++ b/drivers/net/wireless/ath/ath5k/reset.c
@@ -358,7 +358,7 @@ int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
358 mode |= AR5K_PHY_MODE_FREQ_5GHZ; 358 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
359 359
360 if (ah->ah_radio == AR5K_RF5413) 360 if (ah->ah_radio == AR5K_RF5413)
361 clock |= AR5K_PHY_PLL_40MHZ_5413; 361 clock = AR5K_PHY_PLL_40MHZ_5413;
362 else 362 else
363 clock |= AR5K_PHY_PLL_40MHZ; 363 clock |= AR5K_PHY_PLL_40MHZ;
364 364
diff --git a/drivers/net/wireless/ath5k/rfbuffer.h b/drivers/net/wireless/ath/ath5k/rfbuffer.h
index e50baff6617..e50baff6617 100644
--- a/drivers/net/wireless/ath5k/rfbuffer.h
+++ b/drivers/net/wireless/ath/ath5k/rfbuffer.h
diff --git a/drivers/net/wireless/ath5k/rfgain.h b/drivers/net/wireless/ath/ath5k/rfgain.h
index 1354d8c392c..1354d8c392c 100644
--- a/drivers/net/wireless/ath5k/rfgain.h
+++ b/drivers/net/wireless/ath/ath5k/rfgain.h
diff --git a/drivers/net/wireless/ath9k/Kconfig b/drivers/net/wireless/ath/ath9k/Kconfig
index 90a8dd87378..0ed1ac312aa 100644
--- a/drivers/net/wireless/ath9k/Kconfig
+++ b/drivers/net/wireless/ath/ath9k/Kconfig
@@ -2,6 +2,7 @@ config ATH9K
2 tristate "Atheros 802.11n wireless cards support" 2 tristate "Atheros 802.11n wireless cards support"
3 depends on PCI && MAC80211 && WLAN_80211 3 depends on PCI && MAC80211 && WLAN_80211
4 depends on RFKILL || RFKILL=n 4 depends on RFKILL || RFKILL=n
5 select ATH_COMMON
5 select MAC80211_LEDS 6 select MAC80211_LEDS
6 select LEDS_CLASS 7 select LEDS_CLASS
7 select NEW_LEDS 8 select NEW_LEDS
diff --git a/drivers/net/wireless/ath9k/Makefile b/drivers/net/wireless/ath/ath9k/Makefile
index 1a4d4eab6fe..783bc39eb2f 100644
--- a/drivers/net/wireless/ath9k/Makefile
+++ b/drivers/net/wireless/ath/ath9k/Makefile
@@ -4,7 +4,6 @@ ath9k-y += hw.o \
4 calib.o \ 4 calib.o \
5 ani.o \ 5 ani.o \
6 phy.o \ 6 phy.o \
7 regd.o \
8 beacon.o \ 7 beacon.o \
9 main.o \ 8 main.o \
10 recv.o \ 9 recv.o \
diff --git a/drivers/net/wireless/ath9k/ahb.c b/drivers/net/wireless/ath/ath9k/ahb.c
index 0e65c51ba17..0e65c51ba17 100644
--- a/drivers/net/wireless/ath9k/ahb.c
+++ b/drivers/net/wireless/ath/ath9k/ahb.c
diff --git a/drivers/net/wireless/ath9k/ani.c b/drivers/net/wireless/ath/ath9k/ani.c
index 6c5e887d50d..1aeafb511dd 100644
--- a/drivers/net/wireless/ath9k/ani.c
+++ b/drivers/net/wireless/ath/ath9k/ani.c
@@ -569,8 +569,7 @@ void ath9k_hw_ani_monitor(struct ath_hw *ah,
569 DPRINTF(ah->ah_sc, ATH_DBG_ANI, 569 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
570 "phyCnt1 0x%x, resetting " 570 "phyCnt1 0x%x, resetting "
571 "counter value to 0x%x\n", 571 "counter value to 0x%x\n",
572 phyCnt1, 572 phyCnt1, aniState->ofdmPhyErrBase);
573 aniState->ofdmPhyErrBase);
574 REG_WRITE(ah, AR_PHY_ERR_1, 573 REG_WRITE(ah, AR_PHY_ERR_1,
575 aniState->ofdmPhyErrBase); 574 aniState->ofdmPhyErrBase);
576 REG_WRITE(ah, AR_PHY_ERR_MASK_1, 575 REG_WRITE(ah, AR_PHY_ERR_MASK_1,
@@ -580,8 +579,7 @@ void ath9k_hw_ani_monitor(struct ath_hw *ah,
580 DPRINTF(ah->ah_sc, ATH_DBG_ANI, 579 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
581 "phyCnt2 0x%x, resetting " 580 "phyCnt2 0x%x, resetting "
582 "counter value to 0x%x\n", 581 "counter value to 0x%x\n",
583 phyCnt2, 582 phyCnt2, aniState->cckPhyErrBase);
584 aniState->cckPhyErrBase);
585 REG_WRITE(ah, AR_PHY_ERR_2, 583 REG_WRITE(ah, AR_PHY_ERR_2,
586 aniState->cckPhyErrBase); 584 aniState->cckPhyErrBase);
587 REG_WRITE(ah, AR_PHY_ERR_MASK_2, 585 REG_WRITE(ah, AR_PHY_ERR_MASK_2,
@@ -667,7 +665,7 @@ u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hw *ah,
667 u32 cc = REG_READ(ah, AR_CCCNT); 665 u32 cc = REG_READ(ah, AR_CCCNT);
668 666
669 if (cycles == 0 || cycles > cc) { 667 if (cycles == 0 || cycles > cc) {
670 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 668 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
671 "cycle counter wrap. ExtBusy = 0\n"); 669 "cycle counter wrap. ExtBusy = 0\n");
672 good = 0; 670 good = 0;
673 } else { 671 } else {
diff --git a/drivers/net/wireless/ath9k/ani.h b/drivers/net/wireless/ath/ath9k/ani.h
index 08b4e7ed5ff..08b4e7ed5ff 100644
--- a/drivers/net/wireless/ath9k/ani.h
+++ b/drivers/net/wireless/ath/ath9k/ani.h
diff --git a/drivers/net/wireless/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index 7b1b40aaf09..c92d46fa9d5 100644
--- a/drivers/net/wireless/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -66,7 +66,6 @@ struct ath_config {
66 u32 ath_aggr_prot; 66 u32 ath_aggr_prot;
67 u16 txpowlimit; 67 u16 txpowlimit;
68 u8 cabqReadytime; 68 u8 cabqReadytime;
69 u8 swBeaconProcess;
70}; 69};
71 70
72/*************************/ 71/*************************/
@@ -74,13 +73,17 @@ struct ath_config {
74/*************************/ 73/*************************/
75 74
76#define ATH_TXBUF_RESET(_bf) do { \ 75#define ATH_TXBUF_RESET(_bf) do { \
77 (_bf)->bf_status = 0; \ 76 (_bf)->bf_stale = false; \
78 (_bf)->bf_lastbf = NULL; \ 77 (_bf)->bf_lastbf = NULL; \
79 (_bf)->bf_next = NULL; \ 78 (_bf)->bf_next = NULL; \
80 memset(&((_bf)->bf_state), 0, \ 79 memset(&((_bf)->bf_state), 0, \
81 sizeof(struct ath_buf_state)); \ 80 sizeof(struct ath_buf_state)); \
82 } while (0) 81 } while (0)
83 82
83#define ATH_RXBUF_RESET(_bf) do { \
84 (_bf)->bf_stale = false; \
85 } while (0)
86
84/** 87/**
85 * enum buffer_type - Buffer type flags 88 * enum buffer_type - Buffer type flags
86 * 89 *
@@ -106,7 +109,7 @@ struct ath_buf_state {
106 int bfs_seqno; 109 int bfs_seqno;
107 int bfs_tidno; 110 int bfs_tidno;
108 int bfs_retries; 111 int bfs_retries;
109 u32 bf_type; 112 u8 bf_type;
110 u32 bfs_keyix; 113 u32 bfs_keyix;
111 enum ath9k_key_type bfs_keytype; 114 enum ath9k_key_type bfs_keytype;
112}; 115};
@@ -130,26 +133,21 @@ struct ath_buf {
130 struct ath_buf *bf_lastbf; /* last buf of this unit (a frame or 133 struct ath_buf *bf_lastbf; /* last buf of this unit (a frame or
131 an aggregate) */ 134 an aggregate) */
132 struct ath_buf *bf_next; /* next subframe in the aggregate */ 135 struct ath_buf *bf_next; /* next subframe in the aggregate */
133 void *bf_mpdu; /* enclosing frame structure */ 136 struct sk_buff *bf_mpdu; /* enclosing frame structure */
134 struct ath_desc *bf_desc; /* virtual addr of desc */ 137 struct ath_desc *bf_desc; /* virtual addr of desc */
135 dma_addr_t bf_daddr; /* physical addr of desc */ 138 dma_addr_t bf_daddr; /* physical addr of desc */
136 dma_addr_t bf_buf_addr; /* physical addr of data buffer */ 139 dma_addr_t bf_buf_addr; /* physical addr of data buffer */
137 u32 bf_status; 140 bool bf_stale;
138 u16 bf_flags; 141 u16 bf_flags;
139 struct ath_buf_state bf_state; 142 struct ath_buf_state bf_state;
140 dma_addr_t bf_dmacontext; 143 dma_addr_t bf_dmacontext;
141}; 144};
142 145
143#define ATH_RXBUF_RESET(_bf) ((_bf)->bf_status = 0)
144#define ATH_BUFSTATUS_STALE 0x00000002
145
146struct ath_descdma { 146struct ath_descdma {
147 const char *dd_name;
148 struct ath_desc *dd_desc; 147 struct ath_desc *dd_desc;
149 dma_addr_t dd_desc_paddr; 148 dma_addr_t dd_desc_paddr;
150 u32 dd_desc_len; 149 u32 dd_desc_len;
151 struct ath_buf *dd_bufptr; 150 struct ath_buf *dd_bufptr;
152 dma_addr_t dd_dmacontext;
153}; 151};
154 152
155int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd, 153int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
@@ -295,26 +293,6 @@ struct ath_tx_control {
295#define ATH_TX_XRETRY 0x02 293#define ATH_TX_XRETRY 0x02
296#define ATH_TX_BAR 0x04 294#define ATH_TX_BAR 0x04
297 295
298/* All RSSI values are noise floor adjusted */
299struct ath_tx_stat {
300 int rssi;
301 int rssictl[ATH_MAX_ANTENNA];
302 int rssiextn[ATH_MAX_ANTENNA];
303 int rateieee;
304 int rateKbps;
305 int ratecode;
306 int flags;
307 u32 airtime; /* time on air per final tx rate */
308};
309
310struct aggr_rifs_param {
311 int param_max_frames;
312 int param_max_len;
313 int param_rl;
314 int param_al;
315 struct ath_rc_series *param_rcs;
316};
317
318struct ath_node { 296struct ath_node {
319 struct ath_softc *an_sc; 297 struct ath_softc *an_sc;
320 struct ath_atx_tid tid[WME_NUM_TID]; 298 struct ath_atx_tid tid[WME_NUM_TID];
@@ -362,7 +340,7 @@ void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an);
362void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an); 340void ath_tx_node_cleanup(struct ath_softc *sc, struct ath_node *an);
363void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq); 341void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq);
364int ath_tx_init(struct ath_softc *sc, int nbufs); 342int ath_tx_init(struct ath_softc *sc, int nbufs);
365int ath_tx_cleanup(struct ath_softc *sc); 343void ath_tx_cleanup(struct ath_softc *sc);
366struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb); 344struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb);
367int ath_txq_update(struct ath_softc *sc, int qnum, 345int ath_txq_update(struct ath_softc *sc, int qnum,
368 struct ath9k_tx_queue_info *q); 346 struct ath9k_tx_queue_info *q);
@@ -525,19 +503,18 @@ struct ath_rfkill {
525#define SC_OP_BEACONS BIT(1) 503#define SC_OP_BEACONS BIT(1)
526#define SC_OP_RXAGGR BIT(2) 504#define SC_OP_RXAGGR BIT(2)
527#define SC_OP_TXAGGR BIT(3) 505#define SC_OP_TXAGGR BIT(3)
528#define SC_OP_CHAINMASK_UPDATE BIT(4) 506#define SC_OP_FULL_RESET BIT(4)
529#define SC_OP_FULL_RESET BIT(5) 507#define SC_OP_PREAMBLE_SHORT BIT(5)
530#define SC_OP_PREAMBLE_SHORT BIT(6) 508#define SC_OP_PROTECT_ENABLE BIT(6)
531#define SC_OP_PROTECT_ENABLE BIT(7) 509#define SC_OP_RXFLUSH BIT(7)
532#define SC_OP_RXFLUSH BIT(8) 510#define SC_OP_LED_ASSOCIATED BIT(8)
533#define SC_OP_LED_ASSOCIATED BIT(9) 511#define SC_OP_RFKILL_REGISTERED BIT(9)
534#define SC_OP_RFKILL_REGISTERED BIT(10) 512#define SC_OP_RFKILL_SW_BLOCKED BIT(10)
535#define SC_OP_RFKILL_SW_BLOCKED BIT(11) 513#define SC_OP_RFKILL_HW_BLOCKED BIT(11)
536#define SC_OP_RFKILL_HW_BLOCKED BIT(12) 514#define SC_OP_WAIT_FOR_BEACON BIT(12)
537#define SC_OP_WAIT_FOR_BEACON BIT(13) 515#define SC_OP_LED_ON BIT(13)
538#define SC_OP_LED_ON BIT(14) 516#define SC_OP_SCANNING BIT(14)
539#define SC_OP_SCANNING BIT(15) 517#define SC_OP_TSF_RESET BIT(15)
540#define SC_OP_TSF_RESET BIT(16)
541 518
542struct ath_bus_ops { 519struct ath_bus_ops {
543 void (*read_cachesize)(struct ath_softc *sc, int *csz); 520 void (*read_cachesize)(struct ath_softc *sc, int *csz);
diff --git a/drivers/net/wireless/ath9k/beacon.c b/drivers/net/wireless/ath/ath9k/beacon.c
index ec995730632..eb4759fc6a0 100644
--- a/drivers/net/wireless/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -43,7 +43,7 @@ static int ath_beaconq_config(struct ath_softc *sc)
43 43
44 if (!ath9k_hw_set_txq_props(ah, sc->beacon.beaconq, &qi)) { 44 if (!ath9k_hw_set_txq_props(ah, sc->beacon.beaconq, &qi)) {
45 DPRINTF(sc, ATH_DBG_FATAL, 45 DPRINTF(sc, ATH_DBG_FATAL,
46 "unable to update h/w beacon queue parameters\n"); 46 "Unable to update h/w beacon queue parameters\n");
47 return 0; 47 return 0;
48 } else { 48 } else {
49 ath9k_hw_resettxqueue(ah, sc->beacon.beaconq); 49 ath9k_hw_resettxqueue(ah, sc->beacon.beaconq);
@@ -59,7 +59,7 @@ static int ath_beaconq_config(struct ath_softc *sc)
59static void ath_beacon_setup(struct ath_softc *sc, struct ath_vif *avp, 59static void ath_beacon_setup(struct ath_softc *sc, struct ath_vif *avp,
60 struct ath_buf *bf) 60 struct ath_buf *bf)
61{ 61{
62 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu; 62 struct sk_buff *skb = bf->bf_mpdu;
63 struct ath_hw *ah = sc->sc_ah; 63 struct ath_hw *ah = sc->sc_ah;
64 struct ath_desc *ds; 64 struct ath_desc *ds;
65 struct ath9k_11n_rate_series series[4]; 65 struct ath9k_11n_rate_series series[4];
@@ -132,16 +132,13 @@ static struct ath_buf *ath_beacon_generate(struct ieee80211_hw *hw,
132 avp = (void *)vif->drv_priv; 132 avp = (void *)vif->drv_priv;
133 cabq = sc->beacon.cabq; 133 cabq = sc->beacon.cabq;
134 134
135 if (avp->av_bcbuf == NULL) { 135 if (avp->av_bcbuf == NULL)
136 DPRINTF(sc, ATH_DBG_BEACON, "avp=%p av_bcbuf=%p\n",
137 avp, avp->av_bcbuf);
138 return NULL; 136 return NULL;
139 }
140 137
141 /* Release the old beacon first */ 138 /* Release the old beacon first */
142 139
143 bf = avp->av_bcbuf; 140 bf = avp->av_bcbuf;
144 skb = (struct sk_buff *)bf->bf_mpdu; 141 skb = bf->bf_mpdu;
145 if (skb) { 142 if (skb) {
146 dma_unmap_single(sc->dev, bf->bf_dmacontext, 143 dma_unmap_single(sc->dev, bf->bf_dmacontext,
147 skb->len, DMA_TO_DEVICE); 144 skb->len, DMA_TO_DEVICE);
@@ -229,7 +226,7 @@ static void ath_beacon_start_adhoc(struct ath_softc *sc,
229 return; 226 return;
230 227
231 bf = avp->av_bcbuf; 228 bf = avp->av_bcbuf;
232 skb = (struct sk_buff *) bf->bf_mpdu; 229 skb = bf->bf_mpdu;
233 230
234 ath_beacon_setup(sc, avp, bf); 231 ath_beacon_setup(sc, avp, bf);
235 232
@@ -302,7 +299,7 @@ int ath_beacon_alloc(struct ath_wiphy *aphy, struct ieee80211_vif *vif)
302 /* release the previous beacon frame, if it already exists. */ 299 /* release the previous beacon frame, if it already exists. */
303 bf = avp->av_bcbuf; 300 bf = avp->av_bcbuf;
304 if (bf->bf_mpdu != NULL) { 301 if (bf->bf_mpdu != NULL) {
305 skb = (struct sk_buff *)bf->bf_mpdu; 302 skb = bf->bf_mpdu;
306 dma_unmap_single(sc->dev, bf->bf_dmacontext, 303 dma_unmap_single(sc->dev, bf->bf_dmacontext,
307 skb->len, DMA_TO_DEVICE); 304 skb->len, DMA_TO_DEVICE);
308 dev_kfree_skb_any(skb); 305 dev_kfree_skb_any(skb);
@@ -374,7 +371,7 @@ void ath_beacon_return(struct ath_softc *sc, struct ath_vif *avp)
374 371
375 bf = avp->av_bcbuf; 372 bf = avp->av_bcbuf;
376 if (bf->bf_mpdu != NULL) { 373 if (bf->bf_mpdu != NULL) {
377 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu; 374 struct sk_buff *skb = bf->bf_mpdu;
378 dma_unmap_single(sc->dev, bf->bf_dmacontext, 375 dma_unmap_single(sc->dev, bf->bf_dmacontext,
379 skb->len, DMA_TO_DEVICE); 376 skb->len, DMA_TO_DEVICE);
380 dev_kfree_skb_any(skb); 377 dev_kfree_skb_any(skb);
diff --git a/drivers/net/wireless/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index e2d62e97131..a197041d76b 100644
--- a/drivers/net/wireless/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -186,7 +186,7 @@ static bool getNoiseFloorThresh(struct ath_hw *ah,
186} 186}
187 187
188static void ath9k_hw_setup_calibration(struct ath_hw *ah, 188static void ath9k_hw_setup_calibration(struct ath_hw *ah,
189 struct hal_cal_list *currCal) 189 struct ath9k_cal_list *currCal)
190{ 190{
191 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0), 191 REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4(0),
192 AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX, 192 AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX,
@@ -220,7 +220,7 @@ static void ath9k_hw_setup_calibration(struct ath_hw *ah,
220} 220}
221 221
222static void ath9k_hw_reset_calibration(struct ath_hw *ah, 222static void ath9k_hw_reset_calibration(struct ath_hw *ah,
223 struct hal_cal_list *currCal) 223 struct ath9k_cal_list *currCal)
224{ 224{
225 int i; 225 int i;
226 226
@@ -238,13 +238,12 @@ static void ath9k_hw_reset_calibration(struct ath_hw *ah,
238 ah->cal_samples = 0; 238 ah->cal_samples = 0;
239} 239}
240 240
241static void ath9k_hw_per_calibration(struct ath_hw *ah, 241static bool ath9k_hw_per_calibration(struct ath_hw *ah,
242 struct ath9k_channel *ichan, 242 struct ath9k_channel *ichan,
243 u8 rxchainmask, 243 u8 rxchainmask,
244 struct hal_cal_list *currCal, 244 struct ath9k_cal_list *currCal)
245 bool *isCalDone)
246{ 245{
247 *isCalDone = false; 246 bool iscaldone = false;
248 247
249 if (currCal->calState == CAL_RUNNING) { 248 if (currCal->calState == CAL_RUNNING) {
250 if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) & 249 if (!(REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
@@ -263,7 +262,7 @@ static void ath9k_hw_per_calibration(struct ath_hw *ah,
263 currCal->calData->calPostProc(ah, numChains); 262 currCal->calData->calPostProc(ah, numChains);
264 ichan->CalValid |= currCal->calData->calType; 263 ichan->CalValid |= currCal->calData->calType;
265 currCal->calState = CAL_DONE; 264 currCal->calState = CAL_DONE;
266 *isCalDone = true; 265 iscaldone = true;
267 } else { 266 } else {
268 ath9k_hw_setup_calibration(ah, currCal); 267 ath9k_hw_setup_calibration(ah, currCal);
269 } 268 }
@@ -271,11 +270,13 @@ static void ath9k_hw_per_calibration(struct ath_hw *ah,
271 } else if (!(ichan->CalValid & currCal->calData->calType)) { 270 } else if (!(ichan->CalValid & currCal->calData->calType)) {
272 ath9k_hw_reset_calibration(ah, currCal); 271 ath9k_hw_reset_calibration(ah, currCal);
273 } 272 }
273
274 return iscaldone;
274} 275}
275 276
276/* Assumes you are talking about the currently configured channel */ 277/* Assumes you are talking about the currently configured channel */
277static bool ath9k_hw_iscal_supported(struct ath_hw *ah, 278static bool ath9k_hw_iscal_supported(struct ath_hw *ah,
278 enum hal_cal_types calType) 279 enum ath9k_cal_types calType)
279{ 280{
280 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf; 281 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
281 282
@@ -284,8 +285,8 @@ static bool ath9k_hw_iscal_supported(struct ath_hw *ah,
284 return true; 285 return true;
285 case ADC_GAIN_CAL: 286 case ADC_GAIN_CAL:
286 case ADC_DC_CAL: 287 case ADC_DC_CAL:
287 if (conf->channel->band == IEEE80211_BAND_5GHZ && 288 if (!(conf->channel->band == IEEE80211_BAND_2GHZ &&
288 conf_is_ht20(conf)) 289 conf_is_ht20(conf)))
289 return true; 290 return true;
290 break; 291 break;
291 } 292 }
@@ -498,7 +499,7 @@ static void ath9k_hw_adc_dccal_calibrate(struct ath_hw *ah, u8 numChains)
498{ 499{
499 u32 iOddMeasOffset, iEvenMeasOffset, val, i; 500 u32 iOddMeasOffset, iEvenMeasOffset, val, i;
500 int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch; 501 int32_t qOddMeasOffset, qEvenMeasOffset, qDcMismatch, iDcMismatch;
501 const struct hal_percal_data *calData = 502 const struct ath9k_percal_data *calData =
502 ah->cal_list_curr->calData; 503 ah->cal_list_curr->calData;
503 u32 numSamples = 504 u32 numSamples =
504 (1 << (calData->calCountMax + 5)) * calData->calNumSamples; 505 (1 << (calData->calCountMax + 5)) * calData->calNumSamples;
@@ -555,7 +556,7 @@ static void ath9k_hw_adc_dccal_calibrate(struct ath_hw *ah, u8 numChains)
555bool ath9k_hw_reset_calvalid(struct ath_hw *ah) 556bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
556{ 557{
557 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf; 558 struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
558 struct hal_cal_list *currCal = ah->cal_list_curr; 559 struct ath9k_cal_list *currCal = ah->cal_list_curr;
559 560
560 if (!ah->curchan) 561 if (!ah->curchan)
561 return true; 562 return true;
@@ -841,23 +842,21 @@ static inline void ath9k_hw_9285_pa_cal(struct ath_hw *ah)
841} 842}
842 843
843bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan, 844bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
844 u8 rxchainmask, bool longcal, 845 u8 rxchainmask, bool longcal)
845 bool *isCalDone)
846{ 846{
847 struct hal_cal_list *currCal = ah->cal_list_curr; 847 bool iscaldone = true;
848 848 struct ath9k_cal_list *currCal = ah->cal_list_curr;
849 *isCalDone = true;
850 849
851 if (currCal && 850 if (currCal &&
852 (currCal->calState == CAL_RUNNING || 851 (currCal->calState == CAL_RUNNING ||
853 currCal->calState == CAL_WAITING)) { 852 currCal->calState == CAL_WAITING)) {
854 ath9k_hw_per_calibration(ah, chan, rxchainmask, currCal, 853 iscaldone = ath9k_hw_per_calibration(ah, chan,
855 isCalDone); 854 rxchainmask, currCal);
856 if (*isCalDone) { 855 if (iscaldone) {
857 ah->cal_list_curr = currCal = currCal->calNext; 856 ah->cal_list_curr = currCal = currCal->calNext;
858 857
859 if (currCal->calState == CAL_WAITING) { 858 if (currCal->calState == CAL_WAITING) {
860 *isCalDone = false; 859 iscaldone = false;
861 ath9k_hw_reset_calibration(ah, currCal); 860 ath9k_hw_reset_calibration(ah, currCal);
862 } 861 }
863 } 862 }
@@ -872,18 +871,15 @@ bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
872 ath9k_hw_getnf(ah, chan); 871 ath9k_hw_getnf(ah, chan);
873 ath9k_hw_loadnf(ah, ah->curchan); 872 ath9k_hw_loadnf(ah, ah->curchan);
874 ath9k_hw_start_nfcal(ah); 873 ath9k_hw_start_nfcal(ah);
875
876 if (chan->channelFlags & CHANNEL_CW_INT)
877 chan->channelFlags &= ~CHANNEL_CW_INT;
878 } 874 }
879 875
880 return true; 876 return iscaldone;
881} 877}
882 878
883static bool ar9285_clc(struct ath_hw *ah, struct ath9k_channel *chan) 879static bool ar9285_clc(struct ath_hw *ah, struct ath9k_channel *chan)
884{ 880{
885 REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); 881 REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE);
886 if (chan->channelFlags & CHANNEL_HT20) { 882 if (IS_CHAN_HT20(chan)) {
887 REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE); 883 REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_PARALLEL_CAL_ENABLE);
888 REG_SET_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN); 884 REG_SET_BIT(ah, AR_PHY_TURBO, AR_PHY_FC_DYN2040_EN);
889 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, 885 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
@@ -919,83 +915,66 @@ static bool ar9285_clc(struct ath_hw *ah, struct ath9k_channel *chan)
919 return true; 915 return true;
920} 916}
921 917
922bool ath9k_hw_init_cal(struct ath_hw *ah, 918bool ath9k_hw_init_cal(struct ath_hw *ah, struct ath9k_channel *chan)
923 struct ath9k_channel *chan)
924{ 919{
925 if (AR_SREV_9285(ah) && AR_SREV_9285_12_OR_LATER(ah)) { 920 if (AR_SREV_9285(ah) && AR_SREV_9285_12_OR_LATER(ah)) {
926 if (!ar9285_clc(ah, chan)) 921 if (!ar9285_clc(ah, chan))
927 return false; 922 return false;
928 } else if (AR_SREV_9280_10_OR_LATER(ah)) { 923 } else {
929 REG_CLR_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC); 924 if (AR_SREV_9280_10_OR_LATER(ah)) {
930 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL); 925 REG_CLR_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
931 REG_CLR_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); 926 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
927 }
932 928
933 /* Kick off the cal */ 929 /* Calibrate the AGC */
934 REG_WRITE(ah, AR_PHY_AGC_CONTROL, 930 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
935 REG_READ(ah, AR_PHY_AGC_CONTROL) | 931 REG_READ(ah, AR_PHY_AGC_CONTROL) |
936 AR_PHY_AGC_CONTROL_CAL); 932 AR_PHY_AGC_CONTROL_CAL);
937 933
938 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, 934 /* Poll for offset calibration complete */
939 AR_PHY_AGC_CONTROL_CAL, 0, 935 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL,
940 AH_WAIT_TIMEOUT)) { 936 0, AH_WAIT_TIMEOUT)) {
941 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 937 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
942 "offset calibration failed to complete in 1ms; " 938 "offset calibration failed to complete in 1ms; "
943 "noisy environment?\n"); 939 "noisy environment?\n");
944 return false; 940 return false;
945 } 941 }
946 942
947 REG_CLR_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC); 943 if (AR_SREV_9280_10_OR_LATER(ah)) {
948 REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL); 944 REG_SET_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
949 REG_SET_BIT(ah, AR_PHY_CL_CAL_CTL, AR_PHY_CL_CAL_ENABLE); 945 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
950 } 946 }
951
952 /* Calibrate the AGC */
953 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
954 REG_READ(ah, AR_PHY_AGC_CONTROL) |
955 AR_PHY_AGC_CONTROL_CAL);
956
957 if (!ath9k_hw_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL,
958 0, AH_WAIT_TIMEOUT)) {
959 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
960 "offset calibration failed to complete in 1ms; "
961 "noisy environment?\n");
962 return false;
963 }
964
965 if (AR_SREV_9280_10_OR_LATER(ah)) {
966 REG_SET_BIT(ah, AR_PHY_ADC_CTL, AR_PHY_ADC_CTL_OFF_PWDADC);
967 REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_FLTR_CAL);
968 } 947 }
969 948
970 /* Do PA Calibration */ 949 /* Do PA Calibration */
971 if (AR_SREV_9285(ah) && AR_SREV_9285_11_OR_LATER(ah)) 950 if (AR_SREV_9285(ah) && AR_SREV_9285_11_OR_LATER(ah))
972 ath9k_hw_9285_pa_cal(ah); 951 ath9k_hw_9285_pa_cal(ah);
973 952
974 /* Do NF Calibration */ 953 /* Do NF Calibration after DC offset and other calibrations */
975 REG_WRITE(ah, AR_PHY_AGC_CONTROL, 954 REG_WRITE(ah, AR_PHY_AGC_CONTROL,
976 REG_READ(ah, AR_PHY_AGC_CONTROL) | 955 REG_READ(ah, AR_PHY_AGC_CONTROL) | AR_PHY_AGC_CONTROL_NF);
977 AR_PHY_AGC_CONTROL_NF);
978 956
979 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL; 957 ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
980 958
959 /* Enable IQ, ADC Gain and ADC DC offset CALs */
981 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) { 960 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah)) {
982 if (ath9k_hw_iscal_supported(ah, ADC_GAIN_CAL)) { 961 if (ath9k_hw_iscal_supported(ah, ADC_GAIN_CAL)) {
983 INIT_CAL(&ah->adcgain_caldata); 962 INIT_CAL(&ah->adcgain_caldata);
984 INSERT_CAL(ah, &ah->adcgain_caldata); 963 INSERT_CAL(ah, &ah->adcgain_caldata);
985 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 964 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
986 "enabling ADC Gain Calibration.\n"); 965 "enabling ADC Gain Calibration.\n");
987 } 966 }
988 if (ath9k_hw_iscal_supported(ah, ADC_DC_CAL)) { 967 if (ath9k_hw_iscal_supported(ah, ADC_DC_CAL)) {
989 INIT_CAL(&ah->adcdc_caldata); 968 INIT_CAL(&ah->adcdc_caldata);
990 INSERT_CAL(ah, &ah->adcdc_caldata); 969 INSERT_CAL(ah, &ah->adcdc_caldata);
991 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 970 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
992 "enabling ADC DC Calibration.\n"); 971 "enabling ADC DC Calibration.\n");
993 } 972 }
994 if (ath9k_hw_iscal_supported(ah, IQ_MISMATCH_CAL)) { 973 if (ath9k_hw_iscal_supported(ah, IQ_MISMATCH_CAL)) {
995 INIT_CAL(&ah->iq_caldata); 974 INIT_CAL(&ah->iq_caldata);
996 INSERT_CAL(ah, &ah->iq_caldata); 975 INSERT_CAL(ah, &ah->iq_caldata);
997 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE, 976 DPRINTF(ah->ah_sc, ATH_DBG_CALIBRATE,
998 "enabling IQ Calibration.\n"); 977 "enabling IQ Calibration.\n");
999 } 978 }
1000 979
1001 ah->cal_list_curr = ah->cal_list; 980 ah->cal_list_curr = ah->cal_list;
@@ -1009,49 +988,49 @@ bool ath9k_hw_init_cal(struct ath_hw *ah,
1009 return true; 988 return true;
1010} 989}
1011 990
1012const struct hal_percal_data iq_cal_multi_sample = { 991const struct ath9k_percal_data iq_cal_multi_sample = {
1013 IQ_MISMATCH_CAL, 992 IQ_MISMATCH_CAL,
1014 MAX_CAL_SAMPLES, 993 MAX_CAL_SAMPLES,
1015 PER_MIN_LOG_COUNT, 994 PER_MIN_LOG_COUNT,
1016 ath9k_hw_iqcal_collect, 995 ath9k_hw_iqcal_collect,
1017 ath9k_hw_iqcalibrate 996 ath9k_hw_iqcalibrate
1018}; 997};
1019const struct hal_percal_data iq_cal_single_sample = { 998const struct ath9k_percal_data iq_cal_single_sample = {
1020 IQ_MISMATCH_CAL, 999 IQ_MISMATCH_CAL,
1021 MIN_CAL_SAMPLES, 1000 MIN_CAL_SAMPLES,
1022 PER_MAX_LOG_COUNT, 1001 PER_MAX_LOG_COUNT,
1023 ath9k_hw_iqcal_collect, 1002 ath9k_hw_iqcal_collect,
1024 ath9k_hw_iqcalibrate 1003 ath9k_hw_iqcalibrate
1025}; 1004};
1026const struct hal_percal_data adc_gain_cal_multi_sample = { 1005const struct ath9k_percal_data adc_gain_cal_multi_sample = {
1027 ADC_GAIN_CAL, 1006 ADC_GAIN_CAL,
1028 MAX_CAL_SAMPLES, 1007 MAX_CAL_SAMPLES,
1029 PER_MIN_LOG_COUNT, 1008 PER_MIN_LOG_COUNT,
1030 ath9k_hw_adc_gaincal_collect, 1009 ath9k_hw_adc_gaincal_collect,
1031 ath9k_hw_adc_gaincal_calibrate 1010 ath9k_hw_adc_gaincal_calibrate
1032}; 1011};
1033const struct hal_percal_data adc_gain_cal_single_sample = { 1012const struct ath9k_percal_data adc_gain_cal_single_sample = {
1034 ADC_GAIN_CAL, 1013 ADC_GAIN_CAL,
1035 MIN_CAL_SAMPLES, 1014 MIN_CAL_SAMPLES,
1036 PER_MAX_LOG_COUNT, 1015 PER_MAX_LOG_COUNT,
1037 ath9k_hw_adc_gaincal_collect, 1016 ath9k_hw_adc_gaincal_collect,
1038 ath9k_hw_adc_gaincal_calibrate 1017 ath9k_hw_adc_gaincal_calibrate
1039}; 1018};
1040const struct hal_percal_data adc_dc_cal_multi_sample = { 1019const struct ath9k_percal_data adc_dc_cal_multi_sample = {
1041 ADC_DC_CAL, 1020 ADC_DC_CAL,
1042 MAX_CAL_SAMPLES, 1021 MAX_CAL_SAMPLES,
1043 PER_MIN_LOG_COUNT, 1022 PER_MIN_LOG_COUNT,
1044 ath9k_hw_adc_dccal_collect, 1023 ath9k_hw_adc_dccal_collect,
1045 ath9k_hw_adc_dccal_calibrate 1024 ath9k_hw_adc_dccal_calibrate
1046}; 1025};
1047const struct hal_percal_data adc_dc_cal_single_sample = { 1026const struct ath9k_percal_data adc_dc_cal_single_sample = {
1048 ADC_DC_CAL, 1027 ADC_DC_CAL,
1049 MIN_CAL_SAMPLES, 1028 MIN_CAL_SAMPLES,
1050 PER_MAX_LOG_COUNT, 1029 PER_MAX_LOG_COUNT,
1051 ath9k_hw_adc_dccal_collect, 1030 ath9k_hw_adc_dccal_collect,
1052 ath9k_hw_adc_dccal_calibrate 1031 ath9k_hw_adc_dccal_calibrate
1053}; 1032};
1054const struct hal_percal_data adc_init_dc_cal = { 1033const struct ath9k_percal_data adc_init_dc_cal = {
1055 ADC_DC_INIT_CAL, 1034 ADC_DC_INIT_CAL,
1056 MIN_CAL_SAMPLES, 1035 MIN_CAL_SAMPLES,
1057 INIT_LOG_COUNT, 1036 INIT_LOG_COUNT,
diff --git a/drivers/net/wireless/ath9k/calib.h b/drivers/net/wireless/ath/ath9k/calib.h
index 1c74bd50700..fe5367f1414 100644
--- a/drivers/net/wireless/ath9k/calib.h
+++ b/drivers/net/wireless/ath/ath9k/calib.h
@@ -17,13 +17,13 @@
17#ifndef CALIB_H 17#ifndef CALIB_H
18#define CALIB_H 18#define CALIB_H
19 19
20extern const struct hal_percal_data iq_cal_multi_sample; 20extern const struct ath9k_percal_data iq_cal_multi_sample;
21extern const struct hal_percal_data iq_cal_single_sample; 21extern const struct ath9k_percal_data iq_cal_single_sample;
22extern const struct hal_percal_data adc_gain_cal_multi_sample; 22extern const struct ath9k_percal_data adc_gain_cal_multi_sample;
23extern const struct hal_percal_data adc_gain_cal_single_sample; 23extern const struct ath9k_percal_data adc_gain_cal_single_sample;
24extern const struct hal_percal_data adc_dc_cal_multi_sample; 24extern const struct ath9k_percal_data adc_dc_cal_multi_sample;
25extern const struct hal_percal_data adc_dc_cal_single_sample; 25extern const struct ath9k_percal_data adc_dc_cal_single_sample;
26extern const struct hal_percal_data adc_init_dc_cal; 26extern const struct ath9k_percal_data adc_init_dc_cal;
27 27
28#define AR_PHY_CCA_MAX_GOOD_VALUE -85 28#define AR_PHY_CCA_MAX_GOOD_VALUE -85
29#define AR_PHY_CCA_MAX_HIGH_VALUE -62 29#define AR_PHY_CCA_MAX_HIGH_VALUE -62
@@ -67,14 +67,14 @@ struct ar5416IniArray {
67 } \ 67 } \
68 } while (0) 68 } while (0)
69 69
70enum hal_cal_types { 70enum ath9k_cal_types {
71 ADC_DC_INIT_CAL = 0x1, 71 ADC_DC_INIT_CAL = 0x1,
72 ADC_GAIN_CAL = 0x2, 72 ADC_GAIN_CAL = 0x2,
73 ADC_DC_CAL = 0x4, 73 ADC_DC_CAL = 0x4,
74 IQ_MISMATCH_CAL = 0x8 74 IQ_MISMATCH_CAL = 0x8
75}; 75};
76 76
77enum hal_cal_state { 77enum ath9k_cal_state {
78 CAL_INACTIVE, 78 CAL_INACTIVE,
79 CAL_WAITING, 79 CAL_WAITING,
80 CAL_RUNNING, 80 CAL_RUNNING,
@@ -87,18 +87,18 @@ enum hal_cal_state {
87#define PER_MIN_LOG_COUNT 2 87#define PER_MIN_LOG_COUNT 2
88#define PER_MAX_LOG_COUNT 10 88#define PER_MAX_LOG_COUNT 10
89 89
90struct hal_percal_data { 90struct ath9k_percal_data {
91 enum hal_cal_types calType; 91 enum ath9k_cal_types calType;
92 u32 calNumSamples; 92 u32 calNumSamples;
93 u32 calCountMax; 93 u32 calCountMax;
94 void (*calCollect) (struct ath_hw *); 94 void (*calCollect) (struct ath_hw *);
95 void (*calPostProc) (struct ath_hw *, u8); 95 void (*calPostProc) (struct ath_hw *, u8);
96}; 96};
97 97
98struct hal_cal_list { 98struct ath9k_cal_list {
99 const struct hal_percal_data *calData; 99 const struct ath9k_percal_data *calData;
100 enum hal_cal_state calState; 100 enum ath9k_cal_state calState;
101 struct hal_cal_list *calNext; 101 struct ath9k_cal_list *calNext;
102}; 102};
103 103
104struct ath9k_nfcal_hist { 104struct ath9k_nfcal_hist {
@@ -116,8 +116,7 @@ int16_t ath9k_hw_getnf(struct ath_hw *ah,
116void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah); 116void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
117s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan); 117s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
118bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan, 118bool ath9k_hw_calibrate(struct ath_hw *ah, struct ath9k_channel *chan,
119 u8 rxchainmask, bool longcal, 119 u8 rxchainmask, bool longcal);
120 bool *isCalDone);
121bool ath9k_hw_init_cal(struct ath_hw *ah, 120bool ath9k_hw_init_cal(struct ath_hw *ah,
122 struct ath9k_channel *chan); 121 struct ath9k_channel *chan);
123 122
diff --git a/drivers/net/wireless/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index fdf9528fa49..97df20cbf52 100644
--- a/drivers/net/wireless/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -498,6 +498,9 @@ int ath9k_init_debug(struct ath_softc *sc)
498{ 498{
499 sc->debug.debug_mask = ath9k_debug; 499 sc->debug.debug_mask = ath9k_debug;
500 500
501 if (!ath9k_debugfs_root)
502 return -ENOENT;
503
501 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy), 504 sc->debug.debugfs_phy = debugfs_create_dir(wiphy_name(sc->hw->wiphy),
502 ath9k_debugfs_root); 505 ath9k_debugfs_root);
503 if (!sc->debug.debugfs_phy) 506 if (!sc->debug.debugfs_phy)
diff --git a/drivers/net/wireless/ath9k/debug.h b/drivers/net/wireless/ath/ath9k/debug.h
index 7b0e5419d2b..23298b90b52 100644
--- a/drivers/net/wireless/ath9k/debug.h
+++ b/drivers/net/wireless/ath/ath9k/debug.h
@@ -19,20 +19,16 @@
19 19
20enum ATH_DEBUG { 20enum ATH_DEBUG {
21 ATH_DBG_RESET = 0x00000001, 21 ATH_DBG_RESET = 0x00000001,
22 ATH_DBG_REG_IO = 0x00000002, 22 ATH_DBG_QUEUE = 0x00000002,
23 ATH_DBG_QUEUE = 0x00000004, 23 ATH_DBG_EEPROM = 0x00000004,
24 ATH_DBG_EEPROM = 0x00000008, 24 ATH_DBG_CALIBRATE = 0x00000008,
25 ATH_DBG_CALIBRATE = 0x00000010, 25 ATH_DBG_INTERRUPT = 0x00000010,
26 ATH_DBG_CHANNEL = 0x00000020, 26 ATH_DBG_REGULATORY = 0x00000020,
27 ATH_DBG_INTERRUPT = 0x00000040, 27 ATH_DBG_ANI = 0x00000040,
28 ATH_DBG_REGULATORY = 0x00000080, 28 ATH_DBG_XMIT = 0x00000080,
29 ATH_DBG_ANI = 0x00000100, 29 ATH_DBG_BEACON = 0x00000100,
30 ATH_DBG_POWER_MGMT = 0x00000200, 30 ATH_DBG_CONFIG = 0x00000200,
31 ATH_DBG_XMIT = 0x00000400, 31 ATH_DBG_FATAL = 0x00000400,
32 ATH_DBG_BEACON = 0x00001000,
33 ATH_DBG_CONFIG = 0x00002000,
34 ATH_DBG_KEYCACHE = 0x00004000,
35 ATH_DBG_FATAL = 0x00008000,
36 ATH_DBG_ANY = 0xffffffff 32 ATH_DBG_ANY = 0xffffffff
37}; 33};
38 34
diff --git a/drivers/net/wireless/ath9k/eeprom.c b/drivers/net/wireless/ath/ath9k/eeprom.c
index ffc36b0361c..44fee5ae892 100644
--- a/drivers/net/wireless/ath9k/eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom.c
@@ -783,11 +783,11 @@ static bool ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
783 ((pdadcValues[4 * j + 3] & 0xFF) << 24); 783 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
784 REG_WRITE(ah, regOffset, reg32); 784 REG_WRITE(ah, regOffset, reg32);
785 785
786 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 786 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
787 "PDADC (%d,%4x): %4.4x %8.8x\n", 787 "PDADC (%d,%4x): %4.4x %8.8x\n",
788 i, regChainOffset, regOffset, 788 i, regChainOffset, regOffset,
789 reg32); 789 reg32);
790 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 790 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
791 "PDADC: Chain %d | " 791 "PDADC: Chain %d | "
792 "PDADC %3d Value %3d | " 792 "PDADC %3d Value %3d | "
793 "PDADC %3d Value %3d | " 793 "PDADC %3d Value %3d | "
@@ -910,7 +910,7 @@ static bool ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
910 ah->eep_ops->get_eeprom_rev(ah) <= 2) 910 ah->eep_ops->get_eeprom_rev(ah) <= 2)
911 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; 911 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
912 912
913 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 913 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
914 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, " 914 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
915 "EXT_ADDITIVE %d\n", 915 "EXT_ADDITIVE %d\n",
916 ctlMode, numCtlModes, isHt40CtlMode, 916 ctlMode, numCtlModes, isHt40CtlMode,
@@ -918,7 +918,7 @@ static bool ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
918 918
919 for (i = 0; (i < AR5416_NUM_CTLS) && 919 for (i = 0; (i < AR5416_NUM_CTLS) &&
920 pEepData->ctlIndex[i]; i++) { 920 pEepData->ctlIndex[i]; i++) {
921 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 921 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
922 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x " 922 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
923 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x " 923 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
924 "chan %d\n", 924 "chan %d\n",
@@ -941,7 +941,7 @@ static bool ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
941 IS_CHAN_2GHZ(chan), 941 IS_CHAN_2GHZ(chan),
942 AR5416_EEP4K_NUM_BAND_EDGES); 942 AR5416_EEP4K_NUM_BAND_EDGES);
943 943
944 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 944 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
945 " MATCH-EE_IDX %d: ch %d is2 %d " 945 " MATCH-EE_IDX %d: ch %d is2 %d "
946 "2xMinEdge %d chainmask %d chains %d\n", 946 "2xMinEdge %d chainmask %d chains %d\n",
947 i, freq, IS_CHAN_2GHZ(chan), 947 i, freq, IS_CHAN_2GHZ(chan),
@@ -961,7 +961,7 @@ static bool ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
961 961
962 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower); 962 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
963 963
964 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 964 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
965 " SEL-Min ctlMode %d pCtlMode %d " 965 " SEL-Min ctlMode %d pCtlMode %d "
966 "2xMaxEdge %d sP %d minCtlPwr %d\n", 966 "2xMaxEdge %d sP %d minCtlPwr %d\n",
967 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower, 967 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
@@ -2234,11 +2234,11 @@ static bool ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
2234 ((pdadcValues[4 * j + 3] & 0xFF) << 24); 2234 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
2235 REG_WRITE(ah, regOffset, reg32); 2235 REG_WRITE(ah, regOffset, reg32);
2236 2236
2237 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 2237 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2238 "PDADC (%d,%4x): %4.4x %8.8x\n", 2238 "PDADC (%d,%4x): %4.4x %8.8x\n",
2239 i, regChainOffset, regOffset, 2239 i, regChainOffset, regOffset,
2240 reg32); 2240 reg32);
2241 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 2241 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2242 "PDADC: Chain %d | PDADC %3d " 2242 "PDADC: Chain %d | PDADC %3d "
2243 "Value %3d | PDADC %3d Value %3d | " 2243 "Value %3d | PDADC %3d Value %3d | "
2244 "PDADC %3d Value %3d | PDADC %3d " 2244 "PDADC %3d Value %3d | PDADC %3d "
@@ -2415,14 +2415,14 @@ static bool ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
2415 ah->eep_ops->get_eeprom_rev(ah) <= 2) 2415 ah->eep_ops->get_eeprom_rev(ah) <= 2)
2416 twiceMaxEdgePower = AR5416_MAX_RATE_POWER; 2416 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
2417 2417
2418 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 2418 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2419 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, " 2419 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
2420 "EXT_ADDITIVE %d\n", 2420 "EXT_ADDITIVE %d\n",
2421 ctlMode, numCtlModes, isHt40CtlMode, 2421 ctlMode, numCtlModes, isHt40CtlMode,
2422 (pCtlMode[ctlMode] & EXT_ADDITIVE)); 2422 (pCtlMode[ctlMode] & EXT_ADDITIVE));
2423 2423
2424 for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) { 2424 for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
2425 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 2425 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2426 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x " 2426 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
2427 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x " 2427 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
2428 "chan %d\n", 2428 "chan %d\n",
@@ -2441,7 +2441,7 @@ static bool ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
2441 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1], 2441 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
2442 IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES); 2442 IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
2443 2443
2444 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 2444 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2445 " MATCH-EE_IDX %d: ch %d is2 %d " 2445 " MATCH-EE_IDX %d: ch %d is2 %d "
2446 "2xMinEdge %d chainmask %d chains %d\n", 2446 "2xMinEdge %d chainmask %d chains %d\n",
2447 i, freq, IS_CHAN_2GHZ(chan), 2447 i, freq, IS_CHAN_2GHZ(chan),
@@ -2460,7 +2460,7 @@ static bool ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
2460 2460
2461 minCtlPower = min(twiceMaxEdgePower, scaledPower); 2461 minCtlPower = min(twiceMaxEdgePower, scaledPower);
2462 2462
2463 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 2463 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2464 " SEL-Min ctlMode %d pCtlMode %d " 2464 " SEL-Min ctlMode %d pCtlMode %d "
2465 "2xMaxEdge %d sP %d minCtlPwr %d\n", 2465 "2xMaxEdge %d sP %d minCtlPwr %d\n",
2466 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower, 2466 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
diff --git a/drivers/net/wireless/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h
index 25b68c881ff..7c59dc47f91 100644
--- a/drivers/net/wireless/ath9k/eeprom.h
+++ b/drivers/net/wireless/ath/ath9k/eeprom.h
@@ -17,6 +17,8 @@
17#ifndef EEPROM_H 17#ifndef EEPROM_H
18#define EEPROM_H 18#define EEPROM_H
19 19
20#include <net/cfg80211.h>
21
20#define AH_USE_EEPROM 0x1 22#define AH_USE_EEPROM 0x1
21 23
22#ifdef __BIG_ENDIAN 24#ifdef __BIG_ENDIAN
diff --git a/drivers/net/wireless/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index b15eaf8417f..ec2a7a40b00 100644
--- a/drivers/net/wireless/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -97,7 +97,7 @@ bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
97 udelay(AH_TIME_QUANTUM); 97 udelay(AH_TIME_QUANTUM);
98 } 98 }
99 99
100 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 100 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
101 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n", 101 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
102 timeout, reg, REG_READ(ah, reg), mask, val); 102 timeout, reg, REG_READ(ah, reg), mask, val);
103 103
@@ -181,7 +181,7 @@ u16 ath9k_hw_computetxtime(struct ath_hw *ah,
181 } 181 }
182 break; 182 break;
183 default: 183 default:
184 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 184 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
185 "Unknown phy %u (rate ix %u)\n", 185 "Unknown phy %u (rate ix %u)\n",
186 rates->info[rateix].phy, rateix); 186 rates->info[rateix].phy, rateix);
187 txTime = 0; 187 txTime = 0;
@@ -306,7 +306,7 @@ static bool ath9k_hw_chip_test(struct ath_hw *ah)
306 REG_WRITE(ah, addr, wrData); 306 REG_WRITE(ah, addr, wrData);
307 rdData = REG_READ(ah, addr); 307 rdData = REG_READ(ah, addr);
308 if (rdData != wrData) { 308 if (rdData != wrData) {
309 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 309 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
310 "address test failed " 310 "address test failed "
311 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n", 311 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
312 addr, wrData, rdData); 312 addr, wrData, rdData);
@@ -318,7 +318,7 @@ static bool ath9k_hw_chip_test(struct ath_hw *ah)
318 REG_WRITE(ah, addr, wrData); 318 REG_WRITE(ah, addr, wrData);
319 rdData = REG_READ(ah, addr); 319 rdData = REG_READ(ah, addr);
320 if (wrData != rdData) { 320 if (wrData != rdData) {
321 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 321 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
322 "address test failed " 322 "address test failed "
323 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n", 323 "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
324 addr, wrData, rdData); 324 addr, wrData, rdData);
@@ -363,10 +363,7 @@ static void ath9k_hw_set_defaults(struct ath_hw *ah)
363 ah->config.ack_6mb = 0x0; 363 ah->config.ack_6mb = 0x0;
364 ah->config.cwm_ignore_extcca = 0; 364 ah->config.cwm_ignore_extcca = 0;
365 ah->config.pcie_powersave_enable = 0; 365 ah->config.pcie_powersave_enable = 0;
366 ah->config.pcie_l1skp_enable = 0;
367 ah->config.pcie_clock_req = 0; 366 ah->config.pcie_clock_req = 0;
368 ah->config.pcie_power_reset = 0x100;
369 ah->config.pcie_restore = 0;
370 ah->config.pcie_waen = 0; 367 ah->config.pcie_waen = 0;
371 ah->config.analog_shiftreg = 1; 368 ah->config.analog_shiftreg = 1;
372 ah->config.ht_enable = 1; 369 ah->config.ht_enable = 1;
@@ -375,13 +372,6 @@ static void ath9k_hw_set_defaults(struct ath_hw *ah)
375 ah->config.cck_trig_high = 200; 372 ah->config.cck_trig_high = 200;
376 ah->config.cck_trig_low = 100; 373 ah->config.cck_trig_low = 100;
377 ah->config.enable_ani = 1; 374 ah->config.enable_ani = 1;
378 ah->config.noise_immunity_level = 4;
379 ah->config.ofdm_weaksignal_det = 1;
380 ah->config.cck_weaksignal_thr = 0;
381 ah->config.spur_immunity_level = 2;
382 ah->config.firstep_level = 0;
383 ah->config.rssi_thr_high = 40;
384 ah->config.rssi_thr_low = 7;
385 ah->config.diversity_control = 0; 375 ah->config.diversity_control = 0;
386 ah->config.antenna_switch_swap = 0; 376 ah->config.antenna_switch_swap = 0;
387 377
@@ -390,7 +380,7 @@ static void ath9k_hw_set_defaults(struct ath_hw *ah)
390 ah->config.spurchans[i][1] = AR_NO_SPUR; 380 ah->config.spurchans[i][1] = AR_NO_SPUR;
391 } 381 }
392 382
393 ah->config.intr_mitigation = 1; 383 ah->config.intr_mitigation = true;
394 384
395 /* 385 /*
396 * We need this for PCI devices only (Cardbus, PCI, miniPCI) 386 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
@@ -463,8 +453,8 @@ static int ath9k_hw_rfattach(struct ath_hw *ah)
463 453
464 rfStatus = ath9k_hw_init_rf(ah, &ecode); 454 rfStatus = ath9k_hw_init_rf(ah, &ecode);
465 if (!rfStatus) { 455 if (!rfStatus) {
466 DPRINTF(ah->ah_sc, ATH_DBG_RESET, 456 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
467 "RF setup failed, status %u\n", ecode); 457 "RF setup failed, status: %u\n", ecode);
468 return ecode; 458 return ecode;
469 } 459 }
470 460
@@ -488,10 +478,9 @@ static int ath9k_hw_rf_claim(struct ath_hw *ah)
488 case AR_RAD2122_SREV_MAJOR: 478 case AR_RAD2122_SREV_MAJOR:
489 break; 479 break;
490 default: 480 default:
491 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 481 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
492 "5G Radio Chip Rev 0x%02X is not " 482 "Radio Chip Rev 0x%02X not supported\n",
493 "supported by this driver\n", 483 val & AR_RADIO_SREV_MAJOR);
494 ah->hw_version.analog5GhzRev);
495 return -EOPNOTSUPP; 484 return -EOPNOTSUPP;
496 } 485 }
497 486
@@ -513,12 +502,8 @@ static int ath9k_hw_init_macaddr(struct ath_hw *ah)
513 ah->macaddr[2 * i] = eeval >> 8; 502 ah->macaddr[2 * i] = eeval >> 8;
514 ah->macaddr[2 * i + 1] = eeval & 0xff; 503 ah->macaddr[2 * i + 1] = eeval & 0xff;
515 } 504 }
516 if (sum == 0 || sum == 0xffff * 3) { 505 if (sum == 0 || sum == 0xffff * 3)
517 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
518 "mac address read failed: %pM\n",
519 ah->macaddr);
520 return -EADDRNOTAVAIL; 506 return -EADDRNOTAVAIL;
521 }
522 507
523 return 0; 508 return 0;
524} 509}
@@ -575,11 +560,8 @@ static int ath9k_hw_post_attach(struct ath_hw *ah)
575{ 560{
576 int ecode; 561 int ecode;
577 562
578 if (!ath9k_hw_chip_test(ah)) { 563 if (!ath9k_hw_chip_test(ah))
579 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
580 "hardware self-test failed\n");
581 return -ENODEV; 564 return -ENODEV;
582 }
583 565
584 ecode = ath9k_hw_rf_claim(ah); 566 ecode = ath9k_hw_rf_claim(ah);
585 if (ecode != 0) 567 if (ecode != 0)
@@ -617,17 +599,14 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
617 599
618 ath9k_hw_set_defaults(ah); 600 ath9k_hw_set_defaults(ah);
619 601
620 if (ah->config.intr_mitigation != 0)
621 ah->intr_mitigation = true;
622
623 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { 602 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
624 DPRINTF(sc, ATH_DBG_RESET, "Couldn't reset chip\n"); 603 DPRINTF(sc, ATH_DBG_FATAL, "Couldn't reset chip\n");
625 ecode = -EIO; 604 ecode = -EIO;
626 goto bad; 605 goto bad;
627 } 606 }
628 607
629 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) { 608 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
630 DPRINTF(sc, ATH_DBG_RESET, "Couldn't wakeup chip\n"); 609 DPRINTF(sc, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
631 ecode = -EIO; 610 ecode = -EIO;
632 goto bad; 611 goto bad;
633 } 612 }
@@ -650,7 +629,7 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
650 (ah->hw_version.macVersion != AR_SREV_VERSION_5416_PCIE) && 629 (ah->hw_version.macVersion != AR_SREV_VERSION_5416_PCIE) &&
651 (ah->hw_version.macVersion != AR_SREV_VERSION_9160) && 630 (ah->hw_version.macVersion != AR_SREV_VERSION_9160) &&
652 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) { 631 (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) {
653 DPRINTF(sc, ATH_DBG_RESET, 632 DPRINTF(sc, ATH_DBG_FATAL,
654 "Mac Chip Rev 0x%02x.%x is not supported by " 633 "Mac Chip Rev 0x%02x.%x is not supported by "
655 "this driver\n", ah->hw_version.macVersion, 634 "this driver\n", ah->hw_version.macVersion,
656 ah->hw_version.macRev); 635 ah->hw_version.macRev);
@@ -690,10 +669,6 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
690 if (AR_SREV_9280_10_OR_LATER(ah)) 669 if (AR_SREV_9280_10_OR_LATER(ah))
691 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL; 670 ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
692 671
693 DPRINTF(sc, ATH_DBG_RESET,
694 "This Mac Chip Rev 0x%02x.%x is \n",
695 ah->hw_version.macVersion, ah->hw_version.macRev);
696
697 if (AR_SREV_9285_12_OR_LATER(ah)) { 672 if (AR_SREV_9285_12_OR_LATER(ah)) {
698 673
699 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2, 674 INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
@@ -859,11 +834,7 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
859 if (AR_SREV_9280_20(ah)) 834 if (AR_SREV_9280_20(ah))
860 ath9k_hw_init_txgain_ini(ah); 835 ath9k_hw_init_txgain_ini(ah);
861 836
862 if (!ath9k_hw_fill_cap_info(ah)) { 837 ath9k_hw_fill_cap_info(ah);
863 DPRINTF(sc, ATH_DBG_RESET, "failed ath9k_hw_fill_cap_info\n");
864 ecode = -EINVAL;
865 goto bad;
866 }
867 838
868 if ((ah->hw_version.devid == AR9280_DEVID_PCI) && 839 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
869 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) { 840 test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
@@ -885,8 +856,8 @@ static struct ath_hw *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
885 856
886 ecode = ath9k_hw_init_macaddr(ah); 857 ecode = ath9k_hw_init_macaddr(ah);
887 if (ecode != 0) { 858 if (ecode != 0) {
888 DPRINTF(sc, ATH_DBG_RESET, 859 DPRINTF(sc, ATH_DBG_FATAL,
889 "failed initializing mac address\n"); 860 "Failed to initialize MAC address\n");
890 goto bad; 861 goto bad;
891 } 862 }
892 863
@@ -1054,7 +1025,7 @@ static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
1054 AR_IMR_RXORN | 1025 AR_IMR_RXORN |
1055 AR_IMR_BCNMISC; 1026 AR_IMR_BCNMISC;
1056 1027
1057 if (ah->intr_mitigation) 1028 if (ah->config.intr_mitigation)
1058 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR; 1029 ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
1059 else 1030 else
1060 ah->mask_reg |= AR_IMR_RXOK; 1031 ah->mask_reg |= AR_IMR_RXOK;
@@ -1203,23 +1174,23 @@ static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
1203 switch (ah->hw_version.devid) { 1174 switch (ah->hw_version.devid) {
1204 case AR9280_DEVID_PCI: 1175 case AR9280_DEVID_PCI:
1205 if (reg == 0x7894) { 1176 if (reg == 0x7894) {
1206 DPRINTF(ah->ah_sc, ATH_DBG_ANY, 1177 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1207 "ini VAL: %x EEPROM: %x\n", value, 1178 "ini VAL: %x EEPROM: %x\n", value,
1208 (pBase->version & 0xff)); 1179 (pBase->version & 0xff));
1209 1180
1210 if ((pBase->version & 0xff) > 0x0a) { 1181 if ((pBase->version & 0xff) > 0x0a) {
1211 DPRINTF(ah->ah_sc, ATH_DBG_ANY, 1182 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1212 "PWDCLKIND: %d\n", 1183 "PWDCLKIND: %d\n",
1213 pBase->pwdclkind); 1184 pBase->pwdclkind);
1214 value &= ~AR_AN_TOP2_PWDCLKIND; 1185 value &= ~AR_AN_TOP2_PWDCLKIND;
1215 value |= AR_AN_TOP2_PWDCLKIND & 1186 value |= AR_AN_TOP2_PWDCLKIND &
1216 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S); 1187 (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
1217 } else { 1188 } else {
1218 DPRINTF(ah->ah_sc, ATH_DBG_ANY, 1189 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1219 "PWDCLKIND Earlier Rev\n"); 1190 "PWDCLKIND Earlier Rev\n");
1220 } 1191 }
1221 1192
1222 DPRINTF(ah->ah_sc, ATH_DBG_ANY, 1193 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1223 "final ini VAL: %x\n", value); 1194 "final ini VAL: %x\n", value);
1224 } 1195 }
1225 break; 1196 break;
@@ -1249,6 +1220,21 @@ static void ath9k_olc_init(struct ath_hw *ah)
1249 ah->PDADCdelta = 0; 1220 ah->PDADCdelta = 0;
1250} 1221}
1251 1222
1223static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
1224 struct ath9k_channel *chan)
1225{
1226 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1227
1228 if (IS_CHAN_B(chan))
1229 ctl |= CTL_11B;
1230 else if (IS_CHAN_G(chan))
1231 ctl |= CTL_11G;
1232 else
1233 ctl |= CTL_11A;
1234
1235 return ctl;
1236}
1237
1252static int ath9k_hw_process_ini(struct ath_hw *ah, 1238static int ath9k_hw_process_ini(struct ath_hw *ah,
1253 struct ath9k_channel *chan, 1239 struct ath9k_channel *chan,
1254 enum ath9k_ht_macmode macmode) 1240 enum ath9k_ht_macmode macmode)
@@ -1360,19 +1346,19 @@ static int ath9k_hw_process_ini(struct ath_hw *ah,
1360 ath9k_olc_init(ah); 1346 ath9k_olc_init(ah);
1361 1347
1362 status = ah->eep_ops->set_txpower(ah, chan, 1348 status = ah->eep_ops->set_txpower(ah, chan,
1363 ath9k_regd_get_ctl(ah, chan), 1349 ath9k_regd_get_ctl(&ah->regulatory, chan),
1364 channel->max_antenna_gain * 2, 1350 channel->max_antenna_gain * 2,
1365 channel->max_power * 2, 1351 channel->max_power * 2,
1366 min((u32) MAX_RATE_POWER, 1352 min((u32) MAX_RATE_POWER,
1367 (u32) ah->regulatory.power_limit)); 1353 (u32) ah->regulatory.power_limit));
1368 if (status != 0) { 1354 if (status != 0) {
1369 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 1355 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1370 "error init'ing transmit power\n"); 1356 "Error initializing transmit power\n");
1371 return -EIO; 1357 return -EIO;
1372 } 1358 }
1373 1359
1374 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) { 1360 if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
1375 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 1361 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1376 "ar5416SetRfRegs failed\n"); 1362 "ar5416SetRfRegs failed\n");
1377 return -EIO; 1363 return -EIO;
1378 } 1364 }
@@ -1678,7 +1664,7 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1678 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN); 1664 REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
1679 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN, 1665 if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
1680 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) { 1666 AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
1681 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO, 1667 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1682 "Could not kill baseband RX\n"); 1668 "Could not kill baseband RX\n");
1683 return false; 1669 return false;
1684 } 1670 }
@@ -1687,26 +1673,26 @@ static bool ath9k_hw_channel_change(struct ath_hw *ah,
1687 1673
1688 if (AR_SREV_9280_10_OR_LATER(ah)) { 1674 if (AR_SREV_9280_10_OR_LATER(ah)) {
1689 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) { 1675 if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
1690 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 1676 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1691 "failed to set channel\n"); 1677 "Failed to set channel\n");
1692 return false; 1678 return false;
1693 } 1679 }
1694 } else { 1680 } else {
1695 if (!(ath9k_hw_set_channel(ah, chan))) { 1681 if (!(ath9k_hw_set_channel(ah, chan))) {
1696 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 1682 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
1697 "failed to set channel\n"); 1683 "Failed to set channel\n");
1698 return false; 1684 return false;
1699 } 1685 }
1700 } 1686 }
1701 1687
1702 if (ah->eep_ops->set_txpower(ah, chan, 1688 if (ah->eep_ops->set_txpower(ah, chan,
1703 ath9k_regd_get_ctl(ah, chan), 1689 ath9k_regd_get_ctl(&ah->regulatory, chan),
1704 channel->max_antenna_gain * 2, 1690 channel->max_antenna_gain * 2,
1705 channel->max_power * 2, 1691 channel->max_power * 2,
1706 min((u32) MAX_RATE_POWER, 1692 min((u32) MAX_RATE_POWER,
1707 (u32) ah->regulatory.power_limit)) != 0) { 1693 (u32) ah->regulatory.power_limit)) != 0) {
1708 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, 1694 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1709 "error init'ing transmit power\n"); 1695 "Error initializing transmit power\n");
1710 return false; 1696 return false;
1711 } 1697 }
1712 1698
@@ -2199,14 +2185,6 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
2199 ah->txchainmask = sc->tx_chainmask; 2185 ah->txchainmask = sc->tx_chainmask;
2200 ah->rxchainmask = sc->rx_chainmask; 2186 ah->rxchainmask = sc->rx_chainmask;
2201 2187
2202 if (AR_SREV_9285(ah)) {
2203 ah->txchainmask &= 0x1;
2204 ah->rxchainmask &= 0x1;
2205 } else if (AR_SREV_9280(ah)) {
2206 ah->txchainmask &= 0x3;
2207 ah->rxchainmask &= 0x3;
2208 }
2209
2210 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) 2188 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
2211 return -EIO; 2189 return -EIO;
2212 2190
@@ -2242,7 +2220,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
2242 ath9k_hw_mark_phy_inactive(ah); 2220 ath9k_hw_mark_phy_inactive(ah);
2243 2221
2244 if (!ath9k_hw_chip_reset(ah, chan)) { 2222 if (!ath9k_hw_chip_reset(ah, chan)) {
2245 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "chip reset failed\n"); 2223 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Chip reset failed\n");
2246 return -EINVAL; 2224 return -EINVAL;
2247 } 2225 }
2248 2226
@@ -2335,8 +2313,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
2335 2313
2336 REG_WRITE(ah, AR_OBS, 8); 2314 REG_WRITE(ah, AR_OBS, 8);
2337 2315
2338 if (ah->intr_mitigation) { 2316 if (ah->config.intr_mitigation) {
2339
2340 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500); 2317 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
2341 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000); 2318 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
2342 } 2319 }
@@ -2385,8 +2362,8 @@ bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
2385 u32 keyType; 2362 u32 keyType;
2386 2363
2387 if (entry >= ah->caps.keycache_size) { 2364 if (entry >= ah->caps.keycache_size) {
2388 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 2365 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2389 "entry %u out of range\n", entry); 2366 "keychache entry %u out of range\n", entry);
2390 return false; 2367 return false;
2391 } 2368 }
2392 2369
@@ -2422,8 +2399,8 @@ bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
2422 u32 macHi, macLo; 2399 u32 macHi, macLo;
2423 2400
2424 if (entry >= ah->caps.keycache_size) { 2401 if (entry >= ah->caps.keycache_size) {
2425 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 2402 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2426 "entry %u out of range\n", entry); 2403 "keychache entry %u out of range\n", entry);
2427 return false; 2404 return false;
2428 } 2405 }
2429 2406
@@ -2454,8 +2431,8 @@ bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
2454 u32 keyType; 2431 u32 keyType;
2455 2432
2456 if (entry >= pCap->keycache_size) { 2433 if (entry >= pCap->keycache_size) {
2457 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 2434 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2458 "entry %u out of range\n", entry); 2435 "keycache entry %u out of range\n", entry);
2459 return false; 2436 return false;
2460 } 2437 }
2461 2438
@@ -2465,7 +2442,7 @@ bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
2465 break; 2442 break;
2466 case ATH9K_CIPHER_AES_CCM: 2443 case ATH9K_CIPHER_AES_CCM:
2467 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) { 2444 if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
2468 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 2445 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2469 "AES-CCM not supported by mac rev 0x%x\n", 2446 "AES-CCM not supported by mac rev 0x%x\n",
2470 ah->hw_version.macRev); 2447 ah->hw_version.macRev);
2471 return false; 2448 return false;
@@ -2476,14 +2453,14 @@ bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
2476 keyType = AR_KEYTABLE_TYPE_TKIP; 2453 keyType = AR_KEYTABLE_TYPE_TKIP;
2477 if (ATH9K_IS_MIC_ENABLED(ah) 2454 if (ATH9K_IS_MIC_ENABLED(ah)
2478 && entry + 64 >= pCap->keycache_size) { 2455 && entry + 64 >= pCap->keycache_size) {
2479 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 2456 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2480 "entry %u inappropriate for TKIP\n", entry); 2457 "entry %u inappropriate for TKIP\n", entry);
2481 return false; 2458 return false;
2482 } 2459 }
2483 break; 2460 break;
2484 case ATH9K_CIPHER_WEP: 2461 case ATH9K_CIPHER_WEP:
2485 if (k->kv_len < LEN_WEP40) { 2462 if (k->kv_len < LEN_WEP40) {
2486 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 2463 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
2487 "WEP key length %u too small\n", k->kv_len); 2464 "WEP key length %u too small\n", k->kv_len);
2488 return false; 2465 return false;
2489 } 2466 }
@@ -2498,7 +2475,7 @@ bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
2498 keyType = AR_KEYTABLE_TYPE_CLR; 2475 keyType = AR_KEYTABLE_TYPE_CLR;
2499 break; 2476 break;
2500 default: 2477 default:
2501 DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE, 2478 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2502 "cipher %u not supported\n", k->kv_type); 2479 "cipher %u not supported\n", k->kv_type);
2503 return false; 2480 return false;
2504 } 2481 }
@@ -2716,7 +2693,7 @@ static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
2716 AR_RTC_FORCE_WAKE_EN); 2693 AR_RTC_FORCE_WAKE_EN);
2717 } 2694 }
2718 if (i == 0) { 2695 if (i == 0) {
2719 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 2696 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2720 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20); 2697 "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
2721 return false; 2698 return false;
2722 } 2699 }
@@ -2737,9 +2714,8 @@ bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
2737 "UNDEFINED" 2714 "UNDEFINED"
2738 }; 2715 };
2739 2716
2740 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s -> %s (%s)\n", 2717 DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s -> %s\n",
2741 modes[ah->power_mode], modes[mode], 2718 modes[ah->power_mode], modes[mode]);
2742 setChip ? "set chip " : "");
2743 2719
2744 switch (mode) { 2720 switch (mode) {
2745 case ATH9K_PM_AWAKE: 2721 case ATH9K_PM_AWAKE:
@@ -2753,7 +2729,7 @@ bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
2753 ath9k_set_power_network_sleep(ah, setChip); 2729 ath9k_set_power_network_sleep(ah, setChip);
2754 break; 2730 break;
2755 default: 2731 default:
2756 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, 2732 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
2757 "Unknown power mode %u\n", mode); 2733 "Unknown power mode %u\n", mode);
2758 return false; 2734 return false;
2759 } 2735 }
@@ -2943,7 +2919,7 @@ bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
2943 2919
2944 *masked = isr & ATH9K_INT_COMMON; 2920 *masked = isr & ATH9K_INT_COMMON;
2945 2921
2946 if (ah->intr_mitigation) { 2922 if (ah->config.intr_mitigation) {
2947 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM)) 2923 if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
2948 *masked |= ATH9K_INT_RX; 2924 *masked |= ATH9K_INT_RX;
2949 } 2925 }
@@ -3000,6 +2976,7 @@ bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
3000 DPRINTF(ah->ah_sc, ATH_DBG_ANY, 2976 DPRINTF(ah->ah_sc, ATH_DBG_ANY,
3001 "received PCI PERR interrupt\n"); 2977 "received PCI PERR interrupt\n");
3002 } 2978 }
2979 *masked |= ATH9K_INT_FATAL;
3003 } 2980 }
3004 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) { 2981 if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
3005 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, 2982 DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
@@ -3061,7 +3038,7 @@ enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
3061 } 3038 }
3062 if (ints & ATH9K_INT_RX) { 3039 if (ints & ATH9K_INT_RX) {
3063 mask |= AR_IMR_RXERR; 3040 mask |= AR_IMR_RXERR;
3064 if (ah->intr_mitigation) 3041 if (ah->config.intr_mitigation)
3065 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM; 3042 mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
3066 else 3043 else
3067 mask |= AR_IMR_RXOK | AR_IMR_RXDESC; 3044 mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
@@ -3259,7 +3236,7 @@ void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
3259/* HW Capabilities */ 3236/* HW Capabilities */
3260/*******************/ 3237/*******************/
3261 3238
3262bool ath9k_hw_fill_cap_info(struct ath_hw *ah) 3239void ath9k_hw_fill_cap_info(struct ath_hw *ah)
3263{ 3240{
3264 struct ath9k_hw_capabilities *pCap = &ah->caps; 3241 struct ath9k_hw_capabilities *pCap = &ah->caps;
3265 u16 capField = 0, eeval; 3242 u16 capField = 0, eeval;
@@ -3343,8 +3320,6 @@ bool ath9k_hw_fill_cap_info(struct ath_hw *ah)
3343 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP; 3320 pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
3344 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM; 3321 pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
3345 3322
3346 pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
3347
3348 if (ah->config.ht_enable) 3323 if (ah->config.ht_enable)
3349 pCap->hw_caps |= ATH9K_HW_CAP_HT; 3324 pCap->hw_caps |= ATH9K_HW_CAP_HT;
3350 else 3325 else
@@ -3368,7 +3343,6 @@ bool ath9k_hw_fill_cap_info(struct ath_hw *ah)
3368 pCap->keycache_size = AR_KEYTABLE_SIZE; 3343 pCap->keycache_size = AR_KEYTABLE_SIZE;
3369 3344
3370 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC; 3345 pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
3371 pCap->num_mr_retries = 4;
3372 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD; 3346 pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
3373 3347
3374 if (AR_SREV_9285_10_OR_LATER(ah)) 3348 if (AR_SREV_9285_10_OR_LATER(ah))
@@ -3378,14 +3352,6 @@ bool ath9k_hw_fill_cap_info(struct ath_hw *ah)
3378 else 3352 else
3379 pCap->num_gpio_pins = AR_NUM_GPIO; 3353 pCap->num_gpio_pins = AR_NUM_GPIO;
3380 3354
3381 if (AR_SREV_9280_10_OR_LATER(ah)) {
3382 pCap->hw_caps |= ATH9K_HW_CAP_WOW;
3383 pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3384 } else {
3385 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
3386 pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
3387 }
3388
3389 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) { 3355 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
3390 pCap->hw_caps |= ATH9K_HW_CAP_CST; 3356 pCap->hw_caps |= ATH9K_HW_CAP_CST;
3391 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX; 3357 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
@@ -3411,7 +3377,8 @@ bool ath9k_hw_fill_cap_info(struct ath_hw *ah)
3411 (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) || 3377 (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) ||
3412 (ah->hw_version.macVersion == AR_SREV_VERSION_9160) || 3378 (ah->hw_version.macVersion == AR_SREV_VERSION_9160) ||
3413 (ah->hw_version.macVersion == AR_SREV_VERSION_9100) || 3379 (ah->hw_version.macVersion == AR_SREV_VERSION_9100) ||
3414 (ah->hw_version.macVersion == AR_SREV_VERSION_9280)) 3380 (ah->hw_version.macVersion == AR_SREV_VERSION_9280) ||
3381 (ah->hw_version.macVersion == AR_SREV_VERSION_9285))
3415 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP; 3382 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
3416 else 3383 else
3417 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP; 3384 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
@@ -3445,8 +3412,6 @@ bool ath9k_hw_fill_cap_info(struct ath_hw *ah)
3445 ah->btactive_gpio = 6; 3412 ah->btactive_gpio = 6;
3446 ah->wlanactive_gpio = 5; 3413 ah->wlanactive_gpio = 5;
3447 } 3414 }
3448
3449 return true;
3450} 3415}
3451 3416
3452bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type, 3417bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
@@ -3762,7 +3727,7 @@ bool ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
3762 ah->regulatory.power_limit = min(limit, (u32) MAX_RATE_POWER); 3727 ah->regulatory.power_limit = min(limit, (u32) MAX_RATE_POWER);
3763 3728
3764 if (ah->eep_ops->set_txpower(ah, chan, 3729 if (ah->eep_ops->set_txpower(ah, chan,
3765 ath9k_regd_get_ctl(ah, chan), 3730 ath9k_regd_get_ctl(&ah->regulatory, chan),
3766 channel->max_antenna_gain * 2, 3731 channel->max_antenna_gain * 2,
3767 channel->max_power * 2, 3732 channel->max_power * 2,
3768 min((u32) MAX_RATE_POWER, 3733 min((u32) MAX_RATE_POWER,
diff --git a/drivers/net/wireless/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index 0b594e0ee26..ab3412672e3 100644
--- a/drivers/net/wireless/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -25,10 +25,11 @@
25#include "ani.h" 25#include "ani.h"
26#include "eeprom.h" 26#include "eeprom.h"
27#include "calib.h" 27#include "calib.h"
28#include "regd.h"
29#include "reg.h" 28#include "reg.h"
30#include "phy.h" 29#include "phy.h"
31 30
31#include "../regd.h"
32
32#define ATHEROS_VENDOR_ID 0x168c 33#define ATHEROS_VENDOR_ID 0x168c
33#define AR5416_DEVID_PCI 0x0023 34#define AR5416_DEVID_PCI 0x0023
34#define AR5416_DEVID_PCIE 0x0024 35#define AR5416_DEVID_PCIE 0x0024
@@ -124,29 +125,24 @@ enum wireless_mode {
124}; 125};
125 126
126enum ath9k_hw_caps { 127enum ath9k_hw_caps {
127 ATH9K_HW_CAP_CHAN_SPREAD = BIT(0), 128 ATH9K_HW_CAP_MIC_AESCCM = BIT(0),
128 ATH9K_HW_CAP_MIC_AESCCM = BIT(1), 129 ATH9K_HW_CAP_MIC_CKIP = BIT(1),
129 ATH9K_HW_CAP_MIC_CKIP = BIT(2), 130 ATH9K_HW_CAP_MIC_TKIP = BIT(2),
130 ATH9K_HW_CAP_MIC_TKIP = BIT(3), 131 ATH9K_HW_CAP_CIPHER_AESCCM = BIT(3),
131 ATH9K_HW_CAP_CIPHER_AESCCM = BIT(4), 132 ATH9K_HW_CAP_CIPHER_CKIP = BIT(4),
132 ATH9K_HW_CAP_CIPHER_CKIP = BIT(5), 133 ATH9K_HW_CAP_CIPHER_TKIP = BIT(5),
133 ATH9K_HW_CAP_CIPHER_TKIP = BIT(6), 134 ATH9K_HW_CAP_VEOL = BIT(6),
134 ATH9K_HW_CAP_VEOL = BIT(7), 135 ATH9K_HW_CAP_BSSIDMASK = BIT(7),
135 ATH9K_HW_CAP_BSSIDMASK = BIT(8), 136 ATH9K_HW_CAP_MCAST_KEYSEARCH = BIT(8),
136 ATH9K_HW_CAP_MCAST_KEYSEARCH = BIT(9), 137 ATH9K_HW_CAP_HT = BIT(9),
137 ATH9K_HW_CAP_CHAN_HALFRATE = BIT(10), 138 ATH9K_HW_CAP_GTT = BIT(10),
138 ATH9K_HW_CAP_CHAN_QUARTERRATE = BIT(11), 139 ATH9K_HW_CAP_FASTCC = BIT(11),
139 ATH9K_HW_CAP_HT = BIT(12), 140 ATH9K_HW_CAP_RFSILENT = BIT(12),
140 ATH9K_HW_CAP_GTT = BIT(13), 141 ATH9K_HW_CAP_CST = BIT(13),
141 ATH9K_HW_CAP_FASTCC = BIT(14), 142 ATH9K_HW_CAP_ENHANCEDPM = BIT(14),
142 ATH9K_HW_CAP_RFSILENT = BIT(15), 143 ATH9K_HW_CAP_AUTOSLEEP = BIT(15),
143 ATH9K_HW_CAP_WOW = BIT(16), 144 ATH9K_HW_CAP_4KB_SPLITTRANS = BIT(16),
144 ATH9K_HW_CAP_CST = BIT(17), 145 ATH9K_HW_CAP_BT_COEX = BIT(17)
145 ATH9K_HW_CAP_ENHANCEDPM = BIT(18),
146 ATH9K_HW_CAP_AUTOSLEEP = BIT(19),
147 ATH9K_HW_CAP_4KB_SPLITTRANS = BIT(20),
148 ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT = BIT(21),
149 ATH9K_HW_CAP_BT_COEX = BIT(22)
150}; 146};
151 147
152enum ath9k_capability_type { 148enum ath9k_capability_type {
@@ -166,7 +162,6 @@ struct ath9k_hw_capabilities {
166 u16 keycache_size; 162 u16 keycache_size;
167 u16 low_5ghz_chan, high_5ghz_chan; 163 u16 low_5ghz_chan, high_5ghz_chan;
168 u16 low_2ghz_chan, high_2ghz_chan; 164 u16 low_2ghz_chan, high_2ghz_chan;
169 u16 num_mr_retries;
170 u16 rts_aggr_limit; 165 u16 rts_aggr_limit;
171 u8 tx_chainmask; 166 u8 tx_chainmask;
172 u8 rx_chainmask; 167 u8 rx_chainmask;
@@ -184,11 +179,8 @@ struct ath9k_ops_config {
184 int ack_6mb; 179 int ack_6mb;
185 int cwm_ignore_extcca; 180 int cwm_ignore_extcca;
186 u8 pcie_powersave_enable; 181 u8 pcie_powersave_enable;
187 u8 pcie_l1skp_enable;
188 u8 pcie_clock_req; 182 u8 pcie_clock_req;
189 u32 pcie_waen; 183 u32 pcie_waen;
190 int pcie_power_reset;
191 u8 pcie_restore;
192 u8 analog_shiftreg; 184 u8 analog_shiftreg;
193 u8 ht_enable; 185 u8 ht_enable;
194 u32 ofdm_trig_low; 186 u32 ofdm_trig_low;
@@ -196,17 +188,10 @@ struct ath9k_ops_config {
196 u32 cck_trig_high; 188 u32 cck_trig_high;
197 u32 cck_trig_low; 189 u32 cck_trig_low;
198 u32 enable_ani; 190 u32 enable_ani;
199 u8 noise_immunity_level;
200 u32 ofdm_weaksignal_det;
201 u32 cck_weaksignal_thr;
202 u8 spur_immunity_level;
203 u8 firstep_level;
204 int8_t rssi_thr_high;
205 int8_t rssi_thr_low;
206 u16 diversity_control; 191 u16 diversity_control;
207 u16 antenna_switch_swap; 192 u16 antenna_switch_swap;
208 int serialize_regmode; 193 int serialize_regmode;
209 int intr_mitigation; 194 bool intr_mitigation;
210#define SPUR_DISABLE 0 195#define SPUR_DISABLE 0
211#define SPUR_ENABLE_IOCTL 1 196#define SPUR_ENABLE_IOCTL 1
212#define SPUR_ENABLE_EEPROM 2 197#define SPUR_ENABLE_EEPROM 2
@@ -281,13 +266,6 @@ enum ath9k_int {
281#define CHANNEL_HT40PLUS 0x20000 266#define CHANNEL_HT40PLUS 0x20000
282#define CHANNEL_HT40MINUS 0x40000 267#define CHANNEL_HT40MINUS 0x40000
283 268
284#define CHANNEL_INTERFERENCE 0x01
285#define CHANNEL_DFS 0x02
286#define CHANNEL_4MS_LIMIT 0x04
287#define CHANNEL_DFS_CLEAR 0x08
288#define CHANNEL_DISALLOW_ADHOC 0x10
289#define CHANNEL_PER_11D_ADHOC 0x20
290
291#define CHANNEL_A (CHANNEL_5GHZ|CHANNEL_OFDM) 269#define CHANNEL_A (CHANNEL_5GHZ|CHANNEL_OFDM)
292#define CHANNEL_B (CHANNEL_2GHZ|CHANNEL_CCK) 270#define CHANNEL_B (CHANNEL_2GHZ|CHANNEL_CCK)
293#define CHANNEL_G (CHANNEL_2GHZ|CHANNEL_OFDM) 271#define CHANNEL_G (CHANNEL_2GHZ|CHANNEL_OFDM)
@@ -318,10 +296,6 @@ struct ath9k_channel {
318 int16_t rawNoiseFloor; 296 int16_t rawNoiseFloor;
319}; 297};
320 298
321#define IS_CHAN_A(_c) ((((_c)->channelFlags & CHANNEL_A) == CHANNEL_A) || \
322 (((_c)->channelFlags & CHANNEL_A_HT20) == CHANNEL_A_HT20) || \
323 (((_c)->channelFlags & CHANNEL_A_HT40PLUS) == CHANNEL_A_HT40PLUS) || \
324 (((_c)->channelFlags & CHANNEL_A_HT40MINUS) == CHANNEL_A_HT40MINUS))
325#define IS_CHAN_G(_c) ((((_c)->channelFlags & (CHANNEL_G)) == CHANNEL_G) || \ 299#define IS_CHAN_G(_c) ((((_c)->channelFlags & (CHANNEL_G)) == CHANNEL_G) || \
326 (((_c)->channelFlags & CHANNEL_G_HT20) == CHANNEL_G_HT20) || \ 300 (((_c)->channelFlags & CHANNEL_G_HT20) == CHANNEL_G_HT20) || \
327 (((_c)->channelFlags & CHANNEL_G_HT40PLUS) == CHANNEL_G_HT40PLUS) || \ 301 (((_c)->channelFlags & CHANNEL_G_HT40PLUS) == CHANNEL_G_HT40PLUS) || \
@@ -329,7 +303,6 @@ struct ath9k_channel {
329#define IS_CHAN_OFDM(_c) (((_c)->channelFlags & CHANNEL_OFDM) != 0) 303#define IS_CHAN_OFDM(_c) (((_c)->channelFlags & CHANNEL_OFDM) != 0)
330#define IS_CHAN_5GHZ(_c) (((_c)->channelFlags & CHANNEL_5GHZ) != 0) 304#define IS_CHAN_5GHZ(_c) (((_c)->channelFlags & CHANNEL_5GHZ) != 0)
331#define IS_CHAN_2GHZ(_c) (((_c)->channelFlags & CHANNEL_2GHZ) != 0) 305#define IS_CHAN_2GHZ(_c) (((_c)->channelFlags & CHANNEL_2GHZ) != 0)
332#define IS_CHAN_PASSIVE(_c) (((_c)->channelFlags & CHANNEL_PASSIVE) != 0)
333#define IS_CHAN_HALF_RATE(_c) (((_c)->channelFlags & CHANNEL_HALF) != 0) 306#define IS_CHAN_HALF_RATE(_c) (((_c)->channelFlags & CHANNEL_HALF) != 0)
334#define IS_CHAN_QUARTER_RATE(_c) (((_c)->channelFlags & CHANNEL_QUARTER) != 0) 307#define IS_CHAN_QUARTER_RATE(_c) (((_c)->channelFlags & CHANNEL_QUARTER) != 0)
335#define IS_CHAN_A_5MHZ_SPACED(_c) \ 308#define IS_CHAN_A_5MHZ_SPACED(_c) \
@@ -420,7 +393,7 @@ struct ath_hw {
420 struct ath9k_hw_version hw_version; 393 struct ath9k_hw_version hw_version;
421 struct ath9k_ops_config config; 394 struct ath9k_ops_config config;
422 struct ath9k_hw_capabilities caps; 395 struct ath9k_hw_capabilities caps;
423 struct ath9k_regulatory regulatory; 396 struct ath_regulatory regulatory;
424 struct ath9k_channel channels[38]; 397 struct ath9k_channel channels[38];
425 struct ath9k_channel *curchan; 398 struct ath9k_channel *curchan;
426 399
@@ -463,14 +436,14 @@ struct ath_hw {
463 enum ath9k_ant_setting diversity_control; 436 enum ath9k_ant_setting diversity_control;
464 437
465 /* Calibration */ 438 /* Calibration */
466 enum hal_cal_types supp_cals; 439 enum ath9k_cal_types supp_cals;
467 struct hal_cal_list iq_caldata; 440 struct ath9k_cal_list iq_caldata;
468 struct hal_cal_list adcgain_caldata; 441 struct ath9k_cal_list adcgain_caldata;
469 struct hal_cal_list adcdc_calinitdata; 442 struct ath9k_cal_list adcdc_calinitdata;
470 struct hal_cal_list adcdc_caldata; 443 struct ath9k_cal_list adcdc_caldata;
471 struct hal_cal_list *cal_list; 444 struct ath9k_cal_list *cal_list;
472 struct hal_cal_list *cal_list_last; 445 struct ath9k_cal_list *cal_list_last;
473 struct hal_cal_list *cal_list_curr; 446 struct ath9k_cal_list *cal_list_curr;
474#define totalPowerMeasI meas0.unsign 447#define totalPowerMeasI meas0.unsign
475#define totalPowerMeasQ meas1.unsign 448#define totalPowerMeasQ meas1.unsign
476#define totalIqCorrMeas meas2.sign 449#define totalIqCorrMeas meas2.sign
@@ -540,7 +513,6 @@ struct ath_hw {
540 enum ath9k_ani_cmd ani_function; 513 enum ath9k_ani_cmd ani_function;
541 514
542 u32 intr_txqs; 515 u32 intr_txqs;
543 bool intr_mitigation;
544 enum ath9k_ht_extprotspacing extprotspacing; 516 enum ath9k_ht_extprotspacing extprotspacing;
545 u8 txchainmask; 517 u8 txchainmask;
546 u8 rxchainmask; 518 u8 rxchainmask;
@@ -573,7 +545,7 @@ struct ath_hw *ath9k_hw_attach(u16 devid, struct ath_softc *sc, int *error);
573void ath9k_hw_rfdetach(struct ath_hw *ah); 545void ath9k_hw_rfdetach(struct ath_hw *ah);
574int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, 546int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
575 bool bChannelChange); 547 bool bChannelChange);
576bool ath9k_hw_fill_cap_info(struct ath_hw *ah); 548void ath9k_hw_fill_cap_info(struct ath_hw *ah);
577bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type, 549bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
578 u32 capability, u32 *result); 550 u32 capability, u32 *result);
579bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type, 551bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
diff --git a/drivers/net/wireless/ath9k/initvals.h b/drivers/net/wireless/ath/ath9k/initvals.h
index e2f0a34b79a..e2f0a34b79a 100644
--- a/drivers/net/wireless/ath9k/initvals.h
+++ b/drivers/net/wireless/ath/ath9k/initvals.h
diff --git a/drivers/net/wireless/ath9k/mac.c b/drivers/net/wireless/ath/ath9k/mac.c
index e0a6dee4583..8ae4ec21667 100644
--- a/drivers/net/wireless/ath9k/mac.c
+++ b/drivers/net/wireless/ath/ath9k/mac.c
@@ -49,7 +49,7 @@ bool ath9k_hw_puttxbuf(struct ath_hw *ah, u32 q, u32 txdp)
49 49
50bool ath9k_hw_txstart(struct ath_hw *ah, u32 q) 50bool ath9k_hw_txstart(struct ath_hw *ah, u32 q)
51{ 51{
52 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q); 52 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Enable TXE on queue: %u\n", q);
53 53
54 REG_WRITE(ah, AR_Q_TXE, 1 << q); 54 REG_WRITE(ah, AR_Q_TXE, 1 << q);
55 55
@@ -110,13 +110,15 @@ bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
110 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM; 110 u32 wait_time = ATH9K_TX_STOP_DMA_TIMEOUT / ATH9K_TIME_QUANTUM;
111 111
112 if (q >= pCap->total_queues) { 112 if (q >= pCap->total_queues) {
113 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); 113 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Stopping TX DMA, "
114 "invalid queue: %u\n", q);
114 return false; 115 return false;
115 } 116 }
116 117
117 qi = &ah->txq[q]; 118 qi = &ah->txq[q];
118 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 119 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
119 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n"); 120 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Stopping TX DMA, "
121 "inactive queue: %u\n", q);
120 return false; 122 return false;
121 } 123 }
122 124
@@ -146,7 +148,7 @@ bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
146 break; 148 break;
147 149
148 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, 150 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
149 "TSF have moved while trying to set " 151 "TSF has moved while trying to set "
150 "quiet time TSF: 0x%08x\n", tsfLow); 152 "quiet time TSF: 0x%08x\n", tsfLow);
151 } 153 }
152 154
@@ -158,8 +160,8 @@ bool ath9k_hw_stoptxdma(struct ath_hw *ah, u32 q)
158 wait = wait_time; 160 wait = wait_time;
159 while (ath9k_hw_numtxpending(ah, q)) { 161 while (ath9k_hw_numtxpending(ah, q)) {
160 if ((--wait) == 0) { 162 if ((--wait) == 0) {
161 DPRINTF(ah->ah_sc, ATH_DBG_XMIT, 163 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
162 "Failed to stop Tx DMA in 100 " 164 "Failed to stop TX DMA in 100 "
163 "msec after killing last frame\n"); 165 "msec after killing last frame\n");
164 break; 166 break;
165 } 167 }
@@ -454,17 +456,19 @@ bool ath9k_hw_set_txq_props(struct ath_hw *ah, int q,
454 struct ath9k_tx_queue_info *qi; 456 struct ath9k_tx_queue_info *qi;
455 457
456 if (q >= pCap->total_queues) { 458 if (q >= pCap->total_queues) {
457 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); 459 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Set TXQ properties, "
460 "invalid queue: %u\n", q);
458 return false; 461 return false;
459 } 462 }
460 463
461 qi = &ah->txq[q]; 464 qi = &ah->txq[q];
462 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 465 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
463 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n"); 466 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Set TXQ properties, "
467 "inactive queue: %u\n", q);
464 return false; 468 return false;
465 } 469 }
466 470
467 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %p\n", qi); 471 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Set queue properties for: %u\n", q);
468 472
469 qi->tqi_ver = qinfo->tqi_ver; 473 qi->tqi_ver = qinfo->tqi_ver;
470 qi->tqi_subtype = qinfo->tqi_subtype; 474 qi->tqi_subtype = qinfo->tqi_subtype;
@@ -521,13 +525,15 @@ bool ath9k_hw_get_txq_props(struct ath_hw *ah, int q,
521 struct ath9k_tx_queue_info *qi; 525 struct ath9k_tx_queue_info *qi;
522 526
523 if (q >= pCap->total_queues) { 527 if (q >= pCap->total_queues) {
524 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); 528 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Get TXQ properties, "
529 "invalid queue: %u\n", q);
525 return false; 530 return false;
526 } 531 }
527 532
528 qi = &ah->txq[q]; 533 qi = &ah->txq[q];
529 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 534 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
530 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue\n"); 535 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Get TXQ properties, "
536 "inactive queue: %u\n", q);
531 return false; 537 return false;
532 } 538 }
533 539
@@ -575,22 +581,23 @@ int ath9k_hw_setuptxqueue(struct ath_hw *ah, enum ath9k_tx_queue type,
575 ATH9K_TX_QUEUE_INACTIVE) 581 ATH9K_TX_QUEUE_INACTIVE)
576 break; 582 break;
577 if (q == pCap->total_queues) { 583 if (q == pCap->total_queues) {
578 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, 584 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
579 "no available tx queue\n"); 585 "No available TX queue\n");
580 return -1; 586 return -1;
581 } 587 }
582 break; 588 break;
583 default: 589 default:
584 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "bad tx queue type %u\n", type); 590 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Invalid TX queue type: %u\n",
591 type);
585 return -1; 592 return -1;
586 } 593 }
587 594
588 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "queue %u\n", q); 595 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Setup TX queue: %u\n", q);
589 596
590 qi = &ah->txq[q]; 597 qi = &ah->txq[q];
591 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) { 598 if (qi->tqi_type != ATH9K_TX_QUEUE_INACTIVE) {
592 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, 599 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
593 "tx queue %u already active\n", q); 600 "TX queue: %u already active\n", q);
594 return -1; 601 return -1;
595 } 602 }
596 memset(qi, 0, sizeof(struct ath9k_tx_queue_info)); 603 memset(qi, 0, sizeof(struct ath9k_tx_queue_info));
@@ -620,16 +627,18 @@ bool ath9k_hw_releasetxqueue(struct ath_hw *ah, u32 q)
620 struct ath9k_tx_queue_info *qi; 627 struct ath9k_tx_queue_info *qi;
621 628
622 if (q >= pCap->total_queues) { 629 if (q >= pCap->total_queues) {
623 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); 630 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Release TXQ, "
631 "invalid queue: %u\n", q);
624 return false; 632 return false;
625 } 633 }
626 qi = &ah->txq[q]; 634 qi = &ah->txq[q];
627 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 635 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
628 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q); 636 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Release TXQ, "
637 "inactive queue: %u\n", q);
629 return false; 638 return false;
630 } 639 }
631 640
632 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "release queue %u\n", q); 641 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Release TX queue: %u\n", q);
633 642
634 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE; 643 qi->tqi_type = ATH9K_TX_QUEUE_INACTIVE;
635 ah->txok_interrupt_mask &= ~(1 << q); 644 ah->txok_interrupt_mask &= ~(1 << q);
@@ -650,17 +659,19 @@ bool ath9k_hw_resettxqueue(struct ath_hw *ah, u32 q)
650 u32 cwMin, chanCwMin, value; 659 u32 cwMin, chanCwMin, value;
651 660
652 if (q >= pCap->total_queues) { 661 if (q >= pCap->total_queues) {
653 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "invalid queue num %u\n", q); 662 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Reset TXQ, "
663 "invalid queue: %u\n", q);
654 return false; 664 return false;
655 } 665 }
656 666
657 qi = &ah->txq[q]; 667 qi = &ah->txq[q];
658 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) { 668 if (qi->tqi_type == ATH9K_TX_QUEUE_INACTIVE) {
659 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "inactive queue %u\n", q); 669 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Reset TXQ, "
670 "inactive queue: %u\n", q);
660 return true; 671 return true;
661 } 672 }
662 673
663 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "reset queue %u\n", q); 674 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, "Reset TX queue: %u\n", q);
664 675
665 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) { 676 if (qi->tqi_cwmin == ATH9K_TXQ_USEDEFAULT) {
666 if (chan && IS_CHAN_B(chan)) 677 if (chan && IS_CHAN_B(chan))
@@ -894,7 +905,7 @@ bool ath9k_hw_setrxabort(struct ath_hw *ah, bool set)
894 905
895 reg = REG_READ(ah, AR_OBS_BUS_1); 906 reg = REG_READ(ah, AR_OBS_BUS_1);
896 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, 907 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
897 "rx failed to go idle in 10 ms RXSM=0x%x\n", reg); 908 "RX failed to go idle in 10 ms RXSM=0x%x\n", reg);
898 909
899 return false; 910 return false;
900 } 911 }
@@ -949,8 +960,8 @@ bool ath9k_hw_stopdmarecv(struct ath_hw *ah)
949 } 960 }
950 961
951 if (i == 0) { 962 if (i == 0) {
952 DPRINTF(ah->ah_sc, ATH_DBG_QUEUE, 963 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
953 "dma failed to stop in %d ms " 964 "DMA failed to stop in %d ms "
954 "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n", 965 "AR_CR=0x%08x AR_DIAG_SW=0x%08x\n",
955 AH_RX_STOP_DMA_TIMEOUT / 1000, 966 AH_RX_STOP_DMA_TIMEOUT / 1000,
956 REG_READ(ah, AR_CR), 967 REG_READ(ah, AR_CR),
diff --git a/drivers/net/wireless/ath9k/mac.h b/drivers/net/wireless/ath/ath9k/mac.h
index 1176bce8b76..1176bce8b76 100644
--- a/drivers/net/wireless/ath9k/mac.h
+++ b/drivers/net/wireless/ath/ath9k/mac.h
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 13d4e6756c9..2398d4f45f2 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -287,7 +287,6 @@ int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
287 } 287 }
288 spin_unlock_bh(&sc->sc_resetlock); 288 spin_unlock_bh(&sc->sc_resetlock);
289 289
290 sc->sc_flags &= ~SC_OP_CHAINMASK_UPDATE;
291 sc->sc_flags &= ~SC_OP_FULL_RESET; 290 sc->sc_flags &= ~SC_OP_FULL_RESET;
292 291
293 if (ath_startrecv(sc) != 0) { 292 if (ath_startrecv(sc) != 0) {
@@ -368,28 +367,16 @@ static void ath_ani_calibrate(unsigned long data)
368 367
369 /* Perform calibration if necessary */ 368 /* Perform calibration if necessary */
370 if (longcal || shortcal) { 369 if (longcal || shortcal) {
371 bool iscaldone = false; 370 sc->ani.caldone = ath9k_hw_calibrate(ah, ah->curchan,
372 371 sc->rx_chainmask, longcal);
373 if (ath9k_hw_calibrate(ah, ah->curchan, 372
374 sc->rx_chainmask, longcal, 373 if (longcal)
375 &iscaldone)) { 374 sc->ani.noise_floor = ath9k_hw_getchan_noise(ah,
376 if (longcal) 375 ah->curchan);
377 sc->ani.noise_floor = 376
378 ath9k_hw_getchan_noise(ah, 377 DPRINTF(sc, ATH_DBG_ANI," calibrate chan %u/%x nf: %d\n",
379 ah->curchan); 378 ah->curchan->channel, ah->curchan->channelFlags,
380 379 sc->ani.noise_floor);
381 DPRINTF(sc, ATH_DBG_ANI,
382 "calibrate chan %u/%x nf: %d\n",
383 ah->curchan->channel,
384 ah->curchan->channelFlags,
385 sc->ani.noise_floor);
386 } else {
387 DPRINTF(sc, ATH_DBG_ANY,
388 "calibrate chan %u/%x failed\n",
389 ah->curchan->channel,
390 ah->curchan->channelFlags);
391 }
392 sc->ani.caldone = iscaldone;
393 } 380 }
394 } 381 }
395 382
@@ -408,6 +395,18 @@ set_timer:
408 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval)); 395 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
409} 396}
410 397
398static void ath_start_ani(struct ath_softc *sc)
399{
400 unsigned long timestamp = jiffies_to_msecs(jiffies);
401
402 sc->ani.longcal_timer = timestamp;
403 sc->ani.shortcal_timer = timestamp;
404 sc->ani.checkani_timer = timestamp;
405
406 mod_timer(&sc->ani.timer,
407 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
408}
409
411/* 410/*
412 * Update tx/rx chainmask. For legacy association, 411 * Update tx/rx chainmask. For legacy association,
413 * hard code chainmask to 1x1, for 11n association, use 412 * hard code chainmask to 1x1, for 11n association, use
@@ -416,7 +415,6 @@ set_timer:
416 */ 415 */
417void ath_update_chainmask(struct ath_softc *sc, int is_ht) 416void ath_update_chainmask(struct ath_softc *sc, int is_ht)
418{ 417{
419 sc->sc_flags |= SC_OP_CHAINMASK_UPDATE;
420 if (is_ht || 418 if (is_ht ||
421 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BT_COEX)) { 419 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BT_COEX)) {
422 sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask; 420 sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
@@ -436,12 +434,12 @@ static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
436 434
437 an = (struct ath_node *)sta->drv_priv; 435 an = (struct ath_node *)sta->drv_priv;
438 436
439 if (sc->sc_flags & SC_OP_TXAGGR) 437 if (sc->sc_flags & SC_OP_TXAGGR) {
440 ath_tx_node_init(sc, an); 438 ath_tx_node_init(sc, an);
441 439 an->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
442 an->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR + 440 sta->ht_cap.ampdu_factor);
443 sta->ht_cap.ampdu_factor); 441 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
444 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density); 442 }
445} 443}
446 444
447static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta) 445static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
@@ -458,133 +456,124 @@ static void ath9k_tasklet(unsigned long data)
458 u32 status = sc->intrstatus; 456 u32 status = sc->intrstatus;
459 457
460 if (status & ATH9K_INT_FATAL) { 458 if (status & ATH9K_INT_FATAL) {
461 /* need a chip reset */
462 ath_reset(sc, false); 459 ath_reset(sc, false);
463 return; 460 return;
464 } else { 461 }
465 462
466 if (status & 463 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
467 (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) { 464 spin_lock_bh(&sc->rx.rxflushlock);
468 spin_lock_bh(&sc->rx.rxflushlock); 465 ath_rx_tasklet(sc, 0);
469 ath_rx_tasklet(sc, 0); 466 spin_unlock_bh(&sc->rx.rxflushlock);
470 spin_unlock_bh(&sc->rx.rxflushlock);
471 }
472 /* XXX: optimize this */
473 if (status & ATH9K_INT_TX)
474 ath_tx_tasklet(sc);
475 } 467 }
476 468
469 if (status & ATH9K_INT_TX)
470 ath_tx_tasklet(sc);
471
477 /* re-enable hardware interrupt */ 472 /* re-enable hardware interrupt */
478 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask); 473 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
479} 474}
480 475
481irqreturn_t ath_isr(int irq, void *dev) 476irqreturn_t ath_isr(int irq, void *dev)
482{ 477{
478#define SCHED_INTR ( \
479 ATH9K_INT_FATAL | \
480 ATH9K_INT_RXORN | \
481 ATH9K_INT_RXEOL | \
482 ATH9K_INT_RX | \
483 ATH9K_INT_TX | \
484 ATH9K_INT_BMISS | \
485 ATH9K_INT_CST | \
486 ATH9K_INT_TSFOOR)
487
483 struct ath_softc *sc = dev; 488 struct ath_softc *sc = dev;
484 struct ath_hw *ah = sc->sc_ah; 489 struct ath_hw *ah = sc->sc_ah;
485 enum ath9k_int status; 490 enum ath9k_int status;
486 bool sched = false; 491 bool sched = false;
487 492
488 do { 493 /*
489 if (sc->sc_flags & SC_OP_INVALID) { 494 * The hardware is not ready/present, don't
490 /* 495 * touch anything. Note this can happen early
491 * The hardware is not ready/present, don't 496 * on if the IRQ is shared.
492 * touch anything. Note this can happen early 497 */
493 * on if the IRQ is shared. 498 if (sc->sc_flags & SC_OP_INVALID)
494 */ 499 return IRQ_NONE;
495 return IRQ_NONE;
496 }
497 if (!ath9k_hw_intrpend(ah)) { /* shared irq, not for us */
498 return IRQ_NONE;
499 }
500 500
501 /* 501 ath9k_ps_wakeup(sc);
502 * Figure out the reason(s) for the interrupt. Note 502
503 * that the hal returns a pseudo-ISR that may include 503 /* shared irq, not for us */
504 * bits we haven't explicitly enabled so we mask the 504
505 * value to insure we only process bits we requested. 505 if (!ath9k_hw_intrpend(ah)) {
506 */ 506 ath9k_ps_restore(sc);
507 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */ 507 return IRQ_NONE;
508 }
509
510 /*
511 * Figure out the reason(s) for the interrupt. Note
512 * that the hal returns a pseudo-ISR that may include
513 * bits we haven't explicitly enabled so we mask the
514 * value to insure we only process bits we requested.
515 */
516 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
517 status &= sc->imask; /* discard unasked-for bits */
518
519 /*
520 * If there are no status bits set, then this interrupt was not
521 * for me (should have been caught above).
522 */
523 if (!status) {
524 ath9k_ps_restore(sc);
525 return IRQ_NONE;
526 }
527
528 /* Cache the status */
529 sc->intrstatus = status;
508 530
509 status &= sc->imask; /* discard unasked-for bits */ 531 if (status & SCHED_INTR)
532 sched = true;
510 533
534 /*
535 * If a FATAL or RXORN interrupt is received, we have to reset the
536 * chip immediately.
537 */
538 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
539 goto chip_reset;
540
541 if (status & ATH9K_INT_SWBA)
542 tasklet_schedule(&sc->bcon_tasklet);
543
544 if (status & ATH9K_INT_TXURN)
545 ath9k_hw_updatetxtriglevel(ah, true);
546
547 if (status & ATH9K_INT_MIB) {
511 /* 548 /*
512 * If there are no status bits set, then this interrupt was not 549 * Disable interrupts until we service the MIB
513 * for me (should have been caught above). 550 * interrupt; otherwise it will continue to
551 * fire.
514 */ 552 */
515 if (!status) 553 ath9k_hw_set_interrupts(ah, 0);
516 return IRQ_NONE; 554 /*
517 555 * Let the hal handle the event. We assume
518 sc->intrstatus = status; 556 * it will clear whatever condition caused
519 ath9k_ps_wakeup(sc); 557 * the interrupt.
558 */
559 ath9k_hw_procmibevent(ah, &sc->nodestats);
560 ath9k_hw_set_interrupts(ah, sc->imask);
561 }
520 562
521 if (status & ATH9K_INT_FATAL) { 563 if (status & ATH9K_INT_TIM_TIMER) {
522 /* need a chip reset */ 564 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
565 /* Clear RxAbort bit so that we can
566 * receive frames */
567 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
568 ath9k_hw_setrxabort(ah, 0);
523 sched = true; 569 sched = true;
524 } else if (status & ATH9K_INT_RXORN) { 570 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
525 /* need a chip reset */
526 sched = true;
527 } else {
528 if (status & ATH9K_INT_SWBA) {
529 /* schedule a tasklet for beacon handling */
530 tasklet_schedule(&sc->bcon_tasklet);
531 }
532 if (status & ATH9K_INT_RXEOL) {
533 /*
534 * NB: the hardware should re-read the link when
535 * RXE bit is written, but it doesn't work
536 * at least on older hardware revs.
537 */
538 sched = true;
539 }
540
541 if (status & ATH9K_INT_TXURN)
542 /* bump tx trigger level */
543 ath9k_hw_updatetxtriglevel(ah, true);
544 /* XXX: optimize this */
545 if (status & ATH9K_INT_RX)
546 sched = true;
547 if (status & ATH9K_INT_TX)
548 sched = true;
549 if (status & ATH9K_INT_BMISS)
550 sched = true;
551 /* carrier sense timeout */
552 if (status & ATH9K_INT_CST)
553 sched = true;
554 if (status & ATH9K_INT_MIB) {
555 /*
556 * Disable interrupts until we service the MIB
557 * interrupt; otherwise it will continue to
558 * fire.
559 */
560 ath9k_hw_set_interrupts(ah, 0);
561 /*
562 * Let the hal handle the event. We assume
563 * it will clear whatever condition caused
564 * the interrupt.
565 */
566 ath9k_hw_procmibevent(ah, &sc->nodestats);
567 ath9k_hw_set_interrupts(ah, sc->imask);
568 }
569 if (status & ATH9K_INT_TIM_TIMER) {
570 if (!(ah->caps.hw_caps &
571 ATH9K_HW_CAP_AUTOSLEEP)) {
572 /* Clear RxAbort bit so that we can
573 * receive frames */
574 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
575 ath9k_hw_setrxabort(ah, 0);
576 sched = true;
577 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
578 }
579 }
580 if (status & ATH9K_INT_TSFOOR) {
581 /* FIXME: Handle this interrupt for power save */
582 sched = true;
583 }
584 } 571 }
585 ath9k_ps_restore(sc); 572 }
586 } while (0);
587 573
574chip_reset:
575
576 ath9k_ps_restore(sc);
588 ath_debug_stat_interrupt(sc, status); 577 ath_debug_stat_interrupt(sc, status);
589 578
590 if (sched) { 579 if (sched) {
@@ -594,6 +583,8 @@ irqreturn_t ath_isr(int irq, void *dev)
594 } 583 }
595 584
596 return IRQ_HANDLED; 585 return IRQ_HANDLED;
586
587#undef SCHED_INTR
597} 588}
598 589
599static u32 ath_get_extchanmode(struct ath_softc *sc, 590static u32 ath_get_extchanmode(struct ath_softc *sc,
@@ -676,7 +667,7 @@ static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
676 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic)); 667 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
677 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) { 668 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
678 /* TX MIC entry failed. No need to proceed further */ 669 /* TX MIC entry failed. No need to proceed further */
679 DPRINTF(sc, ATH_DBG_KEYCACHE, 670 DPRINTF(sc, ATH_DBG_FATAL,
680 "Setting TX MIC Key Failed\n"); 671 "Setting TX MIC Key Failed\n");
681 return 0; 672 return 0;
682 } 673 }
@@ -920,11 +911,9 @@ static void ath9k_bss_assoc_info(struct ath_softc *sc,
920 sc->nodestats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER; 911 sc->nodestats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER;
921 sc->nodestats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER; 912 sc->nodestats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER;
922 913
923 /* Start ANI */ 914 ath_start_ani(sc);
924 mod_timer(&sc->ani.timer,
925 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
926 } else { 915 } else {
927 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info DISSOC\n"); 916 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
928 sc->curaid = 0; 917 sc->curaid = 0;
929 } 918 }
930} 919}
@@ -1098,10 +1087,10 @@ void ath_radio_enable(struct ath_softc *sc)
1098 int r; 1087 int r;
1099 1088
1100 ath9k_ps_wakeup(sc); 1089 ath9k_ps_wakeup(sc);
1101 spin_lock_bh(&sc->sc_resetlock); 1090 ath9k_hw_configpcipowersave(ah, 0);
1102 1091
1092 spin_lock_bh(&sc->sc_resetlock);
1103 r = ath9k_hw_reset(ah, ah->curchan, false); 1093 r = ath9k_hw_reset(ah, ah->curchan, false);
1104
1105 if (r) { 1094 if (r) {
1106 DPRINTF(sc, ATH_DBG_FATAL, 1095 DPRINTF(sc, ATH_DBG_FATAL,
1107 "Unable to reset channel %u (%uMhz) ", 1096 "Unable to reset channel %u (%uMhz) ",
@@ -1163,6 +1152,7 @@ void ath_radio_disable(struct ath_softc *sc)
1163 spin_unlock_bh(&sc->sc_resetlock); 1152 spin_unlock_bh(&sc->sc_resetlock);
1164 1153
1165 ath9k_hw_phy_disable(ah); 1154 ath9k_hw_phy_disable(ah);
1155 ath9k_hw_configpcipowersave(ah, 1);
1166 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP); 1156 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1167 ath9k_ps_restore(sc); 1157 ath9k_ps_restore(sc);
1168} 1158}
@@ -1267,7 +1257,6 @@ static int ath_init_sw_rfkill(struct ath_softc *sc)
1267 sc->rf_kill.rfkill->data = sc; 1257 sc->rf_kill.rfkill->data = sc;
1268 sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio; 1258 sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio;
1269 sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED; 1259 sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED;
1270 sc->rf_kill.rfkill->user_claim_unsupported = 1;
1271 1260
1272 return 0; 1261 return 0;
1273} 1262}
@@ -1362,6 +1351,17 @@ void ath_detach(struct ath_softc *sc)
1362 ath9k_ps_restore(sc); 1351 ath9k_ps_restore(sc);
1363} 1352}
1364 1353
1354static int ath9k_reg_notifier(struct wiphy *wiphy,
1355 struct regulatory_request *request)
1356{
1357 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1358 struct ath_wiphy *aphy = hw->priv;
1359 struct ath_softc *sc = aphy->sc;
1360 struct ath_regulatory *reg = &sc->sc_ah->regulatory;
1361
1362 return ath_reg_notifier_apply(wiphy, request, reg);
1363}
1364
1365static int ath_init(u16 devid, struct ath_softc *sc) 1365static int ath_init(u16 devid, struct ath_softc *sc)
1366{ 1366{
1367 struct ath_hw *ah = NULL; 1367 struct ath_hw *ah = NULL;
@@ -1403,7 +1403,7 @@ static int ath_init(u16 devid, struct ath_softc *sc)
1403 /* Get the hardware key cache size. */ 1403 /* Get the hardware key cache size. */
1404 sc->keymax = ah->caps.keycache_size; 1404 sc->keymax = ah->caps.keycache_size;
1405 if (sc->keymax > ATH_KEYMAX) { 1405 if (sc->keymax > ATH_KEYMAX) {
1406 DPRINTF(sc, ATH_DBG_KEYCACHE, 1406 DPRINTF(sc, ATH_DBG_ANY,
1407 "Warning, using only %u entries in %u key cache\n", 1407 "Warning, using only %u entries in %u key cache\n",
1408 ATH_KEYMAX, sc->keymax); 1408 ATH_KEYMAX, sc->keymax);
1409 sc->keymax = ATH_KEYMAX; 1409 sc->keymax = ATH_KEYMAX;
@@ -1416,7 +1416,9 @@ static int ath_init(u16 devid, struct ath_softc *sc)
1416 for (i = 0; i < sc->keymax; i++) 1416 for (i = 0; i < sc->keymax; i++)
1417 ath9k_hw_keyreset(ah, (u16) i); 1417 ath9k_hw_keyreset(ah, (u16) i);
1418 1418
1419 if (ath9k_regd_init(sc->sc_ah)) 1419 error = ath_regd_init(&sc->sc_ah->regulatory, sc->hw->wiphy,
1420 ath9k_reg_notifier);
1421 if (error)
1420 goto bad; 1422 goto bad;
1421 1423
1422 /* default to MONITOR mode */ 1424 /* default to MONITOR mode */
@@ -1545,9 +1547,6 @@ static int ath_init(u16 devid, struct ath_softc *sc)
1545 sc->beacon.bslot_aphy[i] = NULL; 1547 sc->beacon.bslot_aphy[i] = NULL;
1546 } 1548 }
1547 1549
1548 /* save MISC configurations */
1549 sc->config.swBeaconProcess = 1;
1550
1551 /* setup channels and rates */ 1550 /* setup channels and rates */
1552 1551
1553 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable; 1552 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
@@ -1602,9 +1601,6 @@ void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
1602 BIT(NL80211_IFTYPE_ADHOC) | 1601 BIT(NL80211_IFTYPE_ADHOC) |
1603 BIT(NL80211_IFTYPE_MESH_POINT); 1602 BIT(NL80211_IFTYPE_MESH_POINT);
1604 1603
1605 hw->wiphy->reg_notifier = ath9k_reg_notifier;
1606 hw->wiphy->strict_regulatory = true;
1607
1608 hw->queues = 4; 1604 hw->queues = 4;
1609 hw->max_rates = 4; 1605 hw->max_rates = 4;
1610 hw->channel_change_time = 5000; 1606 hw->channel_change_time = 5000;
@@ -1625,8 +1621,8 @@ void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
1625int ath_attach(u16 devid, struct ath_softc *sc) 1621int ath_attach(u16 devid, struct ath_softc *sc)
1626{ 1622{
1627 struct ieee80211_hw *hw = sc->hw; 1623 struct ieee80211_hw *hw = sc->hw;
1628 const struct ieee80211_regdomain *regd;
1629 int error = 0, i; 1624 int error = 0, i;
1625 struct ath_regulatory *reg;
1630 1626
1631 DPRINTF(sc, ATH_DBG_CONFIG, "Attach ATH hw\n"); 1627 DPRINTF(sc, ATH_DBG_CONFIG, "Attach ATH hw\n");
1632 1628
@@ -1634,6 +1630,8 @@ int ath_attach(u16 devid, struct ath_softc *sc)
1634 if (error != 0) 1630 if (error != 0)
1635 return error; 1631 return error;
1636 1632
1633 reg = &sc->sc_ah->regulatory;
1634
1637 /* get mac address from hardware and set in mac80211 */ 1635 /* get mac address from hardware and set in mac80211 */
1638 1636
1639 SET_IEEE80211_PERM_ADDR(hw, sc->sc_ah->macaddr); 1637 SET_IEEE80211_PERM_ADDR(hw, sc->sc_ah->macaddr);
@@ -1666,31 +1664,14 @@ int ath_attach(u16 devid, struct ath_softc *sc)
1666 goto error_attach; 1664 goto error_attach;
1667#endif 1665#endif
1668 1666
1669 if (ath9k_is_world_regd(sc->sc_ah)) {
1670 /* Anything applied here (prior to wiphy registration) gets
1671 * saved on the wiphy orig_* parameters */
1672 regd = ath9k_world_regdomain(sc->sc_ah);
1673 hw->wiphy->custom_regulatory = true;
1674 hw->wiphy->strict_regulatory = false;
1675 } else {
1676 /* This gets applied in the case of the absense of CRDA,
1677 * it's our own custom world regulatory domain, similar to
1678 * cfg80211's but we enable passive scanning */
1679 regd = ath9k_default_world_regdomain();
1680 }
1681 wiphy_apply_custom_regulatory(hw->wiphy, regd);
1682 ath9k_reg_apply_radar_flags(hw->wiphy);
1683 ath9k_reg_apply_world_flags(hw->wiphy, NL80211_REGDOM_SET_BY_DRIVER);
1684
1685 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work); 1667 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
1686 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work); 1668 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
1687 sc->wiphy_scheduler_int = msecs_to_jiffies(500); 1669 sc->wiphy_scheduler_int = msecs_to_jiffies(500);
1688 1670
1689 error = ieee80211_register_hw(hw); 1671 error = ieee80211_register_hw(hw);
1690 1672
1691 if (!ath9k_is_world_regd(sc->sc_ah)) { 1673 if (!ath_is_world_regd(reg)) {
1692 error = regulatory_hint(hw->wiphy, 1674 error = regulatory_hint(hw->wiphy, reg->alpha2);
1693 sc->sc_ah->regulatory.alpha2);
1694 if (error) 1675 if (error)
1695 goto error_attach; 1676 goto error_attach;
1696 } 1677 }
@@ -1792,7 +1773,6 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
1792 goto fail; 1773 goto fail;
1793 } 1774 }
1794 1775
1795 dd->dd_name = name;
1796 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc; 1776 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
1797 1777
1798 /* 1778 /*
@@ -1822,7 +1802,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
1822 } 1802 }
1823 ds = dd->dd_desc; 1803 ds = dd->dd_desc;
1824 DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n", 1804 DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
1825 dd->dd_name, ds, (u32) dd->dd_desc_len, 1805 name, ds, (u32) dd->dd_desc_len,
1826 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len); 1806 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
1827 1807
1828 /* allocate buffers */ 1808 /* allocate buffers */
@@ -2043,8 +2023,7 @@ static int ath9k_start(struct ieee80211_hw *hw)
2043 * here except setup the interrupt mask. 2023 * here except setup the interrupt mask.
2044 */ 2024 */
2045 if (ath_startrecv(sc) != 0) { 2025 if (ath_startrecv(sc) != 0) {
2046 DPRINTF(sc, ATH_DBG_FATAL, 2026 DPRINTF(sc, ATH_DBG_FATAL, "Unable to start recv logic\n");
2047 "Unable to start recv logic\n");
2048 r = -EIO; 2027 r = -EIO;
2049 goto mutex_unlock; 2028 goto mutex_unlock;
2050 } 2029 }
@@ -2257,25 +2236,10 @@ static int ath9k_add_interface(struct ieee80211_hw *hw,
2257 sc->imask |= ATH9K_INT_TSFOOR; 2236 sc->imask |= ATH9K_INT_TSFOOR;
2258 } 2237 }
2259 2238
2260 /*
2261 * Some hardware processes the TIM IE and fires an
2262 * interrupt when the TIM bit is set. For hardware
2263 * that does, if not overridden by configuration,
2264 * enable the TIM interrupt when operating as station.
2265 */
2266 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ENHANCEDPM) &&
2267 (conf->type == NL80211_IFTYPE_STATION) &&
2268 !sc->config.swBeaconProcess)
2269 sc->imask |= ATH9K_INT_TIM;
2270
2271 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask); 2239 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
2272 2240
2273 if (conf->type == NL80211_IFTYPE_AP) { 2241 if (conf->type == NL80211_IFTYPE_AP)
2274 /* TODO: is this a suitable place to start ANI for AP mode? */ 2242 ath_start_ani(sc);
2275 /* Start ANI */
2276 mod_timer(&sc->ani.timer,
2277 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
2278 }
2279 2243
2280out: 2244out:
2281 mutex_unlock(&sc->mutex); 2245 mutex_unlock(&sc->mutex);
@@ -2326,26 +2290,33 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
2326 struct ath_wiphy *aphy = hw->priv; 2290 struct ath_wiphy *aphy = hw->priv;
2327 struct ath_softc *sc = aphy->sc; 2291 struct ath_softc *sc = aphy->sc;
2328 struct ieee80211_conf *conf = &hw->conf; 2292 struct ieee80211_conf *conf = &hw->conf;
2293 struct ath_hw *ah = sc->sc_ah;
2329 2294
2330 mutex_lock(&sc->mutex); 2295 mutex_lock(&sc->mutex);
2331 2296
2332 if (changed & IEEE80211_CONF_CHANGE_PS) { 2297 if (changed & IEEE80211_CONF_CHANGE_PS) {
2333 if (conf->flags & IEEE80211_CONF_PS) { 2298 if (conf->flags & IEEE80211_CONF_PS) {
2334 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) { 2299 if (!(ah->caps.hw_caps &
2335 sc->imask |= ATH9K_INT_TIM_TIMER; 2300 ATH9K_HW_CAP_AUTOSLEEP)) {
2336 ath9k_hw_set_interrupts(sc->sc_ah, 2301 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
2337 sc->imask); 2302 sc->imask |= ATH9K_INT_TIM_TIMER;
2303 ath9k_hw_set_interrupts(sc->sc_ah,
2304 sc->imask);
2305 }
2306 ath9k_hw_setrxabort(sc->sc_ah, 1);
2338 } 2307 }
2339 ath9k_hw_setrxabort(sc->sc_ah, 1);
2340 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP); 2308 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
2341 } else { 2309 } else {
2342 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); 2310 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
2343 ath9k_hw_setrxabort(sc->sc_ah, 0); 2311 if (!(ah->caps.hw_caps &
2344 sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON; 2312 ATH9K_HW_CAP_AUTOSLEEP)) {
2345 if (sc->imask & ATH9K_INT_TIM_TIMER) { 2313 ath9k_hw_setrxabort(sc->sc_ah, 0);
2346 sc->imask &= ~ATH9K_INT_TIM_TIMER; 2314 sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON;
2347 ath9k_hw_set_interrupts(sc->sc_ah, 2315 if (sc->imask & ATH9K_INT_TIM_TIMER) {
2348 sc->imask); 2316 sc->imask &= ~ATH9K_INT_TIM_TIMER;
2317 ath9k_hw_set_interrupts(sc->sc_ah,
2318 sc->imask);
2319 }
2349 } 2320 }
2350 } 2321 }
2351 } 2322 }
@@ -2562,6 +2533,8 @@ static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
2562 2533
2563 mutex_lock(&sc->mutex); 2534 mutex_lock(&sc->mutex);
2564 2535
2536 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
2537
2565 qi.tqi_aifs = params->aifs; 2538 qi.tqi_aifs = params->aifs;
2566 qi.tqi_cwmin = params->cw_min; 2539 qi.tqi_cwmin = params->cw_min;
2567 qi.tqi_cwmax = params->cw_max; 2540 qi.tqi_cwmax = params->cw_max;
@@ -2598,7 +2571,7 @@ static int ath9k_set_key(struct ieee80211_hw *hw,
2598 2571
2599 mutex_lock(&sc->mutex); 2572 mutex_lock(&sc->mutex);
2600 ath9k_ps_wakeup(sc); 2573 ath9k_ps_wakeup(sc);
2601 DPRINTF(sc, ATH_DBG_KEYCACHE, "Set HW Key\n"); 2574 DPRINTF(sc, ATH_DBG_CONFIG, "Set HW Key\n");
2602 2575
2603 switch (cmd) { 2576 switch (cmd) {
2604 case SET_KEY: 2577 case SET_KEY:
@@ -2771,6 +2744,7 @@ static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2771 mutex_lock(&sc->mutex); 2744 mutex_lock(&sc->mutex);
2772 aphy->state = ATH_WIPHY_ACTIVE; 2745 aphy->state = ATH_WIPHY_ACTIVE;
2773 sc->sc_flags &= ~SC_OP_SCANNING; 2746 sc->sc_flags &= ~SC_OP_SCANNING;
2747 sc->sc_flags |= SC_OP_FULL_RESET;
2774 mutex_unlock(&sc->mutex); 2748 mutex_unlock(&sc->mutex);
2775} 2749}
2776 2750
diff --git a/drivers/net/wireless/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index 6dbc58580ab..6dbc58580ab 100644
--- a/drivers/net/wireless/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
diff --git a/drivers/net/wireless/ath9k/phy.c b/drivers/net/wireless/ath/ath9k/phy.c
index 8bcba906929..5ec9ce91d97 100644
--- a/drivers/net/wireless/ath9k/phy.c
+++ b/drivers/net/wireless/ath/ath9k/phy.c
@@ -46,7 +46,7 @@ ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
46 channelSel = ((freq - 704) * 2 - 3040) / 10; 46 channelSel = ((freq - 704) * 2 - 3040) / 10;
47 bModeSynth = 1; 47 bModeSynth = 1;
48 } else { 48 } else {
49 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 49 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
50 "Invalid channel %u MHz\n", freq); 50 "Invalid channel %u MHz\n", freq);
51 return false; 51 return false;
52 } 52 }
@@ -79,7 +79,7 @@ ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
79 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8); 79 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
80 aModeRefSel = ath9k_hw_reverse_bits(1, 2); 80 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
81 } else { 81 } else {
82 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, 82 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
83 "Invalid channel %u MHz\n", freq); 83 "Invalid channel %u MHz\n", freq);
84 return false; 84 return false;
85 } 85 }
diff --git a/drivers/net/wireless/ath9k/phy.h b/drivers/net/wireless/ath/ath9k/phy.h
index 0f7f8e0c9c9..296d0e985f2 100644
--- a/drivers/net/wireless/ath9k/phy.h
+++ b/drivers/net/wireless/ath/ath9k/phy.h
@@ -556,9 +556,6 @@ bool ath9k_hw_init_rf(struct ath_hw *ah,
556 int r; \ 556 int r; \
557 for (r = 0; r < ((iniarray)->ia_rows); r++) { \ 557 for (r = 0; r < ((iniarray)->ia_rows); r++) { \
558 REG_WRITE(ah, INI_RA((iniarray), r, 0), (regData)[r]); \ 558 REG_WRITE(ah, INI_RA((iniarray), r, 0), (regData)[r]); \
559 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, \
560 "RF 0x%x V 0x%x\n", \
561 INI_RA((iniarray), r, 0), (regData)[r]); \
562 DO_DELAY(regWr); \ 559 DO_DELAY(regWr); \
563 } \ 560 } \
564 } while (0) 561 } while (0)
diff --git a/drivers/net/wireless/ath9k/rc.c b/drivers/net/wireless/ath/ath9k/rc.c
index 824ccbb8b7b..8f3cf10f65c 100644
--- a/drivers/net/wireless/ath9k/rc.c
+++ b/drivers/net/wireless/ath/ath9k/rc.c
@@ -524,7 +524,7 @@ static u8 ath_rc_init_validrates(struct ath_rate_priv *ath_rc_priv,
524 u32 valid; 524 u32 valid;
525 525
526 for (i = 0; i < rate_table->rate_cnt; i++) { 526 for (i = 0; i < rate_table->rate_cnt; i++) {
527 valid = (ath_rc_priv->single_stream ? 527 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
528 rate_table->info[i].valid_single_stream : 528 rate_table->info[i].valid_single_stream :
529 rate_table->info[i].valid); 529 rate_table->info[i].valid);
530 if (valid == 1) { 530 if (valid == 1) {
@@ -557,9 +557,9 @@ static u8 ath_rc_setvalid_rates(struct ath_rate_priv *ath_rc_priv,
557 for (i = 0; i < rateset->rs_nrates; i++) { 557 for (i = 0; i < rateset->rs_nrates; i++) {
558 for (j = 0; j < rate_table->rate_cnt; j++) { 558 for (j = 0; j < rate_table->rate_cnt; j++) {
559 u32 phy = rate_table->info[j].phy; 559 u32 phy = rate_table->info[j].phy;
560 u32 valid = (ath_rc_priv->single_stream ? 560 u32 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
561 rate_table->info[j].valid_single_stream : 561 rate_table->info[j].valid_single_stream :
562 rate_table->info[j].valid); 562 rate_table->info[j].valid);
563 u8 rate = rateset->rs_rates[i]; 563 u8 rate = rateset->rs_rates[i];
564 u8 dot11rate = rate_table->info[j].dot11rate; 564 u8 dot11rate = rate_table->info[j].dot11rate;
565 565
@@ -603,7 +603,7 @@ static u8 ath_rc_setvalid_htrates(struct ath_rate_priv *ath_rc_priv,
603 for (i = 0; i < rateset->rs_nrates; i++) { 603 for (i = 0; i < rateset->rs_nrates; i++) {
604 for (j = 0; j < rate_table->rate_cnt; j++) { 604 for (j = 0; j < rate_table->rate_cnt; j++) {
605 u32 phy = rate_table->info[j].phy; 605 u32 phy = rate_table->info[j].phy;
606 u32 valid = (ath_rc_priv->single_stream ? 606 u32 valid = (!(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ?
607 rate_table->info[j].valid_single_stream : 607 rate_table->info[j].valid_single_stream :
608 rate_table->info[j].valid); 608 rate_table->info[j].valid);
609 u8 rate = rateset->rs_rates[i]; 609 u8 rate = rateset->rs_rates[i];
@@ -740,9 +740,10 @@ static u8 ath_rc_ratefind_ht(struct ath_softc *sc,
740 if (rate > (ath_rc_priv->rate_table_size - 1)) 740 if (rate > (ath_rc_priv->rate_table_size - 1))
741 rate = ath_rc_priv->rate_table_size - 1; 741 rate = ath_rc_priv->rate_table_size - 1;
742 742
743 ASSERT((rate_table->info[rate].valid && !ath_rc_priv->single_stream) || 743 ASSERT((rate_table->info[rate].valid &&
744 (ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG)) ||
744 (rate_table->info[rate].valid_single_stream && 745 (rate_table->info[rate].valid_single_stream &&
745 ath_rc_priv->single_stream)); 746 !(ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG)));
746 747
747 return rate; 748 return rate;
748} 749}
@@ -811,7 +812,7 @@ static u8 ath_rc_rate_getidx(struct ath_softc *sc,
811 u16 min_rate) 812 u16 min_rate)
812{ 813{
813 u32 j; 814 u32 j;
814 u8 nextindex; 815 u8 nextindex = 0;
815 816
816 if (min_rate) { 817 if (min_rate) {
817 for (j = RATE_TABLE_SIZE; j > 0; j--) { 818 for (j = RATE_TABLE_SIZE; j > 0; j--) {
@@ -1320,7 +1321,7 @@ static void ath_rc_tx_status(struct ath_softc *sc,
1320 * 40 to 20 => don't update */ 1321 * 40 to 20 => don't update */
1321 1322
1322 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) && 1323 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
1323 (ath_rc_priv->rc_phy_mode != WLAN_RC_40_FLAG)) 1324 !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
1324 return; 1325 return;
1325 1326
1326 rix = ath_rc_get_rateindex(rate_table, &rates[i]); 1327 rix = ath_rc_get_rateindex(rate_table, &rates[i]);
@@ -1345,9 +1346,8 @@ static void ath_rc_tx_status(struct ath_softc *sc,
1345 1346
1346 /* If HT40 and we have switched mode from 40 to 20 => don't update */ 1347 /* If HT40 and we have switched mode from 40 to 20 => don't update */
1347 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) && 1348 if ((flags & IEEE80211_TX_RC_40_MHZ_WIDTH) &&
1348 (ath_rc_priv->rc_phy_mode != WLAN_RC_40_FLAG)) { 1349 !(ath_rc_priv->ht_cap & WLAN_RC_40_FLAG))
1349 return; 1350 return;
1350 }
1351 1351
1352 rix = ath_rc_get_rateindex(rate_table, &rates[i]); 1352 rix = ath_rc_get_rateindex(rate_table, &rates[i]);
1353 ath_rc_update_ht(sc, ath_rc_priv, tx_info_priv, rix, 1353 ath_rc_update_ht(sc, ath_rc_priv, tx_info_priv, rix,
@@ -1420,10 +1420,6 @@ static void ath_rc_init(struct ath_softc *sc,
1420 ath_rc_priv->valid_phy_rateidx[i][j] = 0; 1420 ath_rc_priv->valid_phy_rateidx[i][j] = 0;
1421 ath_rc_priv->valid_phy_ratecnt[i] = 0; 1421 ath_rc_priv->valid_phy_ratecnt[i] = 0;
1422 } 1422 }
1423 ath_rc_priv->rc_phy_mode = ath_rc_priv->ht_cap & WLAN_RC_40_FLAG;
1424
1425 /* Set stream capability */
1426 ath_rc_priv->single_stream = (ath_rc_priv->ht_cap & WLAN_RC_DS_FLAG) ? 0 : 1;
1427 1423
1428 if (!rateset->rs_nrates) { 1424 if (!rateset->rs_nrates) {
1429 /* No working rate, just initialize valid rates */ 1425 /* No working rate, just initialize valid rates */
diff --git a/drivers/net/wireless/ath9k/rc.h b/drivers/net/wireless/ath/ath9k/rc.h
index 199a3ce57d6..e3abd76103f 100644
--- a/drivers/net/wireless/ath9k/rc.h
+++ b/drivers/net/wireless/ath/ath9k/rc.h
@@ -24,7 +24,6 @@ struct ath_softc;
24#define ATH_RATE_MAX 30 24#define ATH_RATE_MAX 30
25#define RATE_TABLE_SIZE 64 25#define RATE_TABLE_SIZE 64
26#define MAX_TX_RATE_PHY 48 26#define MAX_TX_RATE_PHY 48
27#define WLAN_CTRL_FRAME_SIZE (2+2+6+4)
28 27
29/* VALID_ALL - valid for 20/40/Legacy, 28/* VALID_ALL - valid for 20/40/Legacy,
30 * VALID - Legacy only, 29 * VALID - Legacy only,
@@ -158,7 +157,6 @@ struct ath_rateset {
158 * @probe_interval: interval for ratectrl to probe for other rates 157 * @probe_interval: interval for ratectrl to probe for other rates
159 * @prev_data_rix: rate idx of last data frame 158 * @prev_data_rix: rate idx of last data frame
160 * @ht_cap: HT capabilities 159 * @ht_cap: HT capabilities
161 * @single_stream: When TRUE, only single TX stream possible
162 * @neg_rates: Negotatied rates 160 * @neg_rates: Negotatied rates
163 * @neg_ht_rates: Negotiated HT rates 161 * @neg_ht_rates: Negotiated HT rates
164 */ 162 */
@@ -176,10 +174,8 @@ struct ath_rate_priv {
176 u8 max_valid_rate; 174 u8 max_valid_rate;
177 u8 valid_rate_index[RATE_TABLE_SIZE]; 175 u8 valid_rate_index[RATE_TABLE_SIZE];
178 u8 ht_cap; 176 u8 ht_cap;
179 u8 single_stream;
180 u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX]; 177 u8 valid_phy_ratecnt[WLAN_RC_PHY_MAX];
181 u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE]; 178 u8 valid_phy_rateidx[WLAN_RC_PHY_MAX][RATE_TABLE_SIZE];
182 u8 rc_phy_mode;
183 u8 rate_max_phy; 179 u8 rate_max_phy;
184 u32 rssi_time; 180 u32 rssi_time;
185 u32 rssi_down_time; 181 u32 rssi_down_time;
diff --git a/drivers/net/wireless/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index dd1f3015674..b46badd21f7 100644
--- a/drivers/net/wireless/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -283,54 +283,51 @@ int ath_rx_init(struct ath_softc *sc, int nbufs)
283 struct ath_buf *bf; 283 struct ath_buf *bf;
284 int error = 0; 284 int error = 0;
285 285
286 do { 286 spin_lock_init(&sc->rx.rxflushlock);
287 spin_lock_init(&sc->rx.rxflushlock); 287 sc->sc_flags &= ~SC_OP_RXFLUSH;
288 sc->sc_flags &= ~SC_OP_RXFLUSH; 288 spin_lock_init(&sc->rx.rxbuflock);
289 spin_lock_init(&sc->rx.rxbuflock);
290
291 sc->rx.bufsize = roundup(IEEE80211_MAX_MPDU_LEN,
292 min(sc->cachelsz,
293 (u16)64));
294 289
295 DPRINTF(sc, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n", 290 sc->rx.bufsize = roundup(IEEE80211_MAX_MPDU_LEN,
296 sc->cachelsz, sc->rx.bufsize); 291 min(sc->cachelsz, (u16)64));
297 292
298 /* Initialize rx descriptors */ 293 DPRINTF(sc, ATH_DBG_CONFIG, "cachelsz %u rxbufsize %u\n",
294 sc->cachelsz, sc->rx.bufsize);
299 295
300 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf, 296 /* Initialize rx descriptors */
301 "rx", nbufs, 1);
302 if (error != 0) {
303 DPRINTF(sc, ATH_DBG_FATAL,
304 "failed to allocate rx descriptors: %d\n", error);
305 break;
306 }
307 297
308 list_for_each_entry(bf, &sc->rx.rxbuf, list) { 298 error = ath_descdma_setup(sc, &sc->rx.rxdma, &sc->rx.rxbuf,
309 skb = ath_rxbuf_alloc(sc, sc->rx.bufsize, GFP_KERNEL); 299 "rx", nbufs, 1);
310 if (skb == NULL) { 300 if (error != 0) {
311 error = -ENOMEM; 301 DPRINTF(sc, ATH_DBG_FATAL,
312 break; 302 "failed to allocate rx descriptors: %d\n", error);
313 } 303 goto err;
304 }
314 305
315 bf->bf_mpdu = skb; 306 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
316 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data, 307 skb = ath_rxbuf_alloc(sc, sc->rx.bufsize, GFP_KERNEL);
317 sc->rx.bufsize, 308 if (skb == NULL) {
318 DMA_FROM_DEVICE); 309 error = -ENOMEM;
319 if (unlikely(dma_mapping_error(sc->dev, 310 goto err;
320 bf->bf_buf_addr))) {
321 dev_kfree_skb_any(skb);
322 bf->bf_mpdu = NULL;
323 DPRINTF(sc, ATH_DBG_CONFIG,
324 "dma_mapping_error() on RX init\n");
325 error = -ENOMEM;
326 break;
327 }
328 bf->bf_dmacontext = bf->bf_buf_addr;
329 } 311 }
330 sc->rx.rxlink = NULL;
331 312
332 } while (0); 313 bf->bf_mpdu = skb;
314 bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
315 sc->rx.bufsize,
316 DMA_FROM_DEVICE);
317 if (unlikely(dma_mapping_error(sc->dev,
318 bf->bf_buf_addr))) {
319 dev_kfree_skb_any(skb);
320 bf->bf_mpdu = NULL;
321 DPRINTF(sc, ATH_DBG_FATAL,
322 "dma_mapping_error() on RX init\n");
323 error = -ENOMEM;
324 goto err;
325 }
326 bf->bf_dmacontext = bf->bf_buf_addr;
327 }
328 sc->rx.rxlink = NULL;
333 329
330err:
334 if (error) 331 if (error)
335 ath_rx_cleanup(sc); 332 ath_rx_cleanup(sc);
336 333
@@ -345,10 +342,8 @@ void ath_rx_cleanup(struct ath_softc *sc)
345 list_for_each_entry(bf, &sc->rx.rxbuf, list) { 342 list_for_each_entry(bf, &sc->rx.rxbuf, list) {
346 skb = bf->bf_mpdu; 343 skb = bf->bf_mpdu;
347 if (skb) { 344 if (skb) {
348 dma_unmap_single(sc->dev, 345 dma_unmap_single(sc->dev, bf->bf_buf_addr,
349 bf->bf_buf_addr, 346 sc->rx.bufsize, DMA_FROM_DEVICE);
350 sc->rx.bufsize,
351 DMA_FROM_DEVICE);
352 dev_kfree_skb(skb); 347 dev_kfree_skb(skb);
353 } 348 }
354 } 349 }
@@ -675,7 +670,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
675 bf->bf_buf_addr))) { 670 bf->bf_buf_addr))) {
676 dev_kfree_skb_any(requeue_skb); 671 dev_kfree_skb_any(requeue_skb);
677 bf->bf_mpdu = NULL; 672 bf->bf_mpdu = NULL;
678 DPRINTF(sc, ATH_DBG_CONFIG, 673 DPRINTF(sc, ATH_DBG_FATAL,
679 "dma_mapping_error() on RX\n"); 674 "dma_mapping_error() on RX\n");
680 break; 675 break;
681 } 676 }
diff --git a/drivers/net/wireless/ath9k/reg.h b/drivers/net/wireless/ath/ath9k/reg.h
index 52605246679..52605246679 100644
--- a/drivers/net/wireless/ath9k/reg.h
+++ b/drivers/net/wireless/ath/ath9k/reg.h
diff --git a/drivers/net/wireless/ath9k/virtual.c b/drivers/net/wireless/ath/ath9k/virtual.c
index 1ff429b027d..1ff429b027d 100644
--- a/drivers/net/wireless/ath9k/virtual.c
+++ b/drivers/net/wireless/ath/ath9k/virtual.c
diff --git a/drivers/net/wireless/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 689bdbf7880..faf2cab49ea 100644
--- a/drivers/net/wireless/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -283,7 +283,7 @@ static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
283 int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0; 283 int isaggr, txfail, txpending, sendbar = 0, needreset = 0, nbad = 0;
284 bool rc_update = true; 284 bool rc_update = true;
285 285
286 skb = (struct sk_buff *)bf->bf_mpdu; 286 skb = bf->bf_mpdu;
287 hdr = (struct ieee80211_hdr *)skb->data; 287 hdr = (struct ieee80211_hdr *)skb->data;
288 288
289 rcu_read_lock(); 289 rcu_read_lock();
@@ -380,8 +380,7 @@ static void ath_tx_complete_aggr(struct ath_softc *sc, struct ath_txq *txq,
380 ath_tx_complete_buf(sc, bf, &bf_head, !txfail, sendbar); 380 ath_tx_complete_buf(sc, bf, &bf_head, !txfail, sendbar);
381 } else { 381 } else {
382 /* retry the un-acked ones */ 382 /* retry the un-acked ones */
383 if (bf->bf_next == NULL && 383 if (bf->bf_next == NULL && bf_last->bf_stale) {
384 bf_last->bf_status & ATH_BUFSTATUS_STALE) {
385 struct ath_buf *tbf; 384 struct ath_buf *tbf;
386 385
387 tbf = ath_clone_txbuf(sc, bf_last); 386 tbf = ath_clone_txbuf(sc, bf_last);
@@ -444,7 +443,7 @@ static u32 ath_lookup_rate(struct ath_softc *sc, struct ath_buf *bf,
444 u16 aggr_limit, legacy = 0, maxampdu; 443 u16 aggr_limit, legacy = 0, maxampdu;
445 int i; 444 int i;
446 445
447 skb = (struct sk_buff *)bf->bf_mpdu; 446 skb = bf->bf_mpdu;
448 tx_info = IEEE80211_SKB_CB(skb); 447 tx_info = IEEE80211_SKB_CB(skb);
449 rates = tx_info->control.rates; 448 rates = tx_info->control.rates;
450 tx_info_priv = (struct ath_tx_info_priv *)tx_info->rate_driver_data[0]; 449 tx_info_priv = (struct ath_tx_info_priv *)tx_info->rate_driver_data[0];
@@ -1004,7 +1003,7 @@ void ath_draintxq(struct ath_softc *sc, struct ath_txq *txq, bool retry_tx)
1004 1003
1005 bf = list_first_entry(&txq->axq_q, struct ath_buf, list); 1004 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
1006 1005
1007 if (bf->bf_status & ATH_BUFSTATUS_STALE) { 1006 if (bf->bf_stale) {
1008 list_del(&bf->list); 1007 list_del(&bf->list);
1009 spin_unlock_bh(&txq->axq_lock); 1008 spin_unlock_bh(&txq->axq_lock);
1010 1009
@@ -1452,7 +1451,7 @@ static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf)
1452 1451
1453 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4); 1452 memset(series, 0, sizeof(struct ath9k_11n_rate_series) * 4);
1454 1453
1455 skb = (struct sk_buff *)bf->bf_mpdu; 1454 skb = bf->bf_mpdu;
1456 tx_info = IEEE80211_SKB_CB(skb); 1455 tx_info = IEEE80211_SKB_CB(skb);
1457 rates = tx_info->control.rates; 1456 rates = tx_info->control.rates;
1458 hdr = (struct ieee80211_hdr *)skb->data; 1457 hdr = (struct ieee80211_hdr *)skb->data;
@@ -1573,8 +1572,9 @@ static int ath_tx_setup_buffer(struct ieee80211_hw *hw, struct ath_buf *bf,
1573 skb->len, DMA_TO_DEVICE); 1572 skb->len, DMA_TO_DEVICE);
1574 if (unlikely(dma_mapping_error(sc->dev, bf->bf_dmacontext))) { 1573 if (unlikely(dma_mapping_error(sc->dev, bf->bf_dmacontext))) {
1575 bf->bf_mpdu = NULL; 1574 bf->bf_mpdu = NULL;
1576 DPRINTF(sc, ATH_DBG_CONFIG, 1575 kfree(tx_info_priv);
1577 "dma_mapping_error() on TX\n"); 1576 tx_info->rate_driver_data[0] = NULL;
1577 DPRINTF(sc, ATH_DBG_FATAL, "dma_mapping_error() on TX\n");
1578 return -ENOMEM; 1578 return -ENOMEM;
1579 } 1579 }
1580 1580
@@ -1586,7 +1586,7 @@ static int ath_tx_setup_buffer(struct ieee80211_hw *hw, struct ath_buf *bf,
1586static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf, 1586static void ath_tx_start_dma(struct ath_softc *sc, struct ath_buf *bf,
1587 struct ath_tx_control *txctl) 1587 struct ath_tx_control *txctl)
1588{ 1588{
1589 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu; 1589 struct sk_buff *skb = bf->bf_mpdu;
1590 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 1590 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1591 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1591 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1592 struct ath_node *an = NULL; 1592 struct ath_node *an = NULL;
@@ -1860,7 +1860,7 @@ static int ath_tx_num_badfrms(struct ath_softc *sc, struct ath_buf *bf,
1860static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds, 1860static void ath_tx_rc_status(struct ath_buf *bf, struct ath_desc *ds,
1861 int nbad, int txok, bool update_rc) 1861 int nbad, int txok, bool update_rc)
1862{ 1862{
1863 struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu; 1863 struct sk_buff *skb = bf->bf_mpdu;
1864 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 1864 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1865 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 1865 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1866 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info); 1866 struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
@@ -1941,7 +1941,7 @@ static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
1941 * it with the STALE flag. 1941 * it with the STALE flag.
1942 */ 1942 */
1943 bf_held = NULL; 1943 bf_held = NULL;
1944 if (bf->bf_status & ATH_BUFSTATUS_STALE) { 1944 if (bf->bf_stale) {
1945 bf_held = bf; 1945 bf_held = bf;
1946 if (list_is_last(&bf_held->list, &txq->axq_q)) { 1946 if (list_is_last(&bf_held->list, &txq->axq_q)) {
1947 txq->axq_link = NULL; 1947 txq->axq_link = NULL;
@@ -1982,7 +1982,7 @@ static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
1982 * however leave the last descriptor back as the holding 1982 * however leave the last descriptor back as the holding
1983 * descriptor for hw. 1983 * descriptor for hw.
1984 */ 1984 */
1985 lastbf->bf_status |= ATH_BUFSTATUS_STALE; 1985 lastbf->bf_stale = true;
1986 INIT_LIST_HEAD(&bf_head); 1986 INIT_LIST_HEAD(&bf_head);
1987 if (!list_is_singular(&lastbf->list)) 1987 if (!list_is_singular(&lastbf->list))
1988 list_cut_position(&bf_head, 1988 list_cut_position(&bf_head,
@@ -2048,44 +2048,38 @@ int ath_tx_init(struct ath_softc *sc, int nbufs)
2048{ 2048{
2049 int error = 0; 2049 int error = 0;
2050 2050
2051 do { 2051 spin_lock_init(&sc->tx.txbuflock);
2052 spin_lock_init(&sc->tx.txbuflock);
2053 2052
2054 error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf, 2053 error = ath_descdma_setup(sc, &sc->tx.txdma, &sc->tx.txbuf,
2055 "tx", nbufs, 1); 2054 "tx", nbufs, 1);
2056 if (error != 0) { 2055 if (error != 0) {
2057 DPRINTF(sc, ATH_DBG_FATAL, 2056 DPRINTF(sc, ATH_DBG_FATAL,
2058 "Failed to allocate tx descriptors: %d\n", 2057 "Failed to allocate tx descriptors: %d\n", error);
2059 error); 2058 goto err;
2060 break; 2059 }
2061 }
2062
2063 error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
2064 "beacon", ATH_BCBUF, 1);
2065 if (error != 0) {
2066 DPRINTF(sc, ATH_DBG_FATAL,
2067 "Failed to allocate beacon descriptors: %d\n",
2068 error);
2069 break;
2070 }
2071 2060
2072 } while (0); 2061 error = ath_descdma_setup(sc, &sc->beacon.bdma, &sc->beacon.bbuf,
2062 "beacon", ATH_BCBUF, 1);
2063 if (error != 0) {
2064 DPRINTF(sc, ATH_DBG_FATAL,
2065 "Failed to allocate beacon descriptors: %d\n", error);
2066 goto err;
2067 }
2073 2068
2069err:
2074 if (error != 0) 2070 if (error != 0)
2075 ath_tx_cleanup(sc); 2071 ath_tx_cleanup(sc);
2076 2072
2077 return error; 2073 return error;
2078} 2074}
2079 2075
2080int ath_tx_cleanup(struct ath_softc *sc) 2076void ath_tx_cleanup(struct ath_softc *sc)
2081{ 2077{
2082 if (sc->beacon.bdma.dd_desc_len != 0) 2078 if (sc->beacon.bdma.dd_desc_len != 0)
2083 ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf); 2079 ath_descdma_cleanup(sc, &sc->beacon.bdma, &sc->beacon.bbuf);
2084 2080
2085 if (sc->tx.txdma.dd_desc_len != 0) 2081 if (sc->tx.txdma.dd_desc_len != 0)
2086 ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf); 2082 ath_descdma_cleanup(sc, &sc->tx.txdma, &sc->tx.txbuf);
2087
2088 return 0;
2089} 2083}
2090 2084
2091void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an) 2085void ath_tx_node_init(struct ath_softc *sc, struct ath_node *an)
diff --git a/drivers/net/wireless/ath/main.c b/drivers/net/wireless/ath/main.c
new file mode 100644
index 00000000000..9949b11cb15
--- /dev/null
+++ b/drivers/net/wireless/ath/main.c
@@ -0,0 +1,22 @@
1/*
2 * Copyright (c) 2009 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19
20MODULE_AUTHOR("Atheros Communications");
21MODULE_DESCRIPTION("Shared library for Atheros wireless LAN cards.");
22MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/net/wireless/ath9k/regd.c b/drivers/net/wireless/ath/regd.c
index 4ca62510229..fdf07c82208 100644
--- a/drivers/net/wireless/ath9k/regd.c
+++ b/drivers/net/wireless/ath/regd.c
@@ -16,7 +16,9 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include "ath9k.h" 19#include <net/cfg80211.h>
20#include <net/mac80211.h>
21#include "regd.h"
20#include "regd_common.h" 22#include "regd_common.h"
21 23
22/* 24/*
@@ -55,7 +57,7 @@
55 57
56/* Can be used for: 58/* Can be used for:
57 * 0x60, 0x61, 0x62 */ 59 * 0x60, 0x61, 0x62 */
58static const struct ieee80211_regdomain ath9k_world_regdom_60_61_62 = { 60static const struct ieee80211_regdomain ath_world_regdom_60_61_62 = {
59 .n_reg_rules = 5, 61 .n_reg_rules = 5,
60 .alpha2 = "99", 62 .alpha2 = "99",
61 .reg_rules = { 63 .reg_rules = {
@@ -65,7 +67,7 @@ static const struct ieee80211_regdomain ath9k_world_regdom_60_61_62 = {
65}; 67};
66 68
67/* Can be used by 0x63 and 0x65 */ 69/* Can be used by 0x63 and 0x65 */
68static const struct ieee80211_regdomain ath9k_world_regdom_63_65 = { 70static const struct ieee80211_regdomain ath_world_regdom_63_65 = {
69 .n_reg_rules = 4, 71 .n_reg_rules = 4,
70 .alpha2 = "99", 72 .alpha2 = "99",
71 .reg_rules = { 73 .reg_rules = {
@@ -76,7 +78,7 @@ static const struct ieee80211_regdomain ath9k_world_regdom_63_65 = {
76}; 78};
77 79
78/* Can be used by 0x64 only */ 80/* Can be used by 0x64 only */
79static const struct ieee80211_regdomain ath9k_world_regdom_64 = { 81static const struct ieee80211_regdomain ath_world_regdom_64 = {
80 .n_reg_rules = 3, 82 .n_reg_rules = 3,
81 .alpha2 = "99", 83 .alpha2 = "99",
82 .reg_rules = { 84 .reg_rules = {
@@ -86,7 +88,7 @@ static const struct ieee80211_regdomain ath9k_world_regdom_64 = {
86}; 88};
87 89
88/* Can be used by 0x66 and 0x69 */ 90/* Can be used by 0x66 and 0x69 */
89static const struct ieee80211_regdomain ath9k_world_regdom_66_69 = { 91static const struct ieee80211_regdomain ath_world_regdom_66_69 = {
90 .n_reg_rules = 3, 92 .n_reg_rules = 3,
91 .alpha2 = "99", 93 .alpha2 = "99",
92 .reg_rules = { 94 .reg_rules = {
@@ -96,7 +98,7 @@ static const struct ieee80211_regdomain ath9k_world_regdom_66_69 = {
96}; 98};
97 99
98/* Can be used by 0x67, 0x6A and 0x68 */ 100/* Can be used by 0x67, 0x6A and 0x68 */
99static const struct ieee80211_regdomain ath9k_world_regdom_67_68_6A = { 101static const struct ieee80211_regdomain ath_world_regdom_67_68_6A = {
100 .n_reg_rules = 4, 102 .n_reg_rules = 4,
101 .alpha2 = "99", 103 .alpha2 = "99",
102 .reg_rules = { 104 .reg_rules = {
@@ -112,49 +114,51 @@ static inline bool is_wwr_sku(u16 regd)
112 (regd == WORLD); 114 (regd == WORLD);
113} 115}
114 116
115static u16 ath9k_regd_get_eepromRD(struct ath_hw *ah) 117static u16 ath_regd_get_eepromRD(struct ath_regulatory *reg)
116{ 118{
117 return ah->regulatory.current_rd & ~WORLDWIDE_ROAMING_FLAG; 119 return reg->current_rd & ~WORLDWIDE_ROAMING_FLAG;
118} 120}
119 121
120bool ath9k_is_world_regd(struct ath_hw *ah) 122bool ath_is_world_regd(struct ath_regulatory *reg)
121{ 123{
122 return is_wwr_sku(ath9k_regd_get_eepromRD(ah)); 124 return is_wwr_sku(ath_regd_get_eepromRD(reg));
123} 125}
126EXPORT_SYMBOL(ath_is_world_regd);
124 127
125const struct ieee80211_regdomain *ath9k_default_world_regdomain(void) 128static const struct ieee80211_regdomain *ath_default_world_regdomain(void)
126{ 129{
127 /* this is the most restrictive */ 130 /* this is the most restrictive */
128 return &ath9k_world_regdom_64; 131 return &ath_world_regdom_64;
129} 132}
130 133
131const struct ieee80211_regdomain *ath9k_world_regdomain(struct ath_hw *ah) 134static const struct
135ieee80211_regdomain *ath_world_regdomain(struct ath_regulatory *reg)
132{ 136{
133 switch (ah->regulatory.regpair->regDmnEnum) { 137 switch (reg->regpair->regDmnEnum) {
134 case 0x60: 138 case 0x60:
135 case 0x61: 139 case 0x61:
136 case 0x62: 140 case 0x62:
137 return &ath9k_world_regdom_60_61_62; 141 return &ath_world_regdom_60_61_62;
138 case 0x63: 142 case 0x63:
139 case 0x65: 143 case 0x65:
140 return &ath9k_world_regdom_63_65; 144 return &ath_world_regdom_63_65;
141 case 0x64: 145 case 0x64:
142 return &ath9k_world_regdom_64; 146 return &ath_world_regdom_64;
143 case 0x66: 147 case 0x66:
144 case 0x69: 148 case 0x69:
145 return &ath9k_world_regdom_66_69; 149 return &ath_world_regdom_66_69;
146 case 0x67: 150 case 0x67:
147 case 0x68: 151 case 0x68:
148 case 0x6A: 152 case 0x6A:
149 return &ath9k_world_regdom_67_68_6A; 153 return &ath_world_regdom_67_68_6A;
150 default: 154 default:
151 WARN_ON(1); 155 WARN_ON(1);
152 return ath9k_default_world_regdomain(); 156 return ath_default_world_regdomain();
153 } 157 }
154} 158}
155 159
156/* Frequency is one where radar detection is required */ 160/* Frequency is one where radar detection is required */
157static bool ath9k_is_radar_freq(u16 center_freq) 161static bool ath_is_radar_freq(u16 center_freq)
158{ 162{
159 return (center_freq >= 5260 && center_freq <= 5700); 163 return (center_freq >= 5260 && center_freq <= 5700);
160} 164}
@@ -168,9 +172,9 @@ static bool ath9k_is_radar_freq(u16 center_freq)
168 * received a beacon on a channel we can enable active scan and 172 * received a beacon on a channel we can enable active scan and
169 * adhoc (or beaconing). 173 * adhoc (or beaconing).
170 */ 174 */
171static void ath9k_reg_apply_beaconing_flags( 175static void
172 struct wiphy *wiphy, 176ath_reg_apply_beaconing_flags(struct wiphy *wiphy,
173 enum nl80211_reg_initiator initiator) 177 enum nl80211_reg_initiator initiator)
174{ 178{
175 enum ieee80211_band band; 179 enum ieee80211_band band;
176 struct ieee80211_supported_band *sband; 180 struct ieee80211_supported_band *sband;
@@ -191,7 +195,7 @@ static void ath9k_reg_apply_beaconing_flags(
191 195
192 ch = &sband->channels[i]; 196 ch = &sband->channels[i];
193 197
194 if (ath9k_is_radar_freq(ch->center_freq) || 198 if (ath_is_radar_freq(ch->center_freq) ||
195 (ch->flags & IEEE80211_CHAN_RADAR)) 199 (ch->flags & IEEE80211_CHAN_RADAR))
196 continue; 200 continue;
197 201
@@ -227,9 +231,9 @@ static void ath9k_reg_apply_beaconing_flags(
227} 231}
228 232
229/* Allows active scan scan on Ch 12 and 13 */ 233/* Allows active scan scan on Ch 12 and 13 */
230static void ath9k_reg_apply_active_scan_flags( 234static void
231 struct wiphy *wiphy, 235ath_reg_apply_active_scan_flags(struct wiphy *wiphy,
232 enum nl80211_reg_initiator initiator) 236 enum nl80211_reg_initiator initiator)
233{ 237{
234 struct ieee80211_supported_band *sband; 238 struct ieee80211_supported_band *sband;
235 struct ieee80211_channel *ch; 239 struct ieee80211_channel *ch;
@@ -278,7 +282,7 @@ static void ath9k_reg_apply_active_scan_flags(
278} 282}
279 283
280/* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */ 284/* Always apply Radar/DFS rules on freq range 5260 MHz - 5700 MHz */
281void ath9k_reg_apply_radar_flags(struct wiphy *wiphy) 285static void ath_reg_apply_radar_flags(struct wiphy *wiphy)
282{ 286{
283 struct ieee80211_supported_band *sband; 287 struct ieee80211_supported_band *sband;
284 struct ieee80211_channel *ch; 288 struct ieee80211_channel *ch;
@@ -291,7 +295,7 @@ void ath9k_reg_apply_radar_flags(struct wiphy *wiphy)
291 295
292 for (i = 0; i < sband->n_channels; i++) { 296 for (i = 0; i < sband->n_channels; i++) {
293 ch = &sband->channels[i]; 297 ch = &sband->channels[i];
294 if (!ath9k_is_radar_freq(ch->center_freq)) 298 if (!ath_is_radar_freq(ch->center_freq))
295 continue; 299 continue;
296 /* We always enable radar detection/DFS on this 300 /* We always enable radar detection/DFS on this
297 * frequency range. Additionally we also apply on 301 * frequency range. Additionally we also apply on
@@ -310,37 +314,31 @@ void ath9k_reg_apply_radar_flags(struct wiphy *wiphy)
310 } 314 }
311} 315}
312 316
313void ath9k_reg_apply_world_flags(struct wiphy *wiphy, 317static void ath_reg_apply_world_flags(struct wiphy *wiphy,
314 enum nl80211_reg_initiator initiator) 318 enum nl80211_reg_initiator initiator,
319 struct ath_regulatory *reg)
315{ 320{
316 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 321 switch (reg->regpair->regDmnEnum) {
317 struct ath_wiphy *aphy = hw->priv;
318 struct ath_softc *sc = aphy->sc;
319 struct ath_hw *ah = sc->sc_ah;
320
321 switch (ah->regulatory.regpair->regDmnEnum) {
322 case 0x60: 322 case 0x60:
323 case 0x63: 323 case 0x63:
324 case 0x66: 324 case 0x66:
325 case 0x67: 325 case 0x67:
326 ath9k_reg_apply_beaconing_flags(wiphy, initiator); 326 ath_reg_apply_beaconing_flags(wiphy, initiator);
327 break; 327 break;
328 case 0x68: 328 case 0x68:
329 ath9k_reg_apply_beaconing_flags(wiphy, initiator); 329 ath_reg_apply_beaconing_flags(wiphy, initiator);
330 ath9k_reg_apply_active_scan_flags(wiphy, initiator); 330 ath_reg_apply_active_scan_flags(wiphy, initiator);
331 break; 331 break;
332 } 332 }
333 return; 333 return;
334} 334}
335 335
336int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request) 336int ath_reg_notifier_apply(struct wiphy *wiphy,
337 struct regulatory_request *request,
338 struct ath_regulatory *reg)
337{ 339{
338 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
339 struct ath_wiphy *aphy = hw->priv;
340 struct ath_softc *sc = aphy->sc;
341
342 /* We always apply this */ 340 /* We always apply this */
343 ath9k_reg_apply_radar_flags(wiphy); 341 ath_reg_apply_radar_flags(wiphy);
344 342
345 switch (request->initiator) { 343 switch (request->initiator) {
346 case NL80211_REGDOM_SET_BY_DRIVER: 344 case NL80211_REGDOM_SET_BY_DRIVER:
@@ -348,17 +346,19 @@ int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
348 case NL80211_REGDOM_SET_BY_USER: 346 case NL80211_REGDOM_SET_BY_USER:
349 break; 347 break;
350 case NL80211_REGDOM_SET_BY_COUNTRY_IE: 348 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
351 if (ath9k_is_world_regd(sc->sc_ah)) 349 if (ath_is_world_regd(reg))
352 ath9k_reg_apply_world_flags(wiphy, request->initiator); 350 ath_reg_apply_world_flags(wiphy, request->initiator,
351 reg);
353 break; 352 break;
354 } 353 }
355 354
356 return 0; 355 return 0;
357} 356}
357EXPORT_SYMBOL(ath_reg_notifier_apply);
358 358
359bool ath9k_regd_is_eeprom_valid(struct ath_hw *ah) 359static bool ath_regd_is_eeprom_valid(struct ath_regulatory *reg)
360{ 360{
361 u16 rd = ath9k_regd_get_eepromRD(ah); 361 u16 rd = ath_regd_get_eepromRD(reg);
362 int i; 362 int i;
363 363
364 if (rd & COUNTRY_ERD_FLAG) { 364 if (rd & COUNTRY_ERD_FLAG) {
@@ -373,14 +373,14 @@ bool ath9k_regd_is_eeprom_valid(struct ath_hw *ah)
373 if (regDomainPairs[i].regDmnEnum == rd) 373 if (regDomainPairs[i].regDmnEnum == rd)
374 return true; 374 return true;
375 } 375 }
376 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY, 376 printk(KERN_DEBUG
377 "invalid regulatory domain/country code 0x%x\n", rd); 377 "ath: invalid regulatory domain/country code 0x%x\n", rd);
378 return false; 378 return false;
379} 379}
380 380
381/* EEPROM country code to regpair mapping */ 381/* EEPROM country code to regpair mapping */
382static struct country_code_to_enum_rd* 382static struct country_code_to_enum_rd*
383ath9k_regd_find_country(u16 countryCode) 383ath_regd_find_country(u16 countryCode)
384{ 384{
385 int i; 385 int i;
386 386
@@ -393,7 +393,7 @@ ath9k_regd_find_country(u16 countryCode)
393 393
394/* EEPROM rd code to regpair mapping */ 394/* EEPROM rd code to regpair mapping */
395static struct country_code_to_enum_rd* 395static struct country_code_to_enum_rd*
396ath9k_regd_find_country_by_rd(int regdmn) 396ath_regd_find_country_by_rd(int regdmn)
397{ 397{
398 int i; 398 int i;
399 399
@@ -405,13 +405,13 @@ ath9k_regd_find_country_by_rd(int regdmn)
405} 405}
406 406
407/* Returns the map of the EEPROM set RD to a country code */ 407/* Returns the map of the EEPROM set RD to a country code */
408static u16 ath9k_regd_get_default_country(u16 rd) 408static u16 ath_regd_get_default_country(u16 rd)
409{ 409{
410 if (rd & COUNTRY_ERD_FLAG) { 410 if (rd & COUNTRY_ERD_FLAG) {
411 struct country_code_to_enum_rd *country = NULL; 411 struct country_code_to_enum_rd *country = NULL;
412 u16 cc = rd & ~COUNTRY_ERD_FLAG; 412 u16 cc = rd & ~COUNTRY_ERD_FLAG;
413 413
414 country = ath9k_regd_find_country(cc); 414 country = ath_regd_find_country(cc);
415 if (country != NULL) 415 if (country != NULL)
416 return cc; 416 return cc;
417 } 417 }
@@ -420,7 +420,7 @@ static u16 ath9k_regd_get_default_country(u16 rd)
420} 420}
421 421
422static struct reg_dmn_pair_mapping* 422static struct reg_dmn_pair_mapping*
423ath9k_get_regpair(int regdmn) 423ath_get_regpair(int regdmn)
424{ 424{
425 int i; 425 int i;
426 426
@@ -433,87 +433,120 @@ ath9k_get_regpair(int regdmn)
433 return NULL; 433 return NULL;
434} 434}
435 435
436int ath9k_regd_init(struct ath_hw *ah) 436static int
437ath_regd_init_wiphy(struct ath_regulatory *reg,
438 struct wiphy *wiphy,
439 int (*reg_notifier)(struct wiphy *wiphy,
440 struct regulatory_request *request))
441{
442 const struct ieee80211_regdomain *regd;
443
444 wiphy->reg_notifier = reg_notifier;
445 wiphy->strict_regulatory = true;
446
447 if (ath_is_world_regd(reg)) {
448 /*
449 * Anything applied here (prior to wiphy registration) gets
450 * saved on the wiphy orig_* parameters
451 */
452 regd = ath_world_regdomain(reg);
453 wiphy->custom_regulatory = true;
454 wiphy->strict_regulatory = false;
455 } else {
456 /*
457 * This gets applied in the case of the absense of CRDA,
458 * it's our own custom world regulatory domain, similar to
459 * cfg80211's but we enable passive scanning.
460 */
461 regd = ath_default_world_regdomain();
462 }
463 wiphy_apply_custom_regulatory(wiphy, regd);
464 ath_reg_apply_radar_flags(wiphy);
465 ath_reg_apply_world_flags(wiphy, NL80211_REGDOM_SET_BY_DRIVER, reg);
466 return 0;
467}
468
469int
470ath_regd_init(struct ath_regulatory *reg,
471 struct wiphy *wiphy,
472 int (*reg_notifier)(struct wiphy *wiphy,
473 struct regulatory_request *request))
437{ 474{
438 struct country_code_to_enum_rd *country = NULL; 475 struct country_code_to_enum_rd *country = NULL;
439 u16 regdmn; 476 u16 regdmn;
440 477
441 if (!ath9k_regd_is_eeprom_valid(ah)) { 478 if (!ath_regd_is_eeprom_valid(reg)) {
442 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY, 479 printk(KERN_ERR "ath: Invalid EEPROM contents\n");
443 "Invalid EEPROM contents\n");
444 return -EINVAL; 480 return -EINVAL;
445 } 481 }
446 482
447 regdmn = ath9k_regd_get_eepromRD(ah); 483 regdmn = ath_regd_get_eepromRD(reg);
448 ah->regulatory.country_code = ath9k_regd_get_default_country(regdmn); 484 reg->country_code = ath_regd_get_default_country(regdmn);
449 485
450 if (ah->regulatory.country_code == CTRY_DEFAULT && 486 if (reg->country_code == CTRY_DEFAULT &&
451 regdmn == CTRY_DEFAULT) 487 regdmn == CTRY_DEFAULT)
452 ah->regulatory.country_code = CTRY_UNITED_STATES; 488 reg->country_code = CTRY_UNITED_STATES;
453 489
454 if (ah->regulatory.country_code == CTRY_DEFAULT) { 490 if (reg->country_code == CTRY_DEFAULT) {
455 country = NULL; 491 country = NULL;
456 } else { 492 } else {
457 country = ath9k_regd_find_country(ah->regulatory.country_code); 493 country = ath_regd_find_country(reg->country_code);
458 if (country == NULL) { 494 if (country == NULL) {
459 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY, 495 printk(KERN_DEBUG
460 "Country is NULL!!!!, cc= %d\n", 496 "ath: Country is NULL!!!!, cc= %d\n",
461 ah->regulatory.country_code); 497 reg->country_code);
462 return -EINVAL; 498 return -EINVAL;
463 } else 499 } else
464 regdmn = country->regDmnEnum; 500 regdmn = country->regDmnEnum;
465 } 501 }
466 502
467 ah->regulatory.regpair = ath9k_get_regpair(regdmn); 503 reg->regpair = ath_get_regpair(regdmn);
468 504
469 if (!ah->regulatory.regpair) { 505 if (!reg->regpair) {
470 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, 506 printk(KERN_DEBUG "ath: "
471 "No regulatory domain pair found, cannot continue\n"); 507 "No regulatory domain pair found, cannot continue\n");
472 return -EINVAL; 508 return -EINVAL;
473 } 509 }
474 510
475 if (!country) 511 if (!country)
476 country = ath9k_regd_find_country_by_rd(regdmn); 512 country = ath_regd_find_country_by_rd(regdmn);
477 513
478 if (country) { 514 if (country) {
479 ah->regulatory.alpha2[0] = country->isoName[0]; 515 reg->alpha2[0] = country->isoName[0];
480 ah->regulatory.alpha2[1] = country->isoName[1]; 516 reg->alpha2[1] = country->isoName[1];
481 } else { 517 } else {
482 ah->regulatory.alpha2[0] = '0'; 518 reg->alpha2[0] = '0';
483 ah->regulatory.alpha2[1] = '0'; 519 reg->alpha2[1] = '0';
484 } 520 }
485 521
486 DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY, 522 printk(KERN_DEBUG "ath: Country alpha2 being used: %c%c\n",
487 "Country alpha2 being used: %c%c\n" 523 reg->alpha2[0], reg->alpha2[1]);
488 "Regulatory.Regpair detected: 0x%0x\n", 524 printk(KERN_DEBUG "ath: Regpair detected: 0x%0x\n",
489 ah->regulatory.alpha2[0], ah->regulatory.alpha2[1], 525 reg->regpair->regDmnEnum);
490 ah->regulatory.regpair->regDmnEnum);
491 526
527 ath_regd_init_wiphy(reg, wiphy, reg_notifier);
492 return 0; 528 return 0;
493} 529}
530EXPORT_SYMBOL(ath_regd_init);
494 531
495u32 ath9k_regd_get_ctl(struct ath_hw *ah, struct ath9k_channel *chan) 532u32 ath_regd_get_band_ctl(struct ath_regulatory *reg,
533 enum ieee80211_band band)
496{ 534{
497 u32 ctl = NO_CTL; 535 if (!reg->regpair ||
498 536 (reg->country_code == CTRY_DEFAULT &&
499 if (!ah->regulatory.regpair || 537 is_wwr_sku(ath_regd_get_eepromRD(reg)))) {
500 (ah->regulatory.country_code == CTRY_DEFAULT && 538 return SD_NO_CTL;
501 is_wwr_sku(ath9k_regd_get_eepromRD(ah)))) {
502 if (IS_CHAN_B(chan))
503 ctl = SD_NO_CTL | CTL_11B;
504 else if (IS_CHAN_G(chan))
505 ctl = SD_NO_CTL | CTL_11G;
506 else
507 ctl = SD_NO_CTL | CTL_11A;
508 return ctl;
509 } 539 }
510 540
511 if (IS_CHAN_B(chan)) 541 switch (band) {
512 ctl = ah->regulatory.regpair->reg_2ghz_ctl | CTL_11B; 542 case IEEE80211_BAND_2GHZ:
513 else if (IS_CHAN_G(chan)) 543 return reg->regpair->reg_2ghz_ctl;
514 ctl = ah->regulatory.regpair->reg_2ghz_ctl | CTL_11G; 544 case IEEE80211_BAND_5GHZ:
515 else 545 return reg->regpair->reg_5ghz_ctl;
516 ctl = ah->regulatory.regpair->reg_5ghz_ctl | CTL_11A; 546 default:
547 return NO_CTL;
548 }
517 549
518 return ctl; 550 return NO_CTL;
519} 551}
552EXPORT_SYMBOL(ath_regd_get_band_ctl);
diff --git a/drivers/net/wireless/ath9k/regd.h b/drivers/net/wireless/ath/regd.h
index 9f5fbd4eea7..07291ccb23f 100644
--- a/drivers/net/wireless/ath9k/regd.h
+++ b/drivers/net/wireless/ath/regd.h
@@ -17,6 +17,25 @@
17#ifndef REGD_H 17#ifndef REGD_H
18#define REGD_H 18#define REGD_H
19 19
20#include <linux/nl80211.h>
21
22#include <net/cfg80211.h>
23
24#define NO_CTL 0xff
25#define SD_NO_CTL 0xE0
26#define NO_CTL 0xff
27#define CTL_MODE_M 7
28#define CTL_11A 0
29#define CTL_11B 1
30#define CTL_11G 2
31#define CTL_2GHT20 5
32#define CTL_5GHT20 6
33#define CTL_2GHT40 7
34#define CTL_5GHT40 8
35
36#define CTRY_DEBUG 0x1ff
37#define CTRY_DEFAULT 0
38
20#define COUNTRY_ERD_FLAG 0x8000 39#define COUNTRY_ERD_FLAG 0x8000
21#define WORLDWIDE_ROAMING_FLAG 0x4000 40#define WORLDWIDE_ROAMING_FLAG 0x4000
22 41
@@ -40,7 +59,7 @@ struct country_code_to_enum_rd {
40 const char *isoName; 59 const char *isoName;
41}; 60};
42 61
43struct ath9k_regulatory { 62struct ath_regulatory {
44 char alpha2[2]; 63 char alpha2[2];
45 u16 country_code; 64 u16 country_code;
46 u16 max_power_level; 65 u16 max_power_level;
@@ -233,15 +252,14 @@ enum CountryCode {
233 CTRY_BELGIUM2 = 5002 252 CTRY_BELGIUM2 = 5002
234}; 253};
235 254
236bool ath9k_is_world_regd(struct ath_hw *ah); 255bool ath_is_world_regd(struct ath_regulatory *reg);
237const struct ieee80211_regdomain *ath9k_world_regdomain(struct ath_hw *ah); 256int ath_regd_init(struct ath_regulatory *reg, struct wiphy *wiphy,
238const struct ieee80211_regdomain *ath9k_default_world_regdomain(void); 257 int (*reg_notifier)(struct wiphy *wiphy,
239void ath9k_reg_apply_world_flags(struct wiphy *wiphy, 258 struct regulatory_request *request));
240 enum nl80211_reg_initiator initiator); 259u32 ath_regd_get_band_ctl(struct ath_regulatory *reg,
241void ath9k_reg_apply_radar_flags(struct wiphy *wiphy); 260 enum ieee80211_band band);
242int ath9k_regd_init(struct ath_hw *ah); 261int ath_reg_notifier_apply(struct wiphy *wiphy,
243bool ath9k_regd_is_eeprom_valid(struct ath_hw *ah); 262 struct regulatory_request *request,
244u32 ath9k_regd_get_ctl(struct ath_hw *ah, struct ath9k_channel *chan); 263 struct ath_regulatory *reg);
245int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request);
246 264
247#endif 265#endif
diff --git a/drivers/net/wireless/ath9k/regd_common.h b/drivers/net/wireless/ath/regd_common.h
index 4d0e298cd1c..4d0e298cd1c 100644
--- a/drivers/net/wireless/ath9k/regd_common.h
+++ b/drivers/net/wireless/ath/regd_common.h
diff --git a/drivers/net/wireless/b43/Kconfig b/drivers/net/wireless/b43/Kconfig
index aab71a70ba7..21572e40b79 100644
--- a/drivers/net/wireless/b43/Kconfig
+++ b/drivers/net/wireless/b43/Kconfig
@@ -3,7 +3,6 @@ config B43
3 depends on SSB_POSSIBLE && MAC80211 && WLAN_80211 && HAS_DMA 3 depends on SSB_POSSIBLE && MAC80211 && WLAN_80211 && HAS_DMA
4 select SSB 4 select SSB
5 select FW_LOADER 5 select FW_LOADER
6 select HW_RANDOM
7 ---help--- 6 ---help---
8 b43 is a driver for the Broadcom 43xx series wireless devices. 7 b43 is a driver for the Broadcom 43xx series wireless devices.
9 8
@@ -106,6 +105,13 @@ config B43_RFKILL
106 depends on B43 && (RFKILL = y || RFKILL = B43) && RFKILL_INPUT && (INPUT_POLLDEV = y || INPUT_POLLDEV = B43) 105 depends on B43 && (RFKILL = y || RFKILL = B43) && RFKILL_INPUT && (INPUT_POLLDEV = y || INPUT_POLLDEV = B43)
107 default y 106 default y
108 107
108# This config option automatically enables b43 HW-RNG support,
109# if the HW-RNG core is enabled.
110config B43_HWRNG
111 bool
112 depends on B43 && (HW_RANDOM = y || HW_RANDOM = B43)
113 default y
114
109config B43_DEBUG 115config B43_DEBUG
110 bool "Broadcom 43xx debugging" 116 bool "Broadcom 43xx debugging"
111 depends on B43 117 depends on B43
diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h
index beaf18d6e8a..4e8ad841c3c 100644
--- a/drivers/net/wireless/b43/b43.h
+++ b/drivers/net/wireless/b43/b43.h
@@ -625,9 +625,11 @@ struct b43_wl {
625 /* Stats about the wireless interface */ 625 /* Stats about the wireless interface */
626 struct ieee80211_low_level_stats ieee_stats; 626 struct ieee80211_low_level_stats ieee_stats;
627 627
628#ifdef CONFIG_B43_HWRNG
628 struct hwrng rng; 629 struct hwrng rng;
629 u8 rng_initialized; 630 bool rng_initialized;
630 char rng_name[30 + 1]; 631 char rng_name[30 + 1];
632#endif /* CONFIG_B43_HWRNG */
631 633
632 /* The RF-kill button */ 634 /* The RF-kill button */
633 struct b43_rfkill rfkill; 635 struct b43_rfkill rfkill;
@@ -776,8 +778,8 @@ struct b43_wldev {
776 /* Reason code of the last interrupt. */ 778 /* Reason code of the last interrupt. */
777 u32 irq_reason; 779 u32 irq_reason;
778 u32 dma_reason[6]; 780 u32 dma_reason[6];
779 /* saved irq enable/disable state bitfield. */ 781 /* The currently active generic-interrupt mask. */
780 u32 irq_savedstate; 782 u32 irq_mask;
781 /* Link Quality calculation context. */ 783 /* Link Quality calculation context. */
782 struct b43_noise_calculation noisecalc; 784 struct b43_noise_calculation noisecalc;
783 /* if > 0 MAC is suspended. if == 0 MAC is enabled. */ 785 /* if > 0 MAC is suspended. if == 0 MAC is enabled. */
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 79b685e300c..a97c6ff0f12 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -673,32 +673,6 @@ static void b43_short_slot_timing_disable(struct b43_wldev *dev)
673 b43_set_slot_time(dev, 20); 673 b43_set_slot_time(dev, 20);
674} 674}
675 675
676/* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
677 * Returns the _previously_ enabled IRQ mask.
678 */
679static inline u32 b43_interrupt_enable(struct b43_wldev *dev, u32 mask)
680{
681 u32 old_mask;
682
683 old_mask = b43_read32(dev, B43_MMIO_GEN_IRQ_MASK);
684 b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, old_mask | mask);
685
686 return old_mask;
687}
688
689/* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
690 * Returns the _previously_ enabled IRQ mask.
691 */
692static inline u32 b43_interrupt_disable(struct b43_wldev *dev, u32 mask)
693{
694 u32 old_mask;
695
696 old_mask = b43_read32(dev, B43_MMIO_GEN_IRQ_MASK);
697 b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
698
699 return old_mask;
700}
701
702/* Synchronize IRQ top- and bottom-half. 676/* Synchronize IRQ top- and bottom-half.
703 * IRQs must be masked before calling this. 677 * IRQs must be masked before calling this.
704 * This must not be called with the irq_lock held. 678 * This must not be called with the irq_lock held.
@@ -1593,7 +1567,7 @@ static void handle_irq_beacon(struct b43_wldev *dev)
1593 /* This is the bottom half of the asynchronous beacon update. */ 1567 /* This is the bottom half of the asynchronous beacon update. */
1594 1568
1595 /* Ignore interrupt in the future. */ 1569 /* Ignore interrupt in the future. */
1596 dev->irq_savedstate &= ~B43_IRQ_BEACON; 1570 dev->irq_mask &= ~B43_IRQ_BEACON;
1597 1571
1598 cmd = b43_read32(dev, B43_MMIO_MACCMD); 1572 cmd = b43_read32(dev, B43_MMIO_MACCMD);
1599 beacon0_valid = (cmd & B43_MACCMD_BEACON0_VALID); 1573 beacon0_valid = (cmd & B43_MACCMD_BEACON0_VALID);
@@ -1602,7 +1576,7 @@ static void handle_irq_beacon(struct b43_wldev *dev)
1602 /* Schedule interrupt manually, if busy. */ 1576 /* Schedule interrupt manually, if busy. */
1603 if (beacon0_valid && beacon1_valid) { 1577 if (beacon0_valid && beacon1_valid) {
1604 b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_BEACON); 1578 b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_BEACON);
1605 dev->irq_savedstate |= B43_IRQ_BEACON; 1579 dev->irq_mask |= B43_IRQ_BEACON;
1606 return; 1580 return;
1607 } 1581 }
1608 1582
@@ -1641,11 +1615,9 @@ static void b43_beacon_update_trigger_work(struct work_struct *work)
1641 if (likely(dev && (b43_status(dev) >= B43_STAT_INITIALIZED))) { 1615 if (likely(dev && (b43_status(dev) >= B43_STAT_INITIALIZED))) {
1642 spin_lock_irq(&wl->irq_lock); 1616 spin_lock_irq(&wl->irq_lock);
1643 /* update beacon right away or defer to irq */ 1617 /* update beacon right away or defer to irq */
1644 dev->irq_savedstate = b43_read32(dev, B43_MMIO_GEN_IRQ_MASK);
1645 handle_irq_beacon(dev); 1618 handle_irq_beacon(dev);
1646 /* The handler might have updated the IRQ mask. */ 1619 /* The handler might have updated the IRQ mask. */
1647 b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 1620 b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
1648 dev->irq_savedstate);
1649 mmiowb(); 1621 mmiowb();
1650 spin_unlock_irq(&wl->irq_lock); 1622 spin_unlock_irq(&wl->irq_lock);
1651 } 1623 }
@@ -1879,7 +1851,7 @@ static void b43_interrupt_tasklet(struct b43_wldev *dev)
1879 if (reason & B43_IRQ_TX_OK) 1851 if (reason & B43_IRQ_TX_OK)
1880 handle_irq_transmit_status(dev); 1852 handle_irq_transmit_status(dev);
1881 1853
1882 b43_interrupt_enable(dev, dev->irq_savedstate); 1854 b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
1883 mmiowb(); 1855 mmiowb();
1884 spin_unlock_irqrestore(&dev->wl->irq_lock, flags); 1856 spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
1885} 1857}
@@ -1893,7 +1865,9 @@ static void b43_interrupt_ack(struct b43_wldev *dev, u32 reason)
1893 b43_write32(dev, B43_MMIO_DMA2_REASON, dev->dma_reason[2]); 1865 b43_write32(dev, B43_MMIO_DMA2_REASON, dev->dma_reason[2]);
1894 b43_write32(dev, B43_MMIO_DMA3_REASON, dev->dma_reason[3]); 1866 b43_write32(dev, B43_MMIO_DMA3_REASON, dev->dma_reason[3]);
1895 b43_write32(dev, B43_MMIO_DMA4_REASON, dev->dma_reason[4]); 1867 b43_write32(dev, B43_MMIO_DMA4_REASON, dev->dma_reason[4]);
1868/* Unused ring
1896 b43_write32(dev, B43_MMIO_DMA5_REASON, dev->dma_reason[5]); 1869 b43_write32(dev, B43_MMIO_DMA5_REASON, dev->dma_reason[5]);
1870*/
1897} 1871}
1898 1872
1899/* Interrupt handler top-half */ 1873/* Interrupt handler top-half */
@@ -1903,18 +1877,19 @@ static irqreturn_t b43_interrupt_handler(int irq, void *dev_id)
1903 struct b43_wldev *dev = dev_id; 1877 struct b43_wldev *dev = dev_id;
1904 u32 reason; 1878 u32 reason;
1905 1879
1906 if (!dev) 1880 B43_WARN_ON(!dev);
1907 return IRQ_NONE;
1908 1881
1909 spin_lock(&dev->wl->irq_lock); 1882 spin_lock(&dev->wl->irq_lock);
1910 1883
1911 if (b43_status(dev) < B43_STAT_STARTED) 1884 if (unlikely(b43_status(dev) < B43_STAT_STARTED)) {
1885 /* This can only happen on shared IRQ lines. */
1912 goto out; 1886 goto out;
1887 }
1913 reason = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON); 1888 reason = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
1914 if (reason == 0xffffffff) /* shared IRQ */ 1889 if (reason == 0xffffffff) /* shared IRQ */
1915 goto out; 1890 goto out;
1916 ret = IRQ_HANDLED; 1891 ret = IRQ_HANDLED;
1917 reason &= b43_read32(dev, B43_MMIO_GEN_IRQ_MASK); 1892 reason &= dev->irq_mask;
1918 if (!reason) 1893 if (!reason)
1919 goto out; 1894 goto out;
1920 1895
@@ -1928,16 +1903,18 @@ static irqreturn_t b43_interrupt_handler(int irq, void *dev_id)
1928 & 0x0001DC00; 1903 & 0x0001DC00;
1929 dev->dma_reason[4] = b43_read32(dev, B43_MMIO_DMA4_REASON) 1904 dev->dma_reason[4] = b43_read32(dev, B43_MMIO_DMA4_REASON)
1930 & 0x0000DC00; 1905 & 0x0000DC00;
1906/* Unused ring
1931 dev->dma_reason[5] = b43_read32(dev, B43_MMIO_DMA5_REASON) 1907 dev->dma_reason[5] = b43_read32(dev, B43_MMIO_DMA5_REASON)
1932 & 0x0000DC00; 1908 & 0x0000DC00;
1909*/
1933 1910
1934 b43_interrupt_ack(dev, reason); 1911 b43_interrupt_ack(dev, reason);
1935 /* disable all IRQs. They are enabled again in the bottom half. */ 1912 /* disable all IRQs. They are enabled again in the bottom half. */
1936 dev->irq_savedstate = b43_interrupt_disable(dev, B43_IRQ_ALL); 1913 b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
1937 /* save the reason code and call our bottom half. */ 1914 /* save the reason code and call our bottom half. */
1938 dev->irq_reason = reason; 1915 dev->irq_reason = reason;
1939 tasklet_schedule(&dev->isr_tasklet); 1916 tasklet_schedule(&dev->isr_tasklet);
1940 out: 1917out:
1941 mmiowb(); 1918 mmiowb();
1942 spin_unlock(&dev->wl->irq_lock); 1919 spin_unlock(&dev->wl->irq_lock);
1943 1920
@@ -2980,6 +2957,7 @@ static void b43_security_init(struct b43_wldev *dev)
2980 b43_clear_keys(dev); 2957 b43_clear_keys(dev);
2981} 2958}
2982 2959
2960#ifdef CONFIG_B43_HWRNG
2983static int b43_rng_read(struct hwrng *rng, u32 *data) 2961static int b43_rng_read(struct hwrng *rng, u32 *data)
2984{ 2962{
2985 struct b43_wl *wl = (struct b43_wl *)rng->priv; 2963 struct b43_wl *wl = (struct b43_wl *)rng->priv;
@@ -2995,17 +2973,21 @@ static int b43_rng_read(struct hwrng *rng, u32 *data)
2995 2973
2996 return (sizeof(u16)); 2974 return (sizeof(u16));
2997} 2975}
2976#endif /* CONFIG_B43_HWRNG */
2998 2977
2999static void b43_rng_exit(struct b43_wl *wl) 2978static void b43_rng_exit(struct b43_wl *wl)
3000{ 2979{
2980#ifdef CONFIG_B43_HWRNG
3001 if (wl->rng_initialized) 2981 if (wl->rng_initialized)
3002 hwrng_unregister(&wl->rng); 2982 hwrng_unregister(&wl->rng);
2983#endif /* CONFIG_B43_HWRNG */
3003} 2984}
3004 2985
3005static int b43_rng_init(struct b43_wl *wl) 2986static int b43_rng_init(struct b43_wl *wl)
3006{ 2987{
3007 int err; 2988 int err = 0;
3008 2989
2990#ifdef CONFIG_B43_HWRNG
3009 snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name), 2991 snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name),
3010 "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy)); 2992 "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy));
3011 wl->rng.name = wl->rng_name; 2993 wl->rng.name = wl->rng_name;
@@ -3018,6 +3000,7 @@ static int b43_rng_init(struct b43_wl *wl)
3018 b43err(wl, "Failed to register the random " 3000 b43err(wl, "Failed to register the random "
3019 "number generator (%d)\n", err); 3001 "number generator (%d)\n", err);
3020 } 3002 }
3003#endif /* CONFIG_B43_HWRNG */
3021 3004
3022 return err; 3005 return err;
3023} 3006}
@@ -3793,7 +3776,7 @@ static void b43_wireless_core_stop(struct b43_wldev *dev)
3793 * setting the status to INITIALIZED, as the interrupt handler 3776 * setting the status to INITIALIZED, as the interrupt handler
3794 * won't care about IRQs then. */ 3777 * won't care about IRQs then. */
3795 spin_lock_irqsave(&wl->irq_lock, flags); 3778 spin_lock_irqsave(&wl->irq_lock, flags);
3796 dev->irq_savedstate = b43_interrupt_disable(dev, B43_IRQ_ALL); 3779 b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
3797 b43_read32(dev, B43_MMIO_GEN_IRQ_MASK); /* flush */ 3780 b43_read32(dev, B43_MMIO_GEN_IRQ_MASK); /* flush */
3798 spin_unlock_irqrestore(&wl->irq_lock, flags); 3781 spin_unlock_irqrestore(&wl->irq_lock, flags);
3799 b43_synchronize_irq(dev); 3782 b43_synchronize_irq(dev);
@@ -3834,7 +3817,7 @@ static int b43_wireless_core_start(struct b43_wldev *dev)
3834 3817
3835 /* Start data flow (TX/RX). */ 3818 /* Start data flow (TX/RX). */
3836 b43_mac_enable(dev); 3819 b43_mac_enable(dev);
3837 b43_interrupt_enable(dev, dev->irq_savedstate); 3820 b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
3838 3821
3839 /* Start maintainance work */ 3822 /* Start maintainance work */
3840 b43_periodic_tasks_setup(dev); 3823 b43_periodic_tasks_setup(dev);
@@ -3997,9 +3980,9 @@ static void setup_struct_wldev_for_init(struct b43_wldev *dev)
3997 /* IRQ related flags */ 3980 /* IRQ related flags */
3998 dev->irq_reason = 0; 3981 dev->irq_reason = 0;
3999 memset(dev->dma_reason, 0, sizeof(dev->dma_reason)); 3982 memset(dev->dma_reason, 0, sizeof(dev->dma_reason));
4000 dev->irq_savedstate = B43_IRQ_MASKTEMPLATE; 3983 dev->irq_mask = B43_IRQ_MASKTEMPLATE;
4001 if (b43_modparam_verbose < B43_VERBOSITY_DEBUG) 3984 if (b43_modparam_verbose < B43_VERBOSITY_DEBUG)
4002 dev->irq_savedstate &= ~B43_IRQ_PHY_TXERR; 3985 dev->irq_mask &= ~B43_IRQ_PHY_TXERR;
4003 3986
4004 dev->mac_suspended = 1; 3987 dev->mac_suspended = 1;
4005 3988
diff --git a/drivers/net/wireless/b43/rfkill.c b/drivers/net/wireless/b43/rfkill.c
index afad4235869..9e1d00bc24d 100644
--- a/drivers/net/wireless/b43/rfkill.c
+++ b/drivers/net/wireless/b43/rfkill.c
@@ -139,7 +139,6 @@ void b43_rfkill_init(struct b43_wldev *dev)
139 rfk->rfkill->state = RFKILL_STATE_UNBLOCKED; 139 rfk->rfkill->state = RFKILL_STATE_UNBLOCKED;
140 rfk->rfkill->data = dev; 140 rfk->rfkill->data = dev;
141 rfk->rfkill->toggle_radio = b43_rfkill_soft_toggle; 141 rfk->rfkill->toggle_radio = b43_rfkill_soft_toggle;
142 rfk->rfkill->user_claim_unsupported = 1;
143 142
144 rfk->poll_dev = input_allocate_polled_device(); 143 rfk->poll_dev = input_allocate_polled_device();
145 if (!rfk->poll_dev) { 144 if (!rfk->poll_dev) {
diff --git a/drivers/net/wireless/b43legacy/Kconfig b/drivers/net/wireless/b43legacy/Kconfig
index aef2298d37a..d4f628a74bb 100644
--- a/drivers/net/wireless/b43legacy/Kconfig
+++ b/drivers/net/wireless/b43legacy/Kconfig
@@ -3,7 +3,6 @@ config B43LEGACY
3 depends on SSB_POSSIBLE && MAC80211 && WLAN_80211 && HAS_DMA 3 depends on SSB_POSSIBLE && MAC80211 && WLAN_80211 && HAS_DMA
4 select SSB 4 select SSB
5 select FW_LOADER 5 select FW_LOADER
6 select HW_RANDOM
7 ---help--- 6 ---help---
8 b43legacy is a driver for 802.11b devices from Broadcom (BCM4301 and 7 b43legacy is a driver for 802.11b devices from Broadcom (BCM4301 and
9 BCM4303) and early model 802.11g chips (BCM4306 Ver. 2) used in the 8 BCM4303) and early model 802.11g chips (BCM4306 Ver. 2) used in the
@@ -51,6 +50,13 @@ config B43LEGACY_RFKILL
51 depends on B43LEGACY && (RFKILL = y || RFKILL = B43LEGACY) && RFKILL_INPUT && (INPUT_POLLDEV = y || INPUT_POLLDEV = B43LEGACY) 50 depends on B43LEGACY && (RFKILL = y || RFKILL = B43LEGACY) && RFKILL_INPUT && (INPUT_POLLDEV = y || INPUT_POLLDEV = B43LEGACY)
52 default y 51 default y
53 52
53# This config option automatically enables b43 HW-RNG support,
54# if the HW-RNG core is enabled.
55config B43LEGACY_HWRNG
56 bool
57 depends on B43LEGACY && (HW_RANDOM = y || HW_RANDOM = B43LEGACY)
58 default y
59
54config B43LEGACY_DEBUG 60config B43LEGACY_DEBUG
55 bool "Broadcom 43xx-legacy debugging" 61 bool "Broadcom 43xx-legacy debugging"
56 depends on B43LEGACY 62 depends on B43LEGACY
diff --git a/drivers/net/wireless/b43legacy/b43legacy.h b/drivers/net/wireless/b43legacy/b43legacy.h
index 97b0e06dfe2..da59ef02b6e 100644
--- a/drivers/net/wireless/b43legacy/b43legacy.h
+++ b/drivers/net/wireless/b43legacy/b43legacy.h
@@ -59,7 +59,8 @@
59#define B43legacy_MMIO_XMITSTAT_1 0x174 59#define B43legacy_MMIO_XMITSTAT_1 0x174
60#define B43legacy_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */ 60#define B43legacy_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
61#define B43legacy_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */ 61#define B43legacy_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */
62 62#define B43legacy_MMIO_TSF_CFP_REP 0x188
63#define B43legacy_MMIO_TSF_CFP_START 0x18C
63/* 32-bit DMA */ 64/* 32-bit DMA */
64#define B43legacy_MMIO_DMA32_BASE0 0x200 65#define B43legacy_MMIO_DMA32_BASE0 0x200
65#define B43legacy_MMIO_DMA32_BASE1 0x220 66#define B43legacy_MMIO_DMA32_BASE1 0x220
@@ -258,7 +259,6 @@
258 259
259#define B43legacy_IRQ_ALL 0xFFFFFFFF 260#define B43legacy_IRQ_ALL 0xFFFFFFFF
260#define B43legacy_IRQ_MASKTEMPLATE (B43legacy_IRQ_MAC_SUSPENDED | \ 261#define B43legacy_IRQ_MASKTEMPLATE (B43legacy_IRQ_MAC_SUSPENDED | \
261 B43legacy_IRQ_BEACON | \
262 B43legacy_IRQ_TBTT_INDI | \ 262 B43legacy_IRQ_TBTT_INDI | \
263 B43legacy_IRQ_ATIM_END | \ 263 B43legacy_IRQ_ATIM_END | \
264 B43legacy_IRQ_PMQ | \ 264 B43legacy_IRQ_PMQ | \
@@ -596,9 +596,11 @@ struct b43legacy_wl {
596 /* Stats about the wireless interface */ 596 /* Stats about the wireless interface */
597 struct ieee80211_low_level_stats ieee_stats; 597 struct ieee80211_low_level_stats ieee_stats;
598 598
599#ifdef CONFIG_B43LEGACY_HWRNG
599 struct hwrng rng; 600 struct hwrng rng;
600 u8 rng_initialized; 601 u8 rng_initialized;
601 char rng_name[30 + 1]; 602 char rng_name[30 + 1];
603#endif
602 604
603 /* The RF-kill button */ 605 /* The RF-kill button */
604 struct b43legacy_rfkill rfkill; 606 struct b43legacy_rfkill rfkill;
@@ -614,6 +616,8 @@ struct b43legacy_wl {
614 struct sk_buff *current_beacon; 616 struct sk_buff *current_beacon;
615 bool beacon0_uploaded; 617 bool beacon0_uploaded;
616 bool beacon1_uploaded; 618 bool beacon1_uploaded;
619 bool beacon_templates_virgin; /* Never wrote the templates? */
620 struct work_struct beacon_update_trigger;
617}; 621};
618 622
619/* Pointers to the firmware data and meta information about it. */ 623/* Pointers to the firmware data and meta information about it. */
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index 879edc78671..ee202b4f77b 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -955,23 +955,54 @@ static void b43legacy_write_template_common(struct b43legacy_wldev *dev,
955 size + sizeof(struct b43legacy_plcp_hdr6)); 955 size + sizeof(struct b43legacy_plcp_hdr6));
956} 956}
957 957
958/* Convert a b43legacy antenna number value to the PHY TX control value. */
959static u16 b43legacy_antenna_to_phyctl(int antenna)
960{
961 switch (antenna) {
962 case B43legacy_ANTENNA0:
963 return B43legacy_TX4_PHY_ANT0;
964 case B43legacy_ANTENNA1:
965 return B43legacy_TX4_PHY_ANT1;
966 }
967 return B43legacy_TX4_PHY_ANTLAST;
968}
969
958static void b43legacy_write_beacon_template(struct b43legacy_wldev *dev, 970static void b43legacy_write_beacon_template(struct b43legacy_wldev *dev,
959 u16 ram_offset, 971 u16 ram_offset,
960 u16 shm_size_offset, u8 rate) 972 u16 shm_size_offset)
961{ 973{
962 974
963 unsigned int i, len, variable_len; 975 unsigned int i, len, variable_len;
964 const struct ieee80211_mgmt *bcn; 976 const struct ieee80211_mgmt *bcn;
965 const u8 *ie; 977 const u8 *ie;
966 bool tim_found = 0; 978 bool tim_found = 0;
979 unsigned int rate;
980 u16 ctl;
981 int antenna;
982 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(dev->wl->current_beacon);
967 983
968 bcn = (const struct ieee80211_mgmt *)(dev->wl->current_beacon->data); 984 bcn = (const struct ieee80211_mgmt *)(dev->wl->current_beacon->data);
969 len = min((size_t)dev->wl->current_beacon->len, 985 len = min((size_t)dev->wl->current_beacon->len,
970 0x200 - sizeof(struct b43legacy_plcp_hdr6)); 986 0x200 - sizeof(struct b43legacy_plcp_hdr6));
987 rate = ieee80211_get_tx_rate(dev->wl->hw, info)->hw_value;
971 988
972 b43legacy_write_template_common(dev, (const u8 *)bcn, len, ram_offset, 989 b43legacy_write_template_common(dev, (const u8 *)bcn, len, ram_offset,
973 shm_size_offset, rate); 990 shm_size_offset, rate);
974 991
992 /* Write the PHY TX control parameters. */
993 antenna = B43legacy_ANTENNA_DEFAULT;
994 antenna = b43legacy_antenna_to_phyctl(antenna);
995 ctl = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
996 B43legacy_SHM_SH_BEACPHYCTL);
997 /* We can't send beacons with short preamble. Would get PHY errors. */
998 ctl &= ~B43legacy_TX4_PHY_SHORTPRMBL;
999 ctl &= ~B43legacy_TX4_PHY_ANT;
1000 ctl &= ~B43legacy_TX4_PHY_ENC;
1001 ctl |= antenna;
1002 ctl |= B43legacy_TX4_PHY_ENC_CCK;
1003 b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
1004 B43legacy_SHM_SH_BEACPHYCTL, ctl);
1005
975 /* Find the position of the TIM and the DTIM_period value 1006 /* Find the position of the TIM and the DTIM_period value
976 * and write them to SHM. */ 1007 * and write them to SHM. */
977 ie = bcn->u.beacon.variable; 1008 ie = bcn->u.beacon.variable;
@@ -1013,7 +1044,8 @@ static void b43legacy_write_beacon_template(struct b43legacy_wldev *dev,
1013 b43legacywarn(dev->wl, "Did not find a valid TIM IE in the " 1044 b43legacywarn(dev->wl, "Did not find a valid TIM IE in the "
1014 "beacon template packet. AP or IBSS operation " 1045 "beacon template packet. AP or IBSS operation "
1015 "may be broken.\n"); 1046 "may be broken.\n");
1016 } 1047 } else
1048 b43legacydbg(dev->wl, "Updated beacon template\n");
1017} 1049}
1018 1050
1019static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev *dev, 1051static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev *dev,
@@ -1025,7 +1057,7 @@ static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev *dev,
1025 __le16 dur; 1057 __le16 dur;
1026 1058
1027 plcp.data = 0; 1059 plcp.data = 0;
1028 b43legacy_generate_plcp_hdr(&plcp, size + FCS_LEN, rate->bitrate); 1060 b43legacy_generate_plcp_hdr(&plcp, size + FCS_LEN, rate->hw_value);
1029 dur = ieee80211_generic_frame_duration(dev->wl->hw, 1061 dur = ieee80211_generic_frame_duration(dev->wl->hw,
1030 dev->wl->vif, 1062 dev->wl->vif,
1031 size, 1063 size,
@@ -1129,10 +1161,104 @@ static void b43legacy_write_probe_resp_template(struct b43legacy_wldev *dev,
1129 0x200 - sizeof(struct b43legacy_plcp_hdr6)); 1161 0x200 - sizeof(struct b43legacy_plcp_hdr6));
1130 b43legacy_write_template_common(dev, probe_resp_data, 1162 b43legacy_write_template_common(dev, probe_resp_data,
1131 size, ram_offset, 1163 size, ram_offset,
1132 shm_size_offset, rate->bitrate); 1164 shm_size_offset, rate->hw_value);
1133 kfree(probe_resp_data); 1165 kfree(probe_resp_data);
1134} 1166}
1135 1167
1168static void b43legacy_upload_beacon0(struct b43legacy_wldev *dev)
1169{
1170 struct b43legacy_wl *wl = dev->wl;
1171
1172 if (wl->beacon0_uploaded)
1173 return;
1174 b43legacy_write_beacon_template(dev, 0x68, 0x18);
1175 /* FIXME: Probe resp upload doesn't really belong here,
1176 * but we don't use that feature anyway. */
1177 b43legacy_write_probe_resp_template(dev, 0x268, 0x4A,
1178 &__b43legacy_ratetable[3]);
1179 wl->beacon0_uploaded = 1;
1180}
1181
1182static void b43legacy_upload_beacon1(struct b43legacy_wldev *dev)
1183{
1184 struct b43legacy_wl *wl = dev->wl;
1185
1186 if (wl->beacon1_uploaded)
1187 return;
1188 b43legacy_write_beacon_template(dev, 0x468, 0x1A);
1189 wl->beacon1_uploaded = 1;
1190}
1191
1192static void handle_irq_beacon(struct b43legacy_wldev *dev)
1193{
1194 struct b43legacy_wl *wl = dev->wl;
1195 u32 cmd, beacon0_valid, beacon1_valid;
1196
1197 if (!b43legacy_is_mode(wl, NL80211_IFTYPE_AP))
1198 return;
1199
1200 /* This is the bottom half of the asynchronous beacon update. */
1201
1202 /* Ignore interrupt in the future. */
1203 dev->irq_savedstate &= ~B43legacy_IRQ_BEACON;
1204
1205 cmd = b43legacy_read32(dev, B43legacy_MMIO_MACCMD);
1206 beacon0_valid = (cmd & B43legacy_MACCMD_BEACON0_VALID);
1207 beacon1_valid = (cmd & B43legacy_MACCMD_BEACON1_VALID);
1208
1209 /* Schedule interrupt manually, if busy. */
1210 if (beacon0_valid && beacon1_valid) {
1211 b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_REASON, B43legacy_IRQ_BEACON);
1212 dev->irq_savedstate |= B43legacy_IRQ_BEACON;
1213 return;
1214 }
1215
1216 if (unlikely(wl->beacon_templates_virgin)) {
1217 /* We never uploaded a beacon before.
1218 * Upload both templates now, but only mark one valid. */
1219 wl->beacon_templates_virgin = 0;
1220 b43legacy_upload_beacon0(dev);
1221 b43legacy_upload_beacon1(dev);
1222 cmd = b43legacy_read32(dev, B43legacy_MMIO_MACCMD);
1223 cmd |= B43legacy_MACCMD_BEACON0_VALID;
1224 b43legacy_write32(dev, B43legacy_MMIO_MACCMD, cmd);
1225 } else {
1226 if (!beacon0_valid) {
1227 b43legacy_upload_beacon0(dev);
1228 cmd = b43legacy_read32(dev, B43legacy_MMIO_MACCMD);
1229 cmd |= B43legacy_MACCMD_BEACON0_VALID;
1230 b43legacy_write32(dev, B43legacy_MMIO_MACCMD, cmd);
1231 } else if (!beacon1_valid) {
1232 b43legacy_upload_beacon1(dev);
1233 cmd = b43legacy_read32(dev, B43legacy_MMIO_MACCMD);
1234 cmd |= B43legacy_MACCMD_BEACON1_VALID;
1235 b43legacy_write32(dev, B43legacy_MMIO_MACCMD, cmd);
1236 }
1237 }
1238}
1239
1240static void b43legacy_beacon_update_trigger_work(struct work_struct *work)
1241{
1242 struct b43legacy_wl *wl = container_of(work, struct b43legacy_wl,
1243 beacon_update_trigger);
1244 struct b43legacy_wldev *dev;
1245
1246 mutex_lock(&wl->mutex);
1247 dev = wl->current_dev;
1248 if (likely(dev && (b43legacy_status(dev) >= B43legacy_STAT_INITIALIZED))) {
1249 spin_lock_irq(&wl->irq_lock);
1250 /* update beacon right away or defer to irq */
1251 dev->irq_savedstate = b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_MASK);
1252 handle_irq_beacon(dev);
1253 /* The handler might have updated the IRQ mask. */
1254 b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_MASK,
1255 dev->irq_savedstate);
1256 mmiowb();
1257 spin_unlock_irq(&wl->irq_lock);
1258 }
1259 mutex_unlock(&wl->mutex);
1260}
1261
1136/* Asynchronously update the packet templates in template RAM. 1262/* Asynchronously update the packet templates in template RAM.
1137 * Locking: Requires wl->irq_lock to be locked. */ 1263 * Locking: Requires wl->irq_lock to be locked. */
1138static void b43legacy_update_templates(struct b43legacy_wl *wl) 1264static void b43legacy_update_templates(struct b43legacy_wl *wl)
@@ -1156,54 +1282,24 @@ static void b43legacy_update_templates(struct b43legacy_wl *wl)
1156 wl->current_beacon = beacon; 1282 wl->current_beacon = beacon;
1157 wl->beacon0_uploaded = 0; 1283 wl->beacon0_uploaded = 0;
1158 wl->beacon1_uploaded = 0; 1284 wl->beacon1_uploaded = 0;
1285 queue_work(wl->hw->workqueue, &wl->beacon_update_trigger);
1159} 1286}
1160 1287
1161static void b43legacy_set_beacon_int(struct b43legacy_wldev *dev, 1288static void b43legacy_set_beacon_int(struct b43legacy_wldev *dev,
1162 u16 beacon_int) 1289 u16 beacon_int)
1163{ 1290{
1164 b43legacy_time_lock(dev); 1291 b43legacy_time_lock(dev);
1165 if (dev->dev->id.revision >= 3) 1292 if (dev->dev->id.revision >= 3) {
1166 b43legacy_write32(dev, 0x188, (beacon_int << 16)); 1293 b43legacy_write32(dev, B43legacy_MMIO_TSF_CFP_REP,
1167 else { 1294 (beacon_int << 16));
1295 b43legacy_write32(dev, B43legacy_MMIO_TSF_CFP_START,
1296 (beacon_int << 10));
1297 } else {
1168 b43legacy_write16(dev, 0x606, (beacon_int >> 6)); 1298 b43legacy_write16(dev, 0x606, (beacon_int >> 6));
1169 b43legacy_write16(dev, 0x610, beacon_int); 1299 b43legacy_write16(dev, 0x610, beacon_int);
1170 } 1300 }
1171 b43legacy_time_unlock(dev); 1301 b43legacy_time_unlock(dev);
1172} 1302 b43legacydbg(dev->wl, "Set beacon interval to %u\n", beacon_int);
1173
1174static void handle_irq_beacon(struct b43legacy_wldev *dev)
1175{
1176 struct b43legacy_wl *wl = dev->wl;
1177 u32 cmd;
1178
1179 if (!b43legacy_is_mode(wl, NL80211_IFTYPE_AP))
1180 return;
1181
1182 /* This is the bottom half of the asynchronous beacon update. */
1183
1184 cmd = b43legacy_read32(dev, B43legacy_MMIO_MACCMD);
1185 if (!(cmd & B43legacy_MACCMD_BEACON0_VALID)) {
1186 if (!wl->beacon0_uploaded) {
1187 b43legacy_write_beacon_template(dev, 0x68,
1188 B43legacy_SHM_SH_BTL0,
1189 B43legacy_CCK_RATE_1MB);
1190 b43legacy_write_probe_resp_template(dev, 0x268,
1191 B43legacy_SHM_SH_PRTLEN,
1192 &__b43legacy_ratetable[3]);
1193 wl->beacon0_uploaded = 1;
1194 }
1195 cmd |= B43legacy_MACCMD_BEACON0_VALID;
1196 }
1197 if (!(cmd & B43legacy_MACCMD_BEACON1_VALID)) {
1198 if (!wl->beacon1_uploaded) {
1199 b43legacy_write_beacon_template(dev, 0x468,
1200 B43legacy_SHM_SH_BTL1,
1201 B43legacy_CCK_RATE_1MB);
1202 wl->beacon1_uploaded = 1;
1203 }
1204 cmd |= B43legacy_MACCMD_BEACON1_VALID;
1205 }
1206 b43legacy_write32(dev, B43legacy_MMIO_MACCMD, cmd);
1207} 1303}
1208 1304
1209static void handle_irq_ucode_debug(struct b43legacy_wldev *dev) 1305static void handle_irq_ucode_debug(struct b43legacy_wldev *dev)
@@ -2297,6 +2393,7 @@ static void b43legacy_security_init(struct b43legacy_wldev *dev)
2297 dev->max_nr_keys - 8); 2393 dev->max_nr_keys - 8);
2298} 2394}
2299 2395
2396#ifdef CONFIG_B43LEGACY_HWRNG
2300static int b43legacy_rng_read(struct hwrng *rng, u32 *data) 2397static int b43legacy_rng_read(struct hwrng *rng, u32 *data)
2301{ 2398{
2302 struct b43legacy_wl *wl = (struct b43legacy_wl *)rng->priv; 2399 struct b43legacy_wl *wl = (struct b43legacy_wl *)rng->priv;
@@ -2312,17 +2409,21 @@ static int b43legacy_rng_read(struct hwrng *rng, u32 *data)
2312 2409
2313 return (sizeof(u16)); 2410 return (sizeof(u16));
2314} 2411}
2412#endif
2315 2413
2316static void b43legacy_rng_exit(struct b43legacy_wl *wl) 2414static void b43legacy_rng_exit(struct b43legacy_wl *wl)
2317{ 2415{
2416#ifdef CONFIG_B43LEGACY_HWRNG
2318 if (wl->rng_initialized) 2417 if (wl->rng_initialized)
2319 hwrng_unregister(&wl->rng); 2418 hwrng_unregister(&wl->rng);
2419#endif
2320} 2420}
2321 2421
2322static int b43legacy_rng_init(struct b43legacy_wl *wl) 2422static int b43legacy_rng_init(struct b43legacy_wl *wl)
2323{ 2423{
2324 int err; 2424 int err = 0;
2325 2425
2426#ifdef CONFIG_B43LEGACY_HWRNG
2326 snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name), 2427 snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name),
2327 "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy)); 2428 "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy));
2328 wl->rng.name = wl->rng_name; 2429 wl->rng.name = wl->rng_name;
@@ -2336,6 +2437,7 @@ static int b43legacy_rng_init(struct b43legacy_wl *wl)
2336 "number generator (%d)\n", err); 2437 "number generator (%d)\n", err);
2337 } 2438 }
2338 2439
2440#endif
2339 return err; 2441 return err;
2340} 2442}
2341 2443
@@ -3392,6 +3494,9 @@ static int b43legacy_op_start(struct ieee80211_hw *hw)
3392 memset(wl->bssid, 0, ETH_ALEN); 3494 memset(wl->bssid, 0, ETH_ALEN);
3393 memset(wl->mac_addr, 0, ETH_ALEN); 3495 memset(wl->mac_addr, 0, ETH_ALEN);
3394 wl->filter_flags = 0; 3496 wl->filter_flags = 0;
3497 wl->beacon0_uploaded = 0;
3498 wl->beacon1_uploaded = 0;
3499 wl->beacon_templates_virgin = 1;
3395 3500
3396 mutex_lock(&wl->mutex); 3501 mutex_lock(&wl->mutex);
3397 3502
@@ -3429,6 +3534,7 @@ static void b43legacy_op_stop(struct ieee80211_hw *hw)
3429 struct b43legacy_wldev *dev = wl->current_dev; 3534 struct b43legacy_wldev *dev = wl->current_dev;
3430 3535
3431 b43legacy_rfkill_exit(dev); 3536 b43legacy_rfkill_exit(dev);
3537 cancel_work_sync(&(wl->beacon_update_trigger));
3432 3538
3433 mutex_lock(&wl->mutex); 3539 mutex_lock(&wl->mutex);
3434 if (b43legacy_status(dev) >= B43legacy_STAT_STARTED) 3540 if (b43legacy_status(dev) >= B43legacy_STAT_STARTED)
@@ -3760,6 +3866,7 @@ static int b43legacy_wireless_init(struct ssb_device *dev)
3760 spin_lock_init(&wl->leds_lock); 3866 spin_lock_init(&wl->leds_lock);
3761 mutex_init(&wl->mutex); 3867 mutex_init(&wl->mutex);
3762 INIT_LIST_HEAD(&wl->devlist); 3868 INIT_LIST_HEAD(&wl->devlist);
3869 INIT_WORK(&wl->beacon_update_trigger, b43legacy_beacon_update_trigger_work);
3763 3870
3764 ssb_set_devtypedata(dev, wl); 3871 ssb_set_devtypedata(dev, wl);
3765 b43legacyinfo(wl, "Broadcom %04X WLAN found\n", dev->bus->chip_id); 3872 b43legacyinfo(wl, "Broadcom %04X WLAN found\n", dev->bus->chip_id);
diff --git a/drivers/net/wireless/b43legacy/rfkill.c b/drivers/net/wireless/b43legacy/rfkill.c
index b32bf6a94f1..4b0c7d27a51 100644
--- a/drivers/net/wireless/b43legacy/rfkill.c
+++ b/drivers/net/wireless/b43legacy/rfkill.c
@@ -142,7 +142,6 @@ void b43legacy_rfkill_init(struct b43legacy_wldev *dev)
142 rfk->rfkill->state = RFKILL_STATE_UNBLOCKED; 142 rfk->rfkill->state = RFKILL_STATE_UNBLOCKED;
143 rfk->rfkill->data = dev; 143 rfk->rfkill->data = dev;
144 rfk->rfkill->toggle_radio = b43legacy_rfkill_soft_toggle; 144 rfk->rfkill->toggle_radio = b43legacy_rfkill_soft_toggle;
145 rfk->rfkill->user_claim_unsupported = 1;
146 145
147 rfk->poll_dev = input_allocate_polled_device(); 146 rfk->poll_dev = input_allocate_polled_device();
148 if (!rfk->poll_dev) { 147 if (!rfk->poll_dev) {
diff --git a/drivers/net/wireless/b43legacy/xmit.c b/drivers/net/wireless/b43legacy/xmit.c
index 12fca99f757..b8e39dd06e9 100644
--- a/drivers/net/wireless/b43legacy/xmit.c
+++ b/drivers/net/wireless/b43legacy/xmit.c
@@ -274,7 +274,7 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
274 274
275 /* PHY TX Control word */ 275 /* PHY TX Control word */
276 if (rate_ofdm) 276 if (rate_ofdm)
277 phy_ctl |= B43legacy_TX4_PHY_OFDM; 277 phy_ctl |= B43legacy_TX4_PHY_ENC_OFDM;
278 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) 278 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
279 phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL; 279 phy_ctl |= B43legacy_TX4_PHY_SHORTPRMBL;
280 switch (info->antenna_sel_tx) { 280 switch (info->antenna_sel_tx) {
diff --git a/drivers/net/wireless/b43legacy/xmit.h b/drivers/net/wireless/b43legacy/xmit.h
index 62e09d02788..91633087a20 100644
--- a/drivers/net/wireless/b43legacy/xmit.h
+++ b/drivers/net/wireless/b43legacy/xmit.h
@@ -67,7 +67,9 @@ struct b43legacy_txhdr_fw3 {
67#define B43legacy_TX4_EFT_RTSFBOFDM 0x0010 /* RTS/CTS fallback rate type */ 67#define B43legacy_TX4_EFT_RTSFBOFDM 0x0010 /* RTS/CTS fallback rate type */
68 68
69/* PHY TX control word */ 69/* PHY TX control word */
70#define B43legacy_TX4_PHY_OFDM 0x0001 /* Data frame rate type */ 70#define B43legacy_TX4_PHY_ENC 0x0003 /* Data frame encoding */
71#define B43legacy_TX4_PHY_ENC_CCK 0x0000 /* CCK */
72#define B43legacy_TX4_PHY_ENC_OFDM 0x0001 /* Data frame rate type */
71#define B43legacy_TX4_PHY_SHORTPRMBL 0x0010 /* Use short preamble */ 73#define B43legacy_TX4_PHY_SHORTPRMBL 0x0010 /* Use short preamble */
72#define B43legacy_TX4_PHY_ANT 0x03C0 /* Antenna selection */ 74#define B43legacy_TX4_PHY_ANT 0x03C0 /* Antenna selection */
73#define B43legacy_TX4_PHY_ANT0 0x0000 /* Use antenna 0 */ 75#define B43legacy_TX4_PHY_ANT0 0x0000 /* Use antenna 0 */
diff --git a/drivers/net/wireless/hostap/hostap_plx.c b/drivers/net/wireless/hostap/hostap_plx.c
index cbf15d70320..0e5d51086a4 100644
--- a/drivers/net/wireless/hostap/hostap_plx.c
+++ b/drivers/net/wireless/hostap/hostap_plx.c
@@ -435,7 +435,7 @@ static int prism2_plx_probe(struct pci_dev *pdev,
435 unsigned long pccard_attr_mem; 435 unsigned long pccard_attr_mem;
436 unsigned int pccard_attr_len; 436 unsigned int pccard_attr_len;
437 void __iomem *attr_mem = NULL; 437 void __iomem *attr_mem = NULL;
438 unsigned int cor_offset, cor_index; 438 unsigned int cor_offset = 0, cor_index = 0;
439 u32 reg; 439 u32 reg;
440 local_info_t *local = NULL; 440 local_info_t *local = NULL;
441 struct net_device *dev = NULL; 441 struct net_device *dev = NULL;
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index af6b9d44477..f63a9c5ba26 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -719,7 +719,7 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
719 IWL_DEBUG_RATE(priv, "LQ: ADD station %pm\n", 719 IWL_DEBUG_RATE(priv, "LQ: ADD station %pm\n",
720 hdr->addr1); 720 hdr->addr1);
721 sta_id = iwl3945_add_station(priv, 721 sta_id = iwl3945_add_station(priv,
722 hdr->addr1, 0, CMD_ASYNC); 722 hdr->addr1, 0, CMD_ASYNC, NULL);
723 } 723 }
724 if (sta_id != IWL_INVALID_STATION) 724 if (sta_id != IWL_INVALID_STATION)
725 rs_sta->ibss_sta_added = 1; 725 rs_sta->ibss_sta_added = 1;
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 527525cc091..41f1d66cfeb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -1964,6 +1964,194 @@ int iwl3945_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
1964 return 0; 1964 return 0;
1965} 1965}
1966 1966
1967static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
1968{
1969 int rc = 0;
1970 struct iwl_rx_packet *res = NULL;
1971 struct iwl3945_rxon_assoc_cmd rxon_assoc;
1972 struct iwl_host_cmd cmd = {
1973 .id = REPLY_RXON_ASSOC,
1974 .len = sizeof(rxon_assoc),
1975 .meta.flags = CMD_WANT_SKB,
1976 .data = &rxon_assoc,
1977 };
1978 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1979 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1980
1981 if ((rxon1->flags == rxon2->flags) &&
1982 (rxon1->filter_flags == rxon2->filter_flags) &&
1983 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1984 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1985 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
1986 return 0;
1987 }
1988
1989 rxon_assoc.flags = priv->staging_rxon.flags;
1990 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1991 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1992 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1993 rxon_assoc.reserved = 0;
1994
1995 rc = iwl_send_cmd_sync(priv, &cmd);
1996 if (rc)
1997 return rc;
1998
1999 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
2000 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
2001 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
2002 rc = -EIO;
2003 }
2004
2005 priv->alloc_rxb_skb--;
2006 dev_kfree_skb_any(cmd.meta.u.skb);
2007
2008 return rc;
2009}
2010
2011/**
2012 * iwl3945_commit_rxon - commit staging_rxon to hardware
2013 *
2014 * The RXON command in staging_rxon is committed to the hardware and
2015 * the active_rxon structure is updated with the new data. This
2016 * function correctly transitions out of the RXON_ASSOC_MSK state if
2017 * a HW tune is required based on the RXON structure changes.
2018 */
2019static int iwl3945_commit_rxon(struct iwl_priv *priv)
2020{
2021 /* cast away the const for active_rxon in this function */
2022 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
2023 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
2024 int rc = 0;
2025 bool new_assoc =
2026 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
2027
2028 if (!iwl_is_alive(priv))
2029 return -1;
2030
2031 /* always get timestamp with Rx frame */
2032 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
2033
2034 /* select antenna */
2035 staging_rxon->flags &=
2036 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
2037 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
2038
2039 rc = iwl_check_rxon_cmd(priv);
2040 if (rc) {
2041 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
2042 return -EINVAL;
2043 }
2044
2045 /* If we don't need to send a full RXON, we can use
2046 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
2047 * and other flags for the current radio configuration. */
2048 if (!iwl_full_rxon_required(priv)) {
2049 rc = iwl_send_rxon_assoc(priv);
2050 if (rc) {
2051 IWL_ERR(priv, "Error setting RXON_ASSOC "
2052 "configuration (%d).\n", rc);
2053 return rc;
2054 }
2055
2056 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
2057
2058 return 0;
2059 }
2060
2061 /* If we are currently associated and the new config requires
2062 * an RXON_ASSOC and the new config wants the associated mask enabled,
2063 * we must clear the associated from the active configuration
2064 * before we apply the new config */
2065 if (iwl_is_associated(priv) && new_assoc) {
2066 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
2067 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2068
2069 /*
2070 * reserved4 and 5 could have been filled by the iwlcore code.
2071 * Let's clear them before pushing to the 3945.
2072 */
2073 active_rxon->reserved4 = 0;
2074 active_rxon->reserved5 = 0;
2075 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
2076 sizeof(struct iwl3945_rxon_cmd),
2077 &priv->active_rxon);
2078
2079 /* If the mask clearing failed then we set
2080 * active_rxon back to what it was previously */
2081 if (rc) {
2082 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
2083 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
2084 "configuration (%d).\n", rc);
2085 return rc;
2086 }
2087 }
2088
2089 IWL_DEBUG_INFO(priv, "Sending RXON\n"
2090 "* with%s RXON_FILTER_ASSOC_MSK\n"
2091 "* channel = %d\n"
2092 "* bssid = %pM\n",
2093 (new_assoc ? "" : "out"),
2094 le16_to_cpu(staging_rxon->channel),
2095 staging_rxon->bssid_addr);
2096
2097 /*
2098 * reserved4 and 5 could have been filled by the iwlcore code.
2099 * Let's clear them before pushing to the 3945.
2100 */
2101 staging_rxon->reserved4 = 0;
2102 staging_rxon->reserved5 = 0;
2103
2104 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
2105
2106 /* Apply the new configuration */
2107 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
2108 sizeof(struct iwl3945_rxon_cmd),
2109 staging_rxon);
2110 if (rc) {
2111 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
2112 return rc;
2113 }
2114
2115 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
2116
2117 priv->cfg->ops->smgmt->clear_station_table(priv);
2118
2119 /* If we issue a new RXON command which required a tune then we must
2120 * send a new TXPOWER command or we won't be able to Tx any frames */
2121 rc = priv->cfg->ops->lib->send_tx_power(priv);
2122 if (rc) {
2123 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
2124 return rc;
2125 }
2126
2127 /* Add the broadcast address so we can send broadcast frames */
2128 if (priv->cfg->ops->smgmt->add_station(priv, iwl_bcast_addr, 0, 0, NULL) ==
2129 IWL_INVALID_STATION) {
2130 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
2131 return -EIO;
2132 }
2133
2134 /* If we have set the ASSOC_MSK and we are in BSS mode then
2135 * add the IWL_AP_ID to the station rate table */
2136 if (iwl_is_associated(priv) &&
2137 (priv->iw_mode == NL80211_IFTYPE_STATION))
2138 if (priv->cfg->ops->smgmt->add_station(priv,
2139 priv->active_rxon.bssid_addr, 1, 0, NULL)
2140 == IWL_INVALID_STATION) {
2141 IWL_ERR(priv, "Error adding AP address for transmit\n");
2142 return -EIO;
2143 }
2144
2145 /* Init the hardware's rate fallback order based on the band */
2146 rc = iwl3945_init_hw_rate_table(priv);
2147 if (rc) {
2148 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
2149 return -EIO;
2150 }
2151
2152 return 0;
2153}
2154
1967/* will add 3945 channel switch cmd handling later */ 2155/* will add 3945 channel switch cmd handling later */
1968int iwl3945_hw_channel_switch(struct iwl_priv *priv, u16 channel) 2156int iwl3945_hw_channel_switch(struct iwl_priv *priv, u16 channel)
1969{ 2157{
@@ -2729,6 +2917,11 @@ static int iwl3945_load_bsm(struct iwl_priv *priv)
2729 return 0; 2917 return 0;
2730} 2918}
2731 2919
2920static struct iwl_hcmd_ops iwl3945_hcmd = {
2921 .rxon_assoc = iwl3945_send_rxon_assoc,
2922 .commit_rxon = iwl3945_commit_rxon,
2923};
2924
2732static struct iwl_lib_ops iwl3945_lib = { 2925static struct iwl_lib_ops iwl3945_lib = {
2733 .txq_attach_buf_to_tfd = iwl3945_hw_txq_attach_buf_to_tfd, 2926 .txq_attach_buf_to_tfd = iwl3945_hw_txq_attach_buf_to_tfd,
2734 .txq_free_tfd = iwl3945_hw_txq_free_tfd, 2927 .txq_free_tfd = iwl3945_hw_txq_free_tfd,
@@ -2758,6 +2951,17 @@ static struct iwl_lib_ops iwl3945_lib = {
2758 }, 2951 },
2759 .send_tx_power = iwl3945_send_tx_power, 2952 .send_tx_power = iwl3945_send_tx_power,
2760 .is_valid_rtc_data_addr = iwl3945_hw_valid_rtc_data_addr, 2953 .is_valid_rtc_data_addr = iwl3945_hw_valid_rtc_data_addr,
2954 .post_associate = iwl3945_post_associate,
2955 .config_ap = iwl3945_config_ap,
2956};
2957
2958static struct iwl_station_mgmt_ops iwl3945_station_mgmt = {
2959 .add_station = iwl3945_add_station,
2960#if 0
2961 .remove_station = iwl3945_remove_station,
2962#endif
2963 .find_station = iwl3945_hw_find_station,
2964 .clear_station_table = iwl3945_clear_stations_table,
2761}; 2965};
2762 2966
2763static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = { 2967static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
@@ -2767,7 +2971,9 @@ static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
2767 2971
2768static struct iwl_ops iwl3945_ops = { 2972static struct iwl_ops iwl3945_ops = {
2769 .lib = &iwl3945_lib, 2973 .lib = &iwl3945_lib,
2974 .hcmd = &iwl3945_hcmd,
2770 .utils = &iwl3945_hcmd_utils, 2975 .utils = &iwl3945_hcmd_utils,
2976 .smgmt = &iwl3945_station_mgmt,
2771}; 2977};
2772 2978
2773static struct iwl_cfg iwl3945_bg_cfg = { 2979static struct iwl_cfg iwl3945_bg_cfg = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index 55188844657..da87528f355 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -162,7 +162,6 @@ struct iwl3945_frame {
162#define STATUS_TEMPERATURE 8 162#define STATUS_TEMPERATURE 8
163#define STATUS_GEO_CONFIGURED 9 163#define STATUS_GEO_CONFIGURED 9
164#define STATUS_EXIT_PENDING 10 164#define STATUS_EXIT_PENDING 10
165#define STATUS_IN_SUSPEND 11
166#define STATUS_STATISTICS 12 165#define STATUS_STATISTICS 12
167#define STATUS_SCANNING 13 166#define STATUS_SCANNING 13
168#define STATUS_SCAN_ABORTING 14 167#define STATUS_SCAN_ABORTING 14
@@ -207,7 +206,8 @@ struct iwl3945_addsta_cmd;
207extern int iwl3945_send_add_station(struct iwl_priv *priv, 206extern int iwl3945_send_add_station(struct iwl_priv *priv,
208 struct iwl3945_addsta_cmd *sta, u8 flags); 207 struct iwl3945_addsta_cmd *sta, u8 flags);
209extern u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *bssid, 208extern u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *bssid,
210 int is_ap, u8 flags); 209 int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info);
210extern void iwl3945_clear_stations_table(struct iwl_priv *priv);
211extern int iwl3945_power_init_handle(struct iwl_priv *priv); 211extern int iwl3945_power_init_handle(struct iwl_priv *priv);
212extern int iwl3945_eeprom_init(struct iwl_priv *priv); 212extern int iwl3945_eeprom_init(struct iwl_priv *priv);
213extern int iwl3945_calc_db_from_ratio(int sig_ratio); 213extern int iwl3945_calc_db_from_ratio(int sig_ratio);
@@ -278,6 +278,8 @@ extern void iwl3945_hw_rx_statistics(struct iwl_priv *priv,
278 struct iwl_rx_mem_buffer *rxb); 278 struct iwl_rx_mem_buffer *rxb);
279extern void iwl3945_disable_events(struct iwl_priv *priv); 279extern void iwl3945_disable_events(struct iwl_priv *priv);
280extern int iwl4965_get_temperature(const struct iwl_priv *priv); 280extern int iwl4965_get_temperature(const struct iwl_priv *priv);
281extern void iwl3945_post_associate(struct iwl_priv *priv);
282extern void iwl3945_config_ap(struct iwl_priv *priv);
281 283
282/** 284/**
283 * iwl3945_hw_find_station - Find station id for a given BSSID 285 * iwl3945_hw_find_station - Find station id for a given BSSID
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index 847a6220c5e..a98ff4ead72 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -2268,9 +2268,17 @@ static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
2268 cancel_work_sync(&priv->txpower_work); 2268 cancel_work_sync(&priv->txpower_work);
2269} 2269}
2270 2270
2271static struct iwl_station_mgmt_ops iwl4965_station_mgmt = {
2272 .add_station = iwl_add_station_flags,
2273 .remove_station = iwl_remove_station,
2274 .find_station = iwl_find_station,
2275 .clear_station_table = iwl_clear_stations_table,
2276};
2271 2277
2272static struct iwl_hcmd_ops iwl4965_hcmd = { 2278static struct iwl_hcmd_ops iwl4965_hcmd = {
2273 .rxon_assoc = iwl4965_send_rxon_assoc, 2279 .rxon_assoc = iwl4965_send_rxon_assoc,
2280 .commit_rxon = iwl_commit_rxon,
2281 .set_rxon_chain = iwl_set_rxon_chain,
2274}; 2282};
2275 2283
2276static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = { 2284static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
@@ -2324,12 +2332,15 @@ static struct iwl_lib_ops iwl4965_lib = {
2324 .send_tx_power = iwl4965_send_tx_power, 2332 .send_tx_power = iwl4965_send_tx_power,
2325 .update_chain_flags = iwl_update_chain_flags, 2333 .update_chain_flags = iwl_update_chain_flags,
2326 .temperature = iwl4965_temperature_calib, 2334 .temperature = iwl4965_temperature_calib,
2335 .post_associate = iwl_post_associate,
2336 .config_ap = iwl_config_ap,
2327}; 2337};
2328 2338
2329static struct iwl_ops iwl4965_ops = { 2339static struct iwl_ops iwl4965_ops = {
2330 .lib = &iwl4965_lib, 2340 .lib = &iwl4965_lib,
2331 .hcmd = &iwl4965_hcmd, 2341 .hcmd = &iwl4965_hcmd,
2332 .utils = &iwl4965_hcmd_utils, 2342 .utils = &iwl4965_hcmd_utils,
2343 .smgmt = &iwl4965_station_mgmt,
2333}; 2344};
2334 2345
2335struct iwl_cfg iwl4965_agn_cfg = { 2346struct iwl_cfg iwl4965_agn_cfg = {
@@ -2350,8 +2361,6 @@ MODULE_FIRMWARE(IWL4965_MODULE_FIRMWARE(IWL4965_UCODE_API_MAX));
2350 2361
2351module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444); 2362module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
2352MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); 2363MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
2353module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
2354MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
2355module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444); 2364module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
2356MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])"); 2365MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
2357module_param_named(debug, iwl4965_mod_params.debug, uint, 0444); 2366module_param_named(debug, iwl4965_mod_params.debug, uint, 0444);
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index e5ca2511a81..d731a836e6c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -678,7 +678,7 @@ static void iwl5000_init_alive_start(struct iwl_priv *priv)
678 goto restart; 678 goto restart;
679 } 679 }
680 680
681 iwl_clear_stations_table(priv); 681 priv->cfg->ops->smgmt->clear_station_table(priv);
682 ret = priv->cfg->ops->lib->alive_notify(priv); 682 ret = priv->cfg->ops->lib->alive_notify(priv);
683 if (ret) { 683 if (ret) {
684 IWL_WARN(priv, 684 IWL_WARN(priv,
@@ -1472,8 +1472,17 @@ int iwl5000_calc_rssi(struct iwl_priv *priv,
1472 return max_rssi - agc - IWL49_RSSI_OFFSET; 1472 return max_rssi - agc - IWL49_RSSI_OFFSET;
1473} 1473}
1474 1474
1475struct iwl_station_mgmt_ops iwl5000_station_mgmt = {
1476 .add_station = iwl_add_station_flags,
1477 .remove_station = iwl_remove_station,
1478 .find_station = iwl_find_station,
1479 .clear_station_table = iwl_clear_stations_table,
1480};
1481
1475struct iwl_hcmd_ops iwl5000_hcmd = { 1482struct iwl_hcmd_ops iwl5000_hcmd = {
1476 .rxon_assoc = iwl5000_send_rxon_assoc, 1483 .rxon_assoc = iwl5000_send_rxon_assoc,
1484 .commit_rxon = iwl_commit_rxon,
1485 .set_rxon_chain = iwl_set_rxon_chain,
1477}; 1486};
1478 1487
1479struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = { 1488struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
@@ -1527,12 +1536,15 @@ struct iwl_lib_ops iwl5000_lib = {
1527 .calib_version = iwl5000_eeprom_calib_version, 1536 .calib_version = iwl5000_eeprom_calib_version,
1528 .query_addr = iwl5000_eeprom_query_addr, 1537 .query_addr = iwl5000_eeprom_query_addr,
1529 }, 1538 },
1539 .post_associate = iwl_post_associate,
1540 .config_ap = iwl_config_ap,
1530}; 1541};
1531 1542
1532struct iwl_ops iwl5000_ops = { 1543struct iwl_ops iwl5000_ops = {
1533 .lib = &iwl5000_lib, 1544 .lib = &iwl5000_lib,
1534 .hcmd = &iwl5000_hcmd, 1545 .hcmd = &iwl5000_hcmd,
1535 .utils = &iwl5000_hcmd_utils, 1546 .utils = &iwl5000_hcmd_utils,
1547 .smgmt = &iwl5000_station_mgmt,
1536}; 1548};
1537 1549
1538struct iwl_mod_params iwl50_mod_params = { 1550struct iwl_mod_params iwl50_mod_params = {
@@ -1643,9 +1655,6 @@ struct iwl_cfg iwl5150_agn_cfg = {
1643MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX)); 1655MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
1644MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX)); 1656MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));
1645 1657
1646module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
1647MODULE_PARM_DESC(disable50,
1648 "manually disable the 50XX radio (default 0 [radio on])");
1649module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444); 1658module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
1650MODULE_PARM_DESC(swcrypto50, 1659MODULE_PARM_DESC(swcrypto50,
1651 "using software crypto engine (default 0 [hardware])\n"); 1660 "using software crypto engine (default 0 [hardware])\n");
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index edfa5e149f7..ee271d7f612 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -72,6 +72,7 @@ static struct iwl_ops iwl6000_ops = {
72 .lib = &iwl5000_lib, 72 .lib = &iwl5000_lib,
73 .hcmd = &iwl5000_hcmd, 73 .hcmd = &iwl5000_hcmd,
74 .utils = &iwl6000_hcmd_utils, 74 .utils = &iwl6000_hcmd_utils,
75 .smgmt = &iwl5000_station_mgmt,
75}; 76};
76 77
77struct iwl_cfg iwl6000_2ag_cfg = { 78struct iwl_cfg iwl6000_2ag_cfg = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index cab7842a73a..3504279c758 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -52,7 +52,7 @@
52/* max allowed rate miss before sync LQ cmd */ 52/* max allowed rate miss before sync LQ cmd */
53#define IWL_MISSED_RATE_MAX 15 53#define IWL_MISSED_RATE_MAX 15
54/* max time to accum history 2 seconds */ 54/* max time to accum history 2 seconds */
55#define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) 55#define IWL_RATE_SCALE_FLUSH_INTVL (3*HZ)
56 56
57static u8 rs_ht_to_legacy[] = { 57static u8 rs_ht_to_legacy[] = {
58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, 58 IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX,
@@ -135,7 +135,7 @@ struct iwl_lq_sta {
135 u32 table_count; 135 u32 table_count;
136 u32 total_failed; /* total failed frames, any/all rates */ 136 u32 total_failed; /* total failed frames, any/all rates */
137 u32 total_success; /* total successful frames, any/all rates */ 137 u32 total_success; /* total successful frames, any/all rates */
138 u32 flush_timer; /* time staying in mode before new search */ 138 u64 flush_timer; /* time staying in mode before new search */
139 139
140 u8 action_counter; /* # mode-switch actions tried */ 140 u8 action_counter; /* # mode-switch actions tried */
141 u8 is_green; 141 u8 is_green;
@@ -167,6 +167,8 @@ struct iwl_lq_sta {
167 167
168 /* used to be in sta_info */ 168 /* used to be in sta_info */
169 int last_txrate_idx; 169 int last_txrate_idx;
170 /* last tx rate_n_flags */
171 u32 last_rate_n_flags;
170}; 172};
171 173
172static void rs_rate_scale_perform(struct iwl_priv *priv, 174static void rs_rate_scale_perform(struct iwl_priv *priv,
@@ -191,7 +193,7 @@ static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
191 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits 193 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
192 * "G" is the only table that supports CCK (the first 4 rates). 194 * "G" is the only table that supports CCK (the first 4 rates).
193 */ 195 */
194/*FIXME:RS:need to separate tables for MIMO2/MIMO3*/ 196
195static s32 expected_tpt_A[IWL_RATE_COUNT] = { 197static s32 expected_tpt_A[IWL_RATE_COUNT] = {
196 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186 198 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
197}; 199};
@@ -208,11 +210,11 @@ static s32 expected_tpt_siso20MHzSGI[IWL_RATE_COUNT] = {
208 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211 210 0, 0, 0, 0, 46, 46, 82, 110, 132, 168, 192, 202, 211
209}; 211};
210 212
211static s32 expected_tpt_mimo20MHz[IWL_RATE_COUNT] = { 213static s32 expected_tpt_mimo2_20MHz[IWL_RATE_COUNT] = {
212 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251 214 0, 0, 0, 0, 74, 74, 123, 155, 179, 214, 236, 244, 251
213}; 215};
214 216
215static s32 expected_tpt_mimo20MHzSGI[IWL_RATE_COUNT] = { 217static s32 expected_tpt_mimo2_20MHzSGI[IWL_RATE_COUNT] = {
216 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257 218 0, 0, 0, 0, 81, 81, 131, 164, 188, 222, 243, 251, 257
217}; 219};
218 220
@@ -224,14 +226,48 @@ static s32 expected_tpt_siso40MHzSGI[IWL_RATE_COUNT] = {
224 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264 226 0, 0, 0, 0, 83, 83, 135, 169, 193, 229, 250, 257, 264
225}; 227};
226 228
227static s32 expected_tpt_mimo40MHz[IWL_RATE_COUNT] = { 229static s32 expected_tpt_mimo2_40MHz[IWL_RATE_COUNT] = {
228 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289 230 0, 0, 0, 0, 123, 123, 182, 214, 235, 264, 279, 285, 289
229}; 231};
230 232
231static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = { 233static s32 expected_tpt_mimo2_40MHzSGI[IWL_RATE_COUNT] = {
232 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293 234 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
233}; 235};
234 236
237/* Expected throughput metric MIMO3 */
238static s32 expected_tpt_mimo3_20MHz[IWL_RATE_COUNT] = {
239 0, 0, 0, 0, 99, 99, 153, 186, 208, 239, 256, 263, 268
240};
241
242static s32 expected_tpt_mimo3_20MHzSGI[IWL_RATE_COUNT] = {
243 0, 0, 0, 0, 106, 106, 162, 194, 215, 246, 262, 268, 273
244};
245
246static s32 expected_tpt_mimo3_40MHz[IWL_RATE_COUNT] = {
247 0, 0, 0, 0, 152, 152, 211, 239, 255, 279, 290, 294, 297
248};
249
250static s32 expected_tpt_mimo3_40MHzSGI[IWL_RATE_COUNT] = {
251 0, 0, 0, 0, 160, 160, 219, 245, 261, 284, 294, 297, 300
252};
253
254/* mbps, mcs */
255const static struct iwl_rate_mcs_info iwl_rate_mcs[IWL_RATE_COUNT] = {
256 {"1", ""},
257 {"2", ""},
258 {"5.5", ""},
259 {"11", ""},
260 {"6", "BPSK 1/2"},
261 {"9", "BPSK 1/2"},
262 {"12", "QPSK 1/2"},
263 {"18", "QPSK 3/4"},
264 {"24", "16QAM 1/2"},
265 {"36", "16QAM 3/4"},
266 {"48", "64QAM 2/3"},
267 {"54", "64QAM 3/4"},
268 {"60", "64QAM 5/6"}
269};
270
235static inline u8 rs_extract_rate(u32 rate_n_flags) 271static inline u8 rs_extract_rate(u32 rate_n_flags)
236{ 272{
237 return (u8)(rate_n_flags & 0xFF); 273 return (u8)(rate_n_flags & 0xFF);
@@ -902,6 +938,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
902 * else look up the rate that was, finally, successful. 938 * else look up the rate that was, finally, successful.
903 */ 939 */
904 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags); 940 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags);
941 lq_sta->last_rate_n_flags = tx_rate;
905 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index); 942 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
906 943
907 /* Update frame history window with "success" if Tx got ACKed ... */ 944 /* Update frame history window with "success" if Tx got ACKed ... */
@@ -988,6 +1025,7 @@ static void rs_set_stay_in_table(struct iwl_priv *priv, u8 is_legacy,
988 lq_sta->table_count = 0; 1025 lq_sta->table_count = 0;
989 lq_sta->total_failed = 0; 1026 lq_sta->total_failed = 0;
990 lq_sta->total_success = 0; 1027 lq_sta->total_success = 0;
1028 lq_sta->flush_timer = jiffies;
991} 1029}
992 1030
993/* 1031/*
@@ -1011,17 +1049,26 @@ static void rs_set_expected_tpt_table(struct iwl_lq_sta *lq_sta,
1011 tbl->expected_tpt = expected_tpt_siso20MHzSGI; 1049 tbl->expected_tpt = expected_tpt_siso20MHzSGI;
1012 else 1050 else
1013 tbl->expected_tpt = expected_tpt_siso20MHz; 1051 tbl->expected_tpt = expected_tpt_siso20MHz;
1014 1052 } else if (is_mimo2(tbl->lq_type)) {
1015 } else if (is_mimo(tbl->lq_type)) { /* FIXME:need to separate mimo2/3 */ 1053 if (tbl->is_fat && !lq_sta->is_dup)
1054 if (tbl->is_SGI)
1055 tbl->expected_tpt = expected_tpt_mimo2_40MHzSGI;
1056 else
1057 tbl->expected_tpt = expected_tpt_mimo2_40MHz;
1058 else if (tbl->is_SGI)
1059 tbl->expected_tpt = expected_tpt_mimo2_20MHzSGI;
1060 else
1061 tbl->expected_tpt = expected_tpt_mimo2_20MHz;
1062 } else if (is_mimo3(tbl->lq_type)) {
1016 if (tbl->is_fat && !lq_sta->is_dup) 1063 if (tbl->is_fat && !lq_sta->is_dup)
1017 if (tbl->is_SGI) 1064 if (tbl->is_SGI)
1018 tbl->expected_tpt = expected_tpt_mimo40MHzSGI; 1065 tbl->expected_tpt = expected_tpt_mimo3_40MHzSGI;
1019 else 1066 else
1020 tbl->expected_tpt = expected_tpt_mimo40MHz; 1067 tbl->expected_tpt = expected_tpt_mimo3_40MHz;
1021 else if (tbl->is_SGI) 1068 else if (tbl->is_SGI)
1022 tbl->expected_tpt = expected_tpt_mimo20MHzSGI; 1069 tbl->expected_tpt = expected_tpt_mimo3_20MHzSGI;
1023 else 1070 else
1024 tbl->expected_tpt = expected_tpt_mimo20MHz; 1071 tbl->expected_tpt = expected_tpt_mimo3_20MHz;
1025 } else 1072 } else
1026 tbl->expected_tpt = expected_tpt_G; 1073 tbl->expected_tpt = expected_tpt_G;
1027} 1074}
@@ -1130,7 +1177,7 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
1130} 1177}
1131 1178
1132/* 1179/*
1133 * Set up search table for MIMO 1180 * Set up search table for MIMO2
1134 */ 1181 */
1135static int rs_switch_to_mimo2(struct iwl_priv *priv, 1182static int rs_switch_to_mimo2(struct iwl_priv *priv,
1136 struct iwl_lq_sta *lq_sta, 1183 struct iwl_lq_sta *lq_sta,
@@ -1183,7 +1230,73 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
1183 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index); 1230 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1184 1231
1185 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask); 1232 IWL_DEBUG_RATE(priv, "LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask);
1233 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1234 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1235 rate, rate_mask);
1236 return -1;
1237 }
1238 tbl->current_rate = rate_n_flags_from_tbl(priv, tbl, rate, is_green);
1239
1240 IWL_DEBUG_RATE(priv, "LQ: Switch to new mcs %X index is green %X\n",
1241 tbl->current_rate, is_green);
1242 return 0;
1243}
1244
1245/*
1246 * Set up search table for MIMO3
1247 */
1248static int rs_switch_to_mimo3(struct iwl_priv *priv,
1249 struct iwl_lq_sta *lq_sta,
1250 struct ieee80211_conf *conf,
1251 struct ieee80211_sta *sta,
1252 struct iwl_scale_tbl_info *tbl, int index)
1253{
1254 u16 rate_mask;
1255 s32 rate;
1256 s8 is_green = lq_sta->is_green;
1257
1258 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1259 return -1;
1260
1261 if (((sta->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >> 2)
1262 == WLAN_HT_CAP_SM_PS_STATIC)
1263 return -1;
1264
1265 /* Need both Tx chains/antennas to support MIMO */
1266 if (priv->hw_params.tx_chains_num < 3)
1267 return -1;
1268
1269 IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n");
1270
1271 tbl->lq_type = LQ_MIMO3;
1272 tbl->is_dup = lq_sta->is_dup;
1273 tbl->action = 0;
1274 rate_mask = lq_sta->active_mimo3_rate;
1275
1276 if (priv->current_ht_config.supported_chan_width
1277 == IWL_CHANNEL_WIDTH_40MHZ)
1278 tbl->is_fat = 1;
1279 else
1280 tbl->is_fat = 0;
1281
1282 /* FIXME: - don't toggle SGI here
1283 if (tbl->is_fat) {
1284 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1285 tbl->is_SGI = 1;
1286 else
1287 tbl->is_SGI = 0;
1288 } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY)
1289 tbl->is_SGI = 1;
1290 else
1291 tbl->is_SGI = 0;
1292 */
1293
1294 rs_set_expected_tpt_table(lq_sta, tbl);
1295
1296 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1186 1297
1298 IWL_DEBUG_RATE(priv, "LQ: MIMO3 best rate %d mask %X\n",
1299 rate, rate_mask);
1187 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { 1300 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1188 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n", 1301 IWL_DEBUG_RATE(priv, "Can't switch with index %d rate mask %x\n",
1189 rate, rate_mask); 1302 rate, rate_mask);
@@ -1342,9 +1455,29 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1342 goto out; 1455 goto out;
1343 } 1456 }
1344 break; 1457 break;
1458
1459 case IWL_LEGACY_SWITCH_MIMO3_ABC:
1460 IWL_DEBUG_RATE(priv, "LQ: Legacy switch to MIMO3\n");
1461
1462 /* Set up search table to try MIMO3 */
1463 memcpy(search_tbl, tbl, sz);
1464 search_tbl->is_SGI = 0;
1465
1466 search_tbl->ant_type = ANT_ABC;
1467
1468 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1469 break;
1470
1471 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1472 search_tbl, index);
1473 if (!ret) {
1474 lq_sta->action_counter = 0;
1475 goto out;
1476 }
1477 break;
1345 } 1478 }
1346 tbl->action++; 1479 tbl->action++;
1347 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2_BC) 1480 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1348 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; 1481 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1349 1482
1350 if (tbl->action == start_action) 1483 if (tbl->action == start_action)
@@ -1357,7 +1490,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1357out: 1490out:
1358 lq_sta->search_better_tbl = 1; 1491 lq_sta->search_better_tbl = 1;
1359 tbl->action++; 1492 tbl->action++;
1360 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2_BC) 1493 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1361 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1; 1494 tbl->action = IWL_LEGACY_SWITCH_ANTENNA1;
1362 return 0; 1495 return 0;
1363 1496
@@ -1457,9 +1590,23 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1457 rate_n_flags_from_tbl(priv, search_tbl, 1590 rate_n_flags_from_tbl(priv, search_tbl,
1458 index, is_green); 1591 index, is_green);
1459 goto out; 1592 goto out;
1593 case IWL_SISO_SWITCH_MIMO3_ABC:
1594 IWL_DEBUG_RATE(priv, "LQ: SISO switch to MIMO3\n");
1595 memcpy(search_tbl, tbl, sz);
1596 search_tbl->is_SGI = 0;
1597 search_tbl->ant_type = ANT_ABC;
1598
1599 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1600 break;
1601
1602 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1603 search_tbl, index);
1604 if (!ret)
1605 goto out;
1606 break;
1460 } 1607 }
1461 tbl->action++; 1608 tbl->action++;
1462 if (tbl->action > IWL_SISO_SWITCH_GI) 1609 if (tbl->action > IWL_LEGACY_SWITCH_MIMO3_ABC)
1463 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1610 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1464 1611
1465 if (tbl->action == start_action) 1612 if (tbl->action == start_action)
@@ -1471,15 +1618,15 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1471 out: 1618 out:
1472 lq_sta->search_better_tbl = 1; 1619 lq_sta->search_better_tbl = 1;
1473 tbl->action++; 1620 tbl->action++;
1474 if (tbl->action > IWL_SISO_SWITCH_GI) 1621 if (tbl->action > IWL_SISO_SWITCH_MIMO3_ABC)
1475 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1622 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1476 return 0; 1623 return 0;
1477} 1624}
1478 1625
1479/* 1626/*
1480 * Try to switch to new modulation mode from MIMO 1627 * Try to switch to new modulation mode from MIMO2
1481 */ 1628 */
1482static int rs_move_mimo_to_other(struct iwl_priv *priv, 1629static int rs_move_mimo2_to_other(struct iwl_priv *priv,
1483 struct iwl_lq_sta *lq_sta, 1630 struct iwl_lq_sta *lq_sta,
1484 struct ieee80211_conf *conf, 1631 struct ieee80211_conf *conf,
1485 struct ieee80211_sta *sta, int index) 1632 struct ieee80211_sta *sta, int index)
@@ -1501,7 +1648,7 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1501 switch (tbl->action) { 1648 switch (tbl->action) {
1502 case IWL_MIMO2_SWITCH_ANTENNA1: 1649 case IWL_MIMO2_SWITCH_ANTENNA1:
1503 case IWL_MIMO2_SWITCH_ANTENNA2: 1650 case IWL_MIMO2_SWITCH_ANTENNA2:
1504 IWL_DEBUG_RATE(priv, "LQ: MIMO toggle Antennas\n"); 1651 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle Antennas\n");
1505 1652
1506 if (tx_chains_num <= 2) 1653 if (tx_chains_num <= 2)
1507 break; 1654 break;
@@ -1549,9 +1696,9 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1549 HT_SHORT_GI_40MHZ)) 1696 HT_SHORT_GI_40MHZ))
1550 break; 1697 break;
1551 1698
1552 IWL_DEBUG_RATE(priv, "LQ: MIMO toggle SGI/NGI\n"); 1699 IWL_DEBUG_RATE(priv, "LQ: MIMO2 toggle SGI/NGI\n");
1553 1700
1554 /* Set up new search table for MIMO */ 1701 /* Set up new search table for MIMO2 */
1555 memcpy(search_tbl, tbl, sz); 1702 memcpy(search_tbl, tbl, sz);
1556 search_tbl->is_SGI = !tbl->is_SGI; 1703 search_tbl->is_SGI = !tbl->is_SGI;
1557 rs_set_expected_tpt_table(lq_sta, search_tbl); 1704 rs_set_expected_tpt_table(lq_sta, search_tbl);
@@ -1571,9 +1718,24 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1571 index, is_green); 1718 index, is_green);
1572 goto out; 1719 goto out;
1573 1720
1721 case IWL_MIMO2_SWITCH_MIMO3_ABC:
1722 IWL_DEBUG_RATE(priv, "LQ: MIMO2 switch to MIMO3\n");
1723 memcpy(search_tbl, tbl, sz);
1724 search_tbl->is_SGI = 0;
1725 search_tbl->ant_type = ANT_ABC;
1726
1727 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1728 break;
1729
1730 ret = rs_switch_to_mimo3(priv, lq_sta, conf, sta,
1731 search_tbl, index);
1732 if (!ret)
1733 goto out;
1734
1735 break;
1574 } 1736 }
1575 tbl->action++; 1737 tbl->action++;
1576 if (tbl->action > IWL_MIMO2_SWITCH_GI) 1738 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1577 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; 1739 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1578 1740
1579 if (tbl->action == start_action) 1741 if (tbl->action == start_action)
@@ -1584,13 +1746,150 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1584 out: 1746 out:
1585 lq_sta->search_better_tbl = 1; 1747 lq_sta->search_better_tbl = 1;
1586 tbl->action++; 1748 tbl->action++;
1587 if (tbl->action > IWL_MIMO2_SWITCH_GI) 1749 if (tbl->action > IWL_MIMO2_SWITCH_MIMO3_ABC)
1588 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1; 1750 tbl->action = IWL_MIMO2_SWITCH_ANTENNA1;
1589 return 0; 1751 return 0;
1590 1752
1591} 1753}
1592 1754
1593/* 1755/*
1756 * Try to switch to new modulation mode from MIMO3
1757 */
1758static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1759 struct iwl_lq_sta *lq_sta,
1760 struct ieee80211_conf *conf,
1761 struct ieee80211_sta *sta, int index)
1762{
1763 s8 is_green = lq_sta->is_green;
1764 struct iwl_scale_tbl_info *tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
1765 struct iwl_scale_tbl_info *search_tbl =
1766 &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]);
1767 struct iwl_rate_scale_data *window = &(tbl->win[index]);
1768 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1769 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1770 u8 start_action = tbl->action;
1771 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1772 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1773 int ret;
1774
1775 for (;;) {
1776 lq_sta->action_counter++;
1777 switch (tbl->action) {
1778 case IWL_MIMO3_SWITCH_ANTENNA1:
1779 case IWL_MIMO3_SWITCH_ANTENNA2:
1780 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle Antennas\n");
1781
1782 if (tx_chains_num <= 3)
1783 break;
1784
1785 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1786 break;
1787
1788 memcpy(search_tbl, tbl, sz);
1789 if (rs_toggle_antenna(valid_tx_ant,
1790 &search_tbl->current_rate, search_tbl))
1791 goto out;
1792 break;
1793 case IWL_MIMO3_SWITCH_SISO_A:
1794 case IWL_MIMO3_SWITCH_SISO_B:
1795 case IWL_MIMO3_SWITCH_SISO_C:
1796 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to SISO\n");
1797
1798 /* Set up new search table for SISO */
1799 memcpy(search_tbl, tbl, sz);
1800
1801 if (tbl->action == IWL_MIMO3_SWITCH_SISO_A)
1802 search_tbl->ant_type = ANT_A;
1803 else if (tbl->action == IWL_MIMO3_SWITCH_SISO_B)
1804 search_tbl->ant_type = ANT_B;
1805 else
1806 search_tbl->ant_type = ANT_C;
1807
1808 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1809 break;
1810
1811 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1812 search_tbl, index);
1813 if (!ret)
1814 goto out;
1815
1816 break;
1817
1818 case IWL_MIMO3_SWITCH_MIMO2_AB:
1819 case IWL_MIMO3_SWITCH_MIMO2_AC:
1820 case IWL_MIMO3_SWITCH_MIMO2_BC:
1821 IWL_DEBUG_RATE(priv, "LQ: MIMO3 switch to MIMO2\n");
1822
1823 memcpy(search_tbl, tbl, sz);
1824 search_tbl->is_SGI = 0;
1825 if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AB)
1826 search_tbl->ant_type = ANT_AB;
1827 else if (tbl->action == IWL_MIMO3_SWITCH_MIMO2_AC)
1828 search_tbl->ant_type = ANT_AC;
1829 else
1830 search_tbl->ant_type = ANT_BC;
1831
1832 if (!rs_is_valid_ant(valid_tx_ant, search_tbl->ant_type))
1833 break;
1834
1835 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1836 search_tbl, index);
1837 if (!ret)
1838 goto out;
1839
1840 break;
1841
1842 case IWL_MIMO3_SWITCH_GI:
1843 if (!tbl->is_fat &&
1844 !(priv->current_ht_config.sgf &
1845 HT_SHORT_GI_20MHZ))
1846 break;
1847 if (tbl->is_fat &&
1848 !(priv->current_ht_config.sgf &
1849 HT_SHORT_GI_40MHZ))
1850 break;
1851
1852 IWL_DEBUG_RATE(priv, "LQ: MIMO3 toggle SGI/NGI\n");
1853
1854 /* Set up new search table for MIMO */
1855 memcpy(search_tbl, tbl, sz);
1856 search_tbl->is_SGI = !tbl->is_SGI;
1857 rs_set_expected_tpt_table(lq_sta, search_tbl);
1858 /*
1859 * If active table already uses the fastest possible
1860 * modulation (dual stream with short guard interval),
1861 * and it's working well, there's no need to look
1862 * for a better type of modulation!
1863 */
1864 if (tbl->is_SGI) {
1865 s32 tpt = lq_sta->last_tpt / 100;
1866 if (tpt >= search_tbl->expected_tpt[index])
1867 break;
1868 }
1869 search_tbl->current_rate =
1870 rate_n_flags_from_tbl(priv, search_tbl,
1871 index, is_green);
1872 goto out;
1873 }
1874 tbl->action++;
1875 if (tbl->action > IWL_MIMO3_SWITCH_GI)
1876 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
1877
1878 if (tbl->action == start_action)
1879 break;
1880 }
1881 search_tbl->lq_type = LQ_NONE;
1882 return 0;
1883 out:
1884 lq_sta->search_better_tbl = 1;
1885 tbl->action++;
1886 if (tbl->action > IWL_MIMO3_SWITCH_GI)
1887 tbl->action = IWL_MIMO3_SWITCH_ANTENNA1;
1888 return 0;
1889
1890}
1891
1892/*
1594 * Check whether we should continue using same modulation mode, or 1893 * Check whether we should continue using same modulation mode, or
1595 * begin search for a new mode, based on: 1894 * begin search for a new mode, based on:
1596 * 1) # tx successes or failures while using this mode 1895 * 1) # tx successes or failures while using this mode
@@ -1616,8 +1915,8 @@ static void rs_stay_in_table(struct iwl_lq_sta *lq_sta)
1616 /* Elapsed time using current modulation mode */ 1915 /* Elapsed time using current modulation mode */
1617 if (lq_sta->flush_timer) 1916 if (lq_sta->flush_timer)
1618 flush_interval_passed = 1917 flush_interval_passed =
1619 time_after(jiffies, 1918 time_after(jiffies,
1620 (unsigned long)(lq_sta->flush_timer + 1919 (unsigned long)(lq_sta->flush_timer +
1621 IWL_RATE_SCALE_FLUSH_INTVL)); 1920 IWL_RATE_SCALE_FLUSH_INTVL));
1622 1921
1623 /* 1922 /*
@@ -1951,6 +2250,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1951 update_lq = 1; 2250 update_lq = 1;
1952 index = low; 2251 index = low;
1953 } 2252 }
2253
1954 break; 2254 break;
1955 case 1: 2255 case 1:
1956 /* Increase starting rate, update uCode's rate table */ 2256 /* Increase starting rate, update uCode's rate table */
@@ -1997,8 +2297,10 @@ lq_update:
1997 rs_move_legacy_other(priv, lq_sta, conf, sta, index); 2297 rs_move_legacy_other(priv, lq_sta, conf, sta, index);
1998 else if (is_siso(tbl->lq_type)) 2298 else if (is_siso(tbl->lq_type))
1999 rs_move_siso_to_other(priv, lq_sta, conf, sta, index); 2299 rs_move_siso_to_other(priv, lq_sta, conf, sta, index);
2300 else if (is_mimo2(tbl->lq_type))
2301 rs_move_mimo2_to_other(priv, lq_sta, conf, sta, index);
2000 else 2302 else
2001 rs_move_mimo_to_other(priv, lq_sta, conf, sta, index); 2303 rs_move_mimo3_to_other(priv, lq_sta, conf, sta, index);
2002 2304
2003 /* If new "search" mode was selected, set up in uCode table */ 2305 /* If new "search" mode was selected, set up in uCode table */
2004 if (lq_sta->search_better_tbl) { 2306 if (lq_sta->search_better_tbl) {
@@ -2014,8 +2316,11 @@ lq_update:
2014 tbl->current_rate, index); 2316 tbl->current_rate, index);
2015 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); 2317 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
2016 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 2318 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2017 } 2319 } else
2320 done_search = 1;
2321 }
2018 2322
2323 if (done_search && !lq_sta->stay_in_tbl) {
2019 /* If the "active" (non-search) mode was legacy, 2324 /* If the "active" (non-search) mode was legacy,
2020 * and we've tried switching antennas, 2325 * and we've tried switching antennas,
2021 * but we haven't been able to try HT modes (not available), 2326 * but we haven't been able to try HT modes (not available),
@@ -2050,17 +2355,6 @@ lq_update:
2050 lq_sta->action_counter = 0; 2355 lq_sta->action_counter = 0;
2051 rs_set_stay_in_table(priv, 0, lq_sta); 2356 rs_set_stay_in_table(priv, 0, lq_sta);
2052 } 2357 }
2053
2054 /*
2055 * Else, don't search for a new modulation mode.
2056 * Put new timestamp in stay-in-modulation-mode flush timer if:
2057 * 1) Not changing rates right now
2058 * 2) Not just finishing up a search
2059 * 3) flush timer is empty
2060 */
2061 } else {
2062 if ((!update_lq) && (!done_search) && (!lq_sta->flush_timer))
2063 lq_sta->flush_timer = jiffies;
2064 } 2358 }
2065 2359
2066out: 2360out:
@@ -2173,13 +2467,15 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2173 2467
2174 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && 2468 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
2175 !lq_sta->ibss_sta_added) { 2469 !lq_sta->ibss_sta_added) {
2176 u8 sta_id = iwl_find_station(priv, hdr->addr1); 2470 u8 sta_id = priv->cfg->ops->smgmt->find_station(priv,
2471 hdr->addr1);
2177 2472
2178 if (sta_id == IWL_INVALID_STATION) { 2473 if (sta_id == IWL_INVALID_STATION) {
2179 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", 2474 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n",
2180 hdr->addr1); 2475 hdr->addr1);
2181 sta_id = iwl_add_station_flags(priv, hdr->addr1, 2476 sta_id = priv->cfg->ops->smgmt->add_station(priv,
2182 0, CMD_ASYNC, NULL); 2477 hdr->addr1, 0,
2478 CMD_ASYNC, NULL);
2183 } 2479 }
2184 if ((sta_id != IWL_INVALID_STATION)) { 2480 if ((sta_id != IWL_INVALID_STATION)) {
2185 lq_sta->lq.sta_id = sta_id; 2481 lq_sta->lq.sta_id = sta_id;
@@ -2246,15 +2542,17 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
2246 2542
2247 lq_sta->ibss_sta_added = 0; 2543 lq_sta->ibss_sta_added = 0;
2248 if (priv->iw_mode == NL80211_IFTYPE_AP) { 2544 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2249 u8 sta_id = iwl_find_station(priv, sta->addr); 2545 u8 sta_id = priv->cfg->ops->smgmt->find_station(priv,
2546 sta->addr);
2250 2547
2251 /* for IBSS the call are from tasklet */ 2548 /* for IBSS the call are from tasklet */
2252 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); 2549 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr);
2253 2550
2254 if (sta_id == IWL_INVALID_STATION) { 2551 if (sta_id == IWL_INVALID_STATION) {
2255 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr); 2552 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr);
2256 sta_id = iwl_add_station_flags(priv, sta->addr, 2553 sta_id = priv->cfg->ops->smgmt->add_station(priv,
2257 0, CMD_ASYNC, NULL); 2554 sta->addr, 0,
2555 CMD_ASYNC, NULL);
2258 } 2556 }
2259 if ((sta_id != IWL_INVALID_STATION)) { 2557 if ((sta_id != IWL_INVALID_STATION)) {
2260 lq_sta->lq.sta_id = sta_id; 2558 lq_sta->lq.sta_id = sta_id;
@@ -2539,6 +2837,7 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2539 char *buff; 2837 char *buff;
2540 int desc = 0; 2838 int desc = 0;
2541 int i = 0; 2839 int i = 0;
2840 int index = 0;
2542 ssize_t ret; 2841 ssize_t ret;
2543 2842
2544 struct iwl_lq_sta *lq_sta = file->private_data; 2843 struct iwl_lq_sta *lq_sta = file->private_data;
@@ -2570,6 +2869,8 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2570 (tbl->is_fat) ? "40MHz" : "20MHz"); 2869 (tbl->is_fat) ? "40MHz" : "20MHz");
2571 desc += sprintf(buff+desc, " %s\n", (tbl->is_SGI) ? "SGI" : ""); 2870 desc += sprintf(buff+desc, " %s\n", (tbl->is_SGI) ? "SGI" : "");
2572 } 2871 }
2872 desc += sprintf(buff+desc, "last tx rate=0x%X\n",
2873 lq_sta->last_rate_n_flags);
2573 desc += sprintf(buff+desc, "general:" 2874 desc += sprintf(buff+desc, "general:"
2574 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", 2875 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2575 lq_sta->lq.general_params.flags, 2876 lq_sta->lq.general_params.flags,
@@ -2590,10 +2891,19 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2590 lq_sta->lq.general_params.start_rate_index[2], 2891 lq_sta->lq.general_params.start_rate_index[2],
2591 lq_sta->lq.general_params.start_rate_index[3]); 2892 lq_sta->lq.general_params.start_rate_index[3]);
2592 2893
2593 2894 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
2594 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) 2895 index = iwl_hwrate_to_plcp_idx(
2595 desc += sprintf(buff+desc, " rate[%d] 0x%X\n", 2896 le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags));
2596 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags)); 2897 if (is_legacy(tbl->lq_type)) {
2898 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps\n",
2899 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
2900 iwl_rate_mcs[index].mbps);
2901 } else {
2902 desc += sprintf(buff+desc, " rate[%d] 0x%X %smbps (%s)\n",
2903 i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags),
2904 iwl_rate_mcs[index].mbps, iwl_rate_mcs[index].mcs);
2905 }
2906 }
2597 2907
2598 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc); 2908 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
2599 kfree(buff); 2909 kfree(buff);
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
index ab59acc405d..f875136bc5d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
@@ -241,6 +241,7 @@ enum {
241#define IWL_LEGACY_SWITCH_MIMO2_AB 3 241#define IWL_LEGACY_SWITCH_MIMO2_AB 3
242#define IWL_LEGACY_SWITCH_MIMO2_AC 4 242#define IWL_LEGACY_SWITCH_MIMO2_AC 4
243#define IWL_LEGACY_SWITCH_MIMO2_BC 5 243#define IWL_LEGACY_SWITCH_MIMO2_BC 5
244#define IWL_LEGACY_SWITCH_MIMO3_ABC 6
244 245
245/* possible actions when in siso mode */ 246/* possible actions when in siso mode */
246#define IWL_SISO_SWITCH_ANTENNA1 0 247#define IWL_SISO_SWITCH_ANTENNA1 0
@@ -249,6 +250,8 @@ enum {
249#define IWL_SISO_SWITCH_MIMO2_AC 3 250#define IWL_SISO_SWITCH_MIMO2_AC 3
250#define IWL_SISO_SWITCH_MIMO2_BC 4 251#define IWL_SISO_SWITCH_MIMO2_BC 4
251#define IWL_SISO_SWITCH_GI 5 252#define IWL_SISO_SWITCH_GI 5
253#define IWL_SISO_SWITCH_MIMO3_ABC 6
254
252 255
253/* possible actions when in mimo mode */ 256/* possible actions when in mimo mode */
254#define IWL_MIMO2_SWITCH_ANTENNA1 0 257#define IWL_MIMO2_SWITCH_ANTENNA1 0
@@ -257,6 +260,21 @@ enum {
257#define IWL_MIMO2_SWITCH_SISO_B 3 260#define IWL_MIMO2_SWITCH_SISO_B 3
258#define IWL_MIMO2_SWITCH_SISO_C 4 261#define IWL_MIMO2_SWITCH_SISO_C 4
259#define IWL_MIMO2_SWITCH_GI 5 262#define IWL_MIMO2_SWITCH_GI 5
263#define IWL_MIMO2_SWITCH_MIMO3_ABC 6
264
265
266/* possible actions when in mimo3 mode */
267#define IWL_MIMO3_SWITCH_ANTENNA1 0
268#define IWL_MIMO3_SWITCH_ANTENNA2 1
269#define IWL_MIMO3_SWITCH_SISO_A 2
270#define IWL_MIMO3_SWITCH_SISO_B 3
271#define IWL_MIMO3_SWITCH_SISO_C 4
272#define IWL_MIMO3_SWITCH_MIMO2_AB 5
273#define IWL_MIMO3_SWITCH_MIMO2_AC 6
274#define IWL_MIMO3_SWITCH_MIMO2_BC 7
275#define IWL_MIMO3_SWITCH_GI 8
276
277
260 278
261/*FIXME:RS:add possible actions for MIMO3*/ 279/*FIXME:RS:add possible actions for MIMO3*/
262 280
@@ -307,6 +325,13 @@ enum iwl_table_type {
307#define ANT_BC (ANT_B | ANT_C) 325#define ANT_BC (ANT_B | ANT_C)
308#define ANT_ABC (ANT_AB | ANT_C) 326#define ANT_ABC (ANT_AB | ANT_C)
309 327
328#define IWL_MAX_MCS_DISPLAY_SIZE 12
329
330struct iwl_rate_mcs_info {
331 char mbps[IWL_MAX_MCS_DISPLAY_SIZE];
332 char mcs[IWL_MAX_MCS_DISPLAY_SIZE];
333};
334
310static inline u8 num_of_ant(u8 mask) 335static inline u8 num_of_ant(u8 mask)
311{ 336{
312 return !!((mask) & ANT_A) + 337 return !!((mask) & ANT_A) +
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 1ef4192207a..277dfc57fde 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -102,7 +102,7 @@ MODULE_ALIAS("iwl4965");
102 * function correctly transitions out of the RXON_ASSOC_MSK state if 102 * function correctly transitions out of the RXON_ASSOC_MSK state if
103 * a HW tune is required based on the RXON structure changes. 103 * a HW tune is required based on the RXON structure changes.
104 */ 104 */
105static int iwl_commit_rxon(struct iwl_priv *priv) 105int iwl_commit_rxon(struct iwl_priv *priv)
106{ 106{
107 /* cast away the const for active_rxon in this function */ 107 /* cast away the const for active_rxon in this function */
108 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; 108 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
@@ -188,7 +188,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
188 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 188 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
189 } 189 }
190 190
191 iwl_clear_stations_table(priv); 191 priv->cfg->ops->smgmt->clear_station_table(priv);
192 192
193 if (!priv->error_recovering) 193 if (!priv->error_recovering)
194 priv->start_calib = 0; 194 priv->start_calib = 0;
@@ -246,8 +246,9 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
246void iwl_update_chain_flags(struct iwl_priv *priv) 246void iwl_update_chain_flags(struct iwl_priv *priv)
247{ 247{
248 248
249 iwl_set_rxon_chain(priv); 249 if (priv->cfg->ops->hcmd->set_rxon_chain)
250 iwl_commit_rxon(priv); 250 priv->cfg->ops->hcmd->set_rxon_chain(priv);
251 iwlcore_commit_rxon(priv);
251} 252}
252 253
253static void iwl_clear_free_frames(struct iwl_priv *priv) 254static void iwl_clear_free_frames(struct iwl_priv *priv)
@@ -531,76 +532,6 @@ int iwl_hw_tx_queue_init(struct iwl_priv *priv,
531 * 532 *
532 ******************************************************************************/ 533 ******************************************************************************/
533 534
534static void iwl_ht_conf(struct iwl_priv *priv,
535 struct ieee80211_bss_conf *bss_conf)
536{
537 struct ieee80211_sta_ht_cap *ht_conf;
538 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
539 struct ieee80211_sta *sta;
540
541 IWL_DEBUG_MAC80211(priv, "enter: \n");
542
543 if (!iwl_conf->is_ht)
544 return;
545
546
547 /*
548 * It is totally wrong to base global information on something
549 * that is valid only when associated, alas, this driver works
550 * that way and I don't know how to fix it.
551 */
552
553 rcu_read_lock();
554 sta = ieee80211_find_sta(priv->hw, priv->bssid);
555 if (!sta) {
556 rcu_read_unlock();
557 return;
558 }
559 ht_conf = &sta->ht_cap;
560
561 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
562 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
563 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
564 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
565
566 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
567 iwl_conf->max_amsdu_size =
568 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
569
570 iwl_conf->supported_chan_width =
571 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
572
573 /*
574 * XXX: The HT configuration needs to be moved into iwl_mac_config()
575 * to be done there correctly.
576 */
577
578 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
579 if (conf_is_ht40_minus(&priv->hw->conf))
580 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
581 else if (conf_is_ht40_plus(&priv->hw->conf))
582 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
583
584 /* If no above or below channel supplied disable FAT channel */
585 if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
586 iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
587 iwl_conf->supported_chan_width = 0;
588
589 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
590
591 memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
592
593 iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
594 iwl_conf->ht_protection =
595 bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
596 iwl_conf->non_GF_STA_present =
597 !!(bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
598
599 rcu_read_unlock();
600
601 IWL_DEBUG_MAC80211(priv, "leave\n");
602}
603
604#define MAX_UCODE_BEACON_INTERVAL 4096 535#define MAX_UCODE_BEACON_INTERVAL 4096
605 536
606static u16 iwl_adjust_beacon_interval(u16 beacon_val) 537static u16 iwl_adjust_beacon_interval(u16 beacon_val)
@@ -657,30 +588,6 @@ static void iwl_setup_rxon_timing(struct iwl_priv *priv)
657 le16_to_cpu(priv->rxon_timing.atim_window)); 588 le16_to_cpu(priv->rxon_timing.atim_window));
658} 589}
659 590
660static int iwl_set_mode(struct iwl_priv *priv, int mode)
661{
662 iwl_connection_init_rx_config(priv, mode);
663 iwl_set_rxon_chain(priv);
664 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
665
666 iwl_clear_stations_table(priv);
667
668 /* dont commit rxon if rf-kill is on*/
669 if (!iwl_is_ready_rf(priv))
670 return -EAGAIN;
671
672 cancel_delayed_work(&priv->scan_check);
673 if (iwl_scan_cancel_timeout(priv, 100)) {
674 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
675 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
676 return -EAGAIN;
677 }
678
679 iwl_commit_rxon(priv);
680
681 return 0;
682}
683
684/****************************************************************************** 591/******************************************************************************
685 * 592 *
686 * Generic RX handler implementations 593 * Generic RX handler implementations
@@ -1002,6 +909,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
1002 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, 909 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
1003 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); 910 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1004 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); 911 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
912 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
1005 } else { 913 } else {
1006 /* No handling needed */ 914 /* No handling needed */
1007 IWL_DEBUG_RX(priv, 915 IWL_DEBUG_RX(priv,
@@ -1065,7 +973,7 @@ static void iwl_error_recovery(struct iwl_priv *priv)
1065 memcpy(&priv->staging_rxon, &priv->recovery_rxon, 973 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1066 sizeof(priv->staging_rxon)); 974 sizeof(priv->staging_rxon));
1067 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 975 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1068 iwl_commit_rxon(priv); 976 iwlcore_commit_rxon(priv);
1069 977
1070 iwl_rxon_add_station(priv, priv->bssid, 1); 978 iwl_rxon_add_station(priv, priv->bssid, 1);
1071 979
@@ -1123,6 +1031,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1123 /* Tell the device to stop sending interrupts */ 1031 /* Tell the device to stop sending interrupts */
1124 iwl_disable_interrupts(priv); 1032 iwl_disable_interrupts(priv);
1125 1033
1034 priv->isr_stats.hw++;
1126 iwl_irq_handle_error(priv); 1035 iwl_irq_handle_error(priv);
1127 1036
1128 handled |= CSR_INT_BIT_HW_ERR; 1037 handled |= CSR_INT_BIT_HW_ERR;
@@ -1135,13 +1044,17 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1135#ifdef CONFIG_IWLWIFI_DEBUG 1044#ifdef CONFIG_IWLWIFI_DEBUG
1136 if (priv->debug_level & (IWL_DL_ISR)) { 1045 if (priv->debug_level & (IWL_DL_ISR)) {
1137 /* NIC fires this, but we don't use it, redundant with WAKEUP */ 1046 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1138 if (inta & CSR_INT_BIT_SCD) 1047 if (inta & CSR_INT_BIT_SCD) {
1139 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit " 1048 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1140 "the frame/frames.\n"); 1049 "the frame/frames.\n");
1050 priv->isr_stats.sch++;
1051 }
1141 1052
1142 /* Alive notification via Rx interrupt will do the real work */ 1053 /* Alive notification via Rx interrupt will do the real work */
1143 if (inta & CSR_INT_BIT_ALIVE) 1054 if (inta & CSR_INT_BIT_ALIVE) {
1144 IWL_DEBUG_ISR(priv, "Alive interrupt\n"); 1055 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1056 priv->isr_stats.alive++;
1057 }
1145 } 1058 }
1146#endif 1059#endif
1147 /* Safely ignore these bits for debug checks below */ 1060 /* Safely ignore these bits for debug checks below */
@@ -1157,6 +1070,8 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1157 IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n", 1070 IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n",
1158 hw_rf_kill ? "disable radio" : "enable radio"); 1071 hw_rf_kill ? "disable radio" : "enable radio");
1159 1072
1073 priv->isr_stats.rfkill++;
1074
1160 /* driver only loads ucode once setting the interface up. 1075 /* driver only loads ucode once setting the interface up.
1161 * the driver allows loading the ucode even if the radio 1076 * the driver allows loading the ucode even if the radio
1162 * is killed. Hence update the killswitch state here. The 1077 * is killed. Hence update the killswitch state here. The
@@ -1176,6 +1091,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1176 /* Chip got too hot and stopped itself */ 1091 /* Chip got too hot and stopped itself */
1177 if (inta & CSR_INT_BIT_CT_KILL) { 1092 if (inta & CSR_INT_BIT_CT_KILL) {
1178 IWL_ERR(priv, "Microcode CT kill error detected.\n"); 1093 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1094 priv->isr_stats.ctkill++;
1179 handled |= CSR_INT_BIT_CT_KILL; 1095 handled |= CSR_INT_BIT_CT_KILL;
1180 } 1096 }
1181 1097
@@ -1183,6 +1099,8 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1183 if (inta & CSR_INT_BIT_SW_ERR) { 1099 if (inta & CSR_INT_BIT_SW_ERR) {
1184 IWL_ERR(priv, "Microcode SW error detected. " 1100 IWL_ERR(priv, "Microcode SW error detected. "
1185 " Restarting 0x%X.\n", inta); 1101 " Restarting 0x%X.\n", inta);
1102 priv->isr_stats.sw++;
1103 priv->isr_stats.sw_err = inta;
1186 iwl_irq_handle_error(priv); 1104 iwl_irq_handle_error(priv);
1187 handled |= CSR_INT_BIT_SW_ERR; 1105 handled |= CSR_INT_BIT_SW_ERR;
1188 } 1106 }
@@ -1198,6 +1116,8 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1198 iwl_txq_update_write_ptr(priv, &priv->txq[4]); 1116 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1199 iwl_txq_update_write_ptr(priv, &priv->txq[5]); 1117 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1200 1118
1119 priv->isr_stats.wakeup++;
1120
1201 handled |= CSR_INT_BIT_WAKEUP; 1121 handled |= CSR_INT_BIT_WAKEUP;
1202 } 1122 }
1203 1123
@@ -1206,19 +1126,23 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1206 * notifications from uCode come through here*/ 1126 * notifications from uCode come through here*/
1207 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { 1127 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1208 iwl_rx_handle(priv); 1128 iwl_rx_handle(priv);
1129 priv->isr_stats.rx++;
1209 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); 1130 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1210 } 1131 }
1211 1132
1212 if (inta & CSR_INT_BIT_FH_TX) { 1133 if (inta & CSR_INT_BIT_FH_TX) {
1213 IWL_DEBUG_ISR(priv, "Tx interrupt\n"); 1134 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
1135 priv->isr_stats.tx++;
1214 handled |= CSR_INT_BIT_FH_TX; 1136 handled |= CSR_INT_BIT_FH_TX;
1215 /* FH finished to write, send event */ 1137 /* FH finished to write, send event */
1216 priv->ucode_write_complete = 1; 1138 priv->ucode_write_complete = 1;
1217 wake_up_interruptible(&priv->wait_command_queue); 1139 wake_up_interruptible(&priv->wait_command_queue);
1218 } 1140 }
1219 1141
1220 if (inta & ~handled) 1142 if (inta & ~handled) {
1221 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); 1143 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1144 priv->isr_stats.unhandled++;
1145 }
1222 1146
1223 if (inta & ~CSR_INI_SET_MASK) { 1147 if (inta & ~CSR_INI_SET_MASK) {
1224 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", 1148 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
@@ -1243,6 +1167,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1243 spin_unlock_irqrestore(&priv->lock, flags); 1167 spin_unlock_irqrestore(&priv->lock, flags);
1244} 1168}
1245 1169
1170
1246/****************************************************************************** 1171/******************************************************************************
1247 * 1172 *
1248 * uCode download functions 1173 * uCode download functions
@@ -1508,10 +1433,6 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1508 return ret; 1433 return ret;
1509} 1434}
1510 1435
1511/* temporary */
1512static int iwl_mac_beacon_update(struct ieee80211_hw *hw,
1513 struct sk_buff *skb);
1514
1515/** 1436/**
1516 * iwl_alive_start - called after REPLY_ALIVE notification received 1437 * iwl_alive_start - called after REPLY_ALIVE notification received
1517 * from protocol/runtime uCode (initialization uCode's 1438 * from protocol/runtime uCode (initialization uCode's
@@ -1540,7 +1461,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
1540 goto restart; 1461 goto restart;
1541 } 1462 }
1542 1463
1543 iwl_clear_stations_table(priv); 1464 priv->cfg->ops->smgmt->clear_station_table(priv);
1544 ret = priv->cfg->ops->lib->alive_notify(priv); 1465 ret = priv->cfg->ops->lib->alive_notify(priv);
1545 if (ret) { 1466 if (ret) {
1546 IWL_WARN(priv, 1467 IWL_WARN(priv,
@@ -1568,7 +1489,10 @@ static void iwl_alive_start(struct iwl_priv *priv)
1568 } else { 1489 } else {
1569 /* Initialize our rx_config data */ 1490 /* Initialize our rx_config data */
1570 iwl_connection_init_rx_config(priv, priv->iw_mode); 1491 iwl_connection_init_rx_config(priv, priv->iw_mode);
1571 iwl_set_rxon_chain(priv); 1492
1493 if (priv->cfg->ops->hcmd->set_rxon_chain)
1494 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1495
1572 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 1496 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1573 } 1497 }
1574 1498
@@ -1578,7 +1502,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
1578 iwl_reset_run_time_calib(priv); 1502 iwl_reset_run_time_calib(priv);
1579 1503
1580 /* Configure the adapter for unassociated operation */ 1504 /* Configure the adapter for unassociated operation */
1581 iwl_commit_rxon(priv); 1505 iwlcore_commit_rxon(priv);
1582 1506
1583 /* At this point, the NIC is initialized and operational */ 1507 /* At this point, the NIC is initialized and operational */
1584 iwl_rf_kill_ct_config(priv); 1508 iwl_rf_kill_ct_config(priv);
@@ -1626,7 +1550,7 @@ static void __iwl_down(struct iwl_priv *priv)
1626 1550
1627 iwl_leds_unregister(priv); 1551 iwl_leds_unregister(priv);
1628 1552
1629 iwl_clear_stations_table(priv); 1553 priv->cfg->ops->smgmt->clear_station_table(priv);
1630 1554
1631 /* Unblock any waiting calls */ 1555 /* Unblock any waiting calls */
1632 wake_up_interruptible_all(&priv->wait_command_queue); 1556 wake_up_interruptible_all(&priv->wait_command_queue);
@@ -1649,7 +1573,7 @@ static void __iwl_down(struct iwl_priv *priv)
1649 ieee80211_stop_queues(priv->hw); 1573 ieee80211_stop_queues(priv->hw);
1650 1574
1651 /* If we have not previously called iwl_init() then 1575 /* If we have not previously called iwl_init() then
1652 * clear all bits but the RF Kill and SUSPEND bits and return */ 1576 * clear all bits but the RF Kill bits and return */
1653 if (!iwl_is_init(priv)) { 1577 if (!iwl_is_init(priv)) {
1654 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << 1578 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1655 STATUS_RF_KILL_HW | 1579 STATUS_RF_KILL_HW |
@@ -1657,23 +1581,19 @@ static void __iwl_down(struct iwl_priv *priv)
1657 STATUS_RF_KILL_SW | 1581 STATUS_RF_KILL_SW |
1658 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 1582 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1659 STATUS_GEO_CONFIGURED | 1583 STATUS_GEO_CONFIGURED |
1660 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
1661 STATUS_IN_SUSPEND |
1662 test_bit(STATUS_EXIT_PENDING, &priv->status) << 1584 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1663 STATUS_EXIT_PENDING; 1585 STATUS_EXIT_PENDING;
1664 goto exit; 1586 goto exit;
1665 } 1587 }
1666 1588
1667 /* ...otherwise clear out all the status bits but the RF Kill and 1589 /* ...otherwise clear out all the status bits but the RF Kill
1668 * SUSPEND bits and continue taking the NIC down. */ 1590 * bits and continue taking the NIC down. */
1669 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << 1591 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1670 STATUS_RF_KILL_HW | 1592 STATUS_RF_KILL_HW |
1671 test_bit(STATUS_RF_KILL_SW, &priv->status) << 1593 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
1672 STATUS_RF_KILL_SW | 1594 STATUS_RF_KILL_SW |
1673 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 1595 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1674 STATUS_GEO_CONFIGURED | 1596 STATUS_GEO_CONFIGURED |
1675 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
1676 STATUS_IN_SUSPEND |
1677 test_bit(STATUS_FW_ERROR, &priv->status) << 1597 test_bit(STATUS_FW_ERROR, &priv->status) <<
1678 STATUS_FW_ERROR | 1598 STATUS_FW_ERROR |
1679 test_bit(STATUS_EXIT_PENDING, &priv->status) << 1599 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
@@ -1698,7 +1618,7 @@ static void __iwl_down(struct iwl_priv *priv)
1698 udelay(5); 1618 udelay(5);
1699 1619
1700 /* FIXME: apm_ops.suspend(priv) */ 1620 /* FIXME: apm_ops.suspend(priv) */
1701 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status)) 1621 if (exit_pending)
1702 priv->cfg->ops->lib->apm_ops.stop(priv); 1622 priv->cfg->ops->lib->apm_ops.stop(priv);
1703 else 1623 else
1704 priv->cfg->ops->lib->apm_ops.reset(priv); 1624 priv->cfg->ops->lib->apm_ops.reset(priv);
@@ -1781,7 +1701,7 @@ static int __iwl_up(struct iwl_priv *priv)
1781 1701
1782 for (i = 0; i < MAX_HW_RESTARTS; i++) { 1702 for (i = 0; i < MAX_HW_RESTARTS; i++) {
1783 1703
1784 iwl_clear_stations_table(priv); 1704 priv->cfg->ops->smgmt->clear_station_table(priv);
1785 1705
1786 /* load bootstrap state machine, 1706 /* load bootstrap state machine,
1787 * load bootstrap program into processor's memory, 1707 * load bootstrap program into processor's memory,
@@ -1910,7 +1830,7 @@ static void iwl_bg_rx_replenish(struct work_struct *data)
1910 1830
1911#define IWL_DELAY_NEXT_SCAN (HZ*2) 1831#define IWL_DELAY_NEXT_SCAN (HZ*2)
1912 1832
1913static void iwl_post_associate(struct iwl_priv *priv) 1833void iwl_post_associate(struct iwl_priv *priv)
1914{ 1834{
1915 struct ieee80211_conf *conf = NULL; 1835 struct ieee80211_conf *conf = NULL;
1916 int ret = 0; 1836 int ret = 0;
@@ -1938,7 +1858,7 @@ static void iwl_post_associate(struct iwl_priv *priv)
1938 conf = ieee80211_get_hw_conf(priv->hw); 1858 conf = ieee80211_get_hw_conf(priv->hw);
1939 1859
1940 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 1860 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1941 iwl_commit_rxon(priv); 1861 iwlcore_commit_rxon(priv);
1942 1862
1943 iwl_setup_rxon_timing(priv); 1863 iwl_setup_rxon_timing(priv);
1944 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, 1864 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
@@ -1951,7 +1871,9 @@ static void iwl_post_associate(struct iwl_priv *priv)
1951 1871
1952 iwl_set_rxon_ht(priv, &priv->current_ht_config); 1872 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1953 1873
1954 iwl_set_rxon_chain(priv); 1874 if (priv->cfg->ops->hcmd->set_rxon_chain)
1875 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1876
1955 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); 1877 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
1956 1878
1957 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n", 1879 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
@@ -1973,7 +1895,7 @@ static void iwl_post_associate(struct iwl_priv *priv)
1973 1895
1974 } 1896 }
1975 1897
1976 iwl_commit_rxon(priv); 1898 iwlcore_commit_rxon(priv);
1977 1899
1978 switch (priv->iw_mode) { 1900 switch (priv->iw_mode) {
1979 case NL80211_IFTYPE_STATION: 1901 case NL80211_IFTYPE_STATION:
@@ -2059,9 +1981,6 @@ static int iwl_mac_start(struct ieee80211_hw *hw)
2059 1981
2060 IWL_DEBUG_INFO(priv, "Start UP work done.\n"); 1982 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
2061 1983
2062 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2063 return 0;
2064
2065 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from 1984 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
2066 * mac80211 will not be run successfully. */ 1985 * mac80211 will not be run successfully. */
2067 ret = wait_event_interruptible_timeout(priv->wait_command_queue, 1986 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
@@ -2130,175 +2049,7 @@ static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2130 return NETDEV_TX_OK; 2049 return NETDEV_TX_OK;
2131} 2050}
2132 2051
2133static int iwl_mac_add_interface(struct ieee80211_hw *hw, 2052void iwl_config_ap(struct iwl_priv *priv)
2134 struct ieee80211_if_init_conf *conf)
2135{
2136 struct iwl_priv *priv = hw->priv;
2137 unsigned long flags;
2138
2139 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
2140
2141 if (priv->vif) {
2142 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
2143 return -EOPNOTSUPP;
2144 }
2145
2146 spin_lock_irqsave(&priv->lock, flags);
2147 priv->vif = conf->vif;
2148 priv->iw_mode = conf->type;
2149
2150 spin_unlock_irqrestore(&priv->lock, flags);
2151
2152 mutex_lock(&priv->mutex);
2153
2154 if (conf->mac_addr) {
2155 IWL_DEBUG_MAC80211(priv, "Set %pM\n", conf->mac_addr);
2156 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2157 }
2158
2159 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
2160 /* we are not ready, will run again when ready */
2161 set_bit(STATUS_MODE_PENDING, &priv->status);
2162
2163 mutex_unlock(&priv->mutex);
2164
2165 IWL_DEBUG_MAC80211(priv, "leave\n");
2166 return 0;
2167}
2168
2169/**
2170 * iwl_mac_config - mac80211 config callback
2171 *
2172 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2173 * be set inappropriately and the driver currently sets the hardware up to
2174 * use it whenever needed.
2175 */
2176static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2177{
2178 struct iwl_priv *priv = hw->priv;
2179 const struct iwl_channel_info *ch_info;
2180 struct ieee80211_conf *conf = &hw->conf;
2181 unsigned long flags = 0;
2182 int ret = 0;
2183 u16 ch;
2184 int scan_active = 0;
2185
2186 mutex_lock(&priv->mutex);
2187 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
2188 conf->channel->hw_value, changed);
2189
2190 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2191 test_bit(STATUS_SCANNING, &priv->status))) {
2192 scan_active = 1;
2193 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
2194 }
2195
2196
2197 /* during scanning mac80211 will delay channel setting until
2198 * scan finish with changed = 0
2199 */
2200 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2201 if (scan_active)
2202 goto set_ch_out;
2203
2204 ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
2205 ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
2206 if (!is_channel_valid(ch_info)) {
2207 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
2208 ret = -EINVAL;
2209 goto set_ch_out;
2210 }
2211
2212 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2213 !is_channel_ibss(ch_info)) {
2214 IWL_ERR(priv, "channel %d in band %d not "
2215 "IBSS channel\n",
2216 conf->channel->hw_value, conf->channel->band);
2217 ret = -EINVAL;
2218 goto set_ch_out;
2219 }
2220
2221 priv->current_ht_config.is_ht = conf_is_ht(conf);
2222
2223 spin_lock_irqsave(&priv->lock, flags);
2224
2225
2226 /* if we are switching from ht to 2.4 clear flags
2227 * from any ht related info since 2.4 does not
2228 * support ht */
2229 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
2230 priv->staging_rxon.flags = 0;
2231
2232 iwl_set_rxon_channel(priv, conf->channel);
2233
2234 iwl_set_flags_for_band(priv, conf->channel->band);
2235 spin_unlock_irqrestore(&priv->lock, flags);
2236 set_ch_out:
2237 /* The list of supported rates and rate mask can be different
2238 * for each band; since the band may have changed, reset
2239 * the rate mask to what mac80211 lists */
2240 iwl_set_rate(priv);
2241 }
2242
2243 if (changed & IEEE80211_CONF_CHANGE_PS) {
2244 if (conf->flags & IEEE80211_CONF_PS)
2245 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2246 else
2247 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2248 if (ret)
2249 IWL_DEBUG_MAC80211(priv, "Error setting power level\n");
2250
2251 }
2252
2253 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2254 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
2255 priv->tx_power_user_lmt, conf->power_level);
2256
2257 iwl_set_tx_power(priv, conf->power_level, false);
2258 }
2259
2260 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2261 iwl_set_rxon_chain(priv);
2262
2263 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
2264 if (conf->radio_enabled &&
2265 iwl_radio_kill_sw_enable_radio(priv)) {
2266 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
2267 "waiting for uCode\n");
2268 goto out;
2269 }
2270
2271 if (!conf->radio_enabled)
2272 iwl_radio_kill_sw_disable_radio(priv);
2273 }
2274
2275 if (!conf->radio_enabled) {
2276 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
2277 goto out;
2278 }
2279
2280 if (!iwl_is_ready(priv)) {
2281 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2282 goto out;
2283 }
2284
2285 if (scan_active)
2286 goto out;
2287
2288 if (memcmp(&priv->active_rxon,
2289 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2290 iwl_commit_rxon(priv);
2291 else
2292 IWL_DEBUG_INFO(priv, "No re-sending same RXON configuration.\n");
2293
2294
2295out:
2296 IWL_DEBUG_MAC80211(priv, "leave\n");
2297 mutex_unlock(&priv->mutex);
2298 return ret;
2299}
2300
2301static void iwl_config_ap(struct iwl_priv *priv)
2302{ 2053{
2303 int ret = 0; 2054 int ret = 0;
2304 unsigned long flags; 2055 unsigned long flags;
@@ -2311,7 +2062,7 @@ static void iwl_config_ap(struct iwl_priv *priv)
2311 2062
2312 /* RXON - unassoc (to set timing command) */ 2063 /* RXON - unassoc (to set timing command) */
2313 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2064 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2314 iwl_commit_rxon(priv); 2065 iwlcore_commit_rxon(priv);
2315 2066
2316 /* RXON Timing */ 2067 /* RXON Timing */
2317 iwl_setup_rxon_timing(priv); 2068 iwl_setup_rxon_timing(priv);
@@ -2321,7 +2072,8 @@ static void iwl_config_ap(struct iwl_priv *priv)
2321 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 2072 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
2322 "Attempting to continue.\n"); 2073 "Attempting to continue.\n");
2323 2074
2324 iwl_set_rxon_chain(priv); 2075 if (priv->cfg->ops->hcmd->set_rxon_chain)
2076 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2325 2077
2326 /* FIXME: what should be the assoc_id for AP? */ 2078 /* FIXME: what should be the assoc_id for AP? */
2327 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); 2079 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
@@ -2347,7 +2099,7 @@ static void iwl_config_ap(struct iwl_priv *priv)
2347 } 2099 }
2348 /* restore RXON assoc */ 2100 /* restore RXON assoc */
2349 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 2101 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2350 iwl_commit_rxon(priv); 2102 iwlcore_commit_rxon(priv);
2351 spin_lock_irqsave(&priv->lock, flags); 2103 spin_lock_irqsave(&priv->lock, flags);
2352 iwl_activate_qos(priv, 1); 2104 iwl_activate_qos(priv, 1);
2353 spin_unlock_irqrestore(&priv->lock, flags); 2105 spin_unlock_irqrestore(&priv->lock, flags);
@@ -2360,194 +2112,6 @@ static void iwl_config_ap(struct iwl_priv *priv)
2360 * clear sta table, add BCAST sta... */ 2112 * clear sta table, add BCAST sta... */
2361} 2113}
2362 2114
2363
2364static int iwl_mac_config_interface(struct ieee80211_hw *hw,
2365 struct ieee80211_vif *vif,
2366 struct ieee80211_if_conf *conf)
2367{
2368 struct iwl_priv *priv = hw->priv;
2369 int rc;
2370
2371 if (conf == NULL)
2372 return -EIO;
2373
2374 if (priv->vif != vif) {
2375 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
2376 return 0;
2377 }
2378
2379 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2380 conf->changed & IEEE80211_IFCC_BEACON) {
2381 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2382 if (!beacon)
2383 return -ENOMEM;
2384 mutex_lock(&priv->mutex);
2385 rc = iwl_mac_beacon_update(hw, beacon);
2386 mutex_unlock(&priv->mutex);
2387 if (rc)
2388 return rc;
2389 }
2390
2391 if (!iwl_is_alive(priv))
2392 return -EAGAIN;
2393
2394 mutex_lock(&priv->mutex);
2395
2396 if (conf->bssid)
2397 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
2398
2399/*
2400 * very dubious code was here; the probe filtering flag is never set:
2401 *
2402 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2403 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
2404 */
2405
2406 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2407 if (!conf->bssid) {
2408 conf->bssid = priv->mac_addr;
2409 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
2410 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
2411 conf->bssid);
2412 }
2413 if (priv->ibss_beacon)
2414 dev_kfree_skb(priv->ibss_beacon);
2415
2416 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
2417 }
2418
2419 if (iwl_is_rfkill(priv))
2420 goto done;
2421
2422 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2423 !is_multicast_ether_addr(conf->bssid)) {
2424 /* If there is currently a HW scan going on in the background
2425 * then we need to cancel it else the RXON below will fail. */
2426 if (iwl_scan_cancel_timeout(priv, 100)) {
2427 IWL_WARN(priv, "Aborted scan still in progress "
2428 "after 100ms\n");
2429 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2430 mutex_unlock(&priv->mutex);
2431 return -EAGAIN;
2432 }
2433 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2434
2435 /* TODO: Audit driver for usage of these members and see
2436 * if mac80211 deprecates them (priv->bssid looks like it
2437 * shouldn't be there, but I haven't scanned the IBSS code
2438 * to verify) - jpk */
2439 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2440
2441 if (priv->iw_mode == NL80211_IFTYPE_AP)
2442 iwl_config_ap(priv);
2443 else {
2444 rc = iwl_commit_rxon(priv);
2445 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
2446 iwl_rxon_add_station(
2447 priv, priv->active_rxon.bssid_addr, 1);
2448 }
2449
2450 } else {
2451 iwl_scan_cancel_timeout(priv, 100);
2452 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2453 iwl_commit_rxon(priv);
2454 }
2455
2456 done:
2457 IWL_DEBUG_MAC80211(priv, "leave\n");
2458 mutex_unlock(&priv->mutex);
2459
2460 return 0;
2461}
2462
2463static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2464 struct ieee80211_if_init_conf *conf)
2465{
2466 struct iwl_priv *priv = hw->priv;
2467
2468 IWL_DEBUG_MAC80211(priv, "enter\n");
2469
2470 mutex_lock(&priv->mutex);
2471
2472 if (iwl_is_ready_rf(priv)) {
2473 iwl_scan_cancel_timeout(priv, 100);
2474 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2475 iwl_commit_rxon(priv);
2476 }
2477 if (priv->vif == conf->vif) {
2478 priv->vif = NULL;
2479 memset(priv->bssid, 0, ETH_ALEN);
2480 }
2481 mutex_unlock(&priv->mutex);
2482
2483 IWL_DEBUG_MAC80211(priv, "leave\n");
2484
2485}
2486
2487#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
2488static void iwl_bss_info_changed(struct ieee80211_hw *hw,
2489 struct ieee80211_vif *vif,
2490 struct ieee80211_bss_conf *bss_conf,
2491 u32 changes)
2492{
2493 struct iwl_priv *priv = hw->priv;
2494
2495 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
2496
2497 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
2498 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
2499 bss_conf->use_short_preamble);
2500 if (bss_conf->use_short_preamble)
2501 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2502 else
2503 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2504 }
2505
2506 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
2507 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
2508 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
2509 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
2510 else
2511 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2512 }
2513
2514 if (changes & BSS_CHANGED_HT) {
2515 iwl_ht_conf(priv, bss_conf);
2516 iwl_set_rxon_chain(priv);
2517 }
2518
2519 if (changes & BSS_CHANGED_ASSOC) {
2520 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
2521 /* This should never happen as this function should
2522 * never be called from interrupt context. */
2523 if (WARN_ON_ONCE(in_interrupt()))
2524 return;
2525 if (bss_conf->assoc) {
2526 priv->assoc_id = bss_conf->aid;
2527 priv->beacon_int = bss_conf->beacon_int;
2528 priv->power_data.dtim_period = bss_conf->dtim_period;
2529 priv->timestamp = bss_conf->timestamp;
2530 priv->assoc_capability = bss_conf->assoc_capability;
2531
2532 /* we have just associated, don't start scan too early
2533 * leave time for EAPOL exchange to complete
2534 */
2535 priv->next_scan_jiffies = jiffies +
2536 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
2537 mutex_lock(&priv->mutex);
2538 iwl_post_associate(priv);
2539 mutex_unlock(&priv->mutex);
2540 } else {
2541 priv->assoc_id = 0;
2542 IWL_DEBUG_MAC80211(priv, "DISASSOC %d\n", bss_conf->assoc);
2543 }
2544 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
2545 IWL_DEBUG_MAC80211(priv, "Associated Changes %d\n", changes);
2546 iwl_send_rxon_assoc(priv);
2547 }
2548
2549}
2550
2551static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw, 2115static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
2552 struct ieee80211_key_conf *keyconf, const u8 *addr, 2116 struct ieee80211_key_conf *keyconf, const u8 *addr,
2553 u32 iv32, u16 *phase1key) 2117 u32 iv32, u16 *phase1key)
@@ -2579,7 +2143,7 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2579 return -EOPNOTSUPP; 2143 return -EOPNOTSUPP;
2580 } 2144 }
2581 addr = sta ? sta->addr : iwl_bcast_addr; 2145 addr = sta ? sta->addr : iwl_bcast_addr;
2582 sta_id = iwl_find_station(priv, addr); 2146 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
2583 if (sta_id == IWL_INVALID_STATION) { 2147 if (sta_id == IWL_INVALID_STATION) {
2584 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", 2148 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
2585 addr); 2149 addr);
@@ -2630,49 +2194,6 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2630 return ret; 2194 return ret;
2631} 2195}
2632 2196
2633static int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
2634 const struct ieee80211_tx_queue_params *params)
2635{
2636 struct iwl_priv *priv = hw->priv;
2637 unsigned long flags;
2638 int q;
2639
2640 IWL_DEBUG_MAC80211(priv, "enter\n");
2641
2642 if (!iwl_is_ready_rf(priv)) {
2643 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2644 return -EIO;
2645 }
2646
2647 if (queue >= AC_NUM) {
2648 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
2649 return 0;
2650 }
2651
2652 q = AC_NUM - 1 - queue;
2653
2654 spin_lock_irqsave(&priv->lock, flags);
2655
2656 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
2657 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
2658 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
2659 priv->qos_data.def_qos_parm.ac[q].edca_txop =
2660 cpu_to_le16((params->txop * 32));
2661
2662 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
2663 priv->qos_data.qos_active = 1;
2664
2665 if (priv->iw_mode == NL80211_IFTYPE_AP)
2666 iwl_activate_qos(priv, 1);
2667 else if (priv->assoc_id && iwl_is_associated(priv))
2668 iwl_activate_qos(priv, 0);
2669
2670 spin_unlock_irqrestore(&priv->lock, flags);
2671
2672 IWL_DEBUG_MAC80211(priv, "leave\n");
2673 return 0;
2674}
2675
2676static int iwl_mac_ampdu_action(struct ieee80211_hw *hw, 2197static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
2677 enum ieee80211_ampdu_mlme_action action, 2198 enum ieee80211_ampdu_mlme_action action,
2678 struct ieee80211_sta *sta, u16 tid, u16 *ssn) 2199 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
@@ -2715,41 +2236,6 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
2715 return 0; 2236 return 0;
2716} 2237}
2717 2238
2718static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
2719 struct ieee80211_tx_queue_stats *stats)
2720{
2721 struct iwl_priv *priv = hw->priv;
2722 int i, avail;
2723 struct iwl_tx_queue *txq;
2724 struct iwl_queue *q;
2725 unsigned long flags;
2726
2727 IWL_DEBUG_MAC80211(priv, "enter\n");
2728
2729 if (!iwl_is_ready_rf(priv)) {
2730 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2731 return -EIO;
2732 }
2733
2734 spin_lock_irqsave(&priv->lock, flags);
2735
2736 for (i = 0; i < AC_NUM; i++) {
2737 txq = &priv->txq[i];
2738 q = &txq->q;
2739 avail = iwl_queue_space(q);
2740
2741 stats[i].len = q->n_window - avail;
2742 stats[i].limit = q->n_window - q->high_mark;
2743 stats[i].count = q->n_window;
2744
2745 }
2746 spin_unlock_irqrestore(&priv->lock, flags);
2747
2748 IWL_DEBUG_MAC80211(priv, "leave\n");
2749
2750 return 0;
2751}
2752
2753static int iwl_mac_get_stats(struct ieee80211_hw *hw, 2239static int iwl_mac_get_stats(struct ieee80211_hw *hw,
2754 struct ieee80211_low_level_stats *stats) 2240 struct ieee80211_low_level_stats *stats)
2755{ 2241{
@@ -2762,120 +2248,6 @@ static int iwl_mac_get_stats(struct ieee80211_hw *hw,
2762 return 0; 2248 return 0;
2763} 2249}
2764 2250
2765static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2766{
2767 struct iwl_priv *priv = hw->priv;
2768 unsigned long flags;
2769
2770 mutex_lock(&priv->mutex);
2771 IWL_DEBUG_MAC80211(priv, "enter\n");
2772
2773 spin_lock_irqsave(&priv->lock, flags);
2774 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
2775 spin_unlock_irqrestore(&priv->lock, flags);
2776
2777 iwl_reset_qos(priv);
2778
2779 spin_lock_irqsave(&priv->lock, flags);
2780 priv->assoc_id = 0;
2781 priv->assoc_capability = 0;
2782 priv->assoc_station_added = 0;
2783
2784 /* new association get rid of ibss beacon skb */
2785 if (priv->ibss_beacon)
2786 dev_kfree_skb(priv->ibss_beacon);
2787
2788 priv->ibss_beacon = NULL;
2789
2790 priv->beacon_int = priv->hw->conf.beacon_int;
2791 priv->timestamp = 0;
2792 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
2793 priv->beacon_int = 0;
2794
2795 spin_unlock_irqrestore(&priv->lock, flags);
2796
2797 if (!iwl_is_ready_rf(priv)) {
2798 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2799 mutex_unlock(&priv->mutex);
2800 return;
2801 }
2802
2803 /* we are restarting association process
2804 * clear RXON_FILTER_ASSOC_MSK bit
2805 */
2806 if (priv->iw_mode != NL80211_IFTYPE_AP) {
2807 iwl_scan_cancel_timeout(priv, 100);
2808 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2809 iwl_commit_rxon(priv);
2810 }
2811
2812 iwl_power_update_mode(priv, 0);
2813
2814 /* Per mac80211.h: This is only used in IBSS mode... */
2815 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2816
2817 /* switch to CAM during association period.
2818 * the ucode will block any association/authentication
2819 * frome during assiciation period if it can not hear
2820 * the AP because of PM. the timer enable PM back is
2821 * association do not complete
2822 */
2823 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
2824 IEEE80211_CHAN_RADAR))
2825 iwl_power_disable_management(priv, 3000);
2826
2827 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
2828 mutex_unlock(&priv->mutex);
2829 return;
2830 }
2831
2832 iwl_set_rate(priv);
2833
2834 mutex_unlock(&priv->mutex);
2835
2836 IWL_DEBUG_MAC80211(priv, "leave\n");
2837}
2838
2839static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
2840{
2841 struct iwl_priv *priv = hw->priv;
2842 unsigned long flags;
2843 __le64 timestamp;
2844
2845 IWL_DEBUG_MAC80211(priv, "enter\n");
2846
2847 if (!iwl_is_ready_rf(priv)) {
2848 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2849 return -EIO;
2850 }
2851
2852 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2853 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
2854 return -EIO;
2855 }
2856
2857 spin_lock_irqsave(&priv->lock, flags);
2858
2859 if (priv->ibss_beacon)
2860 dev_kfree_skb(priv->ibss_beacon);
2861
2862 priv->ibss_beacon = skb;
2863
2864 priv->assoc_id = 0;
2865 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
2866 priv->timestamp = le64_to_cpu(timestamp);
2867
2868 IWL_DEBUG_MAC80211(priv, "leave\n");
2869 spin_unlock_irqrestore(&priv->lock, flags);
2870
2871 iwl_reset_qos(priv);
2872
2873 iwl_post_associate(priv);
2874
2875
2876 return 0;
2877}
2878
2879/***************************************************************************** 2251/*****************************************************************************
2880 * 2252 *
2881 * sysfs attributes 2253 * sysfs attributes
@@ -3025,7 +2397,7 @@ static ssize_t store_flags(struct device *d,
3025 else { 2397 else {
3026 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags); 2398 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags);
3027 priv->staging_rxon.flags = cpu_to_le32(flags); 2399 priv->staging_rxon.flags = cpu_to_le32(flags);
3028 iwl_commit_rxon(priv); 2400 iwlcore_commit_rxon(priv);
3029 } 2401 }
3030 } 2402 }
3031 mutex_unlock(&priv->mutex); 2403 mutex_unlock(&priv->mutex);
@@ -3066,7 +2438,7 @@ static ssize_t store_filter_flags(struct device *d,
3066 "0x%04X\n", filter_flags); 2438 "0x%04X\n", filter_flags);
3067 priv->staging_rxon.filter_flags = 2439 priv->staging_rxon.filter_flags =
3068 cpu_to_le32(filter_flags); 2440 cpu_to_le32(filter_flags);
3069 iwl_commit_rxon(priv); 2441 iwlcore_commit_rxon(priv);
3070 } 2442 }
3071 } 2443 }
3072 mutex_unlock(&priv->mutex); 2444 mutex_unlock(&priv->mutex);
@@ -3397,18 +2769,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3397 goto out_free_eeprom; 2769 goto out_free_eeprom;
3398 /* At this point both hw and priv are initialized. */ 2770 /* At this point both hw and priv are initialized. */
3399 2771
3400 /**********************************
3401 * 7. Initialize module parameters
3402 **********************************/
3403
3404 /* Disable radio (SW RF KILL) via parameter when loading driver */
3405 if (priv->cfg->mod_params->disable) {
3406 set_bit(STATUS_RF_KILL_SW, &priv->status);
3407 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
3408 }
3409
3410 /******************** 2772 /********************
3411 * 8. Setup services 2773 * 7. Setup services
3412 ********************/ 2774 ********************/
3413 spin_lock_irqsave(&priv->lock, flags); 2775 spin_lock_irqsave(&priv->lock, flags);
3414 iwl_disable_interrupts(priv); 2776 iwl_disable_interrupts(priv);
@@ -3432,7 +2794,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3432 iwl_setup_rx_handlers(priv); 2794 iwl_setup_rx_handlers(priv);
3433 2795
3434 /********************************** 2796 /**********************************
3435 * 9. Setup and register mac80211 2797 * 8. Setup and register mac80211
3436 **********************************/ 2798 **********************************/
3437 2799
3438 /* enable interrupts if needed: hw bug w/a */ 2800 /* enable interrupts if needed: hw bug w/a */
@@ -3450,7 +2812,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3450 2812
3451 err = iwl_dbgfs_register(priv, DRV_NAME); 2813 err = iwl_dbgfs_register(priv, DRV_NAME);
3452 if (err) 2814 if (err)
3453 IWL_ERR(priv, "failed to create debugfs files\n"); 2815 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
3454 2816
3455 /* If platform's RF_KILL switch is NOT set to KILL */ 2817 /* If platform's RF_KILL switch is NOT set to KILL */
3456 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) 2818 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
@@ -3533,7 +2895,7 @@ static void __devexit iwl_pci_remove(struct pci_dev *pdev)
3533 iwl_rx_queue_free(priv, &priv->rxq); 2895 iwl_rx_queue_free(priv, &priv->rxq);
3534 iwl_hw_txq_ctx_free(priv); 2896 iwl_hw_txq_ctx_free(priv);
3535 2897
3536 iwl_clear_stations_table(priv); 2898 priv->cfg->ops->smgmt->clear_station_table(priv);
3537 iwl_eeprom_free(priv); 2899 iwl_eeprom_free(priv);
3538 2900
3539 2901
@@ -3561,45 +2923,6 @@ static void __devexit iwl_pci_remove(struct pci_dev *pdev)
3561 ieee80211_free_hw(priv->hw); 2923 ieee80211_free_hw(priv->hw);
3562} 2924}
3563 2925
3564#ifdef CONFIG_PM
3565
3566static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
3567{
3568 struct iwl_priv *priv = pci_get_drvdata(pdev);
3569
3570 if (priv->is_open) {
3571 set_bit(STATUS_IN_SUSPEND, &priv->status);
3572 iwl_mac_stop(priv->hw);
3573 priv->is_open = 1;
3574 }
3575
3576 pci_save_state(pdev);
3577 pci_disable_device(pdev);
3578 pci_set_power_state(pdev, PCI_D3hot);
3579
3580 return 0;
3581}
3582
3583static int iwl_pci_resume(struct pci_dev *pdev)
3584{
3585 struct iwl_priv *priv = pci_get_drvdata(pdev);
3586 int ret;
3587
3588 pci_set_power_state(pdev, PCI_D0);
3589 ret = pci_enable_device(pdev);
3590 if (ret)
3591 return ret;
3592 pci_restore_state(pdev);
3593 iwl_enable_interrupts(priv);
3594
3595 if (priv->is_open)
3596 iwl_mac_start(priv->hw);
3597
3598 clear_bit(STATUS_IN_SUSPEND, &priv->status);
3599 return 0;
3600}
3601
3602#endif /* CONFIG_PM */
3603 2926
3604/***************************************************************************** 2927/*****************************************************************************
3605 * 2928 *
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 29d40746da6..7b84d5246b3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -2469,11 +2469,12 @@ struct iwl_ssid_ie {
2469 u8 ssid[32]; 2469 u8 ssid[32];
2470} __attribute__ ((packed)); 2470} __attribute__ ((packed));
2471 2471
2472#define PROBE_OPTION_MAX_API1 0x4 2472#define PROBE_OPTION_MAX_3945 4
2473#define PROBE_OPTION_MAX 0x14 2473#define PROBE_OPTION_MAX 20
2474#define TX_CMD_LIFE_TIME_INFINITE cpu_to_le32(0xFFFFFFFF) 2474#define TX_CMD_LIFE_TIME_INFINITE cpu_to_le32(0xFFFFFFFF)
2475#define IWL_GOOD_CRC_TH cpu_to_le16(1) 2475#define IWL_GOOD_CRC_TH cpu_to_le16(1)
2476#define IWL_MAX_SCAN_SIZE 1024 2476#define IWL_MAX_SCAN_SIZE 1024
2477#define IWL_MAX_PROBE_REQUEST 200
2477 2478
2478/* 2479/*
2479 * REPLY_SCAN_CMD = 0x80 (command) 2480 * REPLY_SCAN_CMD = 0x80 (command)
@@ -2552,7 +2553,7 @@ struct iwl3945_scan_cmd {
2552 struct iwl3945_tx_cmd tx_cmd; 2553 struct iwl3945_tx_cmd tx_cmd;
2553 2554
2554 /* For directed active scans (set to all-0s otherwise) */ 2555 /* For directed active scans (set to all-0s otherwise) */
2555 struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX_API1]; 2556 struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX_3945];
2556 2557
2557 /* 2558 /*
2558 * Probe request frame, followed by channel list. 2559 * Probe request frame, followed by channel list.
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index c54fb93e9d7..3dec2d25fa3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -735,6 +735,8 @@ int iwl_full_rxon_required(struct iwl_priv *priv)
735 priv->active_rxon.ofdm_ht_single_stream_basic_rates) || 735 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
736 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != 736 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
737 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || 737 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
738 (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
739 priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
738 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) 740 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
739 return 1; 741 return 1;
740 742
@@ -821,7 +823,8 @@ void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
821 823
822 rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS); 824 rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
823 825
824 iwl_set_rxon_chain(priv); 826 if (priv->cfg->ops->hcmd->set_rxon_chain)
827 priv->cfg->ops->hcmd->set_rxon_chain(priv);
825 828
826 IWL_DEBUG_ASSOC(priv, "supported HT rate 0x%X 0x%X 0x%X " 829 IWL_DEBUG_ASSOC(priv, "supported HT rate 0x%X 0x%X 0x%X "
827 "rxon flags 0x%X operation mode :0x%X " 830 "rxon flags 0x%X operation mode :0x%X "
@@ -901,10 +904,11 @@ static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
901 * never called for monitor mode. The only way mac80211 informs us about 904 * never called for monitor mode. The only way mac80211 informs us about
902 * monitor mode is through configuring filters (call to configure_filter). 905 * monitor mode is through configuring filters (call to configure_filter).
903 */ 906 */
904static bool iwl_is_monitor_mode(struct iwl_priv *priv) 907bool iwl_is_monitor_mode(struct iwl_priv *priv)
905{ 908{
906 return !!(priv->staging_rxon.filter_flags & RXON_FILTER_PROMISC_MSK); 909 return !!(priv->staging_rxon.filter_flags & RXON_FILTER_PROMISC_MSK);
907} 910}
911EXPORT_SYMBOL(iwl_is_monitor_mode);
908 912
909/** 913/**
910 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image 914 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
@@ -1068,11 +1072,6 @@ void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
1068 RXON_FILTER_ACCEPT_GRP_MSK; 1072 RXON_FILTER_ACCEPT_GRP_MSK;
1069 break; 1073 break;
1070 1074
1071 case NL80211_IFTYPE_MONITOR:
1072 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
1073 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
1074 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
1075 break;
1076 default: 1075 default:
1077 IWL_ERR(priv, "Unsupported interface type %d\n", mode); 1076 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
1078 break; 1077 break;
@@ -1117,6 +1116,7 @@ void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
1117 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); 1116 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
1118 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; 1117 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1119 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; 1118 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
1119 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
1120} 1120}
1121EXPORT_SYMBOL(iwl_connection_init_rx_config); 1121EXPORT_SYMBOL(iwl_connection_init_rx_config);
1122 1122
@@ -1305,7 +1305,10 @@ int iwl_setup_mac(struct iwl_priv *priv)
1305 BIT(NL80211_IFTYPE_ADHOC); 1305 BIT(NL80211_IFTYPE_ADHOC);
1306 1306
1307 hw->wiphy->custom_regulatory = true; 1307 hw->wiphy->custom_regulatory = true;
1308 hw->wiphy->max_scan_ssids = 1; 1308
1309 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
1310 /* we create the 802.11 header and a zero-length SSID element */
1311 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
1309 1312
1310 /* Default value; 4 EDCA QOS priorities */ 1313 /* Default value; 4 EDCA QOS priorities */
1311 hw->queues = 4; 1314 hw->queues = 4;
@@ -1366,7 +1369,7 @@ int iwl_init_drv(struct iwl_priv *priv)
1366 mutex_init(&priv->mutex); 1369 mutex_init(&priv->mutex);
1367 1370
1368 /* Clear the driver's (not device's) station table */ 1371 /* Clear the driver's (not device's) station table */
1369 iwl_clear_stations_table(priv); 1372 priv->cfg->ops->smgmt->clear_station_table(priv);
1370 1373
1371 priv->data_retry_limit = -1; 1374 priv->data_retry_limit = -1;
1372 priv->ieee_channels = NULL; 1375 priv->ieee_channels = NULL;
@@ -1378,7 +1381,9 @@ int iwl_init_drv(struct iwl_priv *priv)
1378 priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DISABLED; 1381 priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DISABLED;
1379 1382
1380 /* Choose which receivers/antennas to use */ 1383 /* Choose which receivers/antennas to use */
1381 iwl_set_rxon_chain(priv); 1384 if (priv->cfg->ops->hcmd->set_rxon_chain)
1385 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1386
1382 iwl_init_scan_params(priv); 1387 iwl_init_scan_params(priv);
1383 1388
1384 iwl_reset_qos(priv); 1389 iwl_reset_qos(priv);
@@ -2054,7 +2059,7 @@ void iwl_bg_rf_kill(struct work_struct *work)
2054 "HW and/or SW RF Kill no longer active, restarting " 2059 "HW and/or SW RF Kill no longer active, restarting "
2055 "device\n"); 2060 "device\n");
2056 if (!test_bit(STATUS_EXIT_PENDING, &priv->status) && 2061 if (!test_bit(STATUS_EXIT_PENDING, &priv->status) &&
2057 test_bit(STATUS_ALIVE, &priv->status)) 2062 priv->is_open)
2058 queue_work(priv->workqueue, &priv->restart); 2063 queue_work(priv->workqueue, &priv->restart);
2059 } else { 2064 } else {
2060 /* make sure mac80211 stop sending Tx frame */ 2065 /* make sure mac80211 stop sending Tx frame */
@@ -2112,3 +2117,727 @@ void iwl_rx_reply_error(struct iwl_priv *priv,
2112} 2117}
2113EXPORT_SYMBOL(iwl_rx_reply_error); 2118EXPORT_SYMBOL(iwl_rx_reply_error);
2114 2119
2120void iwl_clear_isr_stats(struct iwl_priv *priv)
2121{
2122 memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
2123}
2124EXPORT_SYMBOL(iwl_clear_isr_stats);
2125
2126int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
2127 const struct ieee80211_tx_queue_params *params)
2128{
2129 struct iwl_priv *priv = hw->priv;
2130 unsigned long flags;
2131 int q;
2132
2133 IWL_DEBUG_MAC80211(priv, "enter\n");
2134
2135 if (!iwl_is_ready_rf(priv)) {
2136 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2137 return -EIO;
2138 }
2139
2140 if (queue >= AC_NUM) {
2141 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
2142 return 0;
2143 }
2144
2145 q = AC_NUM - 1 - queue;
2146
2147 spin_lock_irqsave(&priv->lock, flags);
2148
2149 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
2150 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
2151 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
2152 priv->qos_data.def_qos_parm.ac[q].edca_txop =
2153 cpu_to_le16((params->txop * 32));
2154
2155 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
2156 priv->qos_data.qos_active = 1;
2157
2158 if (priv->iw_mode == NL80211_IFTYPE_AP)
2159 iwl_activate_qos(priv, 1);
2160 else if (priv->assoc_id && iwl_is_associated(priv))
2161 iwl_activate_qos(priv, 0);
2162
2163 spin_unlock_irqrestore(&priv->lock, flags);
2164
2165 IWL_DEBUG_MAC80211(priv, "leave\n");
2166 return 0;
2167}
2168EXPORT_SYMBOL(iwl_mac_conf_tx);
2169
2170static void iwl_ht_conf(struct iwl_priv *priv,
2171 struct ieee80211_bss_conf *bss_conf)
2172{
2173 struct ieee80211_sta_ht_cap *ht_conf;
2174 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
2175 struct ieee80211_sta *sta;
2176
2177 IWL_DEBUG_MAC80211(priv, "enter: \n");
2178
2179 if (!iwl_conf->is_ht)
2180 return;
2181
2182
2183 /*
2184 * It is totally wrong to base global information on something
2185 * that is valid only when associated, alas, this driver works
2186 * that way and I don't know how to fix it.
2187 */
2188
2189 rcu_read_lock();
2190 sta = ieee80211_find_sta(priv->hw, priv->bssid);
2191 if (!sta) {
2192 rcu_read_unlock();
2193 return;
2194 }
2195 ht_conf = &sta->ht_cap;
2196
2197 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
2198 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
2199 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
2200 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
2201
2202 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
2203 iwl_conf->max_amsdu_size =
2204 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
2205
2206 iwl_conf->supported_chan_width =
2207 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
2208
2209 /*
2210 * XXX: The HT configuration needs to be moved into iwl_mac_config()
2211 * to be done there correctly.
2212 */
2213
2214 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
2215 if (conf_is_ht40_minus(&priv->hw->conf))
2216 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
2217 else if (conf_is_ht40_plus(&priv->hw->conf))
2218 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
2219
2220 /* If no above or below channel supplied disable FAT channel */
2221 if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
2222 iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
2223 iwl_conf->supported_chan_width = 0;
2224
2225 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
2226
2227 memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
2228
2229 iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
2230 iwl_conf->ht_protection =
2231 bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
2232 iwl_conf->non_GF_STA_present =
2233 !!(bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
2234
2235 rcu_read_unlock();
2236
2237 IWL_DEBUG_MAC80211(priv, "leave\n");
2238}
2239
2240#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
2241void iwl_bss_info_changed(struct ieee80211_hw *hw,
2242 struct ieee80211_vif *vif,
2243 struct ieee80211_bss_conf *bss_conf,
2244 u32 changes)
2245{
2246 struct iwl_priv *priv = hw->priv;
2247 int ret;
2248
2249 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
2250
2251 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
2252 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
2253 bss_conf->use_short_preamble);
2254 if (bss_conf->use_short_preamble)
2255 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2256 else
2257 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2258 }
2259
2260 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
2261 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
2262 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
2263 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
2264 else
2265 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2266 }
2267
2268 if (changes & BSS_CHANGED_HT) {
2269 iwl_ht_conf(priv, bss_conf);
2270
2271 if (priv->cfg->ops->hcmd->set_rxon_chain)
2272 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2273 }
2274
2275 if (changes & BSS_CHANGED_ASSOC) {
2276 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
2277 /* This should never happen as this function should
2278 * never be called from interrupt context. */
2279 if (WARN_ON_ONCE(in_interrupt()))
2280 return;
2281 if (bss_conf->assoc) {
2282 priv->assoc_id = bss_conf->aid;
2283 priv->beacon_int = bss_conf->beacon_int;
2284 priv->power_data.dtim_period = bss_conf->dtim_period;
2285 priv->timestamp = bss_conf->timestamp;
2286 priv->assoc_capability = bss_conf->assoc_capability;
2287
2288 /* we have just associated, don't start scan too early
2289 * leave time for EAPOL exchange to complete
2290 */
2291 priv->next_scan_jiffies = jiffies +
2292 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
2293 mutex_lock(&priv->mutex);
2294 priv->cfg->ops->lib->post_associate(priv);
2295 mutex_unlock(&priv->mutex);
2296 } else {
2297 priv->assoc_id = 0;
2298 IWL_DEBUG_MAC80211(priv, "DISASSOC %d\n", bss_conf->assoc);
2299 }
2300 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
2301 IWL_DEBUG_MAC80211(priv, "Associated Changes %d\n", changes);
2302 ret = iwl_send_rxon_assoc(priv);
2303 if (!ret)
2304 /* Sync active_rxon with latest change. */
2305 memcpy((void *)&priv->active_rxon,
2306 &priv->staging_rxon,
2307 sizeof(struct iwl_rxon_cmd));
2308 }
2309
2310}
2311EXPORT_SYMBOL(iwl_bss_info_changed);
2312
2313int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
2314{
2315 struct iwl_priv *priv = hw->priv;
2316 unsigned long flags;
2317 __le64 timestamp;
2318
2319 IWL_DEBUG_MAC80211(priv, "enter\n");
2320
2321 if (!iwl_is_ready_rf(priv)) {
2322 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2323 return -EIO;
2324 }
2325
2326 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2327 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
2328 return -EIO;
2329 }
2330
2331 spin_lock_irqsave(&priv->lock, flags);
2332
2333 if (priv->ibss_beacon)
2334 dev_kfree_skb(priv->ibss_beacon);
2335
2336 priv->ibss_beacon = skb;
2337
2338 priv->assoc_id = 0;
2339 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
2340 priv->timestamp = le64_to_cpu(timestamp);
2341
2342 IWL_DEBUG_MAC80211(priv, "leave\n");
2343 spin_unlock_irqrestore(&priv->lock, flags);
2344
2345 iwl_reset_qos(priv);
2346
2347 priv->cfg->ops->lib->post_associate(priv);
2348
2349
2350 return 0;
2351}
2352EXPORT_SYMBOL(iwl_mac_beacon_update);
2353
2354int iwl_set_mode(struct iwl_priv *priv, int mode)
2355{
2356 if (mode == NL80211_IFTYPE_ADHOC) {
2357 const struct iwl_channel_info *ch_info;
2358
2359 ch_info = iwl_get_channel_info(priv,
2360 priv->band,
2361 le16_to_cpu(priv->staging_rxon.channel));
2362
2363 if (!ch_info || !is_channel_ibss(ch_info)) {
2364 IWL_ERR(priv, "channel %d not IBSS channel\n",
2365 le16_to_cpu(priv->staging_rxon.channel));
2366 return -EINVAL;
2367 }
2368 }
2369
2370 iwl_connection_init_rx_config(priv, mode);
2371
2372 if (priv->cfg->ops->hcmd->set_rxon_chain)
2373 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2374
2375 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2376
2377 priv->cfg->ops->smgmt->clear_station_table(priv);
2378
2379 /* dont commit rxon if rf-kill is on*/
2380 if (!iwl_is_ready_rf(priv))
2381 return -EAGAIN;
2382
2383 cancel_delayed_work(&priv->scan_check);
2384 if (iwl_scan_cancel_timeout(priv, 100)) {
2385 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
2386 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2387 return -EAGAIN;
2388 }
2389
2390 iwlcore_commit_rxon(priv);
2391
2392 return 0;
2393}
2394EXPORT_SYMBOL(iwl_set_mode);
2395
2396int iwl_mac_add_interface(struct ieee80211_hw *hw,
2397 struct ieee80211_if_init_conf *conf)
2398{
2399 struct iwl_priv *priv = hw->priv;
2400 unsigned long flags;
2401
2402 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
2403
2404 if (priv->vif) {
2405 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
2406 return -EOPNOTSUPP;
2407 }
2408
2409 spin_lock_irqsave(&priv->lock, flags);
2410 priv->vif = conf->vif;
2411 priv->iw_mode = conf->type;
2412
2413 spin_unlock_irqrestore(&priv->lock, flags);
2414
2415 mutex_lock(&priv->mutex);
2416
2417 if (conf->mac_addr) {
2418 IWL_DEBUG_MAC80211(priv, "Set %pM\n", conf->mac_addr);
2419 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2420 }
2421
2422 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
2423 /* we are not ready, will run again when ready */
2424 set_bit(STATUS_MODE_PENDING, &priv->status);
2425
2426 mutex_unlock(&priv->mutex);
2427
2428 IWL_DEBUG_MAC80211(priv, "leave\n");
2429 return 0;
2430}
2431EXPORT_SYMBOL(iwl_mac_add_interface);
2432
2433void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2434 struct ieee80211_if_init_conf *conf)
2435{
2436 struct iwl_priv *priv = hw->priv;
2437
2438 IWL_DEBUG_MAC80211(priv, "enter\n");
2439
2440 mutex_lock(&priv->mutex);
2441
2442 if (iwl_is_ready_rf(priv)) {
2443 iwl_scan_cancel_timeout(priv, 100);
2444 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2445 iwlcore_commit_rxon(priv);
2446 }
2447 if (priv->vif == conf->vif) {
2448 priv->vif = NULL;
2449 memset(priv->bssid, 0, ETH_ALEN);
2450 }
2451 mutex_unlock(&priv->mutex);
2452
2453 IWL_DEBUG_MAC80211(priv, "leave\n");
2454
2455}
2456EXPORT_SYMBOL(iwl_mac_remove_interface);
2457
2458/**
2459 * iwl_mac_config - mac80211 config callback
2460 *
2461 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2462 * be set inappropriately and the driver currently sets the hardware up to
2463 * use it whenever needed.
2464 */
2465int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2466{
2467 struct iwl_priv *priv = hw->priv;
2468 const struct iwl_channel_info *ch_info;
2469 struct ieee80211_conf *conf = &hw->conf;
2470 unsigned long flags = 0;
2471 int ret = 0;
2472 u16 ch;
2473 int scan_active = 0;
2474
2475 mutex_lock(&priv->mutex);
2476
2477 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
2478 conf->channel->hw_value, changed);
2479
2480 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2481 test_bit(STATUS_SCANNING, &priv->status))) {
2482 scan_active = 1;
2483 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
2484 }
2485
2486
2487 /* during scanning mac80211 will delay channel setting until
2488 * scan finish with changed = 0
2489 */
2490 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2491 if (scan_active)
2492 goto set_ch_out;
2493
2494 ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
2495 ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
2496 if (!is_channel_valid(ch_info)) {
2497 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
2498 ret = -EINVAL;
2499 goto set_ch_out;
2500 }
2501
2502 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2503 !is_channel_ibss(ch_info)) {
2504 IWL_ERR(priv, "channel %d in band %d not "
2505 "IBSS channel\n",
2506 conf->channel->hw_value, conf->channel->band);
2507 ret = -EINVAL;
2508 goto set_ch_out;
2509 }
2510
2511 priv->current_ht_config.is_ht = conf_is_ht(conf);
2512
2513 spin_lock_irqsave(&priv->lock, flags);
2514
2515
2516 /* if we are switching from ht to 2.4 clear flags
2517 * from any ht related info since 2.4 does not
2518 * support ht */
2519 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
2520 priv->staging_rxon.flags = 0;
2521
2522 iwl_set_rxon_channel(priv, conf->channel);
2523
2524 iwl_set_flags_for_band(priv, conf->channel->band);
2525 spin_unlock_irqrestore(&priv->lock, flags);
2526 set_ch_out:
2527 /* The list of supported rates and rate mask can be different
2528 * for each band; since the band may have changed, reset
2529 * the rate mask to what mac80211 lists */
2530 iwl_set_rate(priv);
2531 }
2532
2533 if (changed & IEEE80211_CONF_CHANGE_PS) {
2534 if (conf->flags & IEEE80211_CONF_PS)
2535 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2536 else
2537 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2538 if (ret)
2539 IWL_DEBUG_MAC80211(priv, "Error setting power level\n");
2540
2541 }
2542
2543 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2544 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
2545 priv->tx_power_user_lmt, conf->power_level);
2546
2547 iwl_set_tx_power(priv, conf->power_level, false);
2548 }
2549
2550 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2551 if (priv->cfg->ops->hcmd->set_rxon_chain)
2552 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2553
2554 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
2555 if (conf->radio_enabled &&
2556 iwl_radio_kill_sw_enable_radio(priv)) {
2557 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
2558 "waiting for uCode\n");
2559 goto out;
2560 }
2561
2562 if (!conf->radio_enabled)
2563 iwl_radio_kill_sw_disable_radio(priv);
2564 }
2565
2566 if (!conf->radio_enabled) {
2567 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
2568 goto out;
2569 }
2570
2571 if (!iwl_is_ready(priv)) {
2572 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2573 goto out;
2574 }
2575
2576 if (scan_active)
2577 goto out;
2578
2579 if (memcmp(&priv->active_rxon,
2580 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2581 iwlcore_commit_rxon(priv);
2582 else
2583 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
2584
2585
2586out:
2587 IWL_DEBUG_MAC80211(priv, "leave\n");
2588 mutex_unlock(&priv->mutex);
2589 return ret;
2590}
2591EXPORT_SYMBOL(iwl_mac_config);
2592
2593int iwl_mac_config_interface(struct ieee80211_hw *hw,
2594 struct ieee80211_vif *vif,
2595 struct ieee80211_if_conf *conf)
2596{
2597 struct iwl_priv *priv = hw->priv;
2598 int rc;
2599
2600 if (conf == NULL)
2601 return -EIO;
2602
2603 if (priv->vif != vif) {
2604 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
2605 return 0;
2606 }
2607
2608 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2609 conf->changed & IEEE80211_IFCC_BEACON) {
2610 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2611 if (!beacon)
2612 return -ENOMEM;
2613 mutex_lock(&priv->mutex);
2614 rc = iwl_mac_beacon_update(hw, beacon);
2615 mutex_unlock(&priv->mutex);
2616 if (rc)
2617 return rc;
2618 }
2619
2620 if (!iwl_is_alive(priv))
2621 return -EAGAIN;
2622
2623 mutex_lock(&priv->mutex);
2624
2625 if (conf->bssid)
2626 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
2627
2628/*
2629 * very dubious code was here; the probe filtering flag is never set:
2630 *
2631 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2632 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
2633 */
2634
2635 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2636 if (!conf->bssid) {
2637 conf->bssid = priv->mac_addr;
2638 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
2639 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
2640 conf->bssid);
2641 }
2642 if (priv->ibss_beacon)
2643 dev_kfree_skb(priv->ibss_beacon);
2644
2645 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
2646 }
2647
2648 if (iwl_is_rfkill(priv))
2649 goto done;
2650
2651 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2652 !is_multicast_ether_addr(conf->bssid)) {
2653 /* If there is currently a HW scan going on in the background
2654 * then we need to cancel it else the RXON below will fail. */
2655 if (iwl_scan_cancel_timeout(priv, 100)) {
2656 IWL_WARN(priv, "Aborted scan still in progress "
2657 "after 100ms\n");
2658 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
2659 mutex_unlock(&priv->mutex);
2660 return -EAGAIN;
2661 }
2662 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2663
2664 /* TODO: Audit driver for usage of these members and see
2665 * if mac80211 deprecates them (priv->bssid looks like it
2666 * shouldn't be there, but I haven't scanned the IBSS code
2667 * to verify) - jpk */
2668 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2669
2670 if (priv->iw_mode == NL80211_IFTYPE_AP)
2671 iwlcore_config_ap(priv);
2672 else {
2673 rc = iwlcore_commit_rxon(priv);
2674 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
2675 iwl_rxon_add_station(
2676 priv, priv->active_rxon.bssid_addr, 1);
2677 }
2678
2679 } else {
2680 iwl_scan_cancel_timeout(priv, 100);
2681 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2682 iwlcore_commit_rxon(priv);
2683 }
2684
2685 done:
2686 IWL_DEBUG_MAC80211(priv, "leave\n");
2687 mutex_unlock(&priv->mutex);
2688
2689 return 0;
2690}
2691EXPORT_SYMBOL(iwl_mac_config_interface);
2692
2693int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
2694 struct ieee80211_tx_queue_stats *stats)
2695{
2696 struct iwl_priv *priv = hw->priv;
2697 int i, avail;
2698 struct iwl_tx_queue *txq;
2699 struct iwl_queue *q;
2700 unsigned long flags;
2701
2702 IWL_DEBUG_MAC80211(priv, "enter\n");
2703
2704 if (!iwl_is_ready_rf(priv)) {
2705 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2706 return -EIO;
2707 }
2708
2709 spin_lock_irqsave(&priv->lock, flags);
2710
2711 for (i = 0; i < AC_NUM; i++) {
2712 txq = &priv->txq[i];
2713 q = &txq->q;
2714 avail = iwl_queue_space(q);
2715
2716 stats[i].len = q->n_window - avail;
2717 stats[i].limit = q->n_window - q->high_mark;
2718 stats[i].count = q->n_window;
2719
2720 }
2721 spin_unlock_irqrestore(&priv->lock, flags);
2722
2723 IWL_DEBUG_MAC80211(priv, "leave\n");
2724
2725 return 0;
2726}
2727EXPORT_SYMBOL(iwl_mac_get_tx_stats);
2728
2729void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2730{
2731 struct iwl_priv *priv = hw->priv;
2732 unsigned long flags;
2733
2734 mutex_lock(&priv->mutex);
2735 IWL_DEBUG_MAC80211(priv, "enter\n");
2736
2737 spin_lock_irqsave(&priv->lock, flags);
2738 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
2739 spin_unlock_irqrestore(&priv->lock, flags);
2740
2741 iwl_reset_qos(priv);
2742
2743 spin_lock_irqsave(&priv->lock, flags);
2744 priv->assoc_id = 0;
2745 priv->assoc_capability = 0;
2746 priv->assoc_station_added = 0;
2747
2748 /* new association get rid of ibss beacon skb */
2749 if (priv->ibss_beacon)
2750 dev_kfree_skb(priv->ibss_beacon);
2751
2752 priv->ibss_beacon = NULL;
2753
2754 priv->beacon_int = priv->hw->conf.beacon_int;
2755 priv->timestamp = 0;
2756 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
2757 priv->beacon_int = 0;
2758
2759 spin_unlock_irqrestore(&priv->lock, flags);
2760
2761 if (!iwl_is_ready_rf(priv)) {
2762 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2763 mutex_unlock(&priv->mutex);
2764 return;
2765 }
2766
2767 /* we are restarting association process
2768 * clear RXON_FILTER_ASSOC_MSK bit
2769 */
2770 if (priv->iw_mode != NL80211_IFTYPE_AP) {
2771 iwl_scan_cancel_timeout(priv, 100);
2772 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2773 iwlcore_commit_rxon(priv);
2774 }
2775
2776 iwl_power_update_mode(priv, 0);
2777
2778 /* Per mac80211.h: This is only used in IBSS mode... */
2779 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
2780
2781 /* switch to CAM during association period.
2782 * the ucode will block any association/authentication
2783 * frome during assiciation period if it can not hear
2784 * the AP because of PM. the timer enable PM back is
2785 * association do not complete
2786 */
2787 if (priv->hw->conf.channel->flags &
2788 (IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_RADAR))
2789 iwl_power_disable_management(priv, 3000);
2790
2791 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
2792 mutex_unlock(&priv->mutex);
2793 return;
2794 }
2795
2796 iwl_set_rate(priv);
2797
2798 mutex_unlock(&priv->mutex);
2799
2800 IWL_DEBUG_MAC80211(priv, "leave\n");
2801}
2802EXPORT_SYMBOL(iwl_mac_reset_tsf);
2803
2804#ifdef CONFIG_PM
2805
2806int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2807{
2808 struct iwl_priv *priv = pci_get_drvdata(pdev);
2809
2810 /*
2811 * This function is called when system goes into suspend state
2812 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
2813 * first but since iwl_mac_stop() has no knowledge of who the caller is,
2814 * it will not call apm_ops.stop() to stop the DMA operation.
2815 * Calling apm_ops.stop here to make sure we stop the DMA.
2816 */
2817 priv->cfg->ops->lib->apm_ops.stop(priv);
2818
2819 pci_save_state(pdev);
2820 pci_disable_device(pdev);
2821 pci_set_power_state(pdev, PCI_D3hot);
2822
2823 return 0;
2824}
2825EXPORT_SYMBOL(iwl_pci_suspend);
2826
2827int iwl_pci_resume(struct pci_dev *pdev)
2828{
2829 struct iwl_priv *priv = pci_get_drvdata(pdev);
2830 int ret;
2831
2832 pci_set_power_state(pdev, PCI_D0);
2833 ret = pci_enable_device(pdev);
2834 if (ret)
2835 return ret;
2836 pci_restore_state(pdev);
2837 iwl_enable_interrupts(priv);
2838
2839 return 0;
2840}
2841EXPORT_SYMBOL(iwl_pci_resume);
2842
2843#endif /* CONFIG_PM */
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index a8eac8c3c1f..d4c60afa289 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -83,9 +83,21 @@ struct iwl_cmd;
83#define IWL_SKU_A 0x2 83#define IWL_SKU_A 0x2
84#define IWL_SKU_N 0x8 84#define IWL_SKU_N 0x8
85 85
86struct iwl_station_mgmt_ops {
87 u8 (*add_station)(struct iwl_priv *priv, const u8 *addr,
88 int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info);
89 int (*remove_station)(struct iwl_priv *priv, const u8 *addr,
90 int is_ap);
91 u8 (*find_station)(struct iwl_priv *priv, const u8 *addr);
92 void (*clear_station_table)(struct iwl_priv *priv);
93};
94
86struct iwl_hcmd_ops { 95struct iwl_hcmd_ops {
87 int (*rxon_assoc)(struct iwl_priv *priv); 96 int (*rxon_assoc)(struct iwl_priv *priv);
97 int (*commit_rxon)(struct iwl_priv *priv);
98 void (*set_rxon_chain)(struct iwl_priv *priv);
88}; 99};
100
89struct iwl_hcmd_utils_ops { 101struct iwl_hcmd_utils_ops {
90 u16 (*get_hcmd_size)(u8 cmd_id, u16 len); 102 u16 (*get_hcmd_size)(u8 cmd_id, u16 len);
91 u16 (*build_addsta_hcmd)(const struct iwl_addsta_cmd *cmd, u8 *data); 103 u16 (*build_addsta_hcmd)(const struct iwl_addsta_cmd *cmd, u8 *data);
@@ -149,6 +161,9 @@ struct iwl_lib_ops {
149 int (*send_tx_power) (struct iwl_priv *priv); 161 int (*send_tx_power) (struct iwl_priv *priv);
150 void (*update_chain_flags)(struct iwl_priv *priv); 162 void (*update_chain_flags)(struct iwl_priv *priv);
151 void (*temperature) (struct iwl_priv *priv); 163 void (*temperature) (struct iwl_priv *priv);
164 void (*post_associate) (struct iwl_priv *priv);
165 void (*config_ap) (struct iwl_priv *priv);
166
152 /* eeprom operations (as defined in iwl-eeprom.h) */ 167 /* eeprom operations (as defined in iwl-eeprom.h) */
153 struct iwl_eeprom_ops eeprom_ops; 168 struct iwl_eeprom_ops eeprom_ops;
154}; 169};
@@ -157,10 +172,10 @@ struct iwl_ops {
157 const struct iwl_lib_ops *lib; 172 const struct iwl_lib_ops *lib;
158 const struct iwl_hcmd_ops *hcmd; 173 const struct iwl_hcmd_ops *hcmd;
159 const struct iwl_hcmd_utils_ops *utils; 174 const struct iwl_hcmd_utils_ops *utils;
175 const struct iwl_station_mgmt_ops *smgmt;
160}; 176};
161 177
162struct iwl_mod_params { 178struct iwl_mod_params {
163 int disable; /* def: 0 = enable radio */
164 int sw_crypto; /* def: 0 = using hardware encryption */ 179 int sw_crypto; /* def: 0 = using hardware encryption */
165 u32 debug; /* def: 0 = minimal debug log messages */ 180 u32 debug; /* def: 0 = minimal debug log messages */
166 int disable_hw_scan; /* def: 0 = use h/w scan */ 181 int disable_hw_scan; /* def: 0 = use h/w scan */
@@ -225,6 +240,8 @@ struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
225void iwl_hw_detect(struct iwl_priv *priv); 240void iwl_hw_detect(struct iwl_priv *priv);
226void iwl_reset_qos(struct iwl_priv *priv); 241void iwl_reset_qos(struct iwl_priv *priv);
227void iwl_activate_qos(struct iwl_priv *priv, u8 force); 242void iwl_activate_qos(struct iwl_priv *priv, u8 force);
243int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
244 const struct ieee80211_tx_queue_params *params);
228void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt); 245void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt);
229int iwl_check_rxon_cmd(struct iwl_priv *priv); 246int iwl_check_rxon_cmd(struct iwl_priv *priv);
230int iwl_full_rxon_required(struct iwl_priv *priv); 247int iwl_full_rxon_required(struct iwl_priv *priv);
@@ -249,6 +266,27 @@ int iwl_setup_mac(struct iwl_priv *priv);
249int iwl_set_hw_params(struct iwl_priv *priv); 266int iwl_set_hw_params(struct iwl_priv *priv);
250int iwl_init_drv(struct iwl_priv *priv); 267int iwl_init_drv(struct iwl_priv *priv);
251void iwl_uninit_drv(struct iwl_priv *priv); 268void iwl_uninit_drv(struct iwl_priv *priv);
269bool iwl_is_monitor_mode(struct iwl_priv *priv);
270void iwl_post_associate(struct iwl_priv *priv);
271void iwl_bss_info_changed(struct ieee80211_hw *hw,
272 struct ieee80211_vif *vif,
273 struct ieee80211_bss_conf *bss_conf,
274 u32 changes);
275int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
276int iwl_commit_rxon(struct iwl_priv *priv);
277int iwl_set_mode(struct iwl_priv *priv, int mode);
278int iwl_mac_add_interface(struct ieee80211_hw *hw,
279 struct ieee80211_if_init_conf *conf);
280void iwl_mac_remove_interface(struct ieee80211_hw *hw,
281 struct ieee80211_if_init_conf *conf);
282int iwl_mac_config(struct ieee80211_hw *hw, u32 changed);
283void iwl_config_ap(struct iwl_priv *priv);
284int iwl_mac_config_interface(struct ieee80211_hw *hw,
285 struct ieee80211_vif *vif,
286 struct ieee80211_if_conf *conf);
287int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
288 struct ieee80211_tx_queue_stats *stats);
289void iwl_mac_reset_tsf(struct ieee80211_hw *hw);
252 290
253/***************************************************** 291/*****************************************************
254 * RX handlers. 292 * RX handlers.
@@ -358,8 +396,8 @@ int iwl_scan_cancel(struct iwl_priv *priv);
358int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms); 396int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms);
359int iwl_scan_initiate(struct iwl_priv *priv); 397int iwl_scan_initiate(struct iwl_priv *priv);
360int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req); 398int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req);
361u16 iwl_fill_probe_req(struct iwl_priv *priv, enum ieee80211_band band, 399u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
362 struct ieee80211_mgmt *frame, int left); 400 const u8 *ie, int ie_len, int left);
363void iwl_setup_rx_scan_handlers(struct iwl_priv *priv); 401void iwl_setup_rx_scan_handlers(struct iwl_priv *priv);
364u16 iwl_get_active_dwell_time(struct iwl_priv *priv, 402u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
365 enum ieee80211_band band, 403 enum ieee80211_band band,
@@ -432,12 +470,17 @@ static inline u16 iwl_pcie_link_ctl(struct iwl_priv *priv)
432 pci_read_config_word(priv->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl); 470 pci_read_config_word(priv->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
433 return pci_lnk_ctl; 471 return pci_lnk_ctl;
434} 472}
473#ifdef CONFIG_PM
474int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state);
475int iwl_pci_resume(struct pci_dev *pdev);
476#endif /* CONFIG_PM */
435 477
436/***************************************************** 478/*****************************************************
437* Error Handling Debugging 479* Error Handling Debugging
438******************************************************/ 480******************************************************/
439void iwl_dump_nic_error_log(struct iwl_priv *priv); 481void iwl_dump_nic_error_log(struct iwl_priv *priv);
440void iwl_dump_nic_event_log(struct iwl_priv *priv); 482void iwl_dump_nic_event_log(struct iwl_priv *priv);
483void iwl_clear_isr_stats(struct iwl_priv *priv);
441 484
442/***************************************************** 485/*****************************************************
443* GEOS 486* GEOS
@@ -458,7 +501,6 @@ void iwlcore_free_geos(struct iwl_priv *priv);
458#define STATUS_TEMPERATURE 8 501#define STATUS_TEMPERATURE 8
459#define STATUS_GEO_CONFIGURED 9 502#define STATUS_GEO_CONFIGURED 9
460#define STATUS_EXIT_PENDING 10 503#define STATUS_EXIT_PENDING 10
461#define STATUS_IN_SUSPEND 11
462#define STATUS_STATISTICS 12 504#define STATUS_STATISTICS 12
463#define STATUS_SCANNING 13 505#define STATUS_SCANNING 13
464#define STATUS_SCAN_ABORTING 14 506#define STATUS_SCAN_ABORTING 14
@@ -528,7 +570,14 @@ static inline int iwl_send_rxon_assoc(struct iwl_priv *priv)
528{ 570{
529 return priv->cfg->ops->hcmd->rxon_assoc(priv); 571 return priv->cfg->ops->hcmd->rxon_assoc(priv);
530} 572}
531 573static inline int iwlcore_commit_rxon(struct iwl_priv *priv)
574{
575 return priv->cfg->ops->hcmd->commit_rxon(priv);
576}
577static inline void iwlcore_config_ap(struct iwl_priv *priv)
578{
579 priv->cfg->ops->lib->config_ap(priv);
580}
532static inline const struct ieee80211_supported_band *iwl_get_hw_mode( 581static inline const struct ieee80211_supported_band *iwl_get_hw_mode(
533 struct iwl_priv *priv, enum ieee80211_band band) 582 struct iwl_priv *priv, enum ieee80211_band band)
534{ 583{
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
index 65d1a7f2db9..db069801bc4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
@@ -75,6 +75,7 @@ struct iwl_debugfs {
75 struct dentry *file_log_event; 75 struct dentry *file_log_event;
76 struct dentry *file_channels; 76 struct dentry *file_channels;
77 struct dentry *file_status; 77 struct dentry *file_status;
78 struct dentry *file_interrupt;
78 } dbgfs_data_files; 79 } dbgfs_data_files;
79 struct dir_rf_files { 80 struct dir_rf_files {
80 struct dentry *file_disable_sensitivity; 81 struct dentry *file_disable_sensitivity;
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index 64eb585f157..ffc4be3842b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -389,7 +389,7 @@ static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
389 channels[i].max_power, 389 channels[i].max_power,
390 channels[i].flags & IEEE80211_CHAN_RADAR ? 390 channels[i].flags & IEEE80211_CHAN_RADAR ?
391 " (IEEE 802.11h required)" : "", 391 " (IEEE 802.11h required)" : "",
392 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS) 392 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
393 || (channels[i].flags & 393 || (channels[i].flags &
394 IEEE80211_CHAN_RADAR)) ? "" : 394 IEEE80211_CHAN_RADAR)) ? "" :
395 ", IBSS", 395 ", IBSS",
@@ -456,8 +456,6 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
456 test_bit(STATUS_GEO_CONFIGURED, &priv->status)); 456 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
457 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n", 457 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
458 test_bit(STATUS_EXIT_PENDING, &priv->status)); 458 test_bit(STATUS_EXIT_PENDING, &priv->status));
459 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_IN_SUSPEND:\t %d\n",
460 test_bit(STATUS_IN_SUSPEND, &priv->status));
461 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n", 459 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
462 test_bit(STATUS_STATISTICS, &priv->status)); 460 test_bit(STATUS_STATISTICS, &priv->status));
463 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n", 461 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_SCANNING:\t %d\n",
@@ -475,6 +473,95 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
475 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 473 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
476} 474}
477 475
476static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
477 char __user *user_buf,
478 size_t count, loff_t *ppos) {
479
480 struct iwl_priv *priv = (struct iwl_priv *)file->private_data;
481 int pos = 0;
482 int cnt = 0;
483 char *buf;
484 int bufsz = 24 * 64; /* 24 items * 64 char per item */
485 ssize_t ret;
486
487 buf = kzalloc(bufsz, GFP_KERNEL);
488 if (!buf) {
489 IWL_ERR(priv, "Can not allocate Buffer\n");
490 return -ENOMEM;
491 }
492
493 pos += scnprintf(buf + pos, bufsz - pos,
494 "Interrupt Statistics Report:\n");
495
496 pos += scnprintf(buf + pos, bufsz - pos, "HW Error:\t\t\t %u\n",
497 priv->isr_stats.hw);
498 pos += scnprintf(buf + pos, bufsz - pos, "SW Error:\t\t\t %u\n",
499 priv->isr_stats.sw);
500 if (priv->isr_stats.sw > 0) {
501 pos += scnprintf(buf + pos, bufsz - pos,
502 "\tLast Restarting Code: 0x%X\n",
503 priv->isr_stats.sw_err);
504 }
505#ifdef CONFIG_IWLWIFI_DEBUG
506 pos += scnprintf(buf + pos, bufsz - pos, "Frame transmitted:\t\t %u\n",
507 priv->isr_stats.sch);
508 pos += scnprintf(buf + pos, bufsz - pos, "Alive interrupt:\t\t %u\n",
509 priv->isr_stats.alive);
510#endif
511 pos += scnprintf(buf + pos, bufsz - pos,
512 "HW RF KILL switch toggled:\t %u\n",
513 priv->isr_stats.rfkill);
514
515 pos += scnprintf(buf + pos, bufsz - pos, "CT KILL:\t\t\t %u\n",
516 priv->isr_stats.ctkill);
517
518 pos += scnprintf(buf + pos, bufsz - pos, "Wakeup Interrupt:\t\t %u\n",
519 priv->isr_stats.wakeup);
520
521 pos += scnprintf(buf + pos, bufsz - pos,
522 "Rx command responses:\t\t %u\n",
523 priv->isr_stats.rx);
524 for (cnt = 0; cnt < REPLY_MAX; cnt++) {
525 if (priv->isr_stats.rx_handlers[cnt] > 0)
526 pos += scnprintf(buf + pos, bufsz - pos,
527 "\tRx handler[%36s]:\t\t %u\n",
528 get_cmd_string(cnt),
529 priv->isr_stats.rx_handlers[cnt]);
530 }
531
532 pos += scnprintf(buf + pos, bufsz - pos, "Tx/FH interrupt:\t\t %u\n",
533 priv->isr_stats.tx);
534
535 pos += scnprintf(buf + pos, bufsz - pos, "Unexpected INTA:\t\t %u\n",
536 priv->isr_stats.unhandled);
537
538 ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos);
539 kfree(buf);
540 return ret;
541}
542
543static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
544 const char __user *user_buf,
545 size_t count, loff_t *ppos)
546{
547 struct iwl_priv *priv = file->private_data;
548 char buf[8];
549 int buf_size;
550 u32 reset_flag;
551
552 memset(buf, 0, sizeof(buf));
553 buf_size = min(count, sizeof(buf) - 1);
554 if (copy_from_user(buf, user_buf, buf_size))
555 return -EFAULT;
556 if (sscanf(buf, "%x", &reset_flag) != 1)
557 return -EFAULT;
558 if (reset_flag == 0)
559 iwl_clear_isr_stats(priv);
560
561 return count;
562}
563
564
478DEBUGFS_READ_WRITE_FILE_OPS(sram); 565DEBUGFS_READ_WRITE_FILE_OPS(sram);
479DEBUGFS_WRITE_FILE_OPS(log_event); 566DEBUGFS_WRITE_FILE_OPS(log_event);
480DEBUGFS_READ_FILE_OPS(eeprom); 567DEBUGFS_READ_FILE_OPS(eeprom);
@@ -483,6 +570,7 @@ DEBUGFS_READ_FILE_OPS(rx_statistics);
483DEBUGFS_READ_FILE_OPS(tx_statistics); 570DEBUGFS_READ_FILE_OPS(tx_statistics);
484DEBUGFS_READ_FILE_OPS(channels); 571DEBUGFS_READ_FILE_OPS(channels);
485DEBUGFS_READ_FILE_OPS(status); 572DEBUGFS_READ_FILE_OPS(status);
573DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
486 574
487/* 575/*
488 * Create the debugfs files and directories 576 * Create the debugfs files and directories
@@ -518,6 +606,7 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
518 DEBUGFS_ADD_FILE(tx_statistics, data); 606 DEBUGFS_ADD_FILE(tx_statistics, data);
519 DEBUGFS_ADD_FILE(channels, data); 607 DEBUGFS_ADD_FILE(channels, data);
520 DEBUGFS_ADD_FILE(status, data); 608 DEBUGFS_ADD_FILE(status, data);
609 DEBUGFS_ADD_FILE(interrupt, data);
521 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal); 610 DEBUGFS_ADD_BOOL(disable_sensitivity, rf, &priv->disable_sens_cal);
522 DEBUGFS_ADD_BOOL(disable_chain_noise, rf, 611 DEBUGFS_ADD_BOOL(disable_chain_noise, rf,
523 &priv->disable_chain_noise_cal); 612 &priv->disable_chain_noise_cal);
@@ -548,6 +637,7 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv)
548 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations); 637 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_stations);
549 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels); 638 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_channels);
550 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status); 639 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_status);
640 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_data_files.file_interrupt);
551 DEBUGFS_REMOVE(priv->dbgfs->dir_data); 641 DEBUGFS_REMOVE(priv->dbgfs->dir_data);
552 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity); 642 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_sensitivity);
553 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise); 643 DEBUGFS_REMOVE(priv->dbgfs->dbgfs_rf_files.file_disable_chain_noise);
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index cf7f0db58fc..5aa76a70632 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -70,6 +70,7 @@ extern struct iwl_ops iwl5000_ops;
70extern struct iwl_lib_ops iwl5000_lib; 70extern struct iwl_lib_ops iwl5000_lib;
71extern struct iwl_hcmd_ops iwl5000_hcmd; 71extern struct iwl_hcmd_ops iwl5000_hcmd;
72extern struct iwl_hcmd_utils_ops iwl5000_hcmd_utils; 72extern struct iwl_hcmd_utils_ops iwl5000_hcmd_utils;
73extern struct iwl_station_mgmt_ops iwl5000_station_mgmt;
73 74
74/* shared functions from iwl-5000.c */ 75/* shared functions from iwl-5000.c */
75extern u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len); 76extern u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len);
@@ -822,6 +823,21 @@ enum {
822 MEASUREMENT_ACTIVE = (1 << 1), 823 MEASUREMENT_ACTIVE = (1 << 1),
823}; 824};
824 825
826/* interrupt statistics */
827struct isr_statistics {
828 u32 hw;
829 u32 sw;
830 u32 sw_err;
831 u32 sch;
832 u32 alive;
833 u32 rfkill;
834 u32 ctkill;
835 u32 wakeup;
836 u32 rx;
837 u32 rx_handlers[REPLY_MAX];
838 u32 tx;
839 u32 unhandled;
840};
825 841
826#define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */ 842#define IWL_MAX_NUM_QUEUES 20 /* FIXME: do dynamic allocation */
827 843
@@ -877,9 +893,7 @@ struct iwl_priv {
877 unsigned long scan_start_tsf; 893 unsigned long scan_start_tsf;
878 void *scan; 894 void *scan;
879 int scan_bands; 895 int scan_bands;
880 int one_direct_scan; 896 struct cfg80211_scan_request *scan_request;
881 u8 direct_ssid_len;
882 u8 direct_ssid[IW_ESSID_MAX_SIZE];
883 u8 scan_tx_ant[IEEE80211_NUM_BANDS]; 897 u8 scan_tx_ant[IEEE80211_NUM_BANDS];
884 u8 mgmt_tx_ant; 898 u8 mgmt_tx_ant;
885 899
@@ -978,6 +992,9 @@ struct iwl_priv {
978 u64 bytes; 992 u64 bytes;
979 } tx_stats[3], rx_stats[3]; 993 } tx_stats[3], rx_stats[3];
980 994
995 /* counts interrupts */
996 struct isr_statistics isr_stats;
997
981 struct iwl_power_mgr power_data; 998 struct iwl_power_mgr power_data;
982 999
983 struct iwl_notif_statistics statistics; 1000 struct iwl_notif_statistics statistics;
diff --git a/drivers/net/wireless/iwlwifi/iwl-rfkill.c b/drivers/net/wireless/iwlwifi/iwl-rfkill.c
index 2ad9faf1508..65605ad44e4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rfkill.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rfkill.c
@@ -91,7 +91,6 @@ int iwl_rfkill_init(struct iwl_priv *priv)
91 priv->rfkill->data = priv; 91 priv->rfkill->data = priv;
92 priv->rfkill->state = RFKILL_STATE_UNBLOCKED; 92 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
93 priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill; 93 priv->rfkill->toggle_radio = iwl_rfkill_soft_rf_kill;
94 priv->rfkill->user_claim_unsupported = 1;
95 94
96 priv->rfkill->dev.class->suspend = NULL; 95 priv->rfkill->dev.class->suspend = NULL;
97 priv->rfkill->dev.class->resume = NULL; 96 priv->rfkill->dev.class->resume = NULL;
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index 8f65908f66f..fae84262efb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -1102,13 +1102,6 @@ void iwl_rx_reply_rx(struct iwl_priv *priv,
1102 if (rx_start->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) 1102 if (rx_start->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
1103 rx_status.flag |= RX_FLAG_SHORTPRE; 1103 rx_status.flag |= RX_FLAG_SHORTPRE;
1104 1104
1105 /* Take shortcut when only in monitor mode */
1106 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
1107 iwl_pass_packet_to_mac80211(priv, include_phy,
1108 rxb, &rx_status);
1109 return;
1110 }
1111
1112 network_packet = iwl_is_network_packet(priv, header); 1105 network_packet = iwl_is_network_packet(priv, header);
1113 if (network_packet) { 1106 if (network_packet) {
1114 priv->last_rx_rssi = rx_status.signal; 1107 priv->last_rx_rssi = rx_status.signal;
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index 23644cf884f..799f5eb61ec 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -448,13 +448,6 @@ int iwl_mac_hw_scan(struct ieee80211_hw *hw,
448 unsigned long flags; 448 unsigned long flags;
449 struct iwl_priv *priv = hw->priv; 449 struct iwl_priv *priv = hw->priv;
450 int ret; 450 int ret;
451 u8 *ssid = NULL;
452 size_t ssid_len = 0;
453
454 if (req->n_ssids) {
455 ssid = req->ssids[0].ssid;
456 ssid_len = req->ssids[0].ssid_len;
457 }
458 451
459 IWL_DEBUG_MAC80211(priv, "enter\n"); 452 IWL_DEBUG_MAC80211(priv, "enter\n");
460 453
@@ -488,13 +481,7 @@ int iwl_mac_hw_scan(struct ieee80211_hw *hw,
488 goto out_unlock; 481 goto out_unlock;
489 } 482 }
490 483
491 if (ssid_len) { 484 priv->scan_request = req;
492 priv->one_direct_scan = 1;
493 priv->direct_ssid_len = ssid_len;
494 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
495 } else {
496 priv->one_direct_scan = 0;
497 }
498 485
499 ret = iwl_scan_initiate(priv); 486 ret = iwl_scan_initiate(priv);
500 487
@@ -533,73 +520,14 @@ void iwl_bg_scan_check(struct work_struct *data)
533EXPORT_SYMBOL(iwl_bg_scan_check); 520EXPORT_SYMBOL(iwl_bg_scan_check);
534 521
535/** 522/**
536 * iwl_supported_rate_to_ie - fill in the supported rate in IE field
537 *
538 * return : set the bit for each supported rate insert in ie
539 */
540static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate,
541 u16 basic_rate, int *left)
542{
543 u16 ret_rates = 0, bit;
544 int i;
545 u8 *cnt = ie;
546 u8 *rates = ie + 1;
547
548 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
549 if (bit & supported_rate) {
550 ret_rates |= bit;
551 rates[*cnt] = iwl_rates[i].ieee |
552 ((bit & basic_rate) ? 0x80 : 0x00);
553 (*cnt)++;
554 (*left)--;
555 if ((*left <= 0) ||
556 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
557 break;
558 }
559 }
560
561 return ret_rates;
562}
563
564
565static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
566 u8 *pos, int *left)
567{
568 struct ieee80211_ht_cap *ht_cap;
569
570 if (!sband || !sband->ht_cap.ht_supported)
571 return;
572
573 if (*left < sizeof(struct ieee80211_ht_cap))
574 return;
575
576 *pos++ = sizeof(struct ieee80211_ht_cap);
577 ht_cap = (struct ieee80211_ht_cap *) pos;
578
579 ht_cap->cap_info = cpu_to_le16(sband->ht_cap.cap);
580 memcpy(&ht_cap->mcs, &sband->ht_cap.mcs, 16);
581 ht_cap->ampdu_params_info =
582 (sband->ht_cap.ampdu_factor & IEEE80211_HT_AMPDU_PARM_FACTOR) |
583 ((sband->ht_cap.ampdu_density << 2) &
584 IEEE80211_HT_AMPDU_PARM_DENSITY);
585 *left -= sizeof(struct ieee80211_ht_cap);
586}
587
588/**
589 * iwl_fill_probe_req - fill in all required fields and IE for probe request 523 * iwl_fill_probe_req - fill in all required fields and IE for probe request
590 */ 524 */
591 525
592u16 iwl_fill_probe_req(struct iwl_priv *priv, 526u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
593 enum ieee80211_band band, 527 const u8 *ies, int ie_len, int left)
594 struct ieee80211_mgmt *frame,
595 int left)
596{ 528{
597 int len = 0; 529 int len = 0;
598 u8 *pos = NULL; 530 u8 *pos = NULL;
599 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
600 const struct ieee80211_supported_band *sband =
601 iwl_get_hw_mode(priv, band);
602
603 531
604 /* Make sure there is enough space for the probe request, 532 /* Make sure there is enough space for the probe request,
605 * two mandatory IEs and the data */ 533 * two mandatory IEs and the data */
@@ -627,62 +555,12 @@ u16 iwl_fill_probe_req(struct iwl_priv *priv,
627 555
628 len += 2; 556 len += 2;
629 557
630 /* fill in supported rate */ 558 if (WARN_ON(left < ie_len))
631 left -= 2; 559 return len;
632 if (left < 0)
633 return 0;
634
635 *pos++ = WLAN_EID_SUPP_RATES;
636 *pos = 0;
637
638 /* exclude 60M rate */
639 active_rates = priv->rates_mask;
640 active_rates &= ~IWL_RATE_60M_MASK;
641
642 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
643
644 cck_rates = IWL_CCK_RATES_MASK & active_rates;
645 ret_rates = iwl_supported_rate_to_ie(pos, cck_rates,
646 active_rate_basic, &left);
647 active_rates &= ~ret_rates;
648
649 ret_rates = iwl_supported_rate_to_ie(pos, active_rates,
650 active_rate_basic, &left);
651 active_rates &= ~ret_rates;
652
653 len += 2 + *pos;
654 pos += (*pos) + 1;
655 560
656 if (active_rates == 0) 561 memcpy(pos, ies, ie_len);
657 goto fill_end; 562 len += ie_len;
658 563 left -= ie_len;
659 /* fill in supported extended rate */
660 /* ...next IE... */
661 left -= 2;
662 if (left < 0)
663 return 0;
664 /* ... fill it in... */
665 *pos++ = WLAN_EID_EXT_SUPP_RATES;
666 *pos = 0;
667 iwl_supported_rate_to_ie(pos, active_rates, active_rate_basic, &left);
668 if (*pos > 0) {
669 len += 2 + *pos;
670 pos += (*pos) + 1;
671 } else {
672 pos--;
673 }
674
675 fill_end:
676
677 left -= 2;
678 if (left < 0)
679 return 0;
680
681 *pos++ = WLAN_EID_HT_CAPABILITY;
682 *pos = 0;
683 iwl_ht_cap_to_ie(sband, pos, &left);
684 if (*pos > 0)
685 len += 2 + *pos;
686 564
687 return (u16)len; 565 return (u16)len;
688} 566}
@@ -703,10 +581,10 @@ static void iwl_bg_request_scan(struct work_struct *data)
703 u32 rate_flags = 0; 581 u32 rate_flags = 0;
704 u16 cmd_len; 582 u16 cmd_len;
705 enum ieee80211_band band; 583 enum ieee80211_band band;
706 u8 n_probes = 2; 584 u8 n_probes = 0;
707 u8 rx_chain = priv->hw_params.valid_rx_ant; 585 u8 rx_chain = priv->hw_params.valid_rx_ant;
708 u8 rate; 586 u8 rate;
709 DECLARE_SSID_BUF(ssid); 587 bool is_active = false;
710 588
711 conf = ieee80211_get_hw_conf(priv->hw); 589 conf = ieee80211_get_hw_conf(priv->hw);
712 590
@@ -796,19 +674,25 @@ static void iwl_bg_request_scan(struct work_struct *data)
796 scan_suspend_time, interval); 674 scan_suspend_time, interval);
797 } 675 }
798 676
799 /* We should add the ability for user to lock to PASSIVE ONLY */ 677 if (priv->scan_request->n_ssids) {
800 if (priv->one_direct_scan) { 678 int i, p = 0;
801 IWL_DEBUG_SCAN(priv, "Start direct scan for '%s'\n", 679 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
802 print_ssid(ssid, priv->direct_ssid, 680 for (i = 0; i < priv->scan_request->n_ssids; i++) {
803 priv->direct_ssid_len)); 681 /* always does wildcard anyway */
804 scan->direct_scan[0].id = WLAN_EID_SSID; 682 if (!priv->scan_request->ssids[i].ssid_len)
805 scan->direct_scan[0].len = priv->direct_ssid_len; 683 continue;
806 memcpy(scan->direct_scan[0].ssid, 684 scan->direct_scan[p].id = WLAN_EID_SSID;
807 priv->direct_ssid, priv->direct_ssid_len); 685 scan->direct_scan[p].len =
808 n_probes++; 686 priv->scan_request->ssids[i].ssid_len;
809 } else { 687 memcpy(scan->direct_scan[p].ssid,
810 IWL_DEBUG_SCAN(priv, "Start indirect scan.\n"); 688 priv->scan_request->ssids[i].ssid,
811 } 689 priv->scan_request->ssids[i].ssid_len);
690 n_probes++;
691 p++;
692 }
693 is_active = true;
694 } else
695 IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
812 696
813 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; 697 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
814 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; 698 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
@@ -828,7 +712,12 @@ static void iwl_bg_request_scan(struct work_struct *data)
828 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { 712 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
829 band = IEEE80211_BAND_5GHZ; 713 band = IEEE80211_BAND_5GHZ;
830 rate = IWL_RATE_6M_PLCP; 714 rate = IWL_RATE_6M_PLCP;
831 scan->good_CRC_th = IWL_GOOD_CRC_TH; 715 /*
716 * If active scaning is requested but a certain channel
717 * is marked passive, we can do active scanning if we
718 * detect transmissions.
719 */
720 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH : 0;
832 721
833 /* Force use of chains B and C (0x6) for scan Rx for 4965 722 /* Force use of chains B and C (0x6) for scan Rx for 4965
834 * Avoid A (0x1) because of its off-channel reception on A-band. 723 * Avoid A (0x1) because of its off-channel reception on A-band.
@@ -850,22 +739,22 @@ static void iwl_bg_request_scan(struct work_struct *data)
850 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | 739 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
851 (rx_chain << RXON_RX_CHAIN_FORCE_SEL_POS) | 740 (rx_chain << RXON_RX_CHAIN_FORCE_SEL_POS) |
852 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); 741 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
853 742 cmd_len = iwl_fill_probe_req(priv,
854 cmd_len = iwl_fill_probe_req(priv, band, 743 (struct ieee80211_mgmt *)scan->data,
855 (struct ieee80211_mgmt *)scan->data, 744 priv->scan_request->ie,
856 IWL_MAX_SCAN_SIZE - sizeof(*scan)); 745 priv->scan_request->ie_len,
746 IWL_MAX_SCAN_SIZE - sizeof(*scan));
857 747
858 scan->tx_cmd.len = cpu_to_le16(cmd_len); 748 scan->tx_cmd.len = cpu_to_le16(cmd_len);
859 749
860 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) 750 if (iwl_is_monitor_mode(priv))
861 scan->filter_flags = RXON_FILTER_PROMISC_MSK; 751 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
862 752
863 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | 753 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
864 RXON_FILTER_BCON_AWARE_MSK); 754 RXON_FILTER_BCON_AWARE_MSK);
865 755
866 scan->channel_count = 756 scan->channel_count =
867 iwl_get_channels_for_scan(priv, band, 1, /* active */ 757 iwl_get_channels_for_scan(priv, band, is_active, n_probes,
868 n_probes,
869 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 758 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
870 759
871 if (scan->channel_count == 0) { 760 if (scan->channel_count == 0) {
@@ -928,6 +817,7 @@ void iwl_bg_scan_completed(struct work_struct *work)
928 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 817 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
929 return; 818 return;
930 819
820 priv->scan_request = NULL;
931 ieee80211_scan_completed(priv->hw, false); 821 ieee80211_scan_completed(priv->hw, false);
932 822
933 /* Since setting the TXPOWER may have been deferred while 823 /* Since setting the TXPOWER may have been deferred while
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 5798fe49c77..17a4dd2be1f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -75,7 +75,7 @@ int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
75 return IWL_AP_ID; 75 return IWL_AP_ID;
76 } else { 76 } else {
77 u8 *da = ieee80211_get_DA(hdr); 77 u8 *da = ieee80211_get_DA(hdr);
78 return iwl_find_station(priv, da); 78 return priv->cfg->ops->smgmt->find_station(priv, da);
79 } 79 }
80} 80}
81EXPORT_SYMBOL(iwl_get_ra_sta_id); 81EXPORT_SYMBOL(iwl_get_ra_sta_id);
@@ -300,7 +300,7 @@ EXPORT_SYMBOL(iwl_add_station_flags);
300static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr) 300static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
301{ 301{
302 unsigned long flags; 302 unsigned long flags;
303 u8 sta_id = iwl_find_station(priv, addr); 303 u8 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
304 304
305 BUG_ON(sta_id == IWL_INVALID_STATION); 305 BUG_ON(sta_id == IWL_INVALID_STATION);
306 306
@@ -758,7 +758,7 @@ void iwl_update_tkip_key(struct iwl_priv *priv,
758 int i; 758 int i;
759 DECLARE_MAC_BUF(mac); 759 DECLARE_MAC_BUF(mac);
760 760
761 sta_id = iwl_find_station(priv, addr); 761 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
762 if (sta_id == IWL_INVALID_STATION) { 762 if (sta_id == IWL_INVALID_STATION) {
763 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", 763 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
764 addr); 764 addr);
@@ -1019,7 +1019,7 @@ int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
1019 rcu_read_unlock(); 1019 rcu_read_unlock();
1020 } 1020 }
1021 1021
1022 sta_id = iwl_add_station_flags(priv, addr, is_ap, 1022 sta_id = priv->cfg->ops->smgmt->add_station(priv, addr, is_ap,
1023 0, cur_ht_config); 1023 0, cur_ht_config);
1024 1024
1025 /* Set up default rate scaling table in device's station table */ 1025 /* Set up default rate scaling table in device's station table */
@@ -1053,7 +1053,7 @@ int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1053 1053
1054 /* If we are an AP, then find the station, or use BCAST */ 1054 /* If we are an AP, then find the station, or use BCAST */
1055 case NL80211_IFTYPE_AP: 1055 case NL80211_IFTYPE_AP:
1056 sta_id = iwl_find_station(priv, hdr->addr1); 1056 sta_id = priv->cfg->ops->smgmt->find_station(priv, hdr->addr1);
1057 if (sta_id != IWL_INVALID_STATION) 1057 if (sta_id != IWL_INVALID_STATION)
1058 return sta_id; 1058 return sta_id;
1059 return priv->hw_params.bcast_sta_id; 1059 return priv->hw_params.bcast_sta_id;
@@ -1061,12 +1061,12 @@ int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1061 /* If this frame is going out to an IBSS network, find the station, 1061 /* If this frame is going out to an IBSS network, find the station,
1062 * or create a new station table entry */ 1062 * or create a new station table entry */
1063 case NL80211_IFTYPE_ADHOC: 1063 case NL80211_IFTYPE_ADHOC:
1064 sta_id = iwl_find_station(priv, hdr->addr1); 1064 sta_id = priv->cfg->ops->smgmt->find_station(priv, hdr->addr1);
1065 if (sta_id != IWL_INVALID_STATION) 1065 if (sta_id != IWL_INVALID_STATION)
1066 return sta_id; 1066 return sta_id;
1067 1067
1068 /* Create new station table entry */ 1068 /* Create new station table entry */
1069 sta_id = iwl_add_station_flags(priv, hdr->addr1, 1069 sta_id = priv->cfg->ops->smgmt->add_station(priv, hdr->addr1,
1070 0, CMD_ASYNC, NULL); 1070 0, CMD_ASYNC, NULL);
1071 1071
1072 if (sta_id != IWL_INVALID_STATION) 1072 if (sta_id != IWL_INVALID_STATION)
@@ -1078,11 +1078,6 @@ int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1078 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); 1078 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
1079 return priv->hw_params.bcast_sta_id; 1079 return priv->hw_params.bcast_sta_id;
1080 1080
1081 /* If we are in monitor mode, use BCAST. This is required for
1082 * packet injection. */
1083 case NL80211_IFTYPE_MONITOR:
1084 return priv->hw_params.bcast_sta_id;
1085
1086 default: 1081 default:
1087 IWL_WARN(priv, "Unknown mode of operation: %d\n", 1082 IWL_WARN(priv, "Unknown mode of operation: %d\n",
1088 priv->iw_mode); 1083 priv->iw_mode);
@@ -1115,7 +1110,7 @@ int iwl_sta_rx_agg_start(struct iwl_priv *priv,
1115 unsigned long flags; 1110 unsigned long flags;
1116 int sta_id; 1111 int sta_id;
1117 1112
1118 sta_id = iwl_find_station(priv, addr); 1113 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
1119 if (sta_id == IWL_INVALID_STATION) 1114 if (sta_id == IWL_INVALID_STATION)
1120 return -ENXIO; 1115 return -ENXIO;
1121 1116
@@ -1137,7 +1132,7 @@ int iwl_sta_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid)
1137 unsigned long flags; 1132 unsigned long flags;
1138 int sta_id; 1133 int sta_id;
1139 1134
1140 sta_id = iwl_find_station(priv, addr); 1135 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
1141 if (sta_id == IWL_INVALID_STATION) { 1136 if (sta_id == IWL_INVALID_STATION) {
1142 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); 1137 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
1143 return -ENXIO; 1138 return -ENXIO;
@@ -1172,7 +1167,7 @@ static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1172void iwl_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr) 1167void iwl_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
1173{ 1168{
1174 /* FIXME: need locking over ps_status ??? */ 1169 /* FIXME: need locking over ps_status ??? */
1175 u8 sta_id = iwl_find_station(priv, addr); 1170 u8 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
1176 1171
1177 if (sta_id != IWL_INVALID_STATION) { 1172 if (sta_id != IWL_INVALID_STATION) {
1178 u8 sta_awake = priv->stations[sta_id]. 1173 u8 sta_awake = priv->stations[sta_id].
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index 71d5b8a1a73..a82cca0a30c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -728,7 +728,7 @@ int iwl_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
728 728
729 /* drop all data frame if we are not associated */ 729 /* drop all data frame if we are not associated */
730 if (ieee80211_is_data(fc) && 730 if (ieee80211_is_data(fc) &&
731 (priv->iw_mode != NL80211_IFTYPE_MONITOR || 731 (!iwl_is_monitor_mode(priv) ||
732 !(info->flags & IEEE80211_TX_CTL_INJECTED)) && /* packet injection */ 732 !(info->flags & IEEE80211_TX_CTL_INJECTED)) && /* packet injection */
733 (!iwl_is_associated(priv) || 733 (!iwl_is_associated(priv) ||
734 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id) || 734 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id) ||
@@ -1183,8 +1183,10 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1183 __func__, ra, tid); 1183 __func__, ra, tid);
1184 1184
1185 sta_id = iwl_find_station(priv, ra); 1185 sta_id = iwl_find_station(priv, ra);
1186 if (sta_id == IWL_INVALID_STATION) 1186 if (sta_id == IWL_INVALID_STATION) {
1187 IWL_ERR(priv, "Start AGG on invalid station\n");
1187 return -ENXIO; 1188 return -ENXIO;
1189 }
1188 1190
1189 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) { 1191 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
1190 IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n"); 1192 IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n");
@@ -1192,8 +1194,10 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1192 } 1194 }
1193 1195
1194 txq_id = iwl_txq_ctx_activate_free(priv); 1196 txq_id = iwl_txq_ctx_activate_free(priv);
1195 if (txq_id == -1) 1197 if (txq_id == -1) {
1198 IWL_ERR(priv, "No free aggregation queue available\n");
1196 return -ENXIO; 1199 return -ENXIO;
1200 }
1197 1201
1198 spin_lock_irqsave(&priv->sta_lock, flags); 1202 spin_lock_irqsave(&priv->sta_lock, flags);
1199 tid_data = &priv->stations[sta_id].tid[tid]; 1203 tid_data = &priv->stations[sta_id].tid[tid];
@@ -1207,7 +1211,7 @@ int iwl_tx_agg_start(struct iwl_priv *priv, const u8 *ra, u16 tid, u16 *ssn)
1207 return ret; 1211 return ret;
1208 1212
1209 if (tid_data->tfds_in_queue == 0) { 1213 if (tid_data->tfds_in_queue == 0) {
1210 IWL_ERR(priv, "HW queue is empty\n"); 1214 IWL_DEBUG_HT(priv, "HW queue is empty\n");
1211 tid_data->agg.state = IWL_AGG_ON; 1215 tid_data->agg.state = IWL_AGG_ON;
1212 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, ra, tid); 1216 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, ra, tid);
1213 } else { 1217 } else {
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 617c4235d97..84feeb70fea 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -149,7 +149,7 @@ out:
149 * 149 *
150 * NOTE: This does not clear or otherwise alter the device's station table. 150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */ 151 */
152static void iwl3945_clear_stations_table(struct iwl_priv *priv) 152void iwl3945_clear_stations_table(struct iwl_priv *priv)
153{ 153{
154 unsigned long flags; 154 unsigned long flags;
155 155
@@ -164,7 +164,7 @@ static void iwl3945_clear_stations_table(struct iwl_priv *priv)
164/** 164/**
165 * iwl3945_add_station - Add station to station tables in driver and device 165 * iwl3945_add_station - Add station to station tables in driver and device
166 */ 166 */
167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) 167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags, struct ieee80211_sta_ht_cap *ht_info)
168{ 168{
169 int i; 169 int i;
170 int index = IWL_INVALID_STATION; 170 int index = IWL_INVALID_STATION;
@@ -233,50 +233,6 @@ u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flag
233 233
234} 234}
235 235
236static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
237{
238 int rc = 0;
239 struct iwl_rx_packet *res = NULL;
240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
241 struct iwl_host_cmd cmd = {
242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
245 .data = &rxon_assoc,
246 };
247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
249
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
255 return 0;
256 }
257
258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
262 rxon_assoc.reserved = 0;
263
264 rc = iwl_send_cmd_sync(priv, &cmd);
265 if (rc)
266 return rc;
267
268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
271 rc = -EIO;
272 }
273
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
276
277 return rc;
278}
279
280/** 236/**
281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command 237 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags 238 * @priv: eeprom and antenna fields are used to determine antenna flags
@@ -314,150 +270,6 @@ __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
314 return 0; /* "diversity" is default if error */ 270 return 0; /* "diversity" is default if error */
315} 271}
316 272
317/**
318 * iwl3945_commit_rxon - commit staging_rxon to hardware
319 *
320 * The RXON command in staging_rxon is committed to the hardware and
321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
324 */
325static int iwl3945_commit_rxon(struct iwl_priv *priv)
326{
327 /* cast away the const for active_rxon in this function */
328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
330 int rc = 0;
331 bool new_assoc =
332 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
333
334 if (!iwl_is_alive(priv))
335 return -1;
336
337 /* always get timestamp with Rx frame */
338 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
339
340 /* select antenna */
341 staging_rxon->flags &=
342 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
343 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
344
345 rc = iwl_check_rxon_cmd(priv);
346 if (rc) {
347 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
348 return -EINVAL;
349 }
350
351 /* If we don't need to send a full RXON, we can use
352 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
353 * and other flags for the current radio configuration. */
354 if (!iwl_full_rxon_required(priv)) {
355 rc = iwl3945_send_rxon_assoc(priv);
356 if (rc) {
357 IWL_ERR(priv, "Error setting RXON_ASSOC "
358 "configuration (%d).\n", rc);
359 return rc;
360 }
361
362 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
363
364 return 0;
365 }
366
367 /* If we are currently associated and the new config requires
368 * an RXON_ASSOC and the new config wants the associated mask enabled,
369 * we must clear the associated from the active configuration
370 * before we apply the new config */
371 if (iwl_is_associated(priv) && new_assoc) {
372 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
373 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
374
375 /*
376 * reserved4 and 5 could have been filled by the iwlcore code.
377 * Let's clear them before pushing to the 3945.
378 */
379 active_rxon->reserved4 = 0;
380 active_rxon->reserved5 = 0;
381 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
382 sizeof(struct iwl3945_rxon_cmd),
383 &priv->active_rxon);
384
385 /* If the mask clearing failed then we set
386 * active_rxon back to what it was previously */
387 if (rc) {
388 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
389 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
390 "configuration (%d).\n", rc);
391 return rc;
392 }
393 }
394
395 IWL_DEBUG_INFO(priv, "Sending RXON\n"
396 "* with%s RXON_FILTER_ASSOC_MSK\n"
397 "* channel = %d\n"
398 "* bssid = %pM\n",
399 (new_assoc ? "" : "out"),
400 le16_to_cpu(staging_rxon->channel),
401 staging_rxon->bssid_addr);
402
403 /*
404 * reserved4 and 5 could have been filled by the iwlcore code.
405 * Let's clear them before pushing to the 3945.
406 */
407 staging_rxon->reserved4 = 0;
408 staging_rxon->reserved5 = 0;
409
410 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
411
412 /* Apply the new configuration */
413 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
414 sizeof(struct iwl3945_rxon_cmd),
415 staging_rxon);
416 if (rc) {
417 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
418 return rc;
419 }
420
421 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
422
423 iwl3945_clear_stations_table(priv);
424
425 /* If we issue a new RXON command which required a tune then we must
426 * send a new TXPOWER command or we won't be able to Tx any frames */
427 rc = priv->cfg->ops->lib->send_tx_power(priv);
428 if (rc) {
429 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
430 return rc;
431 }
432
433 /* Add the broadcast address so we can send broadcast frames */
434 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
435 IWL_INVALID_STATION) {
436 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
437 return -EIO;
438 }
439
440 /* If we have set the ASSOC_MSK and we are in BSS mode then
441 * add the IWL_AP_ID to the station rate table */
442 if (iwl_is_associated(priv) &&
443 (priv->iw_mode == NL80211_IFTYPE_STATION))
444 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
445 1, 0)
446 == IWL_INVALID_STATION) {
447 IWL_ERR(priv, "Error adding AP address for transmit\n");
448 return -EIO;
449 }
450
451 /* Init the hardware's rate fallback order based on the band */
452 rc = iwl3945_init_hw_rate_table(priv);
453 if (rc) {
454 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
455 return -EIO;
456 }
457
458 return 0;
459}
460
461static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv, 273static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
462 struct ieee80211_key_conf *keyconf, 274 struct ieee80211_key_conf *keyconf,
463 u8 sta_id) 275 u8 sta_id)
@@ -758,42 +570,6 @@ static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
758 le16_to_cpu(priv->rxon_timing.atim_window)); 570 le16_to_cpu(priv->rxon_timing.atim_window));
759} 571}
760 572
761static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
762{
763 if (mode == NL80211_IFTYPE_ADHOC) {
764 const struct iwl_channel_info *ch_info;
765
766 ch_info = iwl_get_channel_info(priv,
767 priv->band,
768 le16_to_cpu(priv->staging_rxon.channel));
769
770 if (!ch_info || !is_channel_ibss(ch_info)) {
771 IWL_ERR(priv, "channel %d not IBSS channel\n",
772 le16_to_cpu(priv->staging_rxon.channel));
773 return -EINVAL;
774 }
775 }
776
777 iwl_connection_init_rx_config(priv, mode);
778
779 iwl3945_clear_stations_table(priv);
780
781 /* don't commit rxon if rf-kill is on*/
782 if (!iwl_is_ready_rf(priv))
783 return -EAGAIN;
784
785 cancel_delayed_work(&priv->scan_check);
786 if (iwl_scan_cancel_timeout(priv, 100)) {
787 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
788 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
789 return -EAGAIN;
790 }
791
792 iwl3945_commit_rxon(priv);
793
794 return 0;
795}
796
797static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, 573static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
798 struct ieee80211_tx_info *info, 574 struct ieee80211_tx_info *info,
799 struct iwl_cmd *cmd, 575 struct iwl_cmd *cmd,
@@ -900,64 +676,6 @@ static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
900 tx->next_frame_len = 0; 676 tx->next_frame_len = 0;
901} 677}
902 678
903/**
904 * iwl3945_get_sta_id - Find station's index within station table
905 */
906static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
907{
908 int sta_id;
909 u16 fc = le16_to_cpu(hdr->frame_control);
910
911 /* If this frame is broadcast or management, use broadcast station id */
912 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
913 is_multicast_ether_addr(hdr->addr1))
914 return priv->hw_params.bcast_sta_id;
915
916 switch (priv->iw_mode) {
917
918 /* If we are a client station in a BSS network, use the special
919 * AP station entry (that's the only station we communicate with) */
920 case NL80211_IFTYPE_STATION:
921 return IWL_AP_ID;
922
923 /* If we are an AP, then find the station, or use BCAST */
924 case NL80211_IFTYPE_AP:
925 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
926 if (sta_id != IWL_INVALID_STATION)
927 return sta_id;
928 return priv->hw_params.bcast_sta_id;
929
930 /* If this frame is going out to an IBSS network, find the station,
931 * or create a new station table entry */
932 case NL80211_IFTYPE_ADHOC: {
933 /* Create new station table entry */
934 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
935 if (sta_id != IWL_INVALID_STATION)
936 return sta_id;
937
938 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
939
940 if (sta_id != IWL_INVALID_STATION)
941 return sta_id;
942
943 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
944 "Defaulting to broadcast...\n",
945 hdr->addr1);
946 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
947 return priv->hw_params.bcast_sta_id;
948 }
949 /* If we are in monitor mode, use BCAST. This is required for
950 * packet injection. */
951 case NL80211_IFTYPE_MONITOR:
952 return priv->hw_params.bcast_sta_id;
953
954 default:
955 IWL_WARN(priv, "Unknown mode of operation: %d\n",
956 priv->iw_mode);
957 return priv->hw_params.bcast_sta_id;
958 }
959}
960
961/* 679/*
962 * start REPLY_TX command process 680 * start REPLY_TX command process
963 */ 681 */
@@ -1011,7 +729,7 @@ static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
1011 729
1012 /* drop all data frame if we are not associated */ 730 /* drop all data frame if we are not associated */
1013 if (ieee80211_is_data(fc) && 731 if (ieee80211_is_data(fc) &&
1014 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */ 732 (!iwl_is_monitor_mode(priv)) && /* packet injection */
1015 (!iwl_is_associated(priv) || 733 (!iwl_is_associated(priv) ||
1016 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) { 734 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
1017 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n"); 735 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
@@ -1023,7 +741,7 @@ static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
1023 hdr_len = ieee80211_hdrlen(fc); 741 hdr_len = ieee80211_hdrlen(fc);
1024 742
1025 /* Find (or create) index into station table for destination station */ 743 /* Find (or create) index into station table for destination station */
1026 sta_id = iwl3945_get_sta_id(priv, hdr); 744 sta_id = iwl_get_sta_id(priv, hdr);
1027 if (sta_id == IWL_INVALID_STATION) { 745 if (sta_id == IWL_INVALID_STATION) {
1028 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n", 746 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
1029 hdr->addr1); 747 hdr->addr1);
@@ -1888,6 +1606,7 @@ static void iwl3945_rx_handle(struct iwl_priv *priv)
1888 "r = %d, i = %d, %s, 0x%02x\n", r, i, 1606 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1889 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); 1607 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1890 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); 1608 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1609 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
1891 } else { 1610 } else {
1892 /* No handling needed */ 1611 /* No handling needed */
1893 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, 1612 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
@@ -2129,9 +1848,9 @@ static void iwl3945_error_recovery(struct iwl_priv *priv)
2129 memcpy(&priv->staging_rxon, &priv->recovery_rxon, 1848 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2130 sizeof(priv->staging_rxon)); 1849 sizeof(priv->staging_rxon));
2131 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 1850 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2132 iwl3945_commit_rxon(priv); 1851 iwlcore_commit_rxon(priv);
2133 1852
2134 iwl3945_add_station(priv, priv->bssid, 1, 0); 1853 priv->cfg->ops->smgmt->add_station(priv, priv->bssid, 1, 0, NULL);
2135 1854
2136 spin_lock_irqsave(&priv->lock, flags); 1855 spin_lock_irqsave(&priv->lock, flags);
2137 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); 1856 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
@@ -2187,6 +1906,7 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2187 /* Tell the device to stop sending interrupts */ 1906 /* Tell the device to stop sending interrupts */
2188 iwl_disable_interrupts(priv); 1907 iwl_disable_interrupts(priv);
2189 1908
1909 priv->isr_stats.hw++;
2190 iwl_irq_handle_error(priv); 1910 iwl_irq_handle_error(priv);
2191 1911
2192 handled |= CSR_INT_BIT_HW_ERR; 1912 handled |= CSR_INT_BIT_HW_ERR;
@@ -2199,13 +1919,17 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2199#ifdef CONFIG_IWLWIFI_DEBUG 1919#ifdef CONFIG_IWLWIFI_DEBUG
2200 if (priv->debug_level & (IWL_DL_ISR)) { 1920 if (priv->debug_level & (IWL_DL_ISR)) {
2201 /* NIC fires this, but we don't use it, redundant with WAKEUP */ 1921 /* NIC fires this, but we don't use it, redundant with WAKEUP */
2202 if (inta & CSR_INT_BIT_SCD) 1922 if (inta & CSR_INT_BIT_SCD) {
2203 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit " 1923 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
2204 "the frame/frames.\n"); 1924 "the frame/frames.\n");
1925 priv->isr_stats.sch++;
1926 }
2205 1927
2206 /* Alive notification via Rx interrupt will do the real work */ 1928 /* Alive notification via Rx interrupt will do the real work */
2207 if (inta & CSR_INT_BIT_ALIVE) 1929 if (inta & CSR_INT_BIT_ALIVE) {
2208 IWL_DEBUG_ISR(priv, "Alive interrupt\n"); 1930 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1931 priv->isr_stats.alive++;
1932 }
2209 } 1933 }
2210#endif 1934#endif
2211 /* Safely ignore these bits for debug checks below */ 1935 /* Safely ignore these bits for debug checks below */
@@ -2215,6 +1939,8 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2215 if (inta & CSR_INT_BIT_SW_ERR) { 1939 if (inta & CSR_INT_BIT_SW_ERR) {
2216 IWL_ERR(priv, "Microcode SW error detected. " 1940 IWL_ERR(priv, "Microcode SW error detected. "
2217 "Restarting 0x%X.\n", inta); 1941 "Restarting 0x%X.\n", inta);
1942 priv->isr_stats.sw++;
1943 priv->isr_stats.sw_err = inta;
2218 iwl_irq_handle_error(priv); 1944 iwl_irq_handle_error(priv);
2219 handled |= CSR_INT_BIT_SW_ERR; 1945 handled |= CSR_INT_BIT_SW_ERR;
2220 } 1946 }
@@ -2230,6 +1956,7 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2230 iwl_txq_update_write_ptr(priv, &priv->txq[4]); 1956 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2231 iwl_txq_update_write_ptr(priv, &priv->txq[5]); 1957 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
2232 1958
1959 priv->isr_stats.wakeup++;
2233 handled |= CSR_INT_BIT_WAKEUP; 1960 handled |= CSR_INT_BIT_WAKEUP;
2234 } 1961 }
2235 1962
@@ -2238,11 +1965,13 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2238 * notifications from uCode come through here*/ 1965 * notifications from uCode come through here*/
2239 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { 1966 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
2240 iwl3945_rx_handle(priv); 1967 iwl3945_rx_handle(priv);
1968 priv->isr_stats.rx++;
2241 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); 1969 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2242 } 1970 }
2243 1971
2244 if (inta & CSR_INT_BIT_FH_TX) { 1972 if (inta & CSR_INT_BIT_FH_TX) {
2245 IWL_DEBUG_ISR(priv, "Tx interrupt\n"); 1973 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
1974 priv->isr_stats.tx++;
2246 1975
2247 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); 1976 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2248 if (!iwl_grab_nic_access(priv)) { 1977 if (!iwl_grab_nic_access(priv)) {
@@ -2253,8 +1982,10 @@ static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2253 handled |= CSR_INT_BIT_FH_TX; 1982 handled |= CSR_INT_BIT_FH_TX;
2254 } 1983 }
2255 1984
2256 if (inta & ~handled) 1985 if (inta & ~handled) {
2257 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); 1986 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1987 priv->isr_stats.unhandled++;
1988 }
2258 1989
2259 if (inta & ~CSR_INI_SET_MASK) { 1990 if (inta & ~CSR_INI_SET_MASK) {
2260 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", 1991 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
@@ -2896,11 +2627,6 @@ static void iwl3945_init_alive_start(struct iwl_priv *priv)
2896 queue_work(priv->workqueue, &priv->restart); 2627 queue_work(priv->workqueue, &priv->restart);
2897} 2628}
2898 2629
2899
2900/* temporary */
2901static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2902 struct sk_buff *skb);
2903
2904/** 2630/**
2905 * iwl3945_alive_start - called after REPLY_ALIVE notification received 2631 * iwl3945_alive_start - called after REPLY_ALIVE notification received
2906 * from protocol/runtime uCode (initialization uCode's 2632 * from protocol/runtime uCode (initialization uCode's
@@ -2931,7 +2657,7 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2931 goto restart; 2657 goto restart;
2932 } 2658 }
2933 2659
2934 iwl3945_clear_stations_table(priv); 2660 priv->cfg->ops->smgmt->clear_station_table(priv);
2935 2661
2936 rc = iwl_grab_nic_access(priv); 2662 rc = iwl_grab_nic_access(priv);
2937 if (rc) { 2663 if (rc) {
@@ -2990,7 +2716,7 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2990 iwl_send_bt_config(priv); 2716 iwl_send_bt_config(priv);
2991 2717
2992 /* Configure the adapter for unassociated operation */ 2718 /* Configure the adapter for unassociated operation */
2993 iwl3945_commit_rxon(priv); 2719 iwlcore_commit_rxon(priv);
2994 2720
2995 iwl3945_reg_txpower_periodic(priv); 2721 iwl3945_reg_txpower_periodic(priv);
2996 2722
@@ -3008,9 +2734,12 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
3008 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw, 2734 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3009 priv->vif); 2735 priv->vif);
3010 if (beacon) 2736 if (beacon)
3011 iwl3945_mac_beacon_update(priv->hw, beacon); 2737 iwl_mac_beacon_update(priv->hw, beacon);
3012 } 2738 }
3013 2739
2740 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2741 iwl_set_mode(priv, priv->iw_mode);
2742
3014 return; 2743 return;
3015 2744
3016 restart: 2745 restart:
@@ -3033,7 +2762,7 @@ static void __iwl3945_down(struct iwl_priv *priv)
3033 set_bit(STATUS_EXIT_PENDING, &priv->status); 2762 set_bit(STATUS_EXIT_PENDING, &priv->status);
3034 2763
3035 iwl3945_led_unregister(priv); 2764 iwl3945_led_unregister(priv);
3036 iwl3945_clear_stations_table(priv); 2765 priv->cfg->ops->smgmt->clear_station_table(priv);
3037 2766
3038 /* Unblock any waiting calls */ 2767 /* Unblock any waiting calls */
3039 wake_up_interruptible_all(&priv->wait_command_queue); 2768 wake_up_interruptible_all(&priv->wait_command_queue);
@@ -3056,7 +2785,7 @@ static void __iwl3945_down(struct iwl_priv *priv)
3056 ieee80211_stop_queues(priv->hw); 2785 ieee80211_stop_queues(priv->hw);
3057 2786
3058 /* If we have not previously called iwl3945_init() then 2787 /* If we have not previously called iwl3945_init() then
3059 * clear all bits but the RF Kill and SUSPEND bits and return */ 2788 * clear all bits but the RF Kill bits and return */
3060 if (!iwl_is_init(priv)) { 2789 if (!iwl_is_init(priv)) {
3061 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << 2790 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3062 STATUS_RF_KILL_HW | 2791 STATUS_RF_KILL_HW |
@@ -3064,23 +2793,19 @@ static void __iwl3945_down(struct iwl_priv *priv)
3064 STATUS_RF_KILL_SW | 2793 STATUS_RF_KILL_SW |
3065 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 2794 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3066 STATUS_GEO_CONFIGURED | 2795 STATUS_GEO_CONFIGURED |
3067 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3068 STATUS_IN_SUSPEND |
3069 test_bit(STATUS_EXIT_PENDING, &priv->status) << 2796 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3070 STATUS_EXIT_PENDING; 2797 STATUS_EXIT_PENDING;
3071 goto exit; 2798 goto exit;
3072 } 2799 }
3073 2800
3074 /* ...otherwise clear out all the status bits but the RF Kill and 2801 /* ...otherwise clear out all the status bits but the RF Kill
3075 * SUSPEND bits and continue taking the NIC down. */ 2802 * bits and continue taking the NIC down. */
3076 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << 2803 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3077 STATUS_RF_KILL_HW | 2804 STATUS_RF_KILL_HW |
3078 test_bit(STATUS_RF_KILL_SW, &priv->status) << 2805 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3079 STATUS_RF_KILL_SW | 2806 STATUS_RF_KILL_SW |
3080 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 2807 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3081 STATUS_GEO_CONFIGURED | 2808 STATUS_GEO_CONFIGURED |
3082 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3083 STATUS_IN_SUSPEND |
3084 test_bit(STATUS_FW_ERROR, &priv->status) << 2809 test_bit(STATUS_FW_ERROR, &priv->status) <<
3085 STATUS_FW_ERROR | 2810 STATUS_FW_ERROR |
3086 test_bit(STATUS_EXIT_PENDING, &priv->status) << 2811 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
@@ -3104,7 +2829,7 @@ static void __iwl3945_down(struct iwl_priv *priv)
3104 2829
3105 udelay(5); 2830 udelay(5);
3106 2831
3107 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status)) 2832 if (exit_pending)
3108 priv->cfg->ops->lib->apm_ops.stop(priv); 2833 priv->cfg->ops->lib->apm_ops.stop(priv);
3109 else 2834 else
3110 priv->cfg->ops->lib->apm_ops.reset(priv); 2835 priv->cfg->ops->lib->apm_ops.reset(priv);
@@ -3157,10 +2882,8 @@ static int __iwl3945_up(struct iwl_priv *priv)
3157 clear_bit(STATUS_RF_KILL_HW, &priv->status); 2882 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3158 else { 2883 else {
3159 set_bit(STATUS_RF_KILL_HW, &priv->status); 2884 set_bit(STATUS_RF_KILL_HW, &priv->status);
3160 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { 2885 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
3161 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); 2886 return -ENODEV;
3162 return -ENODEV;
3163 }
3164 } 2887 }
3165 2888
3166 iwl_write32(priv, CSR_INT, 0xFFFFFFFF); 2889 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
@@ -3196,7 +2919,7 @@ static int __iwl3945_up(struct iwl_priv *priv)
3196 2919
3197 for (i = 0; i < MAX_HW_RESTARTS; i++) { 2920 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3198 2921
3199 iwl3945_clear_stations_table(priv); 2922 priv->cfg->ops->smgmt->clear_station_table(priv);
3200 2923
3201 /* load bootstrap state machine, 2924 /* load bootstrap state machine,
3202 * load bootstrap program into processor's memory, 2925 * load bootstrap program into processor's memory,
@@ -3292,9 +3015,9 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
3292 int rc = 0; 3015 int rc = 0;
3293 struct iwl3945_scan_cmd *scan; 3016 struct iwl3945_scan_cmd *scan;
3294 struct ieee80211_conf *conf = NULL; 3017 struct ieee80211_conf *conf = NULL;
3295 u8 n_probes = 2; 3018 u8 n_probes = 0;
3296 enum ieee80211_band band; 3019 enum ieee80211_band band;
3297 DECLARE_SSID_BUF(ssid); 3020 bool is_active = false;
3298 3021
3299 conf = ieee80211_get_hw_conf(priv->hw); 3022 conf = ieee80211_get_hw_conf(priv->hw);
3300 3023
@@ -3393,18 +3116,25 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
3393 scan_suspend_time, interval); 3116 scan_suspend_time, interval);
3394 } 3117 }
3395 3118
3396 /* We should add the ability for user to lock to PASSIVE ONLY */ 3119 if (priv->scan_request->n_ssids) {
3397 if (priv->one_direct_scan) { 3120 int i, p = 0;
3398 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n", 3121 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
3399 print_ssid(ssid, priv->direct_ssid, 3122 for (i = 0; i < priv->scan_request->n_ssids; i++) {
3400 priv->direct_ssid_len)); 3123 /* always does wildcard anyway */
3401 scan->direct_scan[0].id = WLAN_EID_SSID; 3124 if (!priv->scan_request->ssids[i].ssid_len)
3402 scan->direct_scan[0].len = priv->direct_ssid_len; 3125 continue;
3403 memcpy(scan->direct_scan[0].ssid, 3126 scan->direct_scan[p].id = WLAN_EID_SSID;
3404 priv->direct_ssid, priv->direct_ssid_len); 3127 scan->direct_scan[p].len =
3405 n_probes++; 3128 priv->scan_request->ssids[i].ssid_len;
3129 memcpy(scan->direct_scan[p].ssid,
3130 priv->scan_request->ssids[i].ssid,
3131 priv->scan_request->ssids[i].ssid_len);
3132 n_probes++;
3133 p++;
3134 }
3135 is_active = true;
3406 } else 3136 } else
3407 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n"); 3137 IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n");
3408 3138
3409 /* We don't build a direct scan probe request; the uCode will do 3139 /* We don't build a direct scan probe request; the uCode will do
3410 * that based on the direct_mask added to each channel entry */ 3140 * that based on the direct_mask added to each channel entry */
@@ -3421,7 +3151,12 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
3421 band = IEEE80211_BAND_2GHZ; 3151 band = IEEE80211_BAND_2GHZ;
3422 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { 3152 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
3423 scan->tx_cmd.rate = IWL_RATE_6M_PLCP; 3153 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3424 scan->good_CRC_th = IWL_GOOD_CRC_TH; 3154 /*
3155 * If active scaning is requested but a certain channel
3156 * is marked passive, we can do active scanning if we
3157 * detect transmissions.
3158 */
3159 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH : 0;
3425 band = IEEE80211_BAND_5GHZ; 3160 band = IEEE80211_BAND_5GHZ;
3426 } else { 3161 } else {
3427 IWL_WARN(priv, "Invalid scan band count\n"); 3162 IWL_WARN(priv, "Invalid scan band count\n");
@@ -3429,19 +3164,20 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
3429 } 3164 }
3430 3165
3431 scan->tx_cmd.len = cpu_to_le16( 3166 scan->tx_cmd.len = cpu_to_le16(
3432 iwl_fill_probe_req(priv, band, 3167 iwl_fill_probe_req(priv,
3433 (struct ieee80211_mgmt *)scan->data, 3168 (struct ieee80211_mgmt *)scan->data,
3434 IWL_MAX_SCAN_SIZE - sizeof(*scan))); 3169 priv->scan_request->ie,
3170 priv->scan_request->ie_len,
3171 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3435 3172
3436 /* select Rx antennas */ 3173 /* select Rx antennas */
3437 scan->flags |= iwl3945_get_antenna_flags(priv); 3174 scan->flags |= iwl3945_get_antenna_flags(priv);
3438 3175
3439 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) 3176 if (iwl_is_monitor_mode(priv))
3440 scan->filter_flags = RXON_FILTER_PROMISC_MSK; 3177 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3441 3178
3442 scan->channel_count = 3179 scan->channel_count =
3443 iwl3945_get_channels_for_scan(priv, band, 1, /* active */ 3180 iwl3945_get_channels_for_scan(priv, band, is_active, n_probes,
3444 n_probes,
3445 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 3181 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
3446 3182
3447 if (scan->channel_count == 0) { 3183 if (scan->channel_count == 0) {
@@ -3518,7 +3254,7 @@ static void iwl3945_bg_rx_replenish(struct work_struct *data)
3518 3254
3519#define IWL_DELAY_NEXT_SCAN (HZ*2) 3255#define IWL_DELAY_NEXT_SCAN (HZ*2)
3520 3256
3521static void iwl3945_post_associate(struct iwl_priv *priv) 3257void iwl3945_post_associate(struct iwl_priv *priv)
3522{ 3258{
3523 int rc = 0; 3259 int rc = 0;
3524 struct ieee80211_conf *conf = NULL; 3260 struct ieee80211_conf *conf = NULL;
@@ -3543,7 +3279,7 @@ static void iwl3945_post_associate(struct iwl_priv *priv)
3543 conf = ieee80211_get_hw_conf(priv->hw); 3279 conf = ieee80211_get_hw_conf(priv->hw);
3544 3280
3545 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3281 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3546 iwl3945_commit_rxon(priv); 3282 iwlcore_commit_rxon(priv);
3547 3283
3548 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 3284 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
3549 iwl3945_setup_rxon_timing(priv); 3285 iwl3945_setup_rxon_timing(priv);
@@ -3576,7 +3312,7 @@ static void iwl3945_post_associate(struct iwl_priv *priv)
3576 3312
3577 } 3313 }
3578 3314
3579 iwl3945_commit_rxon(priv); 3315 iwlcore_commit_rxon(priv);
3580 3316
3581 switch (priv->iw_mode) { 3317 switch (priv->iw_mode) {
3582 case NL80211_IFTYPE_STATION: 3318 case NL80211_IFTYPE_STATION:
@@ -3586,7 +3322,7 @@ static void iwl3945_post_associate(struct iwl_priv *priv)
3586 case NL80211_IFTYPE_ADHOC: 3322 case NL80211_IFTYPE_ADHOC:
3587 3323
3588 priv->assoc_id = 1; 3324 priv->assoc_id = 1;
3589 iwl3945_add_station(priv, priv->bssid, 0, 0); 3325 priv->cfg->ops->smgmt->add_station(priv, priv->bssid, 0, 0, NULL);
3590 iwl3945_sync_sta(priv, IWL_STA_ID, 3326 iwl3945_sync_sta(priv, IWL_STA_ID,
3591 (priv->band == IEEE80211_BAND_5GHZ) ? 3327 (priv->band == IEEE80211_BAND_5GHZ) ?
3592 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, 3328 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
@@ -3608,8 +3344,6 @@ static void iwl3945_post_associate(struct iwl_priv *priv)
3608 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; 3344 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
3609} 3345}
3610 3346
3611static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
3612
3613/***************************************************************************** 3347/*****************************************************************************
3614 * 3348 *
3615 * mac80211 entry point functions 3349 * mac80211 entry point functions
@@ -3652,9 +3386,6 @@ static int iwl3945_mac_start(struct ieee80211_hw *hw)
3652 3386
3653 IWL_DEBUG_INFO(priv, "Start UP work.\n"); 3387 IWL_DEBUG_INFO(priv, "Start UP work.\n");
3654 3388
3655 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3656 return 0;
3657
3658 /* Wait for START_ALIVE from ucode. Otherwise callbacks from 3389 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3659 * mac80211 will not be run successfully. */ 3390 * mac80211 will not be run successfully. */
3660 ret = wait_event_interruptible_timeout(priv->wait_command_queue, 3391 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
@@ -3733,144 +3464,7 @@ static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3733 return NETDEV_TX_OK; 3464 return NETDEV_TX_OK;
3734} 3465}
3735 3466
3736static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, 3467void iwl3945_config_ap(struct iwl_priv *priv)
3737 struct ieee80211_if_init_conf *conf)
3738{
3739 struct iwl_priv *priv = hw->priv;
3740 unsigned long flags;
3741
3742 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
3743
3744 if (priv->vif) {
3745 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
3746 return -EOPNOTSUPP;
3747 }
3748
3749 spin_lock_irqsave(&priv->lock, flags);
3750 priv->vif = conf->vif;
3751 priv->iw_mode = conf->type;
3752
3753 spin_unlock_irqrestore(&priv->lock, flags);
3754
3755 mutex_lock(&priv->mutex);
3756
3757 if (conf->mac_addr) {
3758 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
3759 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3760 }
3761
3762 if (iwl_is_ready(priv))
3763 iwl3945_set_mode(priv, conf->type);
3764
3765 mutex_unlock(&priv->mutex);
3766
3767 IWL_DEBUG_MAC80211(priv, "leave\n");
3768 return 0;
3769}
3770
3771/**
3772 * iwl3945_mac_config - mac80211 config callback
3773 *
3774 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3775 * be set inappropriately and the driver currently sets the hardware up to
3776 * use it whenever needed.
3777 */
3778static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
3779{
3780 struct iwl_priv *priv = hw->priv;
3781 const struct iwl_channel_info *ch_info;
3782 struct ieee80211_conf *conf = &hw->conf;
3783 unsigned long flags;
3784 int ret = 0;
3785
3786 mutex_lock(&priv->mutex);
3787 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3788 conf->channel->hw_value);
3789
3790 if (!iwl_is_ready(priv)) {
3791 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
3792 ret = -EIO;
3793 goto out;
3794 }
3795
3796 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
3797 test_bit(STATUS_SCANNING, &priv->status))) {
3798 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
3799 set_bit(STATUS_CONF_PENDING, &priv->status);
3800 mutex_unlock(&priv->mutex);
3801 return 0;
3802 }
3803
3804 spin_lock_irqsave(&priv->lock, flags);
3805
3806 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3807 conf->channel->hw_value);
3808 if (!is_channel_valid(ch_info)) {
3809 IWL_DEBUG_SCAN(priv,
3810 "Channel %d [%d] is INVALID for this band.\n",
3811 conf->channel->hw_value, conf->channel->band);
3812 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
3813 spin_unlock_irqrestore(&priv->lock, flags);
3814 ret = -EINVAL;
3815 goto out;
3816 }
3817
3818 iwl_set_rxon_channel(priv, conf->channel);
3819
3820 iwl_set_flags_for_band(priv, conf->channel->band);
3821
3822 /* The list of supported rates and rate mask can be different
3823 * for each phymode; since the phymode may have changed, reset
3824 * the rate mask to what mac80211 lists */
3825 iwl_set_rate(priv);
3826
3827 spin_unlock_irqrestore(&priv->lock, flags);
3828
3829#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3830 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
3831 iwl3945_hw_channel_switch(priv, conf->channel);
3832 goto out;
3833 }
3834#endif
3835
3836 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
3837 if (conf->radio_enabled &&
3838 iwl_radio_kill_sw_enable_radio(priv)) {
3839 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
3840 "waiting for uCode\n");
3841 goto out;
3842 }
3843
3844 if (!conf->radio_enabled) {
3845 iwl_radio_kill_sw_disable_radio(priv);
3846 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
3847 goto out;
3848 }
3849 }
3850
3851 if (iwl_is_rfkill(priv)) {
3852 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
3853 ret = -EIO;
3854 goto out;
3855 }
3856
3857 iwl_set_rate(priv);
3858
3859 if (memcmp(&priv->active_rxon,
3860 &priv->staging_rxon, sizeof(priv->staging_rxon)))
3861 iwl3945_commit_rxon(priv);
3862 else
3863 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
3864
3865 IWL_DEBUG_MAC80211(priv, "leave\n");
3866
3867out:
3868 clear_bit(STATUS_CONF_PENDING, &priv->status);
3869 mutex_unlock(&priv->mutex);
3870 return ret;
3871}
3872
3873static void iwl3945_config_ap(struct iwl_priv *priv)
3874{ 3468{
3875 int rc = 0; 3469 int rc = 0;
3876 3470
@@ -3882,7 +3476,7 @@ static void iwl3945_config_ap(struct iwl_priv *priv)
3882 3476
3883 /* RXON - unassoc (to set timing command) */ 3477 /* RXON - unassoc (to set timing command) */
3884 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3478 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3885 iwl3945_commit_rxon(priv); 3479 iwlcore_commit_rxon(priv);
3886 3480
3887 /* RXON Timing */ 3481 /* RXON Timing */
3888 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 3482 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
@@ -3918,8 +3512,8 @@ static void iwl3945_config_ap(struct iwl_priv *priv)
3918 } 3512 }
3919 /* restore RXON assoc */ 3513 /* restore RXON assoc */
3920 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3514 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3921 iwl3945_commit_rxon(priv); 3515 iwlcore_commit_rxon(priv);
3922 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0); 3516 priv->cfg->ops->smgmt->add_station(priv, iwl_bcast_addr, 0, 0, NULL);
3923 } 3517 }
3924 iwl3945_send_beacon_cmd(priv); 3518 iwl3945_send_beacon_cmd(priv);
3925 3519
@@ -3928,189 +3522,6 @@ static void iwl3945_config_ap(struct iwl_priv *priv)
3928 * clear sta table, add BCAST sta... */ 3522 * clear sta table, add BCAST sta... */
3929} 3523}
3930 3524
3931static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3932 struct ieee80211_vif *vif,
3933 struct ieee80211_if_conf *conf)
3934{
3935 struct iwl_priv *priv = hw->priv;
3936 int rc;
3937
3938 if (conf == NULL)
3939 return -EIO;
3940
3941 if (priv->vif != vif) {
3942 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
3943 return 0;
3944 }
3945
3946 /* handle this temporarily here */
3947 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
3948 conf->changed & IEEE80211_IFCC_BEACON) {
3949 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3950 if (!beacon)
3951 return -ENOMEM;
3952 mutex_lock(&priv->mutex);
3953 rc = iwl3945_mac_beacon_update(hw, beacon);
3954 mutex_unlock(&priv->mutex);
3955 if (rc)
3956 return rc;
3957 }
3958
3959 if (!iwl_is_alive(priv))
3960 return -EAGAIN;
3961
3962 mutex_lock(&priv->mutex);
3963
3964 if (conf->bssid)
3965 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
3966
3967/*
3968 * very dubious code was here; the probe filtering flag is never set:
3969 *
3970 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3971 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
3972 */
3973
3974 if (priv->iw_mode == NL80211_IFTYPE_AP) {
3975 if (!conf->bssid) {
3976 conf->bssid = priv->mac_addr;
3977 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
3978 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
3979 conf->bssid);
3980 }
3981 if (priv->ibss_beacon)
3982 dev_kfree_skb(priv->ibss_beacon);
3983
3984 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
3985 }
3986
3987 if (iwl_is_rfkill(priv))
3988 goto done;
3989
3990 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3991 !is_multicast_ether_addr(conf->bssid)) {
3992 /* If there is currently a HW scan going on in the background
3993 * then we need to cancel it else the RXON below will fail. */
3994 if (iwl_scan_cancel_timeout(priv, 100)) {
3995 IWL_WARN(priv, "Aborted scan still in progress "
3996 "after 100ms\n");
3997 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
3998 mutex_unlock(&priv->mutex);
3999 return -EAGAIN;
4000 }
4001 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
4002
4003 /* TODO: Audit driver for usage of these members and see
4004 * if mac80211 deprecates them (priv->bssid looks like it
4005 * shouldn't be there, but I haven't scanned the IBSS code
4006 * to verify) - jpk */
4007 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4008
4009 if (priv->iw_mode == NL80211_IFTYPE_AP)
4010 iwl3945_config_ap(priv);
4011 else {
4012 rc = iwl3945_commit_rxon(priv);
4013 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
4014 iwl3945_add_station(priv,
4015 priv->active_rxon.bssid_addr, 1, 0);
4016 }
4017
4018 } else {
4019 iwl_scan_cancel_timeout(priv, 100);
4020 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4021 iwl3945_commit_rxon(priv);
4022 }
4023
4024 done:
4025 IWL_DEBUG_MAC80211(priv, "leave\n");
4026 mutex_unlock(&priv->mutex);
4027
4028 return 0;
4029}
4030
4031static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
4032 struct ieee80211_if_init_conf *conf)
4033{
4034 struct iwl_priv *priv = hw->priv;
4035
4036 IWL_DEBUG_MAC80211(priv, "enter\n");
4037
4038 mutex_lock(&priv->mutex);
4039
4040 if (iwl_is_ready_rf(priv)) {
4041 iwl_scan_cancel_timeout(priv, 100);
4042 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4043 iwl3945_commit_rxon(priv);
4044 }
4045 if (priv->vif == conf->vif) {
4046 priv->vif = NULL;
4047 memset(priv->bssid, 0, ETH_ALEN);
4048 }
4049 mutex_unlock(&priv->mutex);
4050
4051 IWL_DEBUG_MAC80211(priv, "leave\n");
4052}
4053
4054#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4055
4056static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4057 struct ieee80211_vif *vif,
4058 struct ieee80211_bss_conf *bss_conf,
4059 u32 changes)
4060{
4061 struct iwl_priv *priv = hw->priv;
4062
4063 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
4064
4065 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
4066 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
4067 bss_conf->use_short_preamble);
4068 if (bss_conf->use_short_preamble)
4069 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
4070 else
4071 priv->staging_rxon.flags &=
4072 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4073 }
4074
4075 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
4076 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4077 bss_conf->use_cts_prot);
4078 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
4079 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
4080 else
4081 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
4082 }
4083
4084 if (changes & BSS_CHANGED_ASSOC) {
4085 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
4086 /* This should never happen as this function should
4087 * never be called from interrupt context. */
4088 if (WARN_ON_ONCE(in_interrupt()))
4089 return;
4090 if (bss_conf->assoc) {
4091 priv->assoc_id = bss_conf->aid;
4092 priv->beacon_int = bss_conf->beacon_int;
4093 priv->timestamp = bss_conf->timestamp;
4094 priv->assoc_capability = bss_conf->assoc_capability;
4095 priv->power_data.dtim_period = bss_conf->dtim_period;
4096 priv->next_scan_jiffies = jiffies +
4097 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4098 mutex_lock(&priv->mutex);
4099 iwl3945_post_associate(priv);
4100 mutex_unlock(&priv->mutex);
4101 } else {
4102 priv->assoc_id = 0;
4103 IWL_DEBUG_MAC80211(priv,
4104 "DISASSOC %d\n", bss_conf->assoc);
4105 }
4106 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
4107 IWL_DEBUG_MAC80211(priv,
4108 "Associated Changes %d\n", changes);
4109 iwl3945_send_rxon_assoc(priv);
4110 }
4111
4112}
4113
4114static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 3525static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4115 struct ieee80211_vif *vif, 3526 struct ieee80211_vif *vif,
4116 struct ieee80211_sta *sta, 3527 struct ieee80211_sta *sta,
@@ -4133,7 +3544,7 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4133 static_key = !iwl_is_associated(priv); 3544 static_key = !iwl_is_associated(priv);
4134 3545
4135 if (!static_key) { 3546 if (!static_key) {
4136 sta_id = iwl3945_hw_find_station(priv, addr); 3547 sta_id = priv->cfg->ops->smgmt->find_station(priv, addr);
4137 if (sta_id == IWL_INVALID_STATION) { 3548 if (sta_id == IWL_INVALID_STATION) {
4138 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", 3549 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
4139 addr); 3550 addr);
@@ -4169,185 +3580,6 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4169 return ret; 3580 return ret;
4170} 3581}
4171 3582
4172static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
4173 const struct ieee80211_tx_queue_params *params)
4174{
4175 struct iwl_priv *priv = hw->priv;
4176 unsigned long flags;
4177 int q;
4178
4179 IWL_DEBUG_MAC80211(priv, "enter\n");
4180
4181 if (!iwl_is_ready_rf(priv)) {
4182 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4183 return -EIO;
4184 }
4185
4186 if (queue >= AC_NUM) {
4187 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
4188 return 0;
4189 }
4190
4191 q = AC_NUM - 1 - queue;
4192
4193 spin_lock_irqsave(&priv->lock, flags);
4194
4195 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4196 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4197 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4198 priv->qos_data.def_qos_parm.ac[q].edca_txop =
4199 cpu_to_le16((params->txop * 32));
4200
4201 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4202 priv->qos_data.qos_active = 1;
4203
4204 spin_unlock_irqrestore(&priv->lock, flags);
4205
4206 mutex_lock(&priv->mutex);
4207 if (priv->iw_mode == NL80211_IFTYPE_AP)
4208 iwl_activate_qos(priv, 1);
4209 else if (priv->assoc_id && iwl_is_associated(priv))
4210 iwl_activate_qos(priv, 0);
4211
4212 mutex_unlock(&priv->mutex);
4213
4214 IWL_DEBUG_MAC80211(priv, "leave\n");
4215 return 0;
4216}
4217
4218static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
4219 struct ieee80211_tx_queue_stats *stats)
4220{
4221 struct iwl_priv *priv = hw->priv;
4222 int i, avail;
4223 struct iwl_tx_queue *txq;
4224 struct iwl_queue *q;
4225 unsigned long flags;
4226
4227 IWL_DEBUG_MAC80211(priv, "enter\n");
4228
4229 if (!iwl_is_ready_rf(priv)) {
4230 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4231 return -EIO;
4232 }
4233
4234 spin_lock_irqsave(&priv->lock, flags);
4235
4236 for (i = 0; i < AC_NUM; i++) {
4237 txq = &priv->txq[i];
4238 q = &txq->q;
4239 avail = iwl_queue_space(q);
4240
4241 stats[i].len = q->n_window - avail;
4242 stats[i].limit = q->n_window - q->high_mark;
4243 stats[i].count = q->n_window;
4244
4245 }
4246 spin_unlock_irqrestore(&priv->lock, flags);
4247
4248 IWL_DEBUG_MAC80211(priv, "leave\n");
4249
4250 return 0;
4251}
4252
4253static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
4254{
4255 struct iwl_priv *priv = hw->priv;
4256 unsigned long flags;
4257
4258 mutex_lock(&priv->mutex);
4259 IWL_DEBUG_MAC80211(priv, "enter\n");
4260
4261 iwl_reset_qos(priv);
4262
4263 spin_lock_irqsave(&priv->lock, flags);
4264 priv->assoc_id = 0;
4265 priv->assoc_capability = 0;
4266
4267 /* new association get rid of ibss beacon skb */
4268 if (priv->ibss_beacon)
4269 dev_kfree_skb(priv->ibss_beacon);
4270
4271 priv->ibss_beacon = NULL;
4272
4273 priv->beacon_int = priv->hw->conf.beacon_int;
4274 priv->timestamp = 0;
4275 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
4276 priv->beacon_int = 0;
4277
4278 spin_unlock_irqrestore(&priv->lock, flags);
4279
4280 if (!iwl_is_ready_rf(priv)) {
4281 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
4282 mutex_unlock(&priv->mutex);
4283 return;
4284 }
4285
4286 /* we are restarting association process
4287 * clear RXON_FILTER_ASSOC_MSK bit
4288 */
4289 if (priv->iw_mode != NL80211_IFTYPE_AP) {
4290 iwl_scan_cancel_timeout(priv, 100);
4291 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4292 iwl3945_commit_rxon(priv);
4293 }
4294
4295 /* Per mac80211.h: This is only used in IBSS mode... */
4296 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
4297
4298 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
4299 mutex_unlock(&priv->mutex);
4300 return;
4301 }
4302
4303 iwl_set_rate(priv);
4304
4305 mutex_unlock(&priv->mutex);
4306
4307 IWL_DEBUG_MAC80211(priv, "leave\n");
4308
4309}
4310
4311static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
4312{
4313 struct iwl_priv *priv = hw->priv;
4314 unsigned long flags;
4315 __le64 timestamp;
4316
4317 IWL_DEBUG_MAC80211(priv, "enter\n");
4318
4319 if (!iwl_is_ready_rf(priv)) {
4320 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4321 return -EIO;
4322 }
4323
4324 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
4325 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
4326 return -EIO;
4327 }
4328
4329 spin_lock_irqsave(&priv->lock, flags);
4330
4331 if (priv->ibss_beacon)
4332 dev_kfree_skb(priv->ibss_beacon);
4333
4334 priv->ibss_beacon = skb;
4335
4336 priv->assoc_id = 0;
4337 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
4338 priv->timestamp = le64_to_cpu(timestamp);
4339
4340 IWL_DEBUG_MAC80211(priv, "leave\n");
4341 spin_unlock_irqrestore(&priv->lock, flags);
4342
4343 iwl_reset_qos(priv);
4344
4345 iwl3945_post_associate(priv);
4346
4347
4348 return 0;
4349}
4350
4351/***************************************************************************** 3583/*****************************************************************************
4352 * 3584 *
4353 * sysfs attributes 3585 * sysfs attributes
@@ -4455,7 +3687,7 @@ static ssize_t store_flags(struct device *d,
4455 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n", 3687 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
4456 flags); 3688 flags);
4457 priv->staging_rxon.flags = cpu_to_le32(flags); 3689 priv->staging_rxon.flags = cpu_to_le32(flags);
4458 iwl3945_commit_rxon(priv); 3690 iwlcore_commit_rxon(priv);
4459 } 3691 }
4460 } 3692 }
4461 mutex_unlock(&priv->mutex); 3693 mutex_unlock(&priv->mutex);
@@ -4491,7 +3723,7 @@ static ssize_t store_filter_flags(struct device *d,
4491 "0x%04X\n", filter_flags); 3723 "0x%04X\n", filter_flags);
4492 priv->staging_rxon.filter_flags = 3724 priv->staging_rxon.filter_flags =
4493 cpu_to_le32(filter_flags); 3725 cpu_to_le32(filter_flags);
4494 iwl3945_commit_rxon(priv); 3726 iwlcore_commit_rxon(priv);
4495 } 3727 }
4496 } 3728 }
4497 mutex_unlock(&priv->mutex); 3729 mutex_unlock(&priv->mutex);
@@ -4871,16 +4103,16 @@ static struct ieee80211_ops iwl3945_hw_ops = {
4871 .tx = iwl3945_mac_tx, 4103 .tx = iwl3945_mac_tx,
4872 .start = iwl3945_mac_start, 4104 .start = iwl3945_mac_start,
4873 .stop = iwl3945_mac_stop, 4105 .stop = iwl3945_mac_stop,
4874 .add_interface = iwl3945_mac_add_interface, 4106 .add_interface = iwl_mac_add_interface,
4875 .remove_interface = iwl3945_mac_remove_interface, 4107 .remove_interface = iwl_mac_remove_interface,
4876 .config = iwl3945_mac_config, 4108 .config = iwl_mac_config,
4877 .config_interface = iwl3945_mac_config_interface, 4109 .config_interface = iwl_mac_config_interface,
4878 .configure_filter = iwl_configure_filter, 4110 .configure_filter = iwl_configure_filter,
4879 .set_key = iwl3945_mac_set_key, 4111 .set_key = iwl3945_mac_set_key,
4880 .get_tx_stats = iwl3945_mac_get_tx_stats, 4112 .get_tx_stats = iwl_mac_get_tx_stats,
4881 .conf_tx = iwl3945_mac_conf_tx, 4113 .conf_tx = iwl_mac_conf_tx,
4882 .reset_tsf = iwl3945_mac_reset_tsf, 4114 .reset_tsf = iwl_mac_reset_tsf,
4883 .bss_info_changed = iwl3945_bss_info_changed, 4115 .bss_info_changed = iwl_bss_info_changed,
4884 .hw_scan = iwl_mac_hw_scan 4116 .hw_scan = iwl_mac_hw_scan
4885}; 4117};
4886 4118
@@ -4902,7 +4134,7 @@ static int iwl3945_init_drv(struct iwl_priv *priv)
4902 mutex_init(&priv->mutex); 4134 mutex_init(&priv->mutex);
4903 4135
4904 /* Clear the driver's (not device's) station table */ 4136 /* Clear the driver's (not device's) station table */
4905 iwl3945_clear_stations_table(priv); 4137 priv->cfg->ops->smgmt->clear_station_table(priv);
4906 4138
4907 priv->data_retry_limit = -1; 4139 priv->data_retry_limit = -1;
4908 priv->ieee_channels = NULL; 4140 priv->ieee_channels = NULL;
@@ -4973,7 +4205,9 @@ static int iwl3945_setup_mac(struct iwl_priv *priv)
4973 4205
4974 hw->wiphy->custom_regulatory = true; 4206 hw->wiphy->custom_regulatory = true;
4975 4207
4976 hw->wiphy->max_scan_ssids = 1; /* WILL FIX */ 4208 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945;
4209 /* we create the 802.11 header and a zero-length SSID element */
4210 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
4977 4211
4978 /* Default value; 4 EDCA QOS priorities */ 4212 /* Default value; 4 EDCA QOS priorities */
4979 hw->queues = 4; 4213 hw->queues = 4;
@@ -5135,20 +4369,8 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5135 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", 4369 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5136 priv->cfg->name); 4370 priv->cfg->name);
5137 4371
5138 /***********************************
5139 * 7. Initialize Module Parameters
5140 * **********************************/
5141
5142 /* Initialize module parameter values here */
5143 /* Disable radio (SW RF KILL) via parameter when loading driver */
5144 if (iwl3945_mod_params.disable) {
5145 set_bit(STATUS_RF_KILL_SW, &priv->status);
5146 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
5147 }
5148
5149
5150 /*********************** 4372 /***********************
5151 * 8. Setup Services 4373 * 7. Setup Services
5152 * ********************/ 4374 * ********************/
5153 4375
5154 spin_lock_irqsave(&priv->lock, flags); 4376 spin_lock_irqsave(&priv->lock, flags);
@@ -5176,7 +4398,7 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5176 iwl3945_setup_rx_handlers(priv); 4398 iwl3945_setup_rx_handlers(priv);
5177 4399
5178 /********************************* 4400 /*********************************
5179 * 9. Setup and Register mac80211 4401 * 8. Setup and Register mac80211
5180 * *******************************/ 4402 * *******************************/
5181 4403
5182 iwl_enable_interrupts(priv); 4404 iwl_enable_interrupts(priv);
@@ -5185,6 +4407,10 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
5185 if (err) 4407 if (err)
5186 goto out_remove_sysfs; 4408 goto out_remove_sysfs;
5187 4409
4410 err = iwl_dbgfs_register(priv, DRV_NAME);
4411 if (err)
4412 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
4413
5188 err = iwl_rfkill_init(priv); 4414 err = iwl_rfkill_init(priv);
5189 if (err) 4415 if (err)
5190 IWL_ERR(priv, "Unable to initialize RFKILL system. " 4416 IWL_ERR(priv, "Unable to initialize RFKILL system. "
@@ -5235,6 +4461,8 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5235 4461
5236 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n"); 4462 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
5237 4463
4464 iwl_dbgfs_unregister(priv);
4465
5238 set_bit(STATUS_EXIT_PENDING, &priv->status); 4466 set_bit(STATUS_EXIT_PENDING, &priv->status);
5239 4467
5240 if (priv->mac80211_registered) { 4468 if (priv->mac80211_registered) {
@@ -5265,7 +4493,7 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5265 iwl3945_hw_txq_ctx_free(priv); 4493 iwl3945_hw_txq_ctx_free(priv);
5266 4494
5267 iwl3945_unset_hw_params(priv); 4495 iwl3945_unset_hw_params(priv);
5268 iwl3945_clear_stations_table(priv); 4496 priv->cfg->ops->smgmt->clear_station_table(priv);
5269 4497
5270 /*netif_stop_queue(dev); */ 4498 /*netif_stop_queue(dev); */
5271 flush_workqueue(priv->workqueue); 4499 flush_workqueue(priv->workqueue);
@@ -5293,43 +4521,6 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5293 ieee80211_free_hw(priv->hw); 4521 ieee80211_free_hw(priv->hw);
5294} 4522}
5295 4523
5296#ifdef CONFIG_PM
5297
5298static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5299{
5300 struct iwl_priv *priv = pci_get_drvdata(pdev);
5301
5302 if (priv->is_open) {
5303 set_bit(STATUS_IN_SUSPEND, &priv->status);
5304 iwl3945_mac_stop(priv->hw);
5305 priv->is_open = 1;
5306 }
5307 pci_save_state(pdev);
5308 pci_disable_device(pdev);
5309 pci_set_power_state(pdev, PCI_D3hot);
5310
5311 return 0;
5312}
5313
5314static int iwl3945_pci_resume(struct pci_dev *pdev)
5315{
5316 struct iwl_priv *priv = pci_get_drvdata(pdev);
5317 int ret;
5318
5319 pci_set_power_state(pdev, PCI_D0);
5320 ret = pci_enable_device(pdev);
5321 if (ret)
5322 return ret;
5323 pci_restore_state(pdev);
5324
5325 if (priv->is_open)
5326 iwl3945_mac_start(priv->hw);
5327
5328 clear_bit(STATUS_IN_SUSPEND, &priv->status);
5329 return 0;
5330}
5331
5332#endif /* CONFIG_PM */
5333 4524
5334/***************************************************************************** 4525/*****************************************************************************
5335 * 4526 *
@@ -5343,8 +4534,8 @@ static struct pci_driver iwl3945_driver = {
5343 .probe = iwl3945_pci_probe, 4534 .probe = iwl3945_pci_probe,
5344 .remove = __devexit_p(iwl3945_pci_remove), 4535 .remove = __devexit_p(iwl3945_pci_remove),
5345#ifdef CONFIG_PM 4536#ifdef CONFIG_PM
5346 .suspend = iwl3945_pci_suspend, 4537 .suspend = iwl_pci_suspend,
5347 .resume = iwl3945_pci_resume, 4538 .resume = iwl_pci_resume,
5348#endif 4539#endif
5349}; 4540};
5350 4541
@@ -5385,8 +4576,6 @@ MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
5385 4576
5386module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444); 4577module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
5387MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); 4578MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
5388module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
5389MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
5390module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444); 4579module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5391MODULE_PARM_DESC(swcrypto, 4580MODULE_PARM_DESC(swcrypto,
5392 "using software crypto (default 1 [software])\n"); 4581 "using software crypto (default 1 [software])\n");
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
index 8c3605cdc64..c455b9abbfc 100644
--- a/drivers/net/wireless/libertas/cmd.c
+++ b/drivers/net/wireless/libertas/cmd.c
@@ -119,6 +119,19 @@ int lbs_update_hw_spec(struct lbs_private *priv)
119 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n", 119 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
120 cmd.hwifversion, cmd.version); 120 cmd.hwifversion, cmd.version);
121 121
122 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
123 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
124 /* 5.110.22 have mesh command with 0xa3 command id */
125 /* 10.0.0.p0 FW brings in mesh config command with different id */
126 /* Check FW version MSB and initialize mesh_fw_ver */
127 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
128 priv->mesh_fw_ver = MESH_FW_OLD;
129 else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
130 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
131 priv->mesh_fw_ver = MESH_FW_NEW;
132 else
133 priv->mesh_fw_ver = MESH_NONE;
134
122 /* Clamp region code to 8-bit since FW spec indicates that it should 135 /* Clamp region code to 8-bit since FW spec indicates that it should
123 * only ever be 8-bit, even though the field size is 16-bit. Some firmware 136 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
124 * returns non-zero high 8 bits here. 137 * returns non-zero high 8 bits here.
@@ -1036,17 +1049,26 @@ static int __lbs_mesh_config_send(struct lbs_private *priv,
1036 uint16_t action, uint16_t type) 1049 uint16_t action, uint16_t type)
1037{ 1050{
1038 int ret; 1051 int ret;
1052 u16 command = CMD_MESH_CONFIG_OLD;
1039 1053
1040 lbs_deb_enter(LBS_DEB_CMD); 1054 lbs_deb_enter(LBS_DEB_CMD);
1041 1055
1042 cmd->hdr.command = cpu_to_le16(CMD_MESH_CONFIG); 1056 /*
1057 * Command id is 0xac for v10 FW along with mesh interface
1058 * id in bits 14-13-12.
1059 */
1060 if (priv->mesh_fw_ver == MESH_FW_NEW)
1061 command = CMD_MESH_CONFIG |
1062 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
1063
1064 cmd->hdr.command = cpu_to_le16(command);
1043 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config)); 1065 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
1044 cmd->hdr.result = 0; 1066 cmd->hdr.result = 0;
1045 1067
1046 cmd->type = cpu_to_le16(type); 1068 cmd->type = cpu_to_le16(type);
1047 cmd->action = cpu_to_le16(action); 1069 cmd->action = cpu_to_le16(action);
1048 1070
1049 ret = lbs_cmd_with_response(priv, CMD_MESH_CONFIG, cmd); 1071 ret = lbs_cmd_with_response(priv, command, cmd);
1050 1072
1051 lbs_deb_leave(LBS_DEB_CMD); 1073 lbs_deb_leave(LBS_DEB_CMD);
1052 return ret; 1074 return ret;
diff --git a/drivers/net/wireless/libertas/defs.h b/drivers/net/wireless/libertas/defs.h
index e8dfde39abf..48da157d6cd 100644
--- a/drivers/net/wireless/libertas/defs.h
+++ b/drivers/net/wireless/libertas/defs.h
@@ -227,6 +227,20 @@ static inline void lbs_deb_hex(unsigned int grp, const char *prompt, u8 *buf, in
227#define TxPD_CONTROL_WDS_FRAME (1<<17) 227#define TxPD_CONTROL_WDS_FRAME (1<<17)
228#define TxPD_MESH_FRAME TxPD_CONTROL_WDS_FRAME 228#define TxPD_MESH_FRAME TxPD_CONTROL_WDS_FRAME
229 229
230/** Mesh interface ID */
231#define MESH_IFACE_ID 0x0001
232/** Mesh id should be in bits 14-13-12 */
233#define MESH_IFACE_BIT_OFFSET 0x000c
234/** Mesh enable bit in FW capability */
235#define MESH_CAPINFO_ENABLE_MASK (1<<16)
236
237/** FW definition from Marvell v5 */
238#define MRVL_FW_V5 (0x05)
239/** FW definition from Marvell v10 */
240#define MRVL_FW_V10 (0x0a)
241/** FW major revision definition */
242#define MRVL_FW_MAJOR_REV(x) ((x)>>24)
243
230/** RxPD status */ 244/** RxPD status */
231 245
232#define MRVDRV_RXPD_STATUS_OK 0x0001 246#define MRVDRV_RXPD_STATUS_OK 0x0001
@@ -380,6 +394,13 @@ enum KEY_INFO_WPA {
380 KEY_INFO_WPA_ENABLED = 0x04 394 KEY_INFO_WPA_ENABLED = 0x04
381}; 395};
382 396
397/** mesh_fw_ver */
398enum _mesh_fw_ver {
399 MESH_NONE = 0, /* MESH is not supported */
400 MESH_FW_OLD, /* MESH is supported in FW V5 */
401 MESH_FW_NEW, /* MESH is supported in FW V10 and newer */
402};
403
383/* Default values for fwt commands. */ 404/* Default values for fwt commands. */
384#define FWT_DEFAULT_METRIC 0 405#define FWT_DEFAULT_METRIC 0
385#define FWT_DEFAULT_DIR 1 406#define FWT_DEFAULT_DIR 1
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index 27e81fd97c9..cbaafa653b6 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -101,6 +101,7 @@ struct lbs_mesh_stats {
101/** Private structure for the MV device */ 101/** Private structure for the MV device */
102struct lbs_private { 102struct lbs_private {
103 int mesh_open; 103 int mesh_open;
104 int mesh_fw_ver;
104 int infra_open; 105 int infra_open;
105 int mesh_autostart_enabled; 106 int mesh_autostart_enabled;
106 107
diff --git a/drivers/net/wireless/libertas/host.h b/drivers/net/wireless/libertas/host.h
index d4457ef808a..8ff8ac9d817 100644
--- a/drivers/net/wireless/libertas/host.h
+++ b/drivers/net/wireless/libertas/host.h
@@ -83,7 +83,8 @@
83#define CMD_FWT_ACCESS 0x0095 83#define CMD_FWT_ACCESS 0x0095
84#define CMD_802_11_MONITOR_MODE 0x0098 84#define CMD_802_11_MONITOR_MODE 0x0098
85#define CMD_MESH_ACCESS 0x009b 85#define CMD_MESH_ACCESS 0x009b
86#define CMD_MESH_CONFIG 0x00a3 86#define CMD_MESH_CONFIG_OLD 0x00a3
87#define CMD_MESH_CONFIG 0x00ac
87#define CMD_SET_BOOT2_VER 0x00a5 88#define CMD_SET_BOOT2_VER 0x00a5
88#define CMD_802_11_BEACON_CTRL 0x00b0 89#define CMD_802_11_BEACON_CTRL 0x00b0
89 90
diff --git a/drivers/net/wireless/libertas/hostcmd.h b/drivers/net/wireless/libertas/hostcmd.h
index a899aeb676b..391c54ab2b0 100644
--- a/drivers/net/wireless/libertas/hostcmd.h
+++ b/drivers/net/wireless/libertas/hostcmd.h
@@ -13,8 +13,19 @@
13 13
14/* TxPD descriptor */ 14/* TxPD descriptor */
15struct txpd { 15struct txpd {
16 /* Current Tx packet status */ 16 /* union to cope up with later FW revisions */
17 __le32 tx_status; 17 union {
18 /* Current Tx packet status */
19 __le32 tx_status;
20 struct {
21 /* BSS type: client, AP, etc. */
22 u8 bss_type;
23 /* BSS number */
24 u8 bss_num;
25 /* Reserved */
26 __le16 reserved;
27 } bss;
28 } u;
18 /* Tx control */ 29 /* Tx control */
19 __le32 tx_control; 30 __le32 tx_control;
20 __le32 tx_packet_location; 31 __le32 tx_packet_location;
@@ -36,8 +47,17 @@ struct txpd {
36 47
37/* RxPD Descriptor */ 48/* RxPD Descriptor */
38struct rxpd { 49struct rxpd {
39 /* Current Rx packet status */ 50 /* union to cope up with later FW revisions */
40 __le16 status; 51 union {
52 /* Current Rx packet status */
53 __le16 status;
54 struct {
55 /* BSS type: client, AP, etc. */
56 u8 bss_type;
57 /* BSS number */
58 u8 bss_num;
59 } bss;
60 } u;
41 61
42 /* SNR */ 62 /* SNR */
43 u8 snr; 63 u8 snr;
diff --git a/drivers/net/wireless/libertas/if_cs.c b/drivers/net/wireless/libertas/if_cs.c
index cedeac6322f..2a5b083bf9b 100644
--- a/drivers/net/wireless/libertas/if_cs.c
+++ b/drivers/net/wireless/libertas/if_cs.c
@@ -273,7 +273,28 @@ static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 r
273 */ 273 */
274#define IF_CS_PRODUCT_ID 0x0000001C 274#define IF_CS_PRODUCT_ID 0x0000001C
275#define IF_CS_CF8385_B1_REV 0x12 275#define IF_CS_CF8385_B1_REV 0x12
276#define IF_CS_CF8381_B3_REV 0x04
276 277
278/*
279 * Used to detect other cards than CF8385 since their revisions of silicon
280 * doesn't match those from CF8385, eg. CF8381 B3 works with this driver.
281 */
282#define CF8381_MANFID 0x02db
283#define CF8381_CARDID 0x6064
284#define CF8385_MANFID 0x02df
285#define CF8385_CARDID 0x8103
286
287static inline int if_cs_hw_is_cf8381(struct pcmcia_device *p_dev)
288{
289 return (p_dev->manf_id == CF8381_MANFID &&
290 p_dev->card_id == CF8381_CARDID);
291}
292
293static inline int if_cs_hw_is_cf8385(struct pcmcia_device *p_dev)
294{
295 return (p_dev->manf_id == CF8385_MANFID &&
296 p_dev->card_id == CF8385_CARDID);
297}
277 298
278/********************************************************************/ 299/********************************************************************/
279/* I/O and interrupt handling */ 300/* I/O and interrupt handling */
@@ -757,6 +778,7 @@ static void if_cs_release(struct pcmcia_device *p_dev)
757static int if_cs_probe(struct pcmcia_device *p_dev) 778static int if_cs_probe(struct pcmcia_device *p_dev)
758{ 779{
759 int ret = -ENOMEM; 780 int ret = -ENOMEM;
781 unsigned int prod_id;
760 struct lbs_private *priv; 782 struct lbs_private *priv;
761 struct if_cs_card *card; 783 struct if_cs_card *card;
762 /* CIS parsing */ 784 /* CIS parsing */
@@ -859,7 +881,14 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
859 p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1); 881 p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1);
860 882
861 /* Check if we have a current silicon */ 883 /* Check if we have a current silicon */
862 if (if_cs_read8(card, IF_CS_PRODUCT_ID) < IF_CS_CF8385_B1_REV) { 884 prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID);
885 if (if_cs_hw_is_cf8381(p_dev) && prod_id < IF_CS_CF8381_B3_REV) {
886 lbs_pr_err("old chips like 8381 rev B3 aren't supported\n");
887 ret = -ENODEV;
888 goto out2;
889 }
890
891 if (if_cs_hw_is_cf8385(p_dev) && prod_id < IF_CS_CF8385_B1_REV) {
863 lbs_pr_err("old chips like 8385 rev B1 aren't supported\n"); 892 lbs_pr_err("old chips like 8385 rev B1 aren't supported\n");
864 ret = -ENODEV; 893 ret = -ENODEV;
865 goto out2; 894 goto out2;
@@ -950,7 +979,8 @@ static void if_cs_detach(struct pcmcia_device *p_dev)
950/********************************************************************/ 979/********************************************************************/
951 980
952static struct pcmcia_device_id if_cs_ids[] = { 981static struct pcmcia_device_id if_cs_ids[] = {
953 PCMCIA_DEVICE_MANF_CARD(0x02df, 0x8103), 982 PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID),
983 PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID),
954 PCMCIA_DEVICE_NULL, 984 PCMCIA_DEVICE_NULL,
955}; 985};
956MODULE_DEVICE_TABLE(pcmcia, if_cs_ids); 986MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c
index 76f4c653d64..55864c10f9f 100644
--- a/drivers/net/wireless/libertas/if_sdio.c
+++ b/drivers/net/wireless/libertas/if_sdio.c
@@ -48,8 +48,11 @@ static char *lbs_fw_name = NULL;
48module_param_named(fw_name, lbs_fw_name, charp, 0644); 48module_param_named(fw_name, lbs_fw_name, charp, 0644);
49 49
50static const struct sdio_device_id if_sdio_ids[] = { 50static const struct sdio_device_id if_sdio_ids[] = {
51 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_LIBERTAS) }, 51 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL,
52 { /* end: all zeroes */ }, 52 SDIO_DEVICE_ID_MARVELL_LIBERTAS) },
53 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL,
54 SDIO_DEVICE_ID_MARVELL_8688WLAN) },
55 { /* end: all zeroes */ },
53}; 56};
54 57
55MODULE_DEVICE_TABLE(sdio, if_sdio_ids); 58MODULE_DEVICE_TABLE(sdio, if_sdio_ids);
@@ -73,6 +76,12 @@ static struct if_sdio_model if_sdio_models[] = {
73 .helper = "sd8686_helper.bin", 76 .helper = "sd8686_helper.bin",
74 .firmware = "sd8686.bin", 77 .firmware = "sd8686.bin",
75 }, 78 },
79 {
80 /* 8688 */
81 .model = 0x10,
82 .helper = "sd8688_helper.bin",
83 .firmware = "sd8688.bin",
84 },
76}; 85};
77 86
78struct if_sdio_packet { 87struct if_sdio_packet {
@@ -488,7 +497,7 @@ static int if_sdio_prog_helper(struct if_sdio_card *card)
488 ret = 0; 497 ret = 0;
489 498
490release: 499release:
491 sdio_set_block_size(card->func, 0); 500 sdio_set_block_size(card->func, IF_SDIO_BLOCK_SIZE);
492 sdio_release_host(card->func); 501 sdio_release_host(card->func);
493 kfree(chunk_buffer); 502 kfree(chunk_buffer);
494release_fw: 503release_fw:
@@ -624,7 +633,7 @@ static int if_sdio_prog_real(struct if_sdio_card *card)
624 ret = 0; 633 ret = 0;
625 634
626release: 635release:
627 sdio_set_block_size(card->func, 0); 636 sdio_set_block_size(card->func, IF_SDIO_BLOCK_SIZE);
628 sdio_release_host(card->func); 637 sdio_release_host(card->func);
629 kfree(chunk_buffer); 638 kfree(chunk_buffer);
630release_fw: 639release_fw:
diff --git a/drivers/net/wireless/libertas/if_sdio.h b/drivers/net/wireless/libertas/if_sdio.h
index 533bdfbf5d2..37ada2c29aa 100644
--- a/drivers/net/wireless/libertas/if_sdio.h
+++ b/drivers/net/wireless/libertas/if_sdio.h
@@ -42,4 +42,6 @@
42 42
43#define IF_SDIO_EVENT 0x80fc 43#define IF_SDIO_EVENT 0x80fc
44 44
45#define IF_SDIO_BLOCK_SIZE 256
46
45#endif 47#endif
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index 07311e71af9..dccd01fd1f1 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -731,7 +731,7 @@ static int if_spi_c2h_data(struct if_spi_card *card)
731 goto out; 731 goto out;
732 } else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) { 732 } else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
733 lbs_pr_err("%s: error: card has %d bytes of data, but " 733 lbs_pr_err("%s: error: card has %d bytes of data, but "
734 "our maximum skb size is %u\n", 734 "our maximum skb size is %lu\n",
735 __func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE); 735 __func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
736 err = -EINVAL; 736 err = -EINVAL;
737 goto out; 737 goto out;
@@ -1020,6 +1020,7 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1020 struct libertas_spi_platform_data *pdata = spi->dev.platform_data; 1020 struct libertas_spi_platform_data *pdata = spi->dev.platform_data;
1021 int err = 0; 1021 int err = 0;
1022 u32 scratch; 1022 u32 scratch;
1023 struct sched_param param = { .sched_priority = 1 };
1023 1024
1024 lbs_deb_enter(LBS_DEB_SPI); 1025 lbs_deb_enter(LBS_DEB_SPI);
1025 1026
@@ -1123,6 +1124,9 @@ static int __devinit if_spi_probe(struct spi_device *spi)
1123 lbs_pr_err("error creating SPI thread: err=%d\n", err); 1124 lbs_pr_err("error creating SPI thread: err=%d\n", err);
1124 goto remove_card; 1125 goto remove_card;
1125 } 1126 }
1127 if (sched_setscheduler(card->spi_thread, SCHED_FIFO, &param))
1128 lbs_pr_err("Error setting scheduler, using default.\n");
1129
1126 err = request_irq(spi->irq, if_spi_host_interrupt, 1130 err = request_irq(spi->irq, if_spi_host_interrupt,
1127 IRQF_TRIGGER_FALLING, "libertas_spi", card); 1131 IRQF_TRIGGER_FALLING, "libertas_spi", card);
1128 if (err) { 1132 if (err) {
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 8ae935ac32f..89575e44801 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -1307,8 +1307,10 @@ int lbs_start_card(struct lbs_private *priv)
1307 1307
1308 lbs_update_channel(priv); 1308 lbs_update_channel(priv);
1309 1309
1310 /* 5.0.16p0 is known to NOT support any mesh */ 1310 /* Check mesh FW version and appropriately send the mesh start
1311 if (priv->fwrelease > 0x05001000) { 1311 * command
1312 */
1313 if (priv->mesh_fw_ver == MESH_FW_OLD) {
1312 /* Enable mesh, if supported, and work out which TLV it uses. 1314 /* Enable mesh, if supported, and work out which TLV it uses.
1313 0x100 + 291 is an unofficial value used in 5.110.20.pXX 1315 0x100 + 291 is an unofficial value used in 5.110.20.pXX
1314 0x100 + 37 is the official value used in 5.110.21.pXX 1316 0x100 + 37 is the official value used in 5.110.21.pXX
@@ -1322,27 +1324,35 @@ int lbs_start_card(struct lbs_private *priv)
1322 It's just that 5.110.20.pXX will not have done anything 1324 It's just that 5.110.20.pXX will not have done anything
1323 useful */ 1325 useful */
1324 1326
1325 priv->mesh_tlv = 0x100 + 291; 1327 priv->mesh_tlv = TLV_TYPE_OLD_MESH_ID;
1326 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, 1328 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
1327 priv->curbssparams.channel)) { 1329 priv->curbssparams.channel)) {
1328 priv->mesh_tlv = 0x100 + 37; 1330 priv->mesh_tlv = TLV_TYPE_MESH_ID;
1329 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, 1331 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
1330 priv->curbssparams.channel)) 1332 priv->curbssparams.channel))
1331 priv->mesh_tlv = 0; 1333 priv->mesh_tlv = 0;
1332 } 1334 }
1333 if (priv->mesh_tlv) { 1335 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
1334 lbs_add_mesh(priv); 1336 /* 10.0.0.pXX new firmwares should succeed with TLV
1335 1337 * 0x100+37; Do not invoke command with old TLV.
1336 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh)) 1338 */
1337 lbs_pr_err("cannot register lbs_mesh attribute\n"); 1339 priv->mesh_tlv = TLV_TYPE_MESH_ID;
1338 1340 if (lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
1339 /* While rtap isn't related to mesh, only mesh-enabled 1341 priv->curbssparams.channel))
1340 * firmware implements the rtap functionality via 1342 priv->mesh_tlv = 0;
1341 * CMD_802_11_MONITOR_MODE. 1343 }
1342 */ 1344 if (priv->mesh_tlv) {
1343 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap)) 1345 lbs_add_mesh(priv);
1344 lbs_pr_err("cannot register lbs_rtap attribute\n"); 1346
1345 } 1347 if (device_create_file(&dev->dev, &dev_attr_lbs_mesh))
1348 lbs_pr_err("cannot register lbs_mesh attribute\n");
1349
1350 /* While rtap isn't related to mesh, only mesh-enabled
1351 * firmware implements the rtap functionality via
1352 * CMD_802_11_MONITOR_MODE.
1353 */
1354 if (device_create_file(&dev->dev, &dev_attr_lbs_rtap))
1355 lbs_pr_err("cannot register lbs_rtap attribute\n");
1346 } 1356 }
1347 1357
1348 lbs_debugfs_init_one(priv, dev); 1358 lbs_debugfs_init_one(priv, dev);
diff --git a/drivers/net/wireless/libertas/rx.c b/drivers/net/wireless/libertas/rx.c
index 8e669775cb5..65f02cc6752 100644
--- a/drivers/net/wireless/libertas/rx.c
+++ b/drivers/net/wireless/libertas/rx.c
@@ -25,7 +25,6 @@ struct rfc1042hdr {
25} __attribute__ ((packed)); 25} __attribute__ ((packed));
26 26
27struct rxpackethdr { 27struct rxpackethdr {
28 struct rxpd rx_pd;
29 struct eth803hdr eth803_hdr; 28 struct eth803hdr eth803_hdr;
30 struct rfc1042hdr rfc1042_hdr; 29 struct rfc1042hdr rfc1042_hdr;
31} __attribute__ ((packed)); 30} __attribute__ ((packed));
@@ -158,10 +157,18 @@ int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
158 if (priv->monitormode) 157 if (priv->monitormode)
159 return process_rxed_802_11_packet(priv, skb); 158 return process_rxed_802_11_packet(priv, skb);
160 159
161 p_rx_pkt = (struct rxpackethdr *) skb->data; 160 p_rx_pd = (struct rxpd *) skb->data;
162 p_rx_pd = &p_rx_pkt->rx_pd; 161 p_rx_pkt = (struct rxpackethdr *) ((u8 *)p_rx_pd +
163 if (priv->mesh_dev && (p_rx_pd->rx_control & RxPD_MESH_FRAME)) 162 le32_to_cpu(p_rx_pd->pkt_ptr));
164 dev = priv->mesh_dev; 163 if (priv->mesh_dev) {
164 if (priv->mesh_fw_ver == MESH_FW_OLD) {
165 if (p_rx_pd->rx_control & RxPD_MESH_FRAME)
166 dev = priv->mesh_dev;
167 } else if (priv->mesh_fw_ver == MESH_FW_NEW) {
168 if (p_rx_pd->u.bss.bss_num == MESH_IFACE_ID)
169 dev = priv->mesh_dev;
170 }
171 }
165 172
166 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data, 173 lbs_deb_hex(LBS_DEB_RX, "RX Data: Before chop rxpd", skb->data,
167 min_t(unsigned int, skb->len, 100)); 174 min_t(unsigned int, skb->len, 100));
@@ -174,20 +181,9 @@ int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
174 goto done; 181 goto done;
175 } 182 }
176 183
177 /* 184 lbs_deb_rx("rx data: skb->len - pkt_ptr = %d-%zd = %zd\n",
178 * Check rxpd status and update 802.3 stat, 185 skb->len, (size_t)le32_to_cpu(p_rx_pd->pkt_ptr),
179 */ 186 skb->len - (size_t)le32_to_cpu(p_rx_pd->pkt_ptr));
180 if (!(p_rx_pd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) {
181 lbs_deb_rx("rx err: frame received with bad status\n");
182 lbs_pr_alert("rxpd not ok\n");
183 dev->stats.rx_errors++;
184 ret = 0;
185 dev_kfree_skb(skb);
186 goto done;
187 }
188
189 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
190 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
191 187
192 lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr, 188 lbs_deb_hex(LBS_DEB_RX, "RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr,
193 sizeof(p_rx_pkt->eth803_hdr.dest_addr)); 189 sizeof(p_rx_pkt->eth803_hdr.dest_addr));
@@ -221,14 +217,14 @@ int lbs_process_rxed_packet(struct lbs_private *priv, struct sk_buff *skb)
221 /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header 217 /* Chop off the rxpd + the excess memory from the 802.2/llc/snap header
222 * that was removed 218 * that was removed
223 */ 219 */
224 hdrchop = (u8 *) p_ethhdr - (u8 *) p_rx_pkt; 220 hdrchop = (u8 *)p_ethhdr - (u8 *)p_rx_pd;
225 } else { 221 } else {
226 lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP", 222 lbs_deb_hex(LBS_DEB_RX, "RX Data: LLC/SNAP",
227 (u8 *) & p_rx_pkt->rfc1042_hdr, 223 (u8 *) & p_rx_pkt->rfc1042_hdr,
228 sizeof(p_rx_pkt->rfc1042_hdr)); 224 sizeof(p_rx_pkt->rfc1042_hdr));
229 225
230 /* Chop off the rxpd */ 226 /* Chop off the rxpd */
231 hdrchop = (u8 *) & p_rx_pkt->eth803_hdr - (u8 *) p_rx_pkt; 227 hdrchop = (u8 *)&p_rx_pkt->eth803_hdr - (u8 *)p_rx_pd;
232 } 228 }
233 229
234 /* Chop off the leading header bytes so the skb points to the start of 230 /* Chop off the leading header bytes so the skb points to the start of
@@ -334,14 +330,6 @@ static int process_rxed_802_11_packet(struct lbs_private *priv,
334 goto done; 330 goto done;
335 } 331 }
336 332
337 /*
338 * Check rxpd status and update 802.3 stat,
339 */
340 if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK))) {
341 //lbs_deb_rx("rx err: frame received with bad status\n");
342 dev->stats.rx_errors++;
343 }
344
345 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n", 333 lbs_deb_rx("rx data: skb->len-sizeof(RxPd) = %d-%zd = %zd\n",
346 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd)); 334 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
347 335
@@ -353,8 +341,6 @@ static int process_rxed_802_11_packet(struct lbs_private *priv,
353 radiotap_hdr.hdr.it_pad = 0; 341 radiotap_hdr.hdr.it_pad = 0;
354 radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr)); 342 radiotap_hdr.hdr.it_len = cpu_to_le16 (sizeof(struct rx_radiotap_hdr));
355 radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT); 343 radiotap_hdr.hdr.it_present = cpu_to_le32 (RX_RADIOTAP_PRESENT);
356 if (!(prxpd->status & cpu_to_le16(MRVDRV_RXPD_STATUS_OK)))
357 radiotap_hdr.flags |= IEEE80211_RADIOTAP_F_BADFCS;
358 radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate); 344 radiotap_hdr.rate = convert_mv_rate_to_radiotap(prxpd->rx_rate);
359 /* XXX must check no carryout */ 345 /* XXX must check no carryout */
360 radiotap_hdr.antsignal = prxpd->snr + prxpd->nf; 346 radiotap_hdr.antsignal = prxpd->snr + prxpd->nf;
diff --git a/drivers/net/wireless/libertas/tx.c b/drivers/net/wireless/libertas/tx.c
index f10aa39a6b6..160cfd8311c 100644
--- a/drivers/net/wireless/libertas/tx.c
+++ b/drivers/net/wireless/libertas/tx.c
@@ -132,8 +132,12 @@ int lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
132 txpd->tx_packet_length = cpu_to_le16(pkt_len); 132 txpd->tx_packet_length = cpu_to_le16(pkt_len);
133 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd)); 133 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
134 134
135 if (dev == priv->mesh_dev) 135 if (dev == priv->mesh_dev) {
136 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME); 136 if (priv->mesh_fw_ver == MESH_FW_OLD)
137 txpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
138 else if (priv->mesh_fw_ver == MESH_FW_NEW)
139 txpd->u.bss.bss_num = MESH_IFACE_ID;
140 }
137 141
138 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) &txpd, sizeof(struct txpd)); 142 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) &txpd, sizeof(struct txpd));
139 143
diff --git a/drivers/net/wireless/libertas/types.h b/drivers/net/wireless/libertas/types.h
index fb7a2d1a252..de03b9c9c20 100644
--- a/drivers/net/wireless/libertas/types.h
+++ b/drivers/net/wireless/libertas/types.h
@@ -94,6 +94,8 @@ struct ieeetypes_assocrsp {
94#define TLV_TYPE_TSFTIMESTAMP (PROPRIETARY_TLV_BASE_ID + 19) 94#define TLV_TYPE_TSFTIMESTAMP (PROPRIETARY_TLV_BASE_ID + 19)
95#define TLV_TYPE_RSSI_HIGH (PROPRIETARY_TLV_BASE_ID + 22) 95#define TLV_TYPE_RSSI_HIGH (PROPRIETARY_TLV_BASE_ID + 22)
96#define TLV_TYPE_SNR_HIGH (PROPRIETARY_TLV_BASE_ID + 23) 96#define TLV_TYPE_SNR_HIGH (PROPRIETARY_TLV_BASE_ID + 23)
97#define TLV_TYPE_MESH_ID (PROPRIETARY_TLV_BASE_ID + 37)
98#define TLV_TYPE_OLD_MESH_ID (PROPRIETARY_TLV_BASE_ID + 291)
97 99
98/** TLV related data structures*/ 100/** TLV related data structures*/
99struct mrvlietypesheader { 101struct mrvlietypesheader {
diff --git a/drivers/net/wireless/p54/p54.h b/drivers/net/wireless/p54/p54.h
index ecf8b6ed5a4..7fda1a9e263 100644
--- a/drivers/net/wireless/p54/p54.h
+++ b/drivers/net/wireless/p54/p54.h
@@ -125,6 +125,7 @@ struct p54_led_dev {
125 struct led_classdev led_dev; 125 struct led_classdev led_dev;
126 char name[P54_LED_MAX_NAME_LEN + 1]; 126 char name[P54_LED_MAX_NAME_LEN + 1];
127 127
128 unsigned int toggled;
128 unsigned int index; 129 unsigned int index;
129 unsigned int registered; 130 unsigned int registered;
130}; 131};
@@ -133,55 +134,74 @@ struct p54_led_dev {
133 134
134struct p54_common { 135struct p54_common {
135 struct ieee80211_hw *hw; 136 struct ieee80211_hw *hw;
136 u32 rx_start; 137 struct ieee80211_vif *vif;
137 u32 rx_end;
138 struct sk_buff_head tx_queue;
139 void (*tx)(struct ieee80211_hw *dev, struct sk_buff *skb); 138 void (*tx)(struct ieee80211_hw *dev, struct sk_buff *skb);
140 int (*open)(struct ieee80211_hw *dev); 139 int (*open)(struct ieee80211_hw *dev);
141 void (*stop)(struct ieee80211_hw *dev); 140 void (*stop)(struct ieee80211_hw *dev);
142 int mode; 141 struct sk_buff_head tx_queue;
142 struct mutex conf_mutex;
143
144 /* memory management (as seen by the firmware) */
145 u32 rx_start;
146 u32 rx_end;
143 u16 rx_mtu; 147 u16 rx_mtu;
144 u8 headroom; 148 u8 headroom;
145 u8 tailroom; 149 u8 tailroom;
146 struct mutex conf_mutex; 150
147 u8 mac_addr[ETH_ALEN]; 151 /* firmware/hardware info */
148 u8 bssid[ETH_ALEN]; 152 unsigned int tx_hdr_len;
153 unsigned int fw_var;
154 unsigned int fw_interface;
155 u8 version;
156
157 /* (e)DCF / QOS state */
158 bool use_short_slot;
159 struct ieee80211_tx_queue_stats tx_stats[8];
160 struct p54_edcf_queue_param qos_params[8];
161
162 /* Radio data */
163 u16 rxhw;
149 u8 rx_diversity_mask; 164 u8 rx_diversity_mask;
150 u8 tx_diversity_mask; 165 u8 tx_diversity_mask;
166 unsigned int output_power;
167 int noise;
168 /* calibration, output power limit and rssi<->dBm conversation data */
151 struct pda_iq_autocal_entry *iq_autocal; 169 struct pda_iq_autocal_entry *iq_autocal;
152 unsigned int iq_autocal_len; 170 unsigned int iq_autocal_len;
153 struct p54_cal_database *output_limit;
154 struct p54_cal_database *curve_data; 171 struct p54_cal_database *curve_data;
172 struct p54_cal_database *output_limit;
155 struct p54_rssi_linear_approximation rssical_db[IEEE80211_NUM_BANDS]; 173 struct p54_rssi_linear_approximation rssical_db[IEEE80211_NUM_BANDS];
174
175 /* BBP/MAC state */
176 u8 mac_addr[ETH_ALEN];
177 u8 bssid[ETH_ALEN];
178 u16 wakeup_timer;
156 unsigned int filter_flags; 179 unsigned int filter_flags;
157 bool use_short_slot; 180 int mode;
158 u16 rxhw; 181 u32 tsf_low32, tsf_high32;
159 u8 version;
160 unsigned int tx_hdr_len;
161 unsigned int fw_var;
162 unsigned int fw_interface;
163 unsigned int output_power;
164 u32 tsf_low32;
165 u32 tsf_high32;
166 u32 basic_rate_mask; 182 u32 basic_rate_mask;
167 u16 wakeup_timer;
168 u16 aid; 183 u16 aid;
169 struct ieee80211_tx_queue_stats tx_stats[8];
170 struct p54_edcf_queue_param qos_params[8];
171 struct ieee80211_low_level_stats stats;
172 struct delayed_work work;
173 struct sk_buff *cached_beacon; 184 struct sk_buff *cached_beacon;
174 int noise; 185
175 void *eeprom; 186 /* cryptographic engine information */
176 struct completion eeprom_comp;
177 u8 privacy_caps; 187 u8 privacy_caps;
178 u8 rx_keycache_size; 188 u8 rx_keycache_size;
189 unsigned long *used_rxkeys;
190
179 /* LED management */ 191 /* LED management */
180#ifdef CONFIG_P54_LEDS 192#ifdef CONFIG_MAC80211_LEDS
181 struct p54_led_dev assoc_led; 193 struct p54_led_dev leds[4];
182 struct p54_led_dev tx_led; 194 struct delayed_work led_work;
183#endif /* CONFIG_P54_LEDS */ 195#endif /* CONFIG_MAC80211_LEDS */
184 u16 softled_state; /* bit field of glowing LEDs */ 196 u16 softled_state; /* bit field of glowing LEDs */
197
198 /* statistics */
199 struct ieee80211_low_level_stats stats;
200 struct delayed_work work;
201
202 /* eeprom handling */
203 void *eeprom;
204 struct completion eeprom_comp;
185}; 205};
186 206
187int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb); 207int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb);
diff --git a/drivers/net/wireless/p54/p54common.c b/drivers/net/wireless/p54/p54common.c
index c8f0232ee5e..71394968d45 100644
--- a/drivers/net/wireless/p54/p54common.c
+++ b/drivers/net/wireless/p54/p54common.c
@@ -249,7 +249,7 @@ int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
249 dev->queues = P54_QUEUE_AC_NUM; 249 dev->queues = P54_QUEUE_AC_NUM;
250 } 250 }
251 251
252 if (!modparam_nohwcrypt) 252 if (!modparam_nohwcrypt) {
253 printk(KERN_INFO "%s: cryptographic accelerator " 253 printk(KERN_INFO "%s: cryptographic accelerator "
254 "WEP:%s, TKIP:%s, CCMP:%s\n", 254 "WEP:%s, TKIP:%s, CCMP:%s\n",
255 wiphy_name(dev->wiphy), 255 wiphy_name(dev->wiphy),
@@ -259,6 +259,26 @@ int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
259 (priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP) ? 259 (priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP) ?
260 "YES" : "no"); 260 "YES" : "no");
261 261
262 if (priv->rx_keycache_size) {
263 /*
264 * NOTE:
265 *
266 * The firmware provides at most 255 (0 - 254) slots
267 * for keys which are then used to offload decryption.
268 * As a result the 255 entry (aka 0xff) can be used
269 * safely by the driver to mark keys that didn't fit
270 * into the full cache. This trick saves us from
271 * keeping a extra list for uploaded keys.
272 */
273
274 priv->used_rxkeys = kzalloc(BITS_TO_LONGS(
275 priv->rx_keycache_size), GFP_KERNEL);
276
277 if (!priv->used_rxkeys)
278 return -ENOMEM;
279 }
280 }
281
262 return 0; 282 return 0;
263} 283}
264EXPORT_SYMBOL_GPL(p54_parse_firmware); 284EXPORT_SYMBOL_GPL(p54_parse_firmware);
@@ -749,8 +769,6 @@ static int p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb)
749 769
750 rx_status.signal = p54_rssi_to_dbm(dev, hdr->rssi); 770 rx_status.signal = p54_rssi_to_dbm(dev, hdr->rssi);
751 rx_status.noise = priv->noise; 771 rx_status.noise = priv->noise;
752 /* XX correct? */
753 rx_status.qual = (100 * hdr->rssi) / 127;
754 if (hdr->rate & 0x10) 772 if (hdr->rate & 0x10)
755 rx_status.flag |= RX_FLAG_SHORTPRE; 773 rx_status.flag |= RX_FLAG_SHORTPRE;
756 if (dev->conf.channel->band == IEEE80211_BAND_5GHZ) 774 if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
@@ -1044,6 +1062,7 @@ static void p54_rx_stats(struct ieee80211_hw *dev, struct sk_buff *skb)
1044 1062
1045static void p54_rx_trap(struct ieee80211_hw *dev, struct sk_buff *skb) 1063static void p54_rx_trap(struct ieee80211_hw *dev, struct sk_buff *skb)
1046{ 1064{
1065 struct p54_common *priv = dev->priv;
1047 struct p54_hdr *hdr = (struct p54_hdr *) skb->data; 1066 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
1048 struct p54_trap *trap = (struct p54_trap *) hdr->data; 1067 struct p54_trap *trap = (struct p54_trap *) hdr->data;
1049 u16 event = le16_to_cpu(trap->event); 1068 u16 event = le16_to_cpu(trap->event);
@@ -1057,6 +1076,8 @@ static void p54_rx_trap(struct ieee80211_hw *dev, struct sk_buff *skb)
1057 wiphy_name(dev->wiphy), freq); 1076 wiphy_name(dev->wiphy), freq);
1058 break; 1077 break;
1059 case P54_TRAP_NO_BEACON: 1078 case P54_TRAP_NO_BEACON:
1079 if (priv->vif)
1080 ieee80211_beacon_loss(priv->vif);
1060 break; 1081 break;
1061 case P54_TRAP_SCAN: 1082 case P54_TRAP_SCAN:
1062 break; 1083 break;
@@ -1452,7 +1473,8 @@ static int p54_tx_fill(struct ieee80211_hw *dev, struct sk_buff *skb,
1452 1473
1453 if (info->control.sta) 1474 if (info->control.sta)
1454 *aid = info->control.sta->aid; 1475 *aid = info->control.sta->aid;
1455 else 1476
1477 if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
1456 *flags |= P54_HDR_FLAG_DATA_OUT_NOCANCEL; 1478 *flags |= P54_HDR_FLAG_DATA_OUT_NOCANCEL;
1457 break; 1479 break;
1458 } 1480 }
@@ -1939,7 +1961,8 @@ static int p54_set_ps(struct ieee80211_hw *dev)
1939 int i; 1961 int i;
1940 1962
1941 if (dev->conf.flags & IEEE80211_CONF_PS) 1963 if (dev->conf.flags & IEEE80211_CONF_PS)
1942 mode = P54_PSM | P54_PSM_DTIM | P54_PSM_MCBC; 1964 mode = P54_PSM | P54_PSM_BEACON_TIMEOUT | P54_PSM_DTIM |
1965 P54_PSM_CHECKSUM | P54_PSM_MCBC;
1943 else 1966 else
1944 mode = P54_PSM_CAM; 1967 mode = P54_PSM_CAM;
1945 1968
@@ -1957,9 +1980,10 @@ static int p54_set_ps(struct ieee80211_hw *dev)
1957 psm->intervals[i].periods = cpu_to_le16(1); 1980 psm->intervals[i].periods = cpu_to_le16(1);
1958 } 1981 }
1959 1982
1960 psm->beacon_rssi_skip_max = 60; 1983 psm->beacon_rssi_skip_max = 200;
1961 psm->rssi_delta_threshold = 0; 1984 psm->rssi_delta_threshold = 0;
1962 psm->nr = 0; 1985 psm->nr = 10;
1986 psm->exclude[0] = 0;
1963 1987
1964 priv->tx(dev, skb); 1988 priv->tx(dev, skb);
1965 1989
@@ -2088,6 +2112,9 @@ static void p54_stop(struct ieee80211_hw *dev)
2088 priv->softled_state = 0; 2112 priv->softled_state = 0;
2089 p54_set_leds(dev); 2113 p54_set_leds(dev);
2090 2114
2115#ifdef CONFIG_P54_LEDS
2116 cancel_delayed_work_sync(&priv->led_work);
2117#endif /* CONFIG_P54_LEDS */
2091 cancel_delayed_work_sync(&priv->work); 2118 cancel_delayed_work_sync(&priv->work);
2092 if (priv->cached_beacon) 2119 if (priv->cached_beacon)
2093 p54_tx_cancel(dev, priv->cached_beacon); 2120 p54_tx_cancel(dev, priv->cached_beacon);
@@ -2111,6 +2138,8 @@ static int p54_add_interface(struct ieee80211_hw *dev,
2111 return -EOPNOTSUPP; 2138 return -EOPNOTSUPP;
2112 } 2139 }
2113 2140
2141 priv->vif = conf->vif;
2142
2114 switch (conf->type) { 2143 switch (conf->type) {
2115 case NL80211_IFTYPE_STATION: 2144 case NL80211_IFTYPE_STATION:
2116 case NL80211_IFTYPE_ADHOC: 2145 case NL80211_IFTYPE_ADHOC:
@@ -2135,6 +2164,7 @@ static void p54_remove_interface(struct ieee80211_hw *dev,
2135 struct p54_common *priv = dev->priv; 2164 struct p54_common *priv = dev->priv;
2136 2165
2137 mutex_lock(&priv->conf_mutex); 2166 mutex_lock(&priv->conf_mutex);
2167 priv->vif = NULL;
2138 if (priv->cached_beacon) 2168 if (priv->cached_beacon)
2139 p54_tx_cancel(dev, priv->cached_beacon); 2169 p54_tx_cancel(dev, priv->cached_beacon);
2140 priv->mode = NL80211_IFTYPE_MONITOR; 2170 priv->mode = NL80211_IFTYPE_MONITOR;
@@ -2344,61 +2374,84 @@ static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
2344 struct p54_common *priv = dev->priv; 2374 struct p54_common *priv = dev->priv;
2345 struct sk_buff *skb; 2375 struct sk_buff *skb;
2346 struct p54_keycache *rxkey; 2376 struct p54_keycache *rxkey;
2377 int slot, ret = 0;
2347 u8 algo = 0; 2378 u8 algo = 0;
2348 2379
2349 if (modparam_nohwcrypt) 2380 if (modparam_nohwcrypt)
2350 return -EOPNOTSUPP; 2381 return -EOPNOTSUPP;
2351 2382
2352 if (cmd == DISABLE_KEY) 2383 mutex_lock(&priv->conf_mutex);
2353 algo = 0; 2384 if (cmd == SET_KEY) {
2354 else {
2355 switch (key->alg) { 2385 switch (key->alg) {
2356 case ALG_TKIP: 2386 case ALG_TKIP:
2357 if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL | 2387 if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL |
2358 BR_DESC_PRIV_CAP_TKIP))) 2388 BR_DESC_PRIV_CAP_TKIP))) {
2359 return -EOPNOTSUPP; 2389 ret = -EOPNOTSUPP;
2390 goto out_unlock;
2391 }
2360 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 2392 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2361 algo = P54_CRYPTO_TKIPMICHAEL; 2393 algo = P54_CRYPTO_TKIPMICHAEL;
2362 break; 2394 break;
2363 case ALG_WEP: 2395 case ALG_WEP:
2364 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP)) 2396 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP)) {
2365 return -EOPNOTSUPP; 2397 ret = -EOPNOTSUPP;
2398 goto out_unlock;
2399 }
2366 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 2400 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2367 algo = P54_CRYPTO_WEP; 2401 algo = P54_CRYPTO_WEP;
2368 break; 2402 break;
2369 case ALG_CCMP: 2403 case ALG_CCMP:
2370 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP)) 2404 if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP)) {
2371 return -EOPNOTSUPP; 2405 ret = -EOPNOTSUPP;
2406 goto out_unlock;
2407 }
2372 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 2408 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2373 algo = P54_CRYPTO_AESCCMP; 2409 algo = P54_CRYPTO_AESCCMP;
2374 break; 2410 break;
2375 default: 2411 default:
2376 return -EOPNOTSUPP; 2412 ret = -EOPNOTSUPP;
2413 goto out_unlock;
2377 } 2414 }
2378 } 2415 slot = bitmap_find_free_region(priv->used_rxkeys,
2416 priv->rx_keycache_size, 0);
2379 2417
2380 if (key->keyidx > priv->rx_keycache_size) { 2418 if (slot < 0) {
2381 /* 2419 /*
2382 * The device supports the choosen algorithm, but the firmware 2420 * The device supports the choosen algorithm, but the
2383 * does not provide enough key slots to store all of them. 2421 * firmware does not provide enough key slots to store
2384 * So, incoming frames have to be decoded by the mac80211 stack, 2422 * all of them.
2385 * but we can still offload encryption for outgoing frames. 2423 * But encryption offload for outgoing frames is always
2386 */ 2424 * possible, so we just pretend that the upload was
2425 * successful and do the decryption in software.
2426 */
2387 2427
2388 return 0; 2428 /* mark the key as invalid. */
2429 key->hw_key_idx = 0xff;
2430 goto out_unlock;
2431 }
2432 } else {
2433 slot = key->hw_key_idx;
2434
2435 if (slot == 0xff) {
2436 /* This key was not uploaded into the rx key cache. */
2437
2438 goto out_unlock;
2439 }
2440
2441 bitmap_release_region(priv->used_rxkeys, slot, 0);
2442 algo = 0;
2389 } 2443 }
2390 2444
2391 mutex_lock(&priv->conf_mutex);
2392 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey), 2445 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey),
2393 P54_CONTROL_TYPE_RX_KEYCACHE, GFP_ATOMIC); 2446 P54_CONTROL_TYPE_RX_KEYCACHE, GFP_KERNEL);
2394 if (!skb) { 2447 if (!skb) {
2395 mutex_unlock(&priv->conf_mutex); 2448 bitmap_release_region(priv->used_rxkeys, slot, 0);
2396 return -ENOMEM; 2449 ret = -ENOSPC;
2450 goto out_unlock;
2397 } 2451 }
2398 2452
2399 /* TODO: some devices have 4 more free slots for rx keys */
2400 rxkey = (struct p54_keycache *)skb_put(skb, sizeof(*rxkey)); 2453 rxkey = (struct p54_keycache *)skb_put(skb, sizeof(*rxkey));
2401 rxkey->entry = key->keyidx; 2454 rxkey->entry = slot;
2402 rxkey->key_id = key->keyidx; 2455 rxkey->key_id = key->keyidx;
2403 rxkey->key_type = algo; 2456 rxkey->key_type = algo;
2404 if (sta) 2457 if (sta)
@@ -2416,11 +2469,51 @@ static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
2416 } 2469 }
2417 2470
2418 priv->tx(dev, skb); 2471 priv->tx(dev, skb);
2472 key->hw_key_idx = slot;
2473
2474out_unlock:
2419 mutex_unlock(&priv->conf_mutex); 2475 mutex_unlock(&priv->conf_mutex);
2420 return 0; 2476 return ret;
2421} 2477}
2422 2478
2423#ifdef CONFIG_P54_LEDS 2479#ifdef CONFIG_P54_LEDS
2480static void p54_update_leds(struct work_struct *work)
2481{
2482 struct p54_common *priv = container_of(work, struct p54_common,
2483 led_work.work);
2484 int err, i, tmp, blink_delay = 400;
2485 bool rerun = false;
2486
2487 /* Don't toggle the LED, when the device is down. */
2488 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
2489 return ;
2490
2491 for (i = 0; i < ARRAY_SIZE(priv->leds); i++)
2492 if (priv->leds[i].toggled) {
2493 priv->softled_state |= BIT(i);
2494
2495 tmp = 70 + 200 / (priv->leds[i].toggled);
2496 if (tmp < blink_delay)
2497 blink_delay = tmp;
2498
2499 if (priv->leds[i].led_dev.brightness == LED_OFF)
2500 rerun = true;
2501
2502 priv->leds[i].toggled =
2503 !!priv->leds[i].led_dev.brightness;
2504 } else
2505 priv->softled_state &= ~BIT(i);
2506
2507 err = p54_set_leds(priv->hw);
2508 if (err && net_ratelimit())
2509 printk(KERN_ERR "%s: failed to update LEDs.\n",
2510 wiphy_name(priv->hw->wiphy));
2511
2512 if (rerun)
2513 queue_delayed_work(priv->hw->workqueue, &priv->led_work,
2514 msecs_to_jiffies(blink_delay));
2515}
2516
2424static void p54_led_brightness_set(struct led_classdev *led_dev, 2517static void p54_led_brightness_set(struct led_classdev *led_dev,
2425 enum led_brightness brightness) 2518 enum led_brightness brightness)
2426{ 2519{
@@ -2428,28 +2521,23 @@ static void p54_led_brightness_set(struct led_classdev *led_dev,
2428 led_dev); 2521 led_dev);
2429 struct ieee80211_hw *dev = led->hw_dev; 2522 struct ieee80211_hw *dev = led->hw_dev;
2430 struct p54_common *priv = dev->priv; 2523 struct p54_common *priv = dev->priv;
2431 int err;
2432 2524
2433 /* Don't toggle the LED, when the device is down. */
2434 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) 2525 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
2435 return ; 2526 return ;
2436 2527
2437 if (brightness != LED_OFF) 2528 if (brightness) {
2438 priv->softled_state |= BIT(led->index); 2529 led->toggled++;
2439 else 2530 queue_delayed_work(priv->hw->workqueue, &priv->led_work,
2440 priv->softled_state &= ~BIT(led->index); 2531 HZ/10);
2441 2532 }
2442 err = p54_set_leds(dev);
2443 if (err && net_ratelimit())
2444 printk(KERN_ERR "%s: failed to update %s LED.\n",
2445 wiphy_name(dev->wiphy), led_dev->name);
2446} 2533}
2447 2534
2448static int p54_register_led(struct ieee80211_hw *dev, 2535static int p54_register_led(struct ieee80211_hw *dev,
2449 struct p54_led_dev *led,
2450 unsigned int led_index, 2536 unsigned int led_index,
2451 char *name, char *trigger) 2537 char *name, char *trigger)
2452{ 2538{
2539 struct p54_common *priv = dev->priv;
2540 struct p54_led_dev *led = &priv->leds[led_index];
2453 int err; 2541 int err;
2454 2542
2455 if (led->registered) 2543 if (led->registered)
@@ -2482,19 +2570,30 @@ static int p54_init_leds(struct ieee80211_hw *dev)
2482 * TODO: 2570 * TODO:
2483 * Figure out if the EEPROM contains some hints about the number 2571 * Figure out if the EEPROM contains some hints about the number
2484 * of available/programmable LEDs of the device. 2572 * of available/programmable LEDs of the device.
2485 * But for now, we can assume that we have two programmable LEDs.
2486 */ 2573 */
2487 2574
2488 err = p54_register_led(dev, &priv->assoc_led, 0, "assoc", 2575 INIT_DELAYED_WORK(&priv->led_work, p54_update_leds);
2576
2577 err = p54_register_led(dev, 0, "assoc",
2489 ieee80211_get_assoc_led_name(dev)); 2578 ieee80211_get_assoc_led_name(dev));
2490 if (err) 2579 if (err)
2491 return err; 2580 return err;
2492 2581
2493 err = p54_register_led(dev, &priv->tx_led, 1, "tx", 2582 err = p54_register_led(dev, 1, "tx",
2494 ieee80211_get_tx_led_name(dev)); 2583 ieee80211_get_tx_led_name(dev));
2495 if (err) 2584 if (err)
2496 return err; 2585 return err;
2497 2586
2587 err = p54_register_led(dev, 2, "rx",
2588 ieee80211_get_rx_led_name(dev));
2589 if (err)
2590 return err;
2591
2592 err = p54_register_led(dev, 3, "radio",
2593 ieee80211_get_radio_led_name(dev));
2594 if (err)
2595 return err;
2596
2498 err = p54_set_leds(dev); 2597 err = p54_set_leds(dev);
2499 return err; 2598 return err;
2500} 2599}
@@ -2502,11 +2601,11 @@ static int p54_init_leds(struct ieee80211_hw *dev)
2502static void p54_unregister_leds(struct ieee80211_hw *dev) 2601static void p54_unregister_leds(struct ieee80211_hw *dev)
2503{ 2602{
2504 struct p54_common *priv = dev->priv; 2603 struct p54_common *priv = dev->priv;
2604 int i;
2505 2605
2506 if (priv->tx_led.registered) 2606 for (i = 0; i < ARRAY_SIZE(priv->leds); i++)
2507 led_classdev_unregister(&priv->tx_led.led_dev); 2607 if (priv->leds[i].registered)
2508 if (priv->assoc_led.registered) 2608 led_classdev_unregister(&priv->leds[i].led_dev);
2509 led_classdev_unregister(&priv->assoc_led.led_dev);
2510} 2609}
2511#endif /* CONFIG_P54_LEDS */ 2610#endif /* CONFIG_P54_LEDS */
2512 2611
@@ -2607,21 +2706,10 @@ void p54_free_common(struct ieee80211_hw *dev)
2607 kfree(priv->iq_autocal); 2706 kfree(priv->iq_autocal);
2608 kfree(priv->output_limit); 2707 kfree(priv->output_limit);
2609 kfree(priv->curve_data); 2708 kfree(priv->curve_data);
2709 kfree(priv->used_rxkeys);
2610 2710
2611#ifdef CONFIG_P54_LEDS 2711#ifdef CONFIG_P54_LEDS
2612 p54_unregister_leds(dev); 2712 p54_unregister_leds(dev);
2613#endif /* CONFIG_P54_LEDS */ 2713#endif /* CONFIG_P54_LEDS */
2614} 2714}
2615EXPORT_SYMBOL_GPL(p54_free_common); 2715EXPORT_SYMBOL_GPL(p54_free_common);
2616
2617static int __init p54_init(void)
2618{
2619 return 0;
2620}
2621
2622static void __exit p54_exit(void)
2623{
2624}
2625
2626module_init(p54_init);
2627module_exit(p54_exit);
diff --git a/drivers/net/wireless/p54/p54spi.c b/drivers/net/wireless/p54/p54spi.c
index d1fe577de3d..59a5e778bb0 100644
--- a/drivers/net/wireless/p54/p54spi.c
+++ b/drivers/net/wireless/p54/p54spi.c
@@ -167,18 +167,36 @@ static const struct p54spi_spi_reg p54spi_registers_array[] =
167static int p54spi_wait_bit(struct p54s_priv *priv, u16 reg, __le32 bits) 167static int p54spi_wait_bit(struct p54s_priv *priv, u16 reg, __le32 bits)
168{ 168{
169 int i; 169 int i;
170 __le32 buffer;
171 170
172 for (i = 0; i < 2000; i++) { 171 for (i = 0; i < 2000; i++) {
173 p54spi_spi_read(priv, reg, &buffer, sizeof(buffer)); 172 __le32 buffer = p54spi_read32(priv, reg);
174 if (buffer == bits) 173 if ((buffer & bits) == bits)
175 return 1; 174 return 1;
176 175
177 msleep(1); 176 msleep(0);
178 } 177 }
179 return 0; 178 return 0;
180} 179}
181 180
181static int p54spi_spi_write_dma(struct p54s_priv *priv, __le32 base,
182 const void *buf, size_t len)
183{
184 p54spi_write16(priv, SPI_ADRS_DMA_WRITE_CTRL,
185 cpu_to_le16(SPI_DMA_WRITE_CTRL_ENABLE));
186
187 if (!p54spi_wait_bit(priv, SPI_ADRS_DMA_WRITE_CTRL,
188 cpu_to_le32(HOST_ALLOWED))) {
189 dev_err(&priv->spi->dev, "spi_write_dma not allowed "
190 "to DMA write.\n");
191 return -EAGAIN;
192 }
193
194 p54spi_write16(priv, SPI_ADRS_DMA_WRITE_LEN, cpu_to_le16(len));
195 p54spi_write32(priv, SPI_ADRS_DMA_WRITE_BASE, base);
196 p54spi_spi_write(priv, SPI_ADRS_DMA_DATA, buf, len);
197 return 0;
198}
199
182static int p54spi_request_firmware(struct ieee80211_hw *dev) 200static int p54spi_request_firmware(struct ieee80211_hw *dev)
183{ 201{
184 struct p54s_priv *priv = dev->priv; 202 struct p54s_priv *priv = dev->priv;
@@ -228,8 +246,15 @@ static int p54spi_request_eeprom(struct ieee80211_hw *dev)
228static int p54spi_upload_firmware(struct ieee80211_hw *dev) 246static int p54spi_upload_firmware(struct ieee80211_hw *dev)
229{ 247{
230 struct p54s_priv *priv = dev->priv; 248 struct p54s_priv *priv = dev->priv;
231 unsigned long fw_len, fw_addr; 249 unsigned long fw_len, _fw_len;
232 long _fw_len; 250 unsigned int offset = 0;
251 int err = 0;
252 u8 *fw;
253
254 fw_len = priv->firmware->size;
255 fw = kmemdup(priv->firmware->data, fw_len, GFP_KERNEL);
256 if (!fw)
257 return -ENOMEM;
233 258
234 /* stop the device */ 259 /* stop the device */
235 p54spi_write16(priv, SPI_ADRS_DEV_CTRL_STAT, cpu_to_le16( 260 p54spi_write16(priv, SPI_ADRS_DEV_CTRL_STAT, cpu_to_le16(
@@ -244,36 +269,17 @@ static int p54spi_upload_firmware(struct ieee80211_hw *dev)
244 269
245 msleep(TARGET_BOOT_SLEEP); 270 msleep(TARGET_BOOT_SLEEP);
246 271
247 fw_addr = ISL38XX_DEV_FIRMWARE_ADDR;
248 fw_len = priv->firmware->size;
249
250 while (fw_len > 0) { 272 while (fw_len > 0) {
251 _fw_len = min_t(long, fw_len, SPI_MAX_PACKET_SIZE); 273 _fw_len = min_t(long, fw_len, SPI_MAX_PACKET_SIZE);
252 274
253 p54spi_write16(priv, SPI_ADRS_DMA_WRITE_CTRL, 275 err = p54spi_spi_write_dma(priv, cpu_to_le32(
254 cpu_to_le16(SPI_DMA_WRITE_CTRL_ENABLE)); 276 ISL38XX_DEV_FIRMWARE_ADDR + offset),
255 277 (fw + offset), _fw_len);
256 if (p54spi_wait_bit(priv, SPI_ADRS_DMA_WRITE_CTRL, 278 if (err < 0)
257 cpu_to_le32(HOST_ALLOWED)) == 0) { 279 goto out;
258 dev_err(&priv->spi->dev, "fw_upload not allowed "
259 "to DMA write.");
260 return -EAGAIN;
261 }
262
263 p54spi_write16(priv, SPI_ADRS_DMA_WRITE_LEN,
264 cpu_to_le16(_fw_len));
265 p54spi_write32(priv, SPI_ADRS_DMA_WRITE_BASE,
266 cpu_to_le32(fw_addr));
267
268 p54spi_spi_write(priv, SPI_ADRS_DMA_DATA,
269 &priv->firmware->data, _fw_len);
270 280
271 fw_len -= _fw_len; 281 fw_len -= _fw_len;
272 fw_addr += _fw_len; 282 offset += _fw_len;
273
274 /* FIXME: I think this doesn't work if firmware is large,
275 * this loop goes to second round. fw->data is not
276 * increased at all! */
277 } 283 }
278 284
279 BUG_ON(fw_len != 0); 285 BUG_ON(fw_len != 0);
@@ -292,7 +298,10 @@ static int p54spi_upload_firmware(struct ieee80211_hw *dev)
292 p54spi_write16(priv, SPI_ADRS_DEV_CTRL_STAT, cpu_to_le16( 298 p54spi_write16(priv, SPI_ADRS_DEV_CTRL_STAT, cpu_to_le16(
293 SPI_CTRL_STAT_HOST_OVERRIDE | SPI_CTRL_STAT_RAM_BOOT)); 299 SPI_CTRL_STAT_HOST_OVERRIDE | SPI_CTRL_STAT_RAM_BOOT));
294 msleep(TARGET_BOOT_SLEEP); 300 msleep(TARGET_BOOT_SLEEP);
295 return 0; 301
302out:
303 kfree(fw);
304 return err;
296} 305}
297 306
298static void p54spi_power_off(struct p54s_priv *priv) 307static void p54spi_power_off(struct p54s_priv *priv)
@@ -320,21 +329,15 @@ static inline void p54spi_int_ack(struct p54s_priv *priv, u32 val)
320 329
321static void p54spi_wakeup(struct p54s_priv *priv) 330static void p54spi_wakeup(struct p54s_priv *priv)
322{ 331{
323 unsigned long timeout;
324 u32 ints;
325
326 /* wake the chip */ 332 /* wake the chip */
327 p54spi_write32(priv, SPI_ADRS_ARM_INTERRUPTS, 333 p54spi_write32(priv, SPI_ADRS_ARM_INTERRUPTS,
328 cpu_to_le32(SPI_TARGET_INT_WAKEUP)); 334 cpu_to_le32(SPI_TARGET_INT_WAKEUP));
329 335
330 /* And wait for the READY interrupt */ 336 /* And wait for the READY interrupt */
331 timeout = jiffies + HZ; 337 if (!p54spi_wait_bit(priv, SPI_ADRS_HOST_INTERRUPTS,
332 338 cpu_to_le32(SPI_HOST_INT_READY))) {
333 ints = p54spi_read32(priv, SPI_ADRS_HOST_INTERRUPTS); 339 dev_err(&priv->spi->dev, "INT_READY timeout\n");
334 while (!(ints & SPI_HOST_INT_READY)) { 340 goto out;
335 if (time_after(jiffies, timeout))
336 goto out;
337 ints = p54spi_read32(priv, SPI_ADRS_HOST_INTERRUPTS);
338 } 341 }
339 342
340 p54spi_int_ack(priv, SPI_HOST_INT_READY); 343 p54spi_int_ack(priv, SPI_HOST_INT_READY);
@@ -385,7 +388,12 @@ static int p54spi_rx(struct p54s_priv *priv)
385 return 0; 388 return 0;
386 } 389 }
387 390
388 skb = dev_alloc_skb(len); 391
392 /* Firmware may insert up to 4 padding bytes after the lmac header,
393 * but it does not amend the size of SPI data transfer.
394 * Such packets has correct data size in header, thus referencing
395 * past the end of allocated skb. Reserve extra 4 bytes for this case */
396 skb = dev_alloc_skb(len + 4);
389 if (!skb) { 397 if (!skb) {
390 dev_err(&priv->spi->dev, "could not alloc skb"); 398 dev_err(&priv->spi->dev, "could not alloc skb");
391 return 0; 399 return 0;
@@ -393,6 +401,9 @@ static int p54spi_rx(struct p54s_priv *priv)
393 401
394 p54spi_spi_read(priv, SPI_ADRS_DMA_DATA, skb_put(skb, len), len); 402 p54spi_spi_read(priv, SPI_ADRS_DMA_DATA, skb_put(skb, len), len);
395 p54spi_sleep(priv); 403 p54spi_sleep(priv);
404 /* Put additional bytes to compensate for the possible
405 * alignment-caused truncation */
406 skb_put(skb, 4);
396 407
397 if (p54_rx(priv->hw, skb) == 0) 408 if (p54_rx(priv->hw, skb) == 0)
398 dev_kfree_skb(skb); 409 dev_kfree_skb(skb);
@@ -414,39 +425,27 @@ static irqreturn_t p54spi_interrupt(int irq, void *config)
414static int p54spi_tx_frame(struct p54s_priv *priv, struct sk_buff *skb) 425static int p54spi_tx_frame(struct p54s_priv *priv, struct sk_buff *skb)
415{ 426{
416 struct p54_hdr *hdr = (struct p54_hdr *) skb->data; 427 struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
417 struct p54s_dma_regs dma_regs;
418 unsigned long timeout;
419 int ret = 0; 428 int ret = 0;
420 u32 ints;
421 429
422 p54spi_wakeup(priv); 430 p54spi_wakeup(priv);
423 431
424 dma_regs.cmd = cpu_to_le16(SPI_DMA_WRITE_CTRL_ENABLE); 432 ret = p54spi_spi_write_dma(priv, hdr->req_id, skb->data, skb->len);
425 dma_regs.len = cpu_to_le16(skb->len); 433 if (ret < 0)
426 dma_regs.addr = hdr->req_id; 434 goto out;
427
428 p54spi_spi_write(priv, SPI_ADRS_DMA_WRITE_CTRL, &dma_regs,
429 sizeof(dma_regs));
430
431 p54spi_spi_write(priv, SPI_ADRS_DMA_DATA, skb->data, skb->len);
432 435
433 timeout = jiffies + 2 * HZ; 436 if (!p54spi_wait_bit(priv, SPI_ADRS_HOST_INTERRUPTS,
434 ints = p54spi_read32(priv, SPI_ADRS_HOST_INTERRUPTS); 437 cpu_to_le32(SPI_HOST_INT_WR_READY))) {
435 while (!(ints & SPI_HOST_INT_WR_READY)) { 438 dev_err(&priv->spi->dev, "WR_READY timeout\n");
436 if (time_after(jiffies, timeout)) { 439 ret = -1;
437 dev_err(&priv->spi->dev, "WR_READY timeout"); 440 goto out;
438 ret = -1;
439 goto out;
440 }
441 ints = p54spi_read32(priv, SPI_ADRS_HOST_INTERRUPTS);
442 } 441 }
443 442
444 p54spi_int_ack(priv, SPI_HOST_INT_WR_READY); 443 p54spi_int_ack(priv, SPI_HOST_INT_WR_READY);
445 p54spi_sleep(priv); 444 p54spi_sleep(priv);
446 445
447out:
448 if (FREE_AFTER_TX(skb)) 446 if (FREE_AFTER_TX(skb))
449 p54_free_skb(priv->hw, skb); 447 p54_free_skb(priv->hw, skb);
448out:
450 return ret; 449 return ret;
451} 450}
452 451
diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index db91db77650..52fc647e6cb 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -42,6 +42,7 @@
42#include <linux/ctype.h> 42#include <linux/ctype.h>
43#include <linux/spinlock.h> 43#include <linux/spinlock.h>
44#include <net/iw_handler.h> 44#include <net/iw_handler.h>
45#include <net/cfg80211.h>
45#include <linux/usb/usbnet.h> 46#include <linux/usb/usbnet.h>
46#include <linux/usb/rndis_host.h> 47#include <linux/usb/rndis_host.h>
47 48
@@ -316,25 +317,61 @@ enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_PSK, KEY_MGMT_NONE,
316 317
317#define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set)) 318#define COMMAND_BUFFER_SIZE (CONTROL_BUFFER_SIZE + sizeof(struct rndis_set))
318 319
320static const struct ieee80211_channel rndis_channels[] = {
321 { .center_freq = 2412 },
322 { .center_freq = 2417 },
323 { .center_freq = 2422 },
324 { .center_freq = 2427 },
325 { .center_freq = 2432 },
326 { .center_freq = 2437 },
327 { .center_freq = 2442 },
328 { .center_freq = 2447 },
329 { .center_freq = 2452 },
330 { .center_freq = 2457 },
331 { .center_freq = 2462 },
332 { .center_freq = 2467 },
333 { .center_freq = 2472 },
334 { .center_freq = 2484 },
335};
336
337static const struct ieee80211_rate rndis_rates[] = {
338 { .bitrate = 10 },
339 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
340 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
341 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
342 { .bitrate = 60 },
343 { .bitrate = 90 },
344 { .bitrate = 120 },
345 { .bitrate = 180 },
346 { .bitrate = 240 },
347 { .bitrate = 360 },
348 { .bitrate = 480 },
349 { .bitrate = 540 }
350};
351
319/* RNDIS device private data */ 352/* RNDIS device private data */
320struct rndis_wext_private { 353struct rndis_wext_private {
321 char name[32];
322
323 struct usbnet *usbdev; 354 struct usbnet *usbdev;
324 355
356 struct wireless_dev wdev;
357
358 struct cfg80211_scan_request *scan_request;
359
325 struct workqueue_struct *workqueue; 360 struct workqueue_struct *workqueue;
326 struct delayed_work stats_work; 361 struct delayed_work stats_work;
362 struct delayed_work scan_work;
327 struct work_struct work; 363 struct work_struct work;
328 struct mutex command_lock; 364 struct mutex command_lock;
329 spinlock_t stats_lock; 365 spinlock_t stats_lock;
330 unsigned long work_pending; 366 unsigned long work_pending;
331 367
368 struct ieee80211_supported_band band;
369 struct ieee80211_channel channels[ARRAY_SIZE(rndis_channels)];
370 struct ieee80211_rate rates[ARRAY_SIZE(rndis_rates)];
371
332 struct iw_statistics iwstats; 372 struct iw_statistics iwstats;
333 struct iw_statistics privstats; 373 struct iw_statistics privstats;
334 374
335 int nick_len;
336 char nick[32];
337
338 int caps; 375 int caps;
339 int multicast_size; 376 int multicast_size;
340 377
@@ -368,8 +405,22 @@ struct rndis_wext_private {
368 u8 command_buffer[COMMAND_BUFFER_SIZE]; 405 u8 command_buffer[COMMAND_BUFFER_SIZE];
369}; 406};
370 407
408/*
409 * cfg80211 ops
410 */
411static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex,
412 enum nl80211_iftype type, u32 *flags,
413 struct vif_params *params);
414
415static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
416 struct cfg80211_scan_request *request);
417
418static struct cfg80211_ops rndis_config_ops = {
419 .change_virtual_intf = rndis_change_virtual_intf,
420 .scan = rndis_scan,
421};
371 422
372static const int rates_80211g[8] = { 6, 9, 12, 18, 24, 36, 48, 54 }; 423static void *rndis_wiphy_privid = &rndis_wiphy_privid;
373 424
374static const int bcm4320_power_output[4] = { 25, 50, 75, 100 }; 425static const int bcm4320_power_output[4] = { 25, 50, 75, 100 };
375 426
@@ -1086,131 +1137,180 @@ static void set_multicast_list(struct usbnet *usbdev)
1086 1137
1087 1138
1088/* 1139/*
1089 * wireless extension handlers 1140 * cfg80211 ops
1090 */ 1141 */
1091 1142static int rndis_change_virtual_intf(struct wiphy *wiphy, int ifindex,
1092static int rndis_iw_commit(struct net_device *dev, 1143 enum nl80211_iftype type, u32 *flags,
1093 struct iw_request_info *info, union iwreq_data *wrqu, char *extra) 1144 struct vif_params *params)
1094{ 1145{
1095 /* dummy op */ 1146 struct net_device *dev;
1096 return 0; 1147 struct usbnet *usbdev;
1148 int mode;
1149
1150 /* we're under RTNL */
1151 dev = __dev_get_by_index(&init_net, ifindex);
1152 if (!dev)
1153 return -ENODEV;
1154 usbdev = netdev_priv(dev);
1155
1156 switch (type) {
1157 case NL80211_IFTYPE_ADHOC:
1158 mode = ndis_80211_infra_adhoc;
1159 break;
1160 case NL80211_IFTYPE_STATION:
1161 mode = ndis_80211_infra_infra;
1162 break;
1163 default:
1164 return -EINVAL;
1165 }
1166
1167 return set_infra_mode(usbdev, mode);
1097} 1168}
1098 1169
1099 1170
1100static int rndis_iw_get_range(struct net_device *dev, 1171#define SCAN_DELAY_JIFFIES (HZ)
1101 struct iw_request_info *info, union iwreq_data *wrqu, char *extra) 1172static int rndis_scan(struct wiphy *wiphy, struct net_device *dev,
1173 struct cfg80211_scan_request *request)
1102{ 1174{
1103 struct iw_range *range = (struct iw_range *)extra;
1104 struct usbnet *usbdev = netdev_priv(dev); 1175 struct usbnet *usbdev = netdev_priv(dev);
1105 struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev); 1176 struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
1106 int len, ret, i, j, num, has_80211g_rates; 1177 int ret;
1107 u8 rates[8]; 1178 __le32 tmp;
1108 __le32 tx_power;
1109 1179
1110 devdbg(usbdev, "SIOCGIWRANGE"); 1180 devdbg(usbdev, "cfg80211.scan");
1111 1181
1112 /* clear iw_range struct */ 1182 if (!request)
1113 memset(range, 0, sizeof(*range)); 1183 return -EINVAL;
1114 wrqu->data.length = sizeof(*range);
1115 1184
1116 range->txpower_capa = IW_TXPOW_MWATT; 1185 if (priv->scan_request && priv->scan_request != request)
1117 range->num_txpower = 1; 1186 return -EBUSY;
1118 if (priv->caps & CAP_SUPPORT_TXPOWER) {
1119 len = sizeof(tx_power);
1120 ret = rndis_query_oid(usbdev, OID_802_11_TX_POWER_LEVEL,
1121 &tx_power, &len);
1122 if (ret == 0 && le32_to_cpu(tx_power) != 0xFF)
1123 range->txpower[0] = le32_to_cpu(tx_power);
1124 else
1125 range->txpower[0] = get_bcm4320_power(priv);
1126 } else
1127 range->txpower[0] = get_bcm4320_power(priv);
1128 1187
1129 len = sizeof(rates); 1188 priv->scan_request = request;
1130 ret = rndis_query_oid(usbdev, OID_802_11_SUPPORTED_RATES, &rates, 1189
1131 &len); 1190 tmp = cpu_to_le32(1);
1132 has_80211g_rates = 0; 1191 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1192 sizeof(tmp));
1133 if (ret == 0) { 1193 if (ret == 0) {
1134 j = 0; 1194 /* Wait before retrieving scan results from device */
1135 for (i = 0; i < len; i++) { 1195 queue_delayed_work(priv->workqueue, &priv->scan_work,
1136 if (rates[i] == 0) 1196 SCAN_DELAY_JIFFIES);
1137 break; 1197 }
1138 range->bitrate[j] = (rates[i] & 0x7f) * 500000;
1139 /* check for non 802.11b rates */
1140 if (range->bitrate[j] == 6000000 ||
1141 range->bitrate[j] == 9000000 ||
1142 (range->bitrate[j] >= 12000000 &&
1143 range->bitrate[j] != 22000000))
1144 has_80211g_rates = 1;
1145 j++;
1146 }
1147 range->num_bitrates = j;
1148 } else
1149 range->num_bitrates = 0;
1150
1151 /* fill in 802.11g rates */
1152 if (has_80211g_rates) {
1153 num = range->num_bitrates;
1154 for (i = 0; i < ARRAY_SIZE(rates_80211g); i++) {
1155 for (j = 0; j < num; j++) {
1156 if (range->bitrate[j] ==
1157 rates_80211g[i] * 1000000)
1158 break;
1159 }
1160 if (j == num)
1161 range->bitrate[range->num_bitrates++] =
1162 rates_80211g[i] * 1000000;
1163 if (range->num_bitrates == IW_MAX_BITRATES)
1164 break;
1165 }
1166 1198
1167 /* estimated max real througput in bps */ 1199 return ret;
1168 range->throughput = 54 * 1000 * 1000 / 2; 1200}
1169 1201
1170 /* ~35% more with afterburner */ 1202
1171 if (priv->param_afterburner) 1203static struct cfg80211_bss *rndis_bss_info_update(struct usbnet *usbdev,
1172 range->throughput = range->throughput / 100 * 135; 1204 struct ndis_80211_bssid_ex *bssid)
1173 } else { 1205{
1174 /* estimated max real througput in bps */ 1206 struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
1175 range->throughput = 11 * 1000 * 1000 / 2; 1207 struct ieee80211_channel *channel;
1208 s32 signal;
1209 u64 timestamp;
1210 u16 capability;
1211 u16 beacon_interval;
1212 struct ndis_80211_fixed_ies *fixed;
1213 int ie_len, bssid_len;
1214 u8 *ie;
1215
1216 /* parse bssid structure */
1217 bssid_len = le32_to_cpu(bssid->length);
1218
1219 if (bssid_len < sizeof(struct ndis_80211_bssid_ex) +
1220 sizeof(struct ndis_80211_fixed_ies))
1221 return NULL;
1222
1223 fixed = (struct ndis_80211_fixed_ies *)bssid->ies;
1224
1225 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1226 ie_len = min(bssid_len - (int)sizeof(*bssid),
1227 (int)le32_to_cpu(bssid->ie_length));
1228 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1229 if (ie_len < 0)
1230 return NULL;
1231
1232 /* extract data for cfg80211_inform_bss */
1233 channel = ieee80211_get_channel(priv->wdev.wiphy,
1234 KHZ_TO_MHZ(le32_to_cpu(bssid->config.ds_config)));
1235 if (!channel)
1236 return NULL;
1237
1238 signal = level_to_qual(le32_to_cpu(bssid->rssi));
1239 timestamp = le64_to_cpu(*(__le64 *)fixed->timestamp);
1240 capability = le16_to_cpu(fixed->capabilities);
1241 beacon_interval = le16_to_cpu(fixed->beacon_interval);
1242
1243 return cfg80211_inform_bss(priv->wdev.wiphy, channel, bssid->mac,
1244 timestamp, capability, beacon_interval, ie, ie_len, signal,
1245 GFP_KERNEL);
1246}
1247
1248
1249static int rndis_check_bssid_list(struct usbnet *usbdev)
1250{
1251 void *buf = NULL;
1252 struct ndis_80211_bssid_list_ex *bssid_list;
1253 struct ndis_80211_bssid_ex *bssid;
1254 int ret = -EINVAL, len, count, bssid_len;
1255
1256 devdbg(usbdev, "check_bssid_list");
1257
1258 len = CONTROL_BUFFER_SIZE;
1259 buf = kmalloc(len, GFP_KERNEL);
1260 if (!buf) {
1261 ret = -ENOMEM;
1262 goto out;
1176 } 1263 }
1177 1264
1178 range->num_channels = 14; 1265 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1266 if (ret != 0)
1267 goto out;
1179 1268
1180 for (i = 0; (i < 14) && (i < IW_MAX_FREQUENCIES); i++) { 1269 bssid_list = buf;
1181 range->freq[i].i = i + 1; 1270 bssid = bssid_list->bssid;
1182 range->freq[i].m = ieee80211_dsss_chan_to_freq(i + 1) * 100000; 1271 bssid_len = le32_to_cpu(bssid->length);
1183 range->freq[i].e = 1; 1272 count = le32_to_cpu(bssid_list->num_items);
1273 devdbg(usbdev, "check_bssid_list: %d BSSIDs found", count);
1274
1275 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1276 rndis_bss_info_update(usbdev, bssid);
1277
1278 bssid = (void *)bssid + bssid_len;
1279 bssid_len = le32_to_cpu(bssid->length);
1280 count--;
1184 } 1281 }
1185 range->num_frequency = i;
1186 1282
1187 range->min_rts = 0; 1283out:
1188 range->max_rts = 2347; 1284 kfree(buf);
1189 range->min_frag = 256; 1285 return ret;
1190 range->max_frag = 2346; 1286}
1191 1287
1192 range->max_qual.qual = 100;
1193 range->max_qual.level = 154;
1194 range->max_qual.updated = IW_QUAL_QUAL_UPDATED
1195 | IW_QUAL_LEVEL_UPDATED
1196 | IW_QUAL_NOISE_INVALID;
1197 1288
1198 range->we_version_compiled = WIRELESS_EXT; 1289static void rndis_get_scan_results(struct work_struct *work)
1199 range->we_version_source = WIRELESS_EXT; 1290{
1291 struct rndis_wext_private *priv =
1292 container_of(work, struct rndis_wext_private, scan_work.work);
1293 struct usbnet *usbdev = priv->usbdev;
1294 int ret;
1295
1296 devdbg(usbdev, "get_scan_results");
1200 1297
1201 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | 1298 ret = rndis_check_bssid_list(usbdev);
1202 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; 1299
1203 return 0; 1300 cfg80211_scan_done(priv->scan_request, ret < 0);
1301
1302 priv->scan_request = NULL;
1204} 1303}
1205 1304
1206 1305
1207static int rndis_iw_get_name(struct net_device *dev, 1306/*
1307 * wireless extension handlers
1308 */
1309
1310static int rndis_iw_commit(struct net_device *dev,
1208 struct iw_request_info *info, union iwreq_data *wrqu, char *extra) 1311 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1209{ 1312{
1210 struct usbnet *usbdev = netdev_priv(dev); 1313 /* dummy op */
1211 struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
1212
1213 strcpy(wrqu->name, priv->name);
1214 return 0; 1314 return 0;
1215} 1315}
1216 1316
@@ -1422,55 +1522,6 @@ static int rndis_iw_get_auth(struct net_device *dev,
1422} 1522}
1423 1523
1424 1524
1425static int rndis_iw_get_mode(struct net_device *dev,
1426 struct iw_request_info *info,
1427 union iwreq_data *wrqu, char *extra)
1428{
1429 struct usbnet *usbdev = netdev_priv(dev);
1430 struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
1431
1432 switch (priv->infra_mode) {
1433 case ndis_80211_infra_adhoc:
1434 wrqu->mode = IW_MODE_ADHOC;
1435 break;
1436 case ndis_80211_infra_infra:
1437 wrqu->mode = IW_MODE_INFRA;
1438 break;
1439 /*case ndis_80211_infra_auto_unknown:*/
1440 default:
1441 wrqu->mode = IW_MODE_AUTO;
1442 break;
1443 }
1444 devdbg(usbdev, "SIOCGIWMODE: %08x", wrqu->mode);
1445 return 0;
1446}
1447
1448
1449static int rndis_iw_set_mode(struct net_device *dev,
1450 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1451{
1452 struct usbnet *usbdev = netdev_priv(dev);
1453 int mode;
1454
1455 devdbg(usbdev, "SIOCSIWMODE: %08x", wrqu->mode);
1456
1457 switch (wrqu->mode) {
1458 case IW_MODE_ADHOC:
1459 mode = ndis_80211_infra_adhoc;
1460 break;
1461 case IW_MODE_INFRA:
1462 mode = ndis_80211_infra_infra;
1463 break;
1464 /*case IW_MODE_AUTO:*/
1465 default:
1466 mode = ndis_80211_infra_auto_unknown;
1467 break;
1468 }
1469
1470 return set_infra_mode(usbdev, mode);
1471}
1472
1473
1474static int rndis_iw_set_encode(struct net_device *dev, 1525static int rndis_iw_set_encode(struct net_device *dev,
1475 struct iw_request_info *info, union iwreq_data *wrqu, char *extra) 1526 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1476{ 1527{
@@ -1619,198 +1670,6 @@ static int rndis_iw_set_encode_ext(struct net_device *dev,
1619} 1670}
1620 1671
1621 1672
1622static int rndis_iw_set_scan(struct net_device *dev,
1623 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1624{
1625 struct usbnet *usbdev = netdev_priv(dev);
1626 union iwreq_data evt;
1627 int ret = -EINVAL;
1628 __le32 tmp;
1629
1630 devdbg(usbdev, "SIOCSIWSCAN");
1631
1632 if (wrqu->data.flags == 0) {
1633 tmp = cpu_to_le32(1);
1634 ret = rndis_set_oid(usbdev, OID_802_11_BSSID_LIST_SCAN, &tmp,
1635 sizeof(tmp));
1636 evt.data.flags = 0;
1637 evt.data.length = 0;
1638 wireless_send_event(dev, SIOCGIWSCAN, &evt, NULL);
1639 }
1640 return ret;
1641}
1642
1643
1644static char *rndis_translate_scan(struct net_device *dev,
1645 struct iw_request_info *info, char *cev,
1646 char *end_buf,
1647 struct ndis_80211_bssid_ex *bssid)
1648{
1649 struct usbnet *usbdev = netdev_priv(dev);
1650 u8 *ie;
1651 char *current_val;
1652 int bssid_len, ie_len, i;
1653 u32 beacon, atim;
1654 struct iw_event iwe;
1655 unsigned char sbuf[32];
1656
1657 bssid_len = le32_to_cpu(bssid->length);
1658
1659 devdbg(usbdev, "BSSID %pM", bssid->mac);
1660 iwe.cmd = SIOCGIWAP;
1661 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1662 memcpy(iwe.u.ap_addr.sa_data, bssid->mac, ETH_ALEN);
1663 cev = iwe_stream_add_event(info, cev, end_buf, &iwe, IW_EV_ADDR_LEN);
1664
1665 devdbg(usbdev, "SSID(%d) %s", le32_to_cpu(bssid->ssid.length),
1666 bssid->ssid.essid);
1667 iwe.cmd = SIOCGIWESSID;
1668 iwe.u.essid.length = le32_to_cpu(bssid->ssid.length);
1669 iwe.u.essid.flags = 1;
1670 cev = iwe_stream_add_point(info, cev, end_buf, &iwe, bssid->ssid.essid);
1671
1672 devdbg(usbdev, "MODE %d", le32_to_cpu(bssid->net_infra));
1673 iwe.cmd = SIOCGIWMODE;
1674 switch (le32_to_cpu(bssid->net_infra)) {
1675 case ndis_80211_infra_adhoc:
1676 iwe.u.mode = IW_MODE_ADHOC;
1677 break;
1678 case ndis_80211_infra_infra:
1679 iwe.u.mode = IW_MODE_INFRA;
1680 break;
1681 /*case ndis_80211_infra_auto_unknown:*/
1682 default:
1683 iwe.u.mode = IW_MODE_AUTO;
1684 break;
1685 }
1686 cev = iwe_stream_add_event(info, cev, end_buf, &iwe, IW_EV_UINT_LEN);
1687
1688 devdbg(usbdev, "FREQ %d kHz", le32_to_cpu(bssid->config.ds_config));
1689 iwe.cmd = SIOCGIWFREQ;
1690 dsconfig_to_freq(le32_to_cpu(bssid->config.ds_config), &iwe.u.freq);
1691 cev = iwe_stream_add_event(info, cev, end_buf, &iwe, IW_EV_FREQ_LEN);
1692
1693 devdbg(usbdev, "QUAL %d", le32_to_cpu(bssid->rssi));
1694 iwe.cmd = IWEVQUAL;
1695 iwe.u.qual.qual = level_to_qual(le32_to_cpu(bssid->rssi));
1696 iwe.u.qual.level = le32_to_cpu(bssid->rssi);
1697 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
1698 | IW_QUAL_LEVEL_UPDATED
1699 | IW_QUAL_NOISE_INVALID;
1700 cev = iwe_stream_add_event(info, cev, end_buf, &iwe, IW_EV_QUAL_LEN);
1701
1702 devdbg(usbdev, "ENCODE %d", le32_to_cpu(bssid->privacy));
1703 iwe.cmd = SIOCGIWENCODE;
1704 iwe.u.data.length = 0;
1705 if (le32_to_cpu(bssid->privacy) == ndis_80211_priv_accept_all)
1706 iwe.u.data.flags = IW_ENCODE_DISABLED;
1707 else
1708 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1709
1710 cev = iwe_stream_add_point(info, cev, end_buf, &iwe, NULL);
1711
1712 devdbg(usbdev, "RATES:");
1713 current_val = cev + iwe_stream_lcp_len(info);
1714 iwe.cmd = SIOCGIWRATE;
1715 for (i = 0; i < sizeof(bssid->rates); i++) {
1716 if (bssid->rates[i] & 0x7f) {
1717 iwe.u.bitrate.value =
1718 ((bssid->rates[i] & 0x7f) *
1719 500000);
1720 devdbg(usbdev, " %d", iwe.u.bitrate.value);
1721 current_val = iwe_stream_add_value(info, cev,
1722 current_val, end_buf, &iwe,
1723 IW_EV_PARAM_LEN);
1724 }
1725 }
1726
1727 if ((current_val - cev) > iwe_stream_lcp_len(info))
1728 cev = current_val;
1729
1730 beacon = le32_to_cpu(bssid->config.beacon_period);
1731 devdbg(usbdev, "BCN_INT %d", beacon);
1732 iwe.cmd = IWEVCUSTOM;
1733 snprintf(sbuf, sizeof(sbuf), "bcn_int=%d", beacon);
1734 iwe.u.data.length = strlen(sbuf);
1735 cev = iwe_stream_add_point(info, cev, end_buf, &iwe, sbuf);
1736
1737 atim = le32_to_cpu(bssid->config.atim_window);
1738 devdbg(usbdev, "ATIM %d", atim);
1739 iwe.cmd = IWEVCUSTOM;
1740 snprintf(sbuf, sizeof(sbuf), "atim=%u", atim);
1741 iwe.u.data.length = strlen(sbuf);
1742 cev = iwe_stream_add_point(info, cev, end_buf, &iwe, sbuf);
1743
1744 ie = (void *)(bssid->ies + sizeof(struct ndis_80211_fixed_ies));
1745 ie_len = min(bssid_len - (int)sizeof(*bssid),
1746 (int)le32_to_cpu(bssid->ie_length));
1747 ie_len -= sizeof(struct ndis_80211_fixed_ies);
1748 while (ie_len >= 2 && 2 + ie[1] <= ie_len) {
1749 if ((ie[0] == WLAN_EID_GENERIC && ie[1] >= 4 &&
1750 memcmp(ie + 2, "\x00\x50\xf2\x01", 4) == 0) ||
1751 ie[0] == WLAN_EID_RSN) {
1752 devdbg(usbdev, "IE: WPA%d",
1753 (ie[0] == WLAN_EID_RSN) ? 2 : 1);
1754 iwe.cmd = IWEVGENIE;
1755 /* arbitrary cut-off at 64 */
1756 iwe.u.data.length = min(ie[1] + 2, 64);
1757 cev = iwe_stream_add_point(info, cev, end_buf, &iwe, ie);
1758 }
1759
1760 ie_len -= 2 + ie[1];
1761 ie += 2 + ie[1];
1762 }
1763
1764 return cev;
1765}
1766
1767
1768static int rndis_iw_get_scan(struct net_device *dev,
1769 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1770{
1771 struct usbnet *usbdev = netdev_priv(dev);
1772 void *buf = NULL;
1773 char *cev = extra;
1774 struct ndis_80211_bssid_list_ex *bssid_list;
1775 struct ndis_80211_bssid_ex *bssid;
1776 int ret = -EINVAL, len, count, bssid_len;
1777
1778 devdbg(usbdev, "SIOCGIWSCAN");
1779
1780 len = CONTROL_BUFFER_SIZE;
1781 buf = kmalloc(len, GFP_KERNEL);
1782 if (!buf) {
1783 ret = -ENOMEM;
1784 goto out;
1785 }
1786
1787 ret = rndis_query_oid(usbdev, OID_802_11_BSSID_LIST, buf, &len);
1788
1789 if (ret != 0)
1790 goto out;
1791
1792 bssid_list = buf;
1793 bssid = bssid_list->bssid;
1794 bssid_len = le32_to_cpu(bssid->length);
1795 count = le32_to_cpu(bssid_list->num_items);
1796 devdbg(usbdev, "SIOCGIWSCAN: %d BSSIDs found", count);
1797
1798 while (count && ((void *)bssid + bssid_len) <= (buf + len)) {
1799 cev = rndis_translate_scan(dev, info, cev,
1800 extra + IW_SCAN_MAX_DATA, bssid);
1801 bssid = (void *)bssid + bssid_len;
1802 bssid_len = le32_to_cpu(bssid->length);
1803 count--;
1804 }
1805
1806out:
1807 wrqu->data.length = cev - extra;
1808 wrqu->data.flags = 0;
1809 kfree(buf);
1810 return ret;
1811}
1812
1813
1814static int rndis_iw_set_genie(struct net_device *dev, 1673static int rndis_iw_set_genie(struct net_device *dev,
1815 struct iw_request_info *info, union iwreq_data *wrqu, char *extra) 1674 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1816{ 1675{
@@ -1936,39 +1795,6 @@ static int rndis_iw_get_frag(struct net_device *dev,
1936} 1795}
1937 1796
1938 1797
1939static int rndis_iw_set_nick(struct net_device *dev,
1940 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1941{
1942 struct usbnet *usbdev = netdev_priv(dev);
1943 struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
1944
1945 devdbg(usbdev, "SIOCSIWNICK");
1946
1947 priv->nick_len = wrqu->data.length;
1948 if (priv->nick_len > 32)
1949 priv->nick_len = 32;
1950
1951 memcpy(priv->nick, extra, priv->nick_len);
1952 return 0;
1953}
1954
1955
1956static int rndis_iw_get_nick(struct net_device *dev,
1957 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1958{
1959 struct usbnet *usbdev = netdev_priv(dev);
1960 struct rndis_wext_private *priv = get_rndis_wext_priv(usbdev);
1961
1962 wrqu->data.flags = 1;
1963 wrqu->data.length = priv->nick_len;
1964 memcpy(extra, priv->nick, priv->nick_len);
1965
1966 devdbg(usbdev, "SIOCGIWNICK: '%s'", priv->nick);
1967
1968 return 0;
1969}
1970
1971
1972static int rndis_iw_set_freq(struct net_device *dev, 1798static int rndis_iw_set_freq(struct net_device *dev,
1973 struct iw_request_info *info, union iwreq_data *wrqu, char *extra) 1799 struct iw_request_info *info, union iwreq_data *wrqu, char *extra)
1974{ 1800{
@@ -2165,20 +1991,18 @@ static struct iw_statistics *rndis_get_wireless_stats(struct net_device *dev)
2165static const iw_handler rndis_iw_handler[] = 1991static const iw_handler rndis_iw_handler[] =
2166{ 1992{
2167 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit, 1993 IW_IOCTL(SIOCSIWCOMMIT) = rndis_iw_commit,
2168 IW_IOCTL(SIOCGIWNAME) = rndis_iw_get_name, 1994 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
2169 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq, 1995 IW_IOCTL(SIOCSIWFREQ) = rndis_iw_set_freq,
2170 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq, 1996 IW_IOCTL(SIOCGIWFREQ) = rndis_iw_get_freq,
2171 IW_IOCTL(SIOCSIWMODE) = rndis_iw_set_mode, 1997 IW_IOCTL(SIOCSIWMODE) = (iw_handler) cfg80211_wext_siwmode,
2172 IW_IOCTL(SIOCGIWMODE) = rndis_iw_get_mode, 1998 IW_IOCTL(SIOCGIWMODE) = (iw_handler) cfg80211_wext_giwmode,
2173 IW_IOCTL(SIOCGIWRANGE) = rndis_iw_get_range, 1999 IW_IOCTL(SIOCGIWRANGE) = (iw_handler) cfg80211_wext_giwrange,
2174 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid, 2000 IW_IOCTL(SIOCSIWAP) = rndis_iw_set_bssid,
2175 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid, 2001 IW_IOCTL(SIOCGIWAP) = rndis_iw_get_bssid,
2176 IW_IOCTL(SIOCSIWSCAN) = rndis_iw_set_scan, 2002 IW_IOCTL(SIOCSIWSCAN) = (iw_handler) cfg80211_wext_siwscan,
2177 IW_IOCTL(SIOCGIWSCAN) = rndis_iw_get_scan, 2003 IW_IOCTL(SIOCGIWSCAN) = (iw_handler) cfg80211_wext_giwscan,
2178 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid, 2004 IW_IOCTL(SIOCSIWESSID) = rndis_iw_set_essid,
2179 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid, 2005 IW_IOCTL(SIOCGIWESSID) = rndis_iw_get_essid,
2180 IW_IOCTL(SIOCSIWNICKN) = rndis_iw_set_nick,
2181 IW_IOCTL(SIOCGIWNICKN) = rndis_iw_get_nick,
2182 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate, 2006 IW_IOCTL(SIOCGIWRATE) = rndis_iw_get_rate,
2183 IW_IOCTL(SIOCSIWRTS) = rndis_iw_set_rts, 2007 IW_IOCTL(SIOCSIWRTS) = rndis_iw_set_rts,
2184 IW_IOCTL(SIOCGIWRTS) = rndis_iw_get_rts, 2008 IW_IOCTL(SIOCGIWRTS) = rndis_iw_get_rts,
@@ -2338,12 +2162,6 @@ static int rndis_wext_get_caps(struct usbnet *usbdev)
2338 break; 2162 break;
2339 } 2163 }
2340 } 2164 }
2341 if (priv->caps & CAP_MODE_80211A)
2342 strcat(priv->name, "a");
2343 if (priv->caps & CAP_MODE_80211B)
2344 strcat(priv->name, "b");
2345 if (priv->caps & CAP_MODE_80211G)
2346 strcat(priv->name, "g");
2347 } 2165 }
2348 2166
2349 return retval; 2167 return retval;
@@ -2387,7 +2205,7 @@ static void rndis_update_wireless_stats(struct work_struct *work)
2387 if (ret == 0) { 2205 if (ret == 0) {
2388 memset(&iwstats.qual, 0, sizeof(iwstats.qual)); 2206 memset(&iwstats.qual, 0, sizeof(iwstats.qual));
2389 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi)); 2207 iwstats.qual.qual = level_to_qual(le32_to_cpu(rssi));
2390 iwstats.qual.level = le32_to_cpu(rssi); 2208 iwstats.qual.level = level_to_qual(le32_to_cpu(rssi));
2391 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED 2209 iwstats.qual.updated = IW_QUAL_QUAL_UPDATED
2392 | IW_QUAL_LEVEL_UPDATED 2210 | IW_QUAL_LEVEL_UPDATED
2393 | IW_QUAL_NOISE_INVALID; 2211 | IW_QUAL_NOISE_INVALID;
@@ -2538,26 +2356,40 @@ static const struct net_device_ops rndis_wext_netdev_ops = {
2538 2356
2539static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf) 2357static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf)
2540{ 2358{
2359 struct wiphy *wiphy;
2541 struct rndis_wext_private *priv; 2360 struct rndis_wext_private *priv;
2542 int retval, len; 2361 int retval, len;
2543 __le32 tmp; 2362 __le32 tmp;
2544 2363
2545 /* allocate rndis private data */ 2364 /* allocate wiphy and rndis private data
2546 priv = kzalloc(sizeof(struct rndis_wext_private), GFP_KERNEL); 2365 * NOTE: We only support a single virtual interface, so wiphy
2547 if (!priv) 2366 * and wireless_dev are somewhat synonymous for this device.
2367 */
2368 wiphy = wiphy_new(&rndis_config_ops, sizeof(struct rndis_wext_private));
2369 if (!wiphy)
2548 return -ENOMEM; 2370 return -ENOMEM;
2549 2371
2372 priv = wiphy_priv(wiphy);
2373 usbdev->net->ieee80211_ptr = &priv->wdev;
2374 priv->wdev.wiphy = wiphy;
2375 priv->wdev.iftype = NL80211_IFTYPE_STATION;
2376
2550 /* These have to be initialized before calling generic_rndis_bind(). 2377 /* These have to be initialized before calling generic_rndis_bind().
2551 * Otherwise we'll be in big trouble in rndis_wext_early_init(). 2378 * Otherwise we'll be in big trouble in rndis_wext_early_init().
2552 */ 2379 */
2553 usbdev->driver_priv = priv; 2380 usbdev->driver_priv = priv;
2554 strcpy(priv->name, "IEEE802.11");
2555 usbdev->net->wireless_handlers = &rndis_iw_handlers; 2381 usbdev->net->wireless_handlers = &rndis_iw_handlers;
2556 priv->usbdev = usbdev; 2382 priv->usbdev = usbdev;
2557 2383
2558 mutex_init(&priv->command_lock); 2384 mutex_init(&priv->command_lock);
2559 spin_lock_init(&priv->stats_lock); 2385 spin_lock_init(&priv->stats_lock);
2560 2386
2387 /* because rndis_command() sleeps we need to use workqueue */
2388 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
2389 INIT_WORK(&priv->work, rndis_wext_worker);
2390 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2391 INIT_DELAYED_WORK(&priv->scan_work, rndis_get_scan_results);
2392
2561 /* try bind rndis_host */ 2393 /* try bind rndis_host */
2562 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS); 2394 retval = generic_rndis_bind(usbdev, intf, FLAG_RNDIS_PHYM_WIRELESS);
2563 if (retval < 0) 2395 if (retval < 0)
@@ -2595,7 +2427,32 @@ static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf)
2595 | IW_QUAL_QUAL_INVALID 2427 | IW_QUAL_QUAL_INVALID
2596 | IW_QUAL_LEVEL_INVALID; 2428 | IW_QUAL_LEVEL_INVALID;
2597 2429
2430 /* fill-out wiphy structure and register w/ cfg80211 */
2431 memcpy(wiphy->perm_addr, usbdev->net->dev_addr, ETH_ALEN);
2432 wiphy->privid = rndis_wiphy_privid;
2433 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
2434 | BIT(NL80211_IFTYPE_ADHOC);
2435 wiphy->max_scan_ssids = 1;
2436
2437 /* TODO: fill-out band information based on priv->caps */
2598 rndis_wext_get_caps(usbdev); 2438 rndis_wext_get_caps(usbdev);
2439
2440 memcpy(priv->channels, rndis_channels, sizeof(rndis_channels));
2441 memcpy(priv->rates, rndis_rates, sizeof(rndis_rates));
2442 priv->band.channels = priv->channels;
2443 priv->band.n_channels = ARRAY_SIZE(rndis_channels);
2444 priv->band.bitrates = priv->rates;
2445 priv->band.n_bitrates = ARRAY_SIZE(rndis_rates);
2446 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
2447 wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
2448
2449 set_wiphy_dev(wiphy, &usbdev->udev->dev);
2450
2451 if (wiphy_register(wiphy)) {
2452 retval = -ENODEV;
2453 goto fail;
2454 }
2455
2599 set_default_iw_params(usbdev); 2456 set_default_iw_params(usbdev);
2600 2457
2601 /* turn radio on */ 2458 /* turn radio on */
@@ -2603,17 +2460,19 @@ static int rndis_wext_bind(struct usbnet *usbdev, struct usb_interface *intf)
2603 disassociate(usbdev, 1); 2460 disassociate(usbdev, 1);
2604 netif_carrier_off(usbdev->net); 2461 netif_carrier_off(usbdev->net);
2605 2462
2606 /* because rndis_command() sleeps we need to use workqueue */
2607 priv->workqueue = create_singlethread_workqueue("rndis_wlan");
2608 INIT_DELAYED_WORK(&priv->stats_work, rndis_update_wireless_stats);
2609 queue_delayed_work(priv->workqueue, &priv->stats_work, 2463 queue_delayed_work(priv->workqueue, &priv->stats_work,
2610 round_jiffies_relative(STATS_UPDATE_JIFFIES)); 2464 round_jiffies_relative(STATS_UPDATE_JIFFIES));
2611 INIT_WORK(&priv->work, rndis_wext_worker);
2612 2465
2613 return 0; 2466 return 0;
2614 2467
2615fail: 2468fail:
2616 kfree(priv); 2469 cancel_delayed_work_sync(&priv->stats_work);
2470 cancel_delayed_work_sync(&priv->scan_work);
2471 cancel_work_sync(&priv->work);
2472 flush_workqueue(priv->workqueue);
2473 destroy_workqueue(priv->workqueue);
2474
2475 wiphy_free(wiphy);
2617 return retval; 2476 return retval;
2618} 2477}
2619 2478
@@ -2626,15 +2485,18 @@ static void rndis_wext_unbind(struct usbnet *usbdev, struct usb_interface *intf)
2626 disassociate(usbdev, 0); 2485 disassociate(usbdev, 0);
2627 2486
2628 cancel_delayed_work_sync(&priv->stats_work); 2487 cancel_delayed_work_sync(&priv->stats_work);
2488 cancel_delayed_work_sync(&priv->scan_work);
2629 cancel_work_sync(&priv->work); 2489 cancel_work_sync(&priv->work);
2630 flush_workqueue(priv->workqueue); 2490 flush_workqueue(priv->workqueue);
2631 destroy_workqueue(priv->workqueue); 2491 destroy_workqueue(priv->workqueue);
2632 2492
2633 if (priv && priv->wpa_ie_len) 2493 if (priv && priv->wpa_ie_len)
2634 kfree(priv->wpa_ie); 2494 kfree(priv->wpa_ie);
2635 kfree(priv);
2636 2495
2637 rndis_unbind(usbdev, intf); 2496 rndis_unbind(usbdev, intf);
2497
2498 wiphy_unregister(priv->wdev.wiphy);
2499 wiphy_free(priv->wdev.wiphy);
2638} 2500}
2639 2501
2640 2502
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index 0f08773328c..411eb9cbb4e 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -1361,7 +1361,7 @@ static int rt2400pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1361 */ 1361 */
1362 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); 1362 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1363 rt2x00pci_register_read(rt2x00dev, CSR0, &reg); 1363 rt2x00pci_register_read(rt2x00dev, CSR0, &reg);
1364 rt2x00_set_chip(rt2x00dev, RT2460, value, reg); 1364 rt2x00_set_chip_rf(rt2x00dev, value, reg);
1365 1365
1366 if (!rt2x00_rf(&rt2x00dev->chip, RF2420) && 1366 if (!rt2x00_rf(&rt2x00dev->chip, RF2420) &&
1367 !rt2x00_rf(&rt2x00dev->chip, RF2421)) { 1367 !rt2x00_rf(&rt2x00dev->chip, RF2421)) {
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index 276a8232aaa..e1be67ca23d 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -1525,7 +1525,7 @@ static int rt2500pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1525 */ 1525 */
1526 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); 1526 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1527 rt2x00pci_register_read(rt2x00dev, CSR0, &reg); 1527 rt2x00pci_register_read(rt2x00dev, CSR0, &reg);
1528 rt2x00_set_chip(rt2x00dev, RT2560, value, reg); 1528 rt2x00_set_chip_rf(rt2x00dev, value, reg);
1529 1529
1530 if (!rt2x00_rf(&rt2x00dev->chip, RF2522) && 1530 if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
1531 !rt2x00_rf(&rt2x00dev->chip, RF2523) && 1531 !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index 84bd6f19acb..e03d69975ea 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -672,6 +672,12 @@ struct rt2x00_dev {
672 unsigned long flags; 672 unsigned long flags;
673 673
674 /* 674 /*
675 * Device information, Bus IRQ and name (PCI, SoC)
676 */
677 int irq;
678 const char *name;
679
680 /*
675 * Chipset identification. 681 * Chipset identification.
676 */ 682 */
677 struct rt2x00_chip chip; 683 struct rt2x00_chip chip;
@@ -860,6 +866,18 @@ static inline void rt2x00_set_chip(struct rt2x00_dev *rt2x00dev,
860 rt2x00dev->chip.rev = rev; 866 rt2x00dev->chip.rev = rev;
861} 867}
862 868
869static inline void rt2x00_set_chip_rt(struct rt2x00_dev *rt2x00dev,
870 const u16 rt)
871{
872 rt2x00dev->chip.rt = rt;
873}
874
875static inline void rt2x00_set_chip_rf(struct rt2x00_dev *rt2x00dev,
876 const u16 rf, const u32 rev)
877{
878 rt2x00_set_chip(rt2x00dev, rt2x00dev->chip.rt, rf, rev);
879}
880
863static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip) 881static inline char rt2x00_rt(const struct rt2x00_chip *chipset, const u16 chip)
864{ 882{
865 return (chipset->rt == chip); 883 return (chipset->rt == chip);
diff --git a/drivers/net/wireless/rt2x00/rt2x00link.c b/drivers/net/wireless/rt2x00/rt2x00link.c
index 7eb5cd7e5f3..eb9b981b913 100644
--- a/drivers/net/wireless/rt2x00/rt2x00link.c
+++ b/drivers/net/wireless/rt2x00/rt2x00link.c
@@ -387,7 +387,7 @@ void rt2x00link_reset_tuner(struct rt2x00_dev *rt2x00dev, bool antenna)
387 rt2x00link_antenna_reset(rt2x00dev); 387 rt2x00link_antenna_reset(rt2x00dev);
388} 388}
389 389
390void rt2x00link_reset_qual(struct rt2x00_dev *rt2x00dev) 390static void rt2x00link_reset_qual(struct rt2x00_dev *rt2x00dev)
391{ 391{
392 struct link_qual *qual = &rt2x00dev->link.qual; 392 struct link_qual *qual = &rt2x00dev->link.qual;
393 393
diff --git a/drivers/net/wireless/rt2x00/rt2x00pci.c b/drivers/net/wireless/rt2x00/rt2x00pci.c
index 9730b4f8fd2..cdd5154bd4c 100644
--- a/drivers/net/wireless/rt2x00/rt2x00pci.c
+++ b/drivers/net/wireless/rt2x00/rt2x00pci.c
@@ -170,7 +170,6 @@ static void rt2x00pci_free_queue_dma(struct rt2x00_dev *rt2x00dev,
170 170
171int rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev) 171int rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev)
172{ 172{
173 struct pci_dev *pci_dev = to_pci_dev(rt2x00dev->dev);
174 struct data_queue *queue; 173 struct data_queue *queue;
175 int status; 174 int status;
176 175
@@ -186,11 +185,11 @@ int rt2x00pci_initialize(struct rt2x00_dev *rt2x00dev)
186 /* 185 /*
187 * Register interrupt handler. 186 * Register interrupt handler.
188 */ 187 */
189 status = request_irq(pci_dev->irq, rt2x00dev->ops->lib->irq_handler, 188 status = request_irq(rt2x00dev->irq, rt2x00dev->ops->lib->irq_handler,
190 IRQF_SHARED, pci_name(pci_dev), rt2x00dev); 189 IRQF_SHARED, rt2x00dev->name, rt2x00dev);
191 if (status) { 190 if (status) {
192 ERROR(rt2x00dev, "IRQ %d allocation failed (error %d).\n", 191 ERROR(rt2x00dev, "IRQ %d allocation failed (error %d).\n",
193 pci_dev->irq, status); 192 rt2x00dev->irq, status);
194 goto exit; 193 goto exit;
195 } 194 }
196 195
@@ -270,6 +269,7 @@ int rt2x00pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
270 struct ieee80211_hw *hw; 269 struct ieee80211_hw *hw;
271 struct rt2x00_dev *rt2x00dev; 270 struct rt2x00_dev *rt2x00dev;
272 int retval; 271 int retval;
272 u16 chip;
273 273
274 retval = pci_request_regions(pci_dev, pci_name(pci_dev)); 274 retval = pci_request_regions(pci_dev, pci_name(pci_dev));
275 if (retval) { 275 if (retval) {
@@ -307,6 +307,14 @@ int rt2x00pci_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
307 rt2x00dev->dev = &pci_dev->dev; 307 rt2x00dev->dev = &pci_dev->dev;
308 rt2x00dev->ops = ops; 308 rt2x00dev->ops = ops;
309 rt2x00dev->hw = hw; 309 rt2x00dev->hw = hw;
310 rt2x00dev->irq = pci_dev->irq;
311 rt2x00dev->name = pci_name(pci_dev);
312
313 /*
314 * Determine RT chipset by reading PCI header.
315 */
316 pci_read_config_word(pci_dev, PCI_DEVICE_ID, &chip);
317 rt2x00_set_chip_rt(rt2x00dev, chip);
310 318
311 retval = rt2x00pci_alloc_reg(rt2x00dev); 319 retval = rt2x00pci_alloc_reg(rt2x00dev);
312 if (retval) 320 if (retval)
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 2ca8b7a9722..4346cd1494b 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -2308,7 +2308,6 @@ static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2308 u32 reg; 2308 u32 reg;
2309 u16 value; 2309 u16 value;
2310 u16 eeprom; 2310 u16 eeprom;
2311 u16 device;
2312 2311
2313 /* 2312 /*
2314 * Read EEPROM word for configuration. 2313 * Read EEPROM word for configuration.
@@ -2317,14 +2316,10 @@ static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2317 2316
2318 /* 2317 /*
2319 * Identify RF chipset. 2318 * Identify RF chipset.
2320 * To determine the RT chip we have to read the
2321 * PCI header of the device.
2322 */ 2319 */
2323 pci_read_config_word(to_pci_dev(rt2x00dev->dev),
2324 PCI_CONFIG_HEADER_DEVICE, &device);
2325 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE); 2320 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
2326 rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg); 2321 rt2x00pci_register_read(rt2x00dev, MAC_CSR0, &reg);
2327 rt2x00_set_chip(rt2x00dev, device, value, reg); 2322 rt2x00_set_chip_rf(rt2x00dev, value, reg);
2328 2323
2329 if (!rt2x00_rf(&rt2x00dev->chip, RF5225) && 2324 if (!rt2x00_rf(&rt2x00dev->chip, RF5225) &&
2330 !rt2x00_rf(&rt2x00dev->chip, RF5325) && 2325 !rt2x00_rf(&rt2x00dev->chip, RF5325) &&
diff --git a/drivers/net/wireless/rt2x00/rt61pci.h b/drivers/net/wireless/rt2x00/rt61pci.h
index 41e8959919f..6c71f77c816 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.h
+++ b/drivers/net/wireless/rt2x00/rt61pci.h
@@ -63,12 +63,6 @@
63 */ 63 */
64 64
65/* 65/*
66 * PCI Configuration Header
67 */
68#define PCI_CONFIG_HEADER_VENDOR 0x0000
69#define PCI_CONFIG_HEADER_DEVICE 0x0002
70
71/*
72 * HOST_CMD_CSR: For HOST to interrupt embedded processor 66 * HOST_CMD_CSR: For HOST to interrupt embedded processor
73 */ 67 */
74#define HOST_CMD_CSR 0x0008 68#define HOST_CMD_CSR 0x0008
diff --git a/drivers/net/wireless/rtl818x/Makefile b/drivers/net/wireless/rtl818x/Makefile
index c113b3e6904..37e3d4db0c4 100644
--- a/drivers/net/wireless/rtl818x/Makefile
+++ b/drivers/net/wireless/rtl818x/Makefile
@@ -1,5 +1,5 @@
1rtl8180-objs := rtl8180_dev.o rtl8180_rtl8225.o rtl8180_sa2400.o rtl8180_max2820.o rtl8180_grf5101.o 1rtl8180-objs := rtl8180_dev.o rtl8180_rtl8225.o rtl8180_sa2400.o rtl8180_max2820.o rtl8180_grf5101.o
2rtl8187-objs := rtl8187_dev.o rtl8187_rtl8225.o 2rtl8187-objs := rtl8187_dev.o rtl8187_rtl8225.o rtl8187_leds.o
3 3
4obj-$(CONFIG_RTL8180) += rtl8180.o 4obj-$(CONFIG_RTL8180) += rtl8180.o
5obj-$(CONFIG_RTL8187) += rtl8187.o 5obj-$(CONFIG_RTL8187) += rtl8187.o
diff --git a/drivers/net/wireless/rtl818x/rtl8187.h b/drivers/net/wireless/rtl818x/rtl8187.h
index 9718f61809c..622196dc078 100644
--- a/drivers/net/wireless/rtl818x/rtl8187.h
+++ b/drivers/net/wireless/rtl818x/rtl8187.h
@@ -16,6 +16,7 @@
16#define RTL8187_H 16#define RTL8187_H
17 17
18#include "rtl818x.h" 18#include "rtl818x.h"
19#include "rtl8187_leds.h"
19 20
20#define RTL8187_EEPROM_TXPWR_BASE 0x05 21#define RTL8187_EEPROM_TXPWR_BASE 0x05
21#define RTL8187_EEPROM_MAC_ADDR 0x07 22#define RTL8187_EEPROM_MAC_ADDR 0x07
@@ -102,6 +103,12 @@ struct rtl8187_priv {
102 struct usb_anchor anchored; 103 struct usb_anchor anchored;
103 struct delayed_work work; 104 struct delayed_work work;
104 struct ieee80211_hw *dev; 105 struct ieee80211_hw *dev;
106#ifdef CONFIG_RTL8187_LEDS
107 struct rtl8187_led led_tx;
108 struct rtl8187_led led_rx;
109 struct delayed_work led_on;
110 struct delayed_work led_off;
111#endif
105 u16 txpwr_base; 112 u16 txpwr_base;
106 u8 asic_rev; 113 u8 asic_rev;
107 u8 is_rtl8187b; 114 u8 is_rtl8187b;
diff --git a/drivers/net/wireless/rtl818x/rtl8187_dev.c b/drivers/net/wireless/rtl818x/rtl8187_dev.c
index fd81884b9c7..ac558da92aa 100644
--- a/drivers/net/wireless/rtl818x/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187_dev.c
@@ -29,6 +29,9 @@
29 29
30#include "rtl8187.h" 30#include "rtl8187.h"
31#include "rtl8187_rtl8225.h" 31#include "rtl8187_rtl8225.h"
32#ifdef CONFIG_RTL8187_LEDS
33#include "rtl8187_leds.h"
34#endif
32 35
33MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); 36MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
34MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>"); 37MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
@@ -734,10 +737,10 @@ static const u8 rtl8187b_reg_table[][3] = {
734 {0x85, 0x24, 0}, {0x88, 0x54, 0}, {0x8B, 0xB8, 0}, {0x8C, 0x07, 0}, 737 {0x85, 0x24, 0}, {0x88, 0x54, 0}, {0x8B, 0xB8, 0}, {0x8C, 0x07, 0},
735 {0x8D, 0x00, 0}, {0x94, 0x1B, 0}, {0x95, 0x12, 0}, {0x96, 0x00, 0}, 738 {0x8D, 0x00, 0}, {0x94, 0x1B, 0}, {0x95, 0x12, 0}, {0x96, 0x00, 0},
736 {0x97, 0x06, 0}, {0x9D, 0x1A, 0}, {0x9F, 0x10, 0}, {0xB4, 0x22, 0}, 739 {0x97, 0x06, 0}, {0x9D, 0x1A, 0}, {0x9F, 0x10, 0}, {0xB4, 0x22, 0},
737 {0xBE, 0x80, 0}, {0xDB, 0x00, 0}, {0xEE, 0x00, 0}, {0x91, 0x03, 0}, 740 {0xBE, 0x80, 0}, {0xDB, 0x00, 0}, {0xEE, 0x00, 0}, {0x4C, 0x00, 2},
738 741
739 {0x4C, 0x00, 2}, {0x9F, 0x00, 3}, {0x8C, 0x01, 0}, {0x8D, 0x10, 0}, 742 {0x9F, 0x00, 3}, {0x8C, 0x01, 0}, {0x8D, 0x10, 0}, {0x8E, 0x08, 0},
740 {0x8E, 0x08, 0}, {0x8F, 0x00, 0} 743 {0x8F, 0x00, 0}
741}; 744};
742 745
743static int rtl8187b_init_hw(struct ieee80211_hw *dev) 746static int rtl8187b_init_hw(struct ieee80211_hw *dev)
@@ -1470,9 +1473,6 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
1470 (*channel++).hw_value = txpwr >> 8; 1473 (*channel++).hw_value = txpwr >> 8;
1471 } 1474 }
1472 1475
1473 if (priv->is_rtl8187b)
1474 printk(KERN_WARNING "rtl8187: 8187B chip detected.\n");
1475
1476 /* 1476 /*
1477 * XXX: Once this driver supports anything that requires 1477 * XXX: Once this driver supports anything that requires
1478 * beacons it must implement IEEE80211_TX_CTL_ASSIGN_SEQ. 1478 * beacons it must implement IEEE80211_TX_CTL_ASSIGN_SEQ.
@@ -1504,6 +1504,12 @@ static int __devinit rtl8187_probe(struct usb_interface *intf,
1504 wiphy_name(dev->wiphy), dev->wiphy->perm_addr, 1504 wiphy_name(dev->wiphy), dev->wiphy->perm_addr,
1505 chip_name, priv->asic_rev, priv->rf->name); 1505 chip_name, priv->asic_rev, priv->rf->name);
1506 1506
1507#ifdef CONFIG_RTL8187_LEDS
1508 eeprom_93cx6_read(&eeprom, 0x3F, &reg);
1509 reg &= 0xFF;
1510 rtl8187_leds_init(dev, reg);
1511#endif
1512
1507 return 0; 1513 return 0;
1508 1514
1509 err_free_dev: 1515 err_free_dev:
@@ -1521,6 +1527,9 @@ static void __devexit rtl8187_disconnect(struct usb_interface *intf)
1521 if (!dev) 1527 if (!dev)
1522 return; 1528 return;
1523 1529
1530#ifdef CONFIG_RTL8187_LEDS
1531 rtl8187_leds_exit(dev);
1532#endif
1524 ieee80211_unregister_hw(dev); 1533 ieee80211_unregister_hw(dev);
1525 1534
1526 priv = dev->priv; 1535 priv = dev->priv;
diff --git a/drivers/net/wireless/rtl818x/rtl8187_leds.c b/drivers/net/wireless/rtl818x/rtl8187_leds.c
new file mode 100644
index 00000000000..b4425359224
--- /dev/null
+++ b/drivers/net/wireless/rtl818x/rtl8187_leds.c
@@ -0,0 +1,218 @@
1/*
2 * Linux LED driver for RTL8187
3 *
4 * Copyright 2009 Larry Finger <Larry.Finger@lwfinger.net>
5 *
6 * Based on the LED handling in the r8187 driver, which is:
7 * Copyright (c) Realtek Semiconductor Corp. All rights reserved.
8 *
9 * Thanks to Realtek for their support!
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#ifdef CONFIG_RTL8187_LEDS
17
18#include <net/mac80211.h>
19#include <linux/usb.h>
20#include <linux/eeprom_93cx6.h>
21
22#include "rtl8187.h"
23#include "rtl8187_leds.h"
24
25static void led_turn_on(struct work_struct *work)
26{
27 /* As this routine does read/write operations on the hardware, it must
28 * be run from a work queue.
29 */
30 u8 reg;
31 struct rtl8187_priv *priv = container_of(work, struct rtl8187_priv,
32 led_on.work);
33 struct rtl8187_led *led = &priv->led_tx;
34
35 /* Don't change the LED, when the device is down. */
36 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
37 return ;
38
39 /* Skip if the LED is not registered. */
40 if (!led->dev)
41 return;
42 mutex_lock(&priv->conf_mutex);
43 switch (led->ledpin) {
44 case LED_PIN_GPIO0:
45 rtl818x_iowrite8(priv, &priv->map->GPIO, 0x01);
46 rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0x00);
47 break;
48 case LED_PIN_LED0:
49 reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) & ~(1 << 4);
50 rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
51 break;
52 case LED_PIN_LED1:
53 reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) & ~(1 << 5);
54 rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
55 break;
56 case LED_PIN_HW:
57 default:
58 break;
59 }
60 mutex_unlock(&priv->conf_mutex);
61}
62
63static void led_turn_off(struct work_struct *work)
64{
65 /* As this routine does read/write operations on the hardware, it must
66 * be run from a work queue.
67 */
68 u8 reg;
69 struct rtl8187_priv *priv = container_of(work, struct rtl8187_priv,
70 led_off.work);
71 struct rtl8187_led *led = &priv->led_tx;
72
73 /* Don't change the LED, when the device is down. */
74 if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
75 return ;
76
77 /* Skip if the LED is not registered. */
78 if (!led->dev)
79 return;
80 mutex_lock(&priv->conf_mutex);
81 switch (led->ledpin) {
82 case LED_PIN_GPIO0:
83 rtl818x_iowrite8(priv, &priv->map->GPIO, 0x01);
84 rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0x01);
85 break;
86 case LED_PIN_LED0:
87 reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) | (1 << 4);
88 rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
89 break;
90 case LED_PIN_LED1:
91 reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) | (1 << 5);
92 rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
93 break;
94 case LED_PIN_HW:
95 default:
96 break;
97 }
98 mutex_unlock(&priv->conf_mutex);
99}
100
101/* Callback from the LED subsystem. */
102static void rtl8187_led_brightness_set(struct led_classdev *led_dev,
103 enum led_brightness brightness)
104{
105 struct rtl8187_led *led = container_of(led_dev, struct rtl8187_led,
106 led_dev);
107 struct ieee80211_hw *hw = led->dev;
108 struct rtl8187_priv *priv = hw->priv;
109
110 if (brightness == LED_OFF) {
111 queue_delayed_work(hw->workqueue, &priv->led_off, 0);
112 /* The LED is off for 1/20 sec so that it just blinks. */
113 queue_delayed_work(hw->workqueue, &priv->led_on, HZ / 20);
114 } else
115 queue_delayed_work(hw->workqueue, &priv->led_on, 0);
116}
117
118static int rtl8187_register_led(struct ieee80211_hw *dev,
119 struct rtl8187_led *led, const char *name,
120 const char *default_trigger, u8 ledpin)
121{
122 int err;
123 struct rtl8187_priv *priv = dev->priv;
124
125 if (led->dev)
126 return -EEXIST;
127 if (!default_trigger)
128 return -EINVAL;
129 led->dev = dev;
130 led->ledpin = ledpin;
131 strncpy(led->name, name, sizeof(led->name));
132
133 led->led_dev.name = led->name;
134 led->led_dev.default_trigger = default_trigger;
135 led->led_dev.brightness_set = rtl8187_led_brightness_set;
136
137 err = led_classdev_register(&priv->udev->dev, &led->led_dev);
138 if (err) {
139 printk(KERN_INFO "LEDs: Failed to register %s\n", name);
140 led->dev = NULL;
141 return err;
142 }
143 return 0;
144}
145
146static void rtl8187_unregister_led(struct rtl8187_led *led)
147{
148 led_classdev_unregister(&led->led_dev);
149 led->dev = NULL;
150}
151
152void rtl8187_leds_init(struct ieee80211_hw *dev, u16 custid)
153{
154 struct rtl8187_priv *priv = dev->priv;
155 char name[RTL8187_LED_MAX_NAME_LEN + 1];
156 u8 ledpin;
157 int err;
158
159 /* According to the vendor driver, the LED operation depends on the
160 * customer ID encoded in the EEPROM
161 */
162 printk(KERN_INFO "rtl8187: Customer ID is 0x%02X\n", custid);
163 switch (custid) {
164 case EEPROM_CID_RSVD0:
165 case EEPROM_CID_RSVD1:
166 case EEPROM_CID_SERCOMM_PS:
167 case EEPROM_CID_QMI:
168 case EEPROM_CID_DELL:
169 case EEPROM_CID_TOSHIBA:
170 ledpin = LED_PIN_GPIO0;
171 break;
172 case EEPROM_CID_ALPHA0:
173 ledpin = LED_PIN_LED0;
174 break;
175 case EEPROM_CID_HW:
176 ledpin = LED_PIN_HW;
177 break;
178 default:
179 ledpin = LED_PIN_GPIO0;
180 }
181
182 INIT_DELAYED_WORK(&priv->led_on, led_turn_on);
183 INIT_DELAYED_WORK(&priv->led_off, led_turn_off);
184
185 snprintf(name, sizeof(name),
186 "rtl8187-%s::tx", wiphy_name(dev->wiphy));
187 err = rtl8187_register_led(dev, &priv->led_tx, name,
188 ieee80211_get_tx_led_name(dev), ledpin);
189 if (err)
190 goto error;
191 snprintf(name, sizeof(name),
192 "rtl8187-%s::rx", wiphy_name(dev->wiphy));
193 err = rtl8187_register_led(dev, &priv->led_rx, name,
194 ieee80211_get_rx_led_name(dev), ledpin);
195 if (!err) {
196 queue_delayed_work(dev->workqueue, &priv->led_on, 0);
197 return;
198 }
199 /* registration of RX LED failed - unregister TX */
200 rtl8187_unregister_led(&priv->led_tx);
201error:
202 /* If registration of either failed, cancel delayed work */
203 cancel_delayed_work_sync(&priv->led_off);
204 cancel_delayed_work_sync(&priv->led_on);
205}
206
207void rtl8187_leds_exit(struct ieee80211_hw *dev)
208{
209 struct rtl8187_priv *priv = dev->priv;
210
211 rtl8187_unregister_led(&priv->led_tx);
212 /* turn the LED off before exiting */
213 queue_delayed_work(dev->workqueue, &priv->led_off, 0);
214 cancel_delayed_work_sync(&priv->led_off);
215 rtl8187_unregister_led(&priv->led_rx);
216}
217#endif /* def CONFIG_RTL8187_LED */
218
diff --git a/drivers/net/wireless/rtl818x/rtl8187_leds.h b/drivers/net/wireless/rtl818x/rtl8187_leds.h
new file mode 100644
index 00000000000..a0332027aea
--- /dev/null
+++ b/drivers/net/wireless/rtl818x/rtl8187_leds.h
@@ -0,0 +1,57 @@
1/*
2 * Definitions for RTL8187 leds
3 *
4 * Copyright 2009 Larry Finger <Larry.Finger@lwfinger.net>
5 *
6 * Based on the LED handling in the r8187 driver, which is:
7 * Copyright (c) Realtek Semiconductor Corp. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#ifndef RTL8187_LED_H
15#define RTL8187_LED_H
16
17#ifdef CONFIG_RTL8187_LEDS
18
19#define RTL8187_LED_MAX_NAME_LEN 21
20
21#include <linux/leds.h>
22#include <linux/types.h>
23
24enum {
25 LED_PIN_LED0,
26 LED_PIN_LED1,
27 LED_PIN_GPIO0,
28 LED_PIN_HW
29};
30
31enum {
32 EEPROM_CID_RSVD0 = 0x00,
33 EEPROM_CID_RSVD1 = 0xFF,
34 EEPROM_CID_ALPHA0 = 0x01,
35 EEPROM_CID_SERCOMM_PS = 0x02,
36 EEPROM_CID_HW = 0x03,
37 EEPROM_CID_TOSHIBA = 0x04,
38 EEPROM_CID_QMI = 0x07,
39 EEPROM_CID_DELL = 0x08
40};
41
42struct rtl8187_led {
43 struct ieee80211_hw *dev;
44 /* The LED class device */
45 struct led_classdev led_dev;
46 /* The pin/method used to control the led */
47 u8 ledpin;
48 /* The unique name string for this LED device. */
49 char name[RTL8187_LED_MAX_NAME_LEN + 1];
50};
51
52void rtl8187_leds_init(struct ieee80211_hw *dev, u16 code);
53void rtl8187_leds_exit(struct ieee80211_hw *dev);
54
55#endif /* def CONFIG_RTL8187_LED */
56
57#endif /* RTL8187_LED_H */